Skip to content

Commit

Permalink
Ctest runs all tests now, instead all suites, shows more details
Browse files Browse the repository at this point in the history
  • Loading branch information
Thinkpiet committed Nov 18, 2023
1 parent 2551994 commit 79d764b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
25 changes: 23 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ set(CLANGFORMAT_SOURCES
"test/integration/TestMarDynMoleculeIterator.h"
"test/unit/coupling/solvers/LBCouetteSolverStateTest.cpp"
"test/unit/coupling/solvers/PintableLBCouetteSolverTest.cpp"
"test/unit/getTestNames.cpp"
"coupling/scenario/CouetteScenario.h"
"coupling/scenario/main_couette.cpp"
"coupling/scenario/Scenario.h"
Expand Down Expand Up @@ -758,6 +759,21 @@ target_link_libraries(benchmarks PRIVATE mamico)
#
if (BUILD_TESTING)
file(GLOB_RECURSE TEST_SOURCES "test/*Test.cpp")

if(GET_TEST_NAMES)
add_executable(getTestNames
${MAMICO_SOURCES}
"test/unit/getTestNames.cpp"
${TEST_SOURCES}
)
set_target_properties(getTestNames PROPERTIES CXX_STANDARD 17)
target_link_libraries(getTestNames PRIVATE mamico)
target_include_directories(getTestNames PRIVATE ${CPPUNIT_INCLUDE_DIRS})
target_link_directories(getTestNames PRIVATE ${CPPUNIT_LIBRARY})
target_link_libraries(getTestNames PRIVATE cppunit)
return()
endif()

add_executable(testmamico
${MAMICO_SOURCES}
"test/unit/main.cpp"
Expand All @@ -768,8 +784,13 @@ if (BUILD_TESTING)
target_include_directories(testmamico PRIVATE ${CPPUNIT_INCLUDE_DIRS})
target_link_directories(testmamico PRIVATE ${CPPUNIT_LIBRARY})
target_link_libraries(testmamico PRIVATE cppunit)
foreach(TEST ${TEST_SOURCES})
get_filename_component(TEST_NAME ${TEST} NAME_WE)

execute_process(COMMAND cmake -DGET_TEST_NAMES=ON .)
execute_process(COMMAND make getTestNames)
execute_process(COMMAND ./getTestNames OUTPUT_VARIABLE TEST_NAMES)
separate_arguments(TEST_NAMES UNIX_COMMAND ${TEST_NAMES})

foreach(TEST_NAME ${TEST_NAMES})
if (BUILD_WITH_MPI)
add_test(NAME ${TEST_NAME} COMMAND mpirun --oversubscribe -np 4 ./testmamico ${TEST_NAME})
else()
Expand Down
37 changes: 37 additions & 0 deletions test/unit/getTestNames.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "coupling/CouplingMDDefinitions.h"
#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
#include <mpi.h>
#endif
#include <cppunit/Test.h>
#include <cppunit/TestSuite.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

/***
*
* Prints testPath of all tests to stdout, for use by cmake
*
* @author Piet
* Nov 2023
*
*/
int main(int argc, char** argv) {
#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
MPI_Init(&argc, &argv);
#endif

CppUnit::TestSuite* all = dynamic_cast<CppUnit::TestSuite*>(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
auto suites = all->getTests();
for (auto s : suites) {
auto suite = dynamic_cast<CppUnit::TestSuite*>(s);
auto tests = suite->getTests();
for (auto test : tests)
std::cout << test->getName() << " ";
}

std::cout << std::endl;

#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
MPI_Finalize();
#endif
return 0;
}

0 comments on commit 79d764b

Please sign in to comment.