90-test_shlibload.t 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #! /usr/bin/env perl
  2. # Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (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 bldtop_dir bldtop_file/;
  9. use OpenSSL::Test::Utils;
  10. use File::Temp qw(tempfile);
  11. #Load configdata.pm
  12. BEGIN {
  13. setup("test_shlibload");
  14. }
  15. use lib bldtop_dir('.');
  16. use configdata;
  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 VMS" if config('target') =~ m|^vms|;
  20. plan skip_all => "Test only supported in a dso build" if disabled("dso");
  21. plan tests => 10;
  22. # When libssl and libcrypto are compiled on Linux with "-rpath", but not
  23. # "--enable-new-dtags", the RPATH takes precedence over LD_LIBRARY_PATH,
  24. # and we end up running with the wrong libraries. This is resolved by
  25. # using paths to the shared objects, not just the names.
  26. my $libcrypto = bldtop_file(shlib('libcrypto'));
  27. my $libssl = bldtop_file(shlib('libssl'));
  28. (my $fh, my $filename) = tempfile();
  29. ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl, $filename])),
  30. "running shlibloadtest -crypto_first $filename");
  31. ok(check_atexit($fh));
  32. unlink $filename;
  33. ($fh, $filename) = tempfile();
  34. ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl, $filename])),
  35. "running shlibloadtest -ssl_first $filename");
  36. ok(check_atexit($fh));
  37. unlink $filename;
  38. ($fh, $filename) = tempfile();
  39. ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl, $filename])),
  40. "running shlibloadtest -just_crypto $filename");
  41. ok(check_atexit($fh));
  42. unlink $filename;
  43. ($fh, $filename) = tempfile();
  44. ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl, $filename])),
  45. "running shlibloadtest -dso_ref $filename");
  46. ok(check_atexit($fh));
  47. unlink $filename;
  48. ($fh, $filename) = tempfile();
  49. ok(run(test(["shlibloadtest", "-no_atexit", $libcrypto, $libssl, $filename])),
  50. "running shlibloadtest -no_atexit $filename");
  51. ok(!check_atexit($fh));
  52. unlink $filename;
  53. sub shlib {
  54. my $lib = shift;
  55. $lib = $unified_info{rename}->{$lib}
  56. if defined $unified_info{rename}->{$lib};
  57. $lib = $unified_info{sharednames}->{$lib}
  58. . ($target{shlib_variant} || "")
  59. . ($target{shared_extension} || ".so");
  60. $lib =~ s|\.\$\(SHLIB_VERSION_NUMBER\)
  61. |.$config{shlib_version_number}|x;
  62. return $lib;
  63. }
  64. sub check_atexit {
  65. my $fh = shift;
  66. my $data = <$fh>;
  67. return 1 if (defined $data && $data =~ m/atexit\(\) run/);
  68. return 0;
  69. }