From fcad266fd1d1524601cc0d0bd952a0f250946bed Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 30 May 2025 11:27:22 -0400 Subject: tests: Try harder to guess a good parallelism level --- tests/getopts.sh | 6 +----- tests/util.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/getopts.sh b/tests/getopts.sh index 255f2fa..cbb3ce4 100644 --- a/tests/getopts.sh +++ b/tests/getopts.sh @@ -5,11 +5,7 @@ ## Argument parsing -if command -v nproc &>/dev/null; then - JOBS=$(nproc) -else - JOBS=1 -fi +JOBS=$(nproc) MAKE= PATTERNS=() SUDO=() diff --git a/tests/util.sh b/tests/util.sh index b846d45..4bdb86f 100644 --- a/tests/util.sh +++ b/tests/util.sh @@ -190,3 +190,15 @@ pop_defers() { return $ret } + +## Parallelism + +# Get the number of processors +nproc() { + { + (command nproc) \ + || sysctl -n hw.ncpu \ + || getconf _NPROCESSORS_ONLN \ + || echo 1 + } 2>/dev/null +} -- cgit v1.2.3