From 2fb0ca49ff8576d0458d3e764f89ce7e9234e4ce Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 13 Mar 2026 08:38:05 +0100 Subject: [PATCH] Convert gen-tests shell script to python --- tests/.gitignore | 1 + tests/Makefile | 17 +-- tests/aiger/generate_mk.py | 68 +++++++++++ tests/alumacc/generate_mk.py | 8 ++ tests/arch/analogdevices/generate_mk.py | 9 ++ tests/arch/analogdevices/run-test.sh | 5 - tests/arch/anlogic/generate_mk.py | 8 ++ tests/arch/anlogic/run-test.sh | 4 - tests/arch/ecp5/generate_mk.py | 8 ++ tests/arch/ecp5/run-test.sh | 4 - tests/arch/efinix/generate_mk.py | 8 ++ tests/arch/efinix/run-test.sh | 4 - tests/arch/fabulous/fsm.ys | 8 +- tests/arch/fabulous/generate_mk.py | 8 ++ tests/arch/gatemate/generate_mk.py | 8 ++ tests/arch/gatemate/run-test.sh | 4 - tests/arch/gowin/generate_mk.py | 8 ++ tests/arch/gowin/run-test.sh | 4 - tests/arch/ice40/generate_mk.py | 8 ++ tests/arch/ice40/run-test.sh | 4 - tests/arch/intel_alm/generate_mk.py | 8 ++ tests/arch/intel_alm/run-test.sh | 4 - tests/arch/machxo2/generate_mk.py | 8 ++ tests/arch/machxo2/run-test.sh | 4 - tests/arch/microchip/generate_mk.py | 8 ++ tests/arch/microchip/run-test.sh | 4 - tests/arch/nanoxplore/generate_mk.py | 8 ++ tests/arch/nanoxplore/run-test.sh | 4 - tests/arch/nexus/generate_mk.py | 8 ++ tests/arch/nexus/run-test.sh | 4 - tests/arch/quicklogic/pp3/generate_mk.py | 8 ++ tests/arch/quicklogic/pp3/run-test.sh | 4 - .../arch/quicklogic/qlf_k6n10f/generate_mk.py | 9 ++ tests/arch/quicklogic/qlf_k6n10f/run-test.sh | 5 - tests/arch/xilinx/generate_mk.py | 8 ++ tests/arch/xilinx/run-test.sh | 4 - tests/bugpoint/generate_mk.py | 8 ++ tests/bugpoint/run-test.sh | 4 - tests/gen-tests-makefile.sh | 110 ------------------ tests/gen_tests_makefile.py | 86 ++++++++++++++ tests/opt/generate_mk.py | 8 ++ tests/opt/run-test.sh | 4 - tests/rtlil/generate_mk.py | 8 ++ tests/rtlil/run-test.sh | 4 - tests/sat/generate_mk.py | 8 ++ tests/sat/run-test.sh | 4 - tests/sdc/generate_mk.py | 8 ++ tests/sdc/run-test.sh | 4 - tests/sim/generate_mk.py | 35 ++++++ tests/sim/run-test.sh | 12 -- tests/svtypes/generate_mk.py | 8 ++ tests/svtypes/run-test.sh | 4 - tests/techmap/generate_mk.py | 8 ++ tests/techmap/run-test.sh | 4 - tests/various/generate_mk.py | 8 ++ tests/various/run-test.sh | 4 - tests/verific/generate_mk.py | 8 ++ tests/verific/run-test.sh | 5 - tests/verilog/generate_mk.py | 8 ++ tests/verilog/run-test.sh | 4 - 60 files changed, 421 insertions(+), 237 deletions(-) create mode 100644 tests/aiger/generate_mk.py create mode 100644 tests/alumacc/generate_mk.py create mode 100644 tests/arch/analogdevices/generate_mk.py delete mode 100755 tests/arch/analogdevices/run-test.sh create mode 100644 tests/arch/anlogic/generate_mk.py delete mode 100755 tests/arch/anlogic/run-test.sh create mode 100644 tests/arch/ecp5/generate_mk.py delete mode 100755 tests/arch/ecp5/run-test.sh create mode 100644 tests/arch/efinix/generate_mk.py delete mode 100755 tests/arch/efinix/run-test.sh create mode 100644 tests/arch/fabulous/generate_mk.py create mode 100644 tests/arch/gatemate/generate_mk.py delete mode 100755 tests/arch/gatemate/run-test.sh create mode 100644 tests/arch/gowin/generate_mk.py delete mode 100755 tests/arch/gowin/run-test.sh create mode 100644 tests/arch/ice40/generate_mk.py delete mode 100755 tests/arch/ice40/run-test.sh create mode 100644 tests/arch/intel_alm/generate_mk.py delete mode 100755 tests/arch/intel_alm/run-test.sh create mode 100644 tests/arch/machxo2/generate_mk.py delete mode 100644 tests/arch/machxo2/run-test.sh create mode 100644 tests/arch/microchip/generate_mk.py delete mode 100755 tests/arch/microchip/run-test.sh create mode 100644 tests/arch/nanoxplore/generate_mk.py delete mode 100755 tests/arch/nanoxplore/run-test.sh create mode 100644 tests/arch/nexus/generate_mk.py delete mode 100644 tests/arch/nexus/run-test.sh create mode 100644 tests/arch/quicklogic/pp3/generate_mk.py delete mode 100755 tests/arch/quicklogic/pp3/run-test.sh create mode 100644 tests/arch/quicklogic/qlf_k6n10f/generate_mk.py delete mode 100755 tests/arch/quicklogic/qlf_k6n10f/run-test.sh create mode 100644 tests/arch/xilinx/generate_mk.py delete mode 100755 tests/arch/xilinx/run-test.sh create mode 100644 tests/bugpoint/generate_mk.py delete mode 100755 tests/bugpoint/run-test.sh delete mode 100755 tests/gen-tests-makefile.sh create mode 100644 tests/gen_tests_makefile.py create mode 100644 tests/opt/generate_mk.py delete mode 100755 tests/opt/run-test.sh create mode 100644 tests/rtlil/generate_mk.py delete mode 100755 tests/rtlil/run-test.sh create mode 100644 tests/sat/generate_mk.py delete mode 100755 tests/sat/run-test.sh create mode 100644 tests/sdc/generate_mk.py delete mode 100755 tests/sdc/run-test.sh create mode 100644 tests/sim/generate_mk.py delete mode 100755 tests/sim/run-test.sh create mode 100644 tests/svtypes/generate_mk.py delete mode 100755 tests/svtypes/run-test.sh create mode 100644 tests/techmap/generate_mk.py delete mode 100755 tests/techmap/run-test.sh create mode 100644 tests/various/generate_mk.py delete mode 100755 tests/various/run-test.sh create mode 100644 tests/verific/generate_mk.py delete mode 100755 tests/verific/run-test.sh create mode 100644 tests/verilog/generate_mk.py delete mode 100755 tests/verilog/run-test.sh diff --git a/tests/.gitignore b/tests/.gitignore index d8e01e026..da4350076 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -2,3 +2,4 @@ *.out *.err run-test.mk +**/Makefile diff --git a/tests/Makefile b/tests/Makefile index 6742b6076..5ec699417 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,9 +1,10 @@ -# Tests that generate .mk with ./gen-tests-makefile.sh +# Tests that generate Makefile with gen_tests_makefile.py MK_TEST_DIRS = MK_TEST_DIRS += ./arch/analogdevices MK_TEST_DIRS += ./arch/anlogic MK_TEST_DIRS += ./arch/ecp5 MK_TEST_DIRS += ./arch/efinix +MK_TEST_DIRS += ./arch/fabulous MK_TEST_DIRS += ./arch/gatemate MK_TEST_DIRS += ./arch/gowin MK_TEST_DIRS += ./arch/ice40 @@ -84,14 +85,14 @@ abcopt-./%: %/run-test.sh # makefile-./ is a dummy string, not a directory .PHONY: makefile-tests -#.SILENT: $(MK_TEST_DIRS:%=%/run-test.mk) +.SILENT: $(MK_TEST_DIRS:%=%/Makefile) makefile-tests: $(MK_TEST_DIRS:%=makefile-./%) -# this target actually emits .mk files -%.mk: - +@cd $(dir $*) && bash run-test.sh -# this one spawns submake on each -makefile-./%: %/run-test.mk - @$(MAKE) -C $* -f run-test.mk +# this target actually emits Makefile files +%/Makefile: + +@cd $* && python3 generate_mk.py + +makefile-./%: %/Makefile + @$(MAKE) -C $* @echo "...passed tests in $*" vanilla-test: makefile-tests abcopt-tests seed-tests diff --git a/tests/aiger/generate_mk.py b/tests/aiger/generate_mk.py new file mode 100644 index 000000000..e0a15332e --- /dev/null +++ b/tests/aiger/generate_mk.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +import glob +import os + +yosys = "../../yosys" +default_abc = "../../yosys-abc" + +aags = sorted(glob.glob("*.aag")) +yss = sorted(glob.glob("*.ys")) + +print("ABC ?= " + default_abc) +print("YOSYS ?= " + yosys) +print() + +def base(fn): + return os.path.splitext(fn)[0] + +# NB: *.aag and *.aig must contain a symbol table naming the primary +# inputs and outputs, otherwise ABC and Yosys will name them +# arbitrarily (and inconsistently with each other). + +# Since ABC cannot read *.aag, read the *.aig instead +# (which would have been created by the reference aig2aig utility, +# available from http://fmv.jku.at/aiger/) + +for aag in aags: + b = base(aag) + + print(f"all: {aag}") + print(f".PHONY: {aag}") + print(f"{aag}:") + print(f"\t@echo Checking {aag}.") + print(f"\t@$(ABC) -q \"read -c {b}.aig; write {b}_ref.v\" >/dev/null 2>&1") + print("\t@$(YOSYS) -qp \"\\") + print(f"\tread_verilog {b}_ref.v; \\") + print("\tprep; \\") + print("\tdesign -stash gold; \\") + print(f"\tread_aiger -clk_name clock {aag}; \\") + print("\tprep; \\") + print("\tdesign -stash gate; \\") + print("\tdesign -import gold -as gold; \\") + print("\tdesign -import gate -as gate; \\") + print("\tmiter -equiv -flatten -make_assert -make_outputs gold gate miter; \\") + print("\tsat -verify -prove-asserts -show-ports -seq 16 miter; \\") + print(f"\t\" -l {aag}.log >/dev/null 2>&1") + print() + +# ---- Yosys script tests ---- +for ys in yss: + b = base(ys) + print(f"all: {ys}") + print(f".PHONY: {ys}") + print(f"{ys}: ") + print(f"\t@echo Running {ys}.") + print(f"\t@$(YOSYS) -ql {b}.log {ys} >/dev/null 2>&1") + print() + +# ---- aigmap test ---- +print(f"all: aigmap") +print(f".PHONY: aigmap") +print("aigmap:") +print("\t@echo Running aigmap.") +print("\t@rm -rf gate; mkdir gate") +print('\t@$(YOSYS) --no-version -p "test_cell -aigmap -w gate/ -n 1 -s 1 all" >/dev/null 2>&1') +print("\t@set -o pipefail; diff --brief gold gate | tee aigmap.err") +print("\t@rm -f aigmap.err") +print() diff --git a/tests/alumacc/generate_mk.py b/tests/alumacc/generate_mk.py new file mode 100644 index 000000000..6a921d5a0 --- /dev/null +++ b/tests/alumacc/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts"]) diff --git a/tests/arch/analogdevices/generate_mk.py b/tests/arch/analogdevices/generate_mk.py new file mode 100644 index 000000000..b453168c0 --- /dev/null +++ b/tests/arch/analogdevices/generate_mk.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile +import mem_gen + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/analogdevices/run-test.sh b/tests/arch/analogdevices/run-test.sh deleted file mode 100755 index 9b5e2f7f4..000000000 --- a/tests/arch/analogdevices/run-test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -eu -python3 mem_gen.py -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash diff --git a/tests/arch/anlogic/generate_mk.py b/tests/arch/anlogic/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/anlogic/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/anlogic/run-test.sh b/tests/arch/anlogic/run-test.sh deleted file mode 100755 index 691b70966..000000000 --- a/tests/arch/anlogic/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/ecp5/generate_mk.py b/tests/arch/ecp5/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/ecp5/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/ecp5/run-test.sh b/tests/arch/ecp5/run-test.sh deleted file mode 100755 index 691b70966..000000000 --- a/tests/arch/ecp5/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/efinix/generate_mk.py b/tests/arch/efinix/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/efinix/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/efinix/run-test.sh b/tests/arch/efinix/run-test.sh deleted file mode 100755 index 691b70966..000000000 --- a/tests/arch/efinix/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/fabulous/fsm.ys b/tests/arch/fabulous/fsm.ys index 9c3831682..15fd19247 100644 --- a/tests/arch/fabulous/fsm.ys +++ b/tests/arch/fabulous/fsm.ys @@ -11,9 +11,9 @@ sat -verify -prove-asserts -show-public -set-at 1 in_reset 1 -seq 20 -prove-skip design -load postopt # load the post-opt design (otherwise equiv_opt loads the pre-opt design) cd fsm # Constrain all select calls below inside the top module - +stat select -assert-count 6 t:LUTFF -select -assert-max 4 t:LUT2 -select -assert-max 2 t:LUT3 -select -assert-max 9 t:LUT4 +select -assert-max 5 t:LUT2 +select -assert-max 4 t:LUT3 +select -assert-max 8 t:LUT4 select -assert-none t:LUT2 t:LUT3 t:LUT4 t:LUTFF %% t:* %D diff --git a/tests/arch/fabulous/generate_mk.py b/tests/arch/fabulous/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/fabulous/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/gatemate/generate_mk.py b/tests/arch/gatemate/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/gatemate/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/gatemate/run-test.sh b/tests/arch/gatemate/run-test.sh deleted file mode 100755 index 691b70966..000000000 --- a/tests/arch/gatemate/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/gowin/generate_mk.py b/tests/arch/gowin/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/gowin/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/gowin/run-test.sh b/tests/arch/gowin/run-test.sh deleted file mode 100755 index 691b70966..000000000 --- a/tests/arch/gowin/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/ice40/generate_mk.py b/tests/arch/ice40/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/ice40/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/ice40/run-test.sh b/tests/arch/ice40/run-test.sh deleted file mode 100755 index 691b70966..000000000 --- a/tests/arch/ice40/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/intel_alm/generate_mk.py b/tests/arch/intel_alm/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/intel_alm/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/intel_alm/run-test.sh b/tests/arch/intel_alm/run-test.sh deleted file mode 100755 index 691b70966..000000000 --- a/tests/arch/intel_alm/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/machxo2/generate_mk.py b/tests/arch/machxo2/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/machxo2/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/machxo2/run-test.sh b/tests/arch/machxo2/run-test.sh deleted file mode 100644 index 691b70966..000000000 --- a/tests/arch/machxo2/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/microchip/generate_mk.py b/tests/arch/microchip/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/microchip/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/microchip/run-test.sh b/tests/arch/microchip/run-test.sh deleted file mode 100755 index 691b70966..000000000 --- a/tests/arch/microchip/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/nanoxplore/generate_mk.py b/tests/arch/nanoxplore/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/nanoxplore/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/nanoxplore/run-test.sh b/tests/arch/nanoxplore/run-test.sh deleted file mode 100755 index 691b70966..000000000 --- a/tests/arch/nanoxplore/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/nexus/generate_mk.py b/tests/arch/nexus/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/nexus/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/nexus/run-test.sh b/tests/arch/nexus/run-test.sh deleted file mode 100644 index 691b70966..000000000 --- a/tests/arch/nexus/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/quicklogic/pp3/generate_mk.py b/tests/arch/quicklogic/pp3/generate_mk.py new file mode 100644 index 000000000..e001d7e4a --- /dev/null +++ b/tests/arch/quicklogic/pp3/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/quicklogic/pp3/run-test.sh b/tests/arch/quicklogic/pp3/run-test.sh deleted file mode 100755 index 43a7874b2..000000000 --- a/tests/arch/quicklogic/pp3/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/arch/quicklogic/qlf_k6n10f/generate_mk.py b/tests/arch/quicklogic/qlf_k6n10f/generate_mk.py new file mode 100644 index 000000000..e9abad21a --- /dev/null +++ b/tests/arch/quicklogic/qlf_k6n10f/generate_mk.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../../..") + +import gen_tests_makefile +import mem_gen + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/quicklogic/qlf_k6n10f/run-test.sh b/tests/arch/quicklogic/qlf_k6n10f/run-test.sh deleted file mode 100755 index c7daba12d..000000000 --- a/tests/arch/quicklogic/qlf_k6n10f/run-test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -eu -python3 mem_gen.py -source ../../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash diff --git a/tests/arch/xilinx/generate_mk.py b/tests/arch/xilinx/generate_mk.py new file mode 100644 index 000000000..06a6040ad --- /dev/null +++ b/tests/arch/xilinx/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("../..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/arch/xilinx/run-test.sh b/tests/arch/xilinx/run-test.sh deleted file mode 100755 index 691b70966..000000000 --- a/tests/arch/xilinx/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/bugpoint/generate_mk.py b/tests/bugpoint/generate_mk.py new file mode 100644 index 000000000..6a921d5a0 --- /dev/null +++ b/tests/bugpoint/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts"]) diff --git a/tests/bugpoint/run-test.sh b/tests/bugpoint/run-test.sh deleted file mode 100755 index 006c731e3..000000000 --- a/tests/bugpoint/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../gen-tests-makefile.sh -generate_mk --yosys-scripts diff --git a/tests/gen-tests-makefile.sh b/tests/gen-tests-makefile.sh deleted file mode 100755 index 07d70c2a8..000000000 --- a/tests/gen-tests-makefile.sh +++ /dev/null @@ -1,110 +0,0 @@ -set -eu - -YOSYS_BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/../ >/dev/null 2>&1 && pwd)" - -# $ generate_target target_name test_command -generate_target() { - target_name=$(basename $PWD)-$1 - test_command=$2 - echo "all: $target_name" - echo ".PHONY: $target_name" - echo "$target_name:" - printf "\t@YOSYS_MAX_THREADS=4 %s\n" "$test_command" - printf "\t@echo 'Passed %s'\n" "$target_name" -} - -# $ generate_ys_test ys_file [yosys_args] -generate_ys_test() { - ys_file=$1 - yosys_args_=${2:-} - generate_target "$ys_file" "\"$YOSYS_BASEDIR/yosys\" -ql ${ys_file}.err $yosys_args_ $ys_file >/dev/null 2>&1 && mv ${ys_file}.err ${ys_file}.log" -} - -# $ generate_tcl_test tcl_file [yosys_args] -generate_tcl_test() { - tcl_file=$1 - yosys_args_=${2:-} - generate_target "$tcl_file" "\"$YOSYS_BASEDIR/yosys\" -ql ${tcl_file}.err $yosys_args_ $tcl_file >/dev/null 2>&1 && mv ${tcl_file}.err ${tcl_file}.log" -} - -# $ generate_bash_test bash_file -generate_bash_test() { - bash_file=$1 - generate_target "$bash_file" "bash -v $bash_file >${bash_file}.err 2>&1 && mv ${bash_file}.err ${bash_file}.log" -} - -# $ generate_tests [-y|--yosys-scripts] [-s|--prove-sv] [-b|--bash] [-a|--yosys-args yosys_args] -generate_tests() { - do_ys=false - do_tcl=false - do_sv=false - do_sh=false - yosys_args="" - - while [[ $# -gt 0 ]]; do - arg="$1" - case "$arg" in - -y|--yosys-scripts) - do_ys=true - shift - ;; - -t|--tcl-scripts) - do_tcl=true - shift - ;; - -s|--prove-sv) - do_sv=true - shift - ;; - -b|--bash) - do_sh=true - shift - ;; - -a|--yosys-args) - yosys_args+="$2" - shift - shift - ;; - *) - echo >&2 "Unknown argument: $1" - exit 1 - esac - done - - if [[ ! ( $do_ys = true || $do_tcl = true || $do_sv = true || $do_sh = true ) ]]; then - echo >&2 "Error: No file types selected" - exit 1 - fi - - echo ".PHONY: all" - echo "all:" - - if [[ $do_ys = true ]]; then - for x in *.ys; do - generate_ys_test "$x" "$yosys_args" - done - fi; - if [[ $do_tcl = true ]]; then - for x in *.tcl; do - generate_tcl_test "$x" "$yosys_args" - done - fi; - if [[ $do_sv = true ]]; then - for x in *.sv; do - if [ ! -f "${x%.sv}.ys" ]; then - generate_ys_test "$x" "-p \"prep -top top; async2sync; sat -enable_undef -verify -prove-asserts\" $yosys_args" - fi; - done - fi; - if [[ $do_sh == true ]]; then - for s in *.sh; do - if [ "$s" != "run-test.sh" ]; then - generate_bash_test "$s" - fi - done - fi -} - -generate_mk() { - generate_tests "$@" > run-test.mk -} diff --git a/tests/gen_tests_makefile.py b/tests/gen_tests_makefile.py new file mode 100644 index 000000000..dbd7a2bc9 --- /dev/null +++ b/tests/gen_tests_makefile.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 + +import glob +import os +import sys +import argparse + +yosys_basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) + +def _cwd_base(): + return os.path.basename(os.getcwd()) + +def generate_target(name, command): + target = f"{_cwd_base()}-{name}" + print(f"all: {target}") + print(f".PHONY: {target}") + print(f"{target}:") + print(f"\t@YOSYS_MAX_THREADS=4 {command}") + print(f"\t@echo 'Passed {target}'") + +def generate_ys_test(ys_file, yosys_args=""): + cmd = f'$(YOSYS) -ql {ys_file}.err {yosys_args} {ys_file} >/dev/null 2>&1 && mv {ys_file}.err {ys_file}.log' + generate_target(ys_file, cmd) + +def generate_tcl_test(tcl_file, yosys_args=""): + cmd = f'$(YOSYS) -ql {tcl_file}.err {yosys_args} {tcl_file} >/dev/null 2>&1 && mv {tcl_file}.err {tcl_file}.log' + generate_target(tcl_file, cmd) + +def generate_sv_test(sv_file, yosys_args=""): + base = os.path.splitext(sv_file)[0] + if not os.path.exists(base + ".ys"): + yosys_cmd = '-p "prep -top top; async2sync; sat -enable_undef -verify -prove-asserts"' + cmd = f'$(YOSYS) -ql {sv_file}.err {yosys_cmd} {yosys_args} {sv_file} >/dev/null 2>&1 && mv {sv_file}.err {sv_file}.log' + generate_target(sv_file, cmd) + +def generate_bash_test(sh_file): + cmd = f"bash -v {sh_file} >{sh_file}.err 2>&1 && mv {sh_file}.err {sh_file}.log" + generate_target(sh_file, cmd) + +def generate_tests(argv): + parser = argparse.ArgumentParser(add_help=False) + parser.add_argument("-y", "--yosys-scripts", action="store_true") + parser.add_argument("-t", "--tcl-scripts", action="store_true") + parser.add_argument("-s", "--prove-sv", action="store_true") + parser.add_argument("-b", "--bash", action="store_true") + parser.add_argument("-a", "--yosys-args", default="") + + args = parser.parse_args(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"YOSYS ?= {yosys_basedir}/yosys") + print() + + print(".PHONY: all") + print("all:") + + if args.yosys_scripts: + for f in sorted(glob.glob("*.ys")): + generate_ys_test(f, args.yosys_args) + + if args.tcl_scripts: + for f in sorted(glob.glob("*.tcl")): + generate_tcl_test(f, args.yosys_args) + + if args.prove_sv: + for f in sorted(glob.glob("*.sv")): + generate_sv_test(f, args.yosys_args) + + if args.bash: + for f in sorted(glob.glob("*.sh")): + if f != "run-test.sh": + generate_bash_test(f) + +def generate(argv, extra=None): + with open("Makefile", "w") as f: + old = sys.stdout + sys.stdout = f + try: + if extra: + for line in extra: + print(line) + generate_tests(argv) + finally: + sys.stdout = old diff --git a/tests/opt/generate_mk.py b/tests/opt/generate_mk.py new file mode 100644 index 000000000..4c31c5a2b --- /dev/null +++ b/tests/opt/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--tcl-scripts"]) diff --git a/tests/opt/run-test.sh b/tests/opt/run-test.sh deleted file mode 100755 index 1d1d9b7a6..000000000 --- a/tests/opt/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../gen-tests-makefile.sh -generate_mk --yosys-scripts --tcl-scripts diff --git a/tests/rtlil/generate_mk.py b/tests/rtlil/generate_mk.py new file mode 100644 index 000000000..aa88bca13 --- /dev/null +++ b/tests/rtlil/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash"]) diff --git a/tests/rtlil/run-test.sh b/tests/rtlil/run-test.sh deleted file mode 100755 index 83cdf8aeb..000000000 --- a/tests/rtlil/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../gen-tests-makefile.sh -generate_mk --bash --yosys-scripts diff --git a/tests/sat/generate_mk.py b/tests/sat/generate_mk.py new file mode 100644 index 000000000..6a921d5a0 --- /dev/null +++ b/tests/sat/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts"]) diff --git a/tests/sat/run-test.sh b/tests/sat/run-test.sh deleted file mode 100755 index 006c731e3..000000000 --- a/tests/sat/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../gen-tests-makefile.sh -generate_mk --yosys-scripts diff --git a/tests/sdc/generate_mk.py b/tests/sdc/generate_mk.py new file mode 100644 index 000000000..aa88bca13 --- /dev/null +++ b/tests/sdc/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash"]) diff --git a/tests/sdc/run-test.sh b/tests/sdc/run-test.sh deleted file mode 100755 index 971664bdb..000000000 --- a/tests/sdc/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash \ No newline at end of file diff --git a/tests/sim/generate_mk.py b/tests/sim/generate_mk.py new file mode 100644 index 000000000..57138762d --- /dev/null +++ b/tests/sim/generate_mk.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +import subprocess +from pathlib import Path + +print("Generate FST for sim models") + +for name in Path("tb").rglob("tb*.v"): + test_name = name.stem + print(f"Test {test_name}") + + verilog_name = f"{test_name[3:]}.v" + + out_file = Path("tb") / f"{test_name}.out" + + subprocess.run( + ["iverilog", "-o", str(out_file), str(name), verilog_name], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + check=True + ) + + subprocess.run( + [str(out_file), "-fst"], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + check=True + ) + +gen_tests_makefile.generate(["--yosys-scripts", "--bash", "--yosys-args", "-w 'Yosys has only limited support for tri-state logic at the moment.'" ]) diff --git a/tests/sim/run-test.sh b/tests/sim/run-test.sh deleted file mode 100755 index cff85eb65..000000000 --- a/tests/sim/run-test.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../gen-tests-makefile.sh -echo "Generate FST for sim models" -find tb/* -name tb*.v | while read name; do - test_name=$(basename $name .v) - echo "Test $test_name" - verilog_name=${test_name:3}.v - iverilog -o tb/$test_name.out $name $verilog_name >/dev/null 2>&1 - ./tb/$test_name.out -fst >/dev/null 2>&1 -done -generate_mk --yosys-scripts --bash --yosys-args "-w 'Yosys has only limited support for tri-state logic at the moment.'" diff --git a/tests/svtypes/generate_mk.py b/tests/svtypes/generate_mk.py new file mode 100644 index 000000000..618163cca --- /dev/null +++ b/tests/svtypes/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--prove-sv"]) diff --git a/tests/svtypes/run-test.sh b/tests/svtypes/run-test.sh deleted file mode 100755 index 8b0333f27..000000000 --- a/tests/svtypes/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../gen-tests-makefile.sh -generate_mk --yosys-scripts --prove-sv diff --git a/tests/techmap/generate_mk.py b/tests/techmap/generate_mk.py new file mode 100644 index 000000000..c8a4fe054 --- /dev/null +++ b/tests/techmap/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--tcl-scripts", "--bash", "--yosys-args", "-e 'select out of bounds'"]) diff --git a/tests/techmap/run-test.sh b/tests/techmap/run-test.sh deleted file mode 100755 index 0766db999..000000000 --- a/tests/techmap/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../gen-tests-makefile.sh -generate_mk --yosys-scripts --tcl-scripts --bash --yosys-args "-e 'select out of bounds'" diff --git a/tests/various/generate_mk.py b/tests/various/generate_mk.py new file mode 100644 index 000000000..aa88bca13 --- /dev/null +++ b/tests/various/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash"]) diff --git a/tests/various/run-test.sh b/tests/various/run-test.sh deleted file mode 100755 index dee032827..000000000 --- a/tests/various/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash diff --git a/tests/verific/generate_mk.py b/tests/verific/generate_mk.py new file mode 100644 index 000000000..c8c8c53c3 --- /dev/null +++ b/tests/verific/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash"],["export ASAN_OPTIONS=halt_on_error=0"]) diff --git a/tests/verific/run-test.sh b/tests/verific/run-test.sh deleted file mode 100755 index 1666ee1f9..000000000 --- a/tests/verific/run-test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash -{ echo 'export ASAN_OPTIONS=halt_on_error=0'; cat run-test.mk; } > run-test.mk.tmp && mv run-test.mk.tmp run-test.mk diff --git a/tests/verilog/generate_mk.py b/tests/verilog/generate_mk.py new file mode 100644 index 000000000..aa88bca13 --- /dev/null +++ b/tests/verilog/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--yosys-scripts", "--bash"]) diff --git a/tests/verilog/run-test.sh b/tests/verilog/run-test.sh deleted file mode 100755 index dee032827..000000000 --- a/tests/verilog/run-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -eu -source ../gen-tests-makefile.sh -generate_mk --yosys-scripts --bash