Codebase list openssl / a515c82
Fix exit code for VMS in util/wrap.pl and test/run_tests.pl The exit code for VMS is a bit tricky, and while perl translates the VMS status code from a typical C program to posix terms, it doesn't automatically translate its exit code into the typical C program VMS status code. Perl scripts are recommended to do so explicitly. Therefore, we make util/wrap.pl and test/run_tests.pl simulate the typical C program VMS status code for all non-zero exit codes, except we give them all the error severity (according to the VMS C library reference manual, exit codes 2 and above are treated as success...). Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15787) Richard Levitte authored 2 years ago Matt Caswell committed 2 years ago
2 changed file(s) with 32 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
313313 $harness->runtests(map { [ abs2rel($_, rel2abs(curdir())), basename($_) ] }
314314 sort { reorder($a) cmp reorder($b) } keys %tests);
315315
316 # $ret->has_errors may be any number, not just 0 or 1. On VMS, numbers
317 # from 2 and on are used as is as VMS statuses, which has severity encoded
318 # in the lower 3 bits. 0 and 1, on the other hand, generate SUCCESS and
319 # FAILURE, so for currect reporting on all platforms, we make sure the only
320 # exit codes are 0 and 1. Double-bang is the trick to do so.
321 exit !!$ret->has_errors if (ref($ret) eq "TAP::Parser::Aggregator");
316 # If this is a TAP::Parser::Aggregator, $ret->has_errors is the count of
317 # tests that failed. We don't bother with that exact number, just exit
318 # with an appropriate exit code when it isn't zero.
319 if (ref($ret) eq "TAP::Parser::Aggregator") {
320 exit 0 unless $ret->has_errors;
321 exit 1 unless $^O eq 'VMS';
322 # On VMS, perl converts an exit 1 to SS$_ABORT (%SYSTEM-F-ABORT), which
323 # is a bit harsh. As per perl recommendations, we explicitly use the
324 # same VMS status code as typical C programs would for exit(1), except
325 # we set the error severity rather than success.
326 # Ref: https://perldoc.perl.org/perlport#exit
327 # https://perldoc.perl.org/perlvms#$?
328 exit 0x35a000 # C facility code
329 + 8 # 1 << 3 (to make space for the 3 severity bits)
330 + 2 # severity: E(rror)
331 + 0x10000000; # bit 28 set => the shell stays silent
332 }
322333
323334 # If this isn't a TAP::Parser::Aggregator, it's the pre-TAP test harness,
324335 # which simply dies at the end if any test failed, so we don't need to bother
4545 exit(($? & 255) | 128) if ($? & 255) != 0;
4646
4747 # When not a signal, just shift down the subprocess exit code and use that.
48 exit($? >> 8);
48 my $exitcode = $? >> 8;
49
50 # For VMS, perl recommendations is to emulate what the C library exit() does
51 # for all non-zero exit codes, except we set the error severity rather than
52 # success.
53 # Ref: https://perldoc.perl.org/perlport#exit
54 # https://perldoc.perl.org/perlvms#$?
55 if ($^O eq 'VMS' && $exitcode != 0) {
56 $exitcode =
57 0x35a000 # C facility code
58 + ($exitcode * 8) # shift up to make space for the 3 severity bits
59 + 2 # Severity: E(rror)
60 + 0x10000000; # bit 28 set => the shell stays silent
61 }
62 exit($exitcode);