From: Yonggoo Kang Date: Thu, 14 Mar 2024 07:03:40 +0000 (+0900) Subject: Enable gcov X-Git-Tag: accepted/tizen/unified/20240423.164622~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d96e97708b75b5cddd116fed11f1526cd51418a2;p=platform%2Fcore%2Fsecurity%2Fwebauthn.git Enable gcov - Add settings - Change filename tests/main.cpp to unittests.cpp to distinguish it from server/main.cpp Change-Id: I60a32e2eb1a347987bfde1e2a5aacd151dac3a7e --- diff --git a/CMakeLists.txt b/CMakeLists.txt index bf910d5..36eca2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,14 @@ SET(CMAKE_CXX_FLAGS_RELEASE "-g -std=c++17 -O2") SET(CMAKE_C_FLAGS_CCOV "-g -std=c99 -O2 --coverage") SET(CMAKE_CXX_FLAGS_CCOV "-g -std=c++17 -O2 --coverage") +# If gcov enabled, add build options and set the variable used in source codes +IF(GCOV_BUILD) +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") +SET(LDFLAGS "${LDFLAGS} -lgcov") +ADD_DEFINITIONS("-DGCOV_BUILD=\"${GCOV_BUILD}\"") +ENDIF(GCOV_BUILD) + # If supported for the target machine, emit position-independent code,suitable # for dynamic linking and avoiding any limit on the size of the global offset # table. This option makes a difference on the m68k, PowerPC and SPARC. diff --git a/packaging/webauthn.spec b/packaging/webauthn.spec index 9f76326..9b60617 100644 --- a/packaging/webauthn.spec +++ b/packaging/webauthn.spec @@ -97,7 +97,8 @@ Web Authentication Service (unit tests) %setup -q %build -%cmake . -DPREFIX=%{_prefix} \ +%cmake . -DGCOV_BUILD=%{?gcov:1}%{!?gcov:0} \ + -DPREFIX=%{_prefix} \ -DEXEC_PREFIX=%{_exec_prefix} \ -DINCLUDEDIR=%{_includedir} \ -DLIB_DIR=%{lib_dir} \ diff --git a/srcs/server/main.cpp b/srcs/server/main.cpp index a283f88..8223a0b 100644 --- a/srcs/server/main.cpp +++ b/srcs/server/main.cpp @@ -27,6 +27,10 @@ #include #include +#ifdef GCOV_BUILD +extern "C" void __gcov_flush(void); +#endif + #define WEBAUTHN_LOG_TAG "WEBAUTHN" int webauthn_manager() @@ -48,6 +52,10 @@ int webauthn_manager() int main(void) { +#ifdef GCOV_BUILD + setenv("GCOV_PREFIX", "/tmp", 1); +#endif + int ret = EXIT_FAILURE; UNHANDLED_EXCEPTION_HANDLER_BEGIN { WA::Singleton::Instance().SetTag(WEBAUTHN_LOG_TAG); @@ -62,11 +70,15 @@ int main(void) LogError("Error in pthread_sigmask"); return EXIT_FAILURE; } - return webauthn_manager(); + ret = webauthn_manager(); } catch (const std::runtime_error &e) { LogError(e.what()); } UNHANDLED_EXCEPTION_HANDLER_END - - return EXIT_SUCCESS; +#ifdef GCOV_BUILD + LogDebug("Flushing gcov"); + __gcov_flush(); +#endif + LogDebug("Stopping server.."); + return ret; } \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bf33e8c..bb14e0d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,7 +5,7 @@ PKG_CHECK_MODULES(UNIT_TESTS_DEPS ) SET(UNIT_TESTS_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/unittests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/webauthn-client-test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/serialization-test.cpp ) diff --git a/tests/main.cpp b/tests/main.cpp deleted file mode 100644 index 343f8ad..0000000 --- a/tests/main.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved - * - * 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 - * - * - * @file main.cpp - * @version 1.0 - * @brief unit tests for webauthn - */ - - -#include - -int main(int argc, char *argv[]) -{ - try { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); - } catch (...) { - return 1; - } -} diff --git a/tests/unittests.cpp b/tests/unittests.cpp new file mode 100644 index 0000000..84965df --- /dev/null +++ b/tests/unittests.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved + * + * 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 + * + * + * @file main.cpp + * @version 1.0 + * @brief unit tests for webauthn + */ + + +#include +#include +#include + +#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::Instance().SetTag(WEBAUTHN_TEST_LOG_TAG); + + bool ret = false; + LogDebug("START"); +#ifdef GCOV_BUILD + LogDebug("SET GCOV_PREFIX"); + setenv("GCOV_PREFIX", "/tmp", 1); +#endif + try { + ::testing::InitGoogleTest(&argc, argv); + ret = RUN_ALL_TESTS(); + } catch (...) { + ret = true; + } +#ifdef GCOV_BUILD + LogDebug("Waiting 2 mins for terminating webauthn-server process to flush gcov"); + std::cout << "Waiting 2 mins for terminating webauthn-server process to flush gcov" + << std::endl; + sleep(120); +#endif + return ret; +}