From c91cb36f3ed0e5d0683dbc19112a82c25c3231b1 Mon Sep 17 00:00:00 2001 From: Wayne Booth Date: Sun, 30 Jun 2019 12:29:49 +0000 Subject: [PATCH] Add support for testbench simulation --- Makefile | 27 +++++++++++++++------------ README.md | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 116886c..b318b16 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,8 @@ BITGEN_OPTS ?= TRACE_OPTS ?= FUSE_OPTS ?= -incremental +TEST_POSTFIX ?= _tb + PROGRAMMER ?= none IMPACT_OPTS ?= -batch impact.cmd @@ -67,6 +69,8 @@ else PATH := $(PATH):$(XILINX)/bin/$(XILINX_PLATFORM) endif +VTEST = $(foreach file,$(wildcard *$(TEST_POSTFIX).v),$(file)) +VHDTEST = $(foreach file,$(wildcard *$(TEST_POSTFIX).vhd),$(file)) TEST_NAMES = $(foreach file,$(VTEST) $(VHDTEST),$(basename $(file))) TEST_EXES = $(foreach test,$(TEST_NAMES),build/isim_$(test)$(EXE)) @@ -138,24 +142,23 @@ trace: project.cfg $(BITFILE) $(call RUN,trce) $(COMMON_OPTS) $(TRACE_OPTS) \ $(PROJECT).ncd $(PROJECT).pcf -test: $(TEST_EXES) +test: buildtest runtest + +runtest: ${TEST_NAMES} + +${TEST_NAMES}: + @grep --no-filename --no-messages 'ISIM:' $@.{v,vhd} | cut -d: -f2 > build/isim_$@.cmd + @echo "run all" >> build/isim_$@.cmd + cd build ; ./isim_$@$(EXE) -tclbatch isim_$@.cmd ; -build/isim_%$(EXE): build/$(PROJECT)_sim.prj $(VSOURCE) $(VHDSOURCE) $(VTEST) $(VHDTEST) +buildtest: ${TEST_EXES} + +build/isim_%$(EXE): build/$(PROJECT)_sim.prj $(VSOURCE) $(VHDSOURCE) ${VTEST} $(VHDTEST) $(call RUN,fuse) $(COMMON_OPTS) $(FUSE_OPTS) \ -prj $(PROJECT)_sim.prj \ -o isim_$*$(EXE) \ work.$* work.glbl -isim: build/isim_$(TB)$(EXE) - @grep --no-filename --no-messages 'ISIM:' $(TB).{v,vhd} | cut -d: -f2 > build/isim_$(TB).cmd - @echo "run all" >> build/isim_$(TB).cmd - cd build ; ./isim_$(TB)$(EXE) -tclbatch isim_$(TB).cmd - -isimgui: build/isim_$(TB)$(EXE) - @grep --no-filename --no-messages 'ISIM:' $(TB).{v,vhd} | cut -d: -f2 > build/isim_$(TB).cmd - @echo "run all" >> build/isim_$(TB).cmd - cd build ; ./isim_$(TB)$(EXE) -gui -tclbatch isim_$(TB).cmd - ########################################################################### # Programming diff --git a/README.md b/README.md index 24b2965..f42fc8f 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,10 @@ The Xilinx ISE Makefile implements the following targets: Builds the bitstream. + * `make test` + + Runs any testbenches. + * `make clean` Removes the build directory. @@ -152,7 +156,17 @@ The Xilinx ISE Makefile implements the following targets: Running unit tests ------------------ -is a work in progress. +Test `test` target will build and run any testbenches that have been created. + +A testbench is any file with a file finishing in `_tb` (overridden by `TEST_POSTFIX`). + + +Caviates +-------- + + * Module names need to match the filename they are within. + + * Module names cannot start with a number. Unimplemented features