qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject qpid-proton git commit: PROTON-1289: Added code coverage infrastructure to build This is currently C/C++ only, but can be extended to other languages too. This will typically be used like this: - cmake $PROTON_SOURCE -DCMAKE_BUILD_TYPE=Coverage - make -
Date Wed, 24 Aug 2016 17:55:54 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 7f87f1bbc -> 4d4495cc7


PROTON-1289: Added code coverage infrastructure to build
This is currently C/C++ only, but can be extended to other languages too.
This will typically be used like this:
- cmake $PROTON_SOURCE -DCMAKE_BUILD_TYPE=Coverage
- make
- make test
- make coverage
- # Copy result from the coverage_results/html directory


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/4d4495cc
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/4d4495cc
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/4d4495cc

Branch: refs/heads/master
Commit: 4d4495cc73adb4a8888b6b759304a5e2a7fd5db2
Parents: 7f87f1b
Author: Andrew Stitcher <astitcher@apache.org>
Authored: Fri Aug 19 18:21:05 2016 -0400
Committer: Andrew Stitcher <astitcher@apache.org>
Committed: Wed Aug 24 13:52:15 2016 -0400

----------------------------------------------------------------------
 CMakeLists.txt          | 49 ++++++++++++++++++++++++++++--------
 bin/record-coverage.sh  | 60 ++++++++++++++++++++++++++++++++++++++++++++
 proton-c/CMakeLists.txt |  8 +++---
 3 files changed, 103 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4d4495cc/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 57a228a..64311ea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,6 +23,13 @@ project (Proton C)
 # Enable C++ now for examples and bindings subdirectories, but make it optional.
 enable_language(CXX OPTIONAL)
 
+# Enable testing
+enable_testing()
+include (CTest)
+
+# Pull in local cmake modules
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tools/cmake/Modules/")
+
 if (MSVC)
   # No C99 capability, use C++
   set(DEFAULT_BUILD_WITH_CXX ON)
@@ -37,15 +44,36 @@ else (CMAKE_CONFIGURATION_TYPES)
   # If the build type is not set then set the default
   if (NOT CMAKE_BUILD_TYPE)
   set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE string
-       "Build type: Debug, Release, RelWithDebInfo or MinSizeRel (default RelWithDebInfo)"
FORCE)
+       "Build type: Debug, Release, RelWithDebInfo, MinSizeRel or Coverage (default RelWithDebInfo)"
FORCE)
   endif ()
 
+  # Set up extra coverage analysis options for gcc and clang
+  if (CMAKE_COMPILER_IS_GNUCC)
+    set (CMAKE_C_FLAGS_COVERAGE "-g -O0 --coverage")
+    set (CMAKE_CXX_FLAGS_COVERAGE "-g -O0 --coverage")
+    set (CMAKE_EXE_LINKER_FLAGS_COVERAGE "--coverage")
+    set (CMAKE_MODULE_LINKER_FLAGS_COVERAGE "--coverage")
+    set (CMAKE_SHARED_LINKER_FLAGS_COVERAGE "--coverage")
+    mark_as_advanced(
+      CMAKE_C_FLAGS_COVERAGE CMAKE_CXX_FLAGS_COVERAGE
+      CMAKE_EXE_LINKER_FLAGS_COVERAGE CMAKE_MODULE_LINKER_FLAGS_COVERAGE
+      CMAKE_SHARED_LINKER_FLAGS_COVERAGE)
+  endif()
+
   if (CMAKE_BUILD_TYPE MATCHES "Deb")
     set (has_debug_symbols " (has debug symbols)")
   endif (CMAKE_BUILD_TYPE MATCHES "Deb")
   message(STATUS "Build type is \"${CMAKE_BUILD_TYPE}\"${has_debug_symbols}")
 endif (CMAKE_CONFIGURATION_TYPES)
 
+# Add coverage target if we're building for test coverage
+if (CMAKE_BUILD_TYPE MATCHES "Coverage")
+  make_directory(coverage_results)
+  add_custom_target(coverage
+    WORKING_DIRECTORY ./coverage_results
+    COMMAND ${CMAKE_SOURCE_DIR}/bin/record-coverage.sh ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
+endif()
+
 if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
   # Default to universal binary on Mac OS X unless user has overriden
   if (NOT DEFINED CMAKE_OSX_ARCHITECTURES OR "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
@@ -75,8 +103,6 @@ endif()
 
 message(STATUS "PN_VERSION: ${PN_VERSION} (${PN_VERSION_QUALIFIER})")
 
-enable_testing()
-include (CTest)
 set (pn_test_root "${CMAKE_CURRENT_SOURCE_DIR}/tests")
 set (pn_test_bin "${CMAKE_CURRENT_BINARY_DIR}/tests")
 
@@ -129,9 +155,6 @@ endforeach()
 set (PROTON_SHARE ${SHARE_INSTALL_DIR}/proton-${PN_VERSION})
 # End of variables used during install
 
-# Pull in local cmake modules
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tools/cmake/Modules/")
-
 find_package(Java)
 option (BUILD_JAVA "Build proton-j." ${JAVA_FOUND})
 
@@ -141,17 +164,19 @@ endif()
 
 # Check for valgrind here so tests under proton-c/ and examples/ can use it.
 find_program(VALGRIND_EXE valgrind DOC "Location of the valgrind program")
+mark_as_advanced (VALGRIND_EXE)
+
 option(ENABLE_VALGRIND "Use valgrind to detect run-time problems" ON)
 if (ENABLE_VALGRIND)
   if (NOT VALGRIND_EXE)
     message(STATUS "Can't locate the valgrind command; no run-time error detection")
+  elseif (CMAKE_BUILD_TYPE MATCHES "Coverage")
+    message(STATUS "Building for coverage analysis; no run-time error detection")
   else ()
     set (VALGRIND_ENV "VALGRIND=${VALGRIND_EXE}")
   endif ()
 endif (ENABLE_VALGRIND)
 
-mark_as_advanced (VALGRIND_EXE)
-
 add_subdirectory(proton-c)
 add_subdirectory(examples)
 
@@ -166,11 +191,13 @@ install (DIRECTORY examples
 # add relevant CTest support
 find_program (MAVEN_EXE mvn DOC "Location of the maven program")
 mark_as_advanced (MAVEN_EXE)
-if (JAVA_FOUND AND MAVEN_EXE)
+if (CMAKE_BUILD_TYPE MATCHES "Coverage")
+  message (STATUS "Building for coverage analysis: testing disabled for Proton-J")
+elseif (JAVA_FOUND AND MAVEN_EXE)
   add_test (proton-java ${MAVEN_EXE} clean test --file ${Proton_SOURCE_DIR}/pom.xml)
-else (JAVA_FOUND AND MAVEN_EXE)
+else ()
   message (STATUS "Cannot find both Java and Maven: testing disabled for Proton-J")
-endif (JAVA_FOUND AND MAVEN_EXE)
+endif ()
 
 # Generate test environment settings
 configure_file(${CMAKE_SOURCE_DIR}/config.sh.in

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4d4495cc/bin/record-coverage.sh
----------------------------------------------------------------------
diff --git a/bin/record-coverage.sh b/bin/record-coverage.sh
new file mode 100755
index 0000000..edc903d
--- /dev/null
+++ b/bin/record-coverage.sh
@@ -0,0 +1,60 @@
+# /usr/bin/bash
+
+# This script collates coverage data already present from running instrumented code.
+#
+# It requires the lcov tool to be installed (this provides the lcov and genhtml commands)
+#
+# It will produce a coverage analysis for gcc or clang compiled builds and currently for
+# C and C++ parts of the build tree.
+#
+# It takes two command line arguments:
+# - The first is the proton source tree: this is mandatory.
+# - The second is the build tree: this is optional and if not specified is assumed to be
the
+#   current directory.
+#
+# The output is in the form of an html report which will be found in the generated html direectory.
+# - There will also be a number of intermediate files left in the current directory.
+#
+# The typical way to use it would be to use the "Coverage" build type to get instrumented
+# code, then to run the tests then to extract the coverage information from running the
+# tests.
+# Something like:
+#   cmake $PROTON_SRC -DCMAKE_BUILD_TYPE=Coverage
+#   make
+#   make test
+#   make coverage
+
+# set -x
+
+# get full path
+function getpath {
+  pushd -n $1 > /dev/null
+  echo $(dirs -0 -l)
+  popd -n > /dev/null
+}
+
+SRC=${1?}
+BLD=${2:-.}
+
+BLDPATH=$(getpath $BLD)
+SRCPATH=$(getpath $SRC)
+
+# Get base profile
+# - this initialises 0 counts for every profiled file
+#   without this step any file with no counts at all wouldn't
+#   show up on the final output.
+lcov -c -i -d $BLDPATH -o proton-base.info
+
+# Get actual coverage data
+lcov -c -d $BLDPATH -o proton-ctest.info
+
+# Total them up
+lcov --add proton-base.info --add proton-ctest.info > proton-total-raw.info
+
+# Snip out stuff in /usr (we don't care about coverage in system code)
+lcov --remove proton-total-raw.info "/usr/include*" "/usr/share*" > proton-total.info
+
+# Generate report
+rm -rf html
+genhtml -p $SRCPATH -p $BLDPATH proton-total.info --title "Proton CTest Coverage" --demangle-cpp
-o html
+

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4d4495cc/proton-c/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/proton-c/CMakeLists.txt b/proton-c/CMakeLists.txt
index 4e3fadc..f2a5b76 100644
--- a/proton-c/CMakeLists.txt
+++ b/proton-c/CMakeLists.txt
@@ -528,7 +528,9 @@ if (BUILD_PYTHON)
   option(TOX_TEST "Enable muti-version python testing with TOX" ON)
   if (CMAKE_SYSTEM_NAME STREQUAL Linux AND TOX_TEST)
     find_program(TOX_EXE "tox")
-    if (TOX_EXE)
+    if (CMAKE_BUILD_TYPE MATCHES "Coverage")
+      message(STATUS "Building for coverage analysis; skipping the python-tox-tests")
+    elseif (TOX_EXE)
       configure_file(
         "${CMAKE_CURRENT_SOURCE_DIR}/tox.ini.in"
         "${CMAKE_CURRENT_BINARY_DIR}/tox.ini")
@@ -545,8 +547,8 @@ if (BUILD_PYTHON)
                              PASS_REGULAR_EXPRESSION "Totals: .* ignored, 0 failed"
                              FAIL_REGULAR_EXPRESSION "ERROR:[ ]+py[0-9]*: commands failed")
     else (TOX_EXE)
-      message(STATUS "The tox tool is not available - skipping the python-tox-tests")
-    endif (TOX_EXE)
+      message(STATUS "The tox tool is not available; skipping the python-tox-tests")
+    endif ()
   endif (CMAKE_SYSTEM_NAME STREQUAL Linux AND TOX_TEST)
 
   set (perf_pythonpath "${py_pythonpath}" "${CMAKE_SOURCE_DIR}/examples/cpp")


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message