test: use modern qemu numa arguments
authorChristian Ehrhardt <christian.ehrhardt@canonical.com>
Tue, 15 Dec 2020 11:05:14 +0000 (12:05 +0100)
committerMichael Biebl <biebl@debian.org>
Mon, 18 Jan 2021 12:45:15 +0000 (12:45 +0000)
Upgrading to qemu 5.2 breaks TEST-36-NUMAPOLICY like:
  qemu-system-x86_64: total memory for NUMA nodes (0x0) should
  equal RAM size (0x20000000)

Use the new (as in >=2014) form of memdev in test 36:
 -object memory-backend-ram,id=mem0,size=512M -numa node,memdev=mem0,nodeid=0

Since some target systems are as old as qemu 1.5.3 (CentOS7) but the new
kind to specify was added in qemu 2.1 this needs to add version parsing and
add the argument only when qemu is >=5.2.

Fixes #17986.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
(cherry picked from commit 43b49470d1f2808555c07f64cd0a1529b7ddd559)

Gbp-Pq: Name test-use-modern-qemu-numa-arguments.patch

test/TEST-36-NUMAPOLICY/test.sh
test/test-functions

index 02f013568cd44f532c873984b9f5b26ec9725140..a08ad6c14a12277b1b0efc270aa64b62468a7731 100755 (executable)
@@ -3,7 +3,11 @@ set -e
 
 TEST_DESCRIPTION="test MUMAPolicy= and NUMAMask= options"
 TEST_NO_NSPAWN=1
-QEMU_OPTIONS="-numa node,nodeid=0"
 . $TEST_BASE_DIR/test-functions
+if qemu_min_version "5.2.0"; then
+    QEMU_OPTIONS="-object memory-backend-ram,id=mem0,size=512M -numa node,memdev=mem0,nodeid=0"
+else
+    QEMU_OPTIONS="-numa node,nodeid=0"
+fi
 
 do_test "$@" 36
index d5da8e0ea5e621d3078e8e3cd1ab1c5faa10c273..52b52bf29eb65e4b32259e1443e09f735d8acf3d 100644 (file)
@@ -227,6 +227,24 @@ function find_qemu_bin() {
     fi
 }
 
+# Compares argument #1=X.Y.Z (X&Y&Z = numeric) to the version of the installed qemu
+# returns 0 if newer or equal
+# returns 1 if older
+# returns 2 if failing
+function qemu_min_version() {
+    find_qemu_bin || return 2
+
+    # get version from binary
+    qemu_ver=$($QEMU_BIN --version | awk '/^QEMU emulator version ([0-9]*\.[0-9]*\.[0-9]*) / {print $4}')
+
+    # Check version string format
+    echo "$qemu_ver" | grep -q '^[0-9]*\.[0-9]*\.[0-9]*$' || return 2
+    echo "$1" | grep -q '^[0-9]*\.[0-9]*\.[0-9]*$' || return 2
+
+    # compare as last command to return that value
+    printf "%s\n%s\n" "$1" "$qemu_ver" | sort -V -C
+}
+
 # Return 0 if QEMU did run (then you must check the result state/logs for actual
 # success), or 1 if QEMU is not available.
 run_qemu() {