Remove uncaught_exception uses in tests 38/49538/6
authorLukasz Kostyra <l.kostyra@samsung.com>
Tue, 6 Oct 2015 13:18:25 +0000 (15:18 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Thu, 10 Dec 2015 13:43:19 +0000 (14:43 +0100)
[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

src/cynara-tests/common/cynara_test_client_async_client.cpp
src/cynara-tests/common/cynara_test_client_async_client.h
src/cynara-tests/common/cynara_test_client_async_request_monitor.cpp
src/cynara-tests/common/cynara_test_client_async_request_monitor.h
src/cynara-tests/common/cynara_test_cynara_mask.cpp
src/cynara-tests/common/cynara_test_cynara_mask.h
src/framework/include/dpl/test/test_runner.h
src/framework/src/test_runner.cpp
src/security-server-tests/security_server_tests_password.cpp

index 6c70813..32f6d37 100644 (file)
@@ -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.");
     }
 }
index 37abdc5..425e8a7 100644 (file)
@@ -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);
index 33244d0..da05fbd 100644 (file)
@@ -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.
 
 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.");
     }
index 16d4926..98f7f55 100644 (file)
@@ -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);
 
index 7044895..1394761 100644 (file)
@@ -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.");
     }
 }
index fee1e66..f8f1724 100644 (file)
@@ -29,7 +29,7 @@ class CynaraMask
 {
 public:
     CynaraMask();
-    ~CynaraMask() noexcept(false);
+    ~CynaraMask();
 
 private:
     ServiceManager m_serviceManager;
index 4f01833..c8fbdcb 100644 (file)
@@ -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)
 
index 33a4ef7..b98533d 100644 (file)
@@ -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) {
index b9f0584..a92674c 100644 (file)
@@ -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;