summaryrefslogtreecommitdiff
path: root/bin/run_all.pl
blob: 950b61d0e2cff91ad46f2a26a027b4e9cfccc0fe (plain)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# -*- perl -*-
# $Id$
#
# This script execute the test programs (usually, other scripts) in
# the RUN_LIST defined below. If it detects any problem it send email.
#
# This script requires ActivePerl for Win32 and libnet from CPAN.
#
# Usage:  run_all.pl <log directory> <admin email address>
#
#     For example: run_all.pl /tmp/log peter_pan@neverland.org

use Net::SMTP;
use File::Basename;
use FileHandle;
require POSIX;

push @INC, $ENV{'ACE_ROOT'}.'/bin';
require run_all_list;

# Find out the command name.
$CMD = basename($0);

$single_threaded = 0;
$minimum_corba = 0;
$dont_run = 0;
$report_success = 0;
$debug = 0;

@ARGS = ();
while ($#ARGV >= 0) {
  if (!($ARGV[0] =~ m/-/)) {
    push @ARGS, $ARGV[0];
    shift;
  } elsif ($ARGV[0] eq "-single_threaded") {
    $single_threaded = 1;
    shift;
  } elsif ($ARGV[0] eq "-minimum_corba") {
    $minimum_corba = 1;
    shift;
  } elsif ($ARGV[0] eq "-report_success") {
    $report_success = 1;
    shift;
  } elsif ($ARGV[0] eq "-debug") {
    $debug = 1;
    shift;
  }
}

# We obtain our revision to report errors.
$REVISION='$Revision$ ';

# Extract configuration information from command line.
  # TODO: Some validation and checking should be done here.
$LOGDIR   = $ARGS[0];
$ADMIN    = $ARGS[1];
$MAIL = "mail";
if ($#ARGS >= 2) {
  $MAIL     = $ARGS[2];
}

$disable_file = $LOGDIR . '/.disable';
$histfile = $LOGDIR . '/history';
$LOGBASE = POSIX::strftime("%b%d_%Y.log", localtime);
$LOGFILE = $LOGDIR . '/' . $LOGBASE;
$HOST = `hostname`;
chop $HOST;
$LOG_NAME =  $HOST . "_" . $BUILD . "_" . $LOGBASE;
$STATUS = "OK";

sub report_errors {
  # Now send a summary of the errors to the ADMIN account...
  local $to = $ADMIN;

  open (MAIL, "|".$MAIL.' -s [AUTO_COMPILE] '.$to)
    || die "Cannot open mail pipe for: $_\n";

  print MAIL 'The following message is brought to you by: ', "\n";
  print MAIL $CMD, ' [', $REVISION, "] for $BUILD on $CHECKOUT\n";

  local $m;
  foreach $m (@_) {
    print MAIL $m, "\n";
  }

  print MAIL "\nPlease check the following log for more info:\n\n";
  print MAIL 'http://www.cs.wustl.edu/~bugzilla/auto_compile_logs/',
             $LOG_NAME, "\n\n";

  close (MAIL); # Ignore errors....

#  # Now send the complete log to bugzilla...
#  local $bugs = 'bugzilla'.'@cs.wustl.edu';
#  open (MAIL, "|".$MAIL.' -s AUTO_COMPILE_LOG='.$LOG_NAME.' '.$bugs)
#    || die "Cannot open mail pipe for: $LOG_NAME\n";

#  print MAIL 'This is the log for: ', "\n";
#  print MAIL $CMD, ' [', $REVISION, "] for $BUILD on $CHECKOUT\n";

#  print MAIL "\n================================================================\n";

# if (open (THELOG, "$LOGFILE"))
#    {
#      while (<THELOG>) {
#	print MAIL $_;
#      }
#      close (THELOG);
#    }
#  close (MAIL); # Ignore errors....
}
 
### MAIN FUNCTION

$histfile = $LOGDIR . '/history';
open(HIST, '>>' . $histfile)
    # Do not use 'die' to report the problem, it tries to use HIST....
    || die "cannot open history file \"$histfile\"\n";

$date = localtime;

print HIST $CMD, ': running at ', $date, ' ';

if (-f $disable_file) {
    print HIST "DISABLED\n";
    exit 0;
}

open (DISABLE, '>' . $disable_file)
    || die "cannot open disable file";
print DISABLE "auto_compile <$date> is running\n";
close (DISABLE)
    || die "cannot close disable file";

$LOGFILE = $LOGDIR . '/' . POSIX::strftime("%b%d_%Y.log", localtime);
open(LOG, '>' . $LOGFILE)
    || die "cannot open log file";

LOG->autoflush ();

@failures = ();

if ($dont_run == 0) {
  @LIST = @RUN_LIST;
  if ($single_threaded) {
    @LIST = @SINGLE_THREADED_LIST;
  } elsif ($minimum_corba) {
    @LIST = @MINIMUM_CORBA_LIST;
  }

  $DIR = $ENV{'PWD'};
  foreach $i (@LIST) {
    local @test_info = split (/\ \,\ /, $i);
    local $directory = $test_info[0];
    local $program = $test_info[1];

    $date = localtime;
    print LOG "$CMD: =============================================\n";
    print LOG "$CMD: running $program in $directory at ", $date, "\n";
    local $subdir = $DIR . '/' . $directory;
    chdir ($subdir)
	|| die "cannot chdir to $subdir";

    $run_error = 0;
    if (open(RUN, "perl $program 2>&1 |") == 0) {
	push @failures, "cannot run $program in $directory";
	next;
    }
    while (<RUN>) {
	print LOG $_;
	if (m/Error/
	    || m/FAILED/
	    || m/EXCEPTION/
	    || m/pure virtual /i) {
	  if ($STATUS eq "OK") {
	    $STATUS = "RUNTIME ERROR";
	  }
	  $run_error = 1;
	}
    }
    if (close(RUN) == 0) {
      if ($STATUS eq "OK") {
	$STATUS = "RUNTIME ERROR";
      }
      push @failures, "Error when closing pipe for $program in $directory";
      next;
    }
    $date = localtime;
    print LOG "$CMD: $program finished ", $date, "\n";

    if ($run_error != 0) {
      push @failures,
      "errors detected while running $program in $directory";
    }
  }
}

if ($#failures >= 0) {
  report_errors @failures;
}

close(LOG)
    || die "cannot close LOGFILE";

print HIST "$STATUS\n";
close(HIST)
    || die "cannot close history file";

unlink $disable_file
    || die "cannot unlink disable file";

if ($report_success) {
  report_errors "Congratulations: No errors or warnings detected\n";
}

exit 0;