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