Skip to content

Commit 2699408

Browse files
authored
Merge pull request #642 from sebproell/framework-test-support-files
Cmake: copy arbitray number of support files for framework tests
2 parents eb1a8c6 + 2a5b52b commit 2699408

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

cmake/functions/four_c_testing_functions.cmake

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -509,37 +509,63 @@ endfunction()
509509

510510
###------------------------------------------------------------------ Framework Tests
511511
# Testing the whole framework: pre_exodus, 4C, and post-filter
512-
# Usage in tests/lists_of_tests.cmake: "four_c_test_framework(<name_of_input_file> <num_proc> <xml_filename>)"
513-
# <name_of_input_file>: must equal the name of a .e/.bc/.head file in directory tests/framework-test
514-
# <num_proc>: number of processors the test should use
515-
# <xml_filename>: copy any xml-file to the build directory. May also be ""
516-
function(four_c_test_framework name_of_input_file num_proc xml_filename)
512+
#
513+
# Usage in tests/lists_of_tests.cmake:
514+
#
515+
# four_c_test_framework(PREFIX <prefix> NP <NP> [COPY_FILES <file1> <file2> ...])"
516+
#
517+
# PREFIX: must equal the name of a .e/.bc/.head file in directory tests/framework-test
518+
# NP: number of MPI ranks for this test
519+
# COPY_FILES: copy any additional files to the test directory
520+
function(four_c_test_framework)
521+
set(options "")
522+
set(oneValueArgs PREFIX NP)
523+
set(multiValueArgs COPY_FILES)
524+
cmake_parse_arguments(
525+
_parsed
526+
"${options}"
527+
"${oneValueArgs}"
528+
"${multiValueArgs}"
529+
${ARGN}
530+
)
531+
532+
# validate input arguments
533+
if(DEFINED _parsed_UNPARSED_ARGUMENTS)
534+
message(FATAL_ERROR "There are unparsed arguments: ${_parsed_UNPARSED_ARGUMENTS}!")
535+
endif()
536+
537+
set(name_of_input_file ${_parsed_PREFIX})
538+
set(num_proc ${_parsed_NP})
517539
set(name_of_test ${name_of_input_file}-p${num_proc}-fw)
518540
set(test_directory framework_test_output/${name_of_input_file})
519541

520-
set(RUNPREEXODUS
542+
set(_run_pre_exodus
521543
${FOUR_C_ENABLE_ADDRESS_SANITIZER_TEST_OPTIONS}\ ./pre_exodus\ --exo=${PROJECT_SOURCE_DIR}/tests/framework-test/${name_of_input_file}.e\ --bc=${PROJECT_SOURCE_DIR}/tests/framework-test/${name_of_input_file}.bc\ --head=${PROJECT_SOURCE_DIR}/tests/framework-test/${name_of_input_file}.head\ --out=${test_directory}/xxx.4C.yaml
522544
) # pre_exodus is run to generate an input file
523545

524-
if(NOT ${xml_filename} STREQUAL "")
525-
# if a XML file name is given, it is copied from the 4C input directory to the build directory
526-
set(RUNCOPYXML
527-
"cp ${PROJECT_SOURCE_DIR}/tests/input_files/${xml_filename} ./${test_directory}/"
528-
)
546+
# copy additional files to the test directory
547+
if(_parsed_COPY_FILES)
548+
foreach(_file_name IN LISTS _parsed_COPY_FILES)
549+
if(NOT EXISTS ${_file_name})
550+
message(FATAL_ERROR "File ${_file_name} does not exist!")
551+
endif()
552+
list(APPEND _run_copy_files "cp ${_file_name} ${test_directory}")
553+
endforeach()
554+
list(JOIN _run_copy_files " && " _run_copy_files)
529555
else()
530556
# no-op command to do nothing
531-
set(RUNCOPYXML :)
557+
set(_run_copy_files ":")
532558
endif()
533559

534-
set(RUNFOURC
560+
set(_run_4C
535561
${MPIEXEC_EXECUTABLE}\ ${MPIEXEC_EXTRA_OPTS_FOR_TESTING}\ -np\ ${num_proc}\ $<TARGET_FILE:${FOUR_C_EXECUTABLE_NAME}>\ ${test_directory}/xxx.4C.yaml\ ${test_directory}/xxx
536562
) # 4C is run using the generated input file
537563

538564
add_test(
539565
NAME ${name_of_test}
540566
COMMAND
541567
bash -c
542-
"mkdir -p ${PROJECT_BINARY_DIR}/${test_directory} && ${RUNCOPYXML} && ${RUNPREEXODUS} && ${RUNFOURC}"
568+
"mkdir -p ${PROJECT_BINARY_DIR}/${test_directory} && ${_run_copy_files} && ${_run_pre_exodus} && ${_run_4C}"
543569
)
544570

545571
require_fixture(${name_of_test} test_cleanup)

tests/list_of_tests.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,12 +1962,12 @@ four_c_test_nested_parallelism(sohex8_multiscale_macro_2micro.dat sohex8_multisc
19621962
four_c_test_nested_parallelism(tsi_heatconvection_monolithic.dat tsi_heatconvection_monolithic.dat "")
19631963

19641964
# testing the whole framework: from pre_exodus and 4C to the post-filter:
1965-
four_c_test_framework(tutorial_battery 2 "")
1966-
four_c_test_framework(tutorial_contact_3d 2 "")
1967-
four_c_test_framework(tutorial_fluid 2 "")
1968-
four_c_test_framework(tutorial_fsi 2 "")
1969-
four_c_test_framework(tutorial_fsi_3d 2 fsi_part_struct_solver.xml)
1970-
four_c_test_framework(tutorial_solid 3 xml/multigrid/elasticity_template.xml)
1965+
four_c_test_framework(PREFIX tutorial_battery NP 2)
1966+
four_c_test_framework(PREFIX tutorial_contact_3d NP 2)
1967+
four_c_test_framework(PREFIX tutorial_fluid NP 2)
1968+
four_c_test_framework(PREFIX tutorial_fsi NP 2)
1969+
four_c_test_framework(PREFIX tutorial_fsi_3d NP 2 COPY_FILES ${PROJECT_SOURCE_DIR}/tests/input_files/fsi_part_struct_solver.xml)
1970+
four_c_test_framework(PREFIX tutorial_solid NP 3 COPY_FILES ${PROJECT_SOURCE_DIR}/tests/input_files/xml/multigrid/elasticity_template.xml)
19711971

19721972
# four_c_test_post_processing
19731973
four_c_test_post_processing(constr3D_MPC_direct.dat 2 2 ndxyz ndxyz 25)

0 commit comments

Comments
 (0)