Fix no-dso builds
[openssl.git] / test / recipes / 90-test_shlibload.t
1 #! /usr/bin/env perl
2 # Copyright 2016-2018 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 only supported in a dso build" if disabled("dso");
24
25 plan tests => 10;
26
27 # When libssl and libcrypto are compiled on Linux with "-rpath", but not
28 # "--enable-new-dtags", the RPATH takes precedence over LD_LIBRARY_PATH,
29 # and we end up running with the wrong libraries.  This is resolved by
30 # using paths to the shared objects, not just the names.
31
32 my $libcrypto = bldtop_file(shlib('libcrypto'));
33 my $libssl = bldtop_file(shlib('libssl'));
34
35 (my $fh, my $filename) = tempfile();
36 ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl, $filename])),
37    "running shlibloadtest -crypto_first $filename");
38 ok(check_atexit($fh));
39 unlink $filename;
40 ($fh, $filename) = tempfile();
41 ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl, $filename])),
42    "running shlibloadtest -ssl_first $filename");
43 ok(check_atexit($fh));
44 unlink $filename;
45 ($fh, $filename) = tempfile();
46 ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl, $filename])),
47    "running shlibloadtest -just_crypto $filename");
48 ok(check_atexit($fh));
49 unlink $filename;
50 ($fh, $filename) = tempfile();
51 ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl, $filename])),
52    "running shlibloadtest -dso_ref $filename");
53 ok(check_atexit($fh));
54 unlink $filename;
55 ($fh, $filename) = tempfile();
56 ok(run(test(["shlibloadtest", "-no_atexit", $libcrypto, $libssl, $filename])),
57    "running shlibloadtest -no_atexit $filename");
58 ok(!check_atexit($fh));
59 unlink $filename;
60
61 sub shlib {
62     my $lib = shift;
63     $lib = $unified_info{rename}->{$lib}
64         if defined $unified_info{rename}->{$lib};
65     $lib = $unified_info{sharednames}->{$lib}
66         . ($target{shlib_variant} || "")
67         . ($target{shared_extension} || ".so");
68     $lib =~ s|\.\$\(SHLIB_VERSION_NUMBER\)
69              |.$config{shlib_version_number}|x;
70     return $lib;
71 }
72
73 sub check_atexit {
74     my $fh = shift;
75     my $data = <$fh>;
76
77     return 1 if (defined $data && $data =~ m/atexit\(\) run/);
78
79     return 0;
80 }