5
5
# #
6
6
# # Test services variables
7
7
# #
8
- # # - CPPUNIT: cppunit version. Default is set accorging your gcc version
9
- # # - 1.14.0 for gcc >= 6.0
10
- # # - 1.12.1 for gcc < 6.0
11
- # # - TUSEMOD: The other mods of the project to link for the tests.
8
+ # # - CPP_UNIT_TESTER: Unit tester, choose one of:
9
+ # # - cppunit
10
+ # # - googletest
11
+ # # - geod
12
+ # # cppunit is the default.
13
+ # # - TUSEMOD: The other mods of the project to link for the tests.
12
14
# # - TLINKLIB: List of libraries to link for tests.
13
15
# # - TCFLAGS: CFLAGS used for tests compilation
14
16
# # - TLDFLAGS: LDFLAGS used for tests linkage
15
17
# # - TDISABLE_SRC: List of files in test directory to not compile
16
18
# #
17
19
# # ------------------------------------------------------------------------
18
- ifeq ($(filter % -win32 % -posix,$(CC_VERSION ) ) ,)
19
- CC_VERSION_GE6: =$(shell [ `echo "$(CC_VERSION ) " | cut -f1 -d.` -ge 6 ] && echo true || echo false)
20
- ifeq ($(CC_VERSION_GE6 ) ,false)
21
- CPPUNIT? =cppunit|1.12.1
22
- endif
23
- endif
24
- CPPUNIT? =cppunit|1.14.0
25
-
26
- TESTRUNNER =ctrunner$(BINEXT )
27
- TXTXSL =xunit2txt.xsl
28
- # default TIMEOUT 10min
29
- TIMEOUT? =600
30
- ifeq ($(COLORS_TCAP ) ,yes)
31
- TIMEOUTCMD: =
32
- else
33
- TIMEOUTCMD: =timeout $(TIMEOUT )
34
- endif
35
20
36
- CPPUNIT_DIR =$(call GetExtLibDir,$(NDEXTLIBDIR ) ,$(CPPUNIT ) )
37
- TCFLAGS+ =-I$(CPPUNIT_DIR ) /include
38
- TLDFLAGS+ =-L$(CPPUNIT_DIR ) /$(SODIR )
39
- TLINKLIB+ =cppunit
21
+ CPP_UNIT_TESTER? =cppunit
22
+ # include selected test tool definitions
23
+ include $(ABSROOT ) /core/xunit/$(CPP_UNIT_TESTER ) .mk
40
24
41
25
# valgrind
42
26
VALGRIND =valgrind
43
27
44
28
# Target definition.
45
- TTARGETFILE =$(TTARGETDIR ) /t_$(TARGET )
46
29
ifeq ($(ISWINDOWS ) ,true)
47
- TCYGTARGET =$(TTARGETDIR ) /t_$(CYGTARGET )
30
+ ifeq ($(DYNAMIC_LIB),true)
31
+ TCYGTARGET =$(TTARGETDIR ) /t_$(CYGTARGET )
32
+ else
33
+ TCYGTARGET =$(TTARGETDIR ) /t_$(subst $(SOEXT ) ,$(AREXT ) ,$(CYGTARGET ) )
34
+ endif
35
+ else
36
+ ifeq ($(DYNAMIC_LIB),true)
37
+ TTARGETFILE =$(TTARGETDIR ) /t_$(TARGET )
38
+ else
39
+ TTARGETFILE =$(TTARGETDIR ) /t_$(subst $(SOEXT ) ,$(AREXT ) ,$(TARGET ) )
40
+ endif
48
41
endif
49
42
TARGETFILES+ =$(TTARGETFILE )
50
43
@@ -66,7 +59,12 @@ TCFLAGS+=$(patsubst %,-I$(PRJROOT)/%/include,$(INCLUDE_TESTMODS_PROJ))
66
59
67
60
# linker options specific to test
68
61
TLDFLAGS+ =-L$(TRDIR ) /$(SODIR )
62
+ ifeq ($(DYNAMIC_LIB ) ,true)
69
63
TLDFLAGS+ =$(patsubst % ,-l% ,$(call GetExistingModGeneratedSO,$(TESTUSEMOD ) ) )
64
+ endif
65
+ ifeq ($(STATIC_LIB ) ,true)
66
+ TLDFLAGS+ =$(patsubst % ,-l% ,$(call GetExistingModGeneratedArchive,$(TESTUSEMOD ) ) )
67
+ endif
70
68
TLDFLAGS+ =$(patsubst % ,-l% ,$(TLINKLIB ) )
71
69
72
70
INCLUDE_TESTMODS_EXT =$(filter-out $(PROJECT_INC_MODS ) ,$(sort $(T_ALL_DEPENDENCIES ) ) )
@@ -118,22 +116,22 @@ TLDLIBP=$(LDLIBP):$(subst $(_space_),:,$(patsubst -L%,%,$(filter -L%,$(TLDFLAGS)
118
116
$(OBJDIR ) /test/% .o : test/% .cpp
119
117
@$(ABS_PRINT_info ) " Compiling test $< ..."
120
118
@mkdir -p $(@D )
121
- @$(call writeToBuildLogs,$(CPPC ) $(CXXFLAGS ) $(CFLAGS ) $(TCFLAGS ) -c $< -o $@ )
122
- # generation of header for cppunit tests definition. Remove one line defines to avoid resolving them now.
123
- @grep -v " # \s*include" $< | grep -v -E "#\s*define.*[^\]$$" | $(CPPC) -x c++ -E - | \
124
- grep -E "ABS_TEST_.*_BEGIN|ABS_TEST_SUITE_END" | sed -E 's/\{ *$$//g' | \
125
- $(CPPC) -x c++ -E -include $(ABSROOT)/core/include/abs/testdef2cppunitdecl.h - | \
126
- sed -e '/^#/d;s/!$$//g;s/ !!!/\n!!!/g;s/!!!/#/g' > $(patsubst %.o,%.h,$@)
127
- $(gen-json-test-cppc)
128
- @$(CPPC) $(CXXFLAGS) $(CFLAGS) $(TCFLAGS) -include $(patsubst %.o,%.h,$@) $(GEN_DEP_FLAGS) -c $< -o $@
119
+ @$(call writeToBuildLogs,$(CPPC ) $(CXXFLAGS ) $(CFLAGS ) $(TCFLAGS ) $( TCXXFLAGS ) -c $< -o $@ )
120
+ $( pre_compile_cpp_test )
121
+ ifeq ( $( wildcard $( patsubst % .o, % .h, $@ ) ) , $( patsubst % .o, % .h, $@ ) )
122
+ @$(CPPC) $(CXXFLAGS) $(TCXXFLAGS) $(CFLAGS) $(TCFLAGS) -include $(patsubst %.o,%.h,$@) $(GEN_DEP_FLAGS) -c $< -o $@
123
+ else
124
+ @$(CPPC) $(CXXFLAGS) $(TCXXFLAGS) $(CFLAGS) $(TCFLAGS) $(GEN_DEP_FLAGS) -c $< -o $@
125
+ endif
126
+
129
127
ifeq ($(ISWINDOWS ) ,true)
130
128
$(win-patch-dep)
131
129
endif
132
130
133
131
$(OBJDIR ) /test/% .o : test/% .c
134
132
@$(ABS_PRINT_info ) " Compiling test $< ..."
135
133
@mkdir -p $(@D )
136
- $(gen-json-test-cc )
134
+ $(pre_compile_c_test )
137
135
@$(call executeAndLogCmd,$(CC ) $(CFLAGS ) $(TCFLAGS ) $(GEN_DEP_FLAGS ) -c $< -o $@ )
138
136
ifeq ($(ISWINDOWS ) ,true)
139
137
$(win-patch-dep)
@@ -150,7 +148,11 @@ $(OBJDIR)/bintest/%.o: $(OBJDIR)/%.o
150
148
endif
151
149
152
150
ifneq ($(filter exe library,$(MODTYPE ) ) ,)
153
- TTARGETFILEDEP: =$(TARGETFILE )
151
+ ifeq ($(DYNAMIC_LIB),true)
152
+ TTARGETFILEDEP: =$(TARGETFILE )
153
+ else
154
+ TTARGETFILEDEP: =$(subst $(SOEXT ) ,$(AREXT ) ,$(TARGETFILE ) )
155
+ endif
154
156
endif
155
157
156
158
# link main lib dependencies too (in case the main lib is not directly used.)
@@ -160,14 +162,16 @@ ifneq ($(PREPROC_ONLY),true)
160
162
ifneq ($(ISWINDOWS ) ,true)
161
163
define ld-test
162
164
@$(ABS_PRINT_info ) "Linking $@ ..."
165
+ @$(call updateOptionsAndFlags, OPTIONSANDFLAGS, $(LDFLAGS ) , $(TLDFLAGS ) , $@ )
163
166
@$(call writeToBuildLogs,t_$(MODNAME ) linked to $(sort $(patsubst -l% ,% ,$(TLDFLAGS_L ) ) ) )
164
- @$(call executeAndLogCmd,$(LD ) -o $@ $(TCPPOBJS ) $(LDFLAGS ) $( TLDFLAGS ) )
167
+ @$(call executeAndLogCmd,$(LD ) -o $@ $(TCPPOBJS ) $(OPTIONSANDFLAGS ) )
165
168
endef
166
169
else
167
170
define ld-test
168
171
@$(ABS_PRINT_info ) "Linking $(TCYGTARGET ) ..."
172
+ @$(call updateOptionsAndFlags, OPTIONSANDFLAGS, $(LDFLAGS ) , $(TLDFLAGS ) , $@ )
169
173
@$(call writeToBuildLogs,t_$(MODNAME ) linked to $(sort $(patsubst -l% ,% ,$(TLDFLAGS_L ) ) ) )
170
- @$(call executeAndLogCmd,$(LD ) -shared - o $(TCYGTARGET ) $(call getWindowsLibLDFlags,$@ ,$(TCPPOBJS ) ) $(LDFLAGS ) $( TLDFLAGS ) )
174
+ @$(call executeAndLogCmd,$(LD ) -o $(TCYGTARGET ) $(call getWindowsLibLDFlags,$@ ,$(TCPPOBJS ) ) $(OPTIONSANDFLAGS ) )
171
175
endef
172
176
endif
173
177
else
@@ -177,19 +181,26 @@ endef
177
181
endif
178
182
179
183
# link test target from test objects.
180
- $(TTARGETFILE ) : $(TCPPOBJS ) $(TTARGETFILEDEP )
184
+ $(TTARGETFILE ) : $(TCPPOBJS ) $(TTARGETFILEDEP ) $( LD_SCRIPT )
181
185
@mkdir -p $(@D )
182
- @$(ld-test )
186
+ @$(ld-test ) $( LD_APPEND )
183
187
184
188
# CPPUNIT must be added before following rules to recompute $(EXTLIBMAKES)
185
189
NDUSELIB+ =$(CPPUNIT )
190
+ ifneq ($(XARCH ) ,)
191
+ # TODO: Unsure, NDXA_USELIB not define previously (not well reported everything from Antoine)...
192
+ NDXA_USELIB+ =$(CPP_UNIT_TESTER_LIB )
193
+ else
194
+ NDUSELIB+ =$(CPP_UNIT_TESTER_LIB )
195
+ endif
196
+
186
197
# ---------------------------------------------------------------------
187
198
# Extra dependencies
188
199
# ---------------------------------------------------------------------
189
200
# Generating test object need cppunit libs and tools to be availables
190
201
$(TCPPOBJS ) : $(EXTLIBMAKES )
191
202
192
- ifneq ($(wildcard test/Main.cpp ) ,)
203
+ ifneq ($(ARE_TESTS_AVAILABLE ) ,)
193
204
194
205
# Variable to handle the filter of some test files defined in FILTER_TEST_FILES.
195
206
# The files in FILTER_TEST_FILES must start with 'test/'.
@@ -222,21 +233,15 @@ WINEFULLPATH=$(TRDIR)/bin;$(subst :,;,$(TLDLIBP))
222
233
ifneq ($(ISWINDOWS ) ,true)
223
234
define exec-test
224
235
@$(RUNTIME_PROLOG )
225
- @( [ -d test ] && PATH="$(RUNPATH ) " LD_LIBRARY_PATH="$(TLDLIBP ) " WINEPATH="$(WINEFULLPATH ) ;$$WINEPATH" TRDIR="$(TRDIR ) " TTARGETDIR="$(TTARGETDIR ) " LD_PRELOAD="$(TLDPRELOADFORMATTED ) " $(RUNTIME_ENV ) $1 $(ARCH_EXECUTOR ) $(CPPUNIT_DIR ) /bin/ $( TESTRUNNER ) -x $( TEST_REPORT_PATH ) $( TTARGETFILE ) $(RUNARGS ) $(patsubst % ,+f % ,$(T ) ) $(TARGS ) 2>&1 | tee $(TTARGETDIR ) /$(APPNAME ) _$(MODNAME ) .stdout ) || :
236
+ @( [ -d test ] && PATH="$(RUNPATH ) " LD_LIBRARY_PATH="$(TLDLIBP ) " WINEPATH="$(WINEFULLPATH ) ;$$WINEPATH" TRDIR="$(TRDIR ) " TTARGETDIR="$(TTARGETDIR ) " LD_PRELOAD="$(TLDPRELOADFORMATTED ) " $(RUNTIME_ENV ) $1 $(ARCH_EXECUTOR ) $(TEST_RUNNER_CMD ) $( TTARGETFILE ) $( TEST_RUNNER_ARG_XML )$( TEST_REPORT_PATH ) $(RUNARGS ) $(patsubst % ,+f % ,$(T ) ) $(TARGS ) 2>&1 | tee $(TTARGETDIR ) /$(APPNAME ) _$(MODNAME ) .stdout ) || :
226
237
@$(RUNTIME_EPILOG )
227
238
endef
228
239
else
229
240
define exec-test
230
- @( [ -d test ] && PATH="$(RUNPATH ) :$(TLDLIBP ) " LD_LIBRARY_PATH="$(TLDLIBP ) " WINEPATH="$(WINEFULLPATH ) ;$$WINEPATH" TRDIR="$(TRDIR ) " TTARGETDIR="$(TTARGETDIR ) " LD_PRELOAD="$(TLDPRELOADFORMATTED ) " $(RUNTIME_ENV ) $1 $(ARCH_EXECUTOR ) $(CPPUNIT_DIR ) /bin/ $( TESTRUNNER ) -x $( TEST_REPORT_PATH ) $( TCYGTARGET ) $(RUNARGS ) $(patsubst % ,+f % ,$(T ) ) $(TARGS ) 2>&1 | tee $(TTARGETDIR ) /$(APPNAME ) _$(MODNAME ) .stdout ) || true
241
+ @( [ -d test ] && PATH="$(RUNPATH ) :$(TLDLIBP ) " LD_LIBRARY_PATH="$(TLDLIBP ) " WINEPATH="$(WINEFULLPATH ) ;$$WINEPATH" TRDIR="$(TRDIR ) " TTARGETDIR="$(TTARGETDIR ) " LD_PRELOAD="$(TLDPRELOADFORMATTED ) " $(RUNTIME_ENV ) $1 $(ARCH_EXECUTOR ) $(TEST_RUNNER_CMD ) $( TCYGTARGET ) $( TEST_RUNNER_ARG_XML )$( TEST_REPORT_PATH ) $(RUNARGS ) $(patsubst % ,+f % ,$(T ) ) $(TARGS ) 2>&1 | tee $(TTARGETDIR ) /$(APPNAME ) _$(MODNAME ) .stdout ) || true
231
242
endef
232
243
endif
233
244
234
- define post-test
235
- @( [ -d test -a ! -r $(TEST_REPORT_PATH ) ] && $(ABS_PRINT_error ) "no test report, test runner exited abnormally." ) || true
236
- @( [ -d test -a -r $(TEST_REPORT_PATH ) ] && xsltproc $(ABSROOT ) /core/$(TXTXSL ) $(TEST_REPORT_PATH ) ) || true
237
- @if [ -d test ]; then [ -s $(TEST_REPORT_PATH ) ]; else true; fi
238
- endef
239
-
240
245
define run-test
241
246
$(pre-test )
242
247
$(exec-test )
@@ -374,54 +379,7 @@ TESTNAME=$(word 2,$(MAKECMDGOALS))$(T)
374
379
375
380
.PHONY : newtest
376
381
newtest :
377
- @$(ABS_PRINT_info ) " Generating test class test/Test$( TESTNAME) .cpp to test $( TESTNAME) class."
378
- @mkdir -p test
379
- @test -f test/Main.cpp || printf " #include <cppunit/plugin/TestPlugIn.h>\n#undef main\n\
380
- CPPUNIT_PLUGIN_IMPLEMENT();\n" > test/Main.cpp
381
- @test -f test/Test$(TESTNAME).cpp || printf "/*\n\
382
- * @file Test$(TESTNAME).cpp\n\
383
- *\n\
384
- * Copyright %d $(COMPANY). All rights reserved.\n\
385
- * Use is subject to license terms.\n\
386
- *\n\
387
- * \$$Id$$\n\
388
- * \$$Date$$\n\
389
- */\n\
390
- # include \"abs/test.h\"\n\
391
- #include \"$(TINC_PATH)/$(TESTNAME).hpp\"\n\
392
- \n\
393
- namespace test {\n\
394
- using namespace $(TNAMESPACE);\n\
395
- \n\
396
- // ----------------------------------------------------------\n\
397
- // test suite implementation\n\
398
- ABS_TEST_SUITE_BEGIN( $(TESTNAME) )\n\
399
- // uncomment and complete next line for test suite description\n\
400
- // ABS_TEST_DESCR(test description)\n\
401
- \n\
402
- private:\n\
403
- \n\
404
- public:\n\
405
- void setUp() override {\n\
406
- }\n\
407
- \n\
408
- void tearDown() override {\n\
409
- }\n\
410
- \n\
411
- /* Test case template, uncomment and complete according this pattern for each test case\n\
412
- ABS_TEST_CASE_BEGIN(NameOfTestCase) {\n\
413
- ABS_TEST_DESCR(Test case description)\n\
414
- ABS_TEST_CASE_REQ(req.id) // one entry for each requirement checked by this case\n\
415
- // init/call service / function to be tested and collect results\n\
416
- \n\
417
- // check results with cppunit asserts\n\
418
- CPPUNIT_ASSERT( bool expr);\n\
419
- CPPUNIT_ASSERT_EQUAL(expected_value,computed_value);\n\
420
- }\n\
421
- ABS_TEST_CASE_END\n\
422
- */\n\
423
- ABS_TEST_SUITE_END\n\
424
- } // namespace test\n" `date +%Y` > test/Test$(TESTNAME).cpp
382
+ $(new_test_cmd )
425
383
426
384
$(TESTNAME ) :
427
385
@:
0 commit comments