~ubuntu-branches/ubuntu/utopic/xulrunner-1.9/utopic

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/tests/runtests.pl

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack, Alexander Sack, Fabien Tassin
  • Date: 2009-02-05 09:12:37 UTC
  • mfrom: (1.1.16 upstream)
  • Revision ID: james.westby@ubuntu.com-20090205091237-2uu65i47p00yi2xk
Tags: 1.9.0.6+nobinonly-0ubuntu1
[ Alexander Sack <asac@ubuntu.com> ]
* new security/stability update v1.9.0.6 (FIREFOX_3_0_6_RELEASE)
  - see USN-717-1
* adjust patches to changed code base
  - update debian/patches/dom_inspector_support_for_prism.patch

[ Fabien Tassin <fta@ubuntu.com> ]
* Fix preinst script to better handle the /etc/gre.d clean-up
  - update debian/xulrunner-1.9.preinst.in
* Fix permissions in the -dev package (LP: #303940)
  - update debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#
 
3
# ***** BEGIN LICENSE BLOCK *****
 
4
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
5
#
 
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/
 
10
#
 
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
 
14
# License.
 
15
#
 
16
# The Original Code is the Netscape Portable Runtime (NSPR).
 
17
#
 
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.
 
22
#
 
23
# Contributor(s):
 
24
#   Christophe Ravel <christophe.ravel@sun.com>, Sun Microsystems
 
25
#   Slavomir Katuscak <slavomir.katuscak@sun.com>, Sun Microsystems
 
26
#
 
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.
 
38
#
 
39
# ***** END LICENSE BLOCK *****
 
40
 
 
41
use POSIX qw(:sys_wait_h);
 
42
use POSIX qw(setsid);
 
43
use FileHandle;
 
44
 
 
45
# Constants
 
46
$WINOS = "MSWin32";
 
47
 
 
48
$osname = $^O;
 
49
 
 
50
use Cwd;
 
51
if ($osname =~ $WINOS) {
 
52
    # Windows
 
53
    require Win32::Process;
 
54
    require Win32;
 
55
}
 
56
 
 
57
# Get environment variables.
 
58
$output_file = $ENV{NSPR_TEST_LOGFILE};
 
59
$timeout = $ENV{TEST_TIMEOUT};
 
60
 
 
61
$timeout = 0 if (!defined($timeout));
 
62
 
 
63
sub getTime {
 
64
    ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
 
65
 
 
66
    $year = 1900 + $yearOffset;
 
67
 
 
68
    $theTime = sprintf("%04d-%02d-%02d %02d:%02d:%02d",$year,$month,$dayOfMonth,$hour,$minute,$second);
 
69
    return $theTime;
 
70
}
 
71
 
 
72
sub open_log {
 
73
 
 
74
    if (!defined($output_file)) {
 
75
        print "No output file.\n";
 
76
        # null device
 
77
        if ($osname =~ $WINOS) {
 
78
            $output_file = "nul";
 
79
        } else {
 
80
            $output_file = "/dev/null";
 
81
        }
 
82
    }
 
83
    
 
84
    # use STDOUT for OF (to print summary of test results)
 
85
    open(OF, ">&STDOUT") or die "Can't reuse STDOUT for OF\n";
 
86
    OF->autoflush;
 
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";
 
89
    STDOUT->autoflush;
 
90
    # redirect STDERR to STDOUT
 
91
    open(STDERR, ">&STDOUT") or die "Can't redirect STDERR to STDOUT\n";
 
92
    STDERR->autoflush;
 
93
    
 
94
    # Print header test in summary
 
95
    $now = getTime;
 
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";
 
101
}
 
102
 
 
103
sub close_log {
 
104
    # end of test marker in summary
 
105
    $now = getTime;
 
106
    print OF "END\t\t\t$now\n";
 
107
 
 
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";
 
111
}
 
112
 
 
113
sub print_begin {
 
114
$lprog = shift;
 
115
 
 
116
    # Summary output
 
117
    print OF "$prog";
 
118
    # Full output
 
119
    $now = getTime;
 
120
    print "BEGIN TEST: $lprog ($now)\n\n";
 
121
}
 
122
 
 
123
sub print_end {
 
124
($lprog, $exit_status, $exit_signal, $exit_core) = @_;
 
125
 
 
126
    if (($exit_status == 0) && ($exit_signal == 0) && ($exit_core == 0)) {
 
127
        $str_status = "Passed";
 
128
    } else {
 
129
        $str_status = "FAILED";
 
130
    }
 
131
    if ($exit_signal != 0) {
 
132
        $str_signal = " - signal $exit_signal";
 
133
    } else {
 
134
        $str_signal = "";
 
135
    }
 
136
    if ($exit_core != 0) {
 
137
        $str_core = " - core dumped";
 
138
    } else {
 
139
        $str_core = "";
 
140
    }
 
141
    $now = getTime;
 
142
    # Full output
 
143
    print "\nEND TEST: $lprog ($now)\n";
 
144
    print "TEST STATUS: $lprog = $str_status (exit status " . $exit_status . $str_signal . $str_core . ")\n";
 
145
    print "--------------------------------------------------\n\n";
 
146
    # Summary output
 
147
    print OF "\t\t\t$str_status\n";
 
148
}
 
149
 
 
150
sub ux_start_prog {
 
151
# parameters:
 
152
$lprog = shift; # command to run
 
153
 
 
154
    # Create a process group for the child
 
155
    # so we can kill all of it if needed
 
156
    setsid or die "setsid failed: $!";
 
157
    # Start test program    
 
158
    exec("./$lprog");
 
159
    # We should not be here unless exec failed.
 
160
    print "Faild to exec $lprog";
 
161
    exit 1 << 8;
 
162
}   
 
163
 
 
164
sub ux_wait_timeout {
 
165
# parameters:
 
166
$lpid = shift;     # child process id
 
167
$ltimeout = shift; # timeout
 
168
 
 
169
    if ($ltimeout == 0) {
 
170
        # No timeout: use blocking wait
 
171
        $ret = waitpid($lpid,0);
 
172
        # Exit and don't kill
 
173
        $lstatus = $? % 256;
 
174
        $ltimeout = -1;
 
175
    } else {
 
176
        while ($ltimeout > 0) {
 
177
            # Check status of child using non blocking wait
 
178
            $ret = waitpid($lpid, WNOHANG);
 
179
            if ($ret == 0) {
 
180
                # Child still running
 
181
    #           print "Time left=$ltimeout\n";
 
182
                sleep 1;
 
183
                $ltimeout--;
 
184
            } else {
 
185
                # Child has ended
 
186
                $lstatus = $?;
 
187
                # Exit the wait loop and don't kill
 
188
                $ltimeout = -1;
 
189
            }
 
190
        }
 
191
    }
 
192
    
 
193
    if ($ltimeout == 0) {
 
194
        # we ran all the timeout: it's time to kill the child
 
195
        print "Timeout ! Kill child process $lpid\n";
 
196
        # Kill the child process and group
 
197
        kill(-9,$lpid);
 
198
        $lstatus = 9;
 
199
    }
 
200
    
 
201
    return $lstatus;
 
202
}
 
203
 
 
204
sub ux_test_prog {
 
205
# parameters:
 
206
$prog = shift;  # Program to test
 
207
 
 
208
    $child_pid = fork;
 
209
    if ($child_pid == 0) {
 
210
        # we are in the child process
 
211
        print_begin($prog);
 
212
        ux_start_prog($prog);
 
213
    } else {
 
214
        # we are in the parent process
 
215
        $status = ux_wait_timeout($child_pid,$timeout);
 
216
        # See Perlvar for documentation of $?
 
217
        # exit status = $status >> 8
 
218
        # exit signal = $status & 127 (no signal = 0)
 
219
        # core dump = $status & 128 (no core = 0)
 
220
        print_end($prog, $status >> 8, $status & 127, $status & 128);
 
221
    }
 
222
 
 
223
    return $status;
 
224
}
 
225
 
 
226
sub win_path {
 
227
$lpath = shift;
 
228
 
 
229
    # MSYS drive letter = /c/ -> c:/
 
230
    $lpath =~ s/^\/(\w)\//$1:\//;
 
231
    # Cygwin drive letter = /cygdrive/c/ -> c:/
 
232
    $lpath =~ s/^\/cygdrive\/(\w)\//$1:\//;
 
233
    # replace / with \\
 
234
    $lpath =~ s/\//\\\\/g;
 
235
    
 
236
    return $lpath;
 
237
}
 
238
 
 
239
sub win_ErrorReport{
 
240
    print Win32::FormatMessage( Win32::GetLastError() );
 
241
}
 
242
 
 
243
sub win_test_prog {
 
244
# parameters:
 
245
$prog = shift;  # Program to test
 
246
 
 
247
    $status = 1;
 
248
    $curdir = getcwd;
 
249
    $curdir = win_path($curdir);
 
250
    $prog_path = "$curdir\\$prog.exe";
 
251
    
 
252
    print_begin($prog);
 
253
    
 
254
    Win32::Process::Create($ProcessObj,
 
255
                           "$prog_path",
 
256
                           "$prog",
 
257
                           0,
 
258
                           NORMAL_PRIORITY_CLASS,
 
259
                           ".")|| die win_ErrorReport();
 
260
    $retwait = $ProcessObj->Wait($timeout * 1000);
 
261
        
 
262
    if ( $retwait == 0) {
 
263
        # the prog didn't finish after the timeout: kill
 
264
        $ProcessObj->Kill($status);
 
265
        print "Timeout ! Process killed with exit status $status\n";
 
266
    } else {
 
267
        # the prog finished before the timeout: get exit status
 
268
        $ProcessObj->GetExitCode($status);
 
269
    }
 
270
    # There is no signal, no core on Windows
 
271
    print_end($prog, $status, 0, 0);
 
272
 
 
273
    return $status
 
274
}
 
275
 
 
276
# MAIN ---------------
 
277
@progs = (
 
278
"accept",
 
279
"acceptread",
 
280
"acceptreademu",
 
281
"affinity",
 
282
"alarm",
 
283
"anonfm",
 
284
"atomic",
 
285
"attach",
 
286
"bigfile",
 
287
"cleanup",
 
288
"cltsrv",
 
289
"concur",
 
290
"cvar",
 
291
"cvar2",
 
292
"dlltest",
 
293
"dtoa",
 
294
"errcodes",
 
295
"exit",
 
296
"fdcach",
 
297
"fileio",
 
298
"foreign",
 
299
"formattm",
 
300
"fsync",
 
301
"gethost",
 
302
"getproto",
 
303
"i2l",
 
304
"initclk",
 
305
"inrval",
 
306
"instrumt",
 
307
"intrio",
 
308
"intrupt",
 
309
"io_timeout",
 
310
"ioconthr",
 
311
"join",
 
312
"joinkk",
 
313
"joinku",
 
314
"joinuk",
 
315
"joinuu",
 
316
"layer",
 
317
"lazyinit",
 
318
"libfilename",
 
319
"lltest",
 
320
"lock",
 
321
"lockfile",
 
322
"logger",
 
323
"many_cv",
 
324
"multiwait",
 
325
"nameshm1",
 
326
"nblayer",
 
327
"nonblock",
 
328
"ntioto",
 
329
"ntoh",
 
330
"op_2long",
 
331
"op_excl",
 
332
"op_filnf",
 
333
"op_filok",
 
334
"op_nofil",
 
335
"parent",
 
336
"peek",
 
337
"perf",
 
338
"pipeping",
 
339
"pipeping2",
 
340
"pipeself",
 
341
"poll_nm",
 
342
"poll_to",
 
343
"pollable",
 
344
"prftest",
 
345
"primblok",
 
346
"provider",
 
347
"prpollml",
 
348
"ranfile",
 
349
"randseed",
 
350
"rwlocktest",
 
351
"sel_spd",
 
352
"selct_er",
 
353
"selct_nm",
 
354
"selct_to",
 
355
"selintr",
 
356
"sema",
 
357
"semaerr",
 
358
"semaping",
 
359
"sendzlf",
 
360
"server_test",
 
361
"servr_kk",
 
362
"servr_uk",
 
363
"servr_ku",
 
364
"servr_uu",
 
365
"short_thread",
 
366
"sigpipe",
 
367
"socket",
 
368
"sockopt",
 
369
"sockping",
 
370
"sprintf",
 
371
"stack",
 
372
"stdio",
 
373
"str2addr",
 
374
"strod",
 
375
"switch",
 
376
"system",
 
377
"testbit",
 
378
"testfile",
 
379
"threads",
 
380
"timemac",
 
381
"timetest",
 
382
"tpd",
 
383
"udpsrv",
 
384
"vercheck",
 
385
"version",
 
386
"writev",
 
387
"xnotify",
 
388
"zerolen");
 
389
 
 
390
open_log;
 
391
 
 
392
foreach $current_prog (@progs) {
 
393
    if ($osname =~ $WINOS) {
 
394
        win_test_prog($current_prog);
 
395
    } else {
 
396
        ux_test_prog($current_prog);
 
397
    }
 
398
}
 
399
 
 
400
close_log;