From: Bob Beck Date: Tue, 2 Sep 2025 20:46:06 +0000 (-0600) Subject: Make tests run faster on typical platforms. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7b4a56420d1718809d73aa3adf53d3e6c3a2ee91;p=thirdparty%2Fopenssl.git Make tests run faster on typical platforms. Sadly not doable in make as it is notoriously bad at telling you the parallelism being used by make -j. If the HARNESS_JOBS environment variable has not been set, this makes the perl script attempt to figure out how many cpu's are available on anything windows/linux/macos/bsd like, and if it can be successfully detected, we use that value. if not, we use 1 as before. Reviewed-by: Richard Levitte Reviewed-by: Tom Cosgrove (Merged from https://github.com/openssl/openssl/pull/28426) --- diff --git a/test/run_tests.pl b/test/run_tests.pl index 89d7fafb725..7b1c8deecbe 100644 --- a/test/run_tests.pl +++ b/test/run_tests.pl @@ -31,7 +31,41 @@ my $srctop = $ENV{SRCTOP} || $ENV{TOP}; my $bldtop = $ENV{BLDTOP} || $ENV{TOP}; my $recipesdir = catdir($srctop, "test", "recipes"); my $libdir = rel2abs(catdir($srctop, "util", "perl")); -my $jobs = $ENV{HARNESS_JOBS} // 1; + +my $jobs = $ENV{HARNESS_JOBS}; +if (!defined($jobs)) { + my $cpus = $ENV{"NUMBER_OF_PROCESSORS"}; # Windows sets this. + if (!defined($cpus) && $^O =~ /linux/) { + # Perl was built on Linux, so try nproc, which is apparently + # the less worse way if you are restricted in a + # container/cgroup + my $tmp = qx(nproc 2>/dev/null); + if ($? == 0 && $tmp > 0) { + $cpus = $tmp; + } + } + if (!defined($cpus) && -r "/proc/cpuinfo") { + # Smells like Linux or something else attempting bug for bug + # compatibilty with the /proc paradigm. + my $tmp = qx(grep -c ^processor /proc/cpuinfo 2>/dev/null); + if ($? == 0 && $tmp > 0) { + $cpus = $tmp; + } + } + if (!defined($cpus)) { + # OpenBSD, FreeBSD, MacOS + my $tmp = qx(sysctl -n hw.ncpu 2>/dev/null); + if ($? == 0 && $tmp > 0) { + $cpus = $tmp; + } + } + + if (defined($cpus) && $cpus > 0) { + $jobs = $cpus; + } else { + $jobs = 1; + } +} $ENV{OPENSSL_CONF} = rel2abs(catfile($srctop, "apps", "openssl.cnf")); $ENV{OPENSSL_CONF_INCLUDE} = rel2abs(catdir($bldtop, "test"));