]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Make tests run faster on typical platforms.
authorBob Beck <beck@openssl.org>
Tue, 2 Sep 2025 20:46:06 +0000 (14:46 -0600)
committerTomas Mraz <tomas@openssl.org>
Thu, 25 Sep 2025 14:55:50 +0000 (16:55 +0200)
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 <levitte@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/28426)

test/run_tests.pl

index 89d7fafb72566f3cdbe8fe2557726526b2017939..7b1c8deecbea6ce058d6c47760cab26e7835eaca 100644 (file)
@@ -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"));