The branch master has been updated via 30f1c9c4e08d479ab57fa6974dd99b077c745ffb (commit) via 7e46e56acaa27933663a455cf819d841d4dbc436 (commit) via 34a6a9b1599788ce4e85a08d579ff19bcb6a4b89 (commit) from b6ef12c4baa3a2c1ff0e3ac71270588dfcfe8cbd (commit)
- Log ----------------------------------------------------------------- commit 30f1c9c4e08d479ab57fa6974dd99b077c745ffb Author: Richard Levitte <levi...@openssl.org> Date: Tue Mar 21 11:26:28 2017 +0100 Adapt 20-test_enc.t and 20-test_enc_more.t to use statusvar Reviewed-by: Rich Salz <rs...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3004) commit 7e46e56acaa27933663a455cf819d841d4dbc436 Author: Richard Levitte <levi...@openssl.org> Date: Tue Mar 21 10:58:46 2017 +0100 Adapt 80-test_ssl_old.t to use statusvar Reviewed-by: Rich Salz <rs...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3004) commit 34a6a9b1599788ce4e85a08d579ff19bcb6a4b89 Author: Richard Levitte <levi...@openssl.org> Date: Tue Mar 21 10:53:56 2017 +0100 OpenSSL::Test: add a statusvar option for run with capture => 1 When using run() with capture => 1, there was no way to find out if the command was successful or not. This change adds a statusvar option, that must refer to a scalar variable, for example: my $status = undef; my @line = run(["whatever"], capture => 1, statusvar => \$status); $status will be 1 if the command "whatever" was successful, 0 otherwise. Reviewed-by: Rich Salz <rs...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3004) ----------------------------------------------------------------------- Summary of changes: test/recipes/20-test_enc.t | 19 ++++++++++--------- test/recipes/20-test_enc_more.t | 15 ++++++++++----- test/recipes/80-test_ssl_old.t | 21 ++++++++++++++++----- test/testlib/OpenSSL/Test.pm | 17 ++++++++++++++--- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/test/recipes/20-test_enc.t b/test/recipes/20-test_enc.t index 88a5890..32a3016 100644 --- a/test/recipes/20-test_enc.t +++ b/test/recipes/20-test_enc.t @@ -27,20 +27,21 @@ my $test = catfile(".", "p"); my $cmd = "openssl"; +my $ciphersstatus = undef; my @ciphers = map { s/^\s+//; s/\s+$//; split /\s+/ } - run(app([$cmd, "list", "-cipher-commands"]), capture => 1); + run(app([$cmd, "list", "-cipher-commands"]), + capture => 1, statusvar => \$ciphersstatus); -plan tests => 1 + (scalar @ciphers)*2; - -my $init = ok(copy($testsrc,$test)); - -if (!$init) { - diag("Trying to copy $testsrc to $test : $!"); -} +plan tests => 2 + (scalar @ciphers)*2; SKIP: { - skip "Not initialized, skipping...", 11 unless $init; + skip "Problems getting ciphers...", 1 + scalar(@ciphers) + unless ok($ciphersstatus, "Running 'openssl list -cipher-commands'"); + unless (ok(copy($testsrc, $test), "Copying $testsrc to $test")) { + diag($!); + skip "Not initialized, skipping...", scalar(@ciphers); + } foreach my $c (@ciphers) { my %variant = ("$c" => [], diff --git a/test/recipes/20-test_enc_more.t b/test/recipes/20-test_enc_more.t index 1419ddb..b4cef69 100644 --- a/test/recipes/20-test_enc_more.t +++ b/test/recipes/20-test_enc_more.t @@ -28,17 +28,22 @@ my $plaintext = catfile(".", "testdatafile"); my $fail = ""; my $cmd = "openssl"; +my $ciphersstatus = undef; my @ciphers = grep(! /wrap|^$|^[^-]/, (map { split /\s+/ } - run(app([$cmd, "enc", "-ciphers"]), capture => 1))); + run(app([$cmd, "enc", "-ciphers"]), + capture => 1, statusvar => \$ciphersstatus))); -plan tests => 1 + scalar @ciphers; - -my $init = ok(copy($testsrc, $plaintext)); +plan tests => 2 + scalar @ciphers; SKIP: { - skip "Not initialized, skipping...", (scalar @ciphers) unless $init; + skip "Problems getting ciphers...", 1 + scalar(@ciphers) + unless ok($ciphersstatus, "Running 'openssl enc -ciphers'"); + unless (ok(copy($testsrc, $plaintext), "Copying $testsrc to $plaintext")) { + diag($!); + skip "Not initialized, skipping...", scalar(@ciphers); + } foreach my $cipher (@ciphers) { my $ciphername = substr $cipher, 1; diff --git a/test/recipes/80-test_ssl_old.t b/test/recipes/80-test_ssl_old.t index a790d9b..8b6f538 100644 --- a/test/recipes/80-test_ssl_old.t +++ b/test/recipes/80-test_ssl_old.t @@ -424,11 +424,17 @@ sub testssl { push @protocols, "-ssl3" unless $no_ssl3; my $protocolciphersuitecount = 0; my %ciphersuites = (); + my %ciphersstatus = (); foreach my $protocol (@protocols) { - $ciphersuites{$protocol} = - [ map { s|\R||; split(/:/, $_) } - run(app(["openssl", "ciphers", "-s", $protocol, - "ALL:$ciphers"]), capture => 1) ]; + my $ciphersstatus = undef; + my @ciphers = run(app(["openssl", "ciphers", "-s", $protocol, + "ALL:$ciphers"]), + capture => 1, statusvar => \$ciphersstatus); + $ciphersstatus{$protocol} = $ciphersstatus; + if ($ciphersstatus) { + $ciphersuites{$protocol} = [ map { s|\R||; split(/:/, $_) } + @ciphers ]; + } $protocolciphersuitecount += scalar @{$ciphersuites{$protocol}}; } @@ -437,7 +443,12 @@ sub testssl { # The count of protocols is because in addition to the ciphersuits # we got above, we're running a weak DH test for each protocol - plan tests => $protocolciphersuitecount + scalar(keys %ciphersuites); + plan tests => scalar(@protocols) + $protocolciphersuitecount + + scalar(keys %ciphersuites); + + foreach my $protocol (@protocols) { + ok($ciphersstatus{$protocol}, "Getting ciphers for $protocol"); + } foreach my $protocol (sort keys %ciphersuites) { note "Testing ciphersuites for $protocol"; diff --git a/test/testlib/OpenSSL/Test.pm b/test/testlib/OpenSSL/Test.pm index 66fa4dc..cbfc867 100644 --- a/test/testlib/OpenSSL/Test.pm +++ b/test/testlib/OpenSSL/Test.pm @@ -403,6 +403,12 @@ return the resulting output as an array of lines. If false or not given, the command will be executed with C<system()>, and C<run> will return 1 if the command was successful or 0 if it wasn't. +=item B<statusvar =E<gt> VARREF> + +If used, B<VARREF> must be a reference to a scalar variable. It will be +assigned a boolean indicating if the command succeeded or not. This is +particularly useful together with B<capture>. + =back For further discussion on what is considered a successful command or not, see @@ -427,6 +433,9 @@ sub run { my $r = 0; my $e = 0; + die "OpenSSL::Test::run(): statusvar value not a scalar reference" + if $opts{statusvar} && ref($opts{statusvar}) ne "SCALAR"; + # In non-verbose, we want to shut up the command interpreter, in case # it has something to complain about. On VMS, it might complain both # on stdout and stderr @@ -445,11 +454,13 @@ sub run { # to make it easier to compare with a manual run of the command. if ($opts{capture}) { @r = `$prefix$cmd`; - $e = ($? & 0x7f) ? ($? & 0x7f)|0x80 : ($? >> 8); } else { system("$prefix$cmd"); - $e = ($? & 0x7f) ? ($? & 0x7f)|0x80 : ($? >> 8); - $r = $hooks{exit_checker}->($e); + } + $e = ($? & 0x7f) ? ($? & 0x7f)|0x80 : ($? >> 8); + $r = $hooks{exit_checker}->($e); + if ($opts{statusvar}) { + ${$opts{statusvar}} = $r; } if ($ENV{HARNESS_ACTIVE} && !$ENV{HARNESS_VERBOSE}) { _____ openssl-commits mailing list To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-commits