Add basic tests for reading/writing structure files
[alexxy/gromacs.git] / tests / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012,2013,2014,2015, 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.
8 #
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.
13 #
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.
18 #
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.
23 #
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.
31 #
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.
34
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)
39
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
44     else()
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)
49     endif()
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)
55
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}
60 log: ${log}")
61     endif()
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}")
66         endif()
67     else()
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)
76         else()
77             message(FATAL_ERROR "Failed to list the contents of the downloaded tarball: ${REGRESSIONTEST_FILE}")
78         endif()
79     endif()
80
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")
86     endif()
87     set(REGRESSIONTEST_DOWNLOAD OFF CACHE BOOL "Tests already downloaded. Set to yes to download again" FORCE)
88 endif()
89
90 if(REGRESSIONTEST_PATH AND (GMX_BLUEGENE OR CMAKE_CROSSCOMPILING OR CMAKE_CONFIGURATION_TYPES OR GMX_BUILD_MDRUN_ONLY))
91     # TODO: It would be nicer to do these before potentially downloading the tests.
92     # Bluegene requires us to compile both front-end and back-end binaries
93     # (single build is insufficient)
94     # Testing an mdrun-only builds require supporting binaries from a full build
95     message(WARNING
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)
99 endif()
100
101 if(REGRESSIONTEST_PATH)
102     if(NOT EXISTS ${REGRESSIONTEST_PATH}/gmxtest.pl)
103         message(FATAL_ERROR
104             "REGRESSIONTEST_PATH invalid. The path needs to contain gmxtest.pl.")
105     endif()
106
107     # gmxtests target builds all binaries required for running gmxtest
108     add_custom_target(gmxtests DEPENDS gmx)
109     add_dependencies(run-ctest gmxtests)
110
111     if(GMX_DOUBLE)
112         list(APPEND ARGS -double)
113     endif()
114     if(GMX_LIB_MPI AND NOT MPIEXEC) # find_program failed
115         message(WARNING
116             "Please set MPIEXEC. Otherwise mpirun is assumed for running tests.")
117     endif()
118     if(GMX_LIB_MPI)
119         set(GMX_TEST_NUMBER_PROCS 8 CACHE STRING "Number of processors used for testing")
120         mark_as_advanced(GMX_TEST_NUMBER_PROCS)
121         list(APPEND ARGS -np ${GMX_TEST_NUMBER_PROCS})
122         if(MPIEXEC)
123             list(APPEND ARGS -mpirun ${MPIEXEC})
124         endif()
125         #We should use MPIEXEC_NUMPROC_FLAG but gmxtest.pl doesn't let us pass it
126     endif()
127     if(GMX_BINARY_SUFFIX)
128         list(APPEND ARGS -suffix ${GMX_BINARY_SUFFIX})
129     endif()
130     #crosscompile is only used to disable checking whether binaries work
131     #given that we know they are there and that mdrun might not be exectuable
132     #(e.g. Cray) we enable it.
133     list(APPEND ARGS -crosscompile)
134
135     set(REGRESSIONTEST_EXTRA_ARGS "" CACHE STRING 
136         "Extra arguments passed to gmxtest")
137     mark_as_advanced(REGRESSIONTEST_EXTRA_ARGS)
138     list(APPEND ARGS ${REGRESSIONTEST_EXTRA_ARGS})
139
140     list(APPEND ARGS -noverbose -nosuffix)
141
142     if(GMX_NATIVE_WINDOWS)
143         set(PATH_SEPARATOR "\\;")
144         #replacing \ with / shouldn't be neccessary. But otherwise "..\bin\;c:\.."
145         #gets turned into "...\bin\\c:\.." don't know why and don't have a better
146         #workaround. This workaround doesn't hurt.
147         string(REPLACE "\\" "/" PATH "$ENV{PATH}")
148         #protect ; (don't treat as list)
149         string(REPLACE ";" "\\;" PATH "${PATH}")
150     else()
151         set(PATH_SEPARATOR ":")
152         set(PATH "$ENV{PATH}")
153     endif()
154
155     foreach(FOLDER bin lib) #lib folders might be needed for
156         #e.g. DLLs. For GMX paths native ("\") is needed for GMXLIB detection
157         file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${FOLDER}" DIR)
158         set(PATH "${DIR}${PATH_SEPARATOR}${PATH}")
159     endforeach()
160
161     find_program(PERL_EXECUTABLE NAMES "perl")
162     mark_as_advanced(PERL_EXECUTABLE)
163
164     if (NOT PERL_EXECUTABLE)
165         message(FATAL_ERROR "Perl not found. Install perl, set PERL_EXECUTABLE to the perl location, or unset REGRESSIONTEST_PATH to disable testing.")
166     endif()
167
168     #currently not testing tools because they don't contain any useful tests
169     foreach(subtest simple complex kernel freeenergy pdb2gmx rotation)
170         add_test(NAME regressiontests/${subtest}
171             #windows requires the command to be perl and not the script
172             COMMAND perl "${REGRESSIONTEST_PATH}/gmxtest.pl" ${subtest} ${ARGS})
173         set_tests_properties(regressiontests/${subtest} PROPERTIES
174             ENVIRONMENT "PATH=${PATH}")
175     endforeach()
176 else()
177     add_custom_target(regressiontests-notice
178         ${CMAKE_COMMAND} -E echo "NOTE: 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."
179         DEPENDS run-ctest
180         COMMENT "Regression tests not available" VERBATIM)
181     add_dependencies(check regressiontests-notice)
182 endif()
183
184 include(CppCheck.cmake)