3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-10-09 01:11:58 +00:00

tests/pyosys: print log on failed test, fix make clean

This commit is contained in:
Mohamed Gaber 2025-09-23 08:05:04 +03:00
parent 54799bb8be
commit dc88906c91
No known key found for this signature in database
3 changed files with 29 additions and 20 deletions

View file

@ -1,39 +1,46 @@
from pathlib import Path
import shutil
import subprocess
import sys
import shutil
import shlex
import subprocess
from pathlib import Path
__file_dir__ = Path(__file__).absolute().parent
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} {sys.argv[1]}")
if len(sys.argv) > 2 or len(sys.argv) == 2 and sys.argv[1] != 'yosys':
print(f"Usage: {sys.argv[0]} [yosys]")
exit(64)
binary = []
if sys.argv[1] in ["yosys"]:
binary = [__file_dir__.parents[1] / "yosys", "-Qy"]
if len(sys.argv) == 2:
binary = [str(__file_dir__.parents[1] / "yosys"), "-Qy"]
else:
binary = [sys.argv[1]]
binary = [sys.executable or shutil.which("python3") or "python3"] # sys.executable can actually be None
tests = __file_dir__.glob("test_*.py")
errors = False
log_dir = __file_dir__ / "logs"
try:
shutil.rmtree(log_dir)
except FileNotFoundError:
pass
fail_logs = set()
for test in tests:
print(f"* {test.name} ", end="")
log_dir.mkdir(parents=True, exist_ok=True)
log = log_dir / (test.stem + ".log")
result = subprocess.run([
*binary,
test
], stdout=open(log, "w"), stderr=subprocess.STDOUT)
cmd = [*binary, str(test)]
log_file = open(log, "w", encoding="utf8")
log_file.write(f"$ {shlex.join(cmd)}\n")
log_file.flush()
result = subprocess.run(cmd, stdout=log_file, stderr=subprocess.STDOUT)
if result.returncode == 0:
print("OK!")
else:
print(f"FAILED: {log}")
errors = True
if errors:
fail_logs.add(log)
log_file.close()
for log in fail_logs:
print(f">>> {log}")
with open(log, encoding="utf8") as f:
print(f.read())
if len(fail_logs):
exit(1)