2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
5 # Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
6 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 # and including many others, as listed in the AUTHORS file in the
8 # top-level source directory and at http://www.gromacs.org.
10 # GROMACS is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public License
12 # as published by the Free Software Foundation; either version 2.1
13 # of the License, or (at your option) any later version.
15 # GROMACS is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with GROMACS; if not, see
22 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 # If you want to redistribute modifications to GROMACS, please
26 # consider that scientific software is very special. Version
27 # control is crucial - bugs must be traceable. We will be happy to
28 # consider code for inclusion in the official distribution, but
29 # derived work must not be called official GROMACS. Details are found
30 # in the README & COPYING files - if they are missing, get the
31 # official version at http://www.gromacs.org.
33 # To help us fund GROMACS development, we humbly ask that you cite
34 # the research papers on the package. Check out http://www.gromacs.org.
36 set(REGRESSIONTEST_PATH "" CACHE PATH "Directory containing regressiontests")
37 mark_as_advanced(REGRESSIONTEST_PATH)
38 option(REGRESSIONTEST_DOWNLOAD
39 "Automatically download regressiontests. Tests can be run with ctest." OFF)
41 if(REGRESSIONTEST_DOWNLOAD)
42 if (NOT SOURCE_IS_SOURCE_DISTRIBUTION)
43 set(REGRESSIONTEST_URL https://gitlab.com/gromacs/gromacs-regressiontests/-/archive/${REGRESSIONTEST_BRANCH}/gromacs-regressiontests-${REGRESSIONTEST_BRANCH}.tar.gz)
44 # REGRESSIONTEST_PATH for dev trees is set later based on the dirname found in the tar
46 set(REGRESSIONTEST_URL http://ftp.gromacs.org/regressiontests/regressiontests-${REGRESSIONTEST_VERSION}.tar.gz)
47 set(REGRESSIONTEST_PATH
48 "${CMAKE_CURRENT_BINARY_DIR}/regressiontests-${REGRESSIONTEST_VERSION}"
49 CACHE PATH "Path to auto-downloaded regressiontests" FORCE)
51 set(REGRESSIONTEST_FILE "${CMAKE_CURRENT_BINARY_DIR}/regressiontests.tgz")
52 message("Downloading: ${REGRESSIONTEST_URL}")
53 file(DOWNLOAD ${REGRESSIONTEST_URL} "${REGRESSIONTEST_FILE}" SHOW_PROGRESS STATUS status LOG log)
54 list(GET status 0 status_code)
55 list(GET status 1 status_string)
57 if(NOT status_code EQUAL 0)
58 message(FATAL_ERROR "error: downloading '${REGRESSIONTEST_URL}' failed
59 status_code: ${status_code}
60 status_string: ${status_string}
63 if (SOURCE_IS_SOURCE_DISTRIBUTION)
64 file(MD5 ${REGRESSIONTEST_FILE} COMPUTED_MD5SUM)
65 if(NOT ${REGRESSIONTEST_MD5SUM} STREQUAL ${COMPUTED_MD5SUM})
66 message(FATAL_ERROR "Download of regressiontests failed. Expected MD5 of ${REGRESSIONTEST_MD5SUM} but download has ${COMPUTED_MD5SUM}")
69 # Extract the REGRESSIONTEST_PATH from the tar when using dev tree.
70 execute_process(COMMAND ${CMAKE_COMMAND} -E tar tf "${REGRESSIONTEST_FILE}"
71 RESULT_VARIABLE _tar_tf_res
72 OUTPUT_VARIABLE _tar_tf_out)
73 if (${_tar_tf_res} EQUAL 0)
74 string(REGEX REPLACE "/\n.*$" "" _regressiontest_dir "${_tar_tf_out}")
75 set(REGRESSIONTEST_PATH "${CMAKE_CURRENT_BINARY_DIR}/${_regressiontest_dir}"
76 CACHE PATH "Path to auto-downloaded regressiontests" FORCE)
78 message(FATAL_ERROR "Failed to list the contents of the downloaded tarball: ${REGRESSIONTEST_FILE}")
82 file(REMOVE_RECURSE "${REGRESSIONTEST_PATH}") #delete potential prior folder
83 execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${REGRESSIONTEST_FILE}"
84 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
85 if(NOT EXISTS ${REGRESSIONTEST_PATH}/gmxtest.pl)
86 message(FATAL_ERROR "Download incorrect. Doesn't contain required gmxtest.pl")
88 set(REGRESSIONTEST_DOWNLOAD OFF CACHE BOOL "Tests already downloaded. Set to yes to download again" FORCE)
91 if(REGRESSIONTEST_PATH AND (CMAKE_CROSSCOMPILING OR CMAKE_CONFIGURATION_TYPES OR GMX_BUILD_MDRUN_ONLY))
92 # TODO: It would be nicer to do these checks before potentially downloading the tests.
93 # Cross-compiling toolchains require us to compile both front-end and
94 # back-end binaries to run gmxtest.pl.
95 # Testing an mdrun-only builds require supporting binaries from a full build
97 "With cross-compiling, multi-configuration generators (e.g. Visual Studio), or with mdrun-only builds, running regressiontests from build system is not supported. Please run gmxtest.pl directly.")
98 set(REGRESSIONTEST_PATH OFF CACHE BOOL
99 "With cross-compiling or multi-configuration generators, running regressiontests from build system is not supported." FORCE)
102 if(REGRESSIONTEST_PATH)
103 if(NOT EXISTS ${REGRESSIONTEST_PATH}/gmxtest.pl)
105 "REGRESSIONTEST_PATH invalid. The path needs to contain gmxtest.pl.")
108 # gmxtests target builds all binaries required for running gmxtest
109 add_custom_target(gmxtests DEPENDS gmx)
110 add_dependencies(run-ctest gmxtests)
111 add_dependencies(run-ctest-nophys gmxtests)
114 list(APPEND ARGS -double)
116 if(GMX_LIB_MPI AND NOT MPIEXEC) # find_program failed
118 "Please set MPIEXEC. Otherwise mpirun is assumed for running tests.")
120 if(DEFINED ENV{CI_JOB_ID} AND GMX_OPENMP)
121 set(GMX_REGRESSIONTEST_OMP_THREADS 2 CACHE STRING
122 "Number of OpenMP threads to use with the regression tests")
123 mark_as_advanced(GMX_REGRESSIONTEST_OMP_THREADS)
124 list(APPEND ARGS -ntomp ${GMX_REGRESSIONTEST_OMP_THREADS})
127 set(GMX_TEST_NUMBER_PROCS 8 CACHE STRING "Number of processors used for testing")
128 mark_as_advanced(GMX_TEST_NUMBER_PROCS)
129 list(APPEND ARGS -np ${GMX_TEST_NUMBER_PROCS})
131 list(APPEND ARGS -mpirun ${MPIEXEC})
133 #We should use MPIEXEC_NUMPROC_FLAG but gmxtest.pl doesn't let us pass it
135 if(GMX_BINARY_SUFFIX)
136 list(APPEND ARGS -suffix ${GMX_BINARY_SUFFIX})
138 #crosscompile is only used to disable checking whether binaries work
139 #given that we know they are there and that mdrun might not be exectuable
140 #(e.g. Cray) we enable it.
141 list(APPEND ARGS -crosscompile)
143 set(REGRESSIONTEST_EXTRA_ARGS "" CACHE STRING
144 "Extra arguments passed to gmxtest")
145 mark_as_advanced(REGRESSIONTEST_EXTRA_ARGS)
146 list(APPEND ARGS ${REGRESSIONTEST_EXTRA_ARGS})
148 if(DEFINED ENV{CI_JOB_ID} AND GMX_THREAD_MPI)
149 set(GMX_REGRESSIONTEST_THREAD_MPI_THREADS 2 CACHE STRING
150 "Number of thread MPI threads to use for testing")
151 mark_as_advanced(GMX_REGRESSIONTEST_THREAD_MPI_THREADS)
152 list(APPEND ARGS -nt ${GMX_REGRESSIONTEST_THREAD_MPI_THREADS})
154 list(APPEND ARGS -noverbose -nosuffix)
156 if(GMX_NATIVE_WINDOWS)
157 set(PATH_SEPARATOR "\\;")
158 #replacing \ with / shouldn't be neccessary. But otherwise "..\bin\;c:\.."
159 #gets turned into "...\bin\\c:\.." don't know why and don't have a better
160 #workaround. This workaround doesn't hurt.
161 string(REPLACE "\\" "/" PATH "$ENV{PATH}")
162 #protect ; (don't treat as list)
163 string(REPLACE ";" "\\;" PATH "${PATH}")
165 set(PATH_SEPARATOR ":")
166 set(PATH "$ENV{PATH}")
169 foreach(FOLDER bin lib) #lib folders might be needed for
170 #e.g. DLLs. For GMX paths native ("\") is needed for GMXLIB detection
171 file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${FOLDER}" DIR)
172 set(PATH "${DIR}${PATH_SEPARATOR}${PATH}")
175 find_program(PERL_EXECUTABLE NAMES "perl")
176 mark_as_advanced(PERL_EXECUTABLE)
178 if (NOT PERL_EXECUTABLE)
179 message(FATAL_ERROR "Perl not found. Install perl, set PERL_EXECUTABLE to the perl location, or unset REGRESSIONTEST_PATH to disable testing.")
182 #currently not testing tools because they don't contain any useful tests
183 foreach(subtest complex freeenergy rotation essentialdynamics)
184 add_test(NAME regressiontests/${subtest}
185 #windows requires the command to be perl and not the script
186 COMMAND perl "${REGRESSIONTEST_PATH}/gmxtest.pl" ${subtest} ${ARGS})
187 set_tests_properties(regressiontests/${subtest} PROPERTIES
188 ENVIRONMENT "PATH=${PATH}")
191 gmx_add_missing_tests_notice("Regression tests have not been run. If you want to run them from the build system, get the correct version of the regression tests package and set REGRESSIONTEST_PATH in CMake to point to it, or set REGRESSIONTEST_DOWNLOAD=ON.")
196 # Physical validation tests are opt-in via -DGMX_PHYSICAL_VALIDATION=ON
198 if(GMX_PHYSICAL_VALIDATION)
199 include(FindPythonModule)
200 # physical validation suite is distributed with the source
201 set(PHYSVALTEST_SOURCE_PATH
202 "${CMAKE_CURRENT_SOURCE_DIR}/physicalvalidation")
203 # CACHE PATH "Source directory containing physical validation tests.")
204 if(NOT EXISTS ${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py)
206 "GMX_PHYSICAL_VALIDATION set, but physical validation script not found in ${PHYSVALTEST_SOURCE_PATH}.")
209 if(CMAKE_CROSSCOMPILING OR CMAKE_CONFIGURATION_TYPES OR GMX_BUILD_MDRUN_ONLY)
210 # The following comment is copied from regression tests:
211 # Cross-compiling toolchains require us to compile both front-end and
212 # back-end binaries to run gmxtest.pl.
213 # Testing an mdrun-only builds require supporting binaries from a full build
214 # TODO: Look into the details of this.
215 # For now, turn it off - our python-gmx interface is probably not that stable for special cases anyway
217 "With cross-compiling, multi-configuration generators (e.g. Visual Studio), or with mdrun-only builds,\
218 running physical validation tests from build system is not supported.\
219 Please run physicalvalidation.py directly.")
220 set(GMX_PHYSICAL_VALIDATION OFF CACHE BOOL
221 "With cross-compiling or multi-configuration generators, running physical validation tests from build\
222 system is not supported." FORCE)
226 # Making sure gmx is built before running physical validation tests
228 add_dependencies(run-ctest-phys gmx)
229 add_dependencies(run-ctest gmx)
232 # Determine arguments passed to physicalvalidation.py
235 list(APPEND PARGS --wd ${CMAKE_CURRENT_BINARY_DIR}/physicalvalidation)
236 list(APPEND PARGS --bindir ${CMAKE_BINARY_DIR}/bin)
238 if(GMX_LIB_MPI AND NOT MPIEXEC) # find_program failed
240 "Please set MPIEXEC. Otherwise mpirun is assumed for running tests.")
243 # define number of processors in analogy to regression tests?
245 list(APPEND ARGS --mpicmd ${MPIEXEC})
247 list(APPEND ARGS --mpicmd mpirun)
252 "Physical validation using MPI not supported.")
255 if(GMX_BINARY_SUFFIX)
256 list(APPEND PARGS --suffix ${GMX_BINARY_SUFFIX})
260 # Give possibility to add args via cache
262 set(PHYSVALTEST_EXTRA_ARGS "" CACHE STRING
263 "Extra arguments passed to phystest")
264 mark_as_advanced(PHYSVALTEST_EXTRA_ARGS)
265 list(APPEND PARGS ${PHYSVALTEST_EXTRA_ARGS})
268 # The following lines are directly copied from regression tests.
269 # They seem to be applicable to physical validation tests as well.
271 if(GMX_NATIVE_WINDOWS)
272 set(PATH_SEPARATOR "\\;")
273 #replacing \ with / shouldn't be neccessary. But otherwise "..\bin\;c:\.."
274 #gets turned into "...\bin\\c:\.." don't know why and don't have a better
275 #workaround. This workaround doesn't hurt.
276 string(REPLACE "\\" "/" PATH "$ENV{PATH}")
277 #protect ; (don't treat as list)
278 string(REPLACE ";" "\\;" PATH "${PATH}")
280 set(PATH_SEPARATOR ":")
281 set(PATH "$ENV{PATH}")
284 foreach(FOLDER bin lib) #lib folders might be needed for
285 #e.g. DLLs. For GMX paths native ("\") is needed for GMXLIB detection
286 file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${FOLDER}" DIR)
287 set(PATH "${DIR}${PATH_SEPARATOR}${PATH}")
290 # End copied from regression tests.
293 if (NOT Python3_Interpreter_FOUND)
295 "Python not found. Physical validation requires python. \
296 Install python, set Python3_ROOT_DIR or PYTHON_EXECUTABLE to a valid location, \
297 or set GMX_PHYSICAL_VALIDATION=OFF to disable the physical validation tests.")
300 foreach(module numpy scipy pymbar) # add further modules if necessary
301 find_python_module(${module})
302 string(TOUPPER ${module} module_upper)
303 if(NOT PYTHONMODULE_${module_upper})
305 "Python module ${module} not found. Physical validation relies on ${module}. Make sure\
306 ${module} can be found by PYTHON_EXECUTABLE, or set GMX_PHYSICAL_VALIDATION=OFF to disable\
307 the physical validation tests.")
312 # Hook in our own tests
313 # Read them from json file to make every system a separate test
316 set(PHYSVALTEST_JSON "${PHYSVALTEST_SOURCE_PATH}/systems_d.json")
318 set(PHYSVALTEST_JSON "${PHYSVALTEST_SOURCE_PATH}/systems.json")
320 file(STRINGS "${PHYSVALTEST_JSON}" json)
321 string(REPLACE "\"" "" json ${json})
322 string(REPLACE "," "" json ${json})
323 string(REPLACE " " "" json ${json})
324 string(REPLACE ";" "<<>>" json ${json})
325 string(REPLACE "[" "" json ${json})
326 string(REPLACE "]" "" json ${json})
327 string(REPLACE "{" "" json ${json})
328 string(REPLACE "}" "" json ${json})
329 string(REPLACE "<<>>" ";" json ${json})
330 foreach(line ${json})
331 if("${line}" MATCHES "name:")
332 string(REPLACE "name:" "" testname ${line})
333 add_test(NAME physicalvalidationtests/${testname}
334 COMMAND ${PYTHON_EXECUTABLE} "${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py" "${PHYSVALTEST_JSON}" -s ${testname} -a ${PARGS})
335 set_tests_properties(physicalvalidationtests/${testname} PROPERTIES
336 ENVIRONMENT "PATH=${PATH}"
337 LABELS "PhysicalValidationTest")
342 # Create prepare and run targets while all variables are set
343 # Will be referenced in CheckTarget.cmake
345 # "check-phys-prepare" prepares the systems needed for physical validation for external running
346 add_custom_target(check-phys-prepare
347 COMMAND ${PYTHON_EXECUTABLE} "${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py" "${PHYSVALTEST_JSON}" -p ${PARGS}
348 COMMENT "Preparing systems for physical validation"
350 # "run-physval-sims" prepares and runs the systems needed for physical validation
351 add_custom_target(run-physval-sims
352 COMMAND ${PYTHON_EXECUTABLE} "${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py" "${PHYSVALTEST_JSON}" -r ${PARGS}
353 COMMENT "Preparing and running systems for physical validation"
358 # Create dummy prepare and run targets
359 # Will be referenced in CheckTarget.cmake
361 # "check-phys-prepare" prepares the systems needed for physical validation for external running
362 add_custom_target(check-phys-prepare
363 COMMAND ${CMAKE_COMMAND} -E echo "NOTE: You called the target `check-phys-prepare`, but ran cmake with\
364 `-DGMX_PHYSICAL_VALIDATION=OFF`. The physical validation tests are therefore unavailable,\
365 and this target is not doing anything."
366 COMMENT "No physical validation" VERBATIM)
367 # "run-physval-sims" prepares and runs the systems needed for physical validation
368 add_custom_target(run-physval-sims
369 COMMAND ${CMAKE_COMMAND} -E echo "NOTE: You called the target `run-physval-sims`, but ran cmake with\
370 `-DGMX_PHYSICAL_VALIDATION=OFF`. The physical validation tests are therefore unavailable,\
371 and this target is not doing anything."
372 COMMENT "No physical validation" VERBATIM)
375 gmx_create_missing_tests_notice_target()