Update cmake files and wamr-test-suites to support collect code coverage (#1992)
Support collecting code coverage with wamr-test-suites script by using lcov and genhtml tools, eg.: cd tests/wamr-test-suites ./test_wamr.sh -s spec -b -P -C The default code coverage and html files are generated at: tests/wamr-test-suites/workspace/wamr.lcov tests/wamr-test-suites/workspace/wamr-lcov.zip And update wamr-test-suites scripts to support testing GC spec cases to avoid frequent synchronization conflicts between branch main and dev/gc.
This commit is contained in:
80
tests/wamr-test-suites/spec-test-script/collect_coverage.sh
Executable file
80
tests/wamr-test-suites/spec-test-script/collect_coverage.sh
Executable file
@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
readonly WORK_DIR=$PWD
|
||||
readonly WAMR_DIR=${WORK_DIR}/../../..
|
||||
readonly DST_COV_FILE=$1
|
||||
readonly SRC_COV_DIR=$2
|
||||
readonly SRC_TEMP_COV_FILE=wamr_temp.lcov
|
||||
readonly SRC_COV_FILE=wamr.lcov
|
||||
|
||||
# get dest folder
|
||||
dir=$(dirname ${DST_COV_FILE})
|
||||
pushd ${dir} > /dev/null 2>&1
|
||||
readonly DST_COV_DIR=${PWD}
|
||||
popd > /dev/null 2>&1
|
||||
|
||||
if [[ ! -d ${SRC_COV_DIR} ]]; then
|
||||
echo "${SRC_COV_DIR} doesn't exist, ignore code coverage collection"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "Start to collect code coverage of ${SRC_COV_DIR} .."
|
||||
|
||||
pushd ${SRC_COV_DIR} > /dev/null 2>&1
|
||||
|
||||
# collect all code coverage data
|
||||
lcov -o ${SRC_TEMP_COV_FILE} -c -d . --rc lcov_branch_coverage=1
|
||||
# extract code coverage data of WAMR source files
|
||||
lcov -r ${SRC_TEMP_COV_FILE} -o ${SRC_TEMP_COV_FILE} \
|
||||
-rc lcov_branch_coverage=1 \
|
||||
"*/usr/*" "*/_deps/*" "*/deps/*" "*/tests/unit/*" \
|
||||
"*/llvm/include/*" "*/include/llvm/*" "*/samples/*" \
|
||||
"*/app-framework/*" "*/test-tools/*"
|
||||
|
||||
if [[ -s ${SRC_TEMP_COV_FILE} ]]; then
|
||||
if [[ -s ${DST_COV_FILE} ]]; then
|
||||
# merge code coverage data
|
||||
lcov --rc lcov_branch_coverage=1 \
|
||||
--add-tracefile ${SRC_TEMP_COV_FILE} \
|
||||
-a ${DST_COV_FILE} -o ${SRC_COV_FILE}
|
||||
# backup the original lcov file
|
||||
cp -a ${DST_COV_FILE} "${DST_COV_FILE}.orig"
|
||||
# replace the lcov file
|
||||
cp -a ${SRC_COV_FILE} ${DST_COV_FILE}
|
||||
else
|
||||
cp -a ${SRC_TEMP_COV_FILE} ${SRC_COV_FILE}
|
||||
cp -a ${SRC_COV_FILE} ${DST_COV_FILE}
|
||||
fi
|
||||
|
||||
# get ignored prefix path
|
||||
dir=$(dirname ${WAMR_DIR}/../..)
|
||||
pushd ${dir} > /dev/null 2>&1
|
||||
prefix_full_path=${PWD}
|
||||
popd > /dev/null 2>&1
|
||||
|
||||
# generate html output for merged code coverage data
|
||||
rm -fr ${DST_COV_DIR}/wamr-lcov
|
||||
genhtml -t "WAMR Code Coverage" \
|
||||
--rc lcov_branch_coverage=1 --prefix=${prefix_full_path} \
|
||||
-o ${DST_COV_DIR}/wamr-lcov \
|
||||
${DST_COV_FILE}
|
||||
|
||||
cd ${DST_COV_DIR}
|
||||
rm -f wamr-lcov.zip
|
||||
zip -r -q -o wamr-lcov.zip wamr-lcov
|
||||
rm -fr wamr-lcov
|
||||
|
||||
echo "Code coverage file ${DST_COV_FILE} was generated or appended"
|
||||
echo "Code coverage html ${DST_COV_DIR}/wamr-lcov.zip was generated"
|
||||
else
|
||||
echo "generate code coverage html failed"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
popd > /dev/null 2>&1
|
||||
Reference in New Issue
Block a user