Run regressiontests from build
authorRoland Schulz <roland@utk.edu>
Sat, 22 Dec 2012 21:47:50 +0000 (16:47 -0500)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Thu, 17 Jan 2013 17:42:21 +0000 (18:42 +0100)
If either REGRESSIONTEST_PATH or REGRESSIONTEST_DOWNLOAD is set,
the regressiontests are run as ctests. The later option auto-
downloads the regressiontest repo.

The "check" target builds and runs tests in one step.
The "gmxtests" target builds tests.
If neither variable is set by the user, the commit doesn't change
the prior behavior (no messsages). Running the new target "check"
without either variable set, prints a warnings.

This commit also removes the prior pseudo test of running
"mdrun -h".

Change-Id: I103648f8a87891727a70775b19449fc269002a1c

CMakeLists.txt
tests/CMakeLists.txt

index 0a39a467718a2abd4efab81605a40d873fc8bfcf..3a34b8b6a9cf463abe5cbb518a42e2b729db9ac3 100644 (file)
@@ -1136,8 +1136,17 @@ ADD_CUSTOM_TARGET(uninstall
 
 include(CTest)
 mark_as_advanced(BUILD_TESTING)
+#gmxtests target builds all binaries required for running gmxtest
+add_custom_target(gmxtests DEPENDS grompp mdrun pdb2gmx gmxcheck editconf)
 IF(BUILD_TESTING)
-       enable_testing()
-       add_subdirectory(tests)
+    enable_testing()
+    add_subdirectory(tests)
+    if(REGRESSIONTEST_PATH)
+        #check target builds all to run tests and the runs tests
+        add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
+        add_dependencies(check gmxtests)
+    else()
+        add_custom_target(check COMMAND ${CMAKE_COMMAND} -E echo "WARNING: No tests are run. Running the tests requires either of the cmake variables REGRESSIONTEST_PATH or REGRESSIONTEST_DOWNLOAD to be set.")
+    endif()
 ENDIF()
 
index b7b44ddc7abb7ae3f30f4a85640f9ab15f5b6b78..edb5cf471b00f9473e36accca12c3b17aeac57cc 100644 (file)
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 #
-enable_testing()
-add_test(TestExec_mdrun-h ../src/kernel/mdrun -h)
+set(REGRESSIONTEST_PATH "" CACHE PATH "Directory containing regressiontests")
+mark_as_advanced(REGRESSIONTEST_PATH)
+option(REGRESSIONTEST_DOWNLOAD
+    "Automatically download regressiontests. Tests can be run with ctest." no)
+if(REGRESSIONTEST_DOWNLOAD AND CMAKE_VERSION VERSION_LESS "2.8.2")
+    message(WARNING "REGRESSIONTEST_DOWNLOAD requires cmake >=2.8.2. Please update cmake or manually download the regressiontests.")
+    set(REGRESSIONTEST_DOWNLOAD FALSE CACHE BOOL 
+        "REGRESSIONTEST_DOWNLOAD not supported with cmake ${CMAKE_VERSION}" FORCE)
+endif()
+if(REGRESSIONTEST_DOWNLOAD)
+    if("${PROJECT_VERSION}" MATCHES "-dev")
+        set(REGRESSIONTEST_VERSION master)
+    else()
+        set(REGRESSIONTEST_VERSION ${PROJECT_VERSION})
+    endif()
+    set(REGRESSIONTEST_URL
+        http://gerrit.gromacs.org/download/regressiontests-${REGRESSIONTEST_VERSION}.tar.gz)
+    set(REGRESSIONTEST_FILE "${CMAKE_CURRENT_BINARY_DIR}/regressiontests.tgz")
+    message("Downloading: ${REGRESSIONTEST_URL}")
+    file(DOWNLOAD ${REGRESSIONTEST_URL} "${REGRESSIONTEST_FILE}" SHOW_PROGRESS STATUS status LOG log)
+    list(GET status 0 status_code)
+    list(GET status 1 status_string)
+    
+    if(NOT status_code EQUAL 0)
+        message(FATAL_ERROR "error: downloading '${REGRESSIONTEST_URL}' failed
+status_code: ${status_code}
+status_string: ${status_string}
+log: ${log}")
+    endif()
+
+    set(REGRESSIONTEST_PATH
+        "${CMAKE_CURRENT_BINARY_DIR}/regressiontests-${REGRESSIONTEST_VERSION}"
+        CACHE PATH "Path to auto-downloaded regressiontests" FORCE)
+    file(REMOVE_RECURSE "${REGRESSIONTEST_PATH}") #delete potential prior folder
+    execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${REGRESSIONTEST_FILE}"
+        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+    if(NOT EXISTS ${REGRESSIONTEST_PATH}/gmxtest.pl)
+        message(FATAL_ERROR "Download incorrect. Doesn't contain required gmxtest.pl")
+    endif()
+    set(REGRESSIONTEST_DOWNLOAD OFF CACHE BOOL "Tests already downloaded. Set to yes to download again" FORCE)
+endif()
+
+if(REGRESSIONTEST_PATH AND (GMX_BLUEGENE OR CMAKE_CROSSCOMPILING OR CMAKE_CONFIGURATION_TYPES))
+    #Bluegene requires us to compile both front-end and back-end binaries (single build is insufficient)
+    message(WARNING 
+        "With cross-compiling or multi-configuration generators (e.g. Visual Studio), running regressiontests from build system is not supported. Please run gmxtest.pl directly.")
+    set(REGRESSIONTEST_PATH OFF CACHE BOOL 
+        "With cross-compiling or multi-configuration generators, running regressiontests from build system is not supported." FORCE)
+endif()
+
+if(REGRESSIONTEST_PATH)
+    if(NOT EXISTS ${REGRESSIONTEST_PATH}/gmxtest.pl)
+        message(FATAL_ERROR
+            "REGRESSIONTEST_PATH invalid. The path needs to contain gmxtest.pl.")
+    endif()
+    if(GMX_DOUBLE)
+        list(APPEND ARGS -double)
+    endif()
+    if(GMX_LIB_MPI AND NOT MPIEXEC) #autodetection failed or CC=mpicc was used
+        message(WARNING
+            "Please set MPIEXEC. Otherwise mpirun is assumed for runnings tests.")
+    endif()
+    if(GMX_LIB_MPI)
+        set(GMX_TEST_NUMBER_PROCS 8 CACHE STRING "Number of processors used for testing")
+        mark_as_advanced(GMX_TEST_NUMBER_PROCS)
+        list(APPEND ARGS -np ${GMX_TEST_NUMBER_PROCS})
+        if(MPIEXEC)
+            list(APPEND ARGS -mpirun ${MPIEXEC})
+        endif()
+        #We should use MPIEXEC_NUMPROC_FLAG but gmxtest.pl doesn't let us pass it
+    endif()
+    if(GMX_BINARY_SUFFIX)
+        list(APPEND ARGS -suffix ${GMX_BINARY_SUFFIX})
+    endif()
+    #crosscompile is only used to disable checking whether binaries work
+    #given that we know they are there and that mdrun might not be exectuable
+    #(e.g. Cray) we enable it.
+    list(APPEND ARGS -crosscompile)
+
+    set(REGRESSIONTEST_EXTRA_ARGS "" CACHE STRING 
+        "Extra arguments passed to gmxtest")
+    mark_as_advanced(REGRESSIONTEST_EXTRA_ARGS)
+    list(APPEND ARGS ${REGRESSIONTEST_EXTRA_ARGS})
+
+    list(APPEND ARGS -noverbose -nosuffix)
+
+    if(GMX_NATIVE_WINDOWS)
+        set(PATH_SEPARATOR "\\;")
+        #replacing \ with / shouldn't be neccessary. But otherwise "..\bin\;c:\.."
+        #gets turned into "...\bin\\c:\.." don't know why and don't have a better
+        #workaround. This workaround doesn't hurt.
+        string(REPLACE "\\" "/" PATH "$ENV{PATH}")
+        #protect ; (don't treat as list)
+        string(REPLACE ";" "\\;" PATH "${PATH}")
+    else()
+        set(PATH_SEPARATOR ":")
+        set(PATH "$ENV{PATH}")
+    endif()
+
+    foreach(FOLDER kernel tools gmxlib mdlib) #lib folders might be needed for
+        #e.g. DLLs. For GMX paths native ("\") is needed for GMXLIB detection
+        file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/src/${FOLDER}" DIR)
+        set(PATH "${DIR}${PATH_SEPARATOR}${PATH}")
+    endforeach()
+
+    find_program(PERL_EXECUTABLE NAMES "perl")
+    mark_as_advanced(PERL_EXECUTABLE)
+
+    if (NOT PERL_EXECUTABLE)
+        message(FATAL_ERROR "Perl not found. Install perl, set PERL_EXECUTABLE to the perl location, or unset REGRESSIONTEST_PATH to disable testing.")
+    endif()
+
+    #currently not testing tools because they don't contain any useful tests
+    foreach(subtest simple complex kernel freeenergy pdb2gmx)
+        add_test(NAME regressiontests/${subtest}
+            #windows requires the command to be perl and not the script
+            COMMAND perl "${REGRESSIONTEST_PATH}/gmxtest.pl" ${subtest} ${ARGS})
+        set_tests_properties(regressiontests/${subtest} PROPERTIES
+            ENVIRONMENT "PATH=${PATH}")
+    endforeach()
+endif()