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.

137 lines
2.5 KiB

  1. #! perl
  2. use File::Find;
  3. use Cwd;
  4. use File::Basename;
  5. use Getopt::Long;
  6. $last_errors="";
  7. $nosync = 0;
  8. $mail = 0;
  9. $daemon = 0;
  10. $mailto="cgreen";
  11. $mailfrom="autotest";
  12. $ignoremutex = 0;
  13. $result = GetOptions(
  14. "nosync" => \$nosync,
  15. "daemon" => \$daemon,
  16. "mailto:s" => \$mailto,
  17. "mailfrom:s" => \$mailfrom,
  18. "ignoremutex" => \$ignoremutex,
  19. "mail" => \$mail );
  20. $iter = 0;
  21. while( 1 )
  22. {
  23. my $hasChange = 1;
  24. my $mutex_held = 0;
  25. unless($nosync)
  26. {
  27. # check for mutex held
  28. unless( $ignoremutex || $nosync )
  29. {
  30. open(MUTEX,"p4 counters|") || die "cant' run p4";
  31. while(<MUTEX>)
  32. {
  33. $mutex_held = 1 if ( /main_src_lock_\S+\s*=\s*1/);
  34. }
  35. close MUTEX;
  36. }
  37. unless( $mutex_held )
  38. {
  39. print STDERR "Syncing...\n";
  40. system "p4 sync > sync.txt 2>&1";
  41. open SYNC, "<sync.txt";
  42. while( <SYNC> )
  43. {
  44. if( m/File\(s\) up-to-date/ )
  45. {
  46. $hasChange = 0;
  47. }
  48. print;
  49. }
  50. close SYNC;
  51. }
  52. }
  53. if ( $mutex_held )
  54. {
  55. print STDERR "mutex held, waiting\n";
  56. }
  57. else
  58. {
  59. if( $hasChange || ($iter == 0 ) )
  60. {
  61. print "Running tests\n";
  62. &RunUnitTests;
  63. }
  64. else
  65. {
  66. print "no changes\n";
  67. }
  68. $iter++;
  69. last unless ($daemon);
  70. }
  71. sleep 30;
  72. }
  73. sub RunUnitTests
  74. {
  75. $error_output ="";
  76. find(\&Visitfile,".");
  77. if ( length($error_output ) )
  78. {
  79. print STDERR "errors detected\n";
  80. open CHANGES, "p4 changes -m 10 -s submitted //ValveGames/main/src/...|";
  81. my @changes = <CHANGES>;
  82. close CHANGES;
  83. if ( $mail && ($error_output ne $last_errors ) )
  84. {
  85. use Net::SMTP;
  86. $smtp = Net::SMTP->new('exchange2.valvesoftware.com');
  87. $smtp->mail($mailfrom);
  88. $smtp->to($mailto);
  89. $smtp->data();
  90. $smtp->datasend("To: $mailto\n");
  91. $smtp->datasend("Subject: Errors from Unit tests\n");
  92. $smtp->datasend($error_output);
  93. $smtp->datasend("-" x 75);
  94. $smtp->datasend("\nLAST 10 SUBMITS TO MAIN:\n");
  95. $smtp->datasend(join("",@changes ) );
  96. $smtp->dataend();
  97. $smtp->quit;
  98. }
  99. }
  100. $last_errors = $error_output;
  101. }
  102. sub Visitfile
  103. {
  104. local($_)= $File::Find::name;
  105. next unless( -e "test_error_reporting.pl" );
  106. if (/\.(pl|exe|bat)$/i)
  107. {
  108. unlink("errors.txt");
  109. my $extension=$1;
  110. $extension=~tr/A-Z/a-z/;
  111. my $cmd;
  112. $cmd="perl $_" if ( $extension eq "pl");
  113. $cmd="$_" if ( $extension eq "exe");
  114. $cmd="$_" if ( $extension eq "bat");
  115. print STDERR "run $cmd: ",`$cmd`,"\n";
  116. if (open(ERRIN,"errors.txt" ) )
  117. {
  118. local($/);
  119. print STDERR "errors found!\n";
  120. $error_output.="* Failed test: $cmd: ".<ERRIN>."\n";
  121. close ERRIN;
  122. }
  123. }
  124. }