Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
4.5 KiB

  1. #!perl
  2. # read stdio_test_list.cfg and perform all tests
  3. $create_refs=0;
  4. $subset_string=shift;
  5. @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
  6. @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
  7. ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
  8. $year = 1900 + $yearOffset;
  9. $dstamp = "$weekDays[$dayOfWeek] $months[$month] $dayOfMonth $year".sprintf(" %02d:%02d:%02d", $hour,$minute,$second);
  10. $changelist_counter=`p4 counter main_changelist`; # grab value of p4 counter
  11. $dstamp.=" $changelist_counter";
  12. $dstamp=~ s/[\n\r]//g;
  13. $computername=$ENV{'COMPUTERNAME'};
  14. # first, set our priority to high and affinity to 1 to try to get more repeatable benchmark results
  15. #my $pid = $$;
  16. #my $cmd="datafiles\\process.exe -p $pid High";
  17. #print STDERR `$cmd`;
  18. #$cmd="datafiles\\process.exe -a $pid 01";
  19. #print STDERR `$cmd`;
  20. if ( open(CFGFILE, "filecompare_tests.cfg") )
  21. {
  22. while(<CFGFILE>)
  23. {
  24. s/[\n\r]//g;
  25. s@//.*$@@; # kill comments
  26. if (/^([^,]*),([^,]*),(.*$)/)
  27. {
  28. $testname=$1;
  29. $testfile=$2;
  30. $testcommand=$3;
  31. next if ( length($subset_string) && ( ! ( $testname=~/$subset_string/i) ) );
  32. $ext=".txt";
  33. if ( length($testfile ) )
  34. {
  35. $ext="";
  36. $ext = $1 if ( $testfile=~/(\..*)$/ ); # copy extension
  37. unlink $testfile if ( -e $testfile); # kill it if it exists
  38. }
  39. print STDOUT "running $testname : $testcommand ($testfile)\n";
  40. # suck the reference output in. use binary mode unless stdio
  41. $refname="reference_output/$testname$ext";
  42. # run the test
  43. my $stime=time;
  44. $output=`$testcommand`;
  45. $stime=time-$stime;
  46. if ( open(REF,$refname))
  47. {
  48. if ( length($testfile ))
  49. {
  50. binmode REF;
  51. }
  52. $ref_output= do { local( $/ ) ; <REF> } ; # slurp comparison output in
  53. close REF;
  54. if ( length( $testfile ) )
  55. {
  56. print STDERR $output;
  57. # file case
  58. if ( open(TESTFILE, $testfile ))
  59. {
  60. binmode TESTFILE;
  61. $new_output= do { local( $/ ) ; <TESTFILE> } ; # slurp comparison output in
  62. close TESTFILE;
  63. if ($new_output ne $ref_output )
  64. {
  65. $errout.="ERROR: test $testname ($testcommand) : test produced file $testfile (length=".
  66. length($new_output).") but it doesn't match the reference (length=".length($ref_output).")\n";
  67. }
  68. else
  69. {
  70. &UpdateMetrics( $testname, $output, $stime );
  71. }
  72. }
  73. else
  74. {
  75. $errout.="ERROR: test $testname ($testcommand) : test was supposed to create $testfile, but didn't.\n";
  76. }
  77. }
  78. else
  79. {
  80. # strip metrics (like timing) for comparison
  81. my $massaged_ref = $ref_output;
  82. my $massaged_output = $output;
  83. $massaged_ref =~ s/:=\s*[0-9\.]+//g;
  84. $massaged_output =~ s/:=\s*[0-9\.]+//g;
  85. if ($massaged_output ne $massaged_ref )
  86. {
  87. # print STDERR "o=$massaged_output r=$massaged_ref\n";
  88. $errout.="ERROR: test $testname ($testcommand) : output does not match reference output.\n";
  89. }
  90. else
  91. {
  92. &UpdateMetrics( $testname, $output, $stime );
  93. }
  94. }
  95. }
  96. else
  97. {
  98. $errout.="ERROR: Can't open reference $refname for $testname\n";
  99. if ($create_refs)
  100. {
  101. if ( length($testfile ) )
  102. {
  103. if ( -e $testfile )
  104. {
  105. $oname=$refname;
  106. $oname=~s@/@\\@g;
  107. print STDERR "copy $testfile $oname";
  108. print STDERR `copy $testfile $oname`;
  109. print STDERR `p4 add $oname`;
  110. }
  111. }
  112. else
  113. {
  114. if ( open(REFOUT,">$refname") )
  115. {
  116. print REFOUT $output;
  117. }
  118. close REFOUT;
  119. print STDERR `p4 add $refname`;
  120. }
  121. }
  122. }
  123. }
  124. }
  125. }
  126. else
  127. {
  128. $errout.="Can't open stdio_test_list.cfg\n";
  129. }
  130. if (length($errout))
  131. {
  132. print STDERR "There were errors: $errout";
  133. open(ERRORS,">errors.txt") || die "huh - can't write";
  134. print ERRORS $errout;
  135. close ERRORS;
  136. }
  137. sub UpdateMetrics
  138. {
  139. return unless length($computername);
  140. local( $tname, $output, $runtime) = @_;
  141. $output .= "\ntest runtime := $runtime\n";
  142. foreach $_ ( split(/\n/,$output))
  143. {
  144. if (/^(.+):=(.*$)/)
  145. {
  146. my $varname=$1;
  147. my $etime=$2;
  148. $varname=~s@^\s*@@g;
  149. $varname=~s@\s*$@@g;
  150. mkdir "\\\\fileserver\\user\\perf\\$computername";
  151. mkdir "\\\\fileserver\\user\\perf\\$computername\\$tname";
  152. if ( open(COUT,">>\\\\fileserver\\user\\perf\\$computername\\$tname\\$varname.csv") )
  153. {
  154. print COUT "\"$dstamp\",$etime\n";
  155. close COUT;
  156. }
  157. }
  158. }
  159. }