90-test_shlibload.t 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. use OpenSSL::Test qw/:DEFAULT srctop_dir bldtop_dir/;
  9. use OpenSSL::Test::Utils;
  10. #Load configdata.pm
  11. BEGIN {
  12. setup("test_shlibload");
  13. }
  14. use lib srctop_dir('Configurations');
  15. use lib bldtop_dir('.');
  16. use platform;
  17. plan skip_all => "Test only supported in a shared build" if disabled("shared");
  18. plan skip_all => "Test is disabled on AIX" if config('target') =~ m|^aix|;
  19. plan skip_all => "Test is disabled on NonStop" if config('target') =~ m|^nonstop|;
  20. plan skip_all => "Test only supported in a dso build" if disabled("dso");
  21. plan skip_all => "Test is disabled in an address sanitizer build" unless disabled("asan");
  22. plan skip_all => "Test is disabled in no-atexit build" if disabled("atexit");
  23. plan tests => 10;
  24. my $libcrypto = platform->sharedlib('libcrypto');
  25. my $libssl = platform->sharedlib('libssl');
  26. my $atexit_outfile;
  27. $atexit_outfile = 'atexit-cryptofirst.txt';
  28. 1 while unlink $atexit_outfile;
  29. ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl, $atexit_outfile])),
  30. "running shlibloadtest -crypto_first $atexit_outfile");
  31. ok(check_atexit($atexit_outfile));
  32. $atexit_outfile = 'atexit-sslfirst.txt';
  33. 1 while unlink $atexit_outfile;
  34. ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl, $atexit_outfile])),
  35. "running shlibloadtest -ssl_first $atexit_outfile");
  36. ok(check_atexit($atexit_outfile));
  37. $atexit_outfile = 'atexit-justcrypto.txt';
  38. 1 while unlink $atexit_outfile;
  39. ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl, $atexit_outfile])),
  40. "running shlibloadtest -just_crypto $atexit_outfile");
  41. ok(check_atexit($atexit_outfile));
  42. $atexit_outfile = 'atexit-dsoref.txt';
  43. 1 while unlink $atexit_outfile;
  44. ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl, $atexit_outfile])),
  45. "running shlibloadtest -dso_ref $atexit_outfile");
  46. ok(check_atexit($atexit_outfile));
  47. $atexit_outfile = 'atexit-noatexit.txt';
  48. 1 while unlink $atexit_outfile;
  49. ok(run(test(["shlibloadtest", "-no_atexit", $libcrypto, $libssl, $atexit_outfile])),
  50. "running shlibloadtest -no_atexit $atexit_outfile");
  51. ok(!check_atexit($atexit_outfile));
  52. sub check_atexit {
  53. my $filename = shift;
  54. open my $fh, '<', $filename;
  55. return 0 unless defined $fh;
  56. my $data = <$fh>;
  57. return 1 if (defined $data && $data =~ m/atexit\(\) run/);
  58. return 0;
  59. }