blob: d1c8789ead94f75f822df670fcc2a3b22068da0c [file] [log] [blame]
# -*- Makefile -*-
# Each plugin shall have a directory named 'test' that contains test cases
# directories and a Makefile which includes this Makefile template.
# The test Makefile specifies which tests to execute and how to verify them.
# The test to execute should be explicitly specified in the TESTS variable.
# Each test needs a verification step define in the name_of_test_verify variable.
# A simple diff verification template have been defined in the template Makefile
# diff_test performs a simple diff and takes name of file and its extension
# Example of a test Makefile is given below:
#
# include $(shell pwd)/../../Makefile_test.common
# TESTS = test1 test2
# test1_verify = $(call diff_test,test1,ext) && test $$(grep "PASS" test1/test1.txt | wc -l) -eq 2
# test2_verify = $(call diff_test,test2,ext)
#
GTEST_DIR ?= ../../third_party/googletest/googletest
CXX ?= $(shell yosys-config --cxx)
CXXFLAGS ?= $(shell yosys-config --cxxflags) -I.. -I$(GTEST_DIR)/include
LDLIBS ?= $(shell yosys-config --ldlibs) -L$(GTEST_DIR)/build/lib -lgtest -lgtest_main -lpthread
LDFLAGS ?= $(shell yosys-config --ldflags)
TEST_UTILS ?= ../../../test-utils/test-utils.tcl
define test_tpl =
$(1): $(1)/ok
@set +e; \
$$($(1)_verify); \
if [ $$$$? -eq 0 ]; then \
printf "Test %-18s \e[32mPASSED\e[0m @ %s\n" $(1) $(CURDIR); \
touch $$<; \
true; \
else \
printf "Test %-18s \e[31;1mFAILED\e[0m @ %s\n" $(1) $(CURDIR); \
false; \
fi
$(1)/ok: $(1)/$(1).v
@set +e; \
cd $(1); \
echo "source $(TEST_UTILS)" > run-$(1).tcl ;\
echo "source $(1).tcl" >> run-$(1).tcl ;\
DESIGN_TOP=$(1) TEST_OUTPUT_PREFIX=./ \
yosys -c "run-$(1).tcl" -q -q -l $(1).log; \
RETVAL=$$$$?; \
rm -f run-$(1).tcl; \
if [ ! -z "$$($(1)_negative)" ] && [ $$($(1)_negative) -eq 1 ]; then \
if [ $$$$RETVAL -ne 0 ]; then \
printf "Negative test %-18s \e[32mPASSED\e[0m @ %s\n" $(1) $(CURDIR); \
true; \
else \
printf "Negative test %-18s \e[31;1mFAILED\e[0m @ %s\n" $(1) $(CURDIR); \
false; \
fi \
else \
if [ $$$$RETVAL -ne 0 ]; then \
echo "Unexpected runtime error"; \
false; \
fi \
fi
endef
define unit_test_tpl =
$(1): $(1)/$(1).test
@$$<
$(1)/$(1).test: $(1)/$(1).test.o $$(GTEST_DIR)/build/lib/libgtest.a
@$(CXX) $(LDFLAGS) -o $$@ $$< $(LDLIBS)
$(1)/$(1).test.o: $(1)/$(1).test.cc
@$(CXX) $(CXXFLAGS) $(LDFLAGS) -c $$< -o $$@
endef
diff_test = diff $(1)/$(1).golden.$(2) $(1)/$(1).$(2)
all: $(TESTS) $(UNIT_TESTS)
$(GTEST_DIR)/build/lib/libgtest.a $(GTEST_DIR)/build/lib/libgtest_main.a:
@mkdir -p $(GTEST_DIR)/build
@cd $(GTEST_DIR)/build; \
cmake ..; \
make
.PHONY: all clean $(TESTS) $(UNIT_TESTS)
$(foreach test,$(TESTS),$(eval $(call test_tpl,$(test))))
$(foreach test,$(UNIT_TESTS),$(eval $(call unit_test_tpl,$(test))))
clean:
@rm -rf $(foreach test,$(TESTS),$(test)/$(test).sdc $(test)/$(test)_[0-9].sdc $(test)/$(test).txt $(test)/$(test).eblif $(test)/$(test).json)
@rm -rf $(foreach test,$(UNIT_TESTS),$(test)/$(test).test.o $(test)/$(test).test.d $(test)/$(test).test)
@find . -name "ok" -or -name "*.log" | xargs rm -rf