Skip to content

Commit

Permalink
Merge pull request #44 from cpockrandt/tests_refactoring2
Browse files Browse the repository at this point in the history
CMake and CTest refactoring (and minor bug fixes)
  • Loading branch information
cpockrandt authored Mar 14, 2019
2 parents 8f7eb2d + a6d88a2 commit bd9ce15
Show file tree
Hide file tree
Showing 60 changed files with 754 additions and 1,633 deletions.
221 changes: 221 additions & 0 deletions .jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
import hudson.triggers.TimerTrigger;

// ============================================================================
// Global properties
// ============================================================================

// Start build every night between 1:00-4:59
// Keep only last 10 builds
properties([
pipelineTriggers(
[cron(env.BRANCH_NAME == 'master' ? 'H H(1-4) * * *' : '')]
),
buildDiscarder(
logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')
)
])

// Checks whether the current build was triggered by cron job.
// We need this to check, whether we want to trigger a deployment
// step for a stable nightly build.
def is_triggered_by_cron()
{
for (cause in currentBuild.rawBuild.getCauses())
{
if (cause instanceof TimerTrigger.TimerTriggerCause)
return true
return false
}
}

// Check if this build is a nightly build (only master supports building periodically)
Boolean is_nightly = is_triggered_by_cron()

// ============================================================================
// Define test functions
// ============================================================================

/* Executes unit tests
* \param slave_name The name of the slave this test is executed on; String
* \param compiler The name of the compiler to use; String
* \param build_type The build type to use [Debug, Release]; String
*/
def run_unit_tests(slave_name, compiler, build_type)
{
def build_name
def cxx
def workspace
def platform
def checkout_dir

stage('initialise')
{
workspace = pwd()
echo workspace
// Clean the workspace before building.
deleteDir()

build_name = "$slave_name $compiler $build_type $env.BRANCH_NAME Build-$env.BUILD_NUMBER"
platform = sh(script: 'uname -s', returnStdout: true).trim()

// sh 'git clone https://github.com/seqan/seqan3-infrastructure.git seqan3-infra'
cxx = sh(script: "which $compiler", returnStdout: true).trim()

// Perform checkout in specific location.
// The relative folder structure is important for the ctest script.
dir('checkout')
{
checkout scm
checkout_dir = pwd()
}
}

stage('configure')
{
dir("$workspace/build")
{
sh "cmake $checkout_dir -DCMAKE_BUILD_TYPE=$build_type -DCMAKE_CXX_COMPILER=$compiler -DCMAKE_CXX_FLAGS=-DFULL_TEST_SUITE"
}
}

stage('build tests')
{
dir("$workspace/build")
{
sh "make sdsl_test_targets -j 4 -k"
}
}

stage('build examples')
{
dir("$workspace/build")
{
sh "make sdsl_examples -j 4 -k"
}
}

stage('build tutorials')
{
dir("$workspace/build")
{
sh "make sdsl_tutorials -j 4 -k"
}
}

stage('run tests')
{
dir("$workspace/build")
{
sh "ctest --output-on-failure -j 4"
}
}
}

// ============================================================================
// Define unit test matrix
// ============================================================================

// Configure unit tests. Add platforms here but adapt the inner loop of the matrix setup to call instantiate and
// setup the right agent.
def axis_agent = ["ubuntu"]
def axis_compiler = ["g++-4.9", "g++-5", "g++-6", "g++-7", "g++-8"] // "clang++"
def tasks = [:]

// The following nested for loops define the compiler matrix for the unit tests.
// First iterate over all supported compiler versions
// If the compilers do not match on the respective platform either use a different scope to
// iterate over them or define some kind of map to point to the right compiler name per platform.
for(int i = 0; i < axis_compiler.size(); ++i)
{
def axis_compiler_value = axis_compiler[i]
def axis_build_type_value = "Release"

def label = "ubuntu_${axis_compiler_value}_$axis_build_type_value"
label = label.replace("++", "cc") // currently CMake of SDSL fails since it uses the path in a regex string and ++ characters are not escaped
tasks["ubuntu-${axis_compiler_value}-${axis_build_type_value}"] =
{
node("ubuntu && $axis_compiler_value")
{
// For docker nodes we need to define the workspace explicitly, as they use a mounted
// volume on the filesystem which is shared by all docker instances. Since the docker executor
// doesn't know the other running instances it cannot locking the workspace.
ws("$env.WORKSPACE/ws/$label")
{
stage('install')
{
sh """
sudo apt-get update
sudo apt-get install -y $axis_compiler_value cmake git clang-format
"""

}
run_unit_tests(env.DOCKER_SLAVE_NAME,
axis_compiler_value,
axis_build_type_value)
}
}
}
}

// Debug build
def axis_compiler_value = "g++-8"
def axis_build_type_value = "Debug"

def label = "ubuntu_${axis_compiler_value}_$axis_build_type_value"
label = label.replace("++", "cc") // currently CMake of SDSL fails since it uses the path in a regex string and ++ characters are not escaped

tasks["ubuntu-${axis_compiler_value}-${axis_build_type_value}"] =
{
node("ubuntu && $axis_compiler_value")
{
// For docker nodes we need to define the workspace explicitly, as they use a mounted
// volume on the filesystem which is shared by all docker instances. Since the docker executor
// doesn't know the other running instances it cannot locking the workspace.
ws("$env.WORKSPACE/ws/$label")
{
stage('install')
{
sh """
sudo apt-get update
sudo apt-get install -y $axis_compiler_value cmake git clang-format
"""

}
run_unit_tests(env.DOCKER_SLAVE_NAME,
axis_compiler_value,
axis_build_type_value)
}
}
}

/* TODO sanitizer builds
* g++-7 sanitizer options
*/

/* TODO doc builds
* user develop
*/

/* TODO coverage build
* g++-8 debug mode
*/

/* TODO valgrind build
*
*/

/* TODO performance build
* g++-7, g++-8 [, g++-9] [, clang-concpets]
*/

// ============================================================================
// Execute build matrix
// ============================================================================

// This is the main stage that executes all jobs registered in the tasks map
// All steps are executed in parallel. If the contention on the agents are to high
// consider moving some tasks out into another stage that runs after this one.
stage ("matrix")
{
parallel tasks
}
124 changes: 51 additions & 73 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,100 +2,78 @@

language: cpp

cache:
apt: true
ccache: true

sudo: false

matrix:
include:
- env: MYCC="gcc-4.9" MYCXX="g++-4.9" STDLIB=libstdc++
- env: MYCC="gcc-4.9" MYCXX="g++-4.9" MYBUILD=Debug
os: linux
addons: &gcc49
addons:
apt:
sources:
- kalakris-cmake
- ubuntu-toolchain-r-test
packages:
- cmake
- g++-4.9
sources: ['ubuntu-toolchain-r-test']
packages: ['cmake', 'g++-4.9']

- env: MYCC="gcc-5" MYCXX="g++-5" STDLIB=libstdc++
- env: MYCC="gcc-4.9" MYCXX="g++-4.9" MYBUILD=Release
os: linux
addons: &gcc5
addons:
apt:
sources:
- kalakris-cmake
- ubuntu-toolchain-r-test
packages:
- cmake
- g++-5
sources: ['ubuntu-toolchain-r-test']
packages: ['cmake', 'g++-4.9']

# - env: MYCC="clang-3.7" MYCXX="clang++-3.7" STDLIB=libc++
# os: linux
# addons: &clang37
# apt:
# sources:
# - kalakris-cmake
# - ubuntu-toolchain-r-test
# - llvm-toolchain-precise-3.7
# packages:
# - cmake
# - clang-3.7
- env: MYCC="gcc-5" MYCXX="g++-5" MYBUILD=Release
os: linux
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['cmake', 'g++-5']

- env: MYCC="gcc-6" MYCXX="g++-6" MYBUILD=Release
os: linux
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['cmake', 'g++-6']

- env: MYCC="gcc-7" MYCXX="g++-7" MYBUILD=Release
os: linux
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['cmake', 'g++-7']

- env: MYCC="gcc-8" MYCXX="g++-8" MYBUILD=Release
os: linux
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['cmake', 'g++-8']

- env: MYCC="clang" MYCXX="clang++" STDLIB=libc++
os: osx

install:
############################################################################
# All the dependencies are installed in ${TRAVIS_BUILD_DIR}/deps/
############################################################################
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
- mkdir ${DEPS_DIR} && cd ${DEPS_DIR}
############################################################################
# Install a recent CMake (for LLVM)
############################################################################
- |
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
CMAKE_URL="http://www.cmake.org/files/v3.3/cmake-3.3.2-Linux-x86_64.tar.gz"
mkdir cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake
export PATH=${DEPS_DIR}/cmake/bin:${PATH}
fi
############################################################################
# Install libc++ and libc++abi (on Linux only; Xcode uses libc++ by default)
############################################################################
- |
if [[ "${TRAVIS_OS_NAME}" == "linux" && "${STDLIB}" != "libstdc++" ]]; then
if [[ "${COMPILER}" == "clang++-3.5" ]]; then LLVM_VERSION="3.5.2"
elif [[ "${COMPILER}" == "clang++-3.6" ]]; then LLVM_VERSION="3.6.2";
elif [[ "${COMPILER}" == "clang++-3.7" ]]; then LLVM_VERSION="3.7.0";
else LLVM_VERSION="trunk"; fi
if [[ "${LLVM_VERSION}" != "trunk" ]]; then
LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz"
LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz"
LIBCXXABI_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxxabi-${LLVM_VERSION}.src.tar.xz"
TAR_FLAGS="-xJ"
else
LLVM_URL="https://github.com/llvm-mirror/llvm/archive/master.tar.gz"
LIBCXX_URL="https://github.com/llvm-mirror/libcxx/archive/master.tar.gz"
LIBCXXABI_URL="https://github.com/llvm-mirror/libcxxabi/archive/master.tar.gz"
TAR_FLAGS="-xz"
fi
mkdir -p llvm llvm/build llvm/projects/libcxx llvm/projects/libcxxabi
travis_retry wget --quiet -O - ${LLVM_URL} | tar --strip-components=1 ${TAR_FLAGS} -C llvm
travis_retry wget --quiet -O - ${LIBCXX_URL} | tar --strip-components=1 ${TAR_FLAGS} -C llvm/projects/libcxx
travis_retry wget --quiet -O - ${LIBCXXABI_URL} | tar --strip-components=1 ${TAR_FLAGS} -C llvm/projects/libcxxabi
(cd llvm/build && cmake .. -DCMAKE_INSTALL_PREFIX=${DEPS_DIR}/llvm/install -DCMAKE_CXX_COMPILER=clang++)
(cd llvm/build/projects/libcxx && make install -j2)
(cd llvm/build/projects/libcxxabi && make install -j2)
export CXXFLAGS="-isystem ${DEPS_DIR}/llvm/install/include/c++/v1"
export LDFLAGS="-L ${DEPS_DIR}/llvm/install/lib -l c++ -l c++abi"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${DEPS_DIR}/llvm/install/lib"
fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install ccache ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="/usr/local/opt/ccache/libexec:$PATH" ; fi

before_script:
- export CXX=$MYCXX
- export CC=$MYCC
- $CXX --version
- cmake --version
- ccache --version

script:
- cd ${TRAVIS_BUILD_DIR}
- ./install.sh ..
- mkdir sdsl-lite-build && cd sdsl-lite-build
- cmake ${TRAVIS_BUILD_DIR} -DCMAKE_BUILD_TYPE=$MYBUILD
- make sdsl_test_targets -k -j 2
- ctest -j 2 --output-on-failure
- make sdsl_examples -k -j 2
- make sdsl_tutorials -k -j 2

after_script:
- ccache -s
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ include(CompilerFlags)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Make.helper.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/Make.helper" @ONLY)

enable_testing()

# (8) main library target
add_subdirectory(external)
add_subdirectory(include/sdsl)
Expand Down
4 changes: 4 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set(sdsl_examples "")

file(GLOB example_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)

Expand All @@ -8,4 +9,7 @@ include_directories(
foreach(example_source ${example_sources})
get_filename_component(example_name ${example_source} NAME_WE)
add_executable(${example_name} EXCLUDE_FROM_ALL ${example_name}.cpp)
list(APPEND sdsl_examples ${example_name})
endforeach(example_source)

add_custom_target(sdsl_examples DEPENDS ${sdsl_examples})
Loading

0 comments on commit bd9ce15

Please sign in to comment.