Setup CTest Server

We use CTest to test GoFigure2.

CTest is an open source software developed by Kitware, Inc.(http://www.itk.org/Wiki/CMake_Testing_With_CTest) We perform experimental, continuous and nightly builds on GoFigure2. CTest allows us to visualize the results of the different testings on a dashboard. (http://my.cdash.org/index.php?project=GoFigure2)

1. Principle

The objective is to test the software on different platforms (OSX, Linux, Windows) and different configurations (release, debug, static, shared). Experimental build : test if the modifications we did to the code before committing.(on your own machine) Continuous build: test the code, after a modification has been committed. (only on our machines yet... You are very welcome to contribute) Nightly build: test the code every nights. (only on our machines yet... You are very welcome to contribute)

2. Writing the testing file

You should follow the instructions at: http://www.itk.org/Wiki/CMake_Testing_With_CTest. Here is a typical file to use for a nightly build,

cmake_minimum_required(VERSION 2.6)

#~~~~~~~~~~~~~~~~~~
# Configure CTest.
#~~~~~~~~~~~~~~~~~~

set(CTEST_SITE "MegasonLab.Computational.Team")
set(CTEST_BUILD_NAME "Linux-g++4.3.3-sta-dbg")

# Use multiple CPU cores to build
SET (CTEST_BUILD_FLAGS "-j8")

# For convenience
set(source_dir "gofigure2/trunk")
set(build_dir "Static/Debug")

set(CTEST_DASHBOARD_ROOT "/home/username/Dashboard/GoFigure2/Nightly")
set(CTEST_TEST_TIMEOUT 60)
set(CTEST_BUILD_CONFIGURATION Debug)
set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
set(CTEST_SOURCE_DIRECTORY "${CTEST_DASHBOARD_ROOT}/${source_dir}")
set(CTEST_BINARY_DIRECTORY "${CTEST_DASHBOARD_ROOT}/${build_dir}")
set (CTEST_UPDATE_COMMAND "svn")

ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})

#~~~~~~~~~~~~~~~~~~~~~~
# Write initial cache.
#~~~~~~~~~~~~~~~~~~~~~~

file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "
#BUILD TYPE
CMAKE_BUILD_TYPE:STRING=Debug
#VTK PATH
VTK_DIR:PATH=/home/username/GITROOT/VTK/BUILD/Static/Debug
#ITK PATH
ITK_DIR:PATH=/home/username/CVSROOT/Insight/BUILD/Static/Debug
#BUILD EXAMPLES
BUILD_EXAMPLES:BOOL=ON
")

#~~~~~~~~~~~~~~~
# Define tasks.
#~~~~~~~~~~~~~~~

ctest_start (Nightly)
ctest_update (SOURCE "${CTEST_DASHBOARD_ROOT}")
ctest_configure (BUILD "${CTEST_BINARY_DIRECTORY}")
ctest_configure (BUILD "${CTEST_BINARY_DIRECTORY}")
ctest_build (BUILD "${CTEST_BINARY_DIRECTORY}")
ctest_test (BUILD "${CTEST_BINARY_DIRECTORY}")
ctest_submit ()

PS : the folder tree in this example is :

  • folder where ctest_gofigure_shared_debug.ctest is located :

/home/username/Dashboard/GoFigure2/Nightly

  • folder where the trunk of the local svn repository is :

/home/username/Dashboard/GoFigure2/Nightly/gofigure2/trunk

  • folder where we build the nightly build :

/home/username/Dashboard/GoFigure2/Nightly/Static/Debug

3. Automating the job

3.1 Linux

We use cronjobs. http://en.wikipedia.org/wiki/Cron Create a cronjob:

$ crontab -e

Add the job:

00 01 * * * ctest -S /PATH_TO_THE_FILE/ctest_gofigure_shared_debug.ctest -V

Check if the job has been added:

$ crontab -l

You might have to restart you computer.

3.2 Mac

3.2.1 crontab

We can use crontab as well on mac, but on newest version, the way vim backups files prevents crontab from working correctly.

The solution is to create a cronjob using nano instead or vim (default editor), or vi (simulated vi via vim : same error) :

$ EDITOR=nano crontab -e

Add the job:

00 01 * * * ctest -S /PATH_TO_THE_FILE/ctest_gofigure_shared_debug.ctest -V

Check if the job has been added:

$ crontab -l

Wake your Mac up for the cron to work :

  • go to : Applications -> System Preferences -> Energy saver
  • click Schedule button
  • in the pop-up windows, Start up or wake your Mac a few minutes before your job,
    Sleep a few minutes after the end of the job (consider that 30 minutes should be enough for compilation and testing)

Note:
if you installed cmake with macport, you 'll have to specify the full path for the ctest executable.
You might have to restart you computer.

3.2.2 launchd

The recommended way to schedule such task on osx though, is to use launchd :

http://developer.apple.com/macosx/launchd.html

3.3. Windows