From df9a23beeeadf7146715e4968e476cd20dd5b303 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Tue, 2 Apr 2019 19:02:04 +0200 Subject: [PATCH] cputest: Prepare cpu-cpuid.py for MSR features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's make sure the current CPUID specific code is only applied to CPUID features. Signed-off-by: Jiri Denemark Reviewed-by: Ján Tomko --- tests/cputestdata/cpu-cpuid.py | 36 +++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py index cba5fc165a..ac69c5a012 100755 --- a/tests/cputestdata/cpu-cpuid.py +++ b/tests/cputestdata/cpu-cpuid.py @@ -5,7 +5,7 @@ import sys import json import xmltodict -def checkFeature(cpuid, feature): +def checkCPUIDFeature(cpuData, feature): eax_in = feature["eax_in"] ecx_in = feature["ecx_in"] eax = feature["eax"] @@ -13,6 +13,10 @@ def checkFeature(cpuid, feature): ecx = feature["ecx"] edx = feature["edx"] + if "cpuid" not in cpuData: + return False + + cpuid = cpuData["cpuid"] if eax_in not in cpuid or ecx_in not in cpuid[eax_in]: return False @@ -23,7 +27,18 @@ def checkFeature(cpuid, feature): (edx > 0 and leaf["edx"] & edx == edx)) -def addFeature(cpuid, feature): +def checkFeature(cpuData, feature): + if feature["type"] == "cpuid": + return checkCPUIDFeature(cpuData, feature) + + return False + + +def addCPUIDFeature(cpuData, feature): + if "cpuid" not in cpuData: + cpuData["cpuid"] = {} + cpuid = cpuData["cpuid"] + if feature["eax_in"] not in cpuid: cpuid[feature["eax_in"]] = {} leaf = cpuid[feature["eax_in"]] @@ -36,6 +51,11 @@ def addFeature(cpuid, feature): leaf[reg] |= feature[reg] +def addFeature(cpuData, feature): + if feature["type"] == "cpuid": + addCPUIDFeature(cpuData, feature) + + def parseQemu(path, features): cpuData = {} with open(path, "r") as f: @@ -54,7 +74,7 @@ def parseCPUData(path): data = xmltodict.parse(f) for leaf in data["cpudata"]["cpuid"]: - feature = {} + feature = {"type": "cpuid"} feature["eax_in"] = int(leaf["@eax_in"], 0) feature["ecx_in"] = int(leaf["@ecx_in"], 0) for reg in ["eax", "ebx", "ecx", "edx"]: @@ -66,7 +86,7 @@ def parseCPUData(path): def parseMapFeature(data): - cpuid = {} + cpuid = {"type": "cpuid"} for reg in ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"]: attr = "@%s" % reg @@ -92,11 +112,13 @@ def parseMap(): return cpuMap -def formatCPUData(cpuid, path, comment): +def formatCPUData(cpuData, path, comment): print(path) with open(path, "w") as f: f.write("\n") f.write("\n") + + cpuid = cpuData["cpuid"] for eax_in in sorted(cpuid.keys()): for ecx_in in sorted(cpuid[eax_in].keys()): leaf = cpuid[eax_in][ecx_in] @@ -119,8 +141,8 @@ def diff(cpuMap, path): cpuData = parseCPUData(cpuDataFile) qemu = parseQemu(jsonFile, cpuMap) - enabled = {} - disabled = {} + enabled = {"cpuid": {}} + disabled = {"cpuid": {}} for feature in cpuMap.values(): if checkFeature(qemu, feature): addFeature(enabled, feature) -- GitLab