Support auto coverage checking 62/209362/4 accepted/tizen/unified/20190709.071058 submit/tizen/20190708.094113
authorSangwan Kwon <sangwan.kwon@samsung.com>
Thu, 4 Jul 2019 23:36:50 +0000 (08:36 +0900)
committerSangwan Kwon <sangwan.kwon@samsung.com>
Sun, 7 Jul 2019 23:18:00 +0000 (08:18 +0900)
Change-Id: I383849a301f33017d332dabb4650e0763d71419b
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
CMakeLists.txt
packaging/csr-framework.spec
src/framework/common/connection.cpp
src/framework/main/csr-main.cpp
src/framework/ui/popup/main.cpp
test/internals/test-main.cpp
test/popup/test-main.cpp
test/test-main.cpp
test/thread-pool/test-main.cpp

index 1d4503e..ea9a599 100644 (file)
@@ -56,6 +56,10 @@ IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
        ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG")
 ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
 
+IF (BUILD_GCOV)
+       ADD_DEFINITIONS("-DTIZEN_TEST_GCOV")
+ENDIF (BUILD_GCOV)
+
 SET(TARGET_CSR_SERVER ${SERVICE_NAME}-server)
 SET(TARGET_CSR_CLIENT ${SERVICE_NAME}-client)
 SET(TARGET_CSR_COMMON ${SERVICE_NAME}-common)
index 26ec5e4..3b69b24 100644 (file)
@@ -119,11 +119,22 @@ BuildRequires: boost-devel
 BuildRequires: pkgconfig(pkgmgr-info)
 BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(storage)
+Requires:      boost-test
 Requires:      %{name} = %{version}
 
 %description test
 Content Screening and Reputation framework (test program)
 
+%if 0%{?gcov:1}
+%package gcov
+Summary: CSR framework (gcov)
+Group:   Security/Testing
+BuildRequires: lcov
+
+%description gcov
+Content Screening and Reputation framework (gcov)
+%endif
+
 %prep
 %setup -q
 
@@ -136,8 +147,12 @@ Content Screening and Reputation framework (test program)
 %define test_target target
 %endif
 
-export CXXFLAGS="-fprofile-arcs -ftest-coverage"
-export LDFLAGS="-lgcov"
+%if 0%{?gcov:1}
+export CFLAGS+=" -fprofile-arcs -ftest-coverage"
+export CXXFLAGS+=" -fprofile-arcs -ftest-coverage"
+export FFLAGS+=" -fprofile-arcs -ftest-coverage"
+export LDFLAGS+=" -lgcov"
+%endif
 
 %cmake . \
     -DCMAKE_BUILD_TYPE=%{?build_type:%build_type}%{!?build_type:RELEASE} \
@@ -174,10 +189,16 @@ export LDFLAGS="-lgcov"
 %endif
     -DTZ_SYS_STORAGE=%TZ_SYS_STORAGE \
     -DTZ_SYS_RW_APP=%TZ_SYS_RW_APP \
-    -DTZ_SYS_RO_APP=%TZ_SYS_RO_APP
+    -DTZ_SYS_RO_APP=%TZ_SYS_RO_APP \
+    -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0}
 
 make %{?jobs:-j%jobs}
 
+%if 0%{?gcov:1}
+mkdir -p gcov-obj
+find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
+%endif
+
 %install
 %make_install
 %install_service sockets.target.wants %{service_name}-cs.socket
@@ -195,6 +216,11 @@ mkdir -p %{buildroot}%{engine_rw_working_dir}
 
 %find_lang %{service_name}
 
+%if 0%{?gcov:1}
+mkdir -p %{buildroot}%{_datadir}/gcov/obj
+install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj
+%endif
+
 %post
 set_cap_script=%{ro_data_dir}/security-config/set_capability
 if [ -f $set_cap_script ]; then
@@ -255,6 +281,13 @@ touch %{engine_rw_working_dir}/csret_cs_virus_signatures
 touch %{engine_rw_working_dir}/csret_wp_risky_urls
 %endif
 
+%if 0%{?gcov:1}
+chmod 777 -R /tmp/home/abuild/rpmbuild/BUILD/csr-framework-*
+su - owner -c %{bin_dir}/%{service_name}-test
+%{bin_dir}/%{service_name}-internal-test
+%{bin_dir}/%{service_name}-threadpool-test
+%endif
+
 %files -f %{service_name}.lang
 %defattr(-,root,root,-)
 %manifest %{service_name}.manifest
@@ -345,3 +378,8 @@ touch %{engine_rw_working_dir}/csret_wp_risky_urls
 %{engine_dir}/lib%{service_name}-wp-engine.so
 %attr(-, %{service_user}, %{service_group}) %{engine_rw_working_dir}/*
 %endif
+
+%if 0%{?gcov:1}
+%files gcov
+%{_datadir}/gcov/obj/*
+%endif
index 4f026a6..421dde7 100644 (file)
@@ -23,7 +23,9 @@
 
 #include <utility>
 
+#ifdef TIZEN_TEST_GCOV
 extern "C" void __gcov_flush();
+#endif
 
 namespace Csr {
 
@@ -52,7 +54,9 @@ Connection &Connection::operator=(Connection &&other) noexcept
 
 void Connection::send(const RawBuffer &buf) const
 {
+#ifdef TIZEN_TEST_GCOV
        __gcov_flush();
+#endif
        std::lock_guard<std::mutex> lock(this->m_mSend);
        this->m_socket.write(buf);
 }
index 5ba590f..ed6971a 100644 (file)
@@ -26,7 +26,9 @@
 
 int main(void)
 {
-       setenv("GCOV_PREFIX", "/opt/usr", 1);
+#ifdef TIZEN_TEST_GCOV
+       ::setenv("GCOV_PREFIX", "/tmp", 1);
+#endif
        try {
                INFO("Start csr-server main!");
 
index 18b8b54..b00c4c6 100644 (file)
@@ -70,7 +70,9 @@ struct ElmRaii {
 
 int main(int argc, char **argv)
 {
-       setenv("GCOV_PREFIX", "/opt/usr", 1);
+#ifdef TIZEN_TEST_GCOV
+       ::setenv("GCOV_PREFIX", "/tmp", 1);
+#endif
        try {
                Csr::Audit::Logger::setTag("CSR_POPUP");
 
index 84333d2..029887a 100644 (file)
@@ -33,6 +33,9 @@
 struct TestConfig {
        TestConfig()
        {
+#ifdef TIZEN_TEST_GCOV
+               ::setenv("GCOV_PREFIX", "/tmp", 1);
+#endif
                boost::unit_test::unit_test_log.set_threshold_level(
                        boost::unit_test::log_test_units);
                boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);
index ad3c19e..feed79b 100644 (file)
@@ -28,6 +28,9 @@
 struct TestConfig {
        TestConfig()
        {
+#ifdef TIZEN_TEST_GCOV
+               ::setenv("GCOV_PREFIX", "/tmp", 1);
+#endif
                boost::unit_test::unit_test_log.set_threshold_level(
                        boost::unit_test::log_test_units);
                boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);
index f661504..9131ac9 100644 (file)
@@ -78,6 +78,9 @@ csr_state_e setEngineState(csr_engine_id_e id, csr_state_e state)
 struct TestConfig {
        TestConfig()
        {
+#ifdef TIZEN_TEST_GCOV
+               ::setenv("GCOV_PREFIX", "/tmp", 1);
+#endif
                boost::unit_test::unit_test_log.set_threshold_level(
                        boost::unit_test::log_test_units);
                boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);
index 35c4440..74c5ee5 100644 (file)
@@ -28,6 +28,9 @@
 struct TestConfig {
        TestConfig()
        {
+#ifdef TIZEN_TEST_GCOV
+               ::setenv("GCOV_PREFIX", "/tmp", 1);
+#endif
                boost::unit_test::unit_test_log.set_threshold_level(
                        boost::unit_test::log_test_units);
                boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);