From accd51bc35b758d590e5ab97d1e18934500d40eb Mon Sep 17 00:00:00 2001 From: Wilhelm Schuermann Date: Wed, 6 May 2015 22:06:11 +0200 Subject: [PATCH] Tests: Fix problems with "run_all --fast" on OpenBSD --- test/run_all.in | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/test/run_all.in b/test/run_all.in index d86cd1722..574df3315 100755 --- a/test/run_all.in +++ b/test/run_all.in @@ -6,7 +6,7 @@ export TASKD_USE_PATH=1 runlog_cleanup() { if [ -f "_run_all_parallel.txt" ]; then - rm _run_all_parallel.txt + rm _run_all_parallel.txt fi if [ -f "_run_all_serial.txt" ]; then rm _run_all_serial.txt @@ -20,6 +20,29 @@ runlog_cleanup() { done } +get_numprocs() { + numprocs="" + # Most Linux systems and OSX have getconf and _NPROCESSORS_ONLN. + if command -v getconf >/dev/null 2>&1; then + numprocs=$(getconf _NPROCESSORS_ONLN 2>/dev/null) + fi + + # OpenBSD doesn't know _NPROCESSORS_ONLN, but it does have hw.ncpu + if [ "$numprocs" = "" ] && command -v sysctl >/dev/null 2>&1; then + numprocs=$(sysctl -n hw.ncpu 2>/dev/null) + fi + + # If we still haven't found the number of CPU cores available, give up. + if [ "$numprocs" = "" ] || [ "$numprocs" -lt 1 ]; then + echo "Couldn't find number of CPU cores for parallelization. Assuming 2." 1>&2 + numprocs=2 + else + numprocs=$((numprocs+1)) + fi + + echo $numprocs +} + rc=0 if [ x"$1" = x"--verbose" ]; @@ -57,10 +80,12 @@ elif [ "$1" = "--fast" ]; then # Clean up after aborted runs runlog_cleanup + numprocs=$(get_numprocs) + for i in ${TESTBLOB}; do if [ -x "$i" ]; then # Only Python tests are guaranteed to run isolated. - if head -c 21 "$i" | grep -q '#!/usr/bin/env python'; then + if head -n 1 "$i" | grep -q '/usr/bin/env python'; then echo $i >> _run_all_parallel.txt else echo $i >> _run_all_serial.txt @@ -79,13 +104,6 @@ elif [ "$1" = "--fast" ]; then fi done < _run_all_serial.txt - if command -v getconf >/dev/null 2>&1; then - numprocs=$(getconf _NPROCESSORS_ONLN) - numprocs=$((numprocs+1)) - else - numprocs=2 - fi - cat _run_all_parallel.txt | xargs -n 1 -P $numprocs sh -c 'echo "#" $0 > $0.runlog; $0 >> $0.runlog 2>&1' if [ $? -ne 0 ]; then rc=1