Skip to content

Commit

Permalink
[improvement](coverage) build be with coverage enabled, which can get…
Browse files Browse the repository at this point in the history
… coverage data with llvm-cov-15 (apache#17995)
  • Loading branch information
pingchunzhang authored Mar 23, 2023
1 parent 3870689 commit 0bb04c0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions be/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,11 @@ set (TEST_LINK_LIBS ${DORIS_LINK_LIBS}
# 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")
add_compile_options(-fprofile-arcs -ftest-coverage -DGTEST_USE_OWN_TR1_TUPLE=0)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
Expand Down
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -115,6 +116,7 @@ if ! OPTS="$(getopt \
-l 'spark-dpp' \
-l 'hive-udf' \
-l 'clean' \
-l 'coverage' \
-l 'help' \
-o 'hj:' \
-- "$@")"; then
Expand All @@ -136,6 +138,7 @@ CLEAN=0
HELP=0
PARAMETER_COUNT="$#"
PARAMETER_FLAG=0
DENABLE_CLANG_COVERAGE='OFF'
if [[ "$#" == 1 ]]; then
# default
BUILD_FE=1
Expand Down Expand Up @@ -186,6 +189,10 @@ else
CLEAN=1
shift
;;
--coverage)
DENABLE_CLANG_COVERAGE='ON'
shift
;;
-h)
HELP=1
shift
Expand Down Expand Up @@ -358,6 +365,7 @@ echo "Get params:
USE_BTHREAD_SCANNER -- ${USE_BTHREAD_SCANNER}
STRICT_MEMORY_USE -- ${STRICT_MEMORY_USE}
ENABLE_STACKTRACE -- ${ENABLE_STACKTRACE}
DENABLE_CLANG_COVERAGE -- ${DENABLE_CLANG_COVERAGE}
"

# Clean and build generated code
Expand Down Expand Up @@ -433,6 +441,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"

if [[ "${OUTPUT_BE_BINARY}" -eq 1 ]]; then
Expand Down
22 changes: 20 additions & 2 deletions run-be-ut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit 0bb04c0

Please sign in to comment.