From dc88906c9199e93e89a2d78e6a66acc9567cf834 Mon Sep 17 00:00:00 2001 From: Mohamed Gaber Date: Tue, 23 Sep 2025 08:05:04 +0300 Subject: [PATCH] tests/pyosys: print log on failed test, fix make clean --- .github/workflows/wheels.yml | 3 ++- Makefile | 7 ++++--- tests/pyosys/run_tests.py | 39 +++++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index b561b5d32..d6e9832aa 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -2,6 +2,7 @@ name: Build Wheels for PyPI # run every Sunday at 10 AM on: + push: # TODO: REMOVE THIS, DO NOT MERGE TO UPSTREAM THIS IS JUST SO I DON'T HAVE TO MANUALLY RUN THE WORKFLOW WITH EVERY PUSH workflow_dispatch: schedule: - cron: "0 10 * * 0" @@ -107,7 +108,7 @@ jobs: makeFlags='CONFIG=clang' PATH="$PWD/bison/src:$PATH" CIBW_BEFORE_BUILD: bash ./.github/workflows/wheels/cibw_before_build.sh - CIBW_TEST_COMMAND: python3 {project}/tests/pyosys/run_tests.py python3 + CIBW_TEST_COMMAND: python3 {project}/tests/pyosys/run_tests.py - uses: actions/upload-artifact@v4 with: name: python-wheels-${{ matrix.os.runner }} diff --git a/Makefile b/Makefile index 027f18a7a..09d5f055d 100644 --- a/Makefile +++ b/Makefile @@ -344,6 +344,8 @@ ifeq ($(ENABLE_LIBYOSYS),1) TARGETS += libyosys.so endif +PY_WRAPPER_FILE = pyosys/wrappers + ifeq ($(ENABLE_PYOSYS),1) # python-config --ldflags includes -l and -L, but LINKFLAGS is only -L LINKFLAGS += $(filter-out -l%,$(shell $(PYTHON_CONFIG) --ldflags)) @@ -353,7 +355,6 @@ PYBIND11_INCLUDE ?= $(shell $(PYTHON_EXECUTABLE) -m pybind11 --includes) CXXFLAGS += -I$(PYBIND11_INCLUDE) -DWITH_PYTHON CXXFLAGS += $(shell $(PYTHON_CONFIG) --includes) -DWITH_PYTHON -PY_WRAPPER_FILE = pyosys/wrappers OBJS += $(PY_WRAPPER_FILE).o PY_GEN_SCRIPT = pyosys/generator.py PY_WRAP_INCLUDES := $(shell $(PYTHON_EXECUTABLE) $(PY_GEN_SCRIPT) --print-includes) @@ -1110,9 +1111,9 @@ docs: docs/prep clean: rm -rf share rm -rf kernel/*.pyh - rm -f $(OBJS) $(GENFILES) $(TARGETS) $(EXTRA_TARGETS) $(EXTRA_OBJS) $(PY_WRAP_INCLUDES) $(PY_WRAPPER_FILE).cc + rm -f $(OBJS) $(GENFILES) $(TARGETS) $(EXTRA_TARGETS) $(EXTRA_OBJS) $(PY_WRAP_INCLUDES) $(PY_WRAPPER_FILE).inc.cc $(PY_WRAPPER_FILE).cc rm -f kernel/version_*.o kernel/version_*.cc - rm -f kernel/python_wrappers.o + rm -f $(PY_WRAPPER_FILE).o rm -f libs/*/*.d frontends/*/*.d passes/*/*.d backends/*/*.d kernel/*.d techlibs/*/*.d rm -rf tests/asicworld/*.out tests/asicworld/*.log rm -rf tests/hana/*.out tests/hana/*.log diff --git a/tests/pyosys/run_tests.py b/tests/pyosys/run_tests.py index 953462c4f..6c631c507 100644 --- a/tests/pyosys/run_tests.py +++ b/tests/pyosys/run_tests.py @@ -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)