daandemeyer / rpms / systemd

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