mardi 7 juillet 2020

Compiling many test files in parallel

I have a catch2 test bench for a header-only library I am developing. The test bench consists of a header test file for each header file in the library. I compile all of the tests by creating a test_main.cpp file which basically includes all of the test headers. The file layout is depicted below.

include/
-- f1.hpp
-- f2.hpp
...
-- fn.hpp
test/
-- f1_test.hpp
-- f2_test.hpp
...
-- fn_test.hpp
-- test_main.cc
-- test_root.cc

I have a significant number of files to test, and am typically only working on one at a time. However, whenever I need to recompile, I have to start the entire process over since test_main.cc is the only target. This also doesn't allow me to build in parallel.

How can I split the build up into smaller targets so that I can build in parallel and only have to rebuild a small part of the test bench when recompiling?

The corresponding part of the Makefile is bellow:

TEST_OBJS = ${BUILD_DIR}/test_main.o ${BUILD_DIR}/test_root.o
${BUILD_DIR}/test_main.o: ext/catch2.hpp ${TEST_DIR}/test_main.cc 
    mkdir -p ${BUILD_DIR}
    ${CXX} ${FLAGS} ${INCLUDES} ${TEST_DIR}/test_main.cc -c -o $@
${BUILD_DIR}/test_root.o: ext/catch2.hpp ${HEADERS} ${ALGORITHM_HEADERS} ${SRCS} 
    mkdir -p ${BUILD_DIR}
    ${CXX} ${FLAGS} ${INCLUDES} ${TEST_DIR}/test_root.cc -c -o $@ 
tests: ${TEST_OBJS}
    mkdir -p ${BUILD_DIR}
    ${CXX} ${TEST_OBJS} -o ${BUILD_DIR}/tests 

test_root.cc is just a list of #include "fi_test.hpp" and test_main.cc is just

#define CATCH_CONFIG_MAIN
#include "catch2.hpp"

Each of the test files looks like this:

#include "test_root.cc"
TEMPLATE_PRODUCT_TEST_CASE() {
// stuff 
}

Aucun commentaire:

Enregistrer un commentaire