aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/run-sonar.sh
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2022-08-29 18:12:50 +0000
committerMauro Sardara <msardara@cisco.com>2022-08-30 08:06:05 +0000
commit8d7d5327ca86871cdf1d2ce404ca88bb2a58630f (patch)
treedf6c107de0982b0a894616f890709fb68731348d /scripts/run-sonar.sh
parent1d07ab7765be14382f8b711f4211fffb2518581a (diff)
ci(sonar): add test coverage in sonar cloud
Ref: HICN-749 Change-Id: I1523b548df9254949d164b995d24c0210252809f Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'scripts/run-sonar.sh')
-rwxr-xr-xscripts/run-sonar.sh47
1 files changed, 44 insertions, 3 deletions
diff --git a/scripts/run-sonar.sh b/scripts/run-sonar.sh
index 38547bbcf..3d386bbfc 100755
--- a/scripts/run-sonar.sh
+++ b/scripts/run-sonar.sh
@@ -22,12 +22,53 @@ cd /workspace
git config --global --add safe.directory /workspace
git config --global --add safe.directory /workspace/cmake
-export SONAR_BUILD_WRAPPER=$HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64
-make SONAR_OUT_DIR=bw-output build-coverage
+BUILD_PATH=${PWD}/build-debug
+TEST_PATH="${BUILD_PATH}/build-root/bin"
+
+make SONAR_BUILD_WRAPPER=${HOME}/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 SONAR_OUT_DIR=bw-output BUILD_PATH=${BUILD_PATH} wipe build-coverage
+
+# Run tests to compute test coverage
+pushd ${BUILD_PATH}
+
+declare -a TEST_COMPONENTS=(
+ "libtransport"
+ "lib"
+ "hicn_light"
+ "hicnplugin"
+ "libhicnctrl"
+)
+
+# Save first test executable
+FIRST_COMPONENT="${TEST_COMPONENTS[0]}"
+FIRST_TEST="${TEST_PATH}/${FIRST_COMPONENT}_tests"
+
+# Iterate over all tests: build parameters for next tests and get .profraw data
+extension=".profraw"
+PROFRAW_FILES=""
+REMAINING_TESTS=""
+for component in "${TEST_COMPONENTS[@]}"; do
+ # Build PROFRAW parameters for next command
+ PROFRAW_FILES="${PROFRAW_FILES}${component}${extension} "
+
+ # Save if not first binary
+ [[ "${component}" != "${FIRST_COMPONENT}" ]] && REMAINING_TESTS="${REMAINING_TESTS} -object ${TEST_PATH}/${component}_tests"
+
+ # Generate profraw data
+ LLVM_PROFILE_FILE="${BUILD_PATH}/${component}${extension}" ${TEST_PATH}/${component}_tests
+done
+
+# Merge profraw files
+llvm-profdata-11 merge -sparse ${PROFRAW_FILES} -o hicn.profdata
+
+# Generate coverage report
+llvm-cov-11 show ${FIRST_TEST} ${REMAINING_TESTS} -instr-profile=hicn.profdata --format=text > ${BUILD_PATH}/coverage.txt
+
+popd
$SONAR_SCANNER_HOME/bin/sonar-scanner \
-Dsonar.organization=$PROJECT_ORGANIZATION \
-Dsonar.projectKey=$PROJECT_KEY \
-Dsonar.sources=/workspace \
-Dsonar.cfamily.build-wrapper-output=bw-output \
- -Dsonar.host.url=$SONAR_HOST_URL
+ -Dsonar.host.url=$SONAR_HOST_URL \
+ -Dsonar.cfamily.llvm-cov.reportPath=${BUILD_PATH}/coverage.txt