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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit e2bbd2efef0c069bdadc91c2cdf537a2805b0217
Author: chunping <[email protected]>
AuthorDate: Thu Mar 23 12:07:19 2023 +0800

    [improvement](coverage) build be with coverage enabled, which can get 
coverage data with llvm-cov-15 (#17995)
---
 be/CMakeLists.txt |  5 +++++
 build.sh          |  9 +++++++++
 run-be-ut.sh      | 22 ++++++++++++++++++++--
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/be/CMakeLists.txt b/be/CMakeLists.txt
index aedb3a97b7..114e7be057 100644
--- a/be/CMakeLists.txt
+++ b/be/CMakeLists.txt
@@ -856,6 +856,11 @@ endif()
 # Only build static libs
 set(BUILD_SHARED_LIBS OFF)
 
+option(ENABLE_CLANG_COVERAGE "coverage option" OFF)
+if (ENABLE_CLANG_COVERAGE AND ENABLE_CLANG_COVERAGE STREQUAL ON AND 
COMPILER_CLANG)
+    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate 
-fcoverage-mapping")
+endif ()
+
 if (${MAKE_TEST} STREQUAL "ON")
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage 
-DGTEST_USE_OWN_TR1_TUPLE=0")
     SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs 
-ftest-coverage")
diff --git a/build.sh b/build.sh
index 17f6b96ea6..9eaa16d8b6 100755
--- a/build.sh
+++ b/build.sh
@@ -63,6 +63,7 @@ Usage: $0 <options>
     $0 --spark-dpp                          build Spark DPP application alone
     $0 --broker                             build Broker
     $0 --be --fe                            build Backend, Frontend, Spark Dpp 
application and Java UDF library
+    $0 --be --coverage                      build Backend with coverage enabled
 
     USE_AVX2=0 $0 --be                      build Backend and not using AVX2 
instruction.
     USE_AVX2=0 STRIP_DEBUG_INFO=ON $0       build all and not using AVX2 
instruction, and strip the debug info for Backend
@@ -115,6 +116,7 @@ if ! OPTS="$(getopt \
     -l 'spark-dpp' \
     -l 'hive-udf' \
     -l 'clean' \
+    -l 'coverage' \
     -l 'help' \
     -o 'hj:' \
     -- "$@")"; then
@@ -136,6 +138,7 @@ CLEAN=0
 HELP=0
 PARAMETER_COUNT="$#"
 PARAMETER_FLAG=0
+DENABLE_CLANG_COVERAGE='OFF'
 if [[ "$#" == 1 ]]; then
     # default
     BUILD_FE=1
@@ -186,6 +189,10 @@ else
             CLEAN=1
             shift
             ;;
+        --coverage)
+            DENABLE_CLANG_COVERAGE='ON'
+            shift
+            ;;
         -h)
             HELP=1
             shift
@@ -350,6 +357,7 @@ echo "Get params:
     USE_JEMALLOC        -- ${USE_JEMALLOC}
     STRICT_MEMORY_USE   -- ${STRICT_MEMORY_USE}
     ENABLE_STACKTRACE   -- ${ENABLE_STACKTRACE}
+    DENABLE_CLANG_COVERAGE -- ${DENABLE_CLANG_COVERAGE}
 "
 
 # Clean and build generated code
@@ -424,6 +432,7 @@ if [[ "${BUILD_BE}" -eq 1 ]]; then
         -DUSE_AVX2="${USE_AVX2}" \
         -DGLIBC_COMPATIBILITY="${GLIBC_COMPATIBILITY}" \
         -DEXTRA_CXX_FLAGS="${EXTRA_CXX_FLAGS}" \
+        -DENABLE_CLANG_COVERAGE="${DENABLE_CLANG_COVERAGE}" \
         "${DORIS_HOME}/be"
     "${BUILD_SYSTEM}" -j "${PARALLEL}"
     "${BUILD_SYSTEM}" install
diff --git a/run-be-ut.sh b/run-be-ut.sh
index eb695545dc..91cf61148a 100755
--- a/run-be-ut.sh
+++ b/run-be-ut.sh
@@ -50,6 +50,7 @@ Usage: $0 <options>
      --clean            clean and build ut
      --run              build and run all ut
      --run --filter=xx  build and run specified ut
+     --coverage         coverage after run ut
      -j                 build parallel
      -h                 print this help message
 
@@ -64,11 +65,12 @@ Usage: $0 <options>
     $0 --run --filter=FooTest.*:BarTest.*-FooTest.Bar:BarTest.Foo   runs 
everything in test suite FooTest except FooTest.Bar and everything in test 
suite BarTest except BarTest.Foo
     $0 --clean                                                      clean and 
build tests
     $0 --clean --run                                                clean, 
build and run all tests
+    $0 --clean --run --coverage                                     clean, 
build, run all tests and coverage
   "
     exit 1
 }
 
-if ! OPTS="$(getopt -n "$0" -o vhj:f: -l benchmark,run,clean,filter: -- 
"$@")"; then
+if ! OPTS="$(getopt -n "$0" -o vhj:f: -l coverage,benchmark,run,clean,filter: 
-- "$@")"; then
     usage
 fi
 
@@ -77,6 +79,7 @@ eval set -- "${OPTS}"
 CLEAN=0
 RUN=0
 BUILD_BENCHMARK_TOOL='OFF'
+DENABLE_CLANG_COVERAGE='OFF'
 FILTER=""
 if [[ "$#" != 1 ]]; then
     while true; do
@@ -93,6 +96,10 @@ if [[ "$#" != 1 ]]; then
             BUILD_BENCHMARK_TOOL='ON'
             shift
             ;;
+        --coverage)
+            DENABLE_CLANG_COVERAGE='ON'
+            shift
+            ;;
         -f | --filter)
             FILTER="--gtest_filter=$2"
             shift 2
@@ -125,6 +132,10 @@ echo "Get params:
 "
 echo "Build Backend UT"
 
+if [[ "_${DENABLE_CLANG_COVERAGE}" == "_ON" ]]; then
+    echo "export DORIS_TOOLCHAIN=clang" >>custom_env.sh
+fi
+
 CMAKE_BUILD_DIR="${DORIS_HOME}/be/ut_build_${CMAKE_BUILD_TYPE}"
 if [[ "${CLEAN}" -eq 1 ]]; then
     pushd "${DORIS_HOME}/gensrc"
@@ -187,6 +198,7 @@ cd "${CMAKE_BUILD_DIR}"
     -DUSE_JEMALLOC=OFF \
     -DSTRICT_MEMORY_USE=OFF \
     -DEXTRA_CXX_FLAGS="${EXTRA_CXX_FLAGS}" \
+    -DENABLE_CLANG_COVERAGE="${DENABLE_CLANG_COVERAGE}" \
     ${CMAKE_USE_CCACHE:+${CMAKE_USE_CCACHE}} \
     "${DORIS_HOME}/be"
 "${BUILD_SYSTEM}" -j "${PARALLEL}"
@@ -267,9 +279,15 @@ export UBSAN_OPTIONS=print_stacktrace=1
 
 # find all executable test files
 test="${DORIS_TEST_BINARY_DIR}/doris_be_test"
+profraw=${DORIS_TEST_BINARY_DIR}/doris_be_test.profraw
+
 file_name="${test##*/}"
 if [[ -f "${test}" ]]; then
-    "${test}" --gtest_output="xml:${GTEST_OUTPUT_DIR}/${file_name}.xml" 
--gtest_print_time=true "${FILTER}"
+    if [[ "_${DENABLE_CLANG_COVERAGE}" == "_ON" ]]; then
+        LLVM_PROFILE_FILE="${profraw}" "${test}" 
--gtest_output="xml:${GTEST_OUTPUT_DIR}/${file_name}.xml" 
--gtest_print_time=true "${FILTER}"
+    else
+        "${test}" --gtest_output="xml:${GTEST_OUTPUT_DIR}/${file_name}.xml" 
--gtest_print_time=true "${FILTER}"
+    fi
     echo "=== Finished. Gtest output: ${GTEST_OUTPUT_DIR}"
 else
     echo "unit test file: ${test} does not exist."


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to