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.
%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} \
#include <service.h>
#include <service-file-locker.h>
+#ifdef GCOV_BUILD
+extern "C" void __gcov_flush(void);
+#endif
+
#define WEBAUTHN_LOG_TAG "WEBAUTHN"
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<WA::WebAuthnLog>::Instance().SetTag(WEBAUTHN_LOG_TAG);
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
)
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
)
+++ /dev/null
-/*
- * 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 <gtest/gtest.h>
-
-int main(int argc, char *argv[])
-{
- try {
- ::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
- } catch (...) {
- return 1;
- }
-}
--- /dev/null
+/*
+ * 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 <gtest/gtest.h>
+#include <iostream>
+#include <webauthn-log.h>
+
+#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<WA::WebAuthnLog>::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;
+}