summaryrefslogtreecommitdiff
path: root/devtools/bin/run_unit_tests.pl
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /devtools/bin/run_unit_tests.pl
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'devtools/bin/run_unit_tests.pl')
-rw-r--r--devtools/bin/run_unit_tests.pl137
1 files changed, 137 insertions, 0 deletions
diff --git a/devtools/bin/run_unit_tests.pl b/devtools/bin/run_unit_tests.pl
new file mode 100644
index 0000000..4b70292
--- /dev/null
+++ b/devtools/bin/run_unit_tests.pl
@@ -0,0 +1,137 @@
+#! perl
+
+use File::Find;
+use Cwd;
+use File::Basename;
+use Getopt::Long;
+
+
+
+$last_errors="";
+$nosync = 0;
+$mail = 0;
+$daemon = 0;
+$mailto="cgreen";
+$mailfrom="autotest";
+$ignoremutex = 0;
+
+$result = GetOptions(
+ "nosync" => \$nosync,
+ "daemon" => \$daemon,
+ "mailto:s" => \$mailto,
+ "mailfrom:s" => \$mailfrom,
+ "ignoremutex" => \$ignoremutex,
+ "mail" => \$mail );
+
+$iter = 0;
+while( 1 )
+{
+ my $hasChange = 1;
+ my $mutex_held = 0;
+ unless($nosync)
+ {
+ # check for mutex held
+ unless( $ignoremutex || $nosync )
+ {
+ open(MUTEX,"p4 counters|") || die "cant' run p4";
+ while(<MUTEX>)
+ {
+ $mutex_held = 1 if ( /main_src_lock_\S+\s*=\s*1/);
+ }
+ close MUTEX;
+ }
+ unless( $mutex_held )
+ {
+ print STDERR "Syncing...\n";
+ system "p4 sync > sync.txt 2>&1";
+ open SYNC, "<sync.txt";
+ while( <SYNC> )
+ {
+ if( m/File\(s\) up-to-date/ )
+ {
+ $hasChange = 0;
+ }
+ print;
+ }
+ close SYNC;
+ }
+ }
+ if ( $mutex_held )
+ {
+ print STDERR "mutex held, waiting\n";
+ }
+ else
+ {
+ if( $hasChange || ($iter == 0 ) )
+ {
+ print "Running tests\n";
+ &RunUnitTests;
+ }
+ else
+ {
+ print "no changes\n";
+ }
+ $iter++;
+ last unless ($daemon);
+ }
+ sleep 30;
+}
+
+
+
+sub RunUnitTests
+{
+ $error_output ="";
+ find(\&Visitfile,".");
+ if ( length($error_output ) )
+ {
+ print STDERR "errors detected\n";
+ open CHANGES, "p4 changes -m 10 -s submitted //ValveGames/main/src/...|";
+ my @changes = <CHANGES>;
+ close CHANGES;
+
+ if ( $mail && ($error_output ne $last_errors ) )
+ {
+ use Net::SMTP;
+
+ $smtp = Net::SMTP->new('exchange2.valvesoftware.com');
+ $smtp->mail($mailfrom);
+ $smtp->to($mailto);
+
+ $smtp->data();
+ $smtp->datasend("To: $mailto\n");
+ $smtp->datasend("Subject: Errors from Unit tests\n");
+ $smtp->datasend($error_output);
+ $smtp->datasend("-" x 75);
+ $smtp->datasend("\nLAST 10 SUBMITS TO MAIN:\n");
+ $smtp->datasend(join("",@changes ) );
+ $smtp->dataend();
+ $smtp->quit;
+ }
+ }
+ $last_errors = $error_output;
+}
+
+sub Visitfile
+ {
+ local($_)= $File::Find::name;
+ next unless( -e "test_error_reporting.pl" );
+ if (/\.(pl|exe|bat)$/i)
+ {
+ unlink("errors.txt");
+ my $extension=$1;
+ $extension=~tr/A-Z/a-z/;
+ my $cmd;
+ $cmd="perl $_" if ( $extension eq "pl");
+ $cmd="$_" if ( $extension eq "exe");
+ $cmd="$_" if ( $extension eq "bat");
+ print STDERR "run $cmd: ",`$cmd`,"\n";
+ if (open(ERRIN,"errors.txt" ) )
+ {
+ local($/);
+ print STDERR "errors found!\n";
+ $error_output.="* Failed test: $cmd: ".<ERRIN>."\n";
+ close ERRIN;
+ }
+ }
+}