Debian Codegraph @

rhino/testsrc/tests/post-process-logs.pl

raw
1 #!/usr/bin/perl -w
2 # -*- Mode: Perl; tab-width: 4; indent-tabs-mode: nil; -*-
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 use Getopt::Mixed "nextOption";
8 use File::Temp qw/ tempfile tempdir /;
9 use File::Basename;
10
11 sub dbg;
12 sub outresults;
13 sub outputrecord;
14
15 local $file;
16 local $temp;
17 my $debug = $ENV{DEBUG};
18 my $test_dir = $ENV{TEST_DIR};
19
20 die "FATAL ERROR: environment variable TEST_DIR must be set to the Sisyphus root directory" unless ($test_dir);
21
22 # required for mac os x 10.5 to prevent sort from
23 # complaining about illegal byte sequences
24 $ENV{LC_ALL} = 'C';
25
26 (undef, $temp) = tempfile();
27
28 open TEMP, ">$temp" or
29 die "FATAL ERROR: Unable to open temporary file $temp for writing: $!\n";
30
31 local ($test_id,
32 $tmp_test_id,
33 $tmp_test_exit_status,
34 %test_id,
35 %test_reported,
36 $test_result,
37 $test_type,
38 $tmp_test_type,
39 $test_description,
40 $test_jsoptions,
41 @messages,
42 $test_processortype,
43 $test_kernel,
44 $test_suite,
45 $test_exit_status,
46 @expected_exit_code_list,
47 $expected_exit_code,
48 $exit_code,
49 $state);
50
51 local $test_memory = 0;
52 local %test_reported = ();
53 local $test_repo = 'CVS';
54
55 $test_jsoptions = 'none';
56
57 while ($file = shift @ARGV)
58 {
59 @messages = ();
60
61 dbg "file: $file";
62
63 my $filename = basename $file;
64
65 dbg "filename: $file";
66
67 local ($test_date, $test_product, $test_branchid, $test_buildtype,
68 $test_os,
69 $test_machine,$test_global_target) = split /,/, $filename;
70
71 $test_branchid =~ s/[^0-9.]//g;
72 $test_global_target =~ s/.log$//;
73
74 local ($test_timezone) = $test_date;
75 $test_timezone =~ s/.*([-+]\d{4,4})/$1/;
76
77 my $filemode;
78
79 if ($file =~ /\.bz2$/)
80 {
81 $filemode = "bzcat $file|";
82 }
83 elsif ($file =~ /\.gz$/)
84 {
85 $filemode = "zcat $file|";
86 }
87 else
88 {
89 $filemode = "<$file";
90 }
91
92 open FILE, "$filemode" or die "FATAL ERROR: unable to open $file for reading: $!\n";
93
94 dbg "process header with environment variables used in test";
95
96 while (<FILE>)
97 {
98 $state = 'failure';
99
100 chomp;
101
102 # remove carriage returns, bels and other annoyances.
103 $_ =~ s/[\r]$//;
104 $_ =~ s/[\r]/CR/g;
105 $_ =~ s/[\x01-\x08]//g;
106 $_ =~ s/\s+$//;
107
108 if ($debug)
109 {
110 dbg "\nINPUT: $_";
111 }
112
113 last if ( $_ =~ /^include:/);
114
115 if (($envval) = $_ =~ /^environment: TEST_MOZILLA_HG=http:\/\/hg.mozilla.org.*\/([^\/]+)/ )
116 {
117 $test_repo = $envval;
118 }
119 elsif (($envvar, $envval) = $_ =~ /^environment: (TEST_[A-Z0-9_]*)=(.*)/ )
120 {
121 dbg "envvar=$envvar, envval=$envval";
122 if ($envvar =~ /TEST_KERNEL/)
123 {
124 $envval =~ s/([0-9]+)\.([0-9]+)\.([0-9]+).*/$1.$2.$3/;
125 dbg "found TEST_KERNEL";
126 }
127 $envvar =~ tr/A-Z/a-z/;
128 $$envvar = $envval;
129 dbg $envvar . "=" . $$envvar;
130 }
131 elsif (($envval) = $_ =~ /^environment: OSID=(.*)/ )
132 {
133 $test_os = $envval;
134 }
135
136 if ($_ =~ /^arguments: javascriptoptions/)
137 {
138 my ($o, @s, $j);
139
140 ($o) = $_ =~ /^arguments: javascriptoptions=(.*)/;
141 $o =~ s/(-\w) (\w)/$1$2/g;
142 @s = sort split / /, $o;
143 $j = join(" ", @s);
144 $j =~ s/(-\w)(\w)/$1 $2/g;
145
146 $test_jsoptions = $j || "none";
147 dbg "javascriptoptions: $test_jsoptions";
148 }
149 }
150
151 if ($test_product eq "js")
152 {
153 $test_type = "shell";
154 }
155 elsif ($test_product eq "firefox" || $test_product eq "thunderbird" ||
156 $test_product eq "fennec")
157 {
158 $test_buildtype = "nightly" unless $test_buildtype;
159 $test_type = "browser";
160 }
161
162 # Expected sequence if all output written to the log.
163 #
164 # Input
165 # -----------------------------
166 # JavaScriptTest: Begin Run
167 # JavaScriptTest: Begin Test t;
168 # jstest: t
169 # t:.*EXIT STATUS:
170 # JavaScriptTest: End Test t
171 # JavaScriptTest: End Run
172 # EOF
173 #
174 %test_id = ();
175 @messages = ();
176 $test_exit_status = '';
177 $state = 'idle';
178
179 while (<FILE>)
180 {
181 chomp;
182
183 if ($debug)
184 {
185 dbg "\nINPUT: '$_'";
186 }
187
188 $_ =~ s/[\r]$//;
189 $_ =~ s/[\r]/CR/g;
190 $_ =~ s/[\x01-\x08]//g;
191 $_ =~ s/\s+$//;
192
193 if ( /^JavaScriptTest: Begin Run/)
194 {
195 dbg "Begin Run";
196
197 if ($state eq 'idle')
198 {
199 $state = 'beginrun';
200 }
201 else
202 {
203 warn "WARNING: state: $state, expected: idle, log: $file";
204 $state = 'beginrun';
205 }
206 }
207 elsif ( ($tmp_test_id) = $_ =~ /^JavaScriptTest: Begin Test ([^ ]*)/)
208 {
209 dbg "Begin Test: $tmp_test_id";
210
211 if ($state eq 'beginrun' || $state eq 'endtest')
212 {
213 $state = 'runningtest';
214 }
215 else
216 {
217 warn "WARNING: state: $state, expected: beginrun, endtest, log: $file";
218 $state = 'runningtest';
219 }
220
221 $test_id{$state} = $tmp_test_id;
222 @messages = ();
223 @expected_exit_code_list = ();
224 $expected_exit_code = ();
225
226 $test_id = '';
227 $test_result = '';
228 $test_exit_status = 'NORMAL'; # default to normal, so subtests will have a NORMAL status
229 $test_description = '';
230
231 push @expected_exit_code_list, (3) if ($tmp_test_id =~ /-n.js$/);
232
233 }
234 elsif ( ($expected_exit_code) = $_ =~ /WE EXPECT EXIT CODE ([0-9]*)/ )
235 {
236 dbg "Expected Exit Code: $expected_exit_code";
237
238 push @expected_exit_code_list, ($expected_exit_code);
239 }
240 elsif ( ($tmp_test_id) = $_ =~ /^jstest: (.*?) *bug:/)
241 {
242 dbg "jstest: $tmp_test_id";
243
244 # if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
245 # {
246 # warn "WARNING: state: $state, expected runningtest, reportingtest. mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
247 # }
248
249 if ($state eq 'runningtest')
250 {
251 $state = 'reportingtest';
252 }
253 elsif ($state eq 'reportingtest')
254 {
255 $state = 'reportingtest';
256 }
257 else
258 {
259 warn "WARNING: test_id: $test_id{$state}, state: $state, expected: runningtest, reportingtest, log: $file";
260 $state = 'reportingtest';
261 }
262
263 ($test_result) = $_ =~ /result: (.*?) *type:/;
264 ($tmp_test_type) = $_ =~ /type: (.*?) *description:/;
265
266 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"
267 if ($test_type ne $tmp_test_type);
268
269 ($test_description) = $_ =~ /description: (.*)/;
270
271 if (!$test_description)
272 {
273 $test_description = "";
274 }
275 $test_description .= '; messages: ' . (join '; ', @messages) . ';';
276
277 outputrecord $tmp_test_id, $test_description, $test_result;
278
279 $test_id{$state} = $tmp_test_id;
280 }
281 elsif ( $state ne 'idle' && (($tmp_test_id) = $_ =~ /^([^:]*):.* EXIT STATUS: NORMAL/))
282 {
283 $test_exit_status = 'NORMAL';
284 dbg "Exit Status Normal: $tmp_test_id, $test_exit_status";
285
286 if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
287 {
288 warn "WARNING: state: $state, mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
289 }
290
291 if ($state eq 'reportingtest' || $state eq 'runningtest')
292 {
293 $state = 'exitedtest';
294 }
295 else
296 {
297 warn "WARNING: state: $state, expected: reportingtest, runningtest, log: $file";
298 $state = 'exitedtest';
299 }
300
301 if (! $test_reported{$tmp_test_id})
302 {
303 dbg "No test results reported: $tmp_test_id";
304
305 $test_result = 'FAILED';
306 $test_description = 'No test results reported; messages: ' . (join '; ', @messages) . ';';
307
308 outputrecord $tmp_test_id, $test_description, $test_result;
309 }
310
311 $test_id{$state} = $tmp_test_id;
312 }
313 elsif ( $state ne 'idle' && (($tmp_test_id) = $_ =~ /^([^:]*):.* EXIT STATUS: TIMED OUT/))
314 {
315 $test_exit_status = 'TIMED OUT';
316 dbg "Exit Status Timed Out: $tmp_test_id, $test_exit_status";
317
318 if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
319 {
320 warn "WARNING: state: $state, mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
321 }
322
323 if ($state eq 'reportingtest' || $state eq 'runningtest')
324 {
325 $state = 'exitedtest';
326 }
327 else
328 {
329 dbg "state: $state, expected: reportingtest, runningtest";
330 $state = 'exitedtest';
331 }
332
333 $test_result = 'FAILED';
334 $test_description .= '; messages: ' . (join '; ', @messages) . ';';
335
336 outputrecord $tmp_test_id, $test_description, $test_result;
337
338 $test_id{$state} = $tmp_test_id;
339 }
340 elsif ( $state ne 'idle' && (($tmp_test_id, $tmp_test_exit_status) = $_ =~ /^([^:]*):.* EXIT STATUS: (CRASHED signal [0-9]+ [A-Z]+) \([0-9.]+ seconds\)/))
341 {
342 $test_exit_status = $tmp_test_exit_status;
343 dbg "Exit Status Crashed: $tmp_test_id, $test_exit_status";
344
345 if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
346 {
347 warn "WARNING: state: $state, mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
348 }
349
350 if ($state eq 'reportingtest' || $state eq 'runningtest')
351 {
352 $state = 'exitedtest';
353 }
354 else
355 {
356 dbg "state: $state, expected: reportingtest, runningtest";
357 $state = 'exitedtest';
358 }
359
360 $test_result = 'FAILED';
361 $test_description .= '; messages: ' . (join '; ', @messages) . ';';
362
363 outputrecord $tmp_test_id, $test_description, $test_result;
364
365 $test_id{$state} = $tmp_test_id;
366 }
367 elsif ( $state ne 'idle' && (($tmp_test_id, $tmp_test_exit_status) = $_ =~ /^([^:]*):.* EXIT STATUS: (ABNORMAL [0-9]+) \([0-9.]+ seconds\)/))
368 {
369 $test_exit_status = $tmp_test_exit_status;
370 dbg "Exit Status Abnormal: $tmp_test_id, $test_exit_status";
371
372 if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
373 {
374 warn "WARNING: state: $state, mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
375 }
376
377 if ($state eq 'reportingtest' || $state eq 'runningtest')
378 {
379 $state = 'exitedtest';
380 }
381 else
382 {
383 dbg "state: $state, expected: reportingtest, runningtest";
384 $state = 'exitedtest';
385 }
386
387 ($exit_code) = $test_exit_status =~ /ABNORMAL ([0-9]+)/;
388
389 if (grep /$exit_code/, @expected_exit_code_list)
390 {
391 $test_result = 'PASSED';
392 }
393 else
394 {
395 $test_result = 'FAILED';
396 }
397
398 $test_description .= '; messages: ' . (join '; ', @messages) . ';';
399
400 dbg "Exit Code: $exit_code, Test Result: $test_result, Expected Exit Codes: " . (join '; ', @expected_exit_code_list);
401
402 outputrecord $tmp_test_id, $test_description, $test_result;
403
404 $test_id{$state} = $tmp_test_id;
405 }
406 elsif ( ($tmp_test_id) = $_ =~ /^JavaScriptTest: End Test ([^ ]*)/)
407 {
408 dbg "End Test: $tmp_test_id";
409
410 if ($test_id{$state} && $tmp_test_id ne $test_id{$state})
411 {
412 warn "WARNING: state: $state, mismatched test_id: expected: $tmp_test_id, actual: $test_id{$state}, log: $file";
413 }
414
415 if ($state eq 'exitedtest' || $state eq 'runningtest' || $state eq 'reportingtest')
416 {
417 $state = 'endtest';
418 }
419 else
420 {
421 warn "WARNING: state: $state, expected: runningtest, reportingtest, exitedtest, log: $file";
422 $state = 'endtest';
423 }
424
425 $test_id{$state} = $tmp_test_id;
426 }
427 elsif ( /^JavaScriptTest: End Run/)
428 {
429 dbg "End Run";
430
431 if ($state eq 'endtest')
432 {
433 $state = 'endrun';
434 }
435 else
436 {
437 warn "WARNING: state: $state, expected: endtest, log: $file";
438 $state = 'endrun';
439 }
440 }
441 elsif ($_ &&
442 !/^\s+$/ &&
443 !/^(STATUS:| *PASSED!| *FAILED!)/ &&
444 !/^JavaScriptTest:/ &&
445 !/^[*][*][*]/ &&
446 !/^[-+]{2,2}(WEBSHELL|DOMWINDOW)/ &&
447 !/^Spider:/ &&
448 !/real.*user.*sys.*$/ &&
449 !/user.*system.*elapsed/)
450 {
451 if ('runningtest, reportingtest' =~ /$state/ && $#messages < 1000)
452 {
453 # limit the number of processed and collected messages since firefox can
454 # go berserk and dump a couple of million output lines for a single test
455 # if things go horribly wrong.
456 if (/error: can.t allocate region/ || /set a breakpoint in malloc_error_break/ ||
457 /set a breakpoint in szone_error to debug/ || /malloc:.*mmap/ || /vm_allocate/ ||
458 /terminate called after throwing an instance of .*bad_alloc/)
459 {
460 dbg "Adding message: $_ converted to /$test_id{$state}:0: out of memory";
461 push @messages, ('/' . $test_id{$state} . ':0: out of memory');
462 }
463 elsif (/\.js, line [0-9]+: out of memory/ )
464 {
465 s/\.js, line ([0-9]+): out of memory/\.js:$1:/;
466 dbg "Adding message: $_ converted to /$test_id{$state}:0: out of memory";
467 push @messages, ('/' . $test_id{$state} . ':0: out of memory');
468 }
469 else
470 {
471 dbg "Adding message: $_";
472 push @messages, ($_);
473 }
474 }
475 }
476 elsif ($debug)
477 {
478 dbg "Skipping: $_";
479 }
480
481 if ($debug)
482 {
483 if ($test_id{$state})
484 {
485 dbg "test_id{$state}=$test_id{$state}, " . (join '; ', @messages);
486 }
487 else
488 {
489 dbg "state=$state, " . (join '; ', @messages);
490 }
491 }
492 }
493 if ($state eq 'endrun')
494 {
495 $state = 'success';
496 }
497 die "FATAL ERROR: Test run terminated prematurely. state: $state, log: $file" if ($state ne 'success');
498
499 }
500 close FILE;
501 close TEMP;
502
503 undef $test_branchid;
504 undef $test_date;
505 undef $test_buildtype;
506 undef $test_machine;
507 undef $test_product;
508 undef $test_suite;
509
510 outresults;
511
512 unlink $temp;
513
514 sub dbg {
515 if ($debug)
516 {
517 my $msg = shift;
518 print STDERR "DEBUG: $msg\n";
519 }
520 }
521
522 sub outresults
523 {
524 dbg "sorting temp file $temp";
525 system("sort -u < $temp");
526 dbg "finished sorting";
527 }
528
529 sub outputrecord
530 {
531 my ($test_id, $test_description, $test_result) = @_;
532
533 # cut off the extra jstest: summaries as they duplicate the other
534 # output and follow it.
535 $test_description =~ s/jstest:.*//;
536
537 # if (length($test_description) > 6000)
538 # {
539 # $test_description = substr($test_description, 0, 6000);
540 # }
541 #
542
543 my $output =
544 "TEST_ID=$test_id, " .
545 "TEST_BRANCH=$test_branchid, " .
546 "TEST_REPO=$test_repo, " .
547 "TEST_BUILDTYPE=$test_buildtype, " .
548 "TEST_TYPE=$test_type, " .
549 "TEST_OS=$test_os, " .
550 "TEST_KERNEL=$test_kernel, " .
551 "TEST_PROCESSORTYPE=$test_processortype, " .
552 "TEST_MEMORY=$test_memory, " .
553 "TEST_TIMEZONE=$test_timezone, " .
554 "TEST_OPTIONS=$test_jsoptions, " .
555 "TEST_RESULT=$test_result, " .
556 "TEST_EXITSTATUS=$test_exit_status, " .
557 "TEST_DESCRIPTION=$test_description, " .
558 "TEST_MACHINE=$test_machine, " .
559 "TEST_DATE=$test_date" .
560 "\n";
561
562 if ($debug)
563 {
564 dbg "RECORD: $output";
565 }
566 print TEMP $output;
567
568 $test_reported{$test_id} = 1;
569 @messages = ();
570 }