2016-10-18 21:16:35 +08:00
|
|
|
#! /usr/bin/env perl
|
2021-07-29 22:41:35 +08:00
|
|
|
# Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2016-10-18 21:16:35 +08:00
|
|
|
#
|
2018-12-06 20:05:25 +08:00
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-10-18 21:16:35 +08:00
|
|
|
# this file except in compliance with the License. You can obtain a copy
|
|
|
|
# in the file LICENSE in the source distribution or at
|
|
|
|
# https://www.openssl.org/source/license.html
|
|
|
|
|
2018-10-23 21:42:46 +08:00
|
|
|
use OpenSSL::Test qw/:DEFAULT srctop_dir bldtop_dir/;
|
2016-10-18 21:16:35 +08:00
|
|
|
use OpenSSL::Test::Utils;
|
|
|
|
|
|
|
|
#Load configdata.pm
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
setup("test_shlibload");
|
|
|
|
}
|
2018-10-23 21:42:46 +08:00
|
|
|
use lib srctop_dir('Configurations');
|
2016-10-18 21:16:35 +08:00
|
|
|
use lib bldtop_dir('.');
|
2018-10-23 21:42:46 +08:00
|
|
|
use platform;
|
2016-10-18 21:16:35 +08:00
|
|
|
|
|
|
|
plan skip_all => "Test only supported in a shared build" if disabled("shared");
|
2018-06-15 21:41:07 +08:00
|
|
|
plan skip_all => "Test is disabled on AIX" if config('target') =~ m|^aix|;
|
2020-09-07 05:37:47 +08:00
|
|
|
plan skip_all => "Test is disabled on NonStop" if config('target') =~ m|^nonstop|;
|
2019-01-29 19:41:32 +08:00
|
|
|
plan skip_all => "Test only supported in a dso build" if disabled("dso");
|
2020-10-30 20:16:46 +08:00
|
|
|
plan skip_all => "Test is disabled in an address sanitizer build" unless disabled("asan");
|
2016-10-18 21:16:35 +08:00
|
|
|
|
2018-11-16 01:41:06 +08:00
|
|
|
plan tests => 10;
|
2016-10-18 21:16:35 +08:00
|
|
|
|
2018-10-23 21:42:46 +08:00
|
|
|
my $libcrypto = platform->sharedlib('libcrypto');
|
|
|
|
my $libssl = platform->sharedlib('libssl');
|
test/recipes/90-test_shlibload.t: Modify to work with known file names
Using File::Temp::tempfile() is admirable, but isn't necessary for the
sort of thing we use it for.
Furthermore, since tempfile() returns an opened file handle for
reading for the file in question, it may have effect that the file
becomes unwritable. This is the default on VMS, and since tempfile()
doesn't seem to have any option to affect this, it means that
test/shlibloadtest.c can't write the magic line to that file.
Also, if we consider forensics, to be able to see what a test produced
to determine what went wrong, it's better to use specific and known
file names.
Therefore, this test is modified to use well known file names, and to
open them for reading after the shlibloadtest program has been run
instead of before.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15872)
2021-06-23 14:10:37 +08:00
|
|
|
my $atexit_outfile;
|
2016-11-04 01:48:23 +08:00
|
|
|
|
test/recipes/90-test_shlibload.t: Modify to work with known file names
Using File::Temp::tempfile() is admirable, but isn't necessary for the
sort of thing we use it for.
Furthermore, since tempfile() returns an opened file handle for
reading for the file in question, it may have effect that the file
becomes unwritable. This is the default on VMS, and since tempfile()
doesn't seem to have any option to affect this, it means that
test/shlibloadtest.c can't write the magic line to that file.
Also, if we consider forensics, to be able to see what a test produced
to determine what went wrong, it's better to use specific and known
file names.
Therefore, this test is modified to use well known file names, and to
open them for reading after the shlibloadtest program has been run
instead of before.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15872)
2021-06-23 14:10:37 +08:00
|
|
|
$atexit_outfile = 'atexit-cryptofirst.txt';
|
|
|
|
1 while unlink $atexit_outfile;
|
|
|
|
ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl, $atexit_outfile])),
|
|
|
|
"running shlibloadtest -crypto_first $atexit_outfile");
|
|
|
|
ok(check_atexit($atexit_outfile));
|
|
|
|
|
|
|
|
$atexit_outfile = 'atexit-sslfirst.txt';
|
|
|
|
1 while unlink $atexit_outfile;
|
|
|
|
ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl, $atexit_outfile])),
|
|
|
|
"running shlibloadtest -ssl_first $atexit_outfile");
|
|
|
|
ok(check_atexit($atexit_outfile));
|
|
|
|
|
|
|
|
$atexit_outfile = 'atexit-justcrypto.txt';
|
|
|
|
1 while unlink $atexit_outfile;
|
|
|
|
ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl, $atexit_outfile])),
|
|
|
|
"running shlibloadtest -just_crypto $atexit_outfile");
|
|
|
|
ok(check_atexit($atexit_outfile));
|
|
|
|
|
|
|
|
$atexit_outfile = 'atexit-dsoref.txt';
|
|
|
|
1 while unlink $atexit_outfile;
|
|
|
|
ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl, $atexit_outfile])),
|
|
|
|
"running shlibloadtest -dso_ref $atexit_outfile");
|
|
|
|
ok(check_atexit($atexit_outfile));
|
|
|
|
|
|
|
|
$atexit_outfile = 'atexit-noatexit.txt';
|
|
|
|
1 while unlink $atexit_outfile;
|
|
|
|
ok(run(test(["shlibloadtest", "-no_atexit", $libcrypto, $libssl, $atexit_outfile])),
|
|
|
|
"running shlibloadtest -no_atexit $atexit_outfile");
|
|
|
|
ok(!check_atexit($atexit_outfile));
|
2016-10-18 21:16:35 +08:00
|
|
|
|
2018-11-16 01:41:06 +08:00
|
|
|
sub check_atexit {
|
test/recipes/90-test_shlibload.t: Modify to work with known file names
Using File::Temp::tempfile() is admirable, but isn't necessary for the
sort of thing we use it for.
Furthermore, since tempfile() returns an opened file handle for
reading for the file in question, it may have effect that the file
becomes unwritable. This is the default on VMS, and since tempfile()
doesn't seem to have any option to affect this, it means that
test/shlibloadtest.c can't write the magic line to that file.
Also, if we consider forensics, to be able to see what a test produced
to determine what went wrong, it's better to use specific and known
file names.
Therefore, this test is modified to use well known file names, and to
open them for reading after the shlibloadtest program has been run
instead of before.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15872)
2021-06-23 14:10:37 +08:00
|
|
|
my $filename = shift;
|
|
|
|
|
|
|
|
open my $fh, '<', $filename;
|
|
|
|
return 0 unless defined $fh;
|
|
|
|
|
2018-11-16 01:41:06 +08:00
|
|
|
my $data = <$fh>;
|
|
|
|
|
|
|
|
return 1 if (defined $data && $data =~ m/atexit\(\) run/);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|