@@ -178,7 +178,14 @@ meson compile -C %{builddir} %{?_smp_mflags}
178178export MLAGENT_SOURCE_ROOT_PATH= $(pwd)
179179export MLAGENT_BUILD_ROOT_PATH= $(pwd)/%{builddir }
180180
181- # Run test
181+ %if 0%{?testcoverage }
182+ # Capture initial zero coverage data. This will be merged with actual coverage data later.
183+ # This is to prevent null gcda file error if the test is not performed (in case of gcov package generation mode).
184+ pushd %{builddir }
185+ lcov -i -c -o unittest_base.info -d . -b $(pwd) --ignore-errors mismatch
186+ popd
187+ %endif # testcoverage
188+
182189# If gcov package generation is enabled, pass the test from GBS.
183190%if 0%{?unit_test } && ! 0%{?gcov }
184191bash %{test_script } ./tests/daemon/unittest_ml_agent
@@ -200,19 +207,15 @@ TZ='Asia/Seoul'; export TZ
200207VCS= `cat ${RPM_SOURCE_DIR}/mlops-agent.spec | grep "^VCS:" | sed "s|VCS:\\W*\\(.*\\)|\\1|"`
201208
202209# Create human readable coverage report web page.
203- # Create null gcda files if gcov didn't create it because there is completely no unit test for them.
204- find . -name "*.gcno" -exec sh -c 'touch -a "${1%.gcno}.gcda"' _ {} \;
205- # Remove gcda for meaningless file (CMake's autogenerated)
206- find . -name "CMakeCCompilerId*.gcda" -delete
207- find . -name "CMakeCXXCompilerId*.gcda" -delete
208210# Generate report and exclude files which are generated by gdbus-codegen and external files in /usr/*.
209211# TODO: the --no-external option is removed to include machine-learning-agent related source files.
210212# Restore this option when there is proper way to include those source files.
211213pushd %{builddir }
212214# Set different lcov options for Tizen/lcov versions.
213215%if 0%{tizen_version_major } >= 9
214- lcov -t 'ML-Agent unittest coverage' -o unittest.info -c -d . -b $(pwd) --ignore-errors mismatch
215- lcov -r unittest.info "*/tests/*" "*/meson*/*" "*/*@sha/*" "*/*.so.p/*" "*/*tizen*" "*/*-dbus.c" "/usr/*" -o unittest-filtered.info --ignore-errors graph,unused
216+ lcov -t 'ML-Agent unittest coverage' -o unittest_test.info -c -d . -b $(pwd) --ignore-errors mismatch,empty
217+ lcov -a unittest_base.info -a unittest_test.info -o unittest_total.info --ignore-errors empty
218+ lcov -r unittest_total.info "*/tests/*" "*/meson*/*" "*/*@sha/*" "*/*.so.p/*" "*/*tizen*" "*/*-dbus.c" "/usr/*" -o unittest-filtered.info --ignore-errors graph,unused
216219%else
217220lcov -t 'ML-Agent unittest coverage' -o unittest.info -c -d . -b $(pwd)
218221lcov -r unittest.info "*/tests/*" "*/meson*/*" "*/*@sha/*" "*/*.so.p/*" "*/*tizen*" "*/*-dbus.c" "/usr/*" -o unittest-filtered.info
0 commit comments