ParaViewContractTesting.cmake
Go to the documentation of this file.
1 #=========================================================================
2 #
3 # This software is distributed WITHOUT ANY WARRANTY; without even
4 # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
5 # PURPOSE. See the above copyright notice for more information.
6 #
7 #=========================================================================
8 
9 # paraview_contract_test(
10 # TEST_FILE_URL <test_file>
11 # [EXTRA_CMAKE_ARGUMENTS <cmake_arg>...]
12 # )
13 #
14 # add a test that builds and tests a suite of contract tests as described in the test
15 # file.
16 # note: This is derived from https://gitlab.kitware.com/cmb/smtk/-/blob/master/CMake/SMTKPluginTestingMacros.cmake
18  cmake_parse_arguments(PARSE_ARGV 0 _paraview_contract_test
19  ""
20  "TEST_FILE_URL"
21  "EXTRA_CMAKE_ARGUMENTS")
22 
23  if (_paraview_contract_test_UNPARSED_ARGUMENTS)
24  message(FATAL_ERROR
25  "Unrecognized arguments for paraview_contract_test: "
26  "${_paraview_contract_test_UNPARSED_ARGUMENTS}.")
27  endif ()
28 
29  if (NOT DEFINED _paraview_contract_test_TEST_FILE_URL)
30  message(FATAL_ERROR
31  "The `TEST_FILE_URL` argument is required.")
32  endif ()
33  set(test_file_url "${_paraview_contract_test_TEST_FILE_URL}")
34 
35  # Create a testing directory for the contract test based off of its hashed
36  # file name.
37  string(MD5 hashed_test_dir "${test_file_url}")
38  string(SUBSTRING "${hashed_test_dir}" 0 8 hashed_test_dir)
39  set(test_dir "${CMAKE_BINARY_DIR}/ContractTests/${hashed_test_dir}")
40 
41  # Set up a source directory for the contract test
42  set(src_dir "${test_dir}/src")
43  file(MAKE_DIRECTORY "${src_dir}")
44 
45  # Set up a build directory for the contract test
46  set(build_dir "${test_dir}/build")
47  file(MAKE_DIRECTORY "${build_dir}")
48 
49  # Download the contract file into the source directory.
50  file(DOWNLOAD "${test_file_url}" "${src_dir}/CMakeLists.txt")
51 
52  # Check result for success
53  if (NOT EXISTS "${src_dir}/CMakeLists.txt")
54  message(WARNING "Cannot download contract test file <${test_file_url}>.")
55  return ()
56  endif ()
57 
58  # Derive a test name from the contract file name.
59  get_filename_component(test_name ${test_file_url} NAME_WE)
60  set(test_name "contract-${test_name}")
61 
62  set(ctest_extra_args)
63  if (CMAKE_MAKE_PROGRAM)
64  list(APPEND ctest_extra_args
65  --build-makeprogram "${CMAKE_MAKE_PROGRAM}")
66  endif ()
67 
68  if (CMAKE_GENERATOR_PLATFORM)
69  list(APPEND ctest_extra_args
70  --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}")
71  endif ()
72 
73  if (CMAKE_GENERATOR_TOOLSET)
74  list(APPEND ctest_extra_args
75  --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}")
76  endif ()
77 
78  set(cmake_extra_args)
79  if(_paraview_contract_test_EXTRA_CMAKE_ARGUMENTS)
80  list(APPEND cmake_extra_args
81  ${_paraview_contract_test_EXTRA_CMAKE_ARGUMENTS})
82  endif()
83 
84  # Add a test that builds and tests the plugin, but does not install it.
85  add_test(NAME "${test_name}"
86  COMMAND "${CMAKE_CTEST_COMMAND}"
87  --build-and-test "${src_dir}" "${build_dir}"
88  --build-generator "${CMAKE_GENERATOR}"
89  ${ctest_extra_args}
90  --build-options
91  -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
92  -DBUILD_TESTING=ON
93  -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
94  "-Dcatalyst_DIR=${catalyst_DIR}"
95  "-DParaViewCatalyst_DIR=${ParaView_BINARY_DIR}/${paraview_catalyst_directory}"
96  ${cmake_extra_args}
97  )
98 
99  # Contract tests require compiling code, which can take up a lot of memory.
100  # Running them serially may prevent memory-related issues (c++: fatal error:
101  # Killed signal terminated program cc1plus) that sporadically appear on our
102  # dashboards.
103  #
104  # Ideally, `ctest --build-and-test` would support setting load-level
105  # parallelism so that tests can cooperatively work, but that still leaves
106  # testing to take up a lot of resources. Best to leave as serial for now.
107  set_property(TEST "${test_name}"
108  PROPERTY
109  RUN_SERIAL TRUE)
110 
111  set_property(TEST "${test_name}" APPEND
112  PROPERTY
113  ENVIRONMENT "CTEST_OUTPUT_ON_FAILURE=1")
114 
115  set_tests_properties(${test_name} PROPERTIES LABELS "ParaViewContract")
116 endfunction ()
function paraview_contract_test()