This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git


The following commit(s) were added to refs/heads/main by this push:
     new 2be26ea75 PROTON-2882: Improve the coverage report
2be26ea75 is described below

commit 2be26ea75eb197c74851a70acf364518526afee7
Author: Andrew Stitcher <astitc...@apache.org>
AuthorDate: Tue Apr 1 13:08:20 2025 -0400

    PROTON-2882: Improve the coverage report
    
    Make the fuzz testers use files from the source tree not the build tree.
    Include the python coverage into the report.
    Move the ruby coverage results into the coverage_reports directory.
    Restructure the build so that profiling with other compilers (than gcc)
    with different flags is possible.
---
 CMakeLists.txt              | 35 +++++++++++++++++++++++------------
 c/tests/fuzz/CMakeLists.txt | 13 +++++++------
 python/CMakeLists.txt       | 15 +++++++++++++--
 ruby/CMakeLists.txt         |  2 +-
 scripts/record-coverage.sh  |  8 ++++----
 5 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d03973235..5ddc9fe4b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -103,18 +103,26 @@ else (CMAKE_CONFIGURATION_TYPES)
        "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 -fprofile-update=atomic")
-    set (CMAKE_CXX_FLAGS_COVERAGE "-g -O0 --coverage -fprofile-update=atomic ")
-    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()
+  # Set up extra coverage analysis options for gcc (-Og is now the recommended 
optimization level for debugging)
+  # See https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
+  set (COVERAGE_COMPILE_FLAGS_GNU "-g -Og --coverage -fprofile-update=atomic")
+  set (COVERAGE_LINK_FLAGS_GNU "--coverage")
+
+  set (CMAKE_C_FLAGS_COVERAGE 
"${COVERAGE_COMPILE_FLAGS_${CMAKE_C_COMPILER_ID}}" CACHE STRING
+       "Flags used by the C compiler during COVERAGE builds." FORCE)
+  set (CMAKE_CXX_FLAGS_COVERAGE 
"${COVERAGE_COMPILE_FLAGS_${CMAKE_CXX_COMPILER_ID}}" CACHE STRING
+       "Flags used by the CXX compiler during COVERAGE builds." FORCE)
+  set (CMAKE_EXE_LINKER_FLAGS_COVERAGE 
"${COVERAGE_LINK_FLAGS_${CMAKE_C_COMPILER_ID}}" CACHE STRING
+       "Flags used by the linker during COVERAGE builds." FORCE)
+  set (CMAKE_MODULE_LINKER_FLAGS_COVERAGE 
"${COVERAGE_LINK_FLAGS_${CMAKE_C_COMPILER_ID}}" CACHE STRING
+       "Flags used by the linker during the creation of modules during 
COVERAGE builds." FORCE)
+  set (CMAKE_SHARED_LINKER_FLAGS_COVERAGE 
"${COVERAGE_LINK_FLAGS_${CMAKE_C_COMPILER_ID}}" CACHE STRING
+       "Flags used by the linker during the creation of shared libraries 
during COVERAGE builds." FORCE)
+
+  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)
 
   if (CMAKE_BUILD_TYPE MATCHES "Deb")
     set (has_debug_symbols " (has debug symbols)")
@@ -128,6 +136,9 @@ if (CMAKE_BUILD_TYPE MATCHES "Coverage")
   add_custom_target(coverage
     WORKING_DIRECTORY ./coverage_results
     COMMAND ${PROJECT_SOURCE_DIR}/scripts/record-coverage.sh 
${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
+  if (BUILD_PYTHON)
+    add_dependencies(coverage python-coverage)
+  endif()
 endif()
 
 # Try to keep any platform specific overrides together here:
diff --git a/c/tests/fuzz/CMakeLists.txt b/c/tests/fuzz/CMakeLists.txt
index 16080ab1c..ebe22add2 100644
--- a/c/tests/fuzz/CMakeLists.txt
+++ b/c/tests/fuzz/CMakeLists.txt
@@ -17,6 +17,7 @@
 # under the License.
 #
 
+set(C_SOURCE_DIR "${PROJECT_SOURCE_DIR}/c/src")
 add_definitions(${C_STANDARD_FLAGS} ${COMPILE_WARNING_FLAGS})
 
 option(FUZZ_REGRESSION_TESTS "Run fuzz tests with regression test driver" ON)
@@ -83,11 +84,11 @@ target_link_libraries (fuzz-message-decode 
${FUZZING_QPID_PROTON_CORE_LIBRARY})
 # pn_url_parse is not in proton core and is only used by messenger so compile 
specially
 pn_add_fuzz_test (fuzz-url
   fuzz-url.c
-  ${PN_C_SOURCE_DIR}/extra/url.c
-  ${PN_C_SOURCE_DIR}/core/object/object.c
-  ${PN_C_SOURCE_DIR}/core/object/string.c
-  ${PN_C_SOURCE_DIR}/core/util.c
-  ${PN_C_SOURCE_DIR}/core/memory.c)
+  ${C_SOURCE_DIR}/extra/url.c
+  ${C_SOURCE_DIR}/core/object/object.c
+  ${C_SOURCE_DIR}/core/object/string.c
+  ${C_SOURCE_DIR}/core/util.c
+  ${C_SOURCE_DIR}/core/memory.c)
 target_compile_definitions(fuzz-url PRIVATE PROTON_DECLARE_STATIC)
 
 # This regression test can take a very long time so don't run by default
@@ -99,4 +100,4 @@ endif()
 # Fuzz tests of internals
 
 # pni_sniff_header is internal so it has to be compiled specially
-pn_add_fuzz_test (fuzz-sniff-header fuzz-sniff-header.c 
${PN_C_SOURCE_DIR}/core/autodetect.c)
+pn_add_fuzz_test (fuzz-sniff-header fuzz-sniff-header.c 
${C_SOURCE_DIR}/core/autodetect.c)
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 1cc04f235..436719c9c 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -204,7 +204,7 @@ if (BUILD_TESTING)
 
   if (CMAKE_BUILD_TYPE MATCHES "Coverage")
     set (python_coverage_module "coverage")
-    set (python_coverage_options -m ${python_coverage_module} run 
--parallel-mode)
+    set (python_coverage_options -m ${python_coverage_module} run --branch 
--parallel-mode)
   endif(CMAKE_BUILD_TYPE MATCHES "Coverage")
 
   if (ENABLE_PYTHON_ISOLATED)
@@ -249,7 +249,18 @@ if (BUILD_TESTING)
     add_custom_target(pytest_cffi ALL DEPENDS .timestamp.test_env)
   endif()
 
-
+  # If we are doing coverage, then post process the python coverage data 
before running the coverage target
+  if (CMAKE_BUILD_TYPE MATCHES "Coverage")
+    add_custom_command(
+      OUTPUT ../coverage_results/python.info
+      DEPENDS pytest_cffi
+      COMMAND ${pytest_executable} -m coverage combine --append
+      COMMAND ${pytest_executable} -m coverage lcov -o 
../coverage_results/python.info
+    )
+    add_custom_target(python-coverage
+      DEPENDS ../coverage_results/python.info
+    )
+  endif()
 
   if (TARGET pytest_cffi)
     # If we are on windows copy the qpid-proton-core dll to the test directory 
so we can find it easily
diff --git a/ruby/CMakeLists.txt b/ruby/CMakeLists.txt
index 14e483a58..8eafc751b 100644
--- a/ruby/CMakeLists.txt
+++ b/ruby/CMakeLists.txt
@@ -103,7 +103,7 @@ if (result EQUAL 0)  # Have minitest
     "PATH=${PATH}"
     "RUBYLIB=${RUBYLIB}"
     "${COVERAGE}"
-    "COVERAGE_DIR=${CMAKE_CURRENT_BINARY_DIR}/coverage"
+    "COVERAGE_DIR=${PROJECT_BINARY_DIR}/coverage_results/ruby"
     "SASLPASSWD=${CyrusSASL_Saslpasswd_EXECUTABLE}")
 
   macro(add_ruby_test script)
diff --git a/scripts/record-coverage.sh b/scripts/record-coverage.sh
index 619d5b996..079ed67cc 100755
--- a/scripts/record-coverage.sh
+++ b/scripts/record-coverage.sh
@@ -48,13 +48,13 @@ 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
+# Total them up (ignore empty files in case we don't have any python info)
+lcov --ignore-errors empty --add proton-base.info --add proton-ctest.info 
--add python.info -o proton-total-raw.info
 
 # Snip out stuff in /usr (we don't care about coverage in system code) & in 
unit test framework
-lcov --ignore-errors unused --remove proton-total-raw.info "/usr/include*" 
"/usr/share*" "tests/include/*"> proton-total.info
+lcov --ignore-errors unused --remove proton-total-raw.info "/usr/include*" 
"/usr/share*" "tests/include/*" -o proton-total.info
 
 # Generate report
 rm -rf html
-genhtml -p $SRCPATH -p $BLDPATH proton-total.info --title "Proton CTest 
Coverage" --demangle-cpp -o html
+genhtml -p $SRCPATH -p $(dirname $BLDPATH) --source-directory $SRCPATH/python 
proton-total.info --title "Proton CTest Coverage" --demangle-cpp -o html
 


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

Reply via email to