Refuse to run test_cipherlist unless shared library matches build
authorRichard Levitte <levitte@openssl.org>
Mon, 26 Mar 2018 09:00:05 +0000 (11:00 +0200)
committerRichard Levitte <levitte@openssl.org>
Sat, 31 Mar 2018 14:36:49 +0000 (16:36 +0200)
test/cipherlist_test.c is an internal consistency check, and therefore
requires that the shared library it runs against matches what it was
built for.  test/recipes/test_cipherlist.t is made to refuse running
unless library version and build version match.

This adds a helper program test/versions.c, that simply displays the
library and the build version.

Partially fixes #5751

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5753)

test/build.info
test/recipes/80-test_cipherlist.t
test/versions.c [new file with mode: 0644]
util/perl/OpenSSL/Test.pm

index c262248b6f2748ba1305ac7f817203429050d9e7..1c11ae13508c589c95f6a457a5db8c07d46b8ded 100644 (file)
@@ -1,5 +1,6 @@
 IF[{- !$disabled{tests} -}]
   PROGRAMS_NO_INST=\
+          versions \
           aborttest \
           sanitytest exdatatest bntest \
           ectest ecdsatest gmdifftest pbelutest ideatest \
@@ -19,6 +20,10 @@ IF[{- !$disabled{tests} -}]
           bioprinttest sslapitest dtlstest sslcorrupttest bio_enc_test \
           ocspapitest fatalerrtest
 
+  SOURCE[versions]=versions.c
+  INCLUDE[versions]=../include
+  DEPEND[versions]=../libcrypto
+
   SOURCE[aborttest]=aborttest.c
   INCLUDE[aborttest]=../include
   DEPEND[aborttest]=../libcrypto
index 98d537e5f368174e235fc21809a41cc95e63a637..6e869c85b4f741774131a1590f29cb5704c6913a 100644 (file)
@@ -12,11 +12,16 @@ use strict;
 use warnings;
 
 use OpenSSL::Test::Simple;
-use OpenSSL::Test;
+use OpenSSL::Test qw(:DEFAULT openssl_versions);
 use OpenSSL::Test::Utils qw(alldisabled available_protocols);
 
 setup("test_cipherlist");
 
+my ($build_version, $library_version) = openssl_versions();
+plan skip_all =>
+    "This test recipe isn't supported when doing regression testing"
+    if $build_version != $library_version;
+
 my $no_anytls = alldisabled(available_protocols("tls"));
 
 # If we have no protocols, then we also have no supported ciphers.
diff --git a/test/versions.c b/test/versions.c
new file mode 100644 (file)
index 0000000..3ab05ec
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright 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
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <stdio.h>
+#include <openssl/opensslv.h>
+#include <openssl/crypto.h>
+
+/* A simple helper for the perl function OpenSSL::Test::openssl_versions */
+int main(void)
+{
+    printf("Build version: 0x%08lX\n", OPENSSL_VERSION_NUMBER);
+    printf("Library version: 0x%08lX\n", OpenSSL_version_num());
+    return 0;
+}
index 5de7b58e8be404ac5d4e6b9514468b884be0f87e..a6be4878950a591a227b58c39f88f7fa5e2fac62 100644 (file)
@@ -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
 
@@ -695,6 +696,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.