From: Jihoon Jung Date: Thu, 31 Oct 2024 02:10:07 +0000 (+0900) Subject: Fix build error for gcov X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eb045af731ac789d15fa8aa8fe775950ee194d9e;p=platform%2Fcore%2Fapi%2Fnfc.git Fix build error for gcov Change-Id: I9f99cd716fca42e44dcc6b7464d95e9594c286fd Signed-off-by: Jihoon Jung --- diff --git a/packaging/capi-network-nfc.spec b/packaging/capi-network-nfc.spec index 1ca099b..62273eb 100644 --- a/packaging/capi-network-nfc.spec +++ b/packaging/capi-network-nfc.spec @@ -35,29 +35,13 @@ Requires: %{name} = %{version}-%{release} %description devel This package contains the development files for %{name}. -%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 export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE" @@ -70,51 +54,21 @@ cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} 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/libnfc-mock.so /usr/bin/tct-nfc-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/libnfc-mock.so unittest/tct-nfc-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 @@ -132,13 +86,3 @@ genhtml %{name}.info -o out --legend --show-details %{_libdir}/pkgconfig/*.pc %{_libdir}/libcapi-network-nfc.so %{_bindir}/nfc_unit_test - -%if 0%{?gcov:1} -%files gcov -%{_datadir}/gcov/obj/* - -%files unittests -%{_libdir}/libnfc-mock.so -%{_bindir}/tct-nfc-core -%{_bindir}/tizen-unittests/%{name}/run-unittest.sh -%endif diff --git a/src/net_nfc_client_llcp.c b/src/net_nfc_client_llcp.c index eade767..83eac19 100644 --- a/src/net_nfc_client_llcp.c +++ b/src/net_nfc_client_llcp.c @@ -31,6 +31,7 @@ #define CHECK_INITIALIZED() \ do { \ + /* LCOV_EXCL_START */ \ if (llcp_proxy == NULL) { \ if (net_nfc_client_llcp_init() != NET_NFC_OK) { \ DEBUG_ERR_MSG("llcp_proxy fail"); \ @@ -40,6 +41,7 @@ \ if (net_nfc_client_manager_is_activated() == false) \ return NET_NFC_NOT_ACTIVATED; \ + /* LCOV_EXCL_STOP */ \ } while (0) typedef struct _LlcpFuncData LlcpFuncData; diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index aa045bc..56ad695 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -43,7 +43,6 @@ ADD_LIBRARY(${NFC_MOCK} SHARED ${NFC_MOCK_SRCS}) SET_TARGET_PROPERTIES(${NFC_MOCK} PROPERTIES COMPILE_FLAGS ${NFC_MOCK_CFLAGS} ) -INSTALL(TARGETS ${NFC_MOCK} DESTINATION ${LIB_INSTALL_LIB}) ADD_EXECUTABLE(${UNITTEST_NAME} ${UNITTEST_NAME}.cpp ${TC_SOURCES} ) TARGET_LINK_LIBRARIES(${UNITTEST_NAME} @@ -54,4 +53,4 @@ TARGET_LINK_LIBRARIES(${UNITTEST_NAME} capi-network-nfc ) -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 index 0000000..f7471d5 --- /dev/null +++ b/unittest/run_coverage.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +export LD_LIBRARY_PATH=..:.:$LD_LIBRARY_PATH +pushd ../ +RootDir=$PWD +popd + +unitTestFile=tct-nfc-core +if [ ! -x "./$unitTestFile" ] +then + echo "$unitTestFile file does not exist!" + exit -1 +fi + +LD_PRELOAD=./libnfc-mock.so ./$unitTestFile + +CMakeDir=${RootDir}/CMakeFiles/capi-network-nfc.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 . -o cov.info + genhtml cov.info -o ${CoverageDir} + echo "Coverage test result created! [${CoverageDir}]" + else + echo "lcov does not exist!" + fi +popd