2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 set(REGRESSIONTEST_PATH "" CACHE PATH "Directory containing regressiontests")
36 mark_as_advanced(REGRESSIONTEST_PATH)
37 option(REGRESSIONTEST_DOWNLOAD
38 "Automatically download regressiontests. Tests can be run with ctest." OFF)
40 if(REGRESSIONTEST_DOWNLOAD)
41 if (NOT SOURCE_IS_SOURCE_DISTRIBUTION)
42 set(REGRESSIONTEST_URL http://gerrit.gromacs.org/snapshot/${REGRESSIONTEST_BRANCH})
43 # REGRESSIONTEST_PATH for dev trees is set later based on the dirname found in the tar
45 set(REGRESSIONTEST_URL http://gerrit.gromacs.org/download/regressiontests-${REGRESSIONTEST_VERSION}.tar.gz)
46 set(REGRESSIONTEST_PATH
47 "${CMAKE_CURRENT_BINARY_DIR}/regressiontests-${REGRESSIONTEST_VERSION}"
48 CACHE PATH "Path to auto-downloaded regressiontests" FORCE)
50 set(REGRESSIONTEST_FILE "${CMAKE_CURRENT_BINARY_DIR}/regressiontests.tgz")
51 message("Downloading: ${REGRESSIONTEST_URL}")
52 file(DOWNLOAD ${REGRESSIONTEST_URL} "${REGRESSIONTEST_FILE}" SHOW_PROGRESS STATUS status LOG log)
53 list(GET status 0 status_code)
54 list(GET status 1 status_string)
56 if(NOT status_code EQUAL 0)
57 message(FATAL_ERROR "error: downloading '${REGRESSIONTEST_URL}' failed
58 status_code: ${status_code}
59 status_string: ${status_string}
62 if (SOURCE_IS_SOURCE_DISTRIBUTION)
63 file(MD5 ${REGRESSIONTEST_FILE} COMPUTED_MD5SUM)
64 if(NOT ${REGRESSIONTEST_MD5SUM} STREQUAL ${COMPUTED_MD5SUM})
65 message(FATAL_ERROR "Download of regressiontests failed. Expected MD5 of ${REGRESSIONTEST_MD5SUM} but download has ${COMPUTED_MD5SUM}")
68 # Extract the REGRESSIONTEST_PATH from the tar when using dev tree.
69 execute_process(COMMAND ${CMAKE_COMMAND} -E tar tf "${REGRESSIONTEST_FILE}"
70 RESULT_VARIABLE _tar_tf_res
71 OUTPUT_VARIABLE _tar_tf_out)
72 if (${_tar_tf_res} EQUAL 0)
73 string(REGEX REPLACE "/\n.*$" "" _regressiontest_dir "${_tar_tf_out}")
74 set(REGRESSIONTEST_PATH "${CMAKE_CURRENT_BINARY_DIR}/${_regressiontest_dir}"
75 CACHE PATH "Path to auto-downloaded regressiontests" FORCE)
77 message(FATAL_ERROR "Failed to list the contents of the downloaded tarball: ${REGRESSIONTEST_FILE}")
81 file(REMOVE_RECURSE "${REGRESSIONTEST_PATH}") #delete potential prior folder
82 execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${REGRESSIONTEST_FILE}"
83 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
84 if(NOT EXISTS ${REGRESSIONTEST_PATH}/gmxtest.pl)
85 message(FATAL_ERROR "Download incorrect. Doesn't contain required gmxtest.pl")
87 set(REGRESSIONTEST_DOWNLOAD OFF CACHE BOOL "Tests already downloaded. Set to yes to download again" FORCE)
90 if(REGRESSIONTEST_PATH AND (CMAKE_CROSSCOMPILING OR CMAKE_CONFIGURATION_TYPES OR GMX_BUILD_MDRUN_ONLY))
91 # TODO: It would be nicer to do these checks before potentially downloading the tests.
92 # Cross-compiling toolchains require us to compile both front-end and
93 # back-end binaries to run gmxtest.pl.
94 # Testing an mdrun-only builds require supporting binaries from a full build
96 "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.")
97 set(REGRESSIONTEST_PATH OFF CACHE BOOL
98 "With cross-compiling or multi-configuration generators, running regressiontests from build system is not supported." FORCE)
101 if(REGRESSIONTEST_PATH)
102 if(NOT EXISTS ${REGRESSIONTEST_PATH}/gmxtest.pl)
104 "REGRESSIONTEST_PATH invalid. The path needs to contain gmxtest.pl.")
107 # gmxtests target builds all binaries required for running gmxtest
108 add_custom_target(gmxtests DEPENDS gmx)
109 add_dependencies(run-ctest gmxtests)
110 add_dependencies(run-ctest-nophys gmxtests)
113 list(APPEND ARGS -double)
115 if(GMX_LIB_MPI AND NOT MPIEXEC) # find_program failed
117 "Please set MPIEXEC. Otherwise mpirun is assumed for running tests.")
120 set(GMX_TEST_NUMBER_PROCS 8 CACHE STRING "Number of processors used for testing")
121 mark_as_advanced(GMX_TEST_NUMBER_PROCS)
122 list(APPEND ARGS -np ${GMX_TEST_NUMBER_PROCS})
124 list(APPEND ARGS -mpirun ${MPIEXEC})
126 #We should use MPIEXEC_NUMPROC_FLAG but gmxtest.pl doesn't let us pass it
128 if(GMX_BINARY_SUFFIX)
129 list(APPEND ARGS -suffix ${GMX_BINARY_SUFFIX})
131 #crosscompile is only used to disable checking whether binaries work
132 #given that we know they are there and that mdrun might not be exectuable
133 #(e.g. Cray) we enable it.
134 list(APPEND ARGS -crosscompile)
136 set(REGRESSIONTEST_EXTRA_ARGS "" CACHE STRING
137 "Extra arguments passed to gmxtest")
138 mark_as_advanced(REGRESSIONTEST_EXTRA_ARGS)
139 list(APPEND ARGS ${REGRESSIONTEST_EXTRA_ARGS})
141 list(APPEND ARGS -noverbose -nosuffix)
143 if(GMX_NATIVE_WINDOWS)
144 set(PATH_SEPARATOR "\\;")
145 #replacing \ with / shouldn't be neccessary. But otherwise "..\bin\;c:\.."
146 #gets turned into "...\bin\\c:\.." don't know why and don't have a better
147 #workaround. This workaround doesn't hurt.
148 string(REPLACE "\\" "/" PATH "$ENV{PATH}")
149 #protect ; (don't treat as list)
150 string(REPLACE ";" "\\;" PATH "${PATH}")
152 set(PATH_SEPARATOR ":")
153 set(PATH "$ENV{PATH}")
156 foreach(FOLDER bin lib) #lib folders might be needed for
157 #e.g. DLLs. For GMX paths native ("\") is needed for GMXLIB detection
158 file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${FOLDER}" DIR)
159 set(PATH "${DIR}${PATH_SEPARATOR}${PATH}")
162 find_program(PERL_EXECUTABLE NAMES "perl")
163 mark_as_advanced(PERL_EXECUTABLE)
165 if (NOT PERL_EXECUTABLE)
166 message(FATAL_ERROR "Perl not found. Install perl, set PERL_EXECUTABLE to the perl location, or unset REGRESSIONTEST_PATH to disable testing.")
169 #currently not testing tools because they don't contain any useful tests
170 foreach(subtest complex freeenergy rotation essentialdynamics)
171 add_test(NAME regressiontests/${subtest}
172 #windows requires the command to be perl and not the script
173 COMMAND perl "${REGRESSIONTEST_PATH}/gmxtest.pl" ${subtest} ${ARGS})
174 set_tests_properties(regressiontests/${subtest} PROPERTIES
175 ENVIRONMENT "PATH=${PATH}")
178 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.")
183 # Physical validation tests are opt-in via -DGMX_PHYSICAL_VALIDATION=ON
185 if(GMX_PHYSICAL_VALIDATION)
186 # physical validation suite is distributed with the source
187 set(PHYSVALTEST_SOURCE_PATH
188 "${CMAKE_CURRENT_SOURCE_DIR}/physicalvalidation")
189 # CACHE PATH "Source directory containing physical validation tests.")
190 if(NOT EXISTS ${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py)
192 "GMX_PHYSICAL_VALIDATION set, but physical validation script not found in ${PHYSVALTEST_SOURCE_PATH}.")
195 if(CMAKE_CROSSCOMPILING OR CMAKE_CONFIGURATION_TYPES OR GMX_BUILD_MDRUN_ONLY)
196 # The following comment is copied from regression tests:
197 # Cross-compiling toolchains require us to compile both front-end and
198 # back-end binaries to run gmxtest.pl.
199 # Testing an mdrun-only builds require supporting binaries from a full build
200 # TODO: Look into the details of this.
201 # For now, turn it off - our python-gmx interface is probably not that stable for special cases anyway
203 "With cross-compiling, multi-configuration generators (e.g. Visual Studio), or with mdrun-only builds,\
204 running physical validation tests from build system is not supported.\
205 Please run physicalvalidation.py directly.")
206 set(GMX_PHYSICAL_VALIDATION OFF CACHE BOOL
207 "With cross-compiling or multi-configuration generators, running physical validation tests from build\
208 system is not supported." FORCE)
212 # Making sure gmx is built before running physical validation tests
214 add_dependencies(run-ctest-phys gmx)
215 add_dependencies(run-ctest gmx)
218 # Determine arguments passed to physicalvalidation.py
221 list(APPEND PARGS --wd ${CMAKE_CURRENT_BINARY_DIR}/physicalvalidation)
222 list(APPEND PARGS --bindir ${CMAKE_BINARY_DIR}/bin)
224 if(GMX_LIB_MPI AND NOT MPIEXEC) # find_program failed
226 "Please set MPIEXEC. Otherwise mpirun is assumed for running tests.")
229 # define number of processors in analogy to regression tests?
231 list(APPEND ARGS --mpicmd ${MPIEXEC})
233 list(APPEND ARGS --mpicmd mpirun)
238 "Physical validation using MPI not supported.")
241 if(GMX_BINARY_SUFFIX)
242 list(APPEND PARGS --suffix ${GMX_BINARY_SUFFIX})
246 # Give possibility to add args via cache
248 set(PHYSVALTEST_EXTRA_ARGS "" CACHE STRING
249 "Extra arguments passed to phystest")
250 mark_as_advanced(PHYSVALTEST_EXTRA_ARGS)
251 list(APPEND PARGS ${PHYSVALTEST_EXTRA_ARGS})
254 # The following lines are directly copied from regression tests.
255 # They seem to be applicable to physical validation tests as well.
257 if(GMX_NATIVE_WINDOWS)
258 set(PATH_SEPARATOR "\\;")
259 #replacing \ with / shouldn't be neccessary. But otherwise "..\bin\;c:\.."
260 #gets turned into "...\bin\\c:\.." don't know why and don't have a better
261 #workaround. This workaround doesn't hurt.
262 string(REPLACE "\\" "/" PATH "$ENV{PATH}")
263 #protect ; (don't treat as list)
264 string(REPLACE ";" "\\;" PATH "${PATH}")
266 set(PATH_SEPARATOR ":")
267 set(PATH "$ENV{PATH}")
270 foreach(FOLDER bin lib) #lib folders might be needed for
271 #e.g. DLLs. For GMX paths native ("\") is needed for GMXLIB detection
272 file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${FOLDER}" DIR)
273 set(PATH "${DIR}${PATH_SEPARATOR}${PATH}")
276 # End copied from regression tests.
280 # TODO: Switch to python >= 3.3. For now, use 2.7 for compatibility with rest of build system.
282 # ${PYTHON_EXECUTABLE} can only be set for one version per build system.
283 # Currently, the following files set 2.7 explicitly:
284 # * cmake/CheckTarget.cmake
285 # * docs/CMakeList.txt
286 # Parts of the documentation rely on python scripts.
287 # These need to be ported to be able to make the move to python 3.
289 if (NOT PYTHON_EXECUTABLE)
291 "Python not found. Physical validation relies on python >= 3.3 (python 2.7 supported, but\
292 deprecated). Install python, set PYTHON_EXECUTABLE to the python location, or set\
293 GMX_PHYSCIAL_VALIDATION=OFF to disable the physical validation tests.")
296 foreach(module numpy scipy pymbar) # add further modules if necessary
297 find_python_module(${module})
298 string(TOUPPER ${module} module_upper)
299 if(NOT PYTHONMODULE_${module_upper})
301 "Python module ${module} not found. Physical validation relies on ${module}. Make sure\
302 ${module} can be found by PYTHON_EXECUTABLE, or set GMX_PHYSCIAL_VALIDATION=OFF to disable\
303 the physical validation tests.")
308 # Hook in our own tests
309 # Read them from json file to make every system a separate test
312 set(PHYSVALTEST_JSON "${PHYSVALTEST_SOURCE_PATH}/systems_d.json")
314 set(PHYSVALTEST_JSON "${PHYSVALTEST_SOURCE_PATH}/systems.json")
316 file(STRINGS "${PHYSVALTEST_JSON}" json)
317 string(REPLACE "\"" "" json ${json})
318 string(REPLACE "," "" json ${json})
319 string(REPLACE " " "" json ${json})
320 string(REPLACE ";" "<<>>" 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 foreach(line ${json})
327 if("${line}" MATCHES "name:")
328 string(REPLACE "name:" "" testname ${line})
329 add_test(NAME physicalvalidationtests/${testname}
330 COMMAND ${PYTHON_EXECUTABLE} "${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py" "${PHYSVALTEST_JSON}" -s ${testname} -a ${PARGS})
331 set_tests_properties(physicalvalidationtests/${testname} PROPERTIES
332 ENVIRONMENT "PATH=${PATH}"
333 LABELS "PhysicalValidationTest")
338 # Create prepare and run targets while all variables are set
339 # Will be referenced in CheckTarget.cmake
341 # "check-phys-prepare" prepares the systems needed for physical validation for external running
342 add_custom_target(check-phys-prepare
343 COMMAND ${PYTHON_EXECUTABLE} "${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py" "${PHYSVALTEST_JSON}" -p ${PARGS}
344 COMMENT "Preparing systems for physical validation"
346 # "run-physval-sims" prepares and runs the systems needed for physical validation
347 add_custom_target(run-physval-sims
348 COMMAND ${PYTHON_EXECUTABLE} "${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py" "${PHYSVALTEST_JSON}" -r ${PARGS}
349 COMMENT "Preparing and running systems for physical validation"
354 # Create dummy prepare and run targets
355 # Will be referenced in CheckTarget.cmake
357 # "check-phys-prepare" prepares the systems needed for physical validation for external running
358 add_custom_target(check-phys-prepare
359 COMMAND ${CMAKE_COMMAND} -E echo "NOTE: You called the target `check-phys-prepare`, but ran cmake with\
360 `-DGMX_PHYSICAL_VALIDATION=OFF`. The physical validation tests are therefore unavailable,\
361 and this target is not doing anything."
362 COMMENT "No physical validation" VERBATIM)
363 # "run-physval-sims" prepares and runs the systems needed for physical validation
364 add_custom_target(run-physval-sims
365 COMMAND ${CMAKE_COMMAND} -E echo "NOTE: You called the target `run-physval-sims`, but ran cmake with\
366 `-DGMX_PHYSICAL_VALIDATION=OFF`. The physical validation tests are therefore unavailable,\
367 and this target is not doing anything."
368 COMMENT "No physical validation" VERBATIM)
371 gmx_create_missing_tests_notice_target()