PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/gpu_table_tester

https://bitbucket.org/lindenlab/viewer-beta/
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. use English;
  24. use Getopt::Long;
  25. ( $MyName = $0 ) =~ s|.*/||;
  26. my $mini_HELP = "
  27. $MyName {--gpu-table|-g} <gpu_table.txt> {--table-only|-t}
  28. Checks for duplicates and invalid lines in the gpu_table.txt file.
  29. $MyName {--gpu-table|-g} <gpu_table.txt> [ <gpu-strings-file> ... ]
  30. [{--unmatched|-u}]
  31. Tests the recognition of values in the gpu-strings-files (or
  32. standard input if no files are given). The results of attempting to match
  33. each input line are displayed in report form, showing:
  34. - NO MATCH, unsupported, or supported
  35. - the class of the GPU
  36. - the label for the recognizer line from the gpu_table that it matched
  37. If the --unmatched option is specified, then no output is produced for
  38. values that are matched.
  39. $MyName {--gpu-table|-g} <gpu_table.txt> {--diff|-d} <old_results> [ <gpu-strings-file> ...]
  40. With the --diff option, the report compares the current results to <old-results>,
  41. which should be the output from a previous run without --diff. The report shows each
  42. input value with the old result and the new result if it is different.
  43. ";
  44. &GetOptions("help" => \$Help
  45. ,"unmatched" => \$UnMatchedOnly
  46. ,"table-only" => \$TableOnly
  47. ,"gpu-table=s" => \$GpuTable
  48. ,"diff=s" => \$Diff
  49. )
  50. || die "$mini_HELP";
  51. if ($Help)
  52. {
  53. print $mini_HELP;
  54. exit 0;
  55. }
  56. $ErrorsSeen = 0;
  57. $NoMatch = 'NO MATCH'; # constant
  58. die "Must specify a --gpu-table <gpu_table.txt> value"
  59. unless $GpuTable;
  60. open(GPUS, "<$GpuTable")
  61. || die "Failed to open gpu table '$GpuTable':\n\t$!\n";
  62. # Parse the GPU table into these tables, indexed by the name
  63. my %NameLine; # name -> line number on which a given name was found (catches duplicate names)
  64. my %RecognizerLine; # name -> line number on which a given name was found (catches duplicate names)
  65. my %Name; # recognizer -> name
  66. my %Recognizer; # name -> recognizer
  67. my %Class; # recognizer -> class
  68. my %Supported; # recognizer -> supported
  69. my @InOrder; # lowercased recognizers in file order - these are the ones really used to match
  70. $Name{$NoMatch} = $NoMatch;
  71. $NameLine{$NoMatch} = '(hard-coded)'; # use this for error messages in table parsing
  72. $Class{$NoMatch} = '';
  73. $Supported{$NoMatch} = '';
  74. while (<GPUS>)
  75. {
  76. next if m|^//|; # skip comments
  77. next if m|^\s*$|; # skip blank lines
  78. chomp;
  79. my ($name, $regex, $class, $supported, $extra) = split('\t+');
  80. my $errsOnLine = $ErrorsSeen;
  81. if (!$name)
  82. {
  83. print STDERR "No name found on $GpuTable line $INPUT_LINE_NUMBER\n";
  84. $ErrorsSeen++;
  85. }
  86. elsif ( defined $NameLine{$name} )
  87. {
  88. print STDERR "Duplicate name '$name' on $GpuTable lines $NameLine{$name} and $INPUT_LINE_NUMBER:\n";
  89. print STDERR " $NameLine{$name}: /$Recognizer{$name}/ $Supported{$Recognizer{$name}} class $Class{$Recognizer{$name}}\n";
  90. print STDERR " $INPUT_LINE_NUMBER: /$regex/ " . ($supported ? "supported" : "unsupported") . " class $class - ignored\n";
  91. $ErrorsSeen++;
  92. }
  93. if (!$regex)
  94. {
  95. print STDERR "No recognizer found on $GpuTable line $INPUT_LINE_NUMBER\n";
  96. $ErrorsSeen++;
  97. }
  98. elsif ( defined $RecognizerLine{$regex} )
  99. {
  100. print STDERR "Duplicate recognizer /$regex/ found on $GpuTable lines $RecognizerLine{$regex} and $INPUT_LINE_NUMBER (ignored)\n";
  101. print STDERR " $RecognizerLine{$regex}: name '$Name{$regex}' $Supported{$regex} class $Class{$regex}\n";
  102. print STDERR " $INPUT_LINE_NUMBER: name '$name' " . ($supported ? "supported" : "unsupported") . " class $class - ignored\n";
  103. $ErrorsSeen++;
  104. }
  105. if ($class !~ m/[0123]/)
  106. {
  107. print STDERR "Invalid class value '$class' on $GpuTable line $INPUT_LINE_NUMBER\n";
  108. $ErrorsSeen++;
  109. }
  110. if ($supported !~ m/[0123]/)
  111. {
  112. print STDERR "Invalid supported value '$supported' on $GpuTable line $INPUT_LINE_NUMBER\n";
  113. $ErrorsSeen++;
  114. }
  115. if ($extra)
  116. {
  117. print STDERR "Extra data '$extra' on $GpuTable line $INPUT_LINE_NUMBER\n";
  118. $ErrorsSeen++;
  119. }
  120. if ($errsOnLine == $ErrorsSeen) # no errors found on this line
  121. {
  122. push @InOrder,$regex;
  123. $NameLine{$name} = $INPUT_LINE_NUMBER;
  124. $RecognizerLine{$regex} = $INPUT_LINE_NUMBER;
  125. $Name{$regex} = $name;
  126. $Recognizer{$name} = $regex;
  127. $Class{$regex} = $class;
  128. $Supported{$regex} = $supported ? "supported" : "unsupported";
  129. }
  130. }
  131. close GPUS;
  132. print STDERR "\n" if $ErrorsSeen;
  133. exit $ErrorsSeen if $TableOnly;
  134. # Loop over input lines, find the results for each
  135. my %RecognizedBy;
  136. while (<>)
  137. {
  138. chomp;
  139. my $lcInput = lc $_; # the real gpu table parser lowercases the input string
  140. my $recognizer;
  141. $RecognizedBy{$_} = $NoMatch;
  142. foreach $recognizer ( @InOrder ) # note early exit if recognized
  143. {
  144. my $lcRecognizer = lc $recognizer; # the real gpu table parser lowercases the recognizer
  145. if ( $lcInput =~ m/$lcRecognizer/ )
  146. {
  147. $RecognizedBy{$_} = $recognizer;
  148. last; # exit recognizer loop
  149. }
  150. }
  151. }
  152. format STDOUT_TOP =
  153. GPU String Supported? Class Recognizer
  154. ------------------------------------------------------------------------------------------------------ ----------- ----- ------------------------------------
  155. .
  156. format STDOUT =
  157. @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... @<<<<<<<<<< @> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<...
  158. $_, $Supported{$RecognizedBy{$_}},$Class{$RecognizedBy{$_}},$Name{$RecognizedBy{$_}}
  159. .
  160. my $ReportLineTemplate = "A102xxxA12xxxAA*"; # MUST match the format STDOUT above
  161. format DIFF_TOP =
  162. ------ OLD ------ ------ NEW ------
  163. GPU String Supported? Class Supported? Class
  164. ------------------------------------------------------------------------------------------------------ ----------- ----- ----------- -----
  165. .
  166. my ( $oldSupported, $oldClass, $newSupported, $newClass );
  167. format DIFF =
  168. @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... @<<<<<<<<<< @> @<<<<<<<<<< @>
  169. $_, $oldSupported, $oldClass, $newSupported, $newClass
  170. .
  171. if ( ! $Diff )
  172. {
  173. ## Print results.
  174. ## For each input, show supported or unsupported, the class, and the recognizer name
  175. foreach ( sort keys %RecognizedBy )
  176. {
  177. write if ! $UnMatchedOnly || $Name{$RecognizedBy{$_}} eq $NoMatch;
  178. $-++; # suppresses pagination
  179. }
  180. }
  181. else
  182. {
  183. open OLD, "<$Diff"
  184. || die "Failed to open --diff file '$Diff'\n\t$!\n";
  185. my $discard = 2;
  186. while ( <OLD> )
  187. {
  188. if ( $discard > 0 )
  189. {
  190. my ( $gpu, $supported, $class ) = unpack $ReportLineTemplate;
  191. $gpu =~ s/\s*$//;
  192. ( $OldSupported{$gpu} = $supported ) =~ s/\s*$//;
  193. ( $OldClass{$gpu} = $class ) =~ s/\s*$//;
  194. }
  195. else
  196. {
  197. $discard--;
  198. }
  199. }
  200. close OLD;
  201. $FORMAT_TOP_NAME = DIFF_TOP;
  202. $FORMAT_NAME = DIFF;
  203. foreach ( sort keys %RecognizedBy )
  204. {
  205. $newSupported = $Supported{$RecognizedBy{$_}} || $NoMatch;
  206. $newClass = $Class{$RecognizedBy{$_}};
  207. if ( ! defined $OldSupported{$_} )
  208. {
  209. $oldSupported = 'NEW';
  210. $oldClass = '-';
  211. }
  212. else
  213. {
  214. $oldSupported = $OldSupported{$_} || $NoMatch;
  215. $oldClass = $OldClass{$_};
  216. if ( ( $oldSupported eq $newSupported )
  217. && ( $oldClass eq $newClass )
  218. )
  219. {
  220. $newSupported = '';
  221. $newClass = '';
  222. }
  223. }
  224. write;
  225. $-++; # suppresses pagination
  226. }
  227. }
  228. exit $ErrorsSeen;