From: Richard Levitte Date: Sun, 14 Feb 2021 20:53:02 +0000 (+0100) Subject: Remove the use of test/run_tests in favor of 'prove' X-Git-Tag: v3.0.0~42 X-Git-Url: http://wagner.pp.ru/gitweb/?a=commitdiff_plain;h=4573bedad51d6978b26b5d420430d8e64f02d47b;p=openssl-gost%2Fengine.git Remove the use of test/run_tests in favor of 'prove' '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. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c14717a..c7c3ec9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 0000000..8d92af9 --- /dev/null +++ b/test/WrapOpenSSL.pm @@ -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 index 92d2892..0000000 --- a/test/run_tests +++ /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);