%description -n capi-machine-learning-unittests
Unittests for Tizen Machine Learning API.
%endif
+
+%if 0%{?testcoverage}
+%package -n capi-machine-learning-unittest-coverage
+Summary: Unittest coverage result for Tizen Machine Learning API
+%description -n capi-machine-learning-unittest-coverage
+HTML pages of lcov results of ML API generated during rpm build
+%endif
###########################################################################
# Define build options
%define enable_tizen -Denable-tizen=false
# Remove compiler flags for meson to decide the cpp version
CXXFLAGS=`echo $CXXFLAGS | sed -e "s|-std=gnu++11||"`
+%if 0%{?testcoverage}
+# To test coverage, disable optimizations (and should unset _FORTIFY_SOURCE to use -O0)
+CFLAGS=`echo $CFLAGS | sed -e "s|-O[1-9]|-O0|g"`
+CFLAGS=`echo $CFLAGS | sed -e "s|-Wp,-D_FORTIFY_SOURCE=[1-9]||g"`
+CXXFLAGS=`echo $CXXFLAGS | sed -e "s|-O[1-9]|-O0|g"`
+CXXFLAGS=`echo $CXXFLAGS | sed -e "s|-Wp,-D_FORTIFY_SOURCE=[1-9]||g"`
+# also, use the meson's base option, -Db_coverage, instead of --coverage/-fprofile-arcs and -ftest-coverage
+%define enable_test_coverage -Db_coverage=true
+%else
+%define enable_test_coverage -Db_coverage=false
+%endif
+
mkdir -p build
meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} --libdir=%{_libdir} \
- --bindir=%{_bindir} --includedir=%{_includedir} %{install_test} \
+ --bindir=%{_bindir} --includedir=%{_includedir} %{install_test} %{enable_test_coverage} \
%{enable_tizen} %{enable_tizen_privilege_check} %{enable_tizen_feature_check} \
build
%install
DESTDIR=%{buildroot} ninja -C build %{?_smp_mflags} install
+%if 0%{?testcoverage}
+# 'lcov' generates the date format with UTC time zone by default. Let's replace UTC with KST.
+# If you can get a root privilege, run ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
+TZ='Asia/Seoul'; export TZ
+
+# Get commit info
+VCS=`cat ${RPM_SOURCE_DIR}/machine-learning-api.spec | grep "^VCS:" | sed "s|VCS:\\W*\\(.*\\)|\\1|"`
+
+# Create human readable coverage report web page.
+# Create null gcda files if gcov didn't create it because there is completely no unit test for them.
+find . -name "*.gcno" -exec sh -c 'touch -a "${1%.gcno}.gcda"' _ {} \;
+# Remove gcda for meaningless file (CMake's autogenerated)
+find . -name "CMakeCCompilerId*.gcda" -delete
+find . -name "CMakeCXXCompilerId*.gcda" -delete
+# Generate report
+lcov -t 'ML API unittest coverage' -o unittest.info -c -d . -b $(pwd) --no-external
+# Exclude generated files (e.g., Orc, Protobuf) and device-dependent files.
+lcov -r unittest.info "*/tests/*" "*/meson*/*" "*/*@sha/*" "*/*.so.p/*" "*/*tizen*" -o unittest-filtered.info
+# Visualize the report
+genhtml -o result unittest-filtered.info -t "ML API %{version}-%{release} ${VCS}" --ignore-errors source -p ${RPM_BUILD_DIR}
+
+mkdir -p %{buildroot}%{_datadir}/ml-api/unittest/
+cp -r result %{buildroot}%{_datadir}/ml-api/unittest/
+%endif # test coverage
+
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%{_bindir}/unittest-ml
%endif
+%if 0%{?testcoverage}
+%files -n capi-machine-learning-unittest-coverage
+%{_datadir}/ml-api/unittest/*
+%endif
+
%changelog
* Fri Feb 05 2021 MyungJoo Ham <myungjoo.ham@samsung.com>
- Started ML API packaging for 1.7.1