]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test/recipes/90-test_shlibload.t: Modify to work with known file names
authorRichard Levitte <levitte@openssl.org>
Wed, 23 Jun 2021 06:10:37 +0000 (08:10 +0200)
committerPauli <pauli@openssl.org>
Thu, 24 Jun 2021 05:55:14 +0000 (15:55 +1000)
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)

test/recipes/90-test_shlibload.t

index d3944308d36cae5710d42397f247add4219386a0..29826f72527377696b0ec33cd467f17c6bf569b2 100644 (file)
@@ -8,7 +8,6 @@
 
 use OpenSSL::Test qw/:DEFAULT srctop_dir bldtop_dir/;
 use OpenSSL::Test::Utils;
-use File::Temp qw(tempfile);
 
 #Load configdata.pm
 
@@ -29,35 +28,44 @@ plan tests => 10;
 
 my $libcrypto = platform->sharedlib('libcrypto');
 my $libssl = platform->sharedlib('libssl');
+my $atexit_outfile;
 
-(my $fh, my $filename) = tempfile();
-ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl, $filename])),
-   "running shlibloadtest -crypto_first $filename");
-ok(check_atexit($fh));
-unlink $filename;
-($fh, $filename) = tempfile();
-ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl, $filename])),
-   "running shlibloadtest -ssl_first $filename");
-ok(check_atexit($fh));
-unlink $filename;
-($fh, $filename) = tempfile();
-ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl, $filename])),
-   "running shlibloadtest -just_crypto $filename");
-ok(check_atexit($fh));
-unlink $filename;
-($fh, $filename) = tempfile();
-ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl, $filename])),
-   "running shlibloadtest -dso_ref $filename");
-ok(check_atexit($fh));
-unlink $filename;
-($fh, $filename) = tempfile();
-ok(run(test(["shlibloadtest", "-no_atexit", $libcrypto, $libssl, $filename])),
-   "running shlibloadtest -no_atexit $filename");
-ok(!check_atexit($fh));
-unlink $filename;
+$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));
 
 sub check_atexit {
-    my $fh = shift;
+    my $filename = shift;
+
+    open my $fh, '<', $filename;
+    return 0 unless defined $fh;
+
     my $data = <$fh>;
 
     return 1 if (defined $data && $data =~ m/atexit\(\) run/);