From: Neil Horman Date: Fri, 3 Oct 2025 13:41:14 +0000 (-0400) Subject: merge x509 and handshake memfail test X-Git-Tag: 4.0-PRE-CLANG-FORMAT-WEBKIT~163 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b803c2adc2ef6dc3c1ed9f0da1371d2a98b86ff;p=thirdparty%2Fopenssl.git merge x509 and handshake memfail test Reviewed-by: Saša Nedvědický Reviewed-by: Norbert Pocs (Merged from https://github.com/openssl/openssl/pull/28736) --- diff --git a/.github/workflows/run-checker-daily.yml b/.github/workflows/run-checker-daily.yml index 0234ec96610..d517dacf2fe 100644 --- a/.github/workflows/run-checker-daily.yml +++ b/.github/workflows/run-checker-daily.yml @@ -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 index bcb748be28d..00000000000 --- a/test/recipes/90-test_handshake-memfail.t +++ /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 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 index 00000000000..070a270ec4a --- /dev/null +++ b/test/recipes/90-test_memfail.t @@ -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 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 index cce74c739b8..00000000000 --- a/test/recipes/90-test_x509-memfail.t +++ /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 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")]))); -}