From 341503434c437571d02c4f8d4eaa7aaf4c489f2f Mon Sep 17 00:00:00 2001 From: Lukasz Kostyra Date: Tue, 6 Oct 2015 15:18:25 +0200 Subject: [PATCH] Remove uncaught_exception uses in tests [Bug/Feature] uncaught_exception is bugged since 2008 and can return a false result on some specific situations (refer to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37477 for more info). Some tests (especially Cynara Agent) relied on uncaught_exception, which when failed resulted in double-throwing. This caused instant test termination and emitted SIGABRT. [Solution] Remove uncaught_exception calls, reorganize some test parts to avoid throws propagating outside destructors. Additionally, minor corrections to boilerplates (copyright date) were made. [Verification] Build, install, run tests several times on mobile image. The tests should not receive SIGABRT during Cynara Agent tests. Test results should be unaltered (some of the tests fail due to timeouts). Change-Id: Iab282e9cac8bd53a69bb60d84511cd6829540037 --- .../common/cynara_test_client_async_client.cpp | 7 ++----- .../common/cynara_test_client_async_client.h | 4 ++-- .../common/cynara_test_client_async_request_monitor.cpp | 17 +++++++---------- .../common/cynara_test_client_async_request_monitor.h | 4 ++-- src/cynara-tests/common/cynara_test_cynara_mask.cpp | 5 +---- src/cynara-tests/common/cynara_test_cynara_mask.h | 2 +- src/framework/include/dpl/test/test_runner.h | 8 ++------ src/framework/src/test_runner.cpp | 7 +++---- .../security_server_tests_password.cpp | 10 +++------- 9 files changed, 23 insertions(+), 41 deletions(-) diff --git a/src/cynara-tests/common/cynara_test_client_async_client.cpp b/src/cynara-tests/common/cynara_test_client_async_client.cpp index 6c70813..32f6d37 100644 --- a/src/cynara-tests/common/cynara_test_client_async_client.cpp +++ b/src/cynara-tests/common/cynara_test_client_async_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2015 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. @@ -63,15 +63,12 @@ Client::Client(const StatusFunction &userFunction) assertStatus(DISCONNECTED); } -Client::~Client() noexcept(false) +Client::~Client() { - bool oops = std::uncaught_exception(); try { RUNNER_DEFER_SCOPE(cynara_async_finish(m_cynara);); assertStatus(DISCONNECTED); } catch (...) { - if (!oops) - throw; RUNNER_ERROR_MSG("Error: more exceptions thrown while releasing CynaraTestAsync::Client."); } } diff --git a/src/cynara-tests/common/cynara_test_client_async_client.h b/src/cynara-tests/common/cynara_test_client_async_client.h index 37abdc5..425e8a7 100644 --- a/src/cynara-tests/common/cynara_test_client_async_client.h +++ b/src/cynara-tests/common/cynara_test_client_async_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2015 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. @@ -51,7 +51,7 @@ public: }; Client(const StatusFunction &userFunction = StatusFunction()); - ~Client() noexcept(false); + ~Client(); void assertStatus(enum SocketStatus expectedStatus); void checkCache(const CheckData &checkData, int expectedResult); diff --git a/src/cynara-tests/common/cynara_test_client_async_request_monitor.cpp b/src/cynara-tests/common/cynara_test_client_async_request_monitor.cpp index 33244d0..da05fbd 100644 --- a/src/cynara-tests/common/cynara_test_client_async_request_monitor.cpp +++ b/src/cynara-tests/common/cynara_test_client_async_request_monitor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2015 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. @@ -22,22 +22,19 @@ namespace CynaraTestClientAsync { -RequestMonitor::~RequestMonitor() noexcept(false) +RequestMonitor::~RequestMonitor() { - bool oops = std::uncaught_exception(); try { for (auto ent : m_requests) { - RUNNER_ERROR_MSG("There was no callback for request with:" - << "id = " << ent.first << "," - << "expectedResponse = " << ent.second.m_expectedResponse << "," + RUNNER_ERROR_MSG("There was no callback for request with: " + << "id = " << ent.first << ", " + << "expectedResponse = " << ent.second.m_expectedResponse << ", " << "expectedCause = " << ent.second.m_expectedCause << "."); } - RUNNER_ASSERT_MSG(m_requests.empty(), - m_requests.size() << "requests does not receive callback."); + if (!m_requests.empty()) + RUNNER_ERROR_MSG(m_requests.size() << " requests did not receive callback."); } catch (...) { - if (!oops) - throw; RUNNER_ERROR_MSG("Error: more exceptions thrown while releasing" " CynaraTestAsync::RequestMonitor."); } diff --git a/src/cynara-tests/common/cynara_test_client_async_request_monitor.h b/src/cynara-tests/common/cynara_test_client_async_request_monitor.h index 16d4926..98f7f55 100644 --- a/src/cynara-tests/common/cynara_test_client_async_request_monitor.h +++ b/src/cynara-tests/common/cynara_test_client_async_request_monitor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2015 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. @@ -36,7 +36,7 @@ struct RequestEntity class RequestMonitor { public: - ~RequestMonitor() noexcept(false); + ~RequestMonitor(); void registerRequest(cynara_check_id id, const RequestEntity &request); diff --git a/src/cynara-tests/common/cynara_test_cynara_mask.cpp b/src/cynara-tests/common/cynara_test_cynara_mask.cpp index 7044895..1394761 100644 --- a/src/cynara-tests/common/cynara_test_cynara_mask.cpp +++ b/src/cynara-tests/common/cynara_test_cynara_mask.cpp @@ -33,15 +33,12 @@ CynaraMask::CynaraMask() : m_serviceManager(CynaraTestConsts::SERVICE) m_serviceManager.stopService(); } -CynaraMask::~CynaraMask() noexcept(false) +CynaraMask::~CynaraMask() { - bool oops = std::uncaught_exception(); try { m_serviceManager.unmaskService(); m_serviceManager.startService(); } catch (...) { - if (!oops) - throw; RUNNER_ERROR_MSG("Error: more exceptions thrown while releasing CynaraMask."); } } diff --git a/src/cynara-tests/common/cynara_test_cynara_mask.h b/src/cynara-tests/common/cynara_test_cynara_mask.h index fee1e66..f8f1724 100644 --- a/src/cynara-tests/common/cynara_test_cynara_mask.h +++ b/src/cynara-tests/common/cynara_test_cynara_mask.h @@ -29,7 +29,7 @@ class CynaraMask { public: CynaraMask(); - ~CynaraMask() noexcept(false); + ~CynaraMask(); private: ServiceManager m_serviceManager; diff --git a/src/framework/include/dpl/test/test_runner.h b/src/framework/include/dpl/test/test_runner.h index 4f01833..c8fbdcb 100644 --- a/src/framework/include/dpl/test/test_runner.h +++ b/src/framework/include/dpl/test/test_runner.h @@ -246,9 +246,7 @@ protected: __FILE__, \ __LINE__, \ assertMsg.str()); \ - if (!std::uncaught_exception()) \ - throw e; \ - DPL::Test::TestRunnerSingleton::Instance().addFailReason(e.GetMessage()); \ + throw e; \ } \ } while (0) @@ -267,9 +265,7 @@ protected: __FILE__, \ __LINE__, \ assertMsg.str()); \ - if (!std::uncaught_exception()) \ - throw e; \ - DPL::Test::TestRunnerSingleton::Instance().addFailReason(e.GetMessage()); \ + throw e; \ } \ } while (0) diff --git a/src/framework/src/test_runner.cpp b/src/framework/src/test_runner.cpp index 33a4ef7..b98533d 100644 --- a/src/framework/src/test_runner.cpp +++ b/src/framework/src/test_runner.cpp @@ -750,12 +750,11 @@ void TestRunner::deferEnd() if (m_deferDeepness > 0) return; - bool oops = std::uncaught_exception(); - size_t additionalExceptions = oops ? 0 : 1; - for (size_t i = additionalExceptions; i < m_deferredExceptionsMessages.size(); ++i) + for (size_t i = 0; i < m_deferredExceptionsMessages.size(); ++i) { addFailReason(m_deferredExceptionsMessages[i]); + } - if (!oops && !m_deferredExceptionsMessages.empty()) + if (!m_deferredExceptionsMessages.empty()) { m_deferredExceptionsMessages.clear(); switch (m_firstDeferredExceptionType) { diff --git a/src/security-server-tests/security_server_tests_password.cpp b/src/security-server-tests/security_server_tests_password.cpp index b9f0584..a92674c 100644 --- a/src/security-server-tests/security_server_tests_password.cpp +++ b/src/security-server-tests/security_server_tests_password.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved */ /* * @file security_server_tests_password.cpp @@ -66,12 +66,8 @@ struct SystemClock { } ~SystemClock() { - if (std::uncaught_exception()) { - stime(&m_original); - return; - } - - RUNNER_ASSERT_ERRNO(0 == stime(&m_original)); + if (stime(&m_original) != 0) + RUNNER_ERROR_MSG("Failed to set time. Error: " << strerror(errno)); } private: time_t m_original; -- 2.7.4