From: Eric Tzeng Date: Fri, 28 Feb 2014 00:08:16 +0000 (-0800) Subject: Compile a binary to run all tests at once. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8bc83b07dbb5548aa73c55a21596ce35f2a9b141;p=platform%2Fupstream%2Fcaffe.git Compile a binary to run all tests at once. --- diff --git a/Makefile b/Makefile index 54437f1..6043d2d 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,9 @@ HXX_SRCS := $(shell find include/$(PROJECT) ! -name "*.hpp") # 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") @@ -74,6 +76,7 @@ GTEST_OBJ := $(addprefix $(BUILD_DIR)/, ${GTEST_SRC:.cpp=.o}) 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 @@ -133,7 +136,7 @@ $(LINT_REPORT): $(NONGEN_CXX_SRCS) 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) @@ -163,11 +166,14 @@ $(STATIC_NAME): init $(PROTO_OBJS) $(OBJS) 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) diff --git a/src/caffe/test/test_caffe_main.cpp b/src/caffe/test/test_caffe_main.cpp new file mode 100644 index 0000000..4674bb4 --- /dev/null +++ b/src/caffe/test/test_caffe_main.cpp @@ -0,0 +1,32 @@ +// 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(); +} diff --git a/src/caffe/test/test_caffe_main.hpp b/src/caffe/test/test_caffe_main.hpp index 01cb0c8..68374ae 100644 --- a/src/caffe/test/test_caffe_main.hpp +++ b/src/caffe/test/test_caffe_main.hpp @@ -15,32 +15,6 @@ 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_