1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2025-06-07 00:51:40 +00:00

Tests: support XZ files

This commit is contained in:
The Tumultuous Unicorn Of Darkness 2025-02-23 10:49:54 +01:00
parent 817e453e27
commit e46e346a50
No known key found for this signature in database
GPG key ID: 1E55EE2EFF18BC1A

View file

@ -1,7 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os, sys, re, random import os, sys, re, random, lzma
from pathlib import Path
### Constants: ### Constants:
@ -47,7 +48,7 @@ for arg in args[2:]:
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):
filelist += [os.path.join(dirpath, fn) for fn in filenames if fn[-5:] == ".test"] filelist += [os.path.join(dirpath, fn) for fn in filenames if Path(fn).suffixes[0] == ".test"]
else: else:
filelist.append(arg) filelist.append(arg)
@ -128,12 +129,23 @@ def do_test(inp, expected_out, binary, test_file_name, num_cpu_type):
errors = False errors = False
print("Testing...") print("Testing...")
for test_file_name in filelist: for test_file_name_raw in filelist:
test_file_name = Path(test_file_name_raw)
num_cpu_type = 0 num_cpu_type = 0
current_input = [] current_input = []
current_output = [] current_output = []
build_output = False build_output = False
with open(test_file_name, "rt") as f: if len(test_file_name.suffixes) >= 2:
# Compressed file
if test_file_name.suffixes[1] == ".xz":
f = lzma.open(test_file_name, "rt")
else:
print("Test [%s]: skipped because %s is not supported" % (test_file_name.name, "".join(test_file_name.suffixes[1:])))
continue
else:
# Plain text file
f = open(test_file_name, "rt")
# Read file line by line
for line in f.readlines(): for line in f.readlines():
line = line.strip() line = line.strip()
if line == delimiter: if line == delimiter:
@ -144,9 +156,10 @@ for test_file_name in filelist:
current_output.append(line) current_output.append(line)
else: else:
current_input.append(line) current_input.append(line)
f.close()
#codename = current_output[len(current_output) - 2] #codename = current_output[len(current_output) - 2]
result = do_test(current_input, current_output, cpuid_tool, test_file_name, num_cpu_type) result = do_test(current_input, current_output, cpuid_tool, test_file_name, num_cpu_type)
print("Test [%s]: %s" % (test_file_name[:-5], result)) print("Test [%s]: %s" % (test_file_name.name, result))
if result != "OK": if result != "OK":
errors = True errors = True
build_output = False build_output = False