BASIS  version 1.2.3 (revision 2104)
basistest.ctest
Go to the documentation of this file.
00001 ##############################################################################
00002 # @file  basistest.ctest
00003 # @brief CTest script used to test BASIS projects.
00004 #
00005 # To display the help of this CTest script, run:
00006 # @code
00007 # ctest -S basistest.ctest,help
00008 # @endcode
00009 #
00010 # Copyright (c) 2011, 2012 University of Pennsylvania. All rights reserved.<br />
00011 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00012 #
00013 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00014 #
00015 # @ingroup Tools
00016 ##############################################################################
00017 
00018 if (POLICY CMP0007)
00019   cmake_policy(SET CMP0007 NEW)
00020 endif ()
00021 if (POLICY CMP0009)
00022   cmake_policy(SET CMP0009 NEW)
00023 endif ()
00024 
00025 # ============================================================================
00026 # constants - define at first
00027 # ============================================================================
00028 
00029 # names of options whose name will be added to CTEST_TEST_OPTIONS
00030 # instead of CTEST_CMAKE_OPTIONS
00031 set (KNOWN_CTEST_TEST_OPTIONS
00032   START
00033   END
00034   STRIDE
00035   INCLUDE
00036   INCLUDE_LABEL
00037   EXCLUDE
00038   EXCLUDE_LABEL
00039   PARALLEL_LEVEL
00040 )
00041 
00042 # ============================================================================
00043 # help
00044 # ============================================================================
00045 
00046 # ----------------------------------------------------------------------------
00047 ## @brief Print usage section of usage information and help screen.
00048 #
00049 # @param [in] ARGN Not used.
00050 #
00051 # @returns Nothing.
00052 
00053 function (print_usage)
00054   message ("Usage:
00055   ctest [ctest options] -S basistest.ctest[,option[=value]]*
00056 
00057   Note: No commas or equality signs are allowed inside of option values even
00058         if the value is enclosed by quotation marks.")
00059 endfunction ()
00060 
00061 # ----------------------------------------------------------------------------
00062 ## @brief Print options section of usage information and help screen.
00063 #
00064 # @param [in] ARGN Not used.
00065 #
00066 # @returns Nothing.
00067 
00068 function (print_options)
00069   message (
00070 "  <variable>=<value>     Passes -D<variable>=<value> on to CMake for the
00071                          configuration of the build tree if the variable
00072                          name is not named in the following.
00073 
00074                          The values of the following variables are passed on
00075                          to the proper CTest scripting commands:")
00076   foreach (V IN LISTS KNOWN_CTEST_TEST_OPTIONS)
00077     message ("                           - ${V}")
00078   endforeach ()
00079   message ("
00080   project=<project>      Name of the BASIS project to test. If not given, this
00081                          script skips the update step. In this case, the srcdir
00082                          and bindir options have to be given, or the current
00083                          working directory must be the root of an already
00084                          configured build tree.
00085   basedir=<path>         Base path of both source and binary directory.
00086                          Default: \"${HOME}/comp_space/testing\".
00087   srcdir=<path>          Source directory. This option is required if this script
00088                          is executed in a build directory which has not been
00089                          configured yet and if the project option was not specified.
00090                          If it is run in the root directory of an already configured
00091                          build tree, however, the value of this option is read from
00092                          the CMakeCache.txt file. Otherwise, if the project option
00093                          was specified, it is set to
00094                          \"<basedir>/<model>/<project>-source/<branch>/\".
00095   bindir=<path>          Binary directory (i.e., root of build tree).
00096                          This option defaults to the current working directory
00097                          if the project option was not specified. Otherwise,
00098                          it defaults to
00099                          \"<basedir>/<model>/<site>/<project>-build/<branch>/\".
00100   url=<url>              Base URL of the project's SVN repository.
00101                          Only used if the project option was specified.
00102                          Default: \"https://sbia-svn.uphs.upenn.edu/projects/<project>\".
00103   branch=<name>          Name of the SVN branch to test, e.g., \"tags/1.0.0\".
00104                          Default: \"trunk\".
00105   model=<model>          Name of the dashboard model, i.e., one of
00106                          \"Nightly\", \"Continuous\", and \"Experimental\".
00107                          Default: \"Experimental\".
00108   memcheck               Perform memory check. Requires valgrind.
00109                          No memory checks are performed by default.
00110   coverage               Perform coverage analysis. Requires gcov.
00111                          No coverage analysis is performed by default.
00112   install                Perform installation after successful test execution.
00113                          Set CMAKE_INSTALL_PREFIX to change the default installation
00114                          prefix used by the project (or CMake). Moreover, the
00115                          DESTDIR environment variable can be set to change the
00116                          root directory used for installations.
00117                          Note: Currently this script just executes \"make install\",
00118                                i.e., it only works with the CMake Makefile generator.
00119   doxygen[=<path>]       If specified, the API documentation is build
00120                          and the built HTML documentation copied to the
00121                          specified directory. If this option is given without
00122                          argument, the default web server location at SBIA is used,
00123                          i.e., \"/sbia/web/software/doxygen/<project>/<branch>\".
00124   nosubmit               Do not submit test results to the dashboard.
00125   shared-source          Specify that each test site should use the same copy of
00126                          the sources. By default, each test site uses its own copy.
00127   shared-build           Specify that each test site should use the same binary
00128                          directories. By default, each test site uses its own copy.
00129   common-site=<prefix>   Do not distinguish between different sites with a common
00130                          prefix in the name. Useful when the test jobs are executed
00131                          on a commonly configured cluster.
00132   site=<site>            Use given site name no matter on which actual machine
00133                          the test is executed.
00134   force-build            Force build even if no files were updated.
00135   force-test             Force test even if no files were updated.
00136   force                  Alias for options force-build, and force-test.
00137   tmpbin                 Delete binary directory on completion (also if not successful).
00138   help                   Prints help and exits without performing any test.
00139   helpshort              Prints short help and exits without performing any test.
00140   helpoptions            Prints help on options and exists without performing any test.
00141   version                Prints version information and exits.")
00142 endfunction ()
00143 
00144 # ----------------------------------------------------------------------------
00145 ## @brief Print contact section of usage information and help screen.
00146 #
00147 # @param [in] ARGN Not used.
00148 #
00149 # @returns Nothing.
00150 
00151 function (print_contact)
00152   message ("
00153 Contact:
00154   SBIA Group <sbia-software at uphs.upenn.edu>")
00155 endfunction ()
00156 
00157 # ----------------------------------------------------------------------------
00158 ## @brief Print help screen.
00159 #
00160 # @param [in] ARGN Not used.
00161 #
00162 # @returns Nothing.
00163 
00164 function (print_help)
00165   print_usage ()
00166   message ("
00167 Description:
00168   This CTest script is used at SBIA for nightly testing of software projects.
00169   Nightly tests are scheduled by a cron job, for example, every night once.
00170   Contrary to continous testing, does the nightly testing job not loop for
00171   a certain time of iterations and look for changes actively. The nightly
00172   testing job will only perform one test run and then exit.
00173 
00174   Note: Due to a bug in CTest 2.8.2, the first test will fail because of
00175         a missing CTestConfig.cmake file if the source tree is not checked
00176         out already. Therefore, the use of CTest 2.8.4 is recommened.
00177 
00178 Dashboard models:
00179   By default, the dashboard models \"Nightly\", \"Continuous\", and \"Experimental\"
00180   are configured as follows. These default configurations can be modified by
00181   supplying the available options listed below.
00182   
00183     Nightly        Performs all test stages even if the project has not been
00184                    updated since the last test run.
00185     Continuous     Performs an update of the project's working copy and
00186                    exits without submission of any test results if no files
00187                    were updated. Otherwise, it performs all test stages.
00188     Experimental   Performs all test stages even if the project has not been
00189                    updated since the last test run.
00190  
00191   Attention: For each model, only one test process may be running for each
00192              project on each site at one time.
00193              
00194 Build configurations:
00195   By default, the Release configuration is used. If the coverage option is
00196   given, the Coverage configuration is used. If the memcheck option is given
00197   instead, the MemCheck configuration is used. If both coverage and memcheck
00198   options are given, the Coverage configuration is chosen because it generally
00199   can also be used to perform memory checks, while the reported line numbers
00200   may be incorrect in this case, however. Use the CMAKE_BUILD_TYPE variable
00201   to explicitly specify a build configuration.")
00202   message ("
00203 Options:")
00204   print_options ()
00205   message ("
00206 Example:
00207   ctest -V -S basistest.ctest
00208 
00209     Run this command in the root directory of an already configured build tree
00210     to test this project.
00211 
00212   ctest -V -S basistest.ctest,coverage
00213 
00214     Run this command in the root directory of an already configured build tree
00215     to test this project and include coverage analysis results in the test report.
00216 
00217   ctest -V -S basistest.ctest,project=BASIS,model=Experimental,coverage,memcheck
00218 
00219     Performs an experimental nightly test of the main development branch of
00220     BASIS itself, including coverage analysis and memory checks.
00221     The -V option of ctest enables more verbose output of CTest.
00222     Even more verbose output can be requested using -VV.")
00223   print_contact ()
00224 endfunction ()
00225 
00226 # ----------------------------------------------------------------------------
00227 ## @brief Print usage information.
00228 #
00229 # @param [in] ARGN Not used.
00230 #
00231 # @returns Nothing.
00232 
00233 function (print_helpshort)
00234   print_usage ()
00235   message ("
00236 Options:")
00237   print_options ()
00238   print_contact ()
00239 endfunction ()
00240 
00241 # ----------------------------------------------------------------------------
00242 ## @brief Print version information.
00243 #
00244 # @param [in] ARGN Not used.
00245 #
00246 # @returns Nothing.
00247 
00248 function (print_version)
00249   set (VERSION_INFO "version 1.2.3")
00250   if (2104 GREATER 0) # project revision > 0
00251     set (VERSION_INFO "${VERSION_INFO} (revision 2104)")
00252   endif ()
00253   message ("CTest script basistest.ctest (BASIS) ${VERSION_INFO}")
00254   message ("Copyright (c) 2011 University of Pennsylvania. All rights reserved.")
00255   message ("See COPYING file or https://www.rad.upenn.edu/sbia/software/license.html.")
00256 endfunction ()
00257 
00258 # ============================================================================
00259 # helpers
00260 # ============================================================================
00261 
00262 # ----------------------------------------------------------------------------
00263 ## @brief Read value from CMake cache.
00264 #
00265 # @param [in, out] VAR  Name of CMake variable.
00266 # @param [in]      ARGN Not used.
00267 #
00268 # @returns Sets @p VAR to the value of the cached variable @p VAR.
00269 function (read_cmake_cache_value VAR)
00270   file (STRINGS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" ENTRY REGEX "${VAR}:.*=(.*)")
00271   string (REGEX REPLACE "${VAR}:.*=(.*)" "\\1" VALUE "${ENTRY}")
00272   set (${VAR} "${VALUE}" PARENT_SCOPE)
00273 endfunction ()
00274 
00275 # ----------------------------------------------------------------------------
00276 ## @brief Adjust information attached to test results using CMakeCache.txt.
00277 #
00278 # @param [in] ARGN List of XML test report files without directory path.
00279 #                  If omitted, this function globs for all XML files in
00280 #                  the <tt>Testing/&lt;tag&gt;/</tt> directory.
00281 function (update_metadata)
00282   # get compiler information from CMake cache
00283   if (EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
00284     if (WIN32)
00285       set (NAME_COMPONENT "NAME_WE")
00286     else ()
00287       set (NAME_COMPONENT "NAME")
00288     endif ()
00289     if (UNIX OR BORLAND)
00290       read_cmake_cache_value (CMAKE_CXX_COMPILER)
00291       set (COMPILER "${CMAKE_CXX_COMPILER}")
00292       get_filename_component (COMPILER_NAME "${CMAKE_CXX_COMPILER}" ${NAME_COMPONENT})
00293     else ()
00294       read_cmake_cache_value (CMAKE_BUILD_TOOL)
00295       set (COMPILER "${CMAKE_BUILD_TOOL}")
00296       get_filename_component (COMPILER_NAME "${CMAKE_BUILD_TOOL}" ${NAME_COMPONENT})
00297     endif ()
00298     if (COMPILER_NAME MATCHES "msdev")
00299       set (COMPILER_NAME "vs60")
00300     elseif (COMPILER_NAME MATCHES "devenv")
00301       read_cmake_cache_value (CMAKE_GENERATOR)
00302       string (REGEX REPLACE "Visual Studio ([0-9][0-9]?)($|.*)" "\\1" NUMBER "${CMAKE_GENERATOR}") 
00303       if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio 7 .NET 2003")
00304         set (COMPILER_NAME "vs71")
00305       else ()
00306         set (COMPILER_NAME "vs${NUMBER}")
00307       endif ()
00308     endif ()
00309   else ()
00310     set (COMPILER      "unknown")
00311     set (COMPILER_NAME "unknown")
00312   endif ()
00313   # replace COMPILER_NAME in build name
00314   string (CONFIGURE "${CTEST_BUILD_NAME}" BUILDNAME @ONLY)
00315   message ("Change build name to ${BUILDNAME}")
00316   # get tag, i.e., subdirectory name required by update_metadata()
00317   if (EXISTS "${CTEST_BINARY_DIRECTORY}/Testing/TAG")
00318     file (STRINGS "${CTEST_BINARY_DIRECTORY}/Testing/TAG" TAG LIMIT_COUNT 1)
00319   else ()
00320     set (TAG ".")
00321   endif ()
00322   # modify submission files
00323   if (NOT ARGV)
00324     file (
00325       GLOB_RECURSE
00326         ARGV
00327       RELATIVE
00328         "${CTEST_BINARY_DIRECTORY}/Testing/${TAG}"
00329       "${CTEST_BINARY_DIRECTORY}/Testing/${TAG}/*.xml"
00330     )
00331   endif ()
00332   foreach (SUBMISSION_FILE IN LISTS ARGV)
00333     set (SUBMISSION_FILE "${CTEST_BINARY_DIRECTORY}/Testing/${TAG}/${SUBMISSION_FILE}")
00334     # read submission file
00335     file (READ "${SUBMISSION_FILE}" XML)
00336     # set compiler name if necessary
00337     string (REPLACE "CompilerName=\"\"" "CompilerName=\"${COMPILER}\"" XML "${XML}")
00338     string (REPLACE "<CompilerName></CompilerName>" "<CompilerName>${COMPILER}</CompilerName>" XML "${XML}")
00339     # replace intermediate build name
00340     string (REPLACE "BuildName=\"\"" "BuildName=\"${BUILDNAME}\"" XML "${XML}")
00341     string (REPLACE "<BuildName></BuildName>" "<BuildName>${BUILDNAME}</BuildName>" XML "${XML}")
00342     string (REPLACE "BuildName=\"${CTEST_BUILD_NAME}\"" "BuildName=\"${BUILDNAME}\"" XML "${XML}")
00343     string (REPLACE "<BuildName>${CTEST_BUILD_NAME}</BuildName>" "<BuildName>${BUILDNAME}</BuildName>" XML "${XML}")
00344     # write modified submission file
00345     file (WRITE "${SUBMISSION_FILE}" "${XML}")
00346   endforeach ()
00347 endfunction ()
00348 
00349 # ============================================================================
00350 # settings
00351 # ============================================================================
00352 
00353 set (MANUAL_MODE FALSE) # whether this script is running in manual mode, i.e.,
00354                         # executed in the build tree of an existing project
00355                         # instead of run by a cron job
00356 
00357 # ----------------------------------------------------------------------------
00358 # general
00359 set (CTEST_BASE_DIRECTORY   "$ENV{HOME}/comp_space/testing")
00360 set (CTEST_SOURCE_DIRECTORY "")
00361 set (CTEST_BINARY_DIRECTORY "")
00362 set (CTEST_MODEL            "Experimental")
00363 set (SHARED_SOURCE          FALSE)
00364 set (SHARED_BUILD           FALSE)
00365 set (SUBMIT_RESULTS         TRUE)
00366 set (COMMON_SITE_PREFIXES)
00367 
00368 set (CTEST_EXTRA_SUBMIT_FILES) # additional files for submission to the dashboard
00369 
00370 # ----------------------------------------------------------------------------
00371 # project attributes
00372 set (CTEST_PROJECT_NAME "")
00373 set (CTEST_SVN_URL      "https://sbia-svn.uphs.upenn.edu/projects/\@CTEST_PROJECT_NAME\@")
00374 set (CTEST_SVN_BRANCH   "trunk")
00375 
00376 # ----------------------------------------------------------------------------
00377 # build configuration
00378 set (CTEST_CMAKE_GENERATOR "Unix Makefiles") # CMake generator
00379 set (CTEST_BUILD_TYPE      "")               # build type/configuration
00380 set (CTEST_COMPILER_FLAGS  "")               # additional compiler flags
00381 set (CTEST_LINKER_FLAGS    "")               # additional linker flags
00382 set (CTEST_CMAKE_OPTIONS)
00383 set (WITH_MEMCHECK         FALSE)            # enable/disable memory checks
00384 set (WITH_COVERAGE         FALSE)            # enable/disable coverage analysis
00385 set (CTEST_MEMORYCHECK_SUPPRESSIONS_FILE)    # memory checks suppressions
00386 
00387 # ----------------------------------------------------------------------------
00388 # test execution
00389 set (CTEST_TEST_OPTIONS)
00390 
00391 set (FORCE_BUILD    FALSE)
00392 set (FORCE_TEST     FALSE)
00393 
00394 # ----------------------------------------------------------------------------
00395 # installation directories
00396 
00397 # install project files after successful test execution
00398 set (WITH_INSTALL FALSE)
00399 # output directory for built Doxygen documentation
00400 set (INSTALL_DOXYGEN_DIR)
00401 
00402 # ============================================================================
00403 # options
00404 # ============================================================================
00405 
00406 macro (set_option VAR)
00407   if (${ARGC} EQUAL 1)
00408     if (VALUE)
00409       set (${VAR} "${VALUE}")
00410     else ()
00411       set (FAILURE TRUE)
00412     endif ()
00413   else ()
00414     if (VALUE)
00415       set (FAILURE TRUE)
00416     else ()
00417       set (${VAR} "${ARGN}")
00418     endif ()
00419   endif ()
00420 endmacro ()
00421 
00422 macro (append_option VAR)
00423   if (VALUE)
00424     list (APPEND ${VAR} "${VALUE}")
00425   else ()
00426     set (FAILURE TRUE)
00427   endif ()
00428 endmacro ()
00429 
00430 string (REPLACE "," ";" ARGV "${CTEST_SCRIPT_ARG}")
00431 foreach (ARG ${ARGV})
00432   set (FAILURE FALSE)
00433   set (OPTION "")
00434   set (VALUE  "")
00435 
00436   string (REPLACE "=" ";" PARTS "${ARG}")
00437   list (LENGTH PARTS LEN)
00438 
00439   if (LEN EQUAL 1)
00440     set (OPTION "${PARTS}")
00441   elseif (LEN EQUAL 2)
00442     list (GET PARTS 0 OPTION)
00443     list (GET PARTS 1 VALUE)
00444   endif ()
00445  
00446   if (OPTION)
00447     if (${OPTION} STREQUAL "project")
00448       set_option (CTEST_PROJECT_NAME)
00449     elseif (${OPTION} STREQUAL "model")
00450       set_option (CTEST_MODEL)
00451     elseif (${OPTION} STREQUAL "basedir")
00452       set_option (CTEST_BASE_DIRECTORY)
00453     elseif (${OPTION} STREQUAL "srcdir")
00454       set_option (CTEST_SOURCE_DIRECTORY)
00455     elseif (${OPTION} STREQUAL "bindir")
00456       set_option (CTEST_BINARY_DIRECTORY)
00457     elseif (${OPTION} STREQUAL "url")
00458       set_option (CTEST_SVN_URL)
00459     elseif (${OPTION} STREQUAL "branch")
00460       set_option (CTEST_SVN_BRANCH)
00461     elseif (${OPTION} STREQUAL "memcheck")
00462       set_option (WITH_MEMCHECK TRUE)
00463     elseif (${OPTION} STREQUAL "coverage")
00464       set_option (WITH_COVERAGE TRUE)
00465     elseif (${OPTION} STREQUAL "tmpbin")
00466       set_option (TMPBIN TRUE)
00467     elseif (${OPTION} STREQUAL "install")
00468       set_option (WITH_INSTALL TRUE)
00469     elseif (${OPTION} STREQUAL "doxygen")
00470       if (VALUE)
00471         set_option (INSTALL_DOXYGEN_DIR)
00472       else ()
00473         set (INSTALL_DOXYGEN_DIR "/sbia/web/software/doxygen/\@CTEST_PROJECT_NAME_LOWER\@/\@CTEST_SVN_BRANCH\@")
00474       endif ()
00475     elseif (${OPTION} STREQUAL "shared-source")
00476       set_option (SHARED_SOURCE TRUE)
00477     elseif (${OPTION} STREQUAL "shared-build")
00478       set_option (SHARED_BUILD TRUE)
00479     elseif (${OPTION} STREQUAL "submit")
00480       set_option (SUBMIT_RESULTS TRUE)
00481     elseif (${OPTION} STREQUAL "nosubmit")
00482       set_option (SUBMIT_RESULTS FALSE)
00483     elseif (${OPTION} STREQUAL "common-site")
00484       append_option (COMMON_SITE_PREFIXES)
00485     elseif (${OPTION} STREQUAL "site")
00486         set_option (CTEST_SITE)
00487     elseif (${OPTION} STREQUAL "force")
00488       set_option (FORCE_BUILD TRUE)
00489       set_option (FORCE_TEST  TRUE)
00490     elseif (${OPTION} STREQUAL "force-build")
00491       set_option (FORCE_BUILD TRUE)
00492     elseif (${OPTION} STREQUAL "force-test")
00493       set_option (FORCE_TEST TRUE)
00494     elseif (${OPTION} STREQUAL "version")
00495       print_version ()
00496       return ()
00497     elseif (${OPTION} STREQUAL "help")
00498       print_help ()
00499       return ()
00500     elseif (${OPTION} STREQUAL "helpshort")
00501       print_helpshort ()
00502       return ()
00503     elseif (${OPTION} STREQUAL "helpoptions")
00504       print_options ()
00505       return ()
00506     else ()
00507       if (NOT VALUE)
00508         set (FAILURE TRUE)
00509       else ()
00510         string (TOUPPER "${OPTION}" OPTION_UPPER)
00511         list (FIND KNOWN_CTEST_TEST_OPTIONS "${OPTION_UPPER}" IDX)
00512         if (IDX EQUAL -1)
00513           if (OPTION MATCHES "^CMAKE_BUILD_TYPE$")
00514             set (CTEST_BUILD_TYPE "${VALUE}")
00515           else ()
00516             set (CTEST_CMAKE_OPTIONS "${CTEST_CMAKE_OPTIONS} \"-D${OPTION}=${VALUE}\"")
00517           endif ()
00518         else ()
00519           list (APPEND CTEST_TEST_OPTIONS "${OPTION_UPPER}" "${VALUE}")
00520         endif ()
00521       endif ()
00522     endif ()
00523   else ()
00524     set (FAILURE TRUE)
00525   endif ()
00526 
00527   if (FAILURE)
00528     message (FATAL_ERROR "Invalid options: ${CTEST_SCRIPT_ARG}
00529 Failed to parse argument \"${ARG}\" (option: ${OPTION}, value: ${VALUE})")
00530   endif ()
00531 endforeach ()
00532 
00533 if (NOT CTEST_PROJECT_NAME)
00534   set (MANUAL_MODE TRUE)
00535   # automatically set binary directory if not specified
00536   if (NOT CTEST_BINARY_DIRECTORY)
00537     if (UNIX)
00538       find_program (PWD pwd)
00539     else ()
00540       find_program (PWD cd)
00541     endif ()
00542     execute_process (
00543       COMMAND "${PWD}"
00544       RESULT_VARIABLE RT
00545       OUTPUT_VARIABLE CWD
00546       OUTPUT_STRIP_TRAILING_WHITESPACE
00547     )
00548     if (RT EQUAL 0)
00549       set (CTEST_BINARY_DIRECTORY "${CWD}")
00550     else ()
00551       message (FATAL_ERROR "Failed to get current working directory! Try using the bindir option instead.")
00552     endif ()
00553   endif ()
00554   # set project name from CMake cache
00555   if (EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
00556     read_cmake_cache_value (CMAKE_PROJECT_NAME)
00557     if (NOT CMAKE_PROJECT_NAME)
00558       message (FATAL_ERROR "Failed to read project name from ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt!")
00559     endif ()
00560     set (CTEST_PROJECT_NAME "${CMAKE_PROJECT_NAME}")
00561   endif ()
00562   # automatically set source directory if not specified
00563   if (NOT CTEST_SOURCE_DIRECTORY)
00564     if (NOT EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
00565       message (FATAL_ERROR "Missing CMakeCache.txt file! Either specify source directory using the srcdir option or initialize the build tree.")
00566     endif ()
00567     read_cmake_cache_value (${CTEST_PROJECT_NAME}_SOURCE_DIR)
00568     if (NOT ${CTEST_PROJECT_NAME}_SOURCE_DIR)
00569       message (FATAL_ERROR "Failed to read source directory from ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt!")
00570     endif ()
00571     set (CTEST_SOURCE_DIRECTORY "${${CTEST_PROJECT_NAME}_SOURCE_DIR}")
00572   endif ()
00573 endif ()
00574 
00575 if (NOT CTEST_BINARY_DIRECTORY)
00576   set (CTEST_BINARY_DIRECTORY "${CTEST_SOURCE_DIRECTORY}")
00577 endif ()
00578 
00579 string (TOLOWER "${CTEST_PROJECT_NAME}" CTEST_PROJECT_NAME_LOWER)
00580 string (TOUPPER "${CTEST_PROJECT_NAME}" CTEST_PROJECT_NAME_UPPER)
00581 
00582 if (CTEST_MODEL MATCHES "Nightly|Experimental")
00583   set (FORCE_BUILD TRUE)
00584   set (FORCE_TEST  TRUE)
00585 endif ()
00586 
00587 # ============================================================================
00588 # initialization
00589 # ============================================================================
00590 
00591 # ----------------------------------------------------------------------------
00592 # build type
00593 if (NOT CTEST_BUILD_TYPE)
00594   if (WITH_COVERAGE OR WITH_MEMCHECK)
00595     set (CTEST_BUILD_TYPE "Debug")
00596   else ()
00597     set (CTEST_BUILD_TYPE "Release")
00598   endif ()
00599 endif ()
00600 
00601 # ----------------------------------------------------------------------------
00602 # site information
00603 if (NOT CTEST_SITE)
00604   site_name (CTEST_SITE)
00605 
00606   # remove ".local" or ".uphs.upenn.edu" suffix from site name
00607   string (REGEX REPLACE "\\.local$|\\.uphs\\.upenn\\.edu$" "" CTEST_SITE "${CTEST_SITE}")
00608 
00609   # common site name
00610   if (COMMON_SITE_PREFIXES)
00611     foreach (P ${COMMON_SITE_PREFIXES})
00612       if (CTEST_SITE MATCHES "^${P}")
00613         set (CTEST_SITE "${P}")
00614         break ()
00615       endif ()
00616     endforeach ()
00617   endif ()
00618 endif ()
00619 
00620 # ----------------------------------------------------------------------------
00621 # build information
00622 
00623 # Note: The  pattern in the build name as written to the .xml files
00624 #       will be replaced by this script before the submission once the used
00625 #       compiler is known from the CMake cache.
00626 set (CTEST_BUILD_NAME   "${CMAKE_SYSTEM_NAME}-\@COMPILER_NAME\@")
00627 if (WITH_COVERAGE AND WITH_MEMCHECK)
00628   set (CTEST_BUILD_NAME "${CTEST_BUILD_NAME} (Coverage & MemCheck)")
00629 elseif (WITH_COVERAGE)
00630   set (CTEST_BUILD_NAME "${CTEST_BUILD_NAME} (Coverage)")
00631 elseif (WITH_MEMCHECK)
00632   set (CTEST_BUILD_NAME "${CTEST_BUILD_NAME} (MemCheck)")
00633 endif ()
00634 
00635 # ----------------------------------------------------------------------------
00636 # directories
00637 if (NOT MANUAL_MODE)
00638   set (CTEST_BUILD_SUBDIR)
00639   if (WITH_COVERAGE AND WITH_MEMCHECK)
00640     set (CTEST_PREFIX "CoverageAndMemCheck")
00641   elseif (WITH_COVERAGE)
00642     set (CTEST_PREFIX "Coverage")
00643   elseif (WITH_MEMCHECK)
00644     set (CTEST_PREFIX "MemCheck")
00645   else ()
00646     set (CTEST_PREFIX "${CTEST_MODEL}")
00647     if (CTEST_BUILD_TYPE)
00648       set (CTEST_BUILD_SUBDIR "${CTEST_BUILD_TYPE}")
00649     else ()
00650       set (CTEST_BUILD_SUBDIR "Default")
00651     endif ()
00652   endif ()
00653   if (NOT CTEST_SOURCE_DIRECTORY)
00654     if (SHARED_SOURCE)
00655       set (CTEST_SOURCE_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_PROJECT_NAME}-source/${CTEST_SVN_BRANCH}")
00656     else ()
00657       set (CTEST_SOURCE_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_SITE}/${CTEST_PROJECT_NAME}-source/${CTEST_SVN_BRANCH}")
00658     endif ()
00659   endif ()
00660   if (NOT CTEST_BINARY_DIRECTORY)
00661     if (SHARED_BUILD)
00662       set (CTEST_BINARY_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_PROJECT_NAME}-build/${CTEST_SVN_BRANCH}/${CTEST_BUILD_SUBDIR}")
00663     else ()
00664       set (CTEST_BINARY_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_SITE}/${CTEST_PROJECT_NAME}-build/${CTEST_SVN_BRANCH}/${CTEST_BUILD_SUBDIR}")
00665     endif ()
00666   endif ()
00667 endif ()
00668 string (REGEX REPLACE "/$" "" CTEST_BINARY_DIRECTORY "${CTEST_BINARY_DIRECTORY}")
00669 string (REGEX REPLACE "/$" "" CTEST_SOURCE_DIRECTORY "${CTEST_SOURCE_DIRECTORY}")
00670 
00671 string (CONFIGURE "${INSTALL_DOXYGEN_DIR}" INSTALL_DOXYGEN_DIR)
00672 
00673 if (MANUAL_MODE)
00674   set (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY FALSE)
00675 else ()
00676   set (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY TRUE)
00677 endif ()
00678 
00679 # ----------------------------------------------------------------------------
00680 # checkout / update
00681 find_program (
00682   CTEST_SVN_COMMAND
00683   NAMES basistest-svn
00684   HINTS "${CMAKE_CURRENT_LIST_DIR}/../../bin"
00685 )
00686 find_program (CTEST_SVN_COMMAND NAMES svn)
00687 
00688 if (NOT CTEST_SVN_COMMAND)
00689   message (FATAL_ERROR "Could not find \"basistest-svn\" or \"svn\" command!")
00690 endif ()
00691 
00692 string (CONFIGURE "${CTEST_SVN_URL}" CTEST_SVN_URL @ONLY)
00693 
00694 if (NOT MANUAL_MODE AND NOT EXISTS "${CTEST_SOURCE_DIRECTORY}/.svn")
00695   file (MAKE_DIRECTORY "${CTEST_SOURCE_DIRECTORY}")
00696   set (CTEST_CHECKOUT_COMMAND "${CTEST_SVN_COMMAND} co \"${CTEST_SVN_URL}/${CTEST_SVN_BRANCH}\" ${CTEST_SOURCE_DIRECTORY}")
00697 endif ()
00698 set (CTEST_UPDATE_COMMAND "${CTEST_SVN_COMMAND}")
00699 
00700 # ----------------------------------------------------------------------------
00701 # coverage analysis
00702 if (WITH_COVERAGE)
00703   find_program (CTEST_COVERAGE_COMMAND NAMES gcov)
00704   if (NOT CTEST_COVERAGE_COMMAND)
00705     message (FATAL_ERROR "Could not find gcov! Only gcc and gcov supported to perform coverage analysis.")
00706   endif ()
00707   set (CTEST_COMPILER_FLAGS "${CTEST_COMPILER_FLAGS} -O0 -fprofile-arcs -ftest-coverage")
00708   set (CTEST_LINKER_FLAGS "${CTEST_LINKER_FLAGS} -fprofile-arcs")
00709 endif ()
00710 
00711 # ----------------------------------------------------------------------------
00712 # memory check
00713 if (WITH_MEMCHECK)
00714   # TODO Consider switching to AddressSanitizer instead, which requires the
00715   #      use of the clang compiler, however, with the compiler flag
00716   #      -faddress-sanitizer.
00717   find_program (CTEST_MEMORYCHECK_COMMAND NAMES valgrind)
00718   if (NOT CTEST_MEMORYCHECK_COMMAND)
00719     message (FATAL_ERROR "Could not find valgrind! Only valgrind supported as memory error detector.")
00720   endif ()
00721   if (NOT WITH_COVERAGE)
00722     set (CTEST_COMPILER_FLAGS "${CTEST_COMPILER_FLAGS} -O1")
00723   endif ()
00724   set (CTEST_COMPILER_FLAGS "${CTEST_COMPILER_FLAGS} -fno-omit-frame-pointer")
00725   if (CTEST_MEMORYCHECK_SUPPRESSIONS_FILE)
00726     if (NOT IS_ABSOLUTE "${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE}")
00727       set (
00728         CTEST_MEMORYCHECK_SUPPRESSIONS_FILE
00729           "${CTEST_SOURCE_DIRECTORY}/${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE}"
00730       )
00731     endif ()
00732     if (NOT EXISTS "${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE}")
00733       message ("Memory check suppressions file ${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE} not found!")
00734     endif ()
00735   endif ()
00736 endif ()
00737 
00738 # ----------------------------------------------------------------------------
00739 # configuration / build
00740 set (CTEST_CONFIGURE_COMMAND "\"${CMAKE_COMMAND}\"")
00741 if (CTEST_BUILD_TYPE)
00742   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=${CTEST_BUILD_TYPE}")
00743 endif ()
00744 if (CTEST_COMPILER_FLAGS)
00745   string (STRIP "${CTEST_COMPILER_FLAGS}" CTEST_COMPILER_FLAGS)
00746   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_C_FLAGS:STRING=${CTEST_COMPILER_FLAGS}\"")
00747   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_CXX_FLAGS:STRING=${CTEST_COMPILER_FLAGS}\"")
00748 endif ()
00749 if (CTEST_LINKER_FLAGS)
00750   string (STRIP "${CTEST_LINKER_FLAGS}" CTEST_LINKER_FLAGS)
00751   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_EXE_LINKER_FLAGS:STRING=${CTEST_LINKER_FLAGS}\"")
00752   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_MODULE_LINKER_FLAGS:STRING=${CTEST_LINKER_FLAGS}\"")
00753   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CTEST_LINKER_FLAGS}\"")
00754 endif ()
00755 set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DBUILD_TESTING:BOOL=ON")
00756 if (INSTALL_DOXYGEN_DIR)
00757   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DBUILD_DOCUMENTATION:BOOL=ON")
00758 else ()
00759   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DBUILD_DOCUMENTATION:BOOL=OFF")
00760 endif ()
00761 if (CTEST_CMAKE_OPTIONS)
00762   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} ${CTEST_CMAKE_OPTIONS}")
00763 endif ()
00764 set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-G${CTEST_CMAKE_GENERATOR}\"")
00765 set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"${CTEST_SOURCE_DIRECTORY}\"")
00766 
00767 # ============================================================================
00768 # testing
00769 # ============================================================================
00770 
00771 set (CONFIGURE_RESULT 1)   # whether configuration was successful (0 if it was)
00772 set (BUILD_RESULT     1)   # whether build was successful (0 if it was)
00773 
00774 # ----------------------------------------------------------------------------
00775 # in manual mode, preserve CMake cache to be able to restore it later
00776 if (MANUAL_MODE AND EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
00777   execute_process (
00778     COMMAND "${CMAKE_COMMAND}" -E copy
00779         "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt"
00780         "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak"
00781   )
00782 endif ()
00783 
00784 # ----------------------------------------------------------------------------
00785 # empty the binary directory
00786 if (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY)
00787   ctest_empty_binary_directory ("${CTEST_BINARY_DIRECTORY}")
00788 endif ()
00789 
00790 # ----------------------------------------------------------------------------
00791 # start a new test run
00792 ctest_start ("${CTEST_MODEL}")
00793 
00794 # ----------------------------------------------------------------------------
00795 # update working copy
00796 set (UPDATED_FILES TRUE)
00797 
00798 if (NOT MANUAL_MODE)
00799   ctest_update (RETURN_VALUE NUM_FILES)
00800 
00801   if (NOT CTEST_CHECKOUT_COMMAND AND NUM_FILES EQUAL 0)
00802     set (UPDATED_FILES FALSE)
00803     if (NOT FORCE_BUILD)
00804       set (SUBMIT_RESULTS FALSE)
00805     endif ()
00806   endif ()
00807 endif ()
00808 
00809 # perform other test stages and submit results only if required
00810 if (FORCE_BUILD OR UPDATED_FILES)
00811 
00812   # --------------------------------------------------------------------------
00813   # configure build
00814 
00815   # Note: Also in manual mode to enforce the selected build configuration!
00816   ctest_configure (RETURN_VALUE CONFIGURE_RESULT)
00817 
00818   if (CONFIGURE_RESULT EQUAL 0)
00819     ctest_read_custom_files ("${CTEST_BINARY_DIRECTORY}")
00820   endif ()
00821 
00822   # --------------------------------------------------------------------------
00823   # build project
00824   if (CONFIGURE_RESULT EQUAL 0)
00825     ctest_build (NUMBER_ERRORS NUMBER_OF_ERRORS RETURN_VALUE BUILD_RESULT)
00826     if (NUMBER_OF_ERRORS GREATER 0)
00827       set (BUILD_RESULT "${NUMBER_OF_ERRORS}")
00828     endif ()
00829   endif ()
00830 
00831   # --------------------------------------------------------------------------
00832   # build and install API documentation
00833   if (BUILD_RESULT EQUAL 0 AND INSTALL_DOXYGEN_DIR)
00834     if (EXISTS "${CTEST_BINARY_DIRECTORY}/doc/api/html")
00835       if (EXISTS "${INSTALL_DOXYGEN_DIR}/html")
00836         file (REMOVE_RECURSE "${INSTALL_DOXYGEN_DIR}/html")
00837       endif ()
00838       execute_process (
00839         COMMAND "${CMAKE_COMMAND}" "-E" "copy_directory"
00840                     "${CTEST_BINARY_DIRECTORY}/doc/api/html"
00841                     "${INSTALL_DOXYGEN_DIR}/html"
00842         WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}"
00843         RESULT_VARIABLE RT
00844       )
00845       if (RT EQUAL 0)
00846         message ("Copied API documentation to ${INSTALL_DOXYGEN_DIR}.")
00847       else ()
00848         message ("Failed to install API documentation to ${INSTALL_DOXYGEN_DIR}!")
00849       endif ()
00850     else ()
00851       message ("Directory ${CTEST_BINARY_DIRECTORY}/doc/api/html/ does not exist.")
00852       message ("Skipped installation of API documentation.")
00853     endif ()
00854   endif ()
00855 
00856   # perform tests only if required
00857   if (BUILD_RESULT EQUAL 0 AND (FORCE_TEST OR UPDATED_FILES))
00858 
00859     # ------------------------------------------------------------------------
00860     # run tests
00861     if (WITH_COVERAGE OR NOT WITH_MEMCHECK)
00862       ctest_test (${CTEST_TEST_OPTIONS} RETURN_VALUE TEST_RESULT)
00863     endif ()
00864 
00865     # --------------------------------------------------------------------------
00866     # perform coverage analysis
00867     if (WITH_COVERAGE AND CTEST_COVERAGE_COMMAND)
00868       ctest_coverage ()
00869     endif ()
00870 
00871     # --------------------------------------------------------------------------
00872     # perform memory checks
00873     if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
00874       ctest_memcheck (${CTEST_TEST_OPTIONS})
00875     endif ()
00876 
00877     # ---------------------------------------------------------------------------
00878     # perform installation
00879     if (WITH_INSTALL AND TEST_RESULT EQUAL 0)
00880       message ("Install project files")
00881       # First deinstall previously installed files to ensure that obsolete
00882       # files are removed. These obsolete files could otherwise be used by
00883       # other projects and the test would not reveal that the projects are
00884       # actually no longer compatible.
00885       read_cmake_cache_value (CMAKE_INSTALL_PREFIX)
00886       set (UNINSTALLER "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/uninstall_${CTEST_PROJECT_NAME_LOWER}")
00887       if (EXISTS "${UNINSTALLER}")
00888         execute_process (
00889           COMMAND           "${UNINSTALLER}"
00890           WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}"
00891           TIMEOUT           1800 # 30 minutes
00892           RESULT_VARIABLE   UNINSTALL_RESULT
00893           OUTPUT_FILE       "${CTEST_BINARY_DIRECTORY}/install.log"
00894           ERROR_FILE        "${CTEST_BINARY_DIRECTORY}/install.log"
00895         )
00896       else ()
00897         execute_process (
00898           COMMAND           make uninstall
00899           WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}"
00900           TIMEOUT           1800 # 30 minutes
00901           RESULT_VARIABLE   UNINSTALL_RESULT
00902           OUTPUT_FILE       "${CTEST_BINARY_DIRECTORY}/install.log"
00903           ERROR_FILE        "${CTEST_BINARY_DIRECTORY}/install.log"
00904         )
00905       endif ()
00906       # install new files
00907       execute_process (
00908         COMMAND           make install
00909         WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}"
00910         TIMEOUT           1800 # 30 minutes
00911         RESULT_VARIABLE   INSTALL_RESULT
00912         OUTPUT_FILE       "${CTEST_BINARY_DIRECTORY}/install.log"
00913         ERROR_FILE        "${CTEST_BINARY_DIRECTORY}/install.log"
00914       )
00915       # submit log file in case of errors to dashboard
00916       if (NOT UNINSTALL_RESULT EQUAL 0 OR NOT INSTALL_RESULT EQUAL 0)
00917         list (APPEND CTEST_EXTRA_SUBMIT_FILES "${CTEST_BINARY_DIRECTORY}/install.log")
00918       endif ()
00919     endif ()
00920 
00921   endif ()
00922 
00923 endif ()
00924 
00925 # -----------------------------------------------------------------------------
00926 # adjust test result meta-data - even if these will not be submitted yet
00927 update_metadata ()
00928 
00929 # -----------------------------------------------------------------------------
00930 # submit results
00931 if (SUBMIT_RESULTS)
00932   ctest_submit ()
00933 endif ()
00934 
00935 # -----------------------------------------------------------------------------
00936 # clean up
00937 if (TMPBIN)
00938   file (REMOVE_RECURSE "${CTEST_BINARY_DIRECTORY}")
00939 else ()
00940   if (MANUAL_MODE AND EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak")
00941     execute_process (
00942       COMMAND "${CMAKE_COMMAND}" -E compare_files 
00943           "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt"
00944           "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak"
00945       RESULT_VARIABLE RT
00946       OUTPUT_QUIET
00947       ERROR_QUIET
00948     )
00949     if (RT EQUAL 0)
00950       file (REMOVE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak")
00951     else ()
00952       message ("Restoring build system configuration...")
00953       file (
00954         RENAME "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak"
00955                "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt"
00956       )
00957       execute_process (
00958         COMMAND "${CMAKE_COMMAND}" "${CTEST_BINARY_DIRECTORY}"
00959         OUTPUT_QUIET
00960         RESULT_VARIABLE RT
00961       )
00962       if (RT EQUAL 0)
00963         message ("Restoring build system configuration... - done")
00964       else ()
00965         message ("Restoring build system configuration... - failed")
00966       endif ()
00967     endif ()
00968   endif ()
00969 endif ()