1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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;
}
}
}
|