[libvirt PATCH 19/29] cpu-parse: Move file name generation to new script

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


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

diff --git a/tests/cputestdata/cpu-gather.py b/tests/cputestdata/cpu-gather.py
index 0b1019456c..1a15cc1ff0 100755
--- a/tests/cputestdata/cpu-gather.py
+++ b/tests/cputestdata/cpu-gather.py
@@ -4,6 +4,7 @@ import argparse
 import fcntl
 import json
 import os
+import re
 import struct
 import subprocess
 import sys
@@ -192,11 +193,28 @@ def gather(args):
     return result
 
 
+def parse_filename(data):
+    filename = data["name"].strip()
+    filename = re.sub("[ -]+ +", " ", filename)
+    filename = re.sub("\\(([Rr]|[Tt][Mm])\\)", "", filename)
+    filename = re.sub(".*(Intel|AMD) ", "", filename)
+    filename = re.sub(" (Duo|Quad|II X[0-9]+)", " ", filename)
+    filename = re.sub(" (CPU|Processor)", "", filename)
+    filename = re.sub(" @.*", "", filename)
+    filename = re.sub(" APU .*", "", filename)
+    filename = re.sub(" SE$", "", filename)
+    filename = re.sub(" ", "-", filename)
+    return "x86_64-cpuid-{}".format(filename)
+
+
 def parse(args):
     data = json.load(sys.stdin)
 
+    filename = parse_filename(data)
+
     os.environ["CPU_GATHER_PY"] = "true"
     os.environ["model"] = data["name"]
+    os.environ["fname"] = filename
     output = subprocess.check_output(
         "./cpu-parse.sh",
         input=output_to_text(data),
diff --git a/tests/cputestdata/cpu-parse.sh b/tests/cputestdata/cpu-parse.sh
index 5b8e57e427..2a41897538 100755
--- a/tests/cputestdata/cpu-parse.sh
+++ b/tests/cputestdata/cpu-parse.sh
@@ -7,19 +7,6 @@ fi
 
 data=`cat`
 
-fname=`sed -e 's/^ *//;
-               s/ *$//;
-               s/[ -]\+ \+/ /g;
-               s/(\([Rr]\|[Tt][Mm]\))//g;
-               s/.*\(Intel\|AMD\) //;
-               s/ \(Duo\|Quad\|II X[0-9]\+\) / /;
-               s/ \(CPU\|Processor\)\>//;
-               s/ @.*//;
-               s/ APU .*//;
-               s/ SE$//;
-               s/ /-/g' <<<"$model"`
-fname="x86_64-cpuid-$fname"
-
 xml()
 {
     hex='\(0x[0-9a-f]\+\)'
-- 
2.26.2




More information about the libvir-list mailing list