# CU_SRCS are the cuda source files
CU_SRCS := $(shell find src/$(PROJECT) -name "*.cu")
# TEST_SRCS are the test source files
+TEST_MAIN_SRC := src/$(PROJECT)/test/test_caffe_main.cpp
TEST_SRCS := $(shell find src/$(PROJECT) -name "test_*.cpp")
+TEST_SRCS := $(filter-out $(TEST_MAIN_SRC), $(TEST_SRCS))
GTEST_SRC := src/gtest/gtest-all.cpp
# TEST_HDRS are the test header files
TEST_HDRS := $(shell find src/$(PROJECT) -name "test_*.hpp")
TOOL_BINS := ${TOOL_OBJS:.o=.bin}
EXAMPLE_BINS := ${EXAMPLE_OBJS:.o=.bin}
TEST_BINS := ${TEST_OBJS:.o=.testbin}
+TEST_ALL_BIN := $(BUILD_DIR)/src/$(PROJECT)/test/test_all.testbin
##############################
# Derive include and lib directories
echo "Found 1 or more lint errors; see log at $(FAILED_LINT_REPORT)"; \
exit 1)
-test: init $(TEST_BINS)
+test: init $(TEST_BINS) $(TEST_ALL_BIN)
tools: init $(TOOL_BINS)
ar rcs $(STATIC_NAME) $(PROTO_OBJS) $(OBJS)
@echo
-runtest: test
- for testbin in $(TEST_BINS); do $$testbin $(TEST_GPUID); done
+runtest: $(TEST_ALL_BIN)
+ $(TEST_ALL_BIN)
$(TEST_BINS): %.testbin : %.o $(GTEST_OBJ) $(STATIC_NAME) $(TEST_HDRS)
- $(CXX) $< $(GTEST_OBJ) $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS)
+ $(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS)
+
+$(TEST_ALL_BIN): $(TEST_OBJS)
+ $(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) -o $(TEST_ALL_BIN) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS)
$(TOOL_BINS): %.bin : %.o $(STATIC_NAME)
$(CXX) $< $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS)
--- /dev/null
+// Copyright 2013 Yangqing Jia
+
+// The main caffe test code. Your test cpp code should include this hpp
+// to allow a main function to be compiled into the binary.
+
+#include "test_caffe_main.hpp"
+
+namespace caffe {
+ cudaDeviceProp CAFFE_TEST_CUDA_PROP;
+}
+
+using caffe::CAFFE_TEST_CUDA_PROP;
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ ::google::InitGoogleLogging(argv[0]);
+ // Before starting testing, let's first print out a few cuda defice info.
+ int device;
+ cudaGetDeviceCount(&device);
+ cout << "Cuda number of devices: " << device << endl;
+ if (argc > 1) {
+ // Use the given device
+ device = atoi(argv[1]);
+ cudaSetDevice(device);
+ cout << "Setting to use device " << device << endl;
+ }
+ cudaGetDevice(&device);
+ cout << "Current device id: " << device << endl;
+ cudaGetDeviceProperties(&CAFFE_TEST_CUDA_PROP, device);
+ // invoke the test.
+ return RUN_ALL_TESTS();
+}
using std::cout;
using std::endl;
-namespace caffe {
-
-cudaDeviceProp CAFFE_TEST_CUDA_PROP;
-
-} // namespace caffe
-
-using caffe::CAFFE_TEST_CUDA_PROP;
-
-int main(int argc, char** argv) {
- ::testing::InitGoogleTest(&argc, argv);
- ::google::InitGoogleLogging(argv[0]);
- // Before starting testing, let's first print out a few cuda defice info.
- int device;
- cudaGetDeviceCount(&device);
- cout << "Cuda number of devices: " << device << endl;
- if (argc > 1) {
- // Use the given device
- device = atoi(argv[1]);
- cudaSetDevice(device);
- cout << "Setting to use device " << device << endl;
- }
- cudaGetDevice(&device);
- cout << "Current device id: " << device << endl;
- cudaGetDeviceProperties(&CAFFE_TEST_CUDA_PROP, device);
- // invoke the test.
- return RUN_ALL_TESTS();
-}
+int main(int argc, char** argv);
#endif // CAFFE_TEST_TEST_CAFFE_MAIN_HPP_