From a2d65bf64951b17b5252f1723971319157ae8192 Mon Sep 17 00:00:00 2001 From: Damian Kalinowski Date: Wed, 18 Mar 2026 10:44:11 +0100 Subject: [PATCH 1/3] save --- .gitignore | 1 + Dockerfile.redhat | 3 ++- Dockerfile.ubuntu | 3 ++- run_unit_tests.sh | 17 +++++++++++------ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 62dca37b89..a7b0513023 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ tmp/ *.zip *.tar.gz models +genhtml diff --git a/Dockerfile.redhat b/Dockerfile.redhat index 043e1e736f..1613cc72cd 100644 --- a/Dockerfile.redhat +++ b/Dockerfile.redhat @@ -326,7 +326,8 @@ COPY ci/check_coverage.bat /ovms/ ARG CHECK_COVERAGE=0 ARG RUN_TESTS=0 COPY run_unit_tests.sh prepare_llm_models.sh prepare_gpu_models.sh demos/common/export_models/export_model.py /ovms/ -RUN if [ "$RUN_TESTS" == "1" ] ; then mkdir -p demos/common/export_models/ && mv export_model.py demos/common/export_models/ && ./prepare_llm_models.sh /ovms/src/test/llm_testing docker && ./run_unit_tests.sh ; fi +RUN if [ "$RUN_TESTS" == "1" ] ; then mkdir -p demos/common/export_models/ && mv export_model.py demos/common/export_models/ && ./prepare_llm_models.sh /ovms/src/test/llm_testing docker ; fi +RUN if [ "$RUN_TESTS" == "1" ] ; then ./run_unit_tests.sh ; fi ARG ovms_metadata_file diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu index f3883cf986..81eaef1350 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile.ubuntu @@ -329,7 +329,8 @@ ARG OPTIMIZE_BUILDING_TESTS=0 RUN if [ "$FUZZER_BUILD" == "0" ]; then bazel build --jobs=$JOBS ${debug_bazel_flags} ${minitrace_flags} //src:ovms $(if [ "${OPTIMIZE_BUILDING_TESTS}" == "1" ] ; then echo -n //src:ovms_test; fi); fi; ARG RUN_TESTS=0 -RUN if [ "$RUN_TESTS" == "1" ] ; then mkdir -p demos/common/export_models/ && mv export_model.py demos/common/export_models/ && ./prepare_llm_models.sh /ovms/src/test/llm_testing docker && ./run_unit_tests.sh ; fi +RUN if [ "$RUN_TESTS" == "1" ] ; then mkdir -p demos/common/export_models/ && mv export_model.py demos/common/export_models/ && ./prepare_llm_models.sh /ovms/src/test/llm_testing docker ; fi +RUN if [ "$RUN_TESTS" == "1" ] ; then ./run_unit_tests.sh ; fi RUN if [ "$FUZZER_BUILD" == "0" ]; then /ovms/bazel-bin/src/ovms --version && /ovms/bazel-bin/src/ovms; fi; diff --git a/run_unit_tests.sh b/run_unit_tests.sh index e05b0c73b5..97adc85524 100755 --- a/run_unit_tests.sh +++ b/run_unit_tests.sh @@ -56,8 +56,10 @@ 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 --extract "$coverage_dat" 'src/*' --output-file filtered_coverage.dat --ignore-errors negative + lcov --remove filtered_coverage.dat 'src/test/*' 'external/*' --output-file filtered_coverage.dat --ignore-errors negative,unused + genhtml --ignore-errors negative --output genhtml filtered_coverage.dat } echo "Run test: ${RUN_TESTS}" @@ -65,11 +67,14 @@ 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 + generate_coverage_report + 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 From 43bc15ea6bdfe6b42228a25c422ceaf53198abd0 Mon Sep 17 00:00:00 2001 From: dkalinowski Date: Wed, 18 Mar 2026 11:00:19 +0100 Subject: [PATCH 2/3] fix Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- run_unit_tests.sh | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/run_unit_tests.sh b/run_unit_tests.sh index 97adc85524..3eae097dfc 100755 --- a/run_unit_tests.sh +++ b/run_unit_tests.sh @@ -57,9 +57,21 @@ compress_logs() { generate_coverage_report() { local coverage_dat="$(bazel info output_path)/_coverage/_coverage_report.dat" - lcov --extract "$coverage_dat" 'src/*' --output-file filtered_coverage.dat --ignore-errors negative - lcov --remove filtered_coverage.dat 'src/test/*' 'external/*' --output-file filtered_coverage.dat --ignore-errors negative,unused - genhtml --ignore-errors negative --output genhtml filtered_coverage.dat + + if ! lcov --extract "$coverage_dat" 'src/*' --output-file filtered_coverage.dat --ignore-errors negative; then + echo "Error: lcov extraction failed" >&2 + return 1 + fi + + if ! lcov --remove filtered_coverage.dat 'src/test/*' 'external/*' --output-file filtered_coverage.dat --ignore-errors negative,unused; then + echo "Error: lcov filtering failed" >&2 + return 1 + fi + + if ! genhtml --ignore-errors negative --output genhtml filtered_coverage.dat; then + echo "Error: genhtml report generation failed" >&2 + return 1 + fi } echo "Run test: ${RUN_TESTS}" @@ -70,7 +82,10 @@ if [ "$RUN_TESTS" == "1" ] ; then if bazel coverage --instrumentation_filter="-src/test" --combined_report=lcov \ ${SHARED_OPTIONS} ${TEST_FILTER} \ //src:ovms_test ${SHARED_OPTIONS} > ${TEST_LOG} 2>&1 ; then - generate_coverage_report + if ! generate_coverage_report ; then + compress_logs + exit 1 + fi else compress_logs exit 1 From 5a9dc2b6e0aea63e564a8ca49ff6646414240d01 Mon Sep 17 00:00:00 2001 From: Damian Kalinowski Date: Wed, 18 Mar 2026 14:34:21 +0100 Subject: [PATCH 3/3] save --- Dockerfile.redhat | 3 +-- Dockerfile.ubuntu | 3 +-- Makefile | 2 +- ci/check_coverage.bat | 24 ++++++++++++++++-------- run_unit_tests.sh | 16 +++++++++++++--- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Dockerfile.redhat b/Dockerfile.redhat index 1613cc72cd..043e1e736f 100644 --- a/Dockerfile.redhat +++ b/Dockerfile.redhat @@ -326,8 +326,7 @@ COPY ci/check_coverage.bat /ovms/ ARG CHECK_COVERAGE=0 ARG RUN_TESTS=0 COPY run_unit_tests.sh prepare_llm_models.sh prepare_gpu_models.sh demos/common/export_models/export_model.py /ovms/ -RUN if [ "$RUN_TESTS" == "1" ] ; then mkdir -p demos/common/export_models/ && mv export_model.py demos/common/export_models/ && ./prepare_llm_models.sh /ovms/src/test/llm_testing docker ; fi -RUN if [ "$RUN_TESTS" == "1" ] ; then ./run_unit_tests.sh ; fi +RUN if [ "$RUN_TESTS" == "1" ] ; then mkdir -p demos/common/export_models/ && mv export_model.py demos/common/export_models/ && ./prepare_llm_models.sh /ovms/src/test/llm_testing docker && ./run_unit_tests.sh ; fi ARG ovms_metadata_file diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu index 81eaef1350..f3883cf986 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile.ubuntu @@ -329,8 +329,7 @@ ARG OPTIMIZE_BUILDING_TESTS=0 RUN if [ "$FUZZER_BUILD" == "0" ]; then bazel build --jobs=$JOBS ${debug_bazel_flags} ${minitrace_flags} //src:ovms $(if [ "${OPTIMIZE_BUILDING_TESTS}" == "1" ] ; then echo -n //src:ovms_test; fi); fi; ARG RUN_TESTS=0 -RUN if [ "$RUN_TESTS" == "1" ] ; then mkdir -p demos/common/export_models/ && mv export_model.py demos/common/export_models/ && ./prepare_llm_models.sh /ovms/src/test/llm_testing docker ; fi -RUN if [ "$RUN_TESTS" == "1" ] ; then ./run_unit_tests.sh ; fi +RUN if [ "$RUN_TESTS" == "1" ] ; then mkdir -p demos/common/export_models/ && mv export_model.py demos/common/export_models/ && ./prepare_llm_models.sh /ovms/src/test/llm_testing docker && ./run_unit_tests.sh ; fi RUN if [ "$FUZZER_BUILD" == "0" ]; then /ovms/bazel-bin/src/ovms --version && /ovms/bazel-bin/src/ovms; fi; diff --git a/Makefile b/Makefile index 601105274a..f5dc0dd4fa 100644 --- a/Makefile +++ b/Makefile @@ -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..." diff --git a/ci/check_coverage.bat b/ci/check_coverage.bat index e962c255ed..6883c33131 100755 --- a/ci/check_coverage.bat +++ b/ci/check_coverage.bat @@ -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 -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 diff --git a/run_unit_tests.sh b/run_unit_tests.sh index 3eae097dfc..c3a1842b9c 100755 --- a/run_unit_tests.sh +++ b/run_unit_tests.sh @@ -58,17 +58,27 @@ compress_logs() { generate_coverage_report() { local coverage_dat="$(bazel info output_path)/_coverage/_coverage_report.dat" - if ! lcov --extract "$coverage_dat" 'src/*' --output-file filtered_coverage.dat --ignore-errors negative; then + # 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 --ignore-errors negative,unused; then + 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 --ignore-errors negative --output genhtml filtered_coverage.dat; then + if ! genhtml $genhtml_ignore --output genhtml filtered_coverage.dat; then echo "Error: genhtml report generation failed" >&2 return 1 fi