]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Run the LTP syscall tests in parallel
authorMartin Cermak <mcermak@redhat.com>
Mon, 5 May 2025 12:23:16 +0000 (14:23 +0200)
committerMark Wielaard <mark@klomp.org>
Tue, 6 May 2025 09:58:36 +0000 (11:58 +0200)
- Run the LTP syscall tests in parallel to save time.
- Allow for running only selected tests using TESTS env var.

auxprogs/Makefile.am
auxprogs/ltp-tester.sh

index 9cec4f222b364965d19cb4b7b0568cfa584eaa72..3a2d0d17629efb89948eae19bdadbe98198c6339 100644 (file)
@@ -231,7 +231,13 @@ gsl-check: $(GSL_BUILD_DIR)/gsl-build
        diff -u $(abs_top_srcdir)/auxprogs/gsl-1.6.out.x86.exp \
                $(GSL_BUILD_DIR)/valgrind-gsl.out
 
+# Extract -jNUM from MAKEFLAGS.
+# Note that any spaces between -j and NUM have already been removed.
+# Also there will be only one (the last) -jNUM left in MAKEFLAGS.
+PARALLEL_JOBS=$(subst -j,,$(filter -j%,$(MAKEFLAGS)))
+
 ltp-check: $(LTP_SRC_DIR)
+       PARALLEL_JOBS=$(PARALLEL_JOBS) \
        LTP_SRC_DIR=$(LTP_SRC_DIR) \
        VALGRIND=$(abs_top_builddir)/vg-in-place \
          $(abs_top_srcdir)/auxprogs/ltp-tester.sh
index 000cfaa7f336f8641f464d107a363af24f607614..e31f8a6b12e422214802c53480440c914fe9b628 100755 (executable)
@@ -13,31 +13,30 @@ LOGDIR=${LOGDIR:-$LTP_SRC_DIR/valgrind-ltp-logs}
 SUMMARY_LOG="$LOGDIR/summary.log"
 DIFFCMD="diff -u"
 VALGRIND="${VALGRIND:-$LTP_SRC_DIR/../../../vg-in-place}"
+# For parallel testing, consider IO intensive jobs, take nproc into account
+PARALLEL_JOBS=${PARALLEL_JOBS:-$(nproc)}
+# TESTS env var may be specified to restrict testing to selected test cases
 
 # Initialize LOGDIR
-mkdir -p $LOGDIR; rm -rf $LOGDIR/*
+mkdir -p $LOGDIR; rm -rf ${LOGDIR:?}/*
 
 myLog ()
 {
     msg="$1"
     echo "$msg"
-    echo -e "FAIL: $msg" >> $SUMMARY_LOG
+    echo -e "FAIL: $msg" >> summary
 }
 
-cd $LTP_SRC_DIR
-
-mapfile -t files < <(find testcases/kernel/syscalls -executable -and -type f \
-                     | sort | grep -v -f $ORIG_PWD/ltp-excludes.txt)
-c=${#files[@]}; i=0
-
-for test in "${files[@]}"; do
-    dir=$(dirname $test)
-    exe=$(basename $test)
+doTest ()
+{
+    t=$1
+    nr=$2
+    dir=$(dirname $t)
+    exe=$(basename $t)
     l="$LOGDIR/$exe"
     mkdir -p $l
-    i=$((++i))
+    echo "[$nr/$c] Testing $exe ..." | tee -a $l/summary
     pushd $dir >/dev/null
-        echo "[$i/$c] Testing $exe ..." | tee -a $SUMMARY_LOG
         PATH="$ORIG_PATH:$PWD"
         ./$exe >$l/log1std 2>$l/log1err ||:
         $VALGRIND -q --tool=none --log-file=$l/log2 ./$exe >$l/log2std 2>$l/log2err ||:
@@ -60,7 +59,7 @@ for test in "${files[@]}"; do
                 myLog "${exe}: unempty log2:\n$(cat log2)"
             fi
 
-            if grep -f $ORIG_PWD/ltp-error-patterns.txt * > error-patterns-found.txt; then
+            if grep -f $ORIG_PWD/ltp-error-patterns.txt log* > error-patterns-found.txt; then
                 myLog "${exe}: error string found:\n$(cat error-patterns-found.txt)"
             fi
 
@@ -73,7 +72,36 @@ for test in "${files[@]}"; do
             fi
         popd >/dev/null
     popd >/dev/null
+}
+
+cd $LTP_SRC_DIR
+
+if [ -n "$TESTS" ]; then
+    echo "Running individual syscall tests specified in the TESTS env var ..."
+    mapfile -t files < <(find testcases/kernel/syscalls -executable -and -type f \
+                         | sort | grep -f <(echo $TESTS | tr ' ' '\n' | sed 's/.*/\/\0$/'))
+else
+    echo "Running whole the LTP syscall testsuite ..."
+    mapfile -t files < <(find testcases/kernel/syscalls -executable -and -type f \
+                         | sort | grep -v -f $ORIG_PWD/ltp-excludes.txt)
+fi
+
+c=${#files[@]}; i=0
+
+# Run tests in parallel
+for test in "${files[@]}"; do
+    while test "$(jobs -l | wc -l)" -gt $PARALLEL_JOBS; do sleep 0.1; done
+    i=$((++i))
+    doTest $test $i &
 done
 
-echo "TESTING FINISHED, logs in $LOGDIR"
+wait
 
+# Reconstruct $SUMMARY_LOG
+for test in "${files[@]}"; do
+    exe=$(basename $test)
+    l="$LOGDIR/$exe"
+    cat $l/summary >> $SUMMARY_LOG
+done
+
+echo "TESTING FINISHED, logs in $LOGDIR"