]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Remove the use of test/run_tests in favor of 'prove'
authorRichard Levitte <richard@levitte.org>
Sun, 14 Feb 2021 20:53:02 +0000 (21:53 +0100)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Tue, 16 Feb 2021 10:43:15 +0000 (11:43 +0100)
'prove' is a well developed TAP harness program, there's no real need
to write one's own.

We do need to set certain paths properly for the appropriate 'openssl'
program to be run.  We do that with a 'prove' plugin (WrapOpenSSL.pm)
that simply amends the appropriate system environment variables, given
a number of cmake generated environment variables that indicate where
OpenSSL files reside.

CMakeLists.txt
test/WrapOpenSSL.pm [new file with mode: 0644]
test/run_tests [deleted file]

index c14717acb6293b809b0f2997bc8bd749ed3ba220..c7c3ec98b9a52d49d2b89907e3c1b315e0537dbb 100644 (file)
@@ -9,6 +9,9 @@ include(CheckCSourceRuns)
 enable_testing()
 
 find_package(OpenSSL 3.0 REQUIRED)
+find_program(OPENSSL_PROGRAM openssl
+  PATHS ${OPENSSL_ROOT_DIR} PATH_SUFFIXES apps bin NO_DEFAULT_PATH)
+message("-- Found OpenSSL application: ${OPENSSL_PROGRAM}")
 include_directories(${OPENSSL_INCLUDE_DIR})
 
 if (CMAKE_C_COMPILER_ID MATCHES "Clang")
@@ -235,11 +238,17 @@ if(NOT SKIP_PERL_TESTS)
     execute_process(COMMAND perl -MTest2::V0 -e ""
        ERROR_QUIET RESULT_VARIABLE HAVE_TEST2_V0)
     if(NOT HAVE_TEST2_V0)
+        set(TEST_ENVIRONMENT
+          CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
+          PERL5LIB=${CMAKE_CURRENT_SOURCE_DIR}/test
+          OPENSSL_ENGINES=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+          OPENSSL_PROGRAM=${OPENSSL_PROGRAM}
+          OPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
+          OPENSSL_CONF=${CMAKE_CURRENT_SOURCE_DIR}/test/empty.cnf
+          )
        add_test(NAME engine
-           COMMAND perl run_tests
-           WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
-       set_tests_properties(engine PROPERTIES ENVIRONMENT
-           "OPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR};OPENSSL_ENGINES=${OUTPUT_DIRECTORY};OPENSSL_CONF=${CMAKE_SOURCE_DIR}/test/empty.cnf")
+           COMMAND prove --merge -PWrapOpenSSL ${CMAKE_CURRENT_SOURCE_DIR}/test)
+       set_tests_properties(engine PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}")
     else()
       message(STATUS "No Test2::V0 perl module (engine tests skipped)")
     endif()
diff --git a/test/WrapOpenSSL.pm b/test/WrapOpenSSL.pm
new file mode 100644 (file)
index 0000000..8d92af9
--- /dev/null
@@ -0,0 +1,67 @@
+#! /usr/bin/env perl
+#
+# CC0 license applied, see LICENSE.md
+
+package WrapOpenSSL;
+use strict;
+use warnings;
+
+use File::Basename;
+use File::Spec::Functions;
+
+sub load {
+    my ($class, $p) = @_;
+    my $app  = $p->{app_prove};
+
+    # turn on verbosity
+    my $verbose = $ENV{CTEST_INTERACTIVE_DEBUG_MODE} || $app->verbose();
+    $app->verbose( $verbose );
+
+    my $openssl_libdir = dirname($ENV{OPENSSL_CRYPTO_LIBRARY})
+        if $ENV{OPENSSL_CRYPTO_LIBRARY};
+    my $openssl_bindir = dirname($ENV{OPENSSL_PROGRAM})
+        if $ENV{OPENSSL_PROGRAM};
+    my $openssl_rootdir = $ENV{OPENSSL_ROOT_DIR};
+    my $openssl_rootdir_is_buildtree =
+        $openssl_rootdir && -d catdir($openssl_rootdir, 'configdata.pm');
+
+    unless ($openssl_libdir) {
+        $openssl_libdir = $openssl_rootdir_is_buildtree
+            ? $openssl_rootdir
+            : catdir($openssl_rootdir, 'lib');
+    }
+    unless ($openssl_bindir) {
+        $openssl_bindir = $openssl_rootdir_is_buildtree
+            ? catdir($openssl_rootdir, 'apps')
+            : catdir($openssl_rootdir, 'bin');
+    }
+
+    if ($openssl_libdir) {
+        # Variants of library paths
+        $ENV{$_} = join(':', $openssl_libdir, $ENV{$_} // ())
+            foreach (
+                     'LD_LIBRARY_PATH',    # Linux, ELF HP-UX
+                     'DYLD_LIBRARY_PATH',  # MacOS X
+                     'LIBPATH',            # AIX, OS/2
+            );
+        if ($verbose) {
+            print STDERR "Added $openssl_libdir to:\n";
+            print STDERR "  LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, LIBPATH\n";
+        }
+    }
+
+    if ($openssl_bindir) {
+        # Binary path, works the same everywhere
+        $ENV{PATH} = join(':', $openssl_bindir, $ENV{PATH});
+        if ($verbose) {
+            print STDERR "Added $openssl_bindir to:\n";
+            print STDERR "  PATH\n";
+        }
+    }
+    if ($verbose) {
+        print STDERR "$_=", $ENV{$_} // '', "\n"
+            foreach qw(LD_LIBRARY_PATH DYLD_LIBRARY_PATH LIBPATH PATH);
+    }
+}
+
+1;
diff --git a/test/run_tests b/test/run_tests
deleted file mode 100644 (file)
index 92d2892..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/usr/bin/perl
-use TAP::Harness;
-
-exit 0 if (defined $ENV{'SKIP_PERL_TEST'});
-
-if(defined $ENV{'OPENSSL_ROOT_DIR'}) {
-    my $openssl_libdir;
-    my $openssl_bindir;
-
-    if (-d "$ENV{'OPENSSL_ROOT_DIR'}/apps") {
-        # The OpenSSL root dir is an OpenSSL build tree
-        $openssl_bindir = "$ENV{'OPENSSL_ROOT_DIR'}/apps";
-        $openssl_libdir = "$ENV{'OPENSSL_ROOT_DIR'}";
-    } else {
-        # The OpenSSL root dir is an OpenSSL installation tree
-        # Since we're not exactly sure what the library path is (because
-        # multilib), we ask pkg-config
-        local $ENV{PKG_CONFIG_PATH} = "$ENV{'OPENSSL_ROOT_DIR'}/lib/pkgconfig";
-        my $pkgans = `pkg-config --libs-only-L openssl`;
-
-        # If pkg-config failed for any reason, abort.  The tests will most
-        # likely fail anyway because the binary path won't have a matching
-        # library path.
-        die "pkg-config failure: $! (exit code ", $? >> 8, ", signal ", $? & 0xff, ")"
-            if ($? != 0);
-
-        $pkgans =~ s|\R$||;      # Better chomp
-        $pkgans =~ s|^-L||;      # Remove flag from answer
-
-        $openssl_libdir = $pkgans;
-        $openssl_bindir = "$ENV{'OPENSSL_ROOT_DIR'}/bin";
-    }
-
-    # Variants of library paths
-    # Linux, ELF HP-UX
-    $ENV{'LD_LIBRARY_PATH'} =
-        join(':', $openssl_libdir, split(/:/, $ENV{'LD_LIBRARY_PATH'}));
-    # MacOS X
-    $ENV{'DYLD_LIBRARY_PATH'} =
-        join(':', $openssl_libdir, split(/:/, $ENV{'DYLD_LIBRARY_PATH'}));
-    # AIX, OS/2
-    $ENV{'LIBPATH'} =
-        join(':', $openssl_libdir, split(/:/, $ENV{'LIBPATH'}));
-
-    # Binary path, works on all Unix-like platforms
-    $ENV{'PATH'} =
-        join(':', $openssl_bindir, split(/:/, $ENV{'PATH'}));
-}
-my $harness = TAP::Harness->new({
-    verbosity => (($ENV{CTEST_INTERACTIVE_DEBUG_MODE} // 0) != 0)
-});
-exit ($harness->runtests(glob("*.t"))->all_passed() ? 0 : 1);