]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu-gather: Move static model expansion to new script
authorTim Wiederhake <twiederh@redhat.com>
Tue, 15 Dec 2020 16:24:55 +0000 (17:24 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 18 Dec 2020 22:20:03 +0000 (23:20 +0100)
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/cputestdata/cpu-gather.py
tests/cputestdata/cpu-gather.sh

index 7f9479f78d30c1455cd39f994fd36ff5fcac5aaa..e4a82fc9494a691bb89a1b8977d0437b88f92890 100755 (executable)
@@ -2,6 +2,7 @@
 
 import argparse
 import fcntl
+import json
 import os
 import struct
 import subprocess
@@ -66,6 +67,47 @@ def gather_msr():
     return None, {}
 
 
+def call_qemu(qemu, qmp_cmds):
+    cmd = [
+        qemu,
+        "-machine", "accel=kvm",
+        "-cpu", "host",
+        "-nodefaults",
+        "-nographic",
+        "-qmp", "stdio"]
+
+    stdin = list()
+    stdin.append("{\"execute\": \"qmp_capabilities\"}")
+    stdin.extend([json.dumps(o) for o in qmp_cmds])
+    stdin.append("{\"execute\": \"quit\"}")
+
+    try:
+        output = subprocess.check_output(
+            cmd,
+            universal_newlines=True,
+            input="\n".join(stdin))
+    except subprocess.CalledProcessError:
+        exit("Error: Non-zero exit code from '{}'.".format(qemu))
+    except FileNotFoundError:
+        exit("Error: File not found: '{}'.".format(qemu))
+
+    return output
+
+
+def gather_static_model(args):
+    output = call_qemu(args.path_to_qemu, [
+        {
+            "execute": "query-cpu-model-expansion",
+            "arguments":
+            {
+                "type": "static",
+                "model": {"name": "host"}
+            },
+            "id": "model-expansion"
+        }])
+    return output
+
+
 def main():
     parser = argparse.ArgumentParser(description="Gather cpu test data")
     parser.add_argument(
@@ -111,9 +153,12 @@ def main():
         for key, value in sorted(msr.items()):
             print("   0x{:x}: 0x{:016x}\n".format(int(key), value))
 
+    static_model = gather_static_model(args)
+
     print(end="", flush=True)
     os.environ["CPU_GATHER_PY"] = "true"
     os.environ["qemu"] = args.path_to_qemu
+    os.environ["model"] = static_model
     subprocess.check_call("./cpu-gather.sh")
 
 
index 4b4ac1a47c00dbe90083d6bad0490fb3570b273b..af0f40b61c6d97393bf3b0ab09f402538dd09299 100755 (executable)
@@ -21,13 +21,6 @@ model_expansion()
          '{"type":"'"$mode"'","model":'"$model"'},"id":"model-expansion"}'
 }
 
-model=$(
-    $qemu -machine accel=kvm -cpu host -nodefaults -nographic -qmp stdio <<EOF
-{"execute":"qmp_capabilities"}
-$(model_expansion static '{"name":"host"}')
-{"execute":"quit"}
-EOF
-)
 model=$(
     echo "$model" | \
     sed -ne 's/^{"return": {"model": {\(.*{.*}\)}}, .*/{\1}/p'