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

jackietien pushed a commit to branch iotdb
in repository https://gitbox.apache.org/repos/asf/tsfile.git

commit b45db1002d62572fbee6ad4f1e9f5f1fcb2e63f7
Author: Haonan <[email protected]>
AuthorDate: Thu Aug 1 21:17:23 2024 +0800

    Generate code coverage report for c++ code (#191)
---
 .github/workflows/code-coverage.yml | 13 +++++++++----
 codecov.yml                         |  7 +++++++
 cpp/CMakeLists.txt                  | 10 +++++++---
 cpp/pom.xml                         | 10 ++++++++++
 cpp/src/CMakeLists.txt              | 11 ++++++++---
 cpp/test/CMakeLists.txt             |  7 ++++++-
 6 files changed, 47 insertions(+), 11 deletions(-)

diff --git a/.github/workflows/code-coverage.yml 
b/.github/workflows/code-coverage.yml
index 29076c3c..f1a4f116 100644
--- a/.github/workflows/code-coverage.yml
+++ b/.github/workflows/code-coverage.yml
@@ -24,12 +24,17 @@ jobs:
           path: ~/.m2
           key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
           restore-keys: ${{ runner.os }}-m2-
-      - name: Test
+      - name: Generate code coverage reports
         run: |
-          ./mvnw -B -P with-java,with-cpp,with-python,with-code-coverage clean 
verify
-          ./mvnw -B -P with-code-coverage post-integration-test
+          sudo apt-get install lcov
+          ./mvnw -B -P with-java,with-cpp,with-code-coverage clean verify
+          lcov --capture --directory cpp/target/build/test --output-file 
cpp/target/build/test/coverage.info
+          lcov --remove cpp/target/build/test/coverage.info 
'*/tsfile/cpp/test/*' --output-file cpp/target/build/test/coverage_filtered.info
+          genhtml cpp/target/build/test/coverage_filtered.info 
--output-directory cpp/target/build/test/coverage_report
+          rm -rf cpp/target/build/test/CMakeFiles/TsFile_Test.dir
+          rm -rf cpp/target/build/test/coverage.info
       - name: Upload coverage reports to codecov
         uses: codecov/codecov-action@v4
         with:
           token: ${{ secrets.CODECOV_TOKEN }}
-          files: ./code-coverage/target/jacoco-merged-reports/jacoco.xml
+          files: 
code-coverage/target/jacoco-merged-reports/jacoco.xml,cpp/target/build/test/coverage_report/index.html
diff --git a/codecov.yml b/codecov.yml
index aefe55fa..7c21286f 100644
--- a/codecov.yml
+++ b/codecov.yml
@@ -30,6 +30,12 @@ coverage:
 parsers:
   jacoco:
     partials_as_hits: true #false by default
+  gcov:
+    branch_detection:
+      conditional: yes
+      loop: yes
+      method: no
+      macro: no
 
 ignore:
   - "**/pom.xml"
@@ -38,6 +44,7 @@ ignore:
   - "**/*.cmd"
   - "**/*.bat"
   - "**/*.yml"
+  - "*_test.cc"
   - ".mvn"
   - "mvnw"
   - "NOTICE"
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index afca5202..185b3905 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -33,7 +33,7 @@ if(DEFINED ENV{CXX})
     message("cmake using: CXX=${CMAKE_CXX_COMPILER}")
 endif()
 
-if(DEFINED ENV{CC}) 
+if(DEFINED ENV{CC})
   set(CMAKE_C_COMPILER $ENV{CC})
   message("cmake using: CC=${CMAKE_C_COMPILER}")
 endif()
@@ -44,6 +44,11 @@ if (${DEBUG_SE})
   message("add_definitions -DDEBUG_SE=1")
 endif()
 
+if (${COV_ENABLED})
+  add_definitions(-DCOV_ENABLED=1)
+  message("add_definitions -DCOV_ENABLED=1")
+endif()
+
 message("build type: ${BUILD_TYPE}")
 if (CMAKE_BUILD_TYPE STREQUAL "Debug")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
@@ -74,8 +79,7 @@ configure_file(
   "${PROJECT_BINARY_DIR}/cmake_config.h"
 )
 
-set(TESTS_ENABLED OFF)
 add_subdirectory(test)
 if(TESTS_ENABLED)
     add_dependencies(TsFile_Test tsfile)
-endif()
\ No newline at end of file
+endif()
diff --git a/cpp/pom.xml b/cpp/pom.xml
index faad3610..2527014d 100644
--- a/cpp/pom.xml
+++ b/cpp/pom.xml
@@ -32,6 +32,7 @@
         <!-- Tell Sonar where to find the sources -->
         <sonar.sources>common,examples,tsfile</sonar.sources>
         
<sonar.cfamily.build-wrapper-output>${project.build.directory}/build-wrapper-output</sonar.cfamily.build-wrapper-output>
+        <cmake.addition.option>-DCOV_ENABLED=OFF</cmake.addition.option>
     </properties>
     <build>
         <sourceDirectory>${project.basedir}</sourceDirectory>
@@ -69,7 +70,10 @@
                         <configuration>
                             <options>
                                 <option>-DBUILD_PHASE=test-compile</option>
+                                <option>${cmake.addition.option}</option>
                             </options>
+                            <sourcePath/>
+                            <targetPath/>
                         </configuration>
                     </execution>
                     <!-- Compile the test code -->
@@ -119,6 +123,12 @@
         </plugins>
     </build>
     <profiles>
+        <profile>
+            <id>with-code-coverage</id>
+            <properties>
+                <cmake.addition.option>-DCOV_ENABLED=ON</cmake.addition.option>
+            </properties>
+        </profile>
         <!-- When running on jenkins, download the sonar build-wrapper, so we 
can do a code analysis -->
         <profile>
             <id>jenkins-build</id>
diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt
index 9f323c77..ec07d19a 100644
--- a/cpp/src/CMakeLists.txt
+++ b/cpp/src/CMakeLists.txt
@@ -18,7 +18,6 @@ under the License.
 ]]
 message("Running in src diectory")
 include(${PROJECT_SOURCE_DIR}/cmake/build_function.cmake)
-
 add_subdirectory(common)
 add_subdirectory(compress)
 add_subdirectory(cwrapper)
@@ -29,7 +28,13 @@ add_subdirectory(utils)
 add_subdirectory(writer)
 
 add_library(tsfile SHARED)
-target_link_libraries(tsfile common_obj compress_obj cwrapper_obj file_obj 
read_obj write_obj )
+if (${COV_ENABLED})
+    message("Enable code cov...")
+    target_link_libraries(tsfile common_obj compress_obj cwrapper_obj file_obj 
read_obj write_obj -lgcov)
+else()
+    message("Disable code cov...")
+    target_link_libraries(tsfile common_obj compress_obj cwrapper_obj file_obj 
read_obj write_obj)
+endif()
 
 set(LIBTSFILE_PROJECT_VERSION 1.0)
 set(LIBTSFILE_SO_VERSION 1.0)
@@ -53,4 +58,4 @@ install(TARGETS tsfile LIBRARY DESTINATION 
${LIBTSFILE_SDK_DIR})
 # if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
 #   add_custom_command(TARGET tsfile POST_BUILD COMMAND 
${CMAKE_INSTALL_NAME_TOOL} -change `otool -L 
${LIBRARY_OUTPUT_PATH}/libtsfile.dylib | grep liblz4 | sed 's/dylib.*/dylib/g'` 
${my_lz4_lib} ${LIBRARY_OUTPUT_PATH}/libtsfile.dylib)
 #   add_custom_command(TARGET tsfile POST_BUILD COMMAND 
${CMAKE_INSTALL_NAME_TOOL} -change `otool -L 
${LIBRARY_OUTPUT_PATH}/libtsfile.dylib | grep libz | sed 's/dylib.*/dylib/g'` 
${my_z_lib} ${LIBRARY_OUTPUT_PATH}/libtsfile.dylib)
-# endif()
\ No newline at end of file
+# endif()
diff --git a/cpp/test/CMakeLists.txt b/cpp/test/CMakeLists.txt
index 91fa71c5..df6d3015 100644
--- a/cpp/test/CMakeLists.txt
+++ b/cpp/test/CMakeLists.txt
@@ -74,6 +74,11 @@ file(GLOB_RECURSE TEST_SRCS
         "compress/*_test.cc"
         "writer/*_test.cc"
         )
+if (${COV_ENABLED})
+    message("Enable code cov...")
+    add_compile_options(-fprofile-arcs -ftest-coverage)
+endif ()
+
 add_executable(TsFile_Test ${TEST_SRCS})
 target_link_libraries(
   TsFile_Test
@@ -84,4 +89,4 @@ target_link_libraries(
 set_target_properties(TsFile_Test PROPERTIES RUNTIME_OUTPUT_DIRECTORY 
${LIBTSFILE_SDK_DIR})
 
 include(GoogleTest)
-gtest_discover_tests(TsFile_Test)
\ No newline at end of file
+gtest_discover_tests(TsFile_Test)

Reply via email to