[libvirt PATCH 20/29] cpu-parse: Move xml output to new script

Tim Wiederhake twiederh at redhat.com
Tue Dec 15 16:25:06 UTC 2020


Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
---
 tests/cputestdata/cpu-gather.py | 40 +++++++++++++++++++++++++++++++++
 tests/cputestdata/cpu-parse.sh  | 18 ---------------
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/tests/cputestdata/cpu-gather.py b/tests/cputestdata/cpu-gather.py
index 1a15cc1ff0..bc5c7dbb15 100755
--- a/tests/cputestdata/cpu-gather.py
+++ b/tests/cputestdata/cpu-gather.py
@@ -207,10 +207,50 @@ def parse_filename(data):
     return "x86_64-cpuid-{}".format(filename)
 
 
+def output_xml(data, filename):
+    leave_pattern = re.compile(
+        "^\\s*"
+        "(0x[0-9a-f]+)\\s*"
+        "(0x[0-9a-f]+):\\s*"
+        "eax=(0x[0-9a-f]+)\\s*"
+        "ebx=(0x[0-9a-f]+)\\s*"
+        "ecx=(0x[0-9a-f]+)\\s*"
+        "edx=(0x[0-9a-f]+)\\s*$")
+
+    leave_template = \
+        "  <cpuid" \
+        " eax_in='{}'" \
+        " ecx_in='{}'" \
+        " eax='{}'" \
+        " ebx='{}'" \
+        " ecx='{}'" \
+        " edx='{}'" \
+        "/>\n"
+
+    msr_template = "  <msr index='0x{:x}' edx='0x{:08x}' eax='0x{:08x}'/>\n"
+
+    print(filename)
+    with open(filename, "wt") as f:
+        f.write("<!-- {} -->\n".format(data["name"]))
+        f.write("<cpudata arch='x86'>\n")
+        for line in data["leaves"]:
+            match = leave_pattern.match(line)
+            f.write(leave_template.format(*match.groups()))
+        for key, value in sorted(data["msr"].items()):
+            f.write(msr_template.format(
+                int(key),
+                0xffffffff & (value >> 32),
+                0xffffffff & (value >> 0)))
+        f.write("</cpudata>\n")
+
+
 def parse(args):
     data = json.load(sys.stdin)
 
     filename = parse_filename(data)
+    filename_xml = "{}.xml".format(filename)
+
+    output_xml(data, filename_xml)
 
     os.environ["CPU_GATHER_PY"] = "true"
     os.environ["model"] = data["name"]
diff --git a/tests/cputestdata/cpu-parse.sh b/tests/cputestdata/cpu-parse.sh
index 2a41897538..84d37d0df4 100755
--- a/tests/cputestdata/cpu-parse.sh
+++ b/tests/cputestdata/cpu-parse.sh
@@ -7,21 +7,6 @@ fi
 
 data=`cat`
 
-xml()
-{
-    hex='\(0x[0-9a-f]\+\)'
-    matchCPUID="$hex $hex: eax=$hex ebx=$hex ecx=$hex edx=$hex"
-    substCPUID="<cpuid eax_in='\\1' ecx_in='\\2' eax='\\3' ebx='\\4' ecx='\\5' edx='\\6'\\/>"
-
-    matchMSR="$hex: $hex\(.......[0-9a-f]\)"
-    substMSR="<msr index='\\1' edx='\\2' eax='0x\\3'\\/>"
-
-    echo "<!-- $model -->"
-    echo "<cpudata arch='x86'>"
-    sed -ne "s/^ *$matchCPUID$/  $substCPUID/p; s/^ *$matchMSR$/  $substMSR/p"
-    echo "</cpudata>"
-}
-
 json()
 {
     first=true
@@ -36,9 +21,6 @@ json()
     done
 }
 
-xml <<<"$data" >$fname.xml
-echo $fname.xml
-
 json <<<"$data" >$fname.json
 if [[ -s $fname.json ]]; then
     echo $fname.json
-- 
2.26.2




More information about the libvir-list mailing list