Debian Codegraph @

rhino/testsrc/tests/jsDriver.pl

raw
1 #!/usr/bin/perl
2 # -*- Mode: Perl; tab-width: 4; indent-tabs-mode: nil; -*-
3 # vim: set ts=4 sw=4 et tw=80:
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8 # Second cut at runtests.pl script originally by
9 # Christine Begle ([email protected])
10 # Branched 11/01/99
11
12 use strict;
13 use File::Temp qw/ tempfile tempdir /;
14 use POSIX qw(sys_wait_h);
15
16 my $os_type = &get_os_type;
17 my $unixish = (($os_type ne "WIN") && ($os_type ne "MAC"));
18 my $path_sep = ($os_type eq "MAC") ? ":" : "/";
19 my $win_sep = ($os_type eq "WIN")? &get_win_sep : "";
20 my $redirect_command = ($os_type ne "MAC") ? " 2>&1" : "";
21
22 # command line option defaults
23 my $opt_suite_path;
24 my $opt_trace = 0;
25 my $opt_classpath = "";
26 my $opt_rhino_opt = 0;
27 my $opt_rhino_ms = 0;
28 my @opt_engine_list;
29 my $opt_engine_type = "";
30 my $opt_engine_params = "";
31 my $opt_user_output_file = 0;
32 my $opt_output_file = "";
33 my @opt_test_list_files;
34 my @opt_neg_list_files;
35 my $opt_shell_path = "";
36 my $opt_java_path = "";
37 my $opt_bug_url = "https://bugzilla.mozilla.org/show_bug.cgi?id=";
38 my $opt_console_failures = 0;
39 my $opt_console_failures_line = 0;
40 my $opt_lxr_url = "http://lxr.mozilla.org/mozilla/source/js/tests/";
41 my $opt_exit_munge = ($os_type ne "MAC") ? 1 : 0;
42 my $opt_timeout = 3600;
43 my $opt_enable_narcissus = 0;
44 my $opt_narcissus_path = "";
45 my $opt_no_quit = 0;
46 my $opt_report_summarized_results = 0;
47
48 # command line option definition
49 my $options = "b=s bugurl>b c=s classpath>c e=s engine>e f=s file>f " .
50 "h help>h i j=s javapath>j k confail>k K linefail>K R report>R l=s list>l " .
51 "L=s neglist>L o=s opt>o p=s testpath>p s=s shellpath>s t trace>t " .
52 "T=s timeout>T u=s lxrurl>u " .
53 "x noexitmunge>x n=s narcissus>n " .
54 "Q noquitinthandler>Q";
55
56 my $last_option;
57
58 if ($os_type eq "MAC") {
59 $opt_suite_path = `directory`;
60 $opt_suite_path =~ s/[\n\r]//g;
61 $opt_suite_path .= ":";
62 } else {
63 $opt_suite_path = "./";
64 }
65
66 &parse_args;
67
68 my $user_exit = 0;
69 my ($engine_command, $html, $failures_reported, $tests_completed,
70 $exec_time_string);
71 my @failed_tests;
72 my @test_list = &get_test_list;
73
74 if ($#test_list == -1) {
75 die ("Nothing to test.\n");
76 }
77
78 if ($unixish && $opt_no_quit == 0) {
79 # on unix, ^C pauses the tests, and gives the user a chance to quit but
80 # report on what has been done, to just quit, or to continue (the
81 # interrupted test will still be skipped.)
82 # windows doesn't handle the int handler they way we want it to,
83 # so don't even pretend to let the user continue.
84 $SIG{INT} = 'int_handler';
85 }
86
87 my $current_test;
88 my $current_test_pid;
89
90 &main;
91
92 #End.
93
94 sub main {
95 my $start_time;
96
97 while ($opt_engine_type = pop (@opt_engine_list)) {
98 dd ("Testing engine '$opt_engine_type'");
99
100 $engine_command = &get_engine_command;
101 $html = "";
102 @failed_tests = ();
103 $failures_reported = 0;
104 $tests_completed = 0;
105 $start_time = time;
106
107
108 &execute_tests (@test_list);
109
110 my $exec_time = (time - $start_time);
111 my $exec_hours = int($exec_time / 60 / 60);
112 $exec_time -= $exec_hours * 60 * 60;
113 my $exec_mins = int($exec_time / 60);
114 $exec_time -= $exec_mins * 60;
115 my $exec_secs = ($exec_time % 60);
116
117 if ($exec_hours > 0) {
118 $exec_time_string = "$exec_hours hours, $exec_mins minutes, " .
119 "$exec_secs seconds";
120 } elsif ($exec_mins > 0) {
121 $exec_time_string = "$exec_mins minutes, $exec_secs seconds";
122 } else {
123 $exec_time_string = "$exec_secs seconds";
124 }
125
126 if (!$opt_user_output_file) {
127 $opt_output_file = &get_tempfile_name;
128 }
129
130 &write_results;
131
132 }
133 }
134
135 sub append_file_to_command {
136 my ($command, $file) = @_;
137
138 if ($opt_enable_narcissus == 1) {
139 $command .= " -e 'evaluate(\"load(\\\"$file\\\")\")'"
140 } else {
141 $command .= " -f $file";
142 }
143 }
144
145 sub execute_tests {
146 my (@test_list) = @_;
147 my ($test, $shell_command, $line, @output, $path);
148 my ($last_suite, $last_test_dir);
149
150 &status ("Executing " . ($#test_list + 1) . " test(s).");
151
152 foreach $test (@test_list) {
153 my ($suite, $test_dir, $test_file) = split($path_sep, $test);
154 # *-n.js is a negative test, expect exit code 3 (runtime error)
155 my $expected_exit = ($test =~ /\-n\.js$/) ? 3 : 0;
156 my ($got_exit, $exit_signal);
157 my $failure_lines;
158 my $bug_number;
159 my $status_lines;
160 my $result_lines;
161
162 # Allow the test to declare multiple possible success exit codes.
163 # This is useful in situations where the test fails if a
164 # crash occurs but passes if no crash occurs even if an
165 # out of memory error occurs.
166 my @expected_exit_list = ($expected_exit);
167
168 # user selected [Q]uit from ^C handler.
169 if ($user_exit) {
170 return;
171 }
172
173 $current_test = $test;
174
175 # Append the shell.js files to the shell_command if they're there.
176 # (only check for their existance if the suite or test_dir has changed
177 # since the last time we looked.)
178 if ($last_suite ne $suite || $last_test_dir ne $test_dir) {
179 $shell_command = &xp_path($engine_command);
180
181 $path = &xp_path($opt_suite_path ."shell.js");
182 if (-f $path) {
183 $shell_command = &append_file_to_command($shell_command,
184 $path);
185 }
186
187 $path = &xp_path($opt_suite_path . $suite . "/shell.js");
188 if (-f $path) {
189 $shell_command = &append_file_to_command($shell_command,
190 $path);
191 }
192
193 $path = &xp_path($opt_suite_path . $suite . "/" .
194 $test_dir . "/shell.js");
195 if (-f $path) {
196 $shell_command = &append_file_to_command($shell_command,
197 $path);
198 }
199
200 $last_suite = $suite;
201 $last_test_dir = $test_dir;
202 }
203
204 $path = &xp_path($opt_suite_path . $test);
205 my $command = &append_file_to_command($shell_command, $path);
206
207 $path = &xp_path($opt_suite_path ."js-test-driver-end.js");
208 if (-f $path) {
209 $command = &append_file_to_command($command,
210 $path);
211 }
212
213 &dd ("executing: " . $command);
214
215 my $jsout;
216 (undef, $jsout) = tempfile();
217
218 #XXX cloned from tinderbox. See sub kill_process
219 my $pid = fork; # Fork a child process to run the test
220 unless ($pid) {
221 open STDOUT, ">$jsout";
222 open STDERR, ">&STDOUT";
223 select STDOUT; $| = 1; # make STDOUT unbuffered
224 select STDERR; $| = 1; # make STDERR unbuffered
225 exec $command;
226 die "Could not exec $command";
227 }
228
229 $current_test_pid = $pid;
230
231 my $timed_out = 0;
232 my $dumped_core = 0;
233 my $loop_count = 0;
234 my $wait_pid = -1;
235
236 eval
237 {
238 local $SIG{ALRM} = sub { die "time out" };
239 alarm $opt_timeout;
240 $wait_pid = waitpid($pid, 0);
241 alarm 0;
242 };
243
244 if ($@ and $@ =~ /time out/)
245 {
246 kill_process($pid);
247 $timed_out = 1;
248 }
249
250 $current_test_pid = undef;
251
252 if ($opt_exit_munge == 1) {
253 # signal information in the lower 8 bits, exit code above that
254 $got_exit = ($? >> 8);
255 $exit_signal = ($? & 255);
256 } else {
257 # user says not to munge the exit code
258 $got_exit = $?;
259 $exit_signal = 0;
260 }
261
262 open (OUTPUT, "$jsout") or
263 die "failed to open temporary file $jsout: $!\n";
264 @output = <OUTPUT>;
265 close (OUTPUT);
266 unlink "$jsout";
267 @output = grep (!/js\>/, @output);
268
269 $failure_lines = "";
270 $bug_number = "";
271 $status_lines = "";
272 $result_lines = "";
273
274 foreach $line (@output) {
275
276 # watch for testcase to proclaim what exit code it expects to
277 # produce (0 by default)
278 if ($line =~ /expect(ed)?\s*exit\s*code\s*\:?\s*(\d+)/i) {
279 $expected_exit = $2;
280 push @expected_exit_list, ($expected_exit);
281 &dd ("Test case expects exit code $expected_exit");
282 }
283
284 # watch for failures
285 if ($line =~ /^\s*FAILED!/) {
286 $failure_lines .= $line;
287 }
288
289 # and watch for bugnumbers
290 # XXX This only allows 1 bugnumber per testfile, should be
291 # XXX modified to allow for multiple.
292 if ($line =~ /bugnumber\s*\:?\s*(.*)/i) {
293 my $bugline = $1;
294 $bugline =~ /(\d+)/;
295 $bug_number = $1;
296 }
297
298 # and watch for status
299 if ($line =~ /status/i) {
300 $status_lines .= $line;
301 }
302
303 # collect result summary lines
304 if ($line =~ /^jstest:/)
305 {
306 $result_lines .= $line;
307 }
308 }
309
310 if (!@output) {
311 @output = ("Testcase produced no output!");
312 }
313
314 if ($opt_report_summarized_results) {
315 print STDERR $result_lines;
316 if ($timed_out)
317 {
318 &report_summary_result($test, $bug_number, "FAILED TIMED OUT",
319 "", "", "",
320 join("\n",@output));
321 }
322 elsif (index(join(',', @expected_exit_list), $got_exit) == -1 ||
323 $exit_signal != 0) {
324 &report_summary_result($test, $bug_number, "FAILED",
325 "",
326 "Expected exit $expected_exit",
327 "Actual exit $got_exit, signal $exit_signal",
328 join("\n",@output));
329 }
330 elsif ($got_exit != 0) {
331 # abnormal termination but the test passed, so output a summary line
332 &report_summary_result($test, $bug_number, "PASSED",
333 "",
334 "Expected exit $expected_exit",
335 "Actual exit $got_exit, signal $exit_signal",
336 join("\n",@output));
337 }
338 }
339 elsif ($timed_out) {
340 # test was terminated due to timeout
341 &report_failure ($test, "TIMED OUT ($opt_timeout seconds) " .
342 "Complete testcase output was:\n" .
343 join ("\n",@output), $bug_number);
344 }
345 elsif (index(join(',', @expected_exit_list), $got_exit) == -1 ||
346 $exit_signal != 0) {
347 # full testcase output dumped on mismatched exit codes,
348 &report_failure ($test, "Expected exit code " .
349 "$expected_exit, got $got_exit\n" .
350 "Testcase terminated with signal $exit_signal\n" .
351 "Complete testcase output was:\n" .
352 join ("\n",@output), $bug_number);
353 } elsif ($failure_lines) {
354 # only offending lines if exit codes matched
355 &report_failure ($test, "$status_lines\n".
356 "Failure messages were:\n$failure_lines",
357 $bug_number);
358 }
359
360 &dd ("exit code $got_exit, exit signal $exit_signal.");
361
362 $tests_completed++;
363 }
364 }
365
366 sub write_results {
367 my ($list_name, $neglist_name);
368 my $completion_date = localtime;
369 my $failure_pct = int(($failures_reported / $tests_completed) * 10000) /
370 100;
371 &dd ("Writing output to $opt_output_file.");
372
373 if ($#opt_test_list_files == -1) {
374 $list_name = "All tests";
375 } elsif ($#opt_test_list_files < 10) {
376 $list_name = join (", ", @opt_test_list_files);
377 } else {
378 $list_name = "($#opt_test_list_files test files specified)";
379 }
380
381 if ($#opt_neg_list_files == -1) {
382 $neglist_name = "(none)";
383 } elsif ($#opt_test_list_files < 10) {
384 $neglist_name = join (", ", @opt_neg_list_files);
385 } else {
386 $neglist_name = "($#opt_neg_list_files skip files specified)";
387 }
388
389 open (OUTPUT, "> $opt_output_file") ||
390 die ("Could not create output file $opt_output_file");
391
392 print OUTPUT
393 ("<html><head>\n" .
394 "<title>Test results, $opt_engine_type</title>\n" .
395 "</head>\n" .
396 "<body bgcolor='white'>\n" .
397 "<a name='tippy_top'></a>\n" .
398 "<h2>Test results, $opt_engine_type</h2><br>\n" .
399 "<p class='results_summary'>\n" .
400 "Test List: $list_name<br>\n" .
401 "Skip List: $neglist_name<br>\n" .
402 ($#test_list + 1) . " test(s) selected, $tests_completed test(s) " .
403 "completed, $failures_reported failures reported " .
404 "($failure_pct% failed)<br>\n" .
405 "Engine command line: $engine_command<br>\n" .
406 "OS type: $os_type<br>\n");
407
408 if ($opt_engine_type =~ /^rhino/) {
409 open (JAVAOUTPUT, $opt_java_path . "java -fullversion " .
410 $redirect_command . " |");
411 print OUTPUT <JAVAOUTPUT>;
412 print OUTPUT "<BR>";
413 close (JAVAOUTPUT);
414 }
415
416 print OUTPUT
417 ("Testcase execution time: $exec_time_string.<br>\n" .
418 "Tests completed on $completion_date.<br><br>\n");
419
420 if ($failures_reported > 0) {
421 my $output_file_failures = $opt_output_file;
422 $output_file_failures =~ s/(.*)\.html$/$1-failures.txt/;
423 open (OUTPUTFAILURES, "> $output_file_failures") ||
424 die ("Could not create failure output file $output_file_failures");
425 print OUTPUTFAILURES (join ("\n", @failed_tests));
426 print OUTPUTFAILURES "\n";
427 close OUTPUTFAILURES;
428
429 &status ("Wrote failures to '$output_file_failures'.");
430
431 print OUTPUT
432 ("[ <a href='#fail_detail'>Failure Details</a> | " .
433 "<a href='#retest_list'>Retest List</a> | " .
434 "<a href='$opt_lxr_url" . "menu.html'>Test Selection Page</a> ]<br>\n" .
435 "<hr>\n" .
436 "<a name='fail_detail'></a>\n" .
437 "<h2>Failure Details</h2><br>\n<dl>" .
438 $html .
439 "</dl>\n[ <a href='#tippy_top'>Top of Page</a> | " .
440 "<a href='#fail_detail'>Top of Failures</a> ]<br>\n" .
441 "<hr>\n" .
442 "<a name='retest_list'></a>\n" .
443 "<h2>Retest List</h2><br>\n" .
444 "<pre>\n" .
445 "# Retest List, $opt_engine_type, " .
446 "generated $completion_date.\n" .
447 "FAILURE: # Original test base was: $list_name.\n" .
448 "FAILURE: # $tests_completed of " . ($#test_list + 1) .
449 " test(s) were completed, " .
450 "$failures_reported failures reported.\n" .
451 "FAILURE: Engine command line: $engine_command<br>\n" .
452 join ("\n", map { "FAILURE: $_" } @failed_tests) .
453 "\n</pre>\n" .
454 "[ <a href='#tippy_top'>Top of Page</a> | " .
455 "<a href='#retest_list'>Top of Retest List</a> ]<br>\n");
456 } else {
457 print OUTPUT
458 ("<h1>Whoop-de-doo, nothing failed!</h1>\n");
459 }
460
461 print OUTPUT "</body>";
462
463 close (OUTPUT);
464
465 &status ("Wrote results to '$opt_output_file'.");
466
467 if ($opt_console_failures) {
468 &status ("$failures_reported test(s) failed");
469 }
470
471 }
472
473 sub next_option {
474 my ($key, $val, $implied);
475
476 return if @ARGV == 0;
477
478 &dd ("ARGV is now: @ARGV\n");
479
480 $key = shift @ARGV;
481 if ($key =~ s/^--?(.*)/$1/) {
482 $implied = 0;
483 } else {
484 $implied = 1;
485 $val = $key;
486 $key = $last_option;
487 }
488
489 if ($key =~ /\w+/ and $options =~ /\b$key>(\w+)/) {
490 $key = $1;
491 }
492
493 if ($options =~ /\b$key=s\b/) {
494 if (!$implied) {
495 die "option '$key' requires an argument" if @ARGV == 0;
496 $val = shift @ARGV;
497 }
498 } elsif ($options =~ /(^|\s)$key(\s|$)/) {
499 die "option '$key' doesn't take an argument" if $implied;
500 $val = 1;
501 } else {
502 die "can't figure out option '$key'";
503 }
504 $last_option = $key;
505 return ($key, $val);
506 }
507
508 sub parse_args {
509 my ($option, $value, $lastopt);
510
511 &dd ("checking command line options.");
512
513 while (($option, $value) = next_option()) {
514
515 if ($option eq "b") {
516 &dd ("opt: setting bugurl to '$value'.");
517 $opt_bug_url = $value;
518
519 } elsif ($option eq "c") {
520 &dd ("opt: setting classpath to '$value'.");
521 $opt_classpath = $value;
522
523 } elsif (($option eq "e") || (($option eq "") && ($lastopt eq "e"))) {
524 &dd ("opt: adding engine $value.");
525 push (@opt_engine_list, $value);
526
527 } elsif ($option eq "f") {
528 if (!$value) {
529 die ("Output file cannot be null.\n");
530 }
531 &dd ("opt: setting output file to '$value'.");
532 $opt_user_output_file = 1;
533 $opt_output_file = $value;
534
535 } elsif ($option eq "h") {
536 &usage;
537
538 } elsif ($option eq "j") {
539 if (!($value =~ /[\/\\]$/)) {
540 $value .= "/";
541 }
542 &dd ("opt: setting java path to '$value'.");
543 $opt_java_path = $value;
544
545 } elsif ($option eq "k") {
546 &dd ("opt: displaying failures on console.");
547 $opt_console_failures=1;
548
549 } elsif ($option eq "K") {
550 &dd ("opt: displaying failures on console as single line.");
551 $opt_console_failures=1;
552 $opt_console_failures_line=1;
553
554 } elsif ($option eq "R") {
555 &dd ("opt: Report summarized test results.");
556 $opt_report_summarized_results=1;
557
558 } elsif ($option eq "l" || (($option eq "") && ($lastopt eq "l"))) {
559 $option = "l";
560 &dd ("opt: adding test list '$value'.");
561 push (@opt_test_list_files, $value);
562
563 } elsif ($option eq "L" || (($option eq "") && ($lastopt eq "L"))) {
564 $option = "L";
565 &dd ("opt: adding negative list '$value'.");
566 push (@opt_neg_list_files, $value);
567
568 } elsif ($option eq "o") {
569 $opt_engine_params = $value;
570 &dd ("opt: setting engine params to '$opt_engine_params'.");
571
572 } elsif ($option eq "p") {
573 $opt_suite_path = $value;
574
575 if ($os_type eq "MAC") {
576 if (!($opt_suite_path =~ /\:$/)) {
577 $opt_suite_path .= ":";
578 }
579 } else {
580 if (!($opt_suite_path =~ /[\/\\]$/)) {
581 $opt_suite_path .= "/";
582 }
583 }
584
585 &dd ("opt: setting suite path to '$opt_suite_path'.");
586
587 } elsif ($option eq "s") {
588 $opt_shell_path = $value;
589 &dd ("opt: setting shell path to '$opt_shell_path'.");
590
591 } elsif ($option eq "t") {
592 &dd ("opt: tracing output. (console failures at no extra charge.)");
593 $opt_console_failures = 1;
594 $opt_trace = 1;
595
596 } elsif ($option eq "u") {
597 &dd ("opt: setting lxr url to '$value'.");
598 $opt_lxr_url = $value;
599
600 } elsif ($option eq "x") {
601 &dd ("opt: turning off exit munging.");
602 $opt_exit_munge = 0;
603
604 } elsif ($option eq "T") {
605 $opt_timeout = $value;
606 &dd ("opt: setting timeout to $opt_timeout.");
607
608 } elsif ($option eq "n") {
609 &dd ("opt: enabling narcissus.");
610 $opt_enable_narcissus = 1;
611 if ($value) {
612 $opt_narcissus_path = $value;
613 }
614
615 } elsif ($option eq "Q") {
616 &dd ("opt: disabling interrupt handler.");
617 $opt_no_quit = 1;
618
619 } else {
620 &dd ("opt: unknown option $option '$value'.");
621 &usage;
622 }
623
624 $lastopt = $option;
625
626 }
627
628 if ($#opt_engine_list == -1) {
629 die "You must select a shell to test in.\n";
630 }
631
632 }
633
634 #
635 # print the arguments that this script expects
636 #
637 sub usage {
638 print STDERR
639 ("\nusage: $0 [<options>] \n" .
640 "(-b|--bugurl) Bugzilla URL.\n" .
641 " (default is $opt_bug_url)\n" .
642 "(-c|--classpath) Classpath (Rhino only.)\n" .
643 "(-e|--engine) <type> ... Specify the type of engine(s) to test.\n" .
644 " <type> is one or more of\n" .
645 " (smopt|smdebug|lcopt|lcdebug|xpcshell|" .
646 "rhino|rhinoi|rhinoms|rhinomsi|rhino9|rhinoms9).\n" .
647 "(-f|--file) <file> Redirect output to file named <file>.\n" .
648 " (default is " .
649 "results-<engine-type>-<date-stamp>.html)\n" .
650 "(-h|--help) Print this message.\n" .
651 "(-j|--javapath) Location of java executable.\n" .
652 "(-k|--confail) Log failures to console (also.)\n" .
653 "(-K|--linefail) Log failures to console as single line (also.)\n" .
654 "(-R|--report) Report summarized test results.\n" .
655 "(-l|--list) <file> ... List of tests to execute.\n" .
656 "(-L|--neglist) <file> ... List of tests to skip.\n" .
657 "(-o|--opt) <options> Options to pass to the JavaScript engine.\n" .
658 " (Make sure to quote them!)\n" .
659 "(-p|--testpath) <path> Root of the test suite. (default is ./)\n" .
660 "(-s|--shellpath) <path> Location of JavaScript shell.\n" .
661 "(-t|--trace) Trace script execution.\n" .
662 "(-T|--timeout) <seconds> Time in seconds before the test is terminated.\n" .
663 " (default is 3600).\n" .
664 "(-u|--lxrurl) <url> Complete URL to tests subdirectory on lxr.\n" .
665 " (default is $opt_lxr_url)\n" .
666 "(-x|--noexitmunge) Don't do exit code munging (try this if it\n" .
667 " seems like your exit codes are turning up\n" .
668 " as exit signals.)\n" .
669 "(-n|--narcissus)[=<path>] Run the test suite through Narcissus, run\n" .
670 " through the given shell. The optional path\n".
671 " is the path to Narcissus' js.js file.\n".
672 "(-Q|--noquitinthandler) Do not prompt user to Quit, Report or Continue\n".
673 " in the event of a user interrupt.\n"
674 );
675 exit (1);
676
677 }
678
679 #
680 # get the shell command used to start the (either) engine
681 #
682 sub get_engine_command {
683
684 my $retval;
685
686 if ($opt_engine_type eq "rhino") {
687 &dd ("getting rhino engine command.");
688 $opt_rhino_opt = 0;
689 $opt_rhino_ms = 0;
690 $retval = &get_rhino_engine_command;
691 } elsif ($opt_engine_type eq "rhinoi") {
692 &dd ("getting rhinoi engine command.");
693 $opt_rhino_opt = -1;
694 $opt_rhino_ms = 0;
695 $retval = &get_rhino_engine_command;
696 } elsif ($opt_engine_type eq "rhino9") {
697 &dd ("getting rhino engine command.");
698 $opt_rhino_opt = 9;
699 $opt_rhino_ms = 0;
700 $retval = &get_rhino_engine_command;
701 } elsif ($opt_engine_type eq "rhinoms") {
702 &dd ("getting rhinoms engine command.");
703 $opt_rhino_opt = 0;
704 $opt_rhino_ms = 1;
705 $retval = &get_rhino_engine_command;
706 } elsif ($opt_engine_type eq "rhinomsi") {
707 &dd ("getting rhinomsi engine command.");
708 $opt_rhino_opt = -1;
709 $opt_rhino_ms = 1;
710 $retval = &get_rhino_engine_command;
711 } elsif ($opt_engine_type eq "rhinoms9") {
712 &dd ("getting rhinomsi engine command.");
713 $opt_rhino_opt = 9;
714 $opt_rhino_ms = 1;
715 $retval = &get_rhino_engine_command;
716 } elsif ($opt_engine_type eq "xpcshell") {
717 &dd ("getting xpcshell engine command.");
718 $retval = &get_xpc_engine_command;
719 } elsif ($opt_engine_type =~ /^lc(opt|debug)$/) {
720 &dd ("getting liveconnect engine command.");
721 $retval = &get_lc_engine_command;
722 } elsif ($opt_engine_type =~ /^sm(opt|debug)$/) {
723 &dd ("getting spidermonkey engine command.");
724 $retval = &get_sm_engine_command;
725 } elsif ($opt_engine_type =~ /^ep(opt|debug)$/) {
726 &dd ("getting epimetheus engine command.");
727 $retval = &get_ep_engine_command;
728 } else {
729 die ("Unknown engine type selected, '$opt_engine_type'.\n");
730 }
731
732 $retval .= " $opt_engine_params";
733
734 if ($opt_enable_narcissus == 1) {
735 my $narcissus_path = &get_narcissus_path;
736 $retval .= " -f $narcissus_path";
737 }
738
739 &dd ("got '$retval'");
740
741 return $retval;
742 }
743
744 #
745 # get the path to the Narcissus js.js file.
746 #
747 sub get_narcissus_path {
748 my $retval;
749
750 if ($opt_narcissus_path) {
751 $retval = $opt_narcissus_path;
752 } else {
753 # For now, just assume that we're in js/tests.
754 $retval = "../narcissus/js.js";
755 }
756
757 if (!-e $retval) {
758 # XXX if it didn't exist, try something more fancy?
759 die "Unable to find Narcissus' js.js at $retval";
760 }
761
762 return $retval;
763 }
764
765 #
766 # get the shell command used to run rhino
767 #
768 sub get_rhino_engine_command {
769 my $retval = $opt_java_path . ($opt_rhino_ms ? "jview " : "java ");
770
771 if ($opt_shell_path) {
772 $opt_classpath = ($opt_classpath) ?
773 $opt_classpath . ":" . $opt_shell_path :
774 $opt_shell_path;
775 }
776
777 if ($opt_classpath) {
778 $retval .= ($opt_rhino_ms ? "/cp:p" : "-classpath") . " $opt_classpath ";
779 }
780
781 $retval .= "org.mozilla.javascript.tools.shell.Main";
782
783 if ($opt_rhino_opt) {
784 $retval .= " -opt $opt_rhino_opt";
785 }
786
787 return $retval;
788
789 }
790
791 #
792 # get the shell command used to run xpcshell
793 #
794 sub get_xpc_engine_command {
795 my $retval;
796 my $m5_home = @ENV{"MOZILLA_FIVE_HOME"} ||
797 die ("You must set MOZILLA_FIVE_HOME to use the xpcshell" ,
798 (!$unixish) ? "." : ", also " .
799 "setting LD_LIBRARY_PATH to the same directory may get rid of " .
800 "any 'library not found' errors.\n");
801
802 if (($unixish) && (!@ENV{"LD_LIBRARY_PATH"})) {
803 print STDERR "-#- WARNING: LD_LIBRARY_PATH is not set, xpcshell may " .
804 "not be able to find the required components.\n";
805 }
806
807 if (!($m5_home =~ /[\/\\]$/)) {
808 $m5_home .= "/";
809 }
810
811 $retval = $m5_home . "xpcshell";
812
813 if ($os_type eq "WIN") {
814 $retval .= ".exe";
815 }
816
817 $retval = &xp_path($retval);
818
819 if (($os_type ne "MAC") && !(-x $retval)) {
820 # mac doesn't seem to deal with -x correctly
821 die ($retval . " is not a valid executable on this system.\n");
822 }
823
824 return $retval;
825
826 }
827
828 #
829 # get the shell command used to run spidermonkey
830 #
831 sub get_sm_engine_command {
832 my $retval;
833
834 # Look for Makefile.ref style make first.
835 # (On Windows, spidermonkey can be made by two makefiles, each putting the
836 # executable in a diferent directory, under a different name.)
837
838 if ($opt_shell_path) {
839 # if the user provided a path to the shell, return that.
840 $retval = $opt_shell_path;
841
842 } else {
843
844 if ($os_type eq "MAC") {
845 $retval = $opt_suite_path . ":src:macbuild:JS";
846 } else {
847 $retval = $opt_suite_path . "../src/";
848 opendir (SRC_DIR_FILES, $retval);
849 my @src_dir_files = readdir(SRC_DIR_FILES);
850 closedir (SRC_DIR_FILES);
851
852 my ($dir, $object_dir);
853 my $pattern = ($opt_engine_type eq "smdebug") ?
854 'DBG.OBJ' : 'OPT.OBJ';
855
856 # scan for the first directory matching
857 # the pattern expected to hold this type (debug or opt) of engine
858 foreach $dir (@src_dir_files) {
859 if ($dir =~ $pattern) {
860 $object_dir = $dir;
861 last;
862 }
863 }
864
865 if (!$object_dir && $os_type ne "WIN") {
866 die ("Could not locate an object directory in $retval " .
867 "matching the pattern *$pattern. Have you built the " .
868 "engine?\n");
869 }
870
871 if (!(-x $retval . $object_dir . "/js.exe") && ($os_type eq "WIN")) {
872 # On windows, you can build with js.mak as well as Makefile.ref
873 # (Can you say WTF boys and girls? I knew you could.)
874 # So, if the exe the would have been built by Makefile.ref isn't
875 # here, check for the js.mak version before dying.
876 if ($opt_shell_path) {
877 $retval = $opt_shell_path;
878 if (!($retval =~ /[\/\\]$/)) {
879 $retval .= "/";
880 }
881 } else {
882 if ($opt_engine_type eq "smopt") {
883 $retval = "../src/Release/";
884 } else {
885 $retval = "../src/Debug/";
886 }
887 }
888
889 $retval .= "jsshell.exe";
890
891 } else {
892 $retval .= $object_dir . "/js";
893 if ($os_type eq "WIN") {
894 $retval .= ".exe";
895 }
896 }
897 } # mac/ not mac
898
899 $retval = &xp_path($retval);
900
901 } # (user provided a path)
902
903
904 if (($os_type ne "MAC") && !(-x $retval)) {
905 # mac doesn't seem to deal with -x correctly
906 die ($retval . " is not a valid executable on this system.\n");
907 }
908
909 return $retval;
910
911 }
912
913 #
914 # get the shell command used to run epimetheus
915 #
916 sub get_ep_engine_command {
917 my $retval;
918
919 if ($opt_shell_path) {
920 # if the user provided a path to the shell, return that -
921 $retval = $opt_shell_path;
922
923 } else {
924 my $dir;
925 my $os;
926 my $debug;
927 my $opt;
928 my $exe;
929
930 $dir = $opt_suite_path . "../../js2/src/";
931
932 if ($os_type eq "MAC") {
933 #
934 # On the Mac, the debug and opt builds lie in the same directory -
935 #
936 $os = "macbuild:";
937 $debug = "";
938 $opt = "";
939 $exe = "JS2";
940 } elsif ($os_type eq "WIN") {
941 $os = "winbuild/Epimetheus/";
942 $debug = "Debug/";
943 $opt = "Release/";
944 $exe = "Epimetheus.exe";
945 } else {
946 $os = "";
947 $debug = "";
948 $opt = ""; # <<<----- XXX THIS IS NOT RIGHT! CHANGE IT!
949 $exe = "epimetheus";
950 }
951
952
953 if ($opt_engine_type eq "epdebug") {
954 $retval = $dir . $os . $debug . $exe;
955 } else {
956 $retval = $dir . $os . $opt . $exe;
957 }
958
959 $retval = &xp_path($retval);
960
961 }# (user provided a path)
962
963
964 if (($os_type ne "MAC") && !(-x $retval)) {
965 # mac doesn't seem to deal with -x correctly
966 die ($retval . " is not a valid executable on this system.\n");
967 }
968
969 return $retval;
970 }
971
972 #
973 # get the shell command used to run the liveconnect shell
974 #
975 sub get_lc_engine_command {
976 my $retval;
977
978 if ($opt_shell_path) {
979 $retval = $opt_shell_path;
980 } else {
981 if ($os_type eq "MAC") {
982 die "Don't know how to run the lc shell on the mac yet.\n";
983 } else {
984 $retval = $opt_suite_path . "../src/liveconnect/";
985 opendir (SRC_DIR_FILES, $retval);
986 my @src_dir_files = readdir(SRC_DIR_FILES);
987 closedir (SRC_DIR_FILES);
988
989 my ($dir, $object_dir);
990 my $pattern = ($opt_engine_type eq "lcdebug") ?
991 'DBG.OBJ' : 'OPT.OBJ';
992
993 foreach $dir (@src_dir_files) {
994 if ($dir =~ $pattern) {
995 $object_dir = $dir;
996 last;
997 }
998 }
999
1000 if (!$object_dir) {
1001 die ("Could not locate an object directory in $retval " .
1002 "matching the pattern *$pattern. Have you built the " .
1003 "engine?\n");
1004 }
1005
1006 $retval .= $object_dir . "/";
1007
1008 if ($os_type eq "WIN") {
1009 $retval .= "lcshell.exe";
1010 } else {
1011 $retval .= "lcshell";
1012 }
1013 } # mac/ not mac
1014
1015 $retval = &xp_path($retval);
1016
1017 } # (user provided a path)
1018
1019
1020 if (($os_type ne "MAC") && !(-x $retval)) {
1021 # mac doesn't seem to deal with -x correctly
1022 die ("$retval is not a valid executable on this system.\n");
1023 }
1024
1025 return $retval;
1026
1027 }
1028
1029 sub get_os_type {
1030
1031 if ("\n" eq "\015") {
1032 return "MAC";
1033 }
1034
1035 my $uname = `uname -a`;
1036
1037 if ($uname =~ /WIN/) {
1038 $uname = "WIN";
1039 } else {
1040 chop $uname;
1041 }
1042
1043 &dd ("get_os_type returning '$uname'.");
1044 return $uname;
1045
1046 }
1047
1048 sub get_test_list {
1049 my @test_list;
1050 my @neg_list;
1051
1052 if ($#opt_test_list_files > -1) {
1053 my $list_file;
1054
1055 &dd ("getting test list from user specified source.");
1056
1057 foreach $list_file (@opt_test_list_files) {
1058 push (@test_list, &expand_user_test_list($list_file));
1059 }
1060 } else {
1061 &dd ("no list file, groveling in '$opt_suite_path'.");
1062
1063 @test_list = &get_default_test_list($opt_suite_path);
1064 }
1065
1066 if ($#opt_neg_list_files > -1) {
1067 my $list_file;
1068 my $orig_size = $#test_list + 1;
1069 my $actually_skipped;
1070
1071 &dd ("getting negative list from user specified source.");
1072
1073 foreach $list_file (@opt_neg_list_files) {
1074 push (@neg_list, &expand_user_test_list($list_file));
1075 }
1076
1077 @test_list = &subtract_arrays (\@test_list, \@neg_list);
1078
1079 $actually_skipped = $orig_size - ($#test_list + 1);
1080
1081 &dd ($actually_skipped . " of " . $orig_size .
1082 " tests will be skipped.");
1083 &dd ((($#neg_list + 1) - $actually_skipped) . " skip tests were " .
1084 "not actually part of the test list.");
1085
1086 }
1087
1088
1089 # Don't run any shell.js files as tests; they are only utility files
1090 @test_list = grep (!/shell\.js$/, @test_list);
1091
1092 # Don't run any browser.js files as tests; they are only utility files
1093 @test_list = grep (!/browser\.js$/, @test_list);
1094
1095 # Don't run any jsref.js files as tests; they are only utility files
1096 @test_list = grep (!/jsref\.js$/, @test_list);
1097
1098 return @test_list;
1099
1100 }
1101
1102 #
1103 # reads $list_file, storing non-comment lines into an array.
1104 # lines in the form suite_dir/[*] or suite_dir/test_dir/[*] are expanded
1105 # to include all test files under the specified directory
1106 #
1107 sub expand_user_test_list {
1108 my ($list_file) = @_;
1109 my @retval = ();
1110
1111 #
1112 # Trim off the leading path separator that begins relative paths on the Mac.
1113 # Each path will get concatenated with $opt_suite_path, which ends in one.
1114 #
1115 # Also note:
1116 #
1117 # We will call expand_test_list_entry(), which does pattern-matching on $list_file.
1118 # This will make the pattern-matching the same as it would be on Linux/Windows -
1119 #
1120 if ($os_type eq "MAC") {
1121 $list_file =~ s/^$path_sep//;
1122 }
1123
1124 if ($list_file =~ /\.js$/ || -d $opt_suite_path . $list_file) {
1125
1126 push (@retval, &expand_test_list_entry($list_file));
1127
1128 } else {
1129
1130 open (TESTLIST, $list_file) ||
1131 die("Error opening test list file '$list_file': $!\n");
1132
1133 while (<TESTLIST>) {
1134 s/\r*\n*$//;
1135 if (!(/\s*\#/)) {
1136 # It's not a comment, so process it
1137 push (@retval, &expand_test_list_entry($_));
1138 }
1139 }
1140
1141 close (TESTLIST);
1142
1143 }
1144
1145 return @retval;
1146
1147 }
1148
1149
1150 #
1151 # Currently expect all paths to be RELATIVE to the top-level tests directory.
1152 # One day, this should be improved to allow absolute paths as well -
1153 #
1154 sub expand_test_list_entry {
1155 my ($entry) = @_;
1156 my @retval;
1157
1158 if ($entry =~ /\.js$/) {
1159 # it's a regular entry, add it to the list
1160 if (-f $opt_suite_path . $entry) {
1161 push (@retval, $entry);
1162 } else {
1163 status ("testcase '$entry' not found.");
1164 }
1165 } elsif ($entry =~ /(.*$path_sep[^\*][^$path_sep]*)$path_sep?\*?$/) {
1166 # Entry is in the form suite_dir/test_dir[/*]
1167 # so iterate all tests under it
1168 my $suite_and_test_dir = $1;
1169 my @test_files = &get_js_files ($opt_suite_path .
1170 $suite_and_test_dir);
1171 my $i;
1172
1173 foreach $i (0 .. $#test_files) {
1174 $test_files[$i] = $suite_and_test_dir . $path_sep .
1175 $test_files[$i];
1176 }
1177
1178 splice (@retval, $#retval + 1, 0, @test_files);
1179
1180 } elsif ($entry =~ /([^\*][^$path_sep]*)$path_sep?\*?$/) {
1181 # Entry is in the form suite_dir[/*]
1182 # so iterate all test dirs and tests under it
1183 my $suite = $1;
1184 my @test_dirs = &get_subdirs ($opt_suite_path . $suite);
1185 my $test_dir;
1186
1187 foreach $test_dir (@test_dirs) {
1188 my @test_files = &get_js_files ($opt_suite_path . $suite .
1189 $path_sep . $test_dir);
1190 my $i;
1191
1192 foreach $i (0 .. $#test_files) {
1193 $test_files[$i] = $suite . $path_sep . $test_dir . $path_sep .
1194 $test_files[$i];
1195 }
1196
1197 splice (@retval, $#retval + 1, 0, @test_files);
1198 }
1199
1200 } else {
1201 die ("Don't know what to do with list entry '$entry'.\n");
1202 }
1203
1204 return @retval;
1205
1206 }
1207
1208 #
1209 # Grovels through $suite_path, searching for *all* test files. Used when the
1210 # user doesn't supply a test list.
1211 #
1212 sub get_default_test_list {
1213 my ($suite_path) = @_;
1214 my @suite_list = &get_subdirs($suite_path);
1215 my $suite;
1216 my @retval;
1217
1218 foreach $suite (@suite_list) {
1219 my @test_dir_list = get_subdirs ($suite_path . $suite);
1220 my $test_dir;
1221
1222 foreach $test_dir (@test_dir_list) {
1223 my @test_list = get_js_files ($suite_path . $suite . $path_sep .
1224 $test_dir);
1225 my $test;
1226
1227 foreach $test (@test_list) {
1228 $retval[$#retval + 1] = $suite . $path_sep . $test_dir .
1229 $path_sep . $test;
1230 }
1231 }
1232 }
1233
1234 return @retval;
1235
1236 }
1237
1238 #
1239 # generate an output file name based on the date
1240 #
1241 sub get_tempfile_name {
1242 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
1243 &get_padded_time (localtime);
1244 my $rv;
1245
1246 if ($os_type ne "MAC") {
1247 $rv = "results-" . $year . "-" . $mon . "-" . $mday . "-" . $hour .
1248 $min . $sec . "-" . $opt_engine_type;
1249 } else {
1250 $rv = "res-" . $year . $mon . $mday . $hour . $min . $sec . "-" .
1251 $opt_engine_type
1252 }
1253
1254 return $rv . ".html";
1255 }
1256
1257 sub get_padded_time {
1258 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = @_;
1259
1260 $mon++;
1261 $mon = &zero_pad($mon);
1262 $year += 1900;
1263 $mday= &zero_pad($mday);
1264 $sec = &zero_pad($sec);
1265 $min = &zero_pad($min);
1266 $hour = &zero_pad($hour);
1267
1268 return ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
1269
1270 }
1271
1272 sub zero_pad {
1273 my ($string) = @_;
1274
1275 $string = ($string < 10) ? "0" . $string : $string;
1276 return $string;
1277 }
1278
1279 sub subtract_arrays {
1280 my ($whole_ref, $part_ref) = @_;
1281 my @whole = @$whole_ref;
1282 my @part = @$part_ref;
1283 my $line;
1284
1285 foreach $line (@part) {
1286 @whole = grep (!/$line/, @whole);
1287 }
1288
1289 return @whole;
1290
1291 }
1292
1293 #
1294 # Convert unix path to mac style.
1295 #
1296 sub unix_to_mac {
1297 my ($path) = @_;
1298 my @path_elements = split ("/", $path);
1299 my $rv = "";
1300 my $i;
1301
1302 foreach $i (0 .. $#path_elements) {
1303 if ($path_elements[$i] eq ".") {
1304 if (!($rv =~ /\:$/)) {
1305 $rv .= ":";
1306 }
1307 } elsif ($path_elements[$i] eq "..") {
1308 if (!($rv =~ /\:$/)) {
1309 $rv .= "::";
1310 } else {
1311 $rv .= ":";
1312 }
1313 } elsif ($path_elements[$i] ne "") {
1314 $rv .= $path_elements[$i] . ":";
1315 }
1316
1317 }
1318
1319 $rv =~ s/\:$//;
1320
1321 return $rv;
1322 }
1323
1324 #
1325 # Convert unix path to win style.
1326 #
1327 sub unix_to_win {
1328 my ($path) = @_;
1329
1330 if ($path_sep ne $win_sep) {
1331 $path =~ s/$path_sep/$win_sep/g;
1332 }
1333
1334 return $path;
1335 }
1336
1337 #
1338 # Windows shells require "/" or "\" as path separator.
1339 # Find out the one used in the current Windows shell.
1340 #
1341 sub get_win_sep {
1342 my $path = $ENV{"PATH"} || $ENV{"Path"} || $ENV{"path"};
1343 $path =~ /\\|\//;
1344 return $&;
1345 }
1346
1347 #
1348 # Convert unix path to correct style based on platform.
1349 #
1350 sub xp_path {
1351 my ($path) = @_;
1352
1353 if ($os_type eq "MAC") {
1354 return &unix_to_mac($path);
1355 } elsif($os_type eq "WIN") {
1356 return &unix_to_win($path);
1357 } else {
1358 return $path;
1359 }
1360 }
1361
1362 #
1363 # given a directory, return an array of all subdirectories
1364 #
1365 sub get_subdirs {
1366 my ($dir) = @_;
1367 my @subdirs;
1368
1369 if ($os_type ne "MAC") {
1370 if (!($dir =~ /\/$/)) {
1371 $dir = $dir . "/";
1372 }
1373 } else {
1374 if (!($dir =~ /\:$/)) {
1375 $dir = $dir . ":";
1376 }
1377 }
1378 opendir (DIR, $dir) || die ("couldn't open directory $dir: $!");
1379 my @testdir_contents = readdir(DIR);
1380 closedir(DIR);
1381
1382 foreach (@testdir_contents) {
1383 if ((-d ($dir . $_)) && ($_ ne 'CVS') && ($_ ne '.') && ($_ ne '..')) {
1384 @subdirs[$#subdirs + 1] = $_;
1385 }
1386 }
1387
1388 return @subdirs;
1389 }
1390
1391 #
1392 # given a directory, return an array of all the js files that are in it.
1393 #
1394 sub get_js_files {
1395 my ($test_subdir) = @_;
1396 my (@js_file_array, @subdir_files);
1397
1398 opendir (TEST_SUBDIR, $test_subdir) || die ("couldn't open directory " .
1399 "$test_subdir: $!");
1400 @subdir_files = readdir(TEST_SUBDIR);
1401 closedir( TEST_SUBDIR );
1402
1403 foreach (@subdir_files) {
1404 if ($_ =~ /\.js$/) {
1405 $js_file_array[$#js_file_array+1] = $_;
1406 }
1407 }
1408
1409 return @js_file_array;
1410 }
1411
1412 sub report_failure {
1413 my ($test, $message, $bug_number) = @_;
1414 my $bug_line = "";
1415
1416 $failures_reported++;
1417
1418 $message =~ s/\n+/\n/g;
1419 $test =~ s/\:/\//g;
1420
1421 if ($opt_console_failures) {
1422 if ($opt_console_failures_line) {
1423 # report_summary_result increments $failures_reported
1424 # decrement here to prevent overcounting of failures
1425 $failures_reported--;
1426 my $linemessage = $message;
1427 $linemessage =~ s/[\n\r]+/ /mg;
1428 $bug_number = "none" unless $bug_number;
1429 &report_summary_result($test, $bug_number, "FAILED",
1430 "",
1431 "",
1432 "",
1433 $linemessage);
1434 } elsif($bug_number) {
1435 print STDERR ("*-* Testcase $test failed:\nBug Number $bug_number".
1436 "\n$message\n");
1437 } else {
1438 print STDERR ("*-* Testcase $test failed:\n$message\n");
1439 }
1440 }
1441
1442 $message =~ s/&/&amp;/g;
1443 $message =~ s/</&lt;/g;
1444 $message =~ s/>/&gt;/g;
1445 $message =~ s/\n/<br>\n/g;
1446
1447 if ($bug_number) {
1448 my $bug_url = ($bug_number =~ /^\d+$/) ? "$opt_bug_url$bug_number" : $bug_number;
1449 $bug_line = "<a href='$bug_url' target='other_window'>".
1450 "Bug Number $bug_number</a>";
1451 }
1452
1453 if ($opt_lxr_url) {
1454 $test =~ /\/?([^\/]+\/[^\/]+\/[^\/]+)$/;
1455 $test = $1;
1456 $html .= "<dd><b>".
1457 "Testcase <a target='other_window' href='$opt_lxr_url$test'>$1</a> " .
1458 "failed</b> $bug_line<br>\n";
1459 } else {
1460 $html .= "<dd><b>".
1461 "Testcase $test failed</b> $bug_line<br>\n";
1462 }
1463
1464 $html .= " [ ";
1465
1466 $html .= "<a href='#tippy_top'>Top of Page</a> ]<br>\n" .
1467 "<tt>$message</tt><br>\n";
1468
1469 @failed_tests[$#failed_tests + 1] = $test;
1470
1471 }
1472
1473 sub dd {
1474
1475 if ($opt_trace) {
1476 print ("-*- ", @_ , "\n");
1477 }
1478
1479 }
1480
1481 sub status {
1482
1483 print ("-#- ", @_ , "\n");
1484
1485 }
1486
1487 sub int_handler {
1488 my $resp;
1489
1490 if ($current_test_pid)
1491 {
1492 print "User Interrupt: killing process $current_test_pid\n";
1493 kill_process($current_test_pid);
1494 }
1495
1496 do {
1497 print STDERR ("\n*** User Break: Just [Q]uit, Quit and [R]eport, [C]ontinue ?");
1498 $resp = <STDIN>;
1499 } until ($resp =~ /[QqRrCc]/);
1500
1501 if ($resp =~ /[Qq]/) {
1502 print ("User Exit. No results were generated.\n");
1503 exit;
1504 } elsif ($resp =~ /[Rr]/) {
1505 $user_exit = 1;
1506 }
1507
1508 }
1509
1510 # XXX: These functions were pulled from
1511 # lxr.mozilla.org/mozilla/source/tools/tinderbox/build-seamonkey-util.pl
1512 # need a general reusable library of routines for use in all test programs.
1513
1514 sub kill_process {
1515 my ($target_pid) = @_;
1516 my $start_time = time;
1517
1518 # Try to kill and wait 10 seconds, then try a kill -9
1519 my $sig;
1520 for $sig ('TERM', 'KILL') {
1521 print "kill $sig $target_pid\n";
1522 kill $sig => $target_pid;
1523 my $interval_start = time;
1524 while (time - $interval_start < 10) {
1525 # the following will work with 'cygwin' perl on win32, but not
1526 # with 'MSWin32' (ActiveState) perl
1527 my $pid = waitpid($target_pid, POSIX::WNOHANG());
1528 if (($pid == $target_pid and POSIX::WIFEXITED($?)) or $pid == -1) {
1529 my $secs = time - $start_time;
1530 $secs = $secs == 1 ? '1 second' : "$secs seconds";
1531 return;
1532 }
1533 sleep 1;
1534 }
1535 }
1536 die "Unable to kill process: $target_pid";
1537 }
1538
1539 sub report_summary_result
1540 {
1541 my ($test, $bug_number, $result, $description,
1542 $expected, $actual, $reason) = @_;
1543
1544 $description =~ s/[\n\r]+/ /mg;
1545 $expected =~ s/[\n\r]+/ /mg;
1546 $actual =~ s/[\n\r]+/ /mg;
1547 $reason =~ s/[\n\r]+/ /mg;
1548
1549 if ($result !~ /PASSED/)
1550 {
1551 $failures_reported++;
1552 }
1553
1554 print STDERR ("jstest: $test " .
1555 "bug: $bug_number " .
1556 "result: $result " .
1557 "type: shell " .
1558 "description: $description " .
1559 "expected: $expected " .
1560 "actual: $actual " .
1561 "reason: $reason" .
1562 "\n");
1563
1564 }