Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ tmp/
*.zip
*.tar.gz
models
genhtml
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ get_coverage:
fi
check_coverage:
@echo "Checking if coverage is above threshold..."
@docker run $(OVMS_CPP_DOCKER_IMAGE)-build:$(OVMS_CPP_IMAGE_TAG) ./check_coverage.bat | grep success
@bash ci/check_coverage.bat

test_checksec: venv
@echo "Running checksec on libovms_shared library..."
Expand Down
24 changes: 16 additions & 8 deletions ci/check_coverage.bat
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
#!/bin/bash

#Ubuntu
MIN_LINES_COV=76.8
MIN_FUNCTION_COV=87.6
MIN_LINES_COV=76.0
MIN_FUNCTION_COV=83.0

#Rhel
MIN_LINES_COV=75.6
MIN_FUNCTION_COV=73.0
MIN_LINES_COV=76.0
MIN_FUNCTION_COV=83.0
Comment on lines 3 to +9

LINES_COV=`cat genhtml/index.html | grep "headerCovTableEntry.*%" | grep -oP ">\K(\d*.\d*) " | head -n 1`
FUNC_COV=`cat genhtml/index.html | grep "headerCovTableEntry.*%" | grep -oP ">\K(\d*.\d*) " | tail -n 1`
LINES_COV=$(grep "headerCovTableEntry.*%" genhtml/index.html | grep -oP '\d+\.\d+(?=\s*%| %)' | head -n 1)
FUNC_COV=$(grep "headerCovTableEntry.*%" genhtml/index.html | grep -oP '\d+\.\d+(?=\s*%| %)' | tail -n 1)

echo "Lines coverage: ${LINES_COV}% (minimum: ${MIN_LINES_COV}%)"
echo "Functions coverage: ${FUNC_COV}% (minimum: ${MIN_FUNCTION_COV}%)"

if [ -z "$LINES_COV" ] || [ -z "$FUNC_COV" ]; then
echo "Error: Could not parse coverage values from genhtml/index.html"
exit 1
fi

if (( $(echo "$MIN_LINES_COV > $LINES_COV" | bc -l) )); then
echo "Error: $LINES_COV % Lines coverage is lower than minimal $MIN_LINES_COV %"
echo "Error: ${LINES_COV}% Lines coverage is lower than minimal ${MIN_LINES_COV}%"
exit 1
fi

if (( $(echo "$MIN_FUNCTION_COV > $FUNC_COV" | bc -l) )); then
echo "Error: $FUNCTION_COV % Functions coverage is lower than minimal $MIN_FUNCTION_COV %"
echo "Error: ${FUNC_COV}% Functions coverage is lower than minimal ${MIN_FUNCTION_COV}%"
exit 1
fi

Expand Down
42 changes: 36 additions & 6 deletions run_unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,50 @@ compress_logs() {
}

generate_coverage_report() {
test_success_procedure
genhtml --output genhtml "$(bazel info output_path)/_coverage/_coverage_report.dat"
local coverage_dat="$(bazel info output_path)/_coverage/_coverage_report.dat"

# lcov 2.x supports --ignore-errors negative,unused; lcov 1.x does not
local lcov_ver
lcov_ver=$(lcov --version | grep -oP '\d+' | head -1)
local lcov_ignore=""
local genhtml_ignore=""
if [ "$lcov_ver" -ge 2 ] 2>/dev/null; then
lcov_ignore="--ignore-errors negative,unused"
genhtml_ignore="--ignore-errors negative"
fi

if ! lcov --extract "$coverage_dat" 'src/*' --output-file filtered_coverage.dat $lcov_ignore; then
echo "Error: lcov extraction failed" >&2
return 1
fi

if ! lcov --remove filtered_coverage.dat 'src/test/*' 'external/*' --output-file filtered_coverage.dat $lcov_ignore; then
echo "Error: lcov filtering failed" >&2
return 1
fi

if ! genhtml $genhtml_ignore --output genhtml filtered_coverage.dat; then
Comment on lines +76 to +81
echo "Error: genhtml report generation failed" >&2
Comment on lines +61 to +82
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments why such fixes are required, beside that LGTM

return 1
fi
}

echo "Run test: ${RUN_TESTS}"
echo "Run GPU test: ${RUN_GPU_TESTS}"
echo "Run coverage: ${CHECK_COVERAGE}"
if [ "$RUN_TESTS" == "1" ] ; then
if [ "$CHECK_COVERAGE" == "1" ] ; then
{ bazel coverage --instrumentation_filter="-src/test" --combined_report=lcov \
if bazel coverage --instrumentation_filter="-src/test" --combined_report=lcov \
${SHARED_OPTIONS} ${TEST_FILTER} \
//src:ovms_test ${SHARED_OPTIONS} > ${TEST_LOG} 2>&1 || \
compress_logs && exit 1; } && \
generate_coverage_report;
//src:ovms_test ${SHARED_OPTIONS} > ${TEST_LOG} 2>&1 ; then
if ! generate_coverage_report ; then
compress_logs
exit 1
fi
else
compress_logs
exit 1
fi
fi
bazel test ${SHARED_OPTIONS} "${TEST_FILTER}" //src/python/binding:test_python_binding || exit 1
bazel build ${SHARED_OPTIONS} //src:ovms_test || exit 1
Expand Down
Loading