From: rodrigosiqueira Date: Sat, 10 Dec 2016 20:21:56 +0000 (-0200) Subject: Improved unit test structure X-Git-Tag: yosys-0.8~562^2~2 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b932e2355de3d2d3b7a61fe86d11265ba02aba2a;p=yosys.git Improved unit test structure Signed-off-by: rodrigosiqueira Signed-off-by: chaws <18oliveira.charles@gmail.com> * Merged run-all-unitest inside unit-test target * Fixed Makefile dependencies * Updated documentation about unit test --- diff --git a/CodingReadme b/CodingReadme index d2e975dab..041f3b1fa 100644 --- a/CodingReadme +++ b/CodingReadme @@ -436,8 +436,8 @@ test. However, it is strongly recommended that you take a look to the official repository (https://github.com/google/googletest) and refers to that if you have any problem to install it. Follow the steps below: -* Install: cmake -* Clone google test project from: //github.com/rodrigosiqueira/logbook.git and +* Install: cmake and pthread +* Clone google test project from: https://github.com/google/googletest and enter in the project directory * Inside project directory, type: diff --git a/Makefile b/Makefile index 340fe1229..cf40309ce 100644 --- a/Makefile +++ b/Makefile @@ -455,9 +455,6 @@ unit-test: libyosys.so @$(MAKE) -C $(UNITESTPATH) CXX="$(CXX)" CPPFLAGS="$(CPPFLAGS)" \ CXXFLAGS="$(CXXFLAGS)" LDLIBS="$(LDLIBS)" ROOTPATH="$(CURDIR)" -run-all-unitest: - @$(MAKE) -C $(UNITESTPATH) run-tests - clean-unit-test: @$(MAKE) -C $(UNITESTPATH) clean diff --git a/tests/unit/Makefile b/tests/unit/Makefile index 16f65ec20..447a5f619 100644 --- a/tests/unit/Makefile +++ b/tests/unit/Makefile @@ -2,26 +2,33 @@ GTESTFLAG := -lgtest -lgtest_main RPATH := -Wl,-rpath EXTRAFLAGS := -lyosys -ALLTESTFILE := $(wildcard ./**/*Test.cc) OBJTEST := objtest BINTEST := bintest -all: prepare $(ALLTESTFILE:%Test.cc=%Test.o) +ALLTESTFILE := $(shell find -name '*Test.cc' -printf '%P ') +TESTDIRS := $(sort $(dir $(ALLTESTFILE))) +TESTS := $(addprefix $(BINTEST)/, $(basename $(ALLTESTFILE:%Test.cc=%Test.o))) -%Test.o: %Test.cc - $(CXX) -o $(OBJTEST)/$(notdir $@) -c -I$(ROOTPATH) $(CPPFLAGS) $(CXXFLAGS) $< - $(CXX) -L$(ROOTPATH) $(RPATH)=$(ROOTPATH) -o \ - $(BINTEST)/$(basename $(notdir $@)) $(OBJTEST)/$(notdir $@) $(LDLIBS) \ +# Prevent make from removing our .o files +.SECONDARY: + +all: prepare $(TESTS) run-tests + +$(BINTEST)/%: $(OBJTEST)/%.o + $(CXX) -L$(ROOTPATH) $(RPATH)=$(ROOTPATH) -o $@ $^ $(LDLIBS) \ $(GTESTFLAG) $(EXTRAFLAGS) - + +$(OBJTEST)/%.o: $(basename $(subst $(OBJTEST),.,%)).cc + $(CXX) -o $@ -c -I$(ROOTPATH) $(CPPFLAGS) $(CXXFLAGS) $^ + .PHONY: prepare run-tests clean -run-tests: - $(CURDIR)/$(BINTEST)/* +run-tests: $(TESTS) + $(subst Test ,Test; ,$^) prepare: - mkdir -p $(OBJTEST) - mkdir -p $(BINTEST) + mkdir -p $(addprefix $(BINTEST)/,$(TESTDIRS)) + mkdir -p $(addprefix $(OBJTEST)/,$(TESTDIRS)) clean: rm -rf $(OBJTEST)