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,28 +129,40 @@ 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:
for line in f.readlines(): # Compressed file
line = line.strip() if test_file_name.suffixes[1] == ".xz":
if line == delimiter: f = lzma.open(test_file_name, "rt")
build_output = True else:
num_cpu_type += 1 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():
line = line.strip()
if line == delimiter:
build_output = True
num_cpu_type += 1
else:
if build_output:
current_output.append(line)
else: else:
if build_output: current_input.append(line)
current_output.append(line) f.close()
else: #codename = current_output[len(current_output) - 2]
current_input.append(line) result = do_test(current_input, current_output, cpuid_tool, test_file_name, num_cpu_type)
#codename = current_output[len(current_output) - 2] print("Test [%s]: %s" % (test_file_name.name, result))
result = do_test(current_input, current_output, cpuid_tool, test_file_name, num_cpu_type) if result != "OK":
print("Test [%s]: %s" % (test_file_name[:-5], result)) errors = True
if result != "OK": build_output = False
errors = True
build_output = False
if errors: if errors:
if show_test_fast_warning: if show_test_fast_warning: