Setup for automatic coverage measurement accepted/tizen/7.0/unified/20240429.105738 accepted/tizen/8.0/unified/20240429.063534
authorYonggoo Kang <ygace.kang@samsung.com>
Wed, 24 Apr 2024 05:02:43 +0000 (14:02 +0900)
committerDongsun Lee <ds73.lee@samsung.com>
Wed, 24 Apr 2024 07:39:29 +0000 (16:39 +0900)
- Setup automatic coverage measurement by run-unittest.sh
- Merge coverage data with webauthn-server daemon

Change-Id: I1d903ed1d8ce06f0e8b72ec31dc20d5836f9019c

packaging/webauthn.spec
srcs/server/main.cpp
tests/unittests.cpp

index 886bab0be0281168ff90469ddb092d9ad7aaca65..76a88479e2d07b7329d73f8f792383fc000ac42d 100644 (file)
@@ -20,6 +20,9 @@ Requires(postun): /sbin/ldconfig
 BuildRequires: cmake
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(libsystemd)
+%if 0%{?gcov:1}
+BuildRequires: lcov
+%endif
 
 %description
 Web Authentication Service
@@ -84,6 +87,15 @@ Requires:      %{name} = %{version}-%{release}
 %description manual-tests
 Web Authentication Service (manual test)
 
+# gcov
+%if 0%{?gcov:1}
+%package gcov
+Summary:    %{name} gcov data
+
+%description gcov
+Base utils gcov objects
+%endif
+
 %define user_name          security_fw
 %define group_name         security_fw
 %define smack_domain       System
@@ -130,16 +142,52 @@ Web Authentication Service (manual test)
 make %{?jobs:-j%jobs}
 
 %install
+rm -rf %{buildroot}
 %make_install
 %install_service multi-user.target.wants %{name}.service
 %install_service sockets.target.wants %{name}.socket
 
+%if 0%{?gcov:1}
+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
+
+cat << EOF > run-unittest.sh
+#!/bin/sh
+setup() {
+       echo "setup start"
+}
+
+test_main() {
+       echo "test_main start"
+       /usr/bin/webauthn-unit-tests
+}
+
+teardown() {
+       echo "teardown start"
+    chown ${user_name}:${group_name} /home/abuild/rpmbuild/BUILD/%{name}-%{version} -R
+    /usr/bin/killall %{name}-server
+}
+
+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}/
+
 # write macro
 mkdir -p %{buildroot}%{ro_etc_dir}/rpm
 touch %{buildroot}%{macro_file_path}
 echo "%WEBAUTHN_HYBRID_PLUGIN_SO_PATH %{hybrid_plugin_so_path}" >> %{buildroot}%{macro_file_path}
 
-
 %post
 /sbin/ldconfig
 systemctl daemon-reload
@@ -196,10 +244,16 @@ fi
 %{_includedir}/webauthn*.h
 %{lib_dir}/pkgconfig/%{name}-hal.pc
 
+%if 0%{?gcov:1}
+%files gcov
+%{_datadir}/gcov/obj/*
+%endif
+
 %files -n %{name}-unit-tests
 %manifest %{name}-unit-tests.manifest
 %license LICENSE
 %{bin_dir}/%{name}-unit-tests
+%{_bindir}/tizen-unittests/%{name}/run-unittest.sh
 
 %files -n %{name}-manual-tests
 %manifest %{name}-manual-tests.manifest
index e4d9f0b7acd0f8f7fdd5e3f05c59539c5ffdebbc..346581d08e85ee88ac831763e883ec55fde65b14 100644 (file)
@@ -53,9 +53,6 @@ int webauthn_manager()
 
 int main(void)
 {
-#ifdef GCOV_BUILD
-    setenv("GCOV_PREFIX", "/tmp", 1);
-#endif
     int ret = EXIT_FAILURE;
     UNHANDLED_EXCEPTION_HANDLER_BEGIN
     {
index 0934c6dd9e594932f0a239991cd8075b5e1ec851..4408dba95670747b97c64b28bcb83b542853ab41 100644 (file)
 
 #define WEBAUTHN_TEST_LOG_TAG "WEBAUTHN-TEST"
 
-#ifdef GCOV_BUILD
-extern "C" void __gcov_flush(void);
-#endif
-
 int main(int argc, char *argv[])
 {
     WA::Singleton<WA::WebAuthnLog>::Instance().SetTag(WEBAUTHN_TEST_LOG_TAG);
     bool ret = false;
-#ifdef GCOV_BUILD
-    std::cout << "SET GCOV_PREFIX" << std::endl;
-    setenv("GCOV_PREFIX", "/tmp", 1);
-#endif
     try {
         ::testing::InitGoogleTest(&argc, argv);
         ret = RUN_ALL_TESTS();
     } catch (...) {
         ret = true;
     }
-#ifdef GCOV_BUILD
-    std::cout << "The webauthn-server process need to be stopped to flush gcov"
-              << std::endl;
-#endif
     return ret;
 }