Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx> --- tests/cputestdata/cpu-gather.py | 30 ++++++++++++++++++++++++++++++ tests/cputestdata/cpu-parse.sh | 16 ---------------- tests/cputestdata/cpu-reformat.py | 9 --------- 3 files changed, 30 insertions(+), 25 deletions(-) delete mode 100755 tests/cputestdata/cpu-reformat.py diff --git a/tests/cputestdata/cpu-gather.py b/tests/cputestdata/cpu-gather.py index bc5c7dbb15..2c3f39ab35 100755 --- a/tests/cputestdata/cpu-gather.py +++ b/tests/cputestdata/cpu-gather.py @@ -244,13 +244,43 @@ def output_xml(data, filename): f.write("</cpudata>\n") +def output_json(data, filename): + replies = list() + for reply in data["model"]: + if "QMP" in reply: + continue + if "timestamp" in reply: + continue + if "return" in reply and not reply["return"]: + continue + replies.append(reply) + + if not replies: + return + + if "model-expansion" not in [reply.get("id") for reply in replies]: + exit( + "Error: Missing query-cpu-model-expansion reply in " + "{}".format(filename)) + + print(filename) + with open(filename, "wt") as f: + for reply in replies: + if reply is not replies[0]: + f.write("\n") + json.dump(reply, f, indent=2) + f.write("\n") + + def parse(args): data = json.load(sys.stdin) filename = parse_filename(data) filename_xml = "{}.xml".format(filename) + filename_json = "{}.json".format(filename) output_xml(data, filename_xml) + output_json(data, filename_json) 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 84d37d0df4..aeb6e4e07f 100755 --- a/tests/cputestdata/cpu-parse.sh +++ b/tests/cputestdata/cpu-parse.sh @@ -7,23 +7,7 @@ fi data=`cat` -json() -{ - first=true - sed -ne '/{"QMP".*/d; - /{"return": {}}/d; - /{"timestamp":.*/d; - /^{/p' <<<"$data" | \ - while read; do - $first || echo - first=false - $(dirname $0)/cpu-reformat.py <<<"$REPLY" - done -} - -json <<<"$data" >$fname.json if [[ -s $fname.json ]]; then - echo $fname.json if ! grep -q model-expansion $fname.json; then echo "Missing query-cpu-model-expansion reply in $name.json" >&2 exit 1 diff --git a/tests/cputestdata/cpu-reformat.py b/tests/cputestdata/cpu-reformat.py deleted file mode 100755 index fcc6b8ab41..0000000000 --- a/tests/cputestdata/cpu-reformat.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python3 - -import sys -import json - -dec = json.JSONDecoder() -data, pos = dec.raw_decode(sys.stdin.read()) -json.dump(data, sys.stdout, indent=2, separators=(',', ': ')) -print("") -- 2.26.2