From 28782a0d7304738daea18050a57c72337ff5e190 Mon Sep 17 00:00:00 2001 From: Moritz Sigg <50019904+siggmo@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:49:28 +0200 Subject: [PATCH] Add ctest cases from existing example tests (#20) * rework github action for build and test and delete old one * adapt workflow to be compatible with local execution using nektos/act * switch back to explicit docker create/exec commands instead of 'container' option The container option doesn't support QEMU emulation and thus selecting a architecture different from the runners/host's one crashed the container with a 'exec format error'. Unfortunately this breaks running the workflows locally using nektos/act. I still have to figure out why exactly. * fix whitespaces and newline at end of file * replace hardcoded paths by variable ones in upload-artifact steps * Clean up docker create command * Consistently use bash -c in docker exec commands, and use single quotes instead of double quotes to prevent host side shell expansion * Enable testing and add test cases from run_tests.sh * Execute tests as non root since MPI requires this. * fix newline at end of file * set max. cores to two for debugging MPI in GitHub Action runners * Add non-root user already in first stage, to make it available in the fans-ci image as well * remove linux/arm64 from build and test workflow. Drop QEMU and make use of container: parameter * add debug output to compare two ways of determining available cores/mpi slots * use cmake_host_system_information instead as this actually gives the number of physical cores, which is the relevant number for MPI * remove unnecessary ProcessorCount module include * Update test names in CMake recipe * Use correct path in test execution in the CMake recipe * Use correct capital case * Use correct relative path in test/CMakeLists.txt Co-authored-by: Sanath Keshav --------- Co-authored-by: Ishaan Desai Co-authored-by: Sanath Keshav --- CMakeLists.txt | 13 +++++++++++++ test/CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 14d6c11..8ed974f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,6 +251,19 @@ install( COMPONENT FANS_Development ) +# ############################################################################## +# TESTING +# ############################################################################## + +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(FANS_ENABLE_TESTING_DEFAULT ON) +endif () +option(FANS_ENABLE_TESTING "Enable testing" ${FANS_ENABLE_TESTING_DEFAULT}) +if (FANS_ENABLE_TESTING) + enable_testing() + add_subdirectory(test) +endif () + # ############################################################################## # PACKAGING # ############################################################################## diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..5969958 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,33 @@ +set(FANS_TEST_INPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(FANS_TEST_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(FANS_EXECUTABLE $) + +# determine MPI process count. The discretization of the test geometry allows for max. 8 processes. +set(FANS_N_MPI_PROCESSES_MAX 8) +cmake_host_system_information(RESULT FANS_CORES_AVAILABLE QUERY NUMBER_OF_PHYSICAL_CORES) +if (FANS_N_MPI_PROCESSES_MAX LESS FANS_CORES_AVAILABLE) + set(FANS_N_MPI_PROCESSES ${FANS_N_MPI_PROCESSES_MAX}) +else() + set(FANS_N_MPI_PROCESSES ${FANS_CORES_AVAILABLE}) +endif() +message(STATUS "Will use ${FANS_N_MPI_PROCESSES} processes for MPI test cases.") + +set(FANS_TEST_CASES + J2Plasticity + LinearElastic + LinearThermal + PseudoPlastic +) + +list(LENGTH FANS_TEST_CASES N_TESTS) +math(EXPR N_TESTS "${N_TESTS} - 1") + +foreach(N RANGE ${N_TESTS}) + list(GET FANS_TEST_CASES ${N} FANS_TEST_CASE) + + add_test( + NAME ${FANS_TEST_CASE} + COMMAND mpiexec -n ${FANS_N_MPI_PROCESSES} ${FANS_EXECUTABLE} input_files/test_${FANS_TEST_CASE}.json ${FANS_TEST_OUTPUT_DIR}/test_${FANS_TEST_CASE}.h5 + WORKING_DIRECTORY ${FANS_TEST_INPUT_DIR} + ) +endforeach()