90-test_shlibload.t 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. 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 tests => 10;
  23. my $libcrypto = platform->sharedlib('libcrypto');
  24. my $libssl = platform->sharedlib('libssl');
  25. my $atexit_outfile;
  26. $atexit_outfile = 'atexit-cryptofirst.txt';
  27. 1 while unlink $atexit_outfile;
  28. ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl, $atexit_outfile])),
  29. "running shlibloadtest -crypto_first $atexit_outfile");
  30. ok(check_atexit($atexit_outfile));
  31. $atexit_outfile = 'atexit-sslfirst.txt';
  32. 1 while unlink $atexit_outfile;
  33. ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl, $atexit_outfile])),
  34. "running shlibloadtest -ssl_first $atexit_outfile");
  35. ok(check_atexit($atexit_outfile));
  36. $atexit_outfile = 'atexit-justcrypto.txt';
  37. 1 while unlink $atexit_outfile;
  38. ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl, $atexit_outfile])),
  39. "running shlibloadtest -just_crypto $atexit_outfile");
  40. ok(check_atexit($atexit_outfile));
  41. $atexit_outfile = 'atexit-dsoref.txt';
  42. 1 while unlink $atexit_outfile;
  43. ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl, $atexit_outfile])),
  44. "running shlibloadtest -dso_ref $atexit_outfile");
  45. ok(check_atexit($atexit_outfile));
  46. $atexit_outfile = 'atexit-noatexit.txt';
  47. 1 while unlink $atexit_outfile;
  48. ok(run(test(["shlibloadtest", "-no_atexit", $libcrypto, $libssl, $atexit_outfile])),
  49. "running shlibloadtest -no_atexit $atexit_outfile");
  50. ok(!check_atexit($atexit_outfile));
  51. sub check_atexit {
  52. my $filename = shift;
  53. open my $fh, '<', $filename;
  54. return 0 unless defined $fh;
  55. my $data = <$fh>;
  56. return 1 if (defined $data && $data =~ m/atexit\(\) run/);
  57. return 0;
  58. }