]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
merge x509 and handshake memfail test
authorNeil Horman <nhorman@openssl.org>
Fri, 3 Oct 2025 13:41:14 +0000 (09:41 -0400)
committerTomas Mraz <tomas@openssl.org>
Wed, 19 Nov 2025 14:53:01 +0000 (15:53 +0100)
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Norbert Pocs <norbertp@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28736)

.github/workflows/run-checker-daily.yml
test/recipes/90-test_handshake-memfail.t [deleted file]
test/recipes/90-test_memfail.t [new file with mode: 0644]
test/recipes/90-test_x509-memfail.t [deleted file]

index 0234ec966103b46ef8895af407f2db44ce3d3321..d517dacf2fef85f34993c28ae07e1753ca41e30d 100644 (file)
@@ -297,7 +297,7 @@ jobs:
     - name: make test
       continue-on-error: true
       run: |
-        make TESTS="test_handshake-memfail test_x509-memfail" test
+        make TESTS="test_memfail" test
 
   enable_brotli_and_asan_ubsan:
     if: github.repository == 'openssl/openssl'
diff --git a/test/recipes/90-test_handshake-memfail.t b/test/recipes/90-test_handshake-memfail.t
deleted file mode 100644 (file)
index bcb748b..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#! /usr/bin/env perl
-# Copyright 2025 The OpenSSL Project Authors. All Rights Reserved.
-#
-# Licensed under the Apache License 2.0 (the "License").  You may not use
-# 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
-
-use OpenSSL::Test qw/:DEFAULT srctop_dir result_dir/;
-use OpenSSL::Test::Utils;
-use File::Temp qw(tempfile);
-use File::Path 2.00 qw(rmtree mkpath);
-
-setup("test_handshake_memfail");
-
-#
-# Don't run this test if mdebug isn't enabled, it won't work
-#
-plan skip_all => "$test_name requires allocfail-tests to be enabled"
-    if disabled("allocfail-tests");
-
-#
-# We need to know how many mallocs we plan to fail, so run the test in count mode
-# To tell us how many mallocs it executes
-# We capture the result of the test into countinfo.txt
-# and parse that to figure out what our values are
-#
-my $resultdir = result_dir();
-run(test(["handshake-memfail", "count", srctop_dir("test", "certs")], stderr => "$resultdir/countinfo.txt"));
-
-#
-# Read the result file into an array
-#
-open my $handle, '<', "$resultdir/countinfo.txt";
-chomp(my @lines = <$handle>);
-close $handle;
-
-#
-# some line contains our counts, find and split that into an array
-#
-my @vals;
-foreach(@lines) {
-    if ($_ =~/skip:/) {
-        @vals = split ' ', $_;
-        break;
-    }
-}
-
-#
-# The number of mallocs we need to skip is in entry two
-# The number of mallocs to test is in entry 4
-#
-my $skipcount = $vals[2];
-my $malloccount = $vals[4];
-
-#
-# Now we can plan our tests.  We plan to run malloccount iterations of this
-# test
-#
-plan tests => $malloccount;
-
-my @seq = (1..$malloccount);
-for my $idx (@seq) {
-    #
-    # We need to setup our openssl malloc failures env var to fail the target malloc
-    # the format of this string is a series of A@B;C@D tuples where A,C are the number
-    # of mallocs to consider, and B,D are the likelyhood that they should fail.
-    # We always skip the first "skip" allocations, then iteratively guarantee that 
-    # next <idx> mallocs pass, followed by the next single malloc failing, with the remainder
-    # passing
-    #
-    $ENV{OPENSSL_MALLOC_FAILURES} = "$skipcount\@0;$idx\@0;1\@100;0\@0"; 
-    ok(run(test(["handshake-memfail", "run", srctop_dir("test", "certs")])));
-}
diff --git a/test/recipes/90-test_memfail.t b/test/recipes/90-test_memfail.t
new file mode 100644 (file)
index 0000000..070a270
--- /dev/null
@@ -0,0 +1,90 @@
+#! /usr/bin/env perl
+# Copyright 2025 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the Apache License 2.0 (the "License").  You may not use
+# 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
+
+use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file result_dir/;
+use OpenSSL::Test::Utils;
+use File::Temp qw(tempfile);
+use File::Path 2.00 qw(rmtree mkpath);
+
+setup("test_memfail");
+
+#
+# Don't run this test if allocfail-tests isn't enabled, it won't work
+#
+plan skip_all => "$test_name requires allocfail-tests to be enabled"
+    if disabled("allocfail-tests");
+
+#
+# We need to know how many mallocs we plan to fail, so run the test in count mode
+# To tell us how many mallocs it executes
+# We capture the result of the test into countinfo.txt
+# and parse that to figure out what our values are
+#
+my $resultdir = result_dir();
+run(test(["handshake-memfail", "count", srctop_dir("test", "certs")], stderr => "$resultdir/hscountinfo.txt"));
+
+run(test(["x509-memfail", "count", srctop_file("test", "certs", "servercert.pem")], stderr => "$resultdir/x509countinfo.txt"));
+
+sub get_count_info {
+    my ($infile) = @_;
+    my @vals;
+
+    # Read in our input file
+    open my $handle, '<', "$infile";
+    chomp(my @lines = <$handle>);
+    close $handle;
+
+    # parse the input file
+    foreach(@lines) {
+        if ($_ =~/skip:/) {
+            @vals = split ' ', $_;
+            last;
+        }
+    }
+    #
+    #The number of allocations we skip is in argument 2
+    #The number of mallocs we shoudl test is in argument 4
+    #
+    my $skipcount = $vals[2];
+    my $malloccount = $vals[4];
+    return ($skipcount, $malloccount);
+}
+
+my ($hsskipcount, $hsmalloccount) = get_count_info("$resultdir/hscountinfo.txt");
+
+my ($x509skipcount, $x509malloccount) = get_count_info("$resultdir/x509countinfo.txt");
+
+#
+# Now we can plan our tests.  We plan to run malloccount iterations of this
+# test
+#
+plan tests => $hsmalloccount + $x509malloccount;
+
+sub run_memfail_test {
+    my $skipcount = $_[0];
+    my @mallocseq = (1..$_[1]);
+    my @cmd = $_[2];
+
+    for my $idx (@mallocseq) {
+        #
+        # We need to setup our openssl malloc failures env var to fail the target malloc
+        # the format of this string is a series of A@B;C@D tuples where A,C are the number
+        # of mallocs to consider, and B,D are the likelyhood that they should fail.
+        # We always skip the first "skip" allocations, then iteratively guarantee that
+        # next <idx> mallocs pass, followed by the next single malloc failing, with the remainder
+        # passing
+        #
+        $ENV{OPENSSL_MALLOC_FAILURES} = "$skipcount\@0;$idx\@0;1\@100;0\@0";
+        ok(run(test(@cmd)));
+    }
+}
+
+run_memfail_test($hsskipcount, $hsmalloccount, ["handshake-memfail", "run", srctop_dir("test", "certs")]);
+
+run_memfail_test($x509skipcount, $x509malloccount, ["x509-memfail", "run", srctop_file("test", "certs", "servercert.pem")]);
+
diff --git a/test/recipes/90-test_x509-memfail.t b/test/recipes/90-test_x509-memfail.t
deleted file mode 100644 (file)
index cce74c7..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#! /usr/bin/env perl
-# Copyright 2025 The OpenSSL Project Authors. All Rights Reserved.
-#
-# Licensed under the Apache License 2.0 (the "License").  You may not use
-# 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
-
-use OpenSSL::Test qw/:DEFAULT srctop_file result_dir/;
-use OpenSSL::Test::Utils;
-use File::Temp qw(tempfile);
-use File::Path 2.00 qw(rmtree mkpath);
-
-setup("test_x509_memfail");
-
-#
-# Don't run this test if mdebug isn't enabled, it won't work
-#
-plan skip_all => "$test_name requires allocfail-tests to be enabled"
-    if disabled("allocfail-tests");
-
-#
-# We need to know how many mallocs we plan to fail, so run the test in count mode
-# To tell us how many mallocs it executes
-# We capture the result of the test into countinfo.txt
-# and parse that to figure out what our values are
-#
-my $resultdir = result_dir();
-run(test(["x509-memfail", "count", srctop_file("test", "certs", "servercert.pem")], stderr => "$resultdir/countinfo.txt"));
-
-#
-# Read the result file into an array
-#
-open my $handle, '<', "$resultdir/countinfo.txt";
-chomp(my @lines = <$handle>);
-close $handle;
-
-#
-# some line contains our counts, find and split that into an array
-#
-my @vals;
-foreach(@lines) {
-    if ($_ =~/skip:/) {
-        @vals = split ' ', $_;
-        break;
-    }
-}
-
-#
-# The number of mallocs we need to skip is in entry two
-# The number of mallocs to test is in entry 4
-#
-my $skipcount = $vals[2];
-my $malloccount = $vals[4];
-
-#
-# Now we can plan our tests.  We plan to run malloccount iterations of this
-# test
-#
-plan tests => $malloccount;
-
-my @seq = (1..$malloccount);
-for my $idx (@seq) {
-    #
-    # We need to setup our openssl malloc failures env var to fail the target malloc
-    # the format of this string is a series of A@B;C@D tuples where A,C are the number
-    # of mallocs to consider, and B,D are the likelyhood that they should fail.
-    # We always skip the first "skip" allocations, then iteratively guarantee that 
-    # next <idx> mallocs pass, followed by the next single malloc failing, with the remainder
-    # passing
-    #
-    $ENV{OPENSSL_MALLOC_FAILURES} = "$skipcount\@0;$idx\@0;1\@100;0\@0"; 
-    ok(run(test(["x509-memfail", "run", srctop_file("test", "certs", "servercert.pem")])));
-}