From: Mateusz Malicki Date: Wed, 14 Jan 2015 14:28:01 +0000 (+0100) Subject: Fix: Drop exception thrown from async callback X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e649fc7da6a8db91320c1e9f2aed653fba8dce69;p=platform%2Fcore%2Fsecurity%2Fvasum.git Fix: Drop exception thrown from async callback [Bug/Feature] Crash when exception are thrown from async callback [Cause] Exception from async callback [Solution] Drop exception [Verification] Build, install, run test on slp Change-Id: I00fad962beb488508d25a21a68ee7e487f317ba0 --- diff --git a/tests/unit_tests/server/ut-zones-manager.cpp b/tests/unit_tests/server/ut-zones-manager.cpp index a733e05..5b29340 100644 --- a/tests/unit_tests/server/ut-zones-manager.cpp +++ b/tests/unit_tests/server/ut-zones-manager.cpp @@ -42,6 +42,7 @@ #include "utils/fs.hpp" #include "utils/img.hpp" #include "utils/scoped-dir.hpp" +#include "logger/logger.hpp" #include #include @@ -79,6 +80,22 @@ const std::string FILE_CONTENT = "File content\n" const std::string NON_EXISTANT_ZONE_ID = "NON_EXISTANT_ZONE_ID"; const std::string ZONES_PATH = "/tmp/ut-zones"; // the same as in daemon.conf +/** + * Currently there is no way to propagate an error from async call + * dropException are used to prevent system crash + **/ +DbusConnection::AsyncMethodCallCallback +dropException(const DbusConnection::AsyncMethodCallCallback& fun) +{ + return [fun](dbus::AsyncMethodCallResult& arg) -> void { + try { + fun(arg); + } catch (const std::exception& ex) { + LOGE("Got exception: " << ex.what()); + } + }; +} + class DbusAccessory { public: static const int HOST_ID = 0; @@ -326,7 +343,7 @@ public: api::host::METHOD_CREATE_ZONE, parameters, "()", - asyncResult); + dropException(asyncResult)); } void callAsyncMethodDestroyZone(const std::string& id, @@ -346,7 +363,7 @@ public: api::host::METHOD_DESTROY_ZONE, parameters, "()", - asyncResult); + dropException(asyncResult)); } void callAsyncMethodShutdownZone(const std::string& id, @@ -366,7 +383,7 @@ public: api::host::METHOD_SHUTDOWN_ZONE, parameters, "()", - asyncResult); + dropException(asyncResult)); } void callAsyncMethodStartZone(const std::string& id, @@ -386,7 +403,7 @@ public: api::host::METHOD_START_ZONE, parameters, "()", - asyncResult); + dropException(asyncResult)); } void callMethodLockZone(const std::string& id) @@ -576,8 +593,8 @@ BOOST_AUTO_TEST_CASE(NotifyActiveZoneTest) dbus.second->callMethodNotify(); } - BOOST_CHECK(signalReceivedLatch.waitForN(dbuses.size() - 1u, EVENT_TIMEOUT)); - BOOST_CHECK(signalReceivedLatch.empty()); + BOOST_REQUIRE(signalReceivedLatch.waitForN(dbuses.size() - 1u, EVENT_TIMEOUT)); + BOOST_REQUIRE(signalReceivedLatch.empty()); //check if there are no signals that was received more than once for (const auto& source : signalReceivedSourcesMap[1]) { @@ -718,8 +735,8 @@ BOOST_AUTO_TEST_CASE(MoveFileTest) BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE2, TMP + "/file"), api::zone::FILE_MOVE_SUCCEEDED); - BOOST_CHECK(notificationLatch.wait(EVENT_TIMEOUT)); - BOOST_CHECK(notificationLatch.empty()); + BOOST_REQUIRE(notificationLatch.wait(EVENT_TIMEOUT)); + BOOST_REQUIRE(notificationLatch.empty()); BOOST_CHECK_EQUAL(notificationSource, ZONE1); BOOST_CHECK_EQUAL(notificationPath, TMP + "/file"); BOOST_CHECK_EQUAL(notificationRetcode, api::zone::FILE_MOVE_SUCCEEDED);