basistest.ctest
Go to the documentation of this file.
1 # ============================================================================
2 # Copyright (c) 2011-2012 University of Pennsylvania
3 # Copyright (c) 2013-2016 Andreas Schuh
4 # All rights reserved.
5 #
6 # See COPYING file for license information or visit
7 # https://cmake-basis.github.io/download.html#license
8 # ============================================================================
9 
10 ##############################################################################
11 # @file basistest.ctest
12 # @brief CTest script used to test BASIS projects.
13 #
14 # To display the help of this CTest script, run:
15 # @code
16 # ctest -S basistest.ctest,help
17 # @endcode
18 #
19 # @ingroup Tools
20 ##############################################################################
21 
22 if (POLICY CMP0007)
23  cmake_policy(SET CMP0007 NEW)
24 endif ()
25 if (POLICY CMP0009)
26  cmake_policy(SET CMP0009 NEW)
27 endif ()
28 
29 # ============================================================================
30 # constants - define at first
31 # ============================================================================
32 
33 # names of options whose name will be added to CTEST_TEST_OPTIONS
34 # instead of CTEST_CMAKE_OPTIONS
35 set (KNOWN_CTEST_TEST_OPTIONS
36  START
37  END
38  STRIDE
39  INCLUDE
40  INCLUDE_LABEL
41  EXCLUDE
42  EXCLUDE_LABEL
43  PARALLEL_LEVEL
44 )
45 
46 # start time of Nightly test model
47 #
48 # All Nightly tests which are executed within a time window of 24 hours
49 # starting at the specified start time, will replace previous submissions
50 # made within the same time frame such that for each time frame of 24 hours
51 # only one result of test executions is present on the dashboard.
52 # The execution of the Nightly tests is usually triggered automatically
53 # via a scheduled cron job that is run once every 24 hours.
54 #
55 # Use the Continuous or Experimental test models if you want to execute
56 # tests manually.
57 set (CTEST_NIGHTLY_START_TIME "01:00:00 EST")
58 
59 # ============================================================================
60 # help
61 # ============================================================================
62 
63 # ----------------------------------------------------------------------------
64 ## @brief Print usage section of usage information and help screen.
65 #
66 # @param [in] ARGN Not used.
67 #
68 # @returns Nothing.
69 
70 function (print_usage)
71  message ("Usage:
72  ctest [ctest options] -S basistest.ctest[,option[=value]]*
73 
74  Note: No commas or equality signs are allowed inside of option values even
75  if the value is enclosed by quotation marks.")
76 endfunction ()
77 
78 # ----------------------------------------------------------------------------
79 ## @brief Print options section of usage information and help screen.
80 #
81 # @param [in] ARGN Not used.
82 #
83 # @returns Nothing.
84 
85 function (print_options)
86  message (
87 " <variable>=<value> Passes -D<variable>=<value> on to CMake for the
88  configuration of the build tree if the variable
89  name is not named in the following.
90 
91  The values of the following variables are passed on
92  to the proper CTest scripting commands:")
93  foreach (V IN LISTS KNOWN_CTEST_TEST_OPTIONS)
94  message (" - ${V}")
95  endforeach ()
96  message ("
97  project=<project> Name of the BASIS project to test. If not given, this
98  script skips the update step. In this case, the srcdir
99  and bindir options have to be given, or the current
100  working directory must be the root of an already
101  configured build tree.
102  basedir=<path> Base path of both source and binary directory.
103  Default: \"${HOME}/comp_space/testing\".
104  srcdir=<path> Source directory. This option is required if this script
105  is executed in a build directory which has not been
106  configured yet and if the project option was not specified.
107  If it is run in the root directory of an already configured
108  build tree, however, the value of this option is read from
109  the CMakeCache.txt file. Otherwise, if the project option
110  was specified, it is set to
111  \"<basedir>/<model>/<project>-source/<branch>/\".
112  bindir=<path> Binary directory (i.e., root of build tree).
113  This option defaults to the current working directory
114  if the project option was not specified. Otherwise,
115  it defaults to
116  \"<basedir>/<model>/<site>/<project>-build/<branch>/\".
117  url=<url> Base URL of the project's SVN repository.
118  Only used if the project option was specified.
119  Default: \"https://sbia-svn.uphs.upenn.edu/projects/<project>\".
120  branch=<name> Name of the SVN branch to test, e.g., \"tags/1.0.0\".
121  Default: \"trunk\".
122  model=<model> Name of the dashboard model, i.e., one of
123  \"Nightly\", \"Continuous\", and \"Experimental\".
124  Default: \"Experimental\".
125  memcheck Perform memory check. Requires valgrind.
126  No memory checks are performed by default.
127  coverage Perform coverage analysis. Requires gcov.
128  No coverage analysis is performed by default.
129  install Perform installation after successful test execution.
130  Set CMAKE_INSTALL_PREFIX to change the default installation
131  prefix used by the project (or CMake). Moreover, the
132  DESTDIR environment variable can be set to change the
133  root directory used for installations.
134  Note: Currently this script just executes \"make install\",
135  i.e., it only works with the CMake Makefile generator.
136  apidoc[=<path>] If specified, the API documentation is build
137  and the built HTML documentation copied to the
138  specified directory if the install option is given as well.
139  If this option is given without argument, the default
140  installation directory is used.
141  nosubmit Do not submit test results to the dashboard.
142  shared-source Specify that each test site should use the same copy of
143  the sources. By default, each test site uses its own copy.
144  shared-build Specify that each test site should use the same binary
145  directories. By default, each test site uses its own copy.
146  common-site=<prefix> Do not distinguish between different sites with a common
147  prefix in the name. Useful when the test jobs are executed
148  on a commonly configured cluster.
149  drop-site=<hostname> CTest drop site, i.e., hostname of CDash server.
150  site=<site> Use given site name no matter on which actual machine
151  the test is executed.
152  force-build Force build even if no files were updated.
153  force-test Force test even if no files were updated.
154  force Alias for options force-build, and force-test.
155  tmpbin Delete binary directory on completion (also if not successful).
156  help Prints help and exits without performing any test.
157  helpshort Prints short help and exits without performing any test.
158  helpoptions Prints help on options and exists without performing any test.
159  version Prints version information and exits.")
160 endfunction ()
161 
162 # ----------------------------------------------------------------------------
163 ## @brief Print contact section of usage information and help screen.
164 #
165 # @param [in] ARGN Not used.
166 #
167 # @returns Nothing.
168 
169 function (print_contact)
170  message ("
171 Contact:
172  CMake BASIS Team <https://cmake-basis.github.io/help.html>")
173 endfunction ()
174 
175 # ----------------------------------------------------------------------------
176 ## @brief Print help screen.
177 #
178 # @param [in] ARGN Not used.
179 #
180 # @returns Nothing.
181 
182 function (print_help)
183  print_usage ()
184  message ("
185 Description:
186  This CTest script is used at SBIA for nightly testing of software projects.
187  Nightly tests are scheduled by a cron job, for example, every night once.
188  Contrary to continous testing, does the nightly testing job not loop for
189  a certain time of iterations and look for changes actively. The nightly
190  testing job will only perform one test run and then exit.
191 
192  Note: Due to a bug in CTest 2.8.2, the first test will fail because of
193  a missing CTestConfig.cmake file if the source tree is not checked
194  out already. Therefore, the use of CTest 2.8.4 is recommened.
195 
196 Dashboard models:
197  By default, the dashboard models \"Nightly\", \"Continuous\", and \"Experimental\"
198  are configured as follows. These default configurations can be modified by
199  supplying the available options listed below.
200 
201  Nightly Performs all test stages even if the project has not been
202  updated since the last test run.
203  Continuous Performs an update of the project's working copy and
204  exits without submission of any test results if no files
205  were updated. Otherwise, it performs all test stages.
206  Experimental Performs all test stages even if the project has not been
207  updated since the last test run.
208 
209  Attention: For each model, only one test process may be running for each
210  project on each site at one time.
211 
212 Build configurations:
213  By default, the Release configuration is used. If the coverage option is
214  given, the Coverage configuration is used. If the memcheck option is given
215  instead, the MemCheck configuration is used. If both coverage and memcheck
216  options are given, the Coverage configuration is chosen because it generally
217  can also be used to perform memory checks, while the reported line numbers
218  may be incorrect in this case, however. Use the CMAKE_BUILD_TYPE variable
219  to explicitly specify a build configuration.")
220  message ("
221 Options:")
222  print_options ()
223  message ("
224 Example:
225  ctest -V -S basistest.ctest
226 
227  Run this command in the root directory of an already configured build tree
228  to test this project.
229 
230  ctest -V -S basistest.ctest,coverage
231 
232  Run this command in the root directory of an already configured build tree
233  to test this project and include coverage analysis results in the test report.
234 
235  ctest -V -S basistest.ctest,project=BASIS,model=Experimental,coverage,memcheck
236 
237  Performs an experimental nightly test of the main development branch of
238  BASIS itself, including coverage analysis and memory checks.
239  The -V option of ctest enables more verbose output of CTest.
240  Even more verbose output can be requested using -VV.")
241  print_contact ()
242 endfunction ()
243 
244 # ----------------------------------------------------------------------------
245 ## @brief Print usage information.
246 #
247 # @param [in] ARGN Not used.
248 #
249 # @returns Nothing.
250 
251 function (print_helpshort)
252  print_usage ()
253  message ("
254 Options:")
255  print_options ()
256  print_contact ()
257 endfunction ()
258 
259 # ----------------------------------------------------------------------------
260 ## @brief Print version information.
261 #
262 # @param [in] ARGN Not used.
263 #
264 # @returns Nothing.
265 
266 function (print_version)
267  set (VERSION_INFO "version 3.3.1")
268  if (71f5085 GREATER 0) # project revision > 0
269  set (VERSION_INFO "${VERSION_INFO} (revision 71f5085)")
270  endif ()
271  message ("CTest script basistest.ctest (BASIS) ${VERSION_INFO}")
272  message ("Copyright (c) 2011 University of Pennsylvania. All rights reserved.")
273  message ("See COPYING file or https://www.rad.upenn.edu/sbia/software/license.html.")
274 endfunction ()
275 
276 # ============================================================================
277 # helpers
278 # ============================================================================
279 
280 # ----------------------------------------------------------------------------
281 ## @brief Read value from CMake cache.
282 #
283 # @param [in, out] VAR Name of CMake variable.
284 # @param [in] ARGN Not used.
285 #
286 # @returns Sets @p VAR to the value of the cached variable @p VAR.
287 function (read_cmake_cache_value VAR)
288  file (STRINGS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" ENTRY REGEX "${VAR}:.*=(.*)")
289  string (REGEX REPLACE "${VAR}:.*=(.*)" "\\1" VALUE "${ENTRY}")
290  set (${VAR} "${VALUE}" PARENT_SCOPE)
291 endfunction ()
292 
293 # ----------------------------------------------------------------------------
294 ## @brief Adjust information attached to test results using CMakeCache.txt.
295 #
296 # @param [in] ARGN List of XML test report files without directory path.
297 # If omitted, this function globs for all XML files in
298 # the <tt>Testing/&lt;tag&gt;/</tt> directory.
299 function (update_metadata)
300  # get compiler information from CMake cache
301  if (EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
302  if (WIN32)
303  set (NAME_COMPONENT "NAME_WE")
304  else ()
305  set (NAME_COMPONENT "NAME")
306  endif ()
307  if (UNIX OR BORLAND)
308  read_cmake_cache_value (CMAKE_CXX_COMPILER)
309  set (COMPILER "${CMAKE_CXX_COMPILER}")
310  get_filename_component (COMPILER_NAME "${CMAKE_CXX_COMPILER}" ${NAME_COMPONENT})
311  else ()
312  read_cmake_cache_value (CMAKE_BUILD_TOOL)
313  set (COMPILER "${CMAKE_BUILD_TOOL}")
314  get_filename_component (COMPILER_NAME "${CMAKE_BUILD_TOOL}" ${NAME_COMPONENT})
315  endif ()
316  if (COMPILER_NAME MATCHES "msdev")
317  set (COMPILER_NAME "vs60")
318  elseif (COMPILER_NAME MATCHES "devenv")
319  read_cmake_cache_value (CMAKE_GENERATOR)
320  string (REGEX REPLACE "Visual Studio ([0-9][0-9]?)($|.*)" "\\1" NUMBER "${CMAKE_GENERATOR}")
321  if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio 7 .NET 2003")
322  set (COMPILER_NAME "vs71")
323  else ()
324  set (COMPILER_NAME "vs${NUMBER}")
325  endif ()
326  endif ()
327  else ()
328  set (COMPILER "unknown")
329  set (COMPILER_NAME "unknown")
330  endif ()
331  # replace COMPILER_NAME in build name
332  string (CONFIGURE "${CTEST_BUILD_NAME}" BUILDNAME @ONLY)
333  message ("Change build name to ${BUILDNAME}")
334  # get tag, i.e., subdirectory name required by update_metadata()
335  if (EXISTS "${CTEST_BINARY_DIRECTORY}/Testing/TAG")
336  file (STRINGS "${CTEST_BINARY_DIRECTORY}/Testing/TAG" TAG LIMIT_COUNT 1)
337  else ()
338  set (TAG ".")
339  endif ()
340  # modify submission files
341  if (NOT ARGV)
342  file (
343  GLOB_RECURSE
344  ARGV
345  RELATIVE
346  "${CTEST_BINARY_DIRECTORY}/Testing/${TAG}"
347  "${CTEST_BINARY_DIRECTORY}/Testing/${TAG}/*.xml"
348  )
349  endif ()
350  foreach (SUBMISSION_FILE IN LISTS ARGV)
351  set (SUBMISSION_FILE "${CTEST_BINARY_DIRECTORY}/Testing/${TAG}/${SUBMISSION_FILE}")
352  # read submission file
353  file (READ "${SUBMISSION_FILE}" XML)
354  # set compiler name if necessary
355  string (REPLACE "CompilerName=\"\"" "CompilerName=\"${COMPILER}\"" XML "${XML}")
356  string (REPLACE "<CompilerName></CompilerName>" "<CompilerName>${COMPILER}</CompilerName>" XML "${XML}")
357  # replace intermediate build name
358  string (REPLACE "BuildName=\"\"" "BuildName=\"${BUILDNAME}\"" XML "${XML}")
359  string (REPLACE "<BuildName></BuildName>" "<BuildName>${BUILDNAME}</BuildName>" XML "${XML}")
360  string (REPLACE "BuildName=\"${CTEST_BUILD_NAME}\"" "BuildName=\"${BUILDNAME}\"" XML "${XML}")
361  string (REPLACE "<BuildName>${CTEST_BUILD_NAME}</BuildName>" "<BuildName>${BUILDNAME}</BuildName>" XML "${XML}")
362  # write modified submission file
363  file (WRITE "${SUBMISSION_FILE}" "${XML}")
364  endforeach ()
365 endfunction ()
366 
367 # ============================================================================
368 # settings
369 # ============================================================================
370 
371 set (MANUAL_MODE FALSE) # whether this script is running in manual mode, i.e.,
372  # executed in the build tree of an existing project
373  # instead of run by a cron job
374 
375 # ----------------------------------------------------------------------------
376 # general
377 set (CTEST_BASE_DIRECTORY "$ENV{HOME}/comp_space/testing")
380 set (CTEST_MODEL "Experimental")
381 set (SHARED_SOURCE FALSE)
382 set (SHARED_BUILD FALSE)
383 set (SUBMIT_RESULTS TRUE)
384 set (COMMON_SITE_PREFIXES)
385 
386 set (CTEST_EXTRA_SUBMIT_FILES) # additional files for submission to the dashboard
387 
388 # ----------------------------------------------------------------------------
389 # project attributes
391 set (CTEST_SVN_URL "https://sbia-svn.uphs.upenn.edu/projects/\@CTEST_PROJECT_NAME\@")
392 set (CTEST_SVN_BRANCH "trunk")
393 
394 # ----------------------------------------------------------------------------
395 # build configuration
396 set (CTEST_CMAKE_GENERATOR "Unix Makefiles") # CMake generator
397 set (CTEST_BUILD_TYPE "") # build type/configuration
398 set (CTEST_COMPILER_FLAGS "") # additional compiler flags
399 set (CTEST_LINKER_FLAGS "") # additional linker flags
401 set (WITH_APIDOC FALSE) # enable/disable build of API documentation
402 set (WITH_MEMCHECK FALSE) # enable/disable memory checks
403 set (WITH_COVERAGE FALSE) # enable/disable coverage analysis
404 set (CTEST_MEMORYCHECK_SUPPRESSIONS_FILE) # memory checks suppressions
405 
406 # ----------------------------------------------------------------------------
407 # test execution
408 set (CTEST_TEST_OPTIONS)
409 
410 set (FORCE_BUILD FALSE)
411 set (FORCE_TEST FALSE)
412 
413 # ----------------------------------------------------------------------------
414 # installation directories
415 
416 # install project files after successful test execution
417 set (WITH_INSTALL FALSE)
418 # output directory for built Doxygen documentation
419 set (INSTALL_APIDOC_DIR)
420 
421 # ============================================================================
422 # options
423 # ============================================================================
424 
425 macro (set_option VAR)
426  if (${ARGC} EQUAL 1)
427  if (VALUE)
428  set (${VAR} "${VALUE}")
429  else ()
430  set (FAILURE TRUE)
431  endif ()
432  else ()
433  if (VALUE)
434  set (FAILURE TRUE)
435  else ()
436  set (${VAR} "${ARGN}")
437  endif ()
438  endif ()
439 endmacro ()
440 
441 macro (append_option VAR)
442  if (VALUE)
443  list (APPEND ${VAR} "${VALUE}")
444  else ()
445  set (FAILURE TRUE)
446  endif ()
447 endmacro ()
448 
449 string (REPLACE "," ";" ARGV "${CTEST_SCRIPT_ARG}")
450 foreach (ARG ${ARGV})
451  set (FAILURE FALSE)
452  set (OPTION "")
453  set (VALUE "")
454 
455  string (REPLACE "=" ";" PARTS "${ARG}")
456  list (LENGTH PARTS LEN)
457 
458  if (LEN EQUAL 1)
459  set (OPTION "${PARTS}")
460  elseif (LEN EQUAL 2)
461  list (GET PARTS 0 OPTION)
462  list (GET PARTS 1 VALUE)
463  endif ()
464 
465  if (OPTION)
466  if (${OPTION} STREQUAL "project")
468  elseif (${OPTION} STREQUAL "model")
470  elseif (${OPTION} STREQUAL "basedir")
472  elseif (${OPTION} STREQUAL "srcdir")
474  elseif (${OPTION} STREQUAL "bindir")
476  elseif (${OPTION} STREQUAL "url")
477  set_option (CTEST_SVN_URL)
478  elseif (${OPTION} STREQUAL "branch")
480  elseif (${OPTION} STREQUAL "memcheck")
482  elseif (${OPTION} STREQUAL "coverage")
484  elseif (${OPTION} STREQUAL "tmpbin")
485  set_option (TMPBIN TRUE)
486  elseif (${OPTION} STREQUAL "install")
487  set_option (WITH_INSTALL TRUE)
488  elseif (${OPTION} STREQUAL "apidoc")
489  set (WITH_APIDOC TRUE)
490  if (VALUE)
491  set_option (INSTALL_APIDOC_DIR)
492  endif ()
493  elseif (${OPTION} STREQUAL "shared-source")
495  elseif (${OPTION} STREQUAL "shared-build")
496  set_option (SHARED_BUILD TRUE)
497  elseif (${OPTION} STREQUAL "submit")
499  elseif (${OPTION} STREQUAL "nosubmit")
500  set_option (SUBMIT_RESULTS FALSE)
501  elseif (${OPTION} STREQUAL "common-site")
502  append_option (COMMON_SITE_PREFIXES)
503  elseif (${OPTION} STREQUAL "site")
505  elseif (${OPTION} STREQUAL "force")
506  set_option (FORCE_BUILD TRUE)
507  set_option (FORCE_TEST TRUE)
508  elseif (${OPTION} STREQUAL "force-build")
509  set_option (FORCE_BUILD TRUE)
510  elseif (${OPTION} STREQUAL "force-test")
511  set_option (FORCE_TEST TRUE)
512  elseif (${OPTION} STREQUAL "version")
513  print_version ()
514  return ()
515  elseif (${OPTION} STREQUAL "help")
516  print_help ()
517  return ()
518  elseif (${OPTION} STREQUAL "helpshort")
519  print_helpshort ()
520  return ()
521  elseif (${OPTION} STREQUAL "helpoptions")
522  print_options ()
523  return ()
524  else ()
525  if (NOT VALUE)
526  set (FAILURE TRUE)
527  else ()
528  string (TOUPPER "${OPTION}" OPTION_UPPER)
529  list (FIND KNOWN_CTEST_TEST_OPTIONS "${OPTION_UPPER}" IDX)
530  if (IDX EQUAL -1)
531  if (OPTION MATCHES "^CMAKE_BUILD_TYPE$")
532  set (CTEST_BUILD_TYPE "${VALUE}")
533  else ()
534  set (CTEST_CMAKE_OPTIONS "${CTEST_CMAKE_OPTIONS} \"-D${OPTION}=${VALUE}\"")
535  endif ()
536  else ()
537  list (APPEND CTEST_TEST_OPTIONS "${OPTION_UPPER}" "${VALUE}")
538  endif ()
539  endif ()
540  endif ()
541  else ()
542  set (FAILURE TRUE)
543  endif ()
544 
545  if (FAILURE)
546  message (FATAL_ERROR "Invalid options: ${CTEST_SCRIPT_ARG}
547 Failed to parse argument \"${ARG}\" (option: ${OPTION}, value: ${VALUE})")
548  endif ()
549 endforeach ()
550 
551 if (NOT CTEST_PROJECT_NAME)
552  set (MANUAL_MODE TRUE)
553  # automatically set binary directory if not specified
554  if (NOT CTEST_BINARY_DIRECTORY)
555  if (UNIX)
556  find_program (PWD pwd)
557  else ()
558  find_program (PWD cd)
559  endif ()
560  execute_process (
561  COMMAND "${PWD}"
562  RESULT_VARIABLE RT
563  OUTPUT_VARIABLE CWD
564  OUTPUT_STRIP_TRAILING_WHITESPACE
565  )
566  if (RT EQUAL 0)
567  set (CTEST_BINARY_DIRECTORY "${CWD}")
568  else ()
569  message (FATAL_ERROR "Failed to get current working directory! Try using the bindir option instead.")
570  endif ()
571  endif ()
572  # set project name from CMake cache
573  if (EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
574  read_cmake_cache_value (CMAKE_PROJECT_NAME)
575  if (NOT CMAKE_PROJECT_NAME)
576  message (FATAL_ERROR "Failed to read project name from ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt!")
577  endif ()
578  set (CTEST_PROJECT_NAME "${CMAKE_PROJECT_NAME}")
579  endif ()
580  # automatically set source directory if not specified
581  if (NOT CTEST_SOURCE_DIRECTORY)
582  if (NOT EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
583  message (FATAL_ERROR "Missing CMakeCache.txt file! Either specify source directory using the srcdir option or initialize the build tree.")
584  endif ()
585  read_cmake_cache_value (${CTEST_PROJECT_NAME}_SOURCE_DIR)
586  if (NOT ${CTEST_PROJECT_NAME}_SOURCE_DIR)
587  message (FATAL_ERROR "Failed to read source directory from ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt!")
588  endif ()
589  set (CTEST_SOURCE_DIRECTORY "${${CTEST_PROJECT_NAME}_SOURCE_DIR}")
590  endif ()
591 endif ()
592 
593 if (NOT CTEST_BINARY_DIRECTORY)
594  set (CTEST_BINARY_DIRECTORY "${CTEST_SOURCE_DIRECTORY}")
595 endif ()
596 
597 string (TOLOWER "${CTEST_PROJECT_NAME}" CTEST_PROJECT_NAME_LOWER)
598 string (TOUPPER "${CTEST_PROJECT_NAME}" CTEST_PROJECT_NAME_UPPER)
599 
600 if (CTEST_MODEL MATCHES "Nightly|Experimental")
601  set (FORCE_BUILD TRUE)
602  set (FORCE_TEST TRUE)
603 endif ()
604 
605 # ============================================================================
606 # drop site
607 # ============================================================================
608 
609 # dashboard submission to SBIA CDash server
610 #
611 # Note: By default, CTest does not support HTTPS as submission method.
612 # In order to enable it, CTest (and hence CMake) has to be build
613 # manually with the option CMAKE_USE_OPENSSL enabled.
614 set (CTEST_DROP_METHOD "http")
615 set (CTEST_DROP_SITE "sbia-portal.uphs.upenn.edu")
616 set (CTEST_DROP_LOCATION "/cdash/submit.php?project=${CTEST_PROJECT_NAME}")
618 
619 # launchers
620 #
621 # See documentation of CTest.cmake module.
623 
624 # ============================================================================
625 # initialization
626 # ============================================================================
627 
628 # ----------------------------------------------------------------------------
629 # build type
630 if (NOT CTEST_BUILD_TYPE)
632  set (CTEST_BUILD_TYPE "Debug")
633  else ()
634  set (CTEST_BUILD_TYPE "Release")
635  endif ()
636 endif ()
637 
638 # ----------------------------------------------------------------------------
639 # site information
640 if (NOT CTEST_SITE)
641  site_name (CTEST_SITE)
642  # common site name
643  if (COMMON_SITE_PREFIXES)
644  foreach (P ${COMMON_SITE_PREFIXES})
645  if (CTEST_SITE MATCHES "^${P}")
646  set (CTEST_SITE "${P}")
647  break ()
648  endif ()
649  endforeach ()
650  endif ()
651 endif ()
652 
653 # ----------------------------------------------------------------------------
654 # build information
655 
656 # Note: The pattern in the build name as written to the .xml files
657 # will be replaced by this script before the submission once the used
658 # compiler is known from the CMake cache.
659 set (CTEST_BUILD_NAME "${CMAKE_SYSTEM_NAME}-\@COMPILER_NAME\@")
660 if (WITH_COVERAGE AND WITH_MEMCHECK)
661  set (CTEST_BUILD_NAME "${CTEST_BUILD_NAME} (Coverage & MemCheck)")
662 elseif (WITH_COVERAGE)
663  set (CTEST_BUILD_NAME "${CTEST_BUILD_NAME} (Coverage)")
664 elseif (WITH_MEMCHECK)
665  set (CTEST_BUILD_NAME "${CTEST_BUILD_NAME} (MemCheck)")
666 endif ()
667 
668 # ----------------------------------------------------------------------------
669 # directories
670 if (NOT MANUAL_MODE)
671  set (CTEST_BUILD_SUBDIR)
672  if (WITH_COVERAGE AND WITH_MEMCHECK)
673  set (CTEST_PREFIX "CoverageAndMemCheck")
674  elseif (WITH_COVERAGE)
675  set (CTEST_PREFIX "Coverage")
676  elseif (WITH_MEMCHECK)
677  set (CTEST_PREFIX "MemCheck")
678  else ()
679  set (CTEST_PREFIX "${CTEST_MODEL}")
680  if (CTEST_BUILD_TYPE)
681  set (CTEST_BUILD_SUBDIR "${CTEST_BUILD_TYPE}")
682  else ()
683  set (CTEST_BUILD_SUBDIR "Default")
684  endif ()
685  endif ()
686  if (NOT CTEST_SOURCE_DIRECTORY)
687  if (SHARED_SOURCE)
688  set (CTEST_SOURCE_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_PROJECT_NAME}-source/${CTEST_SVN_BRANCH}")
689  else ()
690  set (CTEST_SOURCE_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_SITE}/${CTEST_PROJECT_NAME}-source/${CTEST_SVN_BRANCH}")
691  endif ()
692  endif ()
693  if (NOT CTEST_BINARY_DIRECTORY)
694  if (SHARED_BUILD)
695  set (CTEST_BINARY_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_PROJECT_NAME}-build/${CTEST_SVN_BRANCH}/${CTEST_BUILD_SUBDIR}")
696  else ()
697  set (CTEST_BINARY_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_SITE}/${CTEST_PROJECT_NAME}-build/${CTEST_SVN_BRANCH}/${CTEST_BUILD_SUBDIR}")
698  endif ()
699  endif ()
700 endif ()
701 string (REGEX REPLACE "/$" "" CTEST_BINARY_DIRECTORY "${CTEST_BINARY_DIRECTORY}")
702 string (REGEX REPLACE "/$" "" CTEST_SOURCE_DIRECTORY "${CTEST_SOURCE_DIRECTORY}")
703 
704 string (CONFIGURE "${INSTALL_APIDOC_DIR}" INSTALL_APIDOC_DIR)
705 
706 if (MANUAL_MODE)
707  set (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY FALSE)
708 else ()
709  set (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY TRUE)
710 endif ()
711 
712 # ----------------------------------------------------------------------------
713 # checkout / update
714 find_program (
715  CTEST_SVN_COMMAND
716  NAMES basistest-svn
717  HINTS "${CMAKE_CURRENT_LIST_DIR}/../../bin"
718 )
719 find_program (CTEST_SVN_COMMAND NAMES svn)
720 
721 if (NOT CTEST_SVN_COMMAND)
722  message (FATAL_ERROR "Could not find \"basistest-svn\" or \"svn\" command!")
723 endif ()
724 
725 string (CONFIGURE "${CTEST_SVN_URL}" CTEST_SVN_URL @ONLY)
726 
727 if (NOT MANUAL_MODE AND NOT EXISTS "${CTEST_SOURCE_DIRECTORY}/.svn")
728  file (MAKE_DIRECTORY "${CTEST_SOURCE_DIRECTORY}") # in particular all missing parent directories
729  set (CTEST_CHECKOUT_COMMAND "${CTEST_SVN_COMMAND} co \"${CTEST_SVN_URL}/${CTEST_SVN_BRANCH}\" ${CTEST_SOURCE_DIRECTORY}")
730 endif ()
731 set (CTEST_UPDATE_COMMAND "${CTEST_SVN_COMMAND}")
732 
733 # ----------------------------------------------------------------------------
734 # coverage analysis
735 if (WITH_COVERAGE)
736  find_program (CTEST_COVERAGE_COMMAND NAMES gcov)
737  if (NOT CTEST_COVERAGE_COMMAND)
738  message (FATAL_ERROR "Could not find gcov! Only gcc and gcov supported to perform coverage analysis.")
739  endif ()
740  set (CTEST_COMPILER_FLAGS "${CTEST_COMPILER_FLAGS} -O0 -fprofile-arcs -ftest-coverage")
741  set (CTEST_LINKER_FLAGS "${CTEST_LINKER_FLAGS} -fprofile-arcs")
742 endif ()
743 
744 # ----------------------------------------------------------------------------
745 # memory check
746 if (WITH_MEMCHECK)
747  # TODO Consider switching to AddressSanitizer instead, which requires the
748  # use of the clang compiler, however, with the compiler flag
749  # -faddress-sanitizer.
750  find_program (CTEST_MEMORYCHECK_COMMAND NAMES valgrind)
751  if (NOT CTEST_MEMORYCHECK_COMMAND)
752  message (FATAL_ERROR "Could not find valgrind! Only valgrind supported as memory error detector.")
753  endif ()
754  if (NOT WITH_COVERAGE)
755  set (CTEST_COMPILER_FLAGS "${CTEST_COMPILER_FLAGS} -O1")
756  endif ()
757  set (CTEST_COMPILER_FLAGS "${CTEST_COMPILER_FLAGS} -fno-omit-frame-pointer")
758  if (CTEST_MEMORYCHECK_SUPPRESSIONS_FILE)
759  if (NOT IS_ABSOLUTE "${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE}")
760  set (
761  CTEST_MEMORYCHECK_SUPPRESSIONS_FILE
762  "${CTEST_SOURCE_DIRECTORY}/${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE}"
763  )
764  endif ()
765  if (NOT EXISTS "${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE}")
766  message ("Memory check suppressions file ${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE} not found!")
767  endif ()
768  endif ()
769 endif ()
770 
771 # ----------------------------------------------------------------------------
772 # configuration / build
773 set (CTEST_CONFIGURE_COMMAND "\"${CMAKE_COMMAND}\"")
774 if (CTEST_BUILD_TYPE)
775  set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=${CTEST_BUILD_TYPE}")
776 endif ()
777 if (CTEST_COMPILER_FLAGS)
778  string (STRIP "${CTEST_COMPILER_FLAGS}" CTEST_COMPILER_FLAGS)
779  set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_C_FLAGS:STRING=${CTEST_COMPILER_FLAGS}\"")
780  set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_CXX_FLAGS:STRING=${CTEST_COMPILER_FLAGS}\"")
781 endif ()
783  string (STRIP "${CTEST_LINKER_FLAGS}" CTEST_LINKER_FLAGS)
784  set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_EXE_LINKER_FLAGS:STRING=${CTEST_LINKER_FLAGS}\"")
785  set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_MODULE_LINKER_FLAGS:STRING=${CTEST_LINKER_FLAGS}\"")
786  set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CTEST_LINKER_FLAGS}\"")
787 endif ()
788 set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DBUILD_TESTING:BOOL=ON")
789 if (WITH_APIDOC)
790  set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DBUILD_DOCUMENTATION:BOOL=ON -DBASIS_ALL_DOC:BOOL=ON")
791  if (INSTALL_APIDOC_DIR)
792  set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DBASIS_INSTALL_APIDOC_DIR:PATH=${INSTALL_APIDOC_DIR}")
793  endif ()
794 else ()
795  set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DBUILD_DOCUMENTATION:BOOL=OFF")
796 endif ()
798  set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} ${CTEST_CMAKE_OPTIONS}")
799 endif ()
800 set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-G${CTEST_CMAKE_GENERATOR}\"")
801 set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"${CTEST_SOURCE_DIRECTORY}\"")
802 
803 # ============================================================================
804 # testing
805 # ============================================================================
806 
807 set (CONFIGURE_RESULT 1) # whether configuration was successful (0 if it was)
808 set (BUILD_RESULT 1) # whether build was successful (0 if it was)
809 
810 # ----------------------------------------------------------------------------
811 # in manual mode, preserve CMake cache to be able to restore it later
812 if (MANUAL_MODE AND EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
813  execute_process (
814  COMMAND "${CMAKE_COMMAND}" -E copy
815  "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt"
816  "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak"
817  )
818 endif ()
819 
820 # ----------------------------------------------------------------------------
821 # empty the binary directory
823  ctest_empty_binary_directory ("${CTEST_BINARY_DIRECTORY}")
824 endif ()
825 
826 # ----------------------------------------------------------------------------
827 # start a new test run
828 ctest_start ("${CTEST_MODEL}")
829 
830 # ----------------------------------------------------------------------------
831 # update working copy
832 set (UPDATED_FILES TRUE)
833 
834 if (NOT MANUAL_MODE)
835  ctest_update (RETURN_VALUE NUM_FILES)
836 
837  if (NOT CTEST_CHECKOUT_COMMAND AND NUM_FILES EQUAL 0)
838  set (UPDATED_FILES FALSE)
839  if (NOT FORCE_BUILD)
840  set (SUBMIT_RESULTS FALSE)
841  endif ()
842  endif ()
843 endif ()
844 
845 # perform other test stages and submit results only if required
846 if (FORCE_BUILD OR UPDATED_FILES)
847 
848  # --------------------------------------------------------------------------
849  # configure build
850 
851  # Note: Also in manual mode to enforce the selected build configuration!
852  ctest_configure (RETURN_VALUE CONFIGURE_RESULT)
853 
854  if (CONFIGURE_RESULT EQUAL 0)
855  ctest_read_custom_files ("${CTEST_BINARY_DIRECTORY}")
856  endif ()
857 
858  # --------------------------------------------------------------------------
859  # build project
860  if (CONFIGURE_RESULT EQUAL 0)
861  ctest_build (NUMBER_ERRORS NUMBER_OF_ERRORS RETURN_VALUE BUILD_RESULT)
862  if (NUMBER_OF_ERRORS GREATER 0)
863  set (BUILD_RESULT "${NUMBER_OF_ERRORS}")
864  endif ()
865  endif ()
866 
867  # --------------------------------------------------------------------------
868  # perform tests only if required
869  if (BUILD_RESULT EQUAL 0 AND (FORCE_TEST OR UPDATED_FILES))
870 
871  # ------------------------------------------------------------------------
872  # run tests
873  if (WITH_COVERAGE OR NOT WITH_MEMCHECK)
874  ctest_test (${CTEST_TEST_OPTIONS} RETURN_VALUE TEST_RESULT)
875  endif ()
876 
877  # ---------------------------------------------------------------------------
878  # perform installation
879  if (WITH_INSTALL AND TEST_RESULT EQUAL 0)
880  message ("Install project files")
881  # First deinstall previously installed files to ensure that obsolete
882  # files are removed. These obsolete files could otherwise be used by
883  # other projects and the test would not reveal that the projects are
884  # actually no longer compatible.
886  set (UNINSTALLER "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/uninstall-${CTEST_PROJECT_NAME_LOWER}")
887  if (EXISTS "${UNINSTALLER}")
888  execute_process (
889  COMMAND "${UNINSTALLER}"
890  WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}"
891  TIMEOUT 1800 # 30 minutes
892  RESULT_VARIABLE UNINSTALL_RESULT
893  OUTPUT_FILE "${CTEST_BINARY_DIRECTORY}/install.log"
894  ERROR_FILE "${CTEST_BINARY_DIRECTORY}/install.log"
895  )
896  else ()
897  execute_process (
898  COMMAND make uninstall
899  WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}"
900  TIMEOUT 1800 # 30 minutes
901  RESULT_VARIABLE UNINSTALL_RESULT
902  OUTPUT_FILE "${CTEST_BINARY_DIRECTORY}/install.log"
903  ERROR_FILE "${CTEST_BINARY_DIRECTORY}/install.log"
904  )
905  endif ()
906  # install new files
907  execute_process (
908  COMMAND make install
909  WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}"
910  TIMEOUT 1800 # 30 minutes
911  RESULT_VARIABLE INSTALL_RESULT
912  OUTPUT_FILE "${CTEST_BINARY_DIRECTORY}/install.log"
913  ERROR_FILE "${CTEST_BINARY_DIRECTORY}/install.log"
914  )
915  # submit log file in case of errors to dashboard
916  if (NOT UNINSTALL_RESULT EQUAL 0 OR NOT INSTALL_RESULT EQUAL 0)
917  list (APPEND CTEST_NOTES_FILES "${CTEST_BINARY_DIRECTORY}/install.log")
918  endif ()
919  endif ()
920 
921  # --------------------------------------------------------------------------
922  # perform coverage analysis
923  if (WITH_COVERAGE AND CTEST_COVERAGE_COMMAND)
924  ctest_coverage ()
925  endif ()
926 
927  # --------------------------------------------------------------------------
928  # perform memory checks
929  if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
930  ctest_memcheck (${CTEST_TEST_OPTIONS})
931  endif ()
932 
933  endif ()
934 
935 endif ()
936 
937 # -----------------------------------------------------------------------------
938 # adjust test result meta-data - even if these will not be submitted yet
939 update_metadata ()
940 
941 # -----------------------------------------------------------------------------
942 # submit results
943 if (SUBMIT_RESULTS)
944  ctest_submit ()
945 endif ()
946 
947 # -----------------------------------------------------------------------------
948 # clean up
949 if (TMPBIN)
950  file (REMOVE_RECURSE "${CTEST_BINARY_DIRECTORY}")
951 else ()
952  if (MANUAL_MODE AND EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak")
953  execute_process (
954  COMMAND "${CMAKE_COMMAND}" -E compare_files
955  "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt"
956  "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak"
957  RESULT_VARIABLE RT
958  OUTPUT_QUIET
959  ERROR_QUIET
960  )
961  if (RT EQUAL 0)
962  file (REMOVE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak")
963  else ()
964  message ("Restoring build system configuration...")
965  file (
966  RENAME "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak"
967  "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt"
968  )
969  execute_process (
970  COMMAND "${CMAKE_COMMAND}" "${CTEST_BINARY_DIRECTORY}"
971  OUTPUT_QUIET
972  RESULT_VARIABLE RT
973  )
974  if (RT EQUAL 0)
975  message ("Restoring build system configuration... - done")
976  else ()
977  message ("Restoring build system configuration... - failed")
978  endif ()
979  endif ()
980  endif ()
981 endif ()
cmake WITH_APIDOC
std::string bindir()
Get absolute path to directory containing runtime executables.
Definition: basis.cxx:203
cmake CTEST_LINKER_FLAGS
macro append_option(in VAR, in ARGN)
cmake CTEST_DROP_LOCATION
cmake FORCE_BUILD
cmake CONFIGURE_RESULT
cmake SHARED_SOURCE
cmake CTEST_USE_LAUNCHERS
cmake CMAKE_INSTALL_PREFIX
Installation prefix, i.e., root directory of installation.
cmake CTEST_BINARY_DIRECTORY
cmake CTEST_NIGHTLY_START_TIME
Definition: basistest.ctest:57
function is(in result, in expected, in name)
Test whether a given result is equal to the expected result.
CTEST_PROJECT_NAME
def which(command, path=None, verbose=0, exts=None)
Definition: which.py:257
cmake FAILURE
cmake CTEST_COMPILER_FLAGS
cmake CTEST_MODEL
cmake UNINSTALLER
cmake CTEST_CMAKE_OPTIONS
function print_options(in ARGN)
Print options section of usage information and help screen.
cmake CTEST_PREFIX
cmake WITH_INSTALL
cmake CTEST_SITE
function print_version(in ARGN)
Print version information.
function print_usage(in ARGN)
Print usage section of usage information and help screen.
cmake SUBMIT_RESULTS
cmake CTEST_SVN_BRANCH
function read_cmake_cache_value(inout VAR, in ARGN)
Read value from CMake cache.
cmake CTEST_START_WITH_EMPTY_BINARY_DIRECTORY
cmake CTEST_BUILD_TYPE
cmake UPDATED_FILES
function update_metadata(in ARGN)
Adjust information attached to test results using CMakeCache.txt.
cmake CTEST_UPDATE_COMMAND
cmake MANUAL_MODE
cmake BUILD_RESULT
cmake SHARED_BUILD
cmake CTEST_DROP_SITE_CDASH
CTEST_MEMORYCHECK_SUPPRESSIONS_FILE
cmake CTEST_DROP_SITE
#define UNIX
Whether the sources are compiled on a Unix-based system.
Definition: config.h:60
cmake COMMAND
cmake WITH_MEMCHECK
cmake VALUE
macro set_option(in VAR, in ARGN)
cmake FORCE_TEST
cmake CTEST_DROP_METHOD
cmake CTEST_SOURCE_DIRECTORY
cmake CTEST_CHECKOUT_COMMAND
cmake CTEST_CONFIGURE_COMMAND
cmake CTEST_BUILD_NAME
function print_contact(in ARGN)
Print contact section of usage information and help screen.
cmake CTEST_BUILD_SUBDIR
cmake OPTION
if(oldcoutbuf)
function print_helpshort(in ARGN)
Print usage information.
function get_filename_component(inout ARGN)
Fixes CMake&#39;s get_filename_component() command.
cmake CTEST_BASE_DIRECTORY
cmake WITH_COVERAGE
function print_help(in ARGN)
Print help screen.
cmake CTEST_CMAKE_GENERATOR
function execute(in options, in cmd, in args)
Execute command as subprocess.