@@ -75,6 +75,8 @@ TESTS ?=
7575CPP_TEST_SOURCES := test/native/testRunner.cpp $(shell find test/native -name '* Test.cpp')
7676CPP_TEST_HEADER := test/native/testRunner.hpp
7777CPP_TEST_INCLUDES := -Isrc -Itest/native
78+ CPP_TEST_LIB_SOURCES := test/native/testRunner.cpp $(shell find test/native/libs \( -name "* .c" -o -name "* .cpp" \) )
79+ CPP_TEST_BIN_SOURCES := test/native/testRunner.cpp $(shell find test/test \( -name "* .c" -o -name "* .cpp" \) )
7880
7981ifeq ($(JAVA_HOME ) ,)
8082 JAVA_HOME: =$(shell java -cp . JavaHome)
@@ -132,8 +134,22 @@ ifneq (,$(STATIC_BINARY))
132134 CFLAGS += -static -fdata-sections -ffunction-sections -Wl,--gc-sections
133135endif
134136
137+ # Default to empty
138+ RUN_CPP_TESTS :=
139+
140+ # Determine if the target should run
141+ ifeq ($(filter test-cpp,$(MAKECMDGOALS ) ) ,test-cpp)
142+ RUN_CPP_TESTS := 1
143+ endif
144+
145+ ifeq ($(filter test,$(MAKECMDGOALS ) ) ,test)
146+ ifeq ($(strip $(TESTS)),)
147+ RUN_CPP_TESTS := 1
148+ endif
149+ endif
135150
136- .PHONY : all jar release build-test test clean coverage clean-coverage build-test-java build-test-cpp build-test-libs build-test-bins test-cpp test-java check-md format-md
151+
152+ .PHONY : all jar release build-test test clean coverage clean-coverage build-test-java build-test-cpp test-cpp test-java check-md format-md
137153
138154all : build/bin build/lib build/$(LIB_PROFILER ) build/$(ASPROF ) jar build/$(JFRCONV ) build/$(ASPROF_HEADER )
139155
@@ -175,7 +191,6 @@ build/%:
175191
176192build/$(ASPROF ) : src/main/* src/jattach/* src/fdtransfer.h
177193 $(CC ) $(CPPFLAGS ) $(CFLAGS ) $(DEFS ) -o $@ src/main/* .cpp src/jattach/* .c
178- $(STRIP ) $@
179194
180195build/$(JFRCONV ) : src/launcher/launcher.sh build/$(CONVERTER_JAR )
181196 sed -e ' s/PROFILER_VERSION/$(PROFILER_VERSION)/g' -e ' s/BUILD_DATE/$(shell date "+%b %d %Y")/g' src/launcher/launcher.sh > $@
@@ -211,27 +226,24 @@ build/$(CONVERTER_JAR): $(CONVERTER_SOURCES) $(RESOURCES)
211226
212227build/test/cpptests : $(CPP_TEST_SOURCES ) $(CPP_TEST_HEADER ) $(SOURCES ) $(HEADERS ) $(RESOURCES ) $(JAVA_HELPER_CLASSES )
213228 mkdir -p build/test
229+ ifneq ($(RUN_CPP_TESTS ) ,)
214230ifeq ($(MERGE ) ,true)
215231 for f in src/*.cpp test/native/*.cpp; do echo '# include "'$$f'"'; done |\
216232 $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DEFS) $(INCLUDES) $(CPP_TEST_INCLUDES) -fPIC -o $@ -xc++ - $(LIBS)
217233else
218234 $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(DEFS) $(INCLUDES) $(CPP_TEST_INCLUDES) -fPIC -o $@ $(SOURCES) $(CPP_TEST_SOURCES) $(LIBS)
219235endif
236+ endif
220237
221- build-test-java : all build/$(TEST_JAR ) build- test-libs build-test-bins
238+ build-test-java : all build/$(TEST_JAR ) build/test/build-integ- test-libs build/test/ build-test-bins
222239
223- build-test-cpp : build/test/cpptests build-test-libs
240+ build-test-cpp : build/test/cpptests build/test/build-unit -test-libs
224241
225242build-test : build-test-cpp build-test-java
226243
227- build- test-libs :
244+ build/test/build-unit- test-libs : $( CPP_TEST_LIB_SOURCES )
228245 @mkdir -p $(TEST_LIB_DIR )
229246 $(CC ) -shared -fPIC -o $(TEST_LIB_DIR ) /libreladyn.$(SOEXT ) test/native/libs/reladyn.c
230- $(CC ) -shared -fPIC -o $(TEST_LIB_DIR ) /libcallsmalloc.$(SOEXT ) test/native/libs/callsmalloc.c
231- $(CC ) -shared -fPIC $(INCLUDES ) -Isrc -o $(TEST_LIB_DIR ) /libjnimalloc.$(SOEXT ) test/native/libs/jnimalloc.c
232- $(CC ) -shared -fPIC -o $(TEST_LIB_DIR ) /libmalloc.$(SOEXT ) test/native/libs/malloc.c
233- $(CC ) -fno-optimize-sibling-calls -shared -fPIC $(INCLUDES ) -Isrc -o $(TEST_LIB_DIR ) /libjninativestacks.$(SOEXT ) test/native/libs/jninativestacks.c
234- $(CC ) -shared -fPIC $(INCLUDES ) -Isrc -o $(TEST_LIB_DIR ) /libjninativelocks.$(SOEXT ) test/native/libs/jninativelocks.c -lpthread
235247
236248ifeq ($(OS_TAG ) ,linux)
237249 $(CC) -c -shared -fPIC -o $(TEST_LIB_DIR)/vaddrdif.o test/native/libs/vaddrdif.c
@@ -243,8 +255,18 @@ ifeq ($(OS_TAG),linux)
243255 $(AS) -o $(TEST_LIB_DIR)/twiceatzero.o test/native/libs/twiceatzero.s
244256 $(LD) -shared -o $(TEST_LIB_DIR)/libtwiceatzero.$(SOEXT) $(TEST_LIB_DIR)/twiceatzero.o --section-start=.seg1=0x4000 -z max-page-size=0x1000
245257endif
258+ @touch $@
259+
260+ build/test/build-integ-test-libs : $(CPP_TEST_LIB_SOURCES )
261+ @mkdir -p $(TEST_LIB_DIR )
262+ $(CC ) -shared -fPIC -o $(TEST_LIB_DIR ) /libcallsmalloc.$(SOEXT ) test/native/libs/callsmalloc.c
263+ $(CC ) -shared -fPIC $(INCLUDES ) -Isrc -o $(TEST_LIB_DIR ) /libjnimalloc.$(SOEXT ) test/native/libs/jnimalloc.c
264+ $(CC ) -shared -fPIC -o $(TEST_LIB_DIR ) /libmalloc.$(SOEXT ) test/native/libs/malloc.c
265+ $(CC ) -fno-optimize-sibling-calls -shared -fPIC $(INCLUDES ) -Isrc -o $(TEST_LIB_DIR ) /libjninativestacks.$(SOEXT ) test/native/libs/jninativestacks.c
266+ $(CC ) -shared -fPIC $(INCLUDES ) -Isrc -o $(TEST_LIB_DIR ) /libjninativelocks.$(SOEXT ) test/native/libs/jninativelocks.c -lpthread
267+ @touch $@
246268
247- build-test-bins :
269+ build/test/build -test-bins : $( CPP_TEST_BIN_SOURCES )
248270 @mkdir -p $(TEST_BIN_DIR )
249271 $(CC ) -o $(TEST_BIN_DIR ) /malloc_plt_dyn test/test/nativemem/malloc_plt_dyn.c
250272 $(CC ) -o $(TEST_BIN_DIR ) /native_api -Isrc test/test/c/native_api.c -ldl
@@ -253,10 +275,14 @@ build-test-bins:
253275 $(CC ) -o $(TEST_BIN_DIR ) /preload_malloc -Isrc test/test/nativemem/preload_malloc.c -ldl
254276 $(CC ) -o $(TEST_BIN_DIR ) /nativemem_known_lib_crash -Isrc test/test/nativemem/nativemem_known_lib_crash.c -ldl
255277 $(CXX ) -o $(TEST_BIN_DIR ) /non_java_app -std=c++11 $(INCLUDES ) $(CPP_TEST_INCLUDES ) test/test/nonjava/non_java_app.cpp $(LIBS )
278+ @touch $@
256279
257280test-cpp : build-test-cpp
258- echo " Running cpp tests..."
281+ # Run if test-cpp is explicitly invoked, OR test is invoked and TESTS is empty
282+ ifneq ($(RUN_CPP_TESTS ) ,)
283+ @echo "Running cpp tests..."
259284 LD_LIBRARY_PATH="$(TEST_LIB_DIR)" DYLD_LIBRARY_PATH="$(TEST_LIB_DIR)" build/test/cpptests
285+ endif
260286
261287test-java : build-test-java
262288 echo " Running tests against $( LIB_PROFILER) "
0 commit comments