2 # -*- Mode: Perl; tab-width: 4; indent-tabs-mode: nil; -*-
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
16 # The Original Code is Mozilla JavaScript Testing Utilities
18 # The Initial Developer of the Original Code is
19 # Mozilla Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 2007
21 # the Initial Developer. All Rights Reserved.
23 # Contributor(s): Bob Clary <bclary@bclary.com>
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK *****
39 use Getopt
::Mixed
"nextOption";
40 use File
::Temp qw
/ tempfile tempdir /;
49 my $debug = $ENV{DEBUG
};
50 my $test_dir = $ENV{TEST_DIR
};
52 die "FATAL ERROR: environment variable TEST_DIR must be set to the Sisyphus root directory" unless ($test_dir);
54 # required for mac os x 10.5 to prevent sort from
55 # complaining about illegal byte sequences
58 (undef, $temp) = tempfile
();
60 open TEMP
, ">$temp" or
61 die "FATAL ERROR: Unable to open temporary file $temp for writing: $!\n";
65 $tmp_test_exit_status,
77 @expected_exit_code_list,
82 local $test_memory = 0;
83 local $test_cpuspeed = 0;
84 local %test_reported = ();
85 local $test_repo = 'CVS';
87 while ($file = shift @ARGV)
93 my $filename = basename
$file;
95 dbg
"filename: $file";
97 local ($test_date, $test_product, $test_branchid, $test_buildtype,
99 $test_machine,$test_global_target) = split /,/, $filename;
101 $test_branchid =~ s/[^0-9.]//g;
102 $test_global_target =~ s/.log$//;
104 local ($test_timezone) = $test_date;
105 $test_timezone =~ s/.*([-+]\d{4,4})/$1/;
109 if ($file =~ /\.bz2$/)
111 $filemode = "bzcat $file|";
113 elsif ($file =~ /\.gz$/)
115 $filemode = "zcat $file|";
119 $filemode = "<$file";
122 open FILE
, "$filemode" or die "FATAL ERROR: unable to open $file for reading: $!\n";
124 dbg
"process header with environment variables used in test";
132 # remove carriage returns, bels and other annoyances.
135 $_ =~ s/[\x01-\x08]//g;
143 last if ( $_ =~ /^arguments:/);
145 if (($envval) = $_ =~ /^environment: TEST_MOZILLA_HG=http:\/\
/hg.mozilla.org\/(.*)/ )
147 $test_repo = $envval;
149 elsif (($envvar, $envval) = $_ =~ /^environment: (TEST_[A-Z0-9_]*)=(.*)/ )
151 dbg
"envvar=$envvar, envval=$envval";
152 if ($envvar =~ /TEST_KERNEL/)
154 $envval =~ s/([0-9]+)\.([0-9]+)\.([0-9]+).*/$1.$2.$3/;
155 dbg
"found TEST_KERNEL";
157 $envvar =~ tr/A-Z/a-z/;
159 dbg
$envvar . "=" . $$envvar;
161 elsif (($envval) = $_ =~ /^environment: OSID=(.*)/ )
167 if ($test_cpuspeed < 4)
169 $test_cpuspeed = 'slow';
171 elsif ($test_cpuspeed < 9)
173 $test_cpuspeed = 'medium';
177 $test_cpuspeed = 'fast';
180 if ($test_product eq "js")
182 $test_type = "shell";
184 elsif ($test_product eq "firefox" || $test_product eq "thunderbird" ||
185 $test_product eq "fennec")
187 $test_buildtype = "nightly" unless $test_buildtype;
188 $test_type = "browser";
191 # Expected sequence if all output written to the log.
194 # -----------------------------
195 # JavaScriptTest: Begin Run
196 # JavaScriptTest: Begin Test t;
199 # JavaScriptTest: End Test t
200 # JavaScriptTest: End Run
205 $test_exit_status = '';
219 $_ =~ s/[\x01-\x08]//g;
222 if ( /^JavaScriptTest: Begin Run/)
226 if ($state eq 'idle')
232 warn "WARNING: state: $state, expected: idle, log: $file";
236 elsif ( ($tmp_test_id) = $_ =~ /^JavaScriptTest: Begin Test ([^ ]*)/)
238 dbg
"Begin Test: $tmp_test_id";
240 if ($state eq 'beginrun' || $state eq 'endtest')
242 $state = 'runningtest';
246 warn "WARNING: state: $state, expected: beginrun, endtest, log: $file";
247 $state = 'runningtest';
250 $test_id{$state} = $tmp_test_id;
252 @expected_exit_code_list = ();
253 $expected_exit_code = ();
257 $test_exit_status = 'NORMAL'; # default to normal, so subtests will have a NORMAL status
258 $test_description = '';
260 push @expected_exit_code_list, (3) if ($tmp_test_id =~ /-n.js$/);
263 elsif ( ($expected_exit_code) = $_ =~ /WE EXPECT EXIT CODE ([0-9]*)/ )
265 dbg
"Expected Exit Code: $expected_exit_code";
267 push @expected_exit_code_list, ($expected_exit_code);
269 elsif ( ($tmp_test_id) = $_ =~ /^jstest: (.*?) *bug:/)
271 dbg
"jstest: $tmp_test_id";
273 # if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
275 # warn "WARNING: state: $state, expected runningtest, reportingtest. mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
278 if ($state eq 'runningtest')
280 $state = 'reportingtest';
282 elsif ($state eq 'reportingtest')
284 $state = 'reportingtest';
288 warn "WARNING: test_id: $test_id{$state}, state: $state, expected: runningtest, reportingtest, log: $file";
289 $state = 'reportingtest';
292 ($test_result) = $_ =~ /result: (.*?) *type:/;
293 ($tmp_test_type) = $_ =~ /type: (.*?) *description:/;
295 die "FATAL ERROR: test_id: $test_id{$state}, jstest test type mismatch: start test_type: $test_type, current test_type: $tmp_test_type, test state: $state, log: $file"
296 if ($test_type ne $tmp_test_type);
298 ($test_description) = $_ =~ /description: (.*)/;
300 if (!$test_description)
302 $test_description = "";
304 $test_description .= '; messages: ' . (join '; ', @messages) . ';';
306 outputrecord
$tmp_test_id, $test_description, $test_result;
308 $test_id{$state} = $tmp_test_id;
310 elsif ( $state ne 'idle' && (($tmp_test_id) = $_ =~ /^([^:]*):.* EXIT STATUS: NORMAL/))
312 $test_exit_status = 'NORMAL';
313 dbg
"Exit Status Normal: $tmp_test_id, $test_exit_status";
315 if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
317 warn "WARNING: state: $state, mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
320 if ($state eq 'reportingtest' || $state eq 'runningtest')
322 $state = 'exitedtest';
326 warn "WARNING: state: $state, expected: reportingtest, runningtest, log: $file";
327 $state = 'exitedtest';
330 if (! $test_reported{$tmp_test_id})
332 dbg
"No test results reported: $tmp_test_id";
334 $test_result = 'FAILED';
335 $test_description = 'No test results reported; messages: ' . (join '; ', @messages) . ';';
337 outputrecord
$tmp_test_id, $test_description, $test_result;
340 $test_id{$state} = $tmp_test_id;
342 elsif ( $state ne 'idle' && (($tmp_test_id) = $_ =~ /^([^:]*):.* EXIT STATUS: TIMED OUT/))
344 $test_exit_status = 'TIMED OUT';
345 dbg
"Exit Status Timed Out: $tmp_test_id, $test_exit_status";
347 if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
349 warn "WARNING: state: $state, mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
352 if ($state eq 'reportingtest' || $state eq 'runningtest')
354 $state = 'exitedtest';
358 dbg
"state: $state, expected: reportingtest, runningtest";
359 $state = 'exitedtest';
362 $test_result = 'FAILED';
363 $test_description .= '; messages: ' . (join '; ', @messages) . ';';
365 outputrecord
$tmp_test_id, $test_description, $test_result;
367 $test_id{$state} = $tmp_test_id;
369 elsif ( $state ne 'idle' && (($tmp_test_id, $tmp_test_exit_status) = $_ =~ /^([^:]*):.* EXIT STATUS: (CRASHED signal [0-9]+ [A-Z]+) \([0-9.]+ seconds\)/))
371 $test_exit_status = $tmp_test_exit_status;
372 dbg
"Exit Status Crashed: $tmp_test_id, $test_exit_status";
374 if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
376 warn "WARNING: state: $state, mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
379 if ($state eq 'reportingtest' || $state eq 'runningtest')
381 $state = 'exitedtest';
385 dbg
"state: $state, expected: reportingtest, runningtest";
386 $state = 'exitedtest';
389 $test_result = 'FAILED';
390 $test_description .= '; messages: ' . (join '; ', @messages) . ';';
392 outputrecord
$tmp_test_id, $test_description, $test_result;
394 $test_id{$state} = $tmp_test_id;
396 elsif ( $state ne 'idle' && (($tmp_test_id, $tmp_test_exit_status) = $_ =~ /^([^:]*):.* EXIT STATUS: (ABNORMAL [0-9]+) \([0-9.]+ seconds\)/))
398 $test_exit_status = $tmp_test_exit_status;
399 dbg
"Exit Status Abnormal: $tmp_test_id, $test_exit_status";
401 if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
403 warn "WARNING: state: $state, mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
406 if ($state eq 'reportingtest' || $state eq 'runningtest')
408 $state = 'exitedtest';
412 dbg
"state: $state, expected: reportingtest, runningtest";
413 $state = 'exitedtest';
416 ($exit_code) = $test_exit_status =~ /ABNORMAL ([0-9]+)/;
418 if (grep /$exit_code/, @expected_exit_code_list)
420 $test_result = 'PASSED';
424 $test_result = 'FAILED';
427 $test_description .= '; messages: ' . (join '; ', @messages) . ';';
429 dbg
"Exit Code: $exit_code, Test Result: $test_result, Expected Exit Codes: " . (join '; ', @expected_exit_code_list);
431 outputrecord
$tmp_test_id, $test_description, $test_result;
433 $test_id{$state} = $tmp_test_id;
435 elsif ( ($tmp_test_id) = $_ =~ /^JavaScriptTest: End Test ([^ ]*)/)
437 dbg
"End Test: $tmp_test_id";
439 if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
441 warn "WARNING: state: $state, mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
444 if ($state eq 'exitedtest' || $state eq 'runningtest' || $state eq 'reportingtest')
450 warn "WARNING: state: $state, expected: runningtest, reportingtest, exitedtest, log: $file";
454 $test_id{$state} = $tmp_test_id;
456 elsif ( /^JavaScriptTest: End Run/)
460 if ($state eq 'endtest')
466 warn "WARNING: state: $state, expected: endtest, log: $file";
472 !/^(STATUS:| *PASSED!| *FAILED!)/ &&
473 !/^JavaScriptTest:/ &&
475 !/^[-+]{2,2}(WEBSHELL|DOMWINDOW)/ &&
477 !/real.*user.*sys.*$/ &&
478 !/user.*system.*elapsed/)
480 if ('runningtest, reportingtest' =~ /$state/)
483 if (/error: can.t allocate region/ || /set a breakpoint in malloc_error_break/ ||
484 /set a breakpoint in szone_error to debug/ || /malloc:.*mmap/ || /vm_allocate/ ||
485 /terminate called after throwing an instance of .*bad_alloc/)
487 dbg
"Adding message: $_ converted to /$test_id{$state}:0: out of memory";
488 push @messages, ('/' . $test_id{$state} . ':0: out of memory');
490 elsif (/\.js, line [0-9]+: out of memory/ )
492 s/\.js, line ([0-9]+): out of memory/\.js:$1:/;
493 dbg
"Adding message: $_ converted to /$test_id{$state}:0: out of memory";
494 push @messages, ('/' . $test_id{$state} . ':0: out of memory');
498 dbg
"Adding message: $_";
499 push @messages, ($_);
510 if ($test_id{$state})
512 dbg
"test_id{$state}=$test_id{$state}, " . (join '; ', @messages);
516 dbg
"state=$state, " . (join '; ', @messages);
520 if ($state eq 'endrun')
524 die "FATAL ERROR: Test run terminated prematurely. state: $state, log: $file" if ($state ne 'success');
530 undef $test_branchid;
532 undef $test_buildtype;
545 print STDERR
"DEBUG: $msg\n";
551 dbg
"sorting temp file $temp";
552 system("sort -u < $temp");
553 dbg
"finished sorting";
558 my ($test_id, $test_description, $test_result) = @_;
560 # cut off the extra jstest: summaries as they duplicate the other
561 # output and follow it.
562 $test_description =~ s/jstest:.*//;
564 # if (length($test_description) > 6000)
566 # $test_description = substr($test_description, 0, 6000);
571 "TEST_ID=$test_id, " .
572 "TEST_BRANCH=$test_branchid, " .
573 "TEST_REPO=$test_repo, " .
574 "TEST_BUILDTYPE=$test_buildtype, " .
575 "TEST_TYPE=$test_type, " .
576 "TEST_OS=$test_os, " .
577 "TEST_KERNEL=$test_kernel, " .
578 "TEST_PROCESSORTYPE=$test_processortype, " .
579 "TEST_MEMORY=$test_memory, " .
580 "TEST_CPUSPEED=$test_cpuspeed, " .
581 "TEST_TIMEZONE=$test_timezone, " .
582 "TEST_RESULT=$test_result, " .
583 "TEST_EXITSTATUS=$test_exit_status, " .
584 "TEST_DESCRIPTION=$test_description, " .
585 "TEST_MACHINE=$test_machine, " .
586 "TEST_DATE=$test_date" .
591 dbg
"RECORD: $output";
595 $test_reported{$test_id} = 1;