valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0368-test-try-to-determine-QEMU_SMP-dynamically.patch

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