aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-07 13:54:49 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-07 13:56:59 -0700
commit124114c0a8add705d4c3affb6f602b0a36eb4237 (patch)
treef820133b5e4a38579a026ed4f5ebe00ccf7b0493
parentb02a4341a9214cc57587c300171824d79b346913 (diff)
downloadnng-124114c0a8add705d4c3affb6f602b0a36eb4237.tar.gz
nng-124114c0a8add705d4c3affb6f602b0a36eb4237.tar.bz2
nng-124114c0a8add705d4c3affb6f602b0a36eb4237.zip
Richer CI support on Travis, including code coverage.
We use codecov.io; this seems to work well.
-rw-r--r--.travis.yml74
-rw-r--r--CMakeLists.txt22
-rwxr-xr-xetc/codecov.sh10
-rwxr-xr-xetc/coverage.sh23
4 files changed, 119 insertions, 10 deletions
diff --git a/.travis.yml b/.travis.yml
index 3c0e53a0..6d15f2b8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,22 +1,74 @@
-language: c
+language: generic
dist: trusty
sudo: false
addons:
apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - llvm-toolchain-trusty-4.0
packages:
- cmake
- - uncrustify
- colordiff
+ - g++-4.9
+ - g++-7
+ - clang-4.0
+ - clang-format-4.0
matrix:
include:
+ # default gcc 4.9 build - we also do a clang-format check here.
- os: linux
- compiler: gcc
+ env: >-
+ CC=gcc-4.9
+ CXX=g++-4.9
+ COVERAGE=OFF
+ BUILD_TYPE=Debug
+ TEST_PARALLEL=-j4
+ CLANG_FORMAT=clang-format-4.0
- os: linux
- compiler: clang
-# - os: osx
-# compiler: gcc
+ env: >-
+ CC=gcc-7
+ CXX=g++-7
+ COVERAGE=OFF
+ BUILD_TYPE=Debug
+ TEST_PARALLEL=-j4
+ CLANG_FORMAT=no
+ # clang v4 build
+ - os: linux
+ env: >-
+ CC=clang-4.0
+ CXX=clang++-4.0
+ COVERAGE=OFF
+ BUILD_TYPE=Debug
+ TEST_PARALLEL=-j4
+ CLANG_FORMAT=no
+ # one release build
+ - os: linux
+ env: >-
+ CC=clang-4.0
+ CXX=clang++-4.0
+ COVERAGE=OFF
+ BUILD_TYPE=Release
+ TEST_PARALLEL=-j4
+ CLANG_FORMAT=no
+ # code coverage build
+ - os: linux
+ env: >-
+ CC=clang-4.0
+ CXX=clang++-4.0
+ COVERAGE=ON
+ BUILD_TYPE=Debug
+ TEST_PARALLEL=
+ CLANG_FORMAT=no
+ # One MacOS X build
- os: osx
- compiler: clang
+ env: >-
+ CC=clang
+ CXX=clang++
+ COVERAGE=OFF
+ TEST_PARALLEL=-j4
+ BUILD_TYPE=Debug
+ CLANG_FORMAT=no
+
script:
# Print all environment variables to aid in CI development
- uname -a
@@ -27,7 +79,11 @@ script:
- mkdir build
- cd build
# Perform CMake backend generation, build, and test
- - cmake -DCMAKE_BUILD_TYPE=Debug ..
+ - cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DNNG_ENABLE_COVERAGE=${COVERAGE} ..
- cmake --build . -- -j4
- - ctest --output-on-failure -C Debug -j4
+ - ctest --output-on-failure -C ${BUILD_TYPE} ${TEST_PARALLEL}
- ../etc/format-check.sh
+
+ after_success:
+ - ../etc/codecov.sh
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c6d25f1b..eb93bda2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,8 +2,8 @@
# Copyright (c) 2012 Martin Sustrik All rights reserved.
# Copyright (c) 2013 GoPivotal, Inc. All rights reserved.
# Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved.
-# Copyright 2016 Garrett D'Amore <garrett@damore.org>
# Copyright 2016 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
+# Copyright 2017 Garrett D'Amore <garrett@damore.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"),
@@ -33,6 +33,7 @@ include (CheckStructHasMember)
include (CheckLibraryExists)
include (CheckCSourceCompiles)
include (GNUInstallDirs)
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if (POLICY CMP0042)
# Newer cmake on MacOS should use @rpath
@@ -90,12 +91,31 @@ option (NNG_ENABLE_DOC "Enable building documentation." ON)
option (NNG_TESTS "Build and run tests" ON)
option (NNG_TOOLS "Build extra tools" OFF)
option (NNG_ENABLE_NNGCAT "Enable building nngcat utility." ${NNG_TOOLS})
+option (NNG_ENABLE_COVERAGE "Enable coverage reporting." OFF)
# Enable access to private APIs for our own use.
add_definitions (-DNNG_PRIVATE)
# Platform checks.
+if (NNG_ENABLE_COVERAGE)
+ # NB: This only works for GCC and Clang 3.0 and newer. If your stuff
+ # is older than that, you will need to find something newer. For
+ # correct reporting, we always turn off all optimizations.
+ if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ set(CMAKE_C_FLAGS -g -O0 -fprofile-arcs -ftest-coverage)
+ set(CMAKE_CXX_FLAGS -g -O0 -fprofile-arcs -ftest-coverage)
+ elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ set(CMAKE_C_FLAGS -g -O0 -fprofile-arcs -ftest-coverage)
+ set(CMAKE_CXX_FLAGS -g -O0 -fprofile-arcs -ftest-coverage)
+ elseif (CMAKE_COMPILER_ID STREQUAL "AppleClang")
+ set(CMAKE_C_FLAGS -g -O0 -fprofile-arcs -ftest-coverage)
+ set(CMAKE_CXX_FLAGS -g -O0 -fprofile-arcs -ftest-coverage)
+ else()
+ message(FATAL_ERROR "Unable to enable coverage for your compiler.")
+ endif()
+endif()
+
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
find_package (Threads REQUIRED)
add_definitions (-DPLATFORM_POSIX)
diff --git a/etc/codecov.sh b/etc/codecov.sh
new file mode 100755
index 00000000..58ce44fc
--- /dev/null
+++ b/etc/codecov.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+if [ "${COVERAGE}" != ON ]
+then
+ echo "Code coverage not enabled."
+ exit 0
+fi
+
+bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage"
+echo 0
diff --git a/etc/coverage.sh b/etc/coverage.sh
new file mode 100755
index 00000000..5afc0979
--- /dev/null
+++ b/etc/coverage.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+if [ "${COVERAGE}" != ON ]
+then
+ echo "Code coverage not enabled."
+ exit 0
+fi
+
+# capture all coverage info
+lcov --directory . --capture --output-file coverage.info || exit 1
+
+# filter out system information (C++ templates & inlines)
+lcov --remove coverage.info '/usr/*' --output-file coverage.info || exit 1
+
+# filter out the *test* program data
+lcov --remove coverage.info '*/tests/*' --output-file coverage.info || exit 1
+
+# emit debug stats.
+lcov --list coverage.info
+
+rm coverage.info
+
+echo 0