Refuse to run test_cipherlist unless shared library matches build
[openssl.git] / util / perl / OpenSSL / Test.pm
index f8fcbe906de8dd209f47c6224f8d622b681ebb41..f4b1b50d8b8a14a5d44ca7cfe51072cfd3e03b1b 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
 #
 # Licensed under the OpenSSL license (the "License").  You may not use
 # this file except in compliance with the License.  You can obtain a copy
@@ -21,7 +21,8 @@ $VERSION = "0.8";
 @EXPORT_OK = (@Test::More::EXPORT_OK, qw(bldtop_dir bldtop_file
                                          srctop_dir srctop_file
                                          data_file
-                                         pipe with cmdstr quotify));
+                                         pipe with cmdstr quotify
+                                         openssl_versions));
 
 =head1 NAME
 
@@ -93,7 +94,7 @@ my %hooks = (
     # exit_checker is used by run() directly after completion of a command.
     # it receives the exit code from that command and is expected to return
     # 1 (for success) or 0 (for failure).  This is the status value that run()
-    # will give back (through the |statusvar| referens and as returned value
+    # will give back (through the |statusvar| reference and as returned value
     # when capture => 1 doesn't apply).
     exit_checker => sub { return shift == 0 ? 1 : 0 },
 
@@ -476,7 +477,9 @@ sub run {
        }
        close $pipe;
     } else {
+       $ENV{HARNESS_OSSL_PREFIX} = "# ";
        system("$prefix$cmd");
+       delete $ENV{HARNESS_OSSL_PREFIX};
     }
     $e = ($? & 0x7f) ? ($? & 0x7f)|0x80 : ($? >> 8);
     $r = $hooks{exit_checker}->($e);
@@ -661,7 +664,7 @@ sub pipe {
 
 =item B<with HASHREF, CODEREF>
 
-C<with> will temporarly install hooks given by the HASHREF and then execute
+C<with> will temporarily install hooks given by the HASHREF and then execute
 the given CODEREF.  Hooks are usually expected to have a coderef as value.
 
 The currently available hoosk are:
@@ -707,7 +710,7 @@ sub with {
 C<cmdstr> takes a CODEREF from C<app> or C<test> and simply returns the
 command as a string.
 
-C<cmdstr> takes some additiona options OPTS that affect the string returned:
+C<cmdstr> takes some additional options OPTS that affect the string returned:
 
 =over 4
 
@@ -758,12 +761,13 @@ I<This must never ever be done on VMS.>
 sub quotify {
     # Unix setup (default if nothing else is mentioned)
     my $arg_formatter =
-       sub { $_ = shift; /\s|[\{\}\\\$\[\]\*\?\|\&:;<>]/ ? "'$_'" : $_ };
+       sub { $_ = shift;
+             ($_ eq '' || /\s|[\{\}\\\$\[\]\*\?\|\&:;<>]/) ? "'$_'" : $_ };
 
     if ( $^O eq "VMS") {       # VMS setup
        $arg_formatter = sub {
            $_ = shift;
-           if (/\s|["[:upper:]]/) {
+           if ($_ eq '' || /\s|["[:upper:]]/) {
                s/"/""/g;
                '"'.$_.'"';
            } else {
@@ -773,7 +777,7 @@ sub quotify {
     } elsif ( $^O eq "MSWin32") { # MSWin setup
        $arg_formatter = sub {
            $_ = shift;
-           if (/\s|["\|\&\*\;<>]/) {
+           if ($_ eq '' || /\s|["\|\&\*\;<>]/) {
                s/(["\\])/\\$1/g;
                '"'.$_.'"';
            } else {
@@ -785,6 +789,32 @@ sub quotify {
     return map { $arg_formatter->($_) } @_;
 }
 
+=over 4
+
+=item B<openssl_versions>
+
+Returns a list of two numbers, the first representing the build version,
+the second representing the library version.  See opensslv.h for more
+information on those numbers.
+
+= back
+
+=cut
+
+my @versions = ();
+sub openssl_versions {
+    unless (@versions) {
+        my %lines =
+            map { s/\R$//;
+                  /^(.*): (0x[[:xdigit:]]{8})$/;
+                  die "Weird line: $_" unless defined $1;
+                  $1 => hex($2) }
+            run(test(['versions']), capture => 1);
+        @versions = ( $lines{'Build version'}, $lines{'Library version'} );
+    }
+    return @versions;
+}
+
 ######################################################################
 # private functions.  These are never exported.
 
@@ -905,9 +935,9 @@ sub __test_file {
 
     my $e = pop || "";
     my $f = pop;
-    $f = catfile($directories{BLDTEST},@_,$f . $e);
-    $f = catfile($directories{SRCTEST},@_,$f) unless -f $f;
-    return $f;
+    my $out = catfile($directories{BLDTEST},@_,$f . $e);
+    $out = catfile($directories{SRCTEST},@_,$f) unless -f $out;
+    return $out;
 }
 
 sub __apps_file {
@@ -915,9 +945,9 @@ sub __apps_file {
 
     my $e = pop || "";
     my $f = pop;
-    $f = catfile($directories{BLDAPPS},@_,$f . $e);
-    $f = catfile($directories{SRCAPPS},@_,$f) unless -f $f;
-    return $f;
+    my $out = catfile($directories{BLDAPPS},@_,$f . $e);
+    $out = catfile($directories{SRCAPPS},@_,$f) unless -f $out;
+    return $out;
 }
 
 sub __fuzz_file {
@@ -925,9 +955,9 @@ sub __fuzz_file {
 
     my $e = pop || "";
     my $f = pop;
-    $f = catfile($directories{BLDFUZZ},@_,$f . $e);
-    $f = catfile($directories{SRCFUZZ},@_,$f) unless -f $f;
-    return $f;
+    my $out = catfile($directories{BLDFUZZ},@_,$f . $e);
+    $out = catfile($directories{SRCFUZZ},@_,$f) unless -f $out;
+    return $out;
 }
 
 sub __data_file {
@@ -1015,7 +1045,7 @@ sub __cwd {
     }
 
     # We put back new values carefully.  Doing the obvious
-    # %directories = ( %tmp_irectories )
+    # %directories = ( %tmp_directories )
     # will clear out any value that happens to be an absolute path
     foreach (keys %tmp_directories) {
         $directories{$_} = $tmp_directories{$_};
@@ -1084,11 +1114,6 @@ sub __fixup_prg {
        $prefix = ($prog =~ /^(?:[\$a-z0-9_]+:)?[<\[]/i ? "mcr " : "mcr []");
     }
 
-    # We test if the program to use exists.
-    if ( ! -x $prog ) {
-       $prog = undef;
-    }
-
     if (defined($prog)) {
        # Make sure to quotify the program file on platforms that may
        # have spaces or similar in their path name.
@@ -1151,7 +1176,7 @@ L<Test::More>, L<Test::Harness>
 
 =head1 AUTHORS
 
-Richard Levitte E<lt>levitte@openssl.orgE<gt> with assitance and
+Richard Levitte E<lt>levitte@openssl.orgE<gt> with assistance and
 inspiration from Andy Polyakov E<lt>appro@openssl.org<gt>.
 
 =cut