yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | #! /usr/bin/env perl |
| 2 | # Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the OpenSSL license (the "License"). You may not use |
| 5 | # this file except in compliance with the License. You can obtain a copy |
| 6 | # in the file LICENSE in the source distribution or at |
| 7 | # https://www.openssl.org/source/license.html |
| 8 | |
| 9 | use OpenSSL::Test qw/:DEFAULT bldtop_dir bldtop_file/; |
| 10 | use OpenSSL::Test::Utils; |
| 11 | use File::Temp qw(tempfile); |
| 12 | |
| 13 | #Load configdata.pm |
| 14 | |
| 15 | BEGIN { |
| 16 | setup("test_shlibload"); |
| 17 | } |
| 18 | use lib bldtop_dir('.'); |
| 19 | use configdata; |
| 20 | |
| 21 | plan skip_all => "Test only supported in a shared build" if disabled("shared"); |
| 22 | plan skip_all => "Test is disabled on AIX" if config('target') =~ m|^aix|; |
| 23 | plan skip_all => "Test is disabled on VMS" if config('target') =~ m|^vms|; |
| 24 | plan skip_all => "Test only supported in a dso build" if disabled("dso"); |
| 25 | |
| 26 | plan tests => 10; |
| 27 | |
| 28 | # When libssl and libcrypto are compiled on Linux with "-rpath", but not |
| 29 | # "--enable-new-dtags", the RPATH takes precedence over LD_LIBRARY_PATH, |
| 30 | # and we end up running with the wrong libraries. This is resolved by |
| 31 | # using paths to the shared objects, not just the names. |
| 32 | |
| 33 | my $libcrypto = bldtop_file(shlib('libcrypto')); |
| 34 | my $libssl = bldtop_file(shlib('libssl')); |
| 35 | |
| 36 | (my $fh, my $filename) = tempfile(); |
| 37 | ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl, $filename])), |
| 38 | "running shlibloadtest -crypto_first $filename"); |
| 39 | ok(check_atexit($fh)); |
| 40 | unlink $filename; |
| 41 | ($fh, $filename) = tempfile(); |
| 42 | ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl, $filename])), |
| 43 | "running shlibloadtest -ssl_first $filename"); |
| 44 | ok(check_atexit($fh)); |
| 45 | unlink $filename; |
| 46 | ($fh, $filename) = tempfile(); |
| 47 | ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl, $filename])), |
| 48 | "running shlibloadtest -just_crypto $filename"); |
| 49 | ok(check_atexit($fh)); |
| 50 | unlink $filename; |
| 51 | ($fh, $filename) = tempfile(); |
| 52 | ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl, $filename])), |
| 53 | "running shlibloadtest -dso_ref $filename"); |
| 54 | ok(check_atexit($fh)); |
| 55 | unlink $filename; |
| 56 | ($fh, $filename) = tempfile(); |
| 57 | ok(run(test(["shlibloadtest", "-no_atexit", $libcrypto, $libssl, $filename])), |
| 58 | "running shlibloadtest -no_atexit $filename"); |
| 59 | ok(!check_atexit($fh)); |
| 60 | unlink $filename; |
| 61 | |
| 62 | sub shlib { |
| 63 | my $lib = shift; |
| 64 | $lib = $unified_info{rename}->{$lib} |
| 65 | if defined $unified_info{rename}->{$lib}; |
| 66 | $lib = $unified_info{sharednames}->{$lib} |
| 67 | . ($target{shlib_variant} || "") |
| 68 | . ($target{shared_extension} || ".so"); |
| 69 | $lib =~ s|\.\$\(SHLIB_VERSION_NUMBER\) |
| 70 | |.$config{shlib_version_number}|x; |
| 71 | return $lib; |
| 72 | } |
| 73 | |
| 74 | sub check_atexit { |
| 75 | my $fh = shift; |
| 76 | my $data = <$fh>; |
| 77 | |
| 78 | return 1 if (defined $data && $data =~ m/atexit\(\) run/); |
| 79 | |
| 80 | return 0; |
| 81 | } |