nsprpub/pr/tests/runtests.pl

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial