Skip to content

Commit

Permalink
[feature](selectdb-cloud) be-ut support clang build and coverage (apa…
Browse files Browse the repository at this point in the history
  • Loading branch information
pingchunzhang authored and gavinchou committed Aug 24, 2022
1 parent cc4917f commit 51bf0f1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
5 changes: 5 additions & 0 deletions be/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,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")
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 -lgcov")
Expand Down
11 changes: 1 addition & 10 deletions be/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ CONF_Int32(s3_transfer_executor_pool_size, "2");
CONF_Bool(enable_time_lut, "true");
CONF_Bool(enable_simdjson_reader, "true");

#ifdef BE_TEST
#if defined(BE_TEST) || defined(CLOUD_MODE)
// test s3
CONF_String(test_s3_resource, "resource");
CONF_String(test_s3_ak, "ak");
Expand Down Expand Up @@ -878,15 +878,6 @@ CONF_String(meta_service_endpoint, "");
CONF_Bool(meta_service_use_load_balancer, "true");
CONF_String(tmp_file_dir, "${DORIS_HOME}/storage/tmp");

// test s3
CONF_String(test_s3_resource, "resource");
CONF_String(test_s3_ak, "ak");
CONF_String(test_s3_sk, "sk");
CONF_String(test_s3_endpoint, "endpoint");
CONF_String(test_s3_region, "region");
CONF_String(test_s3_bucket, "bucket");
CONF_String(test_s3_prefix, "prefix");

} // namespace config

} // namespace doris
29 changes: 26 additions & 3 deletions run-be-ut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Usage: $0 <options>
--benchmark build benchmark-tool
--clean clean and build ut
--run build and run all ut
--coverage coverage after run ut
--run --filter=xx build and run specified ut
-j build parallel
-h print this help message
Expand All @@ -61,11 +62,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 @@ -79,7 +81,8 @@ fi

CLEAN=0
RUN=0
BUILD_BENCHMARK_TOOL='OFF'
BUILD_BENCHMARK_TOOL=OFF
DENABLE_CLANG_COVERAGE=OFF
FILTER=""
if [[ "$#" != 1 ]]; then
while true; do
Expand All @@ -96,6 +99,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 @@ -126,6 +133,10 @@ echo "Get params:
"
echo "Build Backend UT"

if [[ "_${DENABLE_CLANG_COVERAGE}" == "_ON" ]]; then
sed -i "s/ DORIS_TOOLCHAIN=gcc/ DORIS_TOOLCHAIN=clang/g" env.sh
fi

. "${DORIS_HOME}/env.sh"

CMAKE_BUILD_DIR="${DORIS_HOME}/be/ut_build_${CMAKE_BUILD_TYPE}"
Expand Down Expand Up @@ -167,6 +178,7 @@ cd "${CMAKE_BUILD_DIR}"
-DSTRICT_MEMORY_USE=OFF \
-DEXTRA_CXX_FLAGS="${EXTRA_CXX_FLAGS}" \
${CMAKE_USE_CCACHE:+${CMAKE_USE_CCACHE}} \
-DENABLE_CLANG_COVERAGE=${DENABLE_CLANG_COVERAGE} \
"${DORIS_HOME}/be"
"${BUILD_SYSTEM}" -j "${PARALLEL}"

Expand All @@ -175,6 +187,12 @@ if [[ "${RUN}" -ne 1 ]]; then
exit 0
fi

#recover dufault build tool to gcc
cd ${DORIS_HOME}
if [[ "_${DENABLE_CLANG_COVERAGE}" == "_ON" ]]; then
sed -i "s/ DORIS_TOOLCHAIN=clang/ DORIS_TOOLCHAIN=gcc/g" env.sh
fi

echo "******************************"
echo " Running Backend Unit Test "
echo "******************************"
Expand Down Expand Up @@ -267,9 +285,14 @@ if [ "${CLOUD_MODE}" == "ON" ]; then
else
test=${DORIS_TEST_BINARY_DIR}/doris_be_test
fi
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 51bf0f1

Please sign in to comment.