Fix build error for gcov 23/319723/1 accepted/tizen_unified accepted/tizen_unified_x accepted/tizen_unified_x_asan tizen accepted/tizen/unified/20241111.160147 accepted/tizen/unified/x/20241218.032725 accepted/tizen/unified/x/asan/20241224.004451
authorJihoon Jung <jh8801.jung@samsung.com>
Thu, 31 Oct 2024 02:09:40 +0000 (11:09 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Thu, 31 Oct 2024 02:09:40 +0000 (11:09 +0900)
Change-Id: I65b1632f76fafcbb51d47c9888cd7a40d6f7d14a
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
packaging/capi-network-smartcard.spec
unittest/CMakeLists.txt
unittest/run_coverage.sh [new file with mode: 0755]

index 8ba4e6962b57091a3a62f144b7e6eb0e1d13b2d6..08af448a2cb83aebfe40a78210366432a904c466 100644 (file)
@@ -30,28 +30,12 @@ Requires: %{name} = %{version}-%{release}
 
 %description devel
 
-%if 0%{?gcov:1}
-%package gcov
-Summary: %{name} gcov data
-
-%description gcov
-gcov objects
-
-%package unittests
-Summary: %{name} unittests binary
-
-%description unittests
-unittests binary
-%endif
-
 %prep
 %setup -q
 
 %build
 %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
 
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
@@ -65,51 +49,21 @@ cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} \
 
 make %{?jobs:-j%jobs}
 
+%if 0%{?gcov:1}
+mkdir -p gcov-obj
+find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
+%endif
+
 %install
 rm -rf %{buildroot}
 
 %make_install
 
-%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 '{}' "$gcno_obj_dir" ';'
-
-cat << EOF > run-unittest.sh
-#!/bin/bash
-setup() {
-    echo "setup start"
-}
-
-test_main() {
-    echo "test_main start"
-    LD_PRELOAD=/usr/lib/libsmartcard-mock.so /usr/bin/tct-smartcard-core
-}
-
-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}
-%endif
-
 %check
 %if 0%{?gcov:1}
-LD_LIBRARY_PATH=. LD_PRELOAD=unittest/libsmartcard-mock.so unittest/tct-smartcard-core
-lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.total.info
-lcov --remove %{name}.total.info -o %{name}.info '*unittest/*'
-genhtml %{name}.info -o out --legend --show-details
+pushd unittest
+./run_coverage.sh
+popd
 %endif
 
 %post -p /sbin/ldconfig
@@ -127,13 +81,3 @@ genhtml %{name}.info -o out --legend --show-details
 %{_libdir}/pkgconfig/*.pc
 %{_libdir}/libcapi-network-smartcard.so
 %{_bindir}/smartcard_unit_test
-
-%if 0%{?gcov:1}
-%files gcov
-%{_datadir}/gcov/obj/*
-
-%files unittests
-%{_libdir}/libsmartcard-mock.so
-%{_bindir}/tct-smartcard-core
-%{_bindir}/tizen-unittests/%{name}/run-unittest.sh
-%endif
index daab75621abcb3c6a02a493d785a0494d567625f..f3409c22f0e15f4989a9c9d5cae59c5eea34e18d 100644 (file)
@@ -29,15 +29,12 @@ ADD_DEFINITIONS( -DMOBILE )
 
 SET(SMARTCARD_MOCK "smartcard-mock")
 SET(SMARTCARD_MOCK_SRCS
-       mock/smartcard-mock.c
-)
-
+       mock/smartcard-mock.c)
 SET(SMARTCARD_MOCK_CFLAGS "${CMAKE_C_FLAGS}" )
 ADD_LIBRARY(${SMARTCARD_MOCK} SHARED ${SMARTCARD_MOCK_SRCS})
 SET_TARGET_PROPERTIES(${SMARTCARD_MOCK} PROPERTIES
        COMPILE_FLAGS ${SMARTCARD_MOCK_CFLAGS}
 )
-INSTALL(TARGETS ${SMARTCARD_MOCK} DESTINATION ${LIB_INSTALL_LIB})
 
 ADD_EXECUTABLE(${UNITTEST_NAME} ${UNITTEST_NAME}.cpp ${TC_SOURCES} )
 TARGET_LINK_LIBRARIES(${UNITTEST_NAME}
@@ -48,4 +45,4 @@ TARGET_LINK_LIBRARIES(${UNITTEST_NAME}
     capi-network-smartcard
 )
 
-INSTALL(TARGETS ${UNITTEST_NAME} DESTINATION ${BIN_INSTALL_DIR})
+# INSTALL(PROGRAMS ${UNITTEST_NAME} DESTINATION ${BIN_INSTALL_DIR})
diff --git a/unittest/run_coverage.sh b/unittest/run_coverage.sh
new file mode 100755 (executable)
index 0000000..38d5cb3
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+export LD_LIBRARY_PATH=..:.:$LD_LIBRARY_PATH
+pushd ../
+RootDir=$PWD
+popd
+
+unitTestFile=tct-smartcard-core
+if [ ! -x  "./$unitTestFile" ]
+then
+    echo "$unitTestFile file does not exist!"
+    exit -1
+fi
+
+LD_PRELOAD=./libsmartcard-mock.so ./$unitTestFile
+
+CMakeDir=${RootDir}/CMakeFiles/capi-network-smartcard.dir/src
+CoverageDir=${RootDir}/coverage
+
+pushd $CMakeDir
+
+    for obj in `ls *.o`
+    do
+        gcov -b -c $obj
+    done
+
+    if [ -f /usr/bin/lcov ]
+    then
+        lcov -c -d . --exclude "/usr/lib/gcc/armv7l-tizen-linux-gnueabi/9.2.0/include/c++/*" -o cov.info
+        genhtml cov.info -o ${CoverageDir}
+        echo "Coverage test result created! [${CoverageDir}]"
+    else
+        echo "lcov does not exist!"
+    fi
+popd