2 # Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
10 no strict 'refs'; # To be able to use strings as function refs
13 use POSIX qw(strerror);
15 # We actually have space for up to 4095 error messages,
16 # numerically speaking... but we're currently only using
17 # numbers 1 through 127.
18 # This constant should correspond to the same constant
19 # defined in crypto/err/err.c, or at least must not be
20 # assigned a greater number.
21 use constant NUM_SYS_STR_REASONS => 127;
25 # These are POSIX error names, which Errno implements as functions
26 # (this is documented)
27 my @posix_errors = @{$Errno::EXPORT_TAGS{POSIX}};
29 plan tests => scalar @posix_errors
30 +1 # Checking that error 128 gives 'reason(128)'
31 +1 # Checking that error 0 gives the library name
34 foreach my $errname (@posix_errors) {
35 my $errnum = "Errno::$errname"->();
38 skip "Error $errname ($errnum) isn't within our range", 1
39 if $errnum > NUM_SYS_STR_REASONS;
42 # Set $! to the error number...
44 # ... and $! will give you the error string back
48 # We know that the system reasons are in OpenSSL error library 2
49 my @oerr = run(app([ qw(openssl errstr), sprintf("2%06x", $errnum) ]),
52 $oerr[0] =~ s|.*system library:||g; # The actual message is last
54 ok($oerr[0] eq $perr, "($errnum) '$oerr[0]' == '$perr'");
58 my @after = run(app([ qw(openssl errstr 2000080) ]), capture => 1);
60 $after[0] =~ s|.*system library:||g;
61 ok($after[0] eq "reason(128)", "(128) '$after[0]' == 'reason(128)'");
63 my @zero = run(app([ qw(openssl errstr 2000000) ]), capture => 1);
65 $zero[0] =~ s|.*system library:||g;
66 ok($zero[0] eq "system library", "(0) '$zero[0]' == 'system library'");