1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2025-10-03 11:01:30 +00:00

Change add_test.py to output the concatenated raw/report to stdout.

Instead of appending it to test_stash.
This commit is contained in:
Veselin Georgiev 2014-07-15 17:55:39 +03:00
commit fbed394404

View file

@ -4,57 +4,56 @@ import os, sys, re
args = sys.argv args = sys.argv
if not len(args) in (3, 4): if len(args) != 3:
print "Usage: add_test.py <rawdata file> <report file> [tests stash file]" print "Usage: create_test.py <rawdata file> <report file>"
print "If the last is not specified, `tests_stash.txt' is assumed" print "The .test file is written to stdout."
sys.exit(1) sys.exit(1)
rawdata = [] def readRawFile():
for line in open(args[1], "rt").readlines(): rawdata = []
lookfor = ["basic_cpuid", "ext_cpuid", "intel_fn4", "intel_fn11"] for line in open(args[1], "rt").readlines():
good = False lookfor = ["basic_cpuid", "ext_cpuid", "intel_fn4", "intel_fn11"]
for match in lookfor: good = False
if line.find(match) != -1: for match in lookfor:
good = True if line.find(match) != -1:
break good = True
if good: break
rawdata.append(line.strip()) if good:
rawdata.append(line.strip())
return rawdata
repdata = [] def readResultFile():
rexp = re.compile('(-?[0-9]+).*') repdata = []
for line in open(args[2], "rt").readlines(): rexp = re.compile('(-?[0-9]+).*')
s = line.strip() for line in open(args[2], "rt").readlines():
if s.find(":") == -1: s = line.strip()
continue if s.find(":") == -1:
numeric = ["family", "model", "stepping", "ext_family", "ext_model", continue
"num_cores", "num_logical", "L1 D cache", "L1 I cache", numeric = ["family", "model", "stepping", "ext_family", "ext_model",
"L2 cache", "L3 cache", "L1D assoc.", "L2 assoc.", "num_cores", "num_logical", "L1 D cache", "L1 I cache",
"L3 assoc.", "L1D line sz", "L2 line sz", "L3 line sz"] "L2 cache", "L3 cache", "L1D assoc.", "L2 assoc.",
field = s[:s.find(":")].strip() "L3 assoc.", "L1D line sz", "L2 line sz", "L3 line sz"]
if field in numeric: field = s[:s.find(":")].strip()
value = s[s.find(":")+1:].strip() if field in numeric:
if not rexp.match(value): value = s[s.find(":")+1:].strip()
raise "Bad format of value: [%s]" % s if not rexp.match(value):
repdata.append(rexp.findall(value)[0]) raise "Bad format of value: [%s]" % s
if field == "code name": repdata.append(rexp.findall(value)[0])
value = s[s.find("`") + 1: s.find("'")] if field == "code name":
repdata.append(value) value = s[s.find("`") + 1: s.find("'")]
if field == "features": repdata.append(value)
value = s[s.find(":") + 2:] if field == "features":
repdata.append(value) value = s[s.find(":") + 2:]
if field == "SSE units": repdata.append(value)
value = s[s.find(":") + 2:] if field == "SSE units":
# the value here is something like "XX bits (authoritative)". We remove the "bits" part: value = s[s.find(":") + 2:]
i = value.find("bits") # the value here is something like "XX bits (authoritative)". We remove the "bits" part:
if i != -1: i = value.find("bits")
value = value[:i] + value[i + 5:] if i != -1:
repdata.append(value) value = value[:i] + value[i + 5:]
repdata.append(value)
return repdata
stash = "tests_stash.txt"
if len(args) == 4:
stash = args[3]
fout = open(stash, "at")
delimiter = "-" * 80 delimiter = "-" * 80
lines = rawdata + [delimiter] + repdata + [delimiter] lines = readRawFile() + [delimiter] + readResultFile()
fout.writelines(map(lambda s: s + "\n", lines)) sys.stdout.writelines(map(lambda s: s + "\n", lines))
fout.close()