2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 use POSIX
qw(sys_wait_h);
12 my ($target_pid) = @_;
13 my $start_time = time;
15 # Try to kill and wait 10 seconds, then try a kill -9
17 for $sig ('TERM', 'KILL') {
18 print "kill $sig $target_pid\n";
19 kill $sig => $target_pid;
20 my $interval_start = time;
21 while (time - $interval_start < 10) {
22 # the following will work with 'cygwin' perl on win32, but not
23 # with 'MSWin32' (ActiveState) perl
24 my $pid = waitpid($target_pid, POSIX
::WNOHANG
());
25 if (($pid == $target_pid and POSIX
::WIFEXITED
($?
)) or $pid == -1) {
26 my $secs = time - $start_time;
27 $secs = $secs == 1 ?
'1 second' : "$secs seconds";
28 print "Process killed. Took $secs to die.\n";
34 die "Unable to kill process: $target_pid";
37 # Stripped down version of fork_and_log().
38 sub system_fork_and_log
{
39 # Fork a sub process and log the output.
42 my $pid = fork; # Fork off a child process.
44 unless ($pid) { # child
45 exec { $cmd->[0] } @
$cmd;
46 die "Could not exec()";
53 # Wait for a process to exit or kill it if it takes too long.
54 my ($pid, $timeout_secs) = @_;
55 my ($exit_value, $signal_num, $dumped_core, $timed_out) = (0,0,0,0);
59 die ("Invalid timeout value passed to wait_for_pid()\n")
60 if ($timeout_secs <= 0);
64 while (++$loop_count < $timeout_secs) {
65 my $wait_pid = waitpid($pid, POSIX
::WNOHANG
());
66 # the following will work with 'cygwin' perl on win32, but not
67 # with 'MSWin32' (ActiveState) perl
68 last if ($wait_pid == $pid and POSIX
::WIFEXITED
($?
)) or $wait_pid == -1;
72 $exit_value = $?
>> 8;
73 $signal_num = $?
>> 127;
74 $dumped_core = $?
& 128;
75 if ($loop_count >= $timeout_secs) {
82 if ($@
=~ /timeout/) {
85 } else { # Died for some other reason.
86 die; # Propagate the error up.
89 # $sig_name = $signal_num ? signal_name($signal_num) : '';
91 # return { timed_out=>$timed_out,
92 # exit_value=>$exit_value,
93 # sig_name=>$sig_name,
94 # dumped_core=>$dumped_core };
97 # System version of run_cmd().
99 my ($cmd, $timeout_secs) = @_;
101 # print_log "cmd = $cmd\n";
102 my $pid = system_fork_and_log
($cmd);
103 my $result = wait_for_pid
($pid, $timeout_secs);
109 # Given profile directory, find pref file hidden in salt directory.
110 # profile $Settings::MozProfileName must exist before calling this sub.
113 my $profile_dir = shift;
116 my $pref_file = "prefs.js";
118 unless (-e
$profile_dir) {
123 my $sub = sub {$pref_file = $File::Find
::name
, $found++ if $pref_file eq $_};
124 File
::Find
::find
($sub, $profile_dir);
135 my $app_name = `grep "MOZ_APP_NAME " config/autoconf.mk | sed "s/.*= //"`;
138 # On mac, the app directory is the product name with the first
141 my $toolkit = `grep "MOZ_WIDGET_TOOLKIT " config/autoconf.mk |sed "s/.*= //"`;
144 if ($toolkit =~ /(mac|cocoa)/) {
145 my $app_dir = uc(substr($app_name, 0, 1)).substr($app_name, 1);
146 chdir "dist/$app_dir.app/Contents/MacOS";
152 if ($toolkit =~ /(windows|os2)/) {
153 $bin_suffix = ".exe";
156 my $old_home = $ENV{HOME
};
159 # Create a profile to test with.
160 run_system_cmd
(["./".$app_name.$bin_suffix, "-createProfile", "testprofile"], 45);
162 my $pref_file = find_pref_file
(".mozilla/".$app_name);
163 open PREFS
, ">>$pref_file";
164 # Add allow_scripts_to_close_windows; this lets us cleanly exit.
165 print PREFS
"user_pref(\"dom.allow_scripts_to_close_windows\", true);\n";
166 # Suppress the default browser dialog since it keeps the test from starting.
167 print PREFS
"user_pref(\"browser.shell.checkDefaultBrowser\", false);\n";
170 # Run the pageload test.
171 run_system_cmd
(["./".$app_name.$bin_suffix, $ENV{PAGELOAD_URL
}."/loader.pl?maxcyc=2&delay=500&nocache=0&timeout=30000&auto=1"], 240);
173 # Start up again; this will gather data for reading global history and
174 # reading the fastload file.
175 run_system_cmd
(["./".$app_name.$bin_suffix, "file://$topdir/build/profile_pageloader.html"], 45);