From 413b9a4639be842f3b7fa871d172cd66ed6039d5 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 13 Mar 2026 11:00:08 +0100 Subject: [PATCH] Add common.mk --- tests/Makefile | 32 ++++++--------------------- tests/common.mk | 43 +++++++++++++++++++++++++++++++++++++ tests/gen_tests_makefile.py | 16 +++----------- 3 files changed, 53 insertions(+), 38 deletions(-) create mode 100644 tests/common.mk diff --git a/tests/Makefile b/tests/Makefile index 5b32bc51d..d22e0bf50 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,3 +1,10 @@ +ifneq ($(wildcard ../Makefile.conf),) +include ../Makefile.conf +endif + +OVERRIDE_MAIN=1 +include ./common.mk + # Tests that generate Makefile with gen_tests_makefile.py MK_TEST_DIRS = MK_TEST_DIRS += ./arch/analogdevices @@ -106,22 +113,6 @@ endif @echo "" -@$(MAKE) --no-print-directory summary -.PHONY: summary -summary: - @pass=$$(find . -type f -name '*.result' -exec grep '^PASS$$' {} + | wc -l); \ - fail=$$(find . -type f -name '*.result' -exec grep '^FAIL$$' {} + | wc -l); \ - total=$$((pass + fail)); \ - echo "=========================="; \ - echo "Tests: $$total"; \ - echo "Passed: $$pass"; \ - echo "Failed: $$fail"; \ - echo "=========================="; \ - if [ $$fail -ne 0 ]; then \ - echo; \ - $(MAKE) --no-print-directory report; \ - fi; \ - test $$fail -eq 0 - clean: @rm -rf ./asicworld/*.out ./asicworld/*.log @rm -rf ./hana/*.out ./hana/*.log @@ -134,12 +125,3 @@ clean: @rm -f $(addsuffix /run-test.mk,$(MK_TEST_DIRS)) @find . -name '*.result' -type f -exec rm -f {} + @find . -mindepth 2 \( -path './sva*' -o -path './unit*' \) -prune -o -name 'Makefile' -type f -exec rm -f {} + - -.PHONY: report -report: - @echo "==========================" - @echo "Failing tests:" - @find . -name '*.result' -type f -exec grep -H '^FAIL$$' {} + \ - | cut -d: -f1 \ - | sed 's|^\./||; s|\.result$$||' - @echo "==========================" diff --git a/tests/common.mk b/tests/common.mk new file mode 100644 index 000000000..ee4c5dee7 --- /dev/null +++ b/tests/common.mk @@ -0,0 +1,43 @@ +all: + +ifndef OVERRIDE_MAIN +clean: + @rm -f *.log *.result +endif + +define run_test + rc=0; \ + $(2) || rc=$$?; \ + if [ $$rc -eq 0 ]; then \ + echo "PASS $1"; \ + echo PASS > $1.result; \ + else \ + echo "FAIL $1"; \ + echo FAIL > $1.result; \ + fi +endef + +.PHONY: summary +summary: + @pass=$$(find . -type f -name '*.result' -exec grep '^PASS$$' {} + | wc -l); \ + fail=$$(find . -type f -name '*.result' -exec grep '^FAIL$$' {} + | wc -l); \ + total=$$((pass + fail)); \ + echo "=========================="; \ + echo "Tests: $$total"; \ + echo "Passed: $$pass"; \ + echo "Failed: $$fail"; \ + echo "=========================="; \ + if [ $$fail -ne 0 ]; then \ + echo; \ + $(MAKE) --no-print-directory report; \ + fi; \ + test $$fail -eq 0 + +.PHONY: report +report: + @echo "==========================" + @echo "Failing tests:" + @find . -name '*.result' -type f -exec grep -H '^FAIL$$' {} + \ + | cut -d: -f1 \ + | sed 's|^\./||; s|\.result$$||' + @echo "==========================" diff --git a/tests/gen_tests_makefile.py b/tests/gen_tests_makefile.py index dea815174..b61e4917d 100644 --- a/tests/gen_tests_makefile.py +++ b/tests/gen_tests_makefile.py @@ -5,7 +5,8 @@ import os import sys import argparse -yosys_basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) +yosys_basedir = os.path.relpath(os.path.join(os.path.dirname(__file__), "..")) +common_mk = os.path.relpath(os.path.join(os.path.dirname(__file__), "common.mk")) def _cwd_base(): return os.path.basename(os.getcwd()) @@ -50,20 +51,9 @@ def generate_tests(argv): if not (args.yosys_scripts or args.tcl_scripts or args.prove_sv or args.bash): raise RuntimeError("No file types selected") + print(f"include {common_mk}") print(f"YOSYS ?= {yosys_basedir}/yosys") print() - print("define run_test") - print(" rc=0; \\") - print(" $(2) || rc=$$?; \\") - print(" if [ $$rc -eq 0 ]; then \\") - print(" echo \"PASS $1\"; \\") - print(" echo PASS > $1.result; \\") - print(" else \\") - print(" echo \"FAIL $1\"; \\") - print(" echo FAIL > $1.result; \\") - print(" fi") - print("endef") - print() print(".PHONY: all") print("all:")