c2dfb7
From fe6e09aa0931112e7e3750801858c66129c7a3a8 Mon Sep 17 00:00:00 2001
c2dfb7
From: Frantisek Sumsal <frantisek@sumsal.cz>
c2dfb7
Date: Tue, 5 Mar 2019 16:08:00 +0100
c2dfb7
Subject: [PATCH] test: try to determine QEMU_SMP dynamically
c2dfb7
c2dfb7
If the QEMU_SMP value has not been explicitly set, try to determine it
c2dfb7
from the number of online CPUs using the nproc utility. If this approach
c2dfb7
fails, fall back to the default value QEMU_SMP=1.
c2dfb7
c2dfb7
This change should significantly help when running integration tests
c2dfb7
under QEMU on multicore systems.
c2dfb7
c2dfb7
(cherry picked from commit 5bfb2a93a4a36bba0d24199553dcda6e560cbb75)
c2dfb7
c2dfb7
Related: #1823767
c2dfb7
---
c2dfb7
 test/test-functions | 11 ++++++++++-
c2dfb7
 1 file changed, 10 insertions(+), 1 deletion(-)
c2dfb7
c2dfb7
diff --git a/test/test-functions b/test/test-functions
c2dfb7
index 0938e6e826..3f1c327f3c 100644
c2dfb7
--- a/test/test-functions
c2dfb7
+++ b/test/test-functions
c2dfb7
@@ -120,7 +120,16 @@ run_qemu() {
c2dfb7
         fi
c2dfb7
     fi
c2dfb7
 
c2dfb7
-    [ "$QEMU_SMP" ]   || QEMU_SMP=1
c2dfb7
+    # If QEMU_SMP was not explicitly set, try to determine the value 'dynamically'
c2dfb7
+    # i.e. use the number of online CPUs on the host machine. If the nproc utility
c2dfb7
+    # is not installed or there's some other error when calling it, fall back
c2dfb7
+    # to the original value (QEMU_SMP=1).
c2dfb7
+    if ! [ "$QEMU_SMP" ]; then
c2dfb7
+        if ! QEMU_SMP=$(nproc); then
c2dfb7
+            dwarn "nproc utility is not installed, falling back to QEMU_SMP=1"
c2dfb7
+            QEMU_SMP=1
c2dfb7
+        fi
c2dfb7
+    fi
c2dfb7
 
c2dfb7
     find_qemu_bin || return 1
c2dfb7