Fix regressiontests automated download
[alexxy/gromacs.git] / tests / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012,2013, by the GROMACS development team, led by
5 # David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 # others, as listed in the AUTHORS file in the top-level source
7 # 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." no)
39 if(REGRESSIONTEST_DOWNLOAD AND CMAKE_VERSION VERSION_LESS "2.8.2")
40     message(WARNING "REGRESSIONTEST_DOWNLOAD requires cmake >=2.8.2. Please update cmake or manually download the regressiontests.")
41     set(REGRESSIONTEST_DOWNLOAD FALSE CACHE BOOL 
42         "REGRESSIONTEST_DOWNLOAD not supported with cmake ${CMAKE_VERSION}" FORCE)
43 endif()
44 if(REGRESSIONTEST_DOWNLOAD)
45     if(NOT REGRESSIONTEST_VERSION)
46         message(FATAL_ERROR "The configuration files do not specify what regressiontests tarball is suitable for automated download and testing. Please obtain and use a suitable set of tests yourself.")
47     endif()
48     set(REGRESSIONTEST_URL
49         http://gerrit.gromacs.org/download/regressiontests-${REGRESSIONTEST_VERSION}.tar.gz)
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
63     set(REGRESSIONTEST_PATH
64         "${CMAKE_CURRENT_BINARY_DIR}/regressiontests-${REGRESSIONTEST_VERSION}"
65         CACHE PATH "Path to auto-downloaded regressiontests" FORCE)
66     file(REMOVE_RECURSE "${REGRESSIONTEST_PATH}") #delete potential prior folder
67     execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${REGRESSIONTEST_FILE}"
68         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
69     if(NOT EXISTS ${REGRESSIONTEST_PATH}/gmxtest.pl)
70         message(FATAL_ERROR "Download incorrect. Doesn't contain required gmxtest.pl")
71     endif()
72     set(REGRESSIONTEST_DOWNLOAD OFF CACHE BOOL "Tests already downloaded. Set to yes to download again" FORCE)
73 endif()
74
75 if(REGRESSIONTEST_PATH AND (GMX_BLUEGENE OR CMAKE_CROSSCOMPILING OR CMAKE_CONFIGURATION_TYPES))
76     #Bluegene requires us to compile both front-end and back-end binaries (single build is insufficient)
77     message(WARNING 
78         "With cross-compiling or multi-configuration generators (e.g. Visual Studio), running regressiontests from build system is not supported. Please run gmxtest.pl directly.")
79     set(REGRESSIONTEST_PATH OFF CACHE BOOL 
80         "With cross-compiling or multi-configuration generators, running regressiontests from build system is not supported." FORCE)
81 endif()
82
83 if(REGRESSIONTEST_PATH)
84     if(NOT EXISTS ${REGRESSIONTEST_PATH}/gmxtest.pl)
85         message(FATAL_ERROR
86             "REGRESSIONTEST_PATH invalid. The path needs to contain gmxtest.pl.")
87     endif()
88     if(GMX_DOUBLE)
89         list(APPEND ARGS -double)
90     endif()
91     if(GMX_LIB_MPI AND NOT MPIEXEC) #autodetection failed or CC=mpicc was used
92         message(WARNING
93             "Please set MPIEXEC. Otherwise mpirun is assumed for runnings tests.")
94     endif()
95     if(GMX_LIB_MPI)
96         set(GMX_TEST_NUMBER_PROCS 8 CACHE STRING "Number of processors used for testing")
97         mark_as_advanced(GMX_TEST_NUMBER_PROCS)
98         list(APPEND ARGS -np ${GMX_TEST_NUMBER_PROCS})
99         if(MPIEXEC)
100             list(APPEND ARGS -mpirun ${MPIEXEC})
101         endif()
102         #We should use MPIEXEC_NUMPROC_FLAG but gmxtest.pl doesn't let us pass it
103     endif()
104     if(GMX_BINARY_SUFFIX)
105         list(APPEND ARGS -suffix ${GMX_BINARY_SUFFIX})
106     endif()
107     #crosscompile is only used to disable checking whether binaries work
108     #given that we know they are there and that mdrun might not be exectuable
109     #(e.g. Cray) we enable it.
110     list(APPEND ARGS -crosscompile)
111
112     set(REGRESSIONTEST_EXTRA_ARGS "" CACHE STRING 
113         "Extra arguments passed to gmxtest")
114     mark_as_advanced(REGRESSIONTEST_EXTRA_ARGS)
115     list(APPEND ARGS ${REGRESSIONTEST_EXTRA_ARGS})
116
117     list(APPEND ARGS -noverbose -nosuffix)
118
119     if(GMX_NATIVE_WINDOWS)
120         set(PATH_SEPARATOR "\\;")
121         #replacing \ with / shouldn't be neccessary. But otherwise "..\bin\;c:\.."
122         #gets turned into "...\bin\\c:\.." don't know why and don't have a better
123         #workaround. This workaround doesn't hurt.
124         string(REPLACE "\\" "/" PATH "$ENV{PATH}")
125         #protect ; (don't treat as list)
126         string(REPLACE ";" "\\;" PATH "${PATH}")
127     else()
128         set(PATH_SEPARATOR ":")
129         set(PATH "$ENV{PATH}")
130     endif()
131
132     foreach(FOLDER kernel tools gmxlib mdlib) #lib folders might be needed for
133         #e.g. DLLs. For GMX paths native ("\") is needed for GMXLIB detection
134         file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/src/${FOLDER}" DIR)
135         set(PATH "${DIR}${PATH_SEPARATOR}${PATH}")
136     endforeach()
137
138     find_program(PERL_EXECUTABLE NAMES "perl")
139     mark_as_advanced(PERL_EXECUTABLE)
140
141     if (NOT PERL_EXECUTABLE)
142         message(FATAL_ERROR "Perl not found. Install perl, set PERL_EXECUTABLE to the perl location, or unset REGRESSIONTEST_PATH to disable testing.")
143     endif()
144
145     #currently not testing tools because they don't contain any useful tests
146     foreach(subtest simple complex kernel freeenergy pdb2gmx)
147         add_test(NAME regressiontests/${subtest}
148             #windows requires the command to be perl and not the script
149             COMMAND perl "${REGRESSIONTEST_PATH}/gmxtest.pl" ${subtest} ${ARGS})
150         set_tests_properties(regressiontests/${subtest} PROPERTIES
151             ENVIRONMENT "PATH=${PATH}")
152     endforeach()
153 endif()