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 <levitte@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/28426)
This commit is contained in:
Bob Beck 2025-09-02 14:46:06 -06:00 committed by Tomas Mraz
parent 07474a3e8f
commit 7b4a56420d
1 changed files with 35 additions and 1 deletions

View 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"));