Fix spec file for coverage measurement 78/275478/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 25 May 2022 22:21:51 +0000 (07:21 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 25 May 2022 22:21:51 +0000 (07:21 +0900)
To measure code coverages automatically, a run-unittest.sh is needed.

Change-Id: I00d7683e45bbb1d9b8012cdc90ee46b553747a60
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
packaging/appcore-agent.spec
unittests/CMakeLists.txt

index c478eca..a18e1fd 100644 (file)
@@ -18,6 +18,10 @@ BuildRequires:  pkgconfig(gmock)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(vconf-internal-keys)
 
+%if 0%{?gcov:1}
+BuildRequires:  lcov
+%endif
+
 %description
 Service Application basic
 
@@ -46,6 +50,12 @@ Group:    System/API
 gcov objects of a service application library
 %endif
 
+%package unittests
+Summary:  %{name} unittests binary
+
+%description unittests
+unittests binary
+
 %prep
 %setup -q
 cp %{SOURCE1001} .
@@ -64,23 +74,53 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
        .
 %__make %{?_smp_mflags}
 
-%if 0%{?gcov:1}
-mkdir -p gcov-obj
-find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
-%endif
-
 %install
 %make_install
 
 %if 0%{?gcov:1}
-mkdir -p %{buildroot}%{_datadir}/gcov/obj/%{name}
-install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj/%{name}
+builddir=$(basename $PWD)
+gcno_obj_dir=%{buildroot}%{_datadir}/gcov/obj/%{name}/"$builddir"
+mkdir -p "$gcno_obj_dir"
+find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';'
 %endif
 
+## To run unittest
+cat << EOF > run-unittest.sh
+#!/bin/bash
+setup() {
+    echo "setup start"
+}
+
+test_main() {
+    echo "test_main start"
+    /usr/bin/appcore-agent-test
+}
+
+teardown() {
+    echo "teardown start"
+}
+
+main() {
+    setup
+    test_main
+    teardown
+}
+
+main "$@"
+EOF
+
+mkdir -p %{buildroot}%{_bindir}/tizen-unittests/%{name}
+install -m 0755 run-unittest.sh %{buildroot}%{_bindir}/tizen-unittests/%{name}/
+
 %check
 cd unittests
 LD_LIBRARY_PATH=../ ctest  -V
 
+%if 0%{?gcov:1}
+lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.info
+genhtml %{name}.info -o out --legend --show-details
+%endif
+
 %post -p /sbin/ldconfig
 
 %postun -p /sbin/ldconfig
@@ -110,3 +150,7 @@ LD_LIBRARY_PATH=../ ctest  -V
 %files gcov
 %{_datadir}/gcov/obj/*
 %endif
+
+%files unittests
+%{_bindir}/appcore-agent-test
+%{_bindir}/tizen-unittests/%{name}/run-unittest.sh
index c8fc391..bc193b0 100644 (file)
@@ -36,3 +36,5 @@ ADD_EXECUTABLE(${TARGET_TEST} ${MOCK_SRCS} ${TEST_SRCS} ${LIB_SRCS})
 TARGET_LINK_LIBRARIES(${TARGET_TEST} ${test_LDFLAGS} ${gtest_pkgs_LIBRARIES})
 
 ADD_TEST(${TARGET_TEST} ${TARGET_TEST})
+
+INSTALL(TARGETS ${TARGET_TEST} DESTINATION bin)