From 2e49d357c38cda277a9926a6e84051742019517a Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Fri, 10 Jun 2022 18:45:31 +0900 Subject: [PATCH] Fix unittest for line coverage automation Change-Id: I55a086595b43ea33f6d9aaf1304f90edc99eb8f9 Signed-off-by: Suyeon Hwang --- packaging/stt.spec | 34 ++++++++++++++++++++++++++-- tests/CMakeLists.txt | 6 ++--- tests/src/main.cpp | 17 +++++++++++++- tests/src/stt_denied_unittests.cpp | 46 -------------------------------------- tests/src/stt_unittests.cpp | 13 ----------- 5 files changed, 50 insertions(+), 66 deletions(-) delete mode 100644 tests/src/stt_denied_unittests.cpp diff --git a/packaging/stt.spec b/packaging/stt.spec index 03e7601..120c871 100644 --- a/packaging/stt.spec +++ b/packaging/stt.spec @@ -108,8 +108,8 @@ export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" %if 0%{?gcov:1} -export CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage" -export CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage" +export CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage -DTIZEN_TEST_GCOV" +export CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage -DTIZEN_TEST_GCOV" export FFLAGS="$FFLAGS -fprofile-arcs -ftest-coverage" export LDFLAGS="$LDFLAGS -lgcov" %endif @@ -145,6 +145,35 @@ 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" + touch /opt/share/askuser_disable + mount -o remount,rw / + tpk-backend --preload -y org.tizen.stt-unittests +} + +test_main() { + echo "test_main start" + launch_app org.tizen.stt-unittests +} + +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} %post /sbin/ldconfig @@ -203,3 +232,4 @@ mkdir -p %{TZ_SYS_RO_SHARE}/voice/test %defattr(-,root,root,-) %{TZ_SYS_RO_PACKAGES}/org.tizen.stt-unittests.xml %{TZ_SYS_RO_APP}/org.tizen.stt-unittests/bin/stt-unittests +%{_bindir}/tizen-unittests/%{name}/run-unittest.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 429674a..1dffba8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,16 +22,14 @@ INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/common) AUX_SOURCE_DIRECTORY(src SOURCES) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../client STT_CLIENT_SOURCES) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../common STT_COMMON_SOURCES) ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"") ADD_EXECUTABLE(${UNITTEST_STT} - ${STT_COMMON_SOURCES} - ${STT_CLIENT_SOURCES} ${SOURCES} ) + +TARGET_LINK_LIBRARIES(${UNITTEST_STT} stt -ldl ${pkgs_LDFLAGS}) TARGET_LINK_LIBRARIES(${UNITTEST_STT} ${GTEST_LIBRARIES} ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS}) SET_TARGET_PROPERTIES(${UNITTEST_STT} PROPERTIES COMPILE_FLAGS "-fPIE" diff --git a/tests/src/main.cpp b/tests/src/main.cpp index a37d671..450edea 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -1,7 +1,22 @@ #include #include + +#ifdef TIZEN_TEST_GCOV +extern "C" void __gcov_flush(void); +#endif + int main(int argc, char** argv) { +#ifdef TIZEN_TEST_GCOV + setenv("GCOV_PREFIX", "/tmp", 1); +#endif + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + auto testResults = RUN_ALL_TESTS(); + +#ifdef TIZEN_TEST_GCOV + __gcov_flush(); +#endif + + return testResults; } diff --git a/tests/src/stt_denied_unittests.cpp b/tests/src/stt_denied_unittests.cpp deleted file mode 100644 index 0f17f44..0000000 --- a/tests/src/stt_denied_unittests.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "cynara_mock.h" -#include "system_info_mock.h" - -namespace { - -class STTDeniedTest : public testing::Test { - public: - virtual void SetUp() { - /* start of TC */ - cynara_check_set_result(CYNARA_API_ACCESS_DENIED); - } - virtual void TearDown() { - /* end of TC */ - cynara_check_set_result(CYNARA_API_ACCESS_ALLOWED); - } -}; - -TEST_F(STTDeniedTest, utc_stt_create_denied) -{ - int ret = STT_ERROR_NONE; - - stt_h stt = NULL; - ret = stt_create(&stt); - EXPECT_EQ(ret, STT_ERROR_PERMISSION_DENIED); -} - -} // namespace diff --git a/tests/src/stt_unittests.cpp b/tests/src/stt_unittests.cpp index ae3f74a..ba29f50 100644 --- a/tests/src/stt_unittests.cpp +++ b/tests/src/stt_unittests.cpp @@ -2166,17 +2166,4 @@ TEST_F(STTTest, utc_stt_unset_speech_status_cb_n) } } -TEST_F(STTTest, utc_stt_create_out_of_memory) -{ - int ret = STT_ERROR_NONE; - - stt_mock_calloc_set_up(sizeof(stt_client_s), 0); - - stt_h stt = NULL; - ret = stt_create(&stt); - EXPECT_EQ(ret, STT_ERROR_OUT_OF_MEMORY); - - stt_mock_calloc_set_up(sizeof(stt_client_s), sizeof(stt_client_s)); -} - } // namespace -- 2.7.4