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 include(FindPythonModule)
187 # physical validation suite is distributed with the source
188 set(PHYSVALTEST_SOURCE_PATH
189 "${CMAKE_CURRENT_SOURCE_DIR}/physicalvalidation")
190 # CACHE PATH "Source directory containing physical validation tests.")
191 if(NOT EXISTS ${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py)
193 "GMX_PHYSICAL_VALIDATION set, but physical validation script not found in ${PHYSVALTEST_SOURCE_PATH}.")
196 if(CMAKE_CROSSCOMPILING OR CMAKE_CONFIGURATION_TYPES OR GMX_BUILD_MDRUN_ONLY)
197 # The following comment is copied from regression tests:
198 # Cross-compiling toolchains require us to compile both front-end and
199 # back-end binaries to run gmxtest.pl.
200 # Testing an mdrun-only builds require supporting binaries from a full build
201 # TODO: Look into the details of this.
202 # For now, turn it off - our python-gmx interface is probably not that stable for special cases anyway
204 "With cross-compiling, multi-configuration generators (e.g. Visual Studio), or with mdrun-only builds,\
205 running physical validation tests from build system is not supported.\
206 Please run physicalvalidation.py directly.")
207 set(GMX_PHYSICAL_VALIDATION OFF CACHE BOOL
208 "With cross-compiling or multi-configuration generators, running physical validation tests from build\
209 system is not supported." FORCE)
213 # Making sure gmx is built before running physical validation tests
215 add_dependencies(run-ctest-phys gmx)
216 add_dependencies(run-ctest gmx)
219 # Determine arguments passed to physicalvalidation.py
222 list(APPEND PARGS --wd ${CMAKE_CURRENT_BINARY_DIR}/physicalvalidation)
223 list(APPEND PARGS --bindir ${CMAKE_BINARY_DIR}/bin)
225 if(GMX_LIB_MPI AND NOT MPIEXEC) # find_program failed
227 "Please set MPIEXEC. Otherwise mpirun is assumed for running tests.")
230 # define number of processors in analogy to regression tests?
232 list(APPEND ARGS --mpicmd ${MPIEXEC})
234 list(APPEND ARGS --mpicmd mpirun)
239 "Physical validation using MPI not supported.")
242 if(GMX_BINARY_SUFFIX)
243 list(APPEND PARGS --suffix ${GMX_BINARY_SUFFIX})
247 # Give possibility to add args via cache
249 set(PHYSVALTEST_EXTRA_ARGS "" CACHE STRING
250 "Extra arguments passed to phystest")
251 mark_as_advanced(PHYSVALTEST_EXTRA_ARGS)
252 list(APPEND PARGS ${PHYSVALTEST_EXTRA_ARGS})
255 # The following lines are directly copied from regression tests.
256 # They seem to be applicable to physical validation tests as well.
258 if(GMX_NATIVE_WINDOWS)
259 set(PATH_SEPARATOR "\\;")
260 #replacing \ with / shouldn't be neccessary. But otherwise "..\bin\;c:\.."
261 #gets turned into "...\bin\\c:\.." don't know why and don't have a better
262 #workaround. This workaround doesn't hurt.
263 string(REPLACE "\\" "/" PATH "$ENV{PATH}")
264 #protect ; (don't treat as list)
265 string(REPLACE ";" "\\;" PATH "${PATH}")
267 set(PATH_SEPARATOR ":")
268 set(PATH "$ENV{PATH}")
271 foreach(FOLDER bin lib) #lib folders might be needed for
272 #e.g. DLLs. For GMX paths native ("\") is needed for GMXLIB detection
273 file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${FOLDER}" DIR)
274 set(PATH "${DIR}${PATH_SEPARATOR}${PATH}")
277 # End copied from regression tests.
280 if (NOT PYTHONINTERP_FOUND)
282 "Python not found. Physical validation requires python. \
283 Install python, set PYTHON_EXECUTABLE to a valid python location, \
284 or set GMX_PHYSICAL_VALIDATION=OFF to disable the physical validation tests.")
287 foreach(module numpy scipy pymbar) # add further modules if necessary
288 find_python_module(${module})
289 string(TOUPPER ${module} module_upper)
290 if(NOT PYTHONMODULE_${module_upper})
292 "Python module ${module} not found. Physical validation relies on ${module}. Make sure\
293 ${module} can be found by PYTHON_EXECUTABLE, or set GMX_PHYSICAL_VALIDATION=OFF to disable\
294 the physical validation tests.")
299 # Hook in our own tests
300 # Read them from json file to make every system a separate test
303 set(PHYSVALTEST_JSON "${PHYSVALTEST_SOURCE_PATH}/systems_d.json")
305 set(PHYSVALTEST_JSON "${PHYSVALTEST_SOURCE_PATH}/systems.json")
307 file(STRINGS "${PHYSVALTEST_JSON}" json)
308 string(REPLACE "\"" "" json ${json})
309 string(REPLACE "," "" json ${json})
310 string(REPLACE " " "" json ${json})
311 string(REPLACE ";" "<<>>" json ${json})
312 string(REPLACE "[" "" json ${json})
313 string(REPLACE "]" "" json ${json})
314 string(REPLACE "{" "" json ${json})
315 string(REPLACE "}" "" json ${json})
316 string(REPLACE "<<>>" ";" json ${json})
317 foreach(line ${json})
318 if("${line}" MATCHES "name:")
319 string(REPLACE "name:" "" testname ${line})
320 add_test(NAME physicalvalidationtests/${testname}
321 COMMAND ${PYTHON_EXECUTABLE} "${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py" "${PHYSVALTEST_JSON}" -s ${testname} -a ${PARGS})
322 set_tests_properties(physicalvalidationtests/${testname} PROPERTIES
323 ENVIRONMENT "PATH=${PATH}"
324 LABELS "PhysicalValidationTest")
329 # Create prepare and run targets while all variables are set
330 # Will be referenced in CheckTarget.cmake
332 # "check-phys-prepare" prepares the systems needed for physical validation for external running
333 add_custom_target(check-phys-prepare
334 COMMAND ${PYTHON_EXECUTABLE} "${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py" "${PHYSVALTEST_JSON}" -p ${PARGS}
335 COMMENT "Preparing systems for physical validation"
337 # "run-physval-sims" prepares and runs the systems needed for physical validation
338 add_custom_target(run-physval-sims
339 COMMAND ${PYTHON_EXECUTABLE} "${PHYSVALTEST_SOURCE_PATH}/gmx_physicalvalidation.py" "${PHYSVALTEST_JSON}" -r ${PARGS}
340 COMMENT "Preparing and running systems for physical validation"
345 # Create dummy prepare and run targets
346 # Will be referenced in CheckTarget.cmake
348 # "check-phys-prepare" prepares the systems needed for physical validation for external running
349 add_custom_target(check-phys-prepare
350 COMMAND ${CMAKE_COMMAND} -E echo "NOTE: You called the target `check-phys-prepare`, but ran cmake with\
351 `-DGMX_PHYSICAL_VALIDATION=OFF`. The physical validation tests are therefore unavailable,\
352 and this target is not doing anything."
353 COMMENT "No physical validation" VERBATIM)
354 # "run-physval-sims" prepares and runs the systems needed for physical validation
355 add_custom_target(run-physval-sims
356 COMMAND ${CMAKE_COMMAND} -E echo "NOTE: You called the target `run-physval-sims`, but ran cmake with\
357 `-DGMX_PHYSICAL_VALIDATION=OFF`. The physical validation tests are therefore unavailable,\
358 and this target is not doing anything."
359 COMMENT "No physical validation" VERBATIM)
362 gmx_create_missing_tests_notice_target()