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 the Netscape Portable Runtime (NSPR).
18 # The Initial Developer of the Original Code is
19 # Sun Microsystems, Inc.
20 # Portions created by the Initial Developer are Copyright (C) 2008
21 # the Initial Developer. All Rights Reserved.
24 # Christophe Ravel <christophe.ravel@sun.com>, Sun Microsystems
25 # Slavomir Katuscak <slavomir.katuscak@sun.com>, Sun Microsystems
27 # Alternatively, the contents of this file may be used under the terms of
28 # either the GNU General Public License Version 2 or later (the "GPL"), or
29 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 # in which case the provisions of the GPL or the LGPL are applicable instead
31 # of those above. If you wish to allow use of your version of this file only
32 # under the terms of either the GPL or the LGPL, and not to allow others to
33 # use your version of this file under the terms of the MPL, indicate your
34 # decision by deleting the provisions above and replace them with the notice
35 # and other provisions required by the GPL or the LGPL. If you do not delete
36 # the provisions above, a recipient may use your version of this file under
37 # the terms of any one of the MPL, the GPL or the LGPL.
39 # ***** END LICENSE BLOCK *****
41 use POSIX
qw(:sys_wait_h);
51 if ($osname =~ $WINOS) {
53 require Win32
::Process
;
57 # Get environment variables.
58 $output_file = $ENV{NSPR_TEST_LOGFILE
};
59 $timeout = $ENV{TEST_TIMEOUT
};
61 $timeout = 0 if (!defined($timeout));
64 ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
66 $year = 1900 + $yearOffset;
68 $theTime = sprintf("%04d-%02d-%02d %02d:%02d:%02d",$year,$month,$dayOfMonth,$hour,$minute,$second);
74 if (!defined($output_file)) {
75 print "No output file.\n";
77 if ($osname =~ $WINOS) {
80 $output_file = "/dev/null";
84 # use STDOUT for OF (to print summary of test results)
85 open(OF
, ">&STDOUT") or die "Can't reuse STDOUT for OF\n";
87 # reassign STDOUT to $output_file (to print details of test results)
88 open(STDOUT
, ">$output_file") or die "Can't open file $output_file for STDOUT\n";
90 # redirect STDERR to STDOUT
91 open(STDERR
, ">&STDOUT") or die "Can't redirect STDERR to STDOUT\n";
94 # Print header test in summary
96 print OF
"\nNSPR Test Results - tests\n";
97 print OF
"\nBEGIN\t\t\t$now\n";
98 print OF
"NSPR_TEST_LOGFILE\t$output_file\n";
99 print OF
"TEST_TIMEOUT\t$timeout\n\n";
100 print OF
"\nTest\t\t\tResult\n\n";
104 # end of test marker in summary
106 print OF
"END\t\t\t$now\n";
108 close(OF
) or die "Can't close file OF\n";
109 close(STDERR
) or die "Can't close STDERR\n";
110 close(STDOUT
) or die "Can't close STDOUT\n";
120 print "BEGIN TEST: $lprog ($now)\n\n";
128 $str_status = "Passed";
130 $str_status = "FAILED";
134 print "\nEND TEST: $lprog ($now)\n";
135 print "TEST STATUS: $lprog = $str_status (errno $lstatus)\n";
136 print "--------------------------------------------------\n\n";
138 print OF
"\t\t\t$str_status\n";
143 $lprog = shift; # command to run
145 # Create a process group for the child
146 # so we can kill all of it if needed
147 setsid
or die "setsid failed: $!";
152 sub ux_wait_timeout
{
154 $lpid = shift; # child process id
155 $ltimeout = shift; # timeout
157 if ($ltimeout == 0) {
158 # No timeout: use blocking wait
159 $ret = waitpid($lpid,0);
160 # Exit and don't kill
164 while ($ltimeout > 0) {
165 # Check status of child using non blocking wait
166 $ret = waitpid($lpid, WNOHANG
);
168 # Child still running
169 # print "Time left=$ltimeout\n";
175 # Exit the wait loop and don't kill
181 if ($ltimeout == 0) {
182 # we ran all the timeout: it's time to kill the child
183 print "Timeout ! Kill child process $lpid\n";
184 # Kill the child process and group
194 $prog = shift; # Program to test
197 if ($child_pid == 0) {
198 # we are in the child process
200 ux_start_prog
($prog);
202 # we are in the parent process
203 $status = ux_wait_timeout
($child_pid,$timeout);
204 print_end
($prog, $status);
213 # MSYS drive letter = /c/ -> c:/
214 $lpath =~ s/^\/(\w)\//$1:\//;
215 # Cygwin drive letter = /cygdrive/c/ -> c:/
216 $lpath =~ s/^\/cygdrive\/(\w
)\
//$1:\
//;
218 $lpath =~ s/\//\\\\/g
;
224 print Win32
::FormatMessage
( Win32
::GetLastError
() );
229 $prog = shift; # Program to test
233 $curdir = win_path
($curdir);
234 $prog_path = "$curdir\\$prog.exe";
238 Win32
::Process
::Create
($ProcessObj,
242 NORMAL_PRIORITY_CLASS
,
243 ".")|| die win_ErrorReport
();
244 $retwait = $ProcessObj->Wait($timeout * 1000);
246 if ( $retwait == 0) {
247 # the prog didn't finish after the timeout: kill
248 $ProcessObj->Kill($status);
249 print "Timeout ! Process killed with error code $status\n";
251 # the prog finished before the timeout: get exit code
252 $ProcessObj->GetExitCode($status);
254 print_end
($prog,$status);
259 # MAIN ---------------
375 foreach $current_prog (@progs) {
376 # print "Current_prog=$current_prog\n";
377 if ($osname =~ $WINOS) {
378 win_test_prog
($current_prog);
380 ux_test_prog
($current_prog);