[kvm-unit-tests PATCH 10/18] run_tests: probe for max-smp

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



KVM can be configured to only support a few vcpus. ARM and AArch64
currently have a default config of only 4. While it's nice to be
able to write tests that use the maximum recommended, nr-host-cpus,
we can't assume that nr-host-cpus == kvm-max-vcpus. This patch allows
one to put $MAX_SMP in the smp = <num> line of a unittests.cfg file.
That variable will then expand to the number of host cpus, or to the
maximum vcpus allowed by KVM.

[Inspired by a patch from Alex Bennée solving the same issue.]

Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 arm/unittests.cfg       | 3 ++-
 run_tests.sh            | 9 +++++++++
 scripts/mkstandalone.sh | 9 ++++++++-
 x86/unittests.cfg       | 1 +
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index 243c13301811b..5e26da1a8c1bc 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -2,6 +2,7 @@
 # [unittest_name]
 # file = foo.flat # Name of the flat file to be used
 # smp  = 2        # Number of processors the VM will use during this test
+#                 # Use $MAX_SMP to use the maximum the host supports.
 # extra_params = -append <params...> # Additional parameters used
 # arch = arm|arm64                   # Only if test case is specific to one
 # groups = group1 group2 # Used to identify test cases with run_tests -g ...
@@ -34,6 +35,6 @@ groups = selftest
 # Test SMP support
 [selftest-smp]
 file = selftest.flat
-smp = `getconf _NPROCESSORS_CONF`
+smp = $MAX_SMP
 extra_params = -append 'smp'
 groups = selftest
diff --git a/run_tests.sh b/run_tests.sh
index b1b4c541ecaea..fad22a935b007 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -98,4 +98,13 @@ while getopts "g:hv" opt; do
     esac
 done
 
+#
+# Probe for MAX_SMP
+#
+MAX_SMP=$(getconf _NPROCESSORS_CONF)
+while ./$TEST_DIR-run _NO_FILE_4Uhere_ -smp $MAX_SMP \
+		|& grep -q 'exceeds max cpus'; do
+	((--MAX_SMP))
+done
+
 for_each_unittest $config run
diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
index 0c39451e538c9..3ce244aff67b9 100755
--- a/scripts/mkstandalone.sh
+++ b/scripts/mkstandalone.sh
@@ -95,12 +95,19 @@ qemu="$qemu"
 if [ "\$QEMU" ]; then
 	qemu="\$QEMU"
 fi
+
+MAX_SMP="MAX_SMP"
 echo \$qemu $cmdline -smp $smp $opts
 
 cmdline="\`echo '$cmdline' | sed s%$kernel%_NO_FILE_4Uhere_%\`"
 if \$qemu \$cmdline 2>&1 | grep 'No accelerator found'; then
-        ret=2
+	ret=2
 else
+	MAX_SMP=\`getconf _NPROCESSORS_CONF\`
+	while \$qemu \$cmdline -smp \$MAX_SMP 2>&1 | grep 'exceeds max cpus' > /dev/null; do
+		MAX_SMP=\`expr \$MAX_SMP - 1\`
+	done
+
 	cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`"
 	\$qemu \$cmdline -smp $smp $opts
 	ret=\$?
diff --git a/x86/unittests.cfg b/x86/unittests.cfg
index a38544f77c056..337cc19d3d19d 100644
--- a/x86/unittests.cfg
+++ b/x86/unittests.cfg
@@ -2,6 +2,7 @@
 # [unittest_name]
 # file = foo.flat # Name of the flat file to be used
 # smp = 2 # Number of processors the VM will use during this test
+#         # Use $MAX_SMP to use the maximum the host supports.
 # extra_params = -cpu qemu64,+x2apic # Additional parameters used
 # arch = i386/x86_64 # Only if the test case works only on one of them
 # groups = group1 group2 # Used to identify test cases with run_tests -g ...
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux