1#! /usr/bin/env perl 2# Copyright 2016-2024 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"); 26plan skip_all => "Test is disabled in no-atexit build" if disabled("atexit"); 27 28plan tests => 10; 29 30my $libcrypto = platform->sharedlib('libcrypto'); 31my $libssl = platform->sharedlib('libssl'); 32my $atexit_outfile; 33 34$atexit_outfile = 'atexit-cryptofirst.txt'; 351 while unlink $atexit_outfile; 36ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl, $atexit_outfile])), 37 "running shlibloadtest -crypto_first $atexit_outfile"); 38ok(check_atexit($atexit_outfile)); 39 40$atexit_outfile = 'atexit-sslfirst.txt'; 411 while unlink $atexit_outfile; 42ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl, $atexit_outfile])), 43 "running shlibloadtest -ssl_first $atexit_outfile"); 44ok(check_atexit($atexit_outfile)); 45 46$atexit_outfile = 'atexit-justcrypto.txt'; 471 while unlink $atexit_outfile; 48ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl, $atexit_outfile])), 49 "running shlibloadtest -just_crypto $atexit_outfile"); 50ok(check_atexit($atexit_outfile)); 51 52$atexit_outfile = 'atexit-dsoref.txt'; 531 while unlink $atexit_outfile; 54ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl, $atexit_outfile])), 55 "running shlibloadtest -dso_ref $atexit_outfile"); 56ok(check_atexit($atexit_outfile)); 57 58$atexit_outfile = 'atexit-noatexit.txt'; 591 while unlink $atexit_outfile; 60ok(run(test(["shlibloadtest", "-no_atexit", $libcrypto, $libssl, $atexit_outfile])), 61 "running shlibloadtest -no_atexit $atexit_outfile"); 62ok(!check_atexit($atexit_outfile)); 63 64sub check_atexit { 65 my $filename = shift; 66 67 open my $fh, '<', $filename; 68 return 0 unless defined $fh; 69 70 my $data = <$fh>; 71 72 return 1 if (defined $data && $data =~ m/atexit\(\) run/); 73 74 return 0; 75} 76