xref: /freebsd/crypto/openssl/test/recipes/90-test_shlibload.t (revision 6580f5c38dd5b01aeeaed16b370f1a12423437f0)
1#! /usr/bin/env perl
2# Copyright 2016-2021 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
9use OpenSSL::Test qw/:DEFAULT srctop_dir bldtop_dir/;
10use OpenSSL::Test::Utils;
11
12#Load configdata.pm
13
14BEGIN {
15    setup("test_shlibload");
16}
17use lib srctop_dir('Configurations');
18use lib bldtop_dir('.');
19use platform;
20
21plan skip_all => "Test only supported in a shared build" if disabled("shared");
22plan skip_all => "Test is disabled on AIX" if config('target') =~ m|^aix|;
23plan skip_all => "Test is disabled on NonStop" if config('target') =~ m|^nonstop|;
24plan skip_all => "Test only supported in a dso build" if disabled("dso");
25plan skip_all => "Test is disabled in an address sanitizer build" unless disabled("asan");
26
27plan tests => 10;
28
29my $libcrypto = platform->sharedlib('libcrypto');
30my $libssl = platform->sharedlib('libssl');
31my $atexit_outfile;
32
33$atexit_outfile = 'atexit-cryptofirst.txt';
341 while unlink $atexit_outfile;
35ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl, $atexit_outfile])),
36   "running shlibloadtest -crypto_first $atexit_outfile");
37ok(check_atexit($atexit_outfile));
38
39$atexit_outfile = 'atexit-sslfirst.txt';
401 while unlink $atexit_outfile;
41ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl, $atexit_outfile])),
42   "running shlibloadtest -ssl_first $atexit_outfile");
43ok(check_atexit($atexit_outfile));
44
45$atexit_outfile = 'atexit-justcrypto.txt';
461 while unlink $atexit_outfile;
47ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl, $atexit_outfile])),
48   "running shlibloadtest -just_crypto $atexit_outfile");
49ok(check_atexit($atexit_outfile));
50
51$atexit_outfile = 'atexit-dsoref.txt';
521 while unlink $atexit_outfile;
53ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl, $atexit_outfile])),
54   "running shlibloadtest -dso_ref $atexit_outfile");
55ok(check_atexit($atexit_outfile));
56
57$atexit_outfile = 'atexit-noatexit.txt';
581 while unlink $atexit_outfile;
59ok(run(test(["shlibloadtest", "-no_atexit", $libcrypto, $libssl, $atexit_outfile])),
60   "running shlibloadtest -no_atexit $atexit_outfile");
61ok(!check_atexit($atexit_outfile));
62
63sub check_atexit {
64    my $filename = shift;
65
66    open my $fh, '<', $filename;
67    return 0 unless defined $fh;
68
69    my $data = <$fh>;
70
71    return 1 if (defined $data && $data =~ m/atexit\(\) run/);
72
73    return 0;
74}
75