/scripts/gpu_table_tester
Perl | 262 lines | 202 code | 34 blank | 26 comment | 32 complexity | 26334f729d3a77980d81abf26c07608c MD5 | raw file
Possible License(s): LGPL-2.1
1#!/usr/bin/perl 2## Checks entries in the indra/newview/gpu_table.txt file against sample data 3## 4## Copyright (c) 2011, Linden Research, Inc. 5## 6## Permission is hereby granted, free of charge, to any person obtaining a copy 7## of this software and associated documentation files (the "Software"), to deal 8## in the Software without restriction, including without limitation the rights 9## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10## copies of the Software, and to permit persons to whom the Software is 11## furnished to do so, subject to the following conditions: 12## 13## The above copyright notice and this permission notice shall be included in 14## all copies or substantial portions of the Software. 15## 16## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22## THE SOFTWARE. 23 24use English; 25use Getopt::Long; 26 27( $MyName = $0 ) =~ s|.*/||; 28my $mini_HELP = " 29 $MyName {--gpu-table|-g} <gpu_table.txt> {--table-only|-t} 30 31 Checks for duplicates and invalid lines in the gpu_table.txt file. 32 33 $MyName {--gpu-table|-g} <gpu_table.txt> [ <gpu-strings-file> ... ] 34 [{--unmatched|-u}] 35 36 Tests the recognition of values in the gpu-strings-files (or 37 standard input if no files are given). The results of attempting to match 38 each input line are displayed in report form, showing: 39 - NO MATCH, unsupported, or supported 40 - the class of the GPU 41 - the label for the recognizer line from the gpu_table that it matched 42 43 If the --unmatched option is specified, then no output is produced for 44 values that are matched. 45 46 $MyName {--gpu-table|-g} <gpu_table.txt> {--diff|-d} <old_results> [ <gpu-strings-file> ...] 47 48 With the --diff option, the report compares the current results to <old-results>, 49 which should be the output from a previous run without --diff. The report shows each 50 input value with the old result and the new result if it is different. 51"; 52 53&GetOptions("help" => \$Help 54 ,"unmatched" => \$UnMatchedOnly 55 ,"table-only" => \$TableOnly 56 ,"gpu-table=s" => \$GpuTable 57 ,"diff=s" => \$Diff 58 ) 59 || die "$mini_HELP"; 60 61if ($Help) 62{ 63 print $mini_HELP; 64 exit 0; 65} 66 67$ErrorsSeen = 0; 68$NoMatch = 'NO MATCH'; # constant 69 70die "Must specify a --gpu-table <gpu_table.txt> value" 71 unless $GpuTable; 72 73open(GPUS, "<$GpuTable") 74 || die "Failed to open gpu table '$GpuTable':\n\t$!\n"; 75 76# Parse the GPU table into these tables, indexed by the name 77my %NameLine; # name -> line number on which a given name was found (catches duplicate names) 78my %RecognizerLine; # name -> line number on which a given name was found (catches duplicate names) 79my %Name; # recognizer -> name 80my %Recognizer; # name -> recognizer 81my %Class; # recognizer -> class 82my %Supported; # recognizer -> supported 83my @InOrder; # lowercased recognizers in file order - these are the ones really used to match 84 85$Name{$NoMatch} = $NoMatch; 86$NameLine{$NoMatch} = '(hard-coded)'; # use this for error messages in table parsing 87$Class{$NoMatch} = ''; 88$Supported{$NoMatch} = ''; 89 90while (<GPUS>) 91{ 92 next if m|^//|; # skip comments 93 next if m|^\s*$|; # skip blank lines 94 95 chomp; 96 my ($name, $regex, $class, $supported, $extra) = split('\t+'); 97 my $errsOnLine = $ErrorsSeen; 98 if (!$name) 99 { 100 print STDERR "No name found on $GpuTable line $INPUT_LINE_NUMBER\n"; 101 $ErrorsSeen++; 102 } 103 elsif ( defined $NameLine{$name} ) 104 { 105 print STDERR "Duplicate name '$name' on $GpuTable lines $NameLine{$name} and $INPUT_LINE_NUMBER:\n"; 106 print STDERR " $NameLine{$name}: /$Recognizer{$name}/ $Supported{$Recognizer{$name}} class $Class{$Recognizer{$name}}\n"; 107 print STDERR " $INPUT_LINE_NUMBER: /$regex/ " . ($supported ? "supported" : "unsupported") . " class $class - ignored\n"; 108 $ErrorsSeen++; 109 } 110 if (!$regex) 111 { 112 print STDERR "No recognizer found on $GpuTable line $INPUT_LINE_NUMBER\n"; 113 $ErrorsSeen++; 114 } 115 elsif ( defined $RecognizerLine{$regex} ) 116 { 117 print STDERR "Duplicate recognizer /$regex/ found on $GpuTable lines $RecognizerLine{$regex} and $INPUT_LINE_NUMBER (ignored)\n"; 118 print STDERR " $RecognizerLine{$regex}: name '$Name{$regex}' $Supported{$regex} class $Class{$regex}\n"; 119 print STDERR " $INPUT_LINE_NUMBER: name '$name' " . ($supported ? "supported" : "unsupported") . " class $class - ignored\n"; 120 $ErrorsSeen++; 121 } 122 if ($class !~ m/[0123]/) 123 { 124 print STDERR "Invalid class value '$class' on $GpuTable line $INPUT_LINE_NUMBER\n"; 125 $ErrorsSeen++; 126 } 127 if ($supported !~ m/[0123]/) 128 { 129 print STDERR "Invalid supported value '$supported' on $GpuTable line $INPUT_LINE_NUMBER\n"; 130 $ErrorsSeen++; 131 } 132 if ($extra) 133 { 134 print STDERR "Extra data '$extra' on $GpuTable line $INPUT_LINE_NUMBER\n"; 135 $ErrorsSeen++; 136 } 137 138 if ($errsOnLine == $ErrorsSeen) # no errors found on this line 139 { 140 push @InOrder,$regex; 141 $NameLine{$name} = $INPUT_LINE_NUMBER; 142 $RecognizerLine{$regex} = $INPUT_LINE_NUMBER; 143 $Name{$regex} = $name; 144 $Recognizer{$name} = $regex; 145 $Class{$regex} = $class; 146 $Supported{$regex} = $supported ? "supported" : "unsupported"; 147 } 148} 149 150close GPUS; 151 152print STDERR "\n" if $ErrorsSeen; 153 154exit $ErrorsSeen if $TableOnly; 155 156 157# Loop over input lines, find the results for each 158my %RecognizedBy; 159while (<>) 160{ 161 chomp; 162 my $lcInput = lc $_; # the real gpu table parser lowercases the input string 163 my $recognizer; 164 $RecognizedBy{$_} = $NoMatch; 165 foreach $recognizer ( @InOrder ) # note early exit if recognized 166 { 167 my $lcRecognizer = lc $recognizer; # the real gpu table parser lowercases the recognizer 168 if ( $lcInput =~ m/$lcRecognizer/ ) 169 { 170 $RecognizedBy{$_} = $recognizer; 171 last; # exit recognizer loop 172 } 173 } 174} 175 176format STDOUT_TOP = 177GPU String Supported? Class Recognizer 178------------------------------------------------------------------------------------------------------ ----------- ----- ------------------------------------ 179. 180format STDOUT = 181@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... @<<<<<<<<<< @> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... 182$_, $Supported{$RecognizedBy{$_}},$Class{$RecognizedBy{$_}},$Name{$RecognizedBy{$_}} 183. 184 185my $ReportLineTemplate = "A102xxxA12xxxAA*"; # MUST match the format STDOUT above 186 187format DIFF_TOP = 188 ------ OLD ------ ------ NEW ------ 189GPU String Supported? Class Supported? Class 190------------------------------------------------------------------------------------------------------ ----------- ----- ----------- ----- 191. 192 193my ( $oldSupported, $oldClass, $newSupported, $newClass ); 194 195format DIFF = 196@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... @<<<<<<<<<< @> @<<<<<<<<<< @> 197$_, $oldSupported, $oldClass, $newSupported, $newClass 198. 199 200if ( ! $Diff ) 201{ 202 ## Print results. 203 ## For each input, show supported or unsupported, the class, and the recognizer name 204 205 foreach ( sort keys %RecognizedBy ) 206 { 207 write if ! $UnMatchedOnly || $Name{$RecognizedBy{$_}} eq $NoMatch; 208 $-++; # suppresses pagination 209 } 210} 211else 212{ 213 open OLD, "<$Diff" 214 || die "Failed to open --diff file '$Diff'\n\t$!\n"; 215 my $discard = 2; 216 while ( <OLD> ) 217 { 218 if ( $discard > 0 ) 219 { 220 my ( $gpu, $supported, $class ) = unpack $ReportLineTemplate; 221 $gpu =~ s/\s*$//; 222 ( $OldSupported{$gpu} = $supported ) =~ s/\s*$//; 223 ( $OldClass{$gpu} = $class ) =~ s/\s*$//; 224 } 225 else 226 { 227 $discard--; 228 } 229 } 230 close OLD; 231 232 $FORMAT_TOP_NAME = DIFF_TOP; 233 $FORMAT_NAME = DIFF; 234 foreach ( sort keys %RecognizedBy ) 235 { 236 $newSupported = $Supported{$RecognizedBy{$_}} || $NoMatch; 237 $newClass = $Class{$RecognizedBy{$_}}; 238 239 if ( ! defined $OldSupported{$_} ) 240 { 241 $oldSupported = 'NEW'; 242 $oldClass = '-'; 243 } 244 else 245 { 246 $oldSupported = $OldSupported{$_} || $NoMatch; 247 $oldClass = $OldClass{$_}; 248 249 if ( ( $oldSupported eq $newSupported ) 250 && ( $oldClass eq $newClass ) 251 ) 252 { 253 $newSupported = ''; 254 $newClass = ''; 255 } 256 } 257 write; 258 $-++; # suppresses pagination 259 } 260} 261 262exit $ErrorsSeen;