1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-11-10 22:59:13 +00:00

Refactor "make test" as well.

This commit is contained in:
Veselin Georgiev 2014-07-16 10:10:51 +03:00
parent 019170b65f
commit f6acf1b634
2 changed files with 41 additions and 30 deletions

View file

@ -10,4 +10,4 @@ consistency:
$(top_srcdir)/libcpuid/check-consistency.py $(top_srcdir)/libcpuid $(top_srcdir)/libcpuid/check-consistency.py $(top_srcdir)/libcpuid
test: test:
$(top_srcdir)/tests/run_tests.py $(top_srcdir)/tests/tests_stash.txt $(top_srcdir)/cpuid_tool/cpuid_tool $(top_srcdir)/tests/run_tests.py $(top_srcdir)/cpuid_tool/cpuid_tool $(top_srcdir)/tests

View file

@ -11,13 +11,28 @@ fields = [ "family", "model", "stepping", "extfamily", "extmodel", "cores",
args = sys.argv args = sys.argv
if len(args) != 3: if len(args) < 3:
print "Usage: run_tests <tests stash file> <cpiud_tool binary>" print """
Usage: run_tests.py <cpuid_tool binary> <test file/dir> [test file/dir ...]
If a test file is given, it is tested by itself.
If a directory is given, process all *.test files there, subdirectories included.
"""
sys.exit(1) sys.exit(1)
f = open(args[1], "rt") filelist = []
lines = f.readlines() cpuid_tool = args[1]
f.close() for arg in args[2:]:
if os.path.isdir(arg):
# gather all *.test files from subdirs amd and intel:
for dirpath, dirnames, filenames in os.walk(arg):
filelist += [os.path.join(dirpath, fn) for fn in filenames if fn[-5:] == ".test"]
else:
filelist.append(arg)
#f = open(args[1], "rt")
#lines = f.readlines()
#f.close()
# One would usually use os.tempnam, but libc gives off hell a lot of # One would usually use os.tempnam, but libc gives off hell a lot of
# warnings when you attempt to use that :( # warnings when you attempt to use that :(
@ -36,7 +51,7 @@ 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, testno, binary): def do_test(inp, expected_out, binary):
fninp = make_tempname("cpuidin") fninp = make_tempname("cpuidin")
fnoutp = make_tempname("cpuidout") fnoutp = make_tempname("cpuidout")
f = open(fninp, "wt") f = open(fninp, "wt")
@ -64,31 +79,27 @@ def do_test(inp, expected_out, testno, binary):
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])
current_input = []
current_output = []
build_output = False
errors = False errors = False
test_no = 1
print "Testing..." print "Testing..."
for line in lines: for test_file_name in filelist:
if line[:3] == "---": current_input = []
if build_output: current_output = []
codename = current_output[len(current_output) - 2] build_output = False
result = do_test(current_input, current_output, test_no, args[2]) with open(test_file_name, "rt") as f:
print "Test %d [%s]: %s" % (test_no, codename, result) for line in f.readlines():
if result != "OK": if line[:3] == "---":
errors = True build_output = True
build_output = False else:
test_no += 1 if build_output:
current_input = [] current_output.append(line.strip())
current_output = [] else:
else: current_input.append(line.strip())
build_output = True #codename = current_output[len(current_output) - 2]
else: result = do_test(current_input, current_output, cpuid_tool)
if build_output: print "Test [%s]: %s" % (test_file_name[:-5], result)
current_output.append(line.strip()) if result != "OK":
else: errors = True
current_input.append(line.strip()) build_output = False
if not errors: if not errors:
print "All successfull!" print "All successfull!"