mirror of
https://github.com/anrieff/libcpuid
synced 2024-11-10 22:59:13 +00:00
Add to makefile: "make fix-tests" to fix failing tests.
The last change to flags detection caused a bunch of tests to fail. The reason is that they are bogus, all recent Intel chips don't have RDTSCP indicated in the test files, whereas they have it in reality. I figured it will be easier to add "--fix" option to run_tests.py, rather than fixing each testfile by hand. This is also extended in the Makefile: "make test" runs the tests and reports discrepancies. "make fix-tests" fixes any offending tests. This blindly assumes that libcpuid is sane.
This commit is contained in:
parent
fc4ff90ea8
commit
a716585cc0
2 changed files with 25 additions and 4 deletions
|
@ -11,3 +11,6 @@ consistency:
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(top_srcdir)/tests/run_tests.py $(top_srcdir)/cpuid_tool/cpuid_tool $(top_srcdir)/tests
|
$(top_srcdir)/tests/run_tests.py $(top_srcdir)/cpuid_tool/cpuid_tool $(top_srcdir)/tests
|
||||||
|
|
||||||
|
fix-tests:
|
||||||
|
$(top_srcdir)/tests/run_tests.py $(top_srcdir)/cpuid_tool/cpuid_tool $(top_srcdir)/tests --fix
|
||||||
|
|
|
@ -10,19 +10,26 @@ fields = [ "family", "model", "stepping", "extfamily", "extmodel", "cores",
|
||||||
"l2-cacheline", "l3-cacheline", "sse-size", "codename", "flags" ]
|
"l2-cacheline", "l3-cacheline", "sse-size", "codename", "flags" ]
|
||||||
|
|
||||||
args = sys.argv
|
args = sys.argv
|
||||||
|
fix = False
|
||||||
|
|
||||||
if len(args) < 3:
|
if len(args) < 3:
|
||||||
print """
|
print """
|
||||||
Usage: run_tests.py <cpuid_tool binary> <test file/dir> [test file/dir ...]
|
Usage: run_tests.py <cpuid_tool binary> <test file/dir> [test file/dir ...] [OPTIONS]
|
||||||
|
|
||||||
If a test file is given, it is tested by itself.
|
If a test file is given, it is tested by itself.
|
||||||
If a directory is given, process all *.test files there, subdirectories included.
|
If a directory is given, process all *.test files there, subdirectories included.
|
||||||
|
|
||||||
|
If the --fix option is given, the behaviour of the cpuid_tool binary is deemed correct
|
||||||
|
and any failing tests are updated.
|
||||||
"""
|
"""
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
filelist = []
|
filelist = []
|
||||||
cpuid_tool = args[1]
|
cpuid_tool = args[1]
|
||||||
for arg in args[2:]:
|
for arg in args[2:]:
|
||||||
|
if arg == "--fix":
|
||||||
|
fix = True
|
||||||
|
continue
|
||||||
if os.path.isdir(arg):
|
if os.path.isdir(arg):
|
||||||
# gather all *.test files from subdirs amd and intel:
|
# gather all *.test files from subdirs amd and intel:
|
||||||
for dirpath, dirnames, filenames in os.walk(arg):
|
for dirpath, dirnames, filenames in os.walk(arg):
|
||||||
|
@ -51,7 +58,14 @@ def fmt_error(err):
|
||||||
pfix = " %s: " % err[0]
|
pfix = " %s: " % err[0]
|
||||||
return "%sexpected `%s'\n%sgot `%s'" % (pfix, err[1], " "*len(pfix), err[2])
|
return "%sexpected `%s'\n%sgot `%s'" % (pfix, err[1], " "*len(pfix), err[2])
|
||||||
|
|
||||||
def do_test(inp, expected_out, binary):
|
def fixFile(filename, input_lines, output_lines):
|
||||||
|
f = open(filename, "wt")
|
||||||
|
f.writelines(map(lambda s: s + "\n", input_lines))
|
||||||
|
f.write("--------------------------------------------------------------------------------\n")
|
||||||
|
f.writelines(map(lambda s: s + "\n", output_lines))
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def do_test(inp, expected_out, binary, test_file_name):
|
||||||
fninp = make_tempname("cpuidin")
|
fninp = make_tempname("cpuidin")
|
||||||
fnoutp = make_tempname("cpuidout")
|
fnoutp = make_tempname("cpuidout")
|
||||||
f = open(fninp, "wt")
|
f = open(fninp, "wt")
|
||||||
|
@ -76,6 +90,10 @@ def do_test(inp, expected_out, binary):
|
||||||
err_fields.append((fields[i], expected_out[i], real_out[i]))
|
err_fields.append((fields[i], expected_out[i], real_out[i]))
|
||||||
if not err_fields:
|
if not err_fields:
|
||||||
return "OK"
|
return "OK"
|
||||||
|
else:
|
||||||
|
if fix:
|
||||||
|
fixFile(test_file_name, inp, real_out)
|
||||||
|
return "Mismatch, fixed."
|
||||||
else:
|
else:
|
||||||
return "Mismatch in fields:\n%s" % "\n".join([fmt_error(err) for err in err_fields])
|
return "Mismatch in fields:\n%s" % "\n".join([fmt_error(err) for err in err_fields])
|
||||||
|
|
||||||
|
@ -95,7 +113,7 @@ for test_file_name in filelist:
|
||||||
else:
|
else:
|
||||||
current_input.append(line.strip())
|
current_input.append(line.strip())
|
||||||
#codename = current_output[len(current_output) - 2]
|
#codename = current_output[len(current_output) - 2]
|
||||||
result = do_test(current_input, current_output, cpuid_tool)
|
result = do_test(current_input, current_output, cpuid_tool, test_file_name)
|
||||||
print "Test [%s]: %s" % (test_file_name[:-5], result)
|
print "Test [%s]: %s" % (test_file_name[:-5], result)
|
||||||
if result != "OK":
|
if result != "OK":
|
||||||
errors = True
|
errors = True
|
||||||
|
|
Loading…
Reference in a new issue