From: cc Date: Mon, 28 Nov 2016 12:39:35 +0000 (+0900) Subject: [IoT-1562] Handle unit test segfaults at notification service X-Git-Tag: 1.3.0~1049^2~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=681a1f3986d0f108c27e30d00c655bf1c32b5c25;p=platform%2Fupstream%2Fiotivity.git [IoT-1562] Handle unit test segfaults at notification service Fix unittest segfault caused by discovery failure. It is because external consumers or providers on the same network interupt discovery or subscription precedure. The test will be terminated once this situation happens, even though precondition of the unittest is guided to prevent this issue. Change-Id: I0f763db760d8d2af0a185b9e7c3c6e71dfc5e5bf Signed-off-by: cc Reviewed-on: https://gerrit.iotivity.org/gerrit/14851 Tested-by: jenkins-iotivity Reviewed-by: JungYong KIM Reviewed-by: Uze Choi (cherry picked from commit eb8ec52d48bb8def2a8862118d2fb97aed4c3c2f) Reviewed-on: https://gerrit.iotivity.org/gerrit/14987 Reviewed-by: Phil Coval --- diff --git a/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp b/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp index e64b3e7..295a35e 100755 --- a/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp +++ b/service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp @@ -206,6 +206,8 @@ TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithNonAccepterWhenStart std::unique_lock< std::mutex > lock { mutexForCondition }; responseCon.wait_for(lock, g_waitForResponse); + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + } TEST_F(NotificationServiceConsumerTest, DiscoverProviderWithNonAccepterWhenRescan) @@ -237,6 +239,8 @@ TEST_F(NotificationServiceConsumerTest, ExpectSubscribeSuccess) responseCon.notify_all(); }); + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + g_provider->setListener( (OIC::Service::NSProvider::ProviderStateCallback) ProviderChangedCallbackEmpty, (OIC::Service::NSProvider::MessageReceivedCallback)NotificationReceivedCallbackEmpty, @@ -402,6 +406,8 @@ TEST_F(NotificationServiceConsumerTest, ExpectCallbackReadCheckWhenConsumerPostS std::string msg = "msg"; OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED; + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do( [this]( OIC::Service::NSMessage * message) { @@ -437,6 +443,8 @@ TEST_F(NotificationServiceConsumerTest, ExpectCallbackDismissCheckWhenConsumerPo std::string msg = "msg"; OIC::Service::NSSyncInfo::NSSyncType type = OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ; + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + mocks.OnCallFunc(NotificationReceivedCallbackEmpty).Do( [this]( OIC::Service::NSMessage * message) { @@ -467,6 +475,8 @@ TEST_F(NotificationServiceConsumerTest, ExpectCallbackDismissCheckWhenConsumerPo TEST_F(NotificationServiceConsumerTest, ExpectGetProviderSuccessWithValidProviderId) { + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + OIC::Service::NSProvider *provider = OIC::Service::NSConsumerService::getInstance()->getProvider(g_provider->getProviderId()); int ret = strcmp(provider->getProviderId().c_str(), g_provider->getProviderId().c_str()); @@ -513,6 +523,8 @@ TEST_F(NotificationServiceConsumerTest, ExpectEQTopicList) topics.push_back("2"); topics.push_back("3"); + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + std::list retTopic = g_provider->getTopicList()->getTopicsList(); auto it1 = retTopic.begin(); auto it2 = topics.begin(); @@ -531,6 +543,8 @@ TEST_F(NotificationServiceConsumerTest, ExpectEQTopicList) TEST_F(NotificationServiceConsumerTest, ExpectFailUpdateTopicOnConsumer) { + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + OIC::Service::NSTopicsList *retTopic = g_provider->getTopicList(); for (auto it : retTopic->getTopicsList()) { diff --git a/service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp b/service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp index 81cb1e8..215359a 100755 --- a/service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp +++ b/service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp @@ -199,7 +199,7 @@ TEST_F(NotificationProviderServiceTest, std::unique_lock< std::mutex > lock { mutexForCondition }; responseCon.wait_for(lock, g_waitForResponse); - EXPECT_NE((void *)g_consumer, (void *)NULL); + ASSERT_NE(nullptr, g_consumer) << "error: discovery failure"; } TEST_F(NotificationProviderServiceTest, NeverCallNotifyOnConsumerByAcceptIsFalse) @@ -219,6 +219,8 @@ TEST_F(NotificationProviderServiceTest, NeverCallNotifyOnConsumerByAcceptIsFalse responseCon.notify_all(); }); + ASSERT_NE(nullptr, g_consumer) << "error: discovery failure"; + g_consumer->acceptSubscription(false); OIC::Service::NSMessage *msg = OIC::Service::NSProviderService::getInstance()->createMessage(); @@ -245,6 +247,8 @@ TEST_F(NotificationProviderServiceTest, ExpectCallNotifyOnConsumerByAcceptIsTrue { int msgID = 0; + ASSERT_NE(nullptr, g_consumer) << "error: discovery failure"; + mocks.ExpectCallFunc(MessageCallbackFromConsumerEmpty).Do( [&msgID](const int &id, const std::string &, const std::string &, const std::string &) { @@ -413,6 +417,9 @@ TEST_F(NotificationProviderServiceTest, ExpectEqualSetConsumerTopicsAndGetConsum std::string str2("TEST2"); OIC::Service::NSProviderService::getInstance()->registerTopic(str1); OIC::Service::NSProviderService::getInstance()->registerTopic(str2); + + ASSERT_NE(nullptr, g_consumer) << "error: discovery failure"; + g_consumer->setTopic(str1); std::unique_lock< std::mutex > lock { mutexForCondition }; @@ -461,6 +468,9 @@ TEST_F(NotificationProviderServiceTest, ExpectEqualUnSetConsumerTopicsAndGetCons std::string str2("TEST2"); OIC::Service::NSProviderService::getInstance()->registerTopic(str1); OIC::Service::NSProviderService::getInstance()->registerTopic(str2); + + ASSERT_NE(nullptr, g_consumer) << "error: discovery failure"; + g_consumer->setTopic(str1); g_consumer->setTopic(str2); g_consumer->unsetTopic(str1); diff --git a/service/notification/unittest/NSConsumerTest.cpp b/service/notification/unittest/NSConsumerTest.cpp index 8eb2153..4a57bde 100644 --- a/service/notification/unittest/NSConsumerTest.cpp +++ b/service/notification/unittest/NSConsumerTest.cpp @@ -255,6 +255,8 @@ TEST_F(NotificationConsumerTest, DiscoverProviderWithNonAccepterWhenStartedConsu responseCon.wait_for(lock, g_waitForResponse); EXPECT_EQ(NS_DISCOVERED, revState); + + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; } TEST_F(NotificationConsumerTest, DiscoverProviderWithNonAccepterWhenRescan) @@ -282,6 +284,9 @@ TEST_F(NotificationConsumerTest, DiscoverProviderWithNonAccepterWhenRescan) TEST_F(NotificationConsumerTest, ExpectSubscribeSuccess) { NSProviderState revState = NS_DENY; + + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + mocks.OnCallFunc(NSProviderChangedCallback).Do( [this, & revState](NSProvider * , NSProviderState state) { @@ -303,7 +308,6 @@ TEST_F(NotificationConsumerTest, ExpectReceiveNotification) uint64_t id = 10; std::string title = "title"; std::string msg = "msg"; - uint64_t revId = 0; mocks.OnCallFunc(NSNotificationReceivedCallbackEmpty).Do( @@ -526,6 +530,8 @@ TEST_F(NotificationConsumerTest, ExpectCallbackDismissCheckWhenConsumerPostSync) TEST_F(NotificationConsumerTest, ExpectGetProviderSuccessWithValidProviderId) { + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + NSProvider * provider = NSConsumerGetProvider(g_provider->providerId); int ret = strcmp(provider->providerId, g_provider->providerId); EXPECT_EQ(0, ret); @@ -546,6 +552,8 @@ TEST_F(NotificationConsumerTest, ExpectGetProviderSuccessWithNULL) TEST_F(NotificationConsumerTest, ExpectGetTopicListIsNULL) { + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + NSTopicLL * currentTopics = NSConsumerGetTopicList(g_provider->providerId); EXPECT_EQ(NULL, currentTopics); } @@ -583,6 +591,8 @@ TEST_F(NotificationConsumerTest, ExpectEQTopicList) topics.push_back("2"); topics.push_back("3"); + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + NSTopicLL * retTopic = NSConsumerGetTopicList(g_provider->providerId); std::for_each (topics.begin(), topics.end(), [this, & retTopic, & isSame](const std::string & str) @@ -596,6 +606,8 @@ TEST_F(NotificationConsumerTest, ExpectEQTopicList) TEST_F(NotificationConsumerTest, ExpectFailUpdateTopicOnConsumer) { + ASSERT_NE(nullptr, g_provider) << "error: discovery failure"; + NSTopicLL * retTopic = NSConsumerGetTopicList(g_provider->providerId); for (; retTopic; retTopic = retTopic->next) { diff --git a/service/notification/unittest/NSProviderTest.cpp b/service/notification/unittest/NSProviderTest.cpp index 0349297..dda37b9 100755 --- a/service/notification/unittest/NSProviderTest.cpp +++ b/service/notification/unittest/NSProviderTest.cpp @@ -208,7 +208,7 @@ TEST_F(NotificationProviderTest, ExpectCallbackWhenReceiveSubscribeRequestWithAc std::unique_lock< std::mutex > lock{ mutexForCondition }; responseCon.wait_for(lock, g_waitForResponse); - EXPECT_NE((void*)g_consumerID, (void*)NULL); + ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure"; } TEST_F(NotificationProviderTest, NeverCallNotifyOnConsumerByAcceptIsFalse) @@ -216,6 +216,8 @@ TEST_F(NotificationProviderTest, NeverCallNotifyOnConsumerByAcceptIsFalse) bool expectTrue = true; int msgID; + ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure"; + mocks.OnCallFunc(NSMessageCallbackFromConsumerEmpty).Do( [& expectTrue, &msgID](const int &id, const std::string&, const std::string&, const std::string&) { @@ -254,6 +256,8 @@ TEST_F(NotificationProviderTest, ExpectCallNotifyOnConsumerByAcceptIsTrue) { int msgID; + ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure"; + mocks.ExpectCallFunc(NSMessageCallbackFromConsumerEmpty).Do( [&msgID](const int &id, const std::string&, const std::string&, const std::string&) { @@ -281,6 +285,8 @@ TEST_F(NotificationProviderTest, ExpectCallbackSyncOnReadToConsumer) { int id; + ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure"; + mocks.ExpectCallFunc(NSSyncCallbackFromConsumerEmpty).Do( [& id](int & type, int &syncId) { @@ -308,6 +314,9 @@ TEST_F(NotificationProviderTest, ExpectCallbackSyncOnReadFromConsumer) { int type = NS_SYNC_READ; int id; + + ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure"; + mocks.ExpectCallFunc(NSSyncCallbackEmpty).Do( [& id](NSSyncInfo * sync) { @@ -441,6 +450,9 @@ TEST_F(NotificationProviderTest, ExpectEqualUnSetConsumerTopicsAndGetConsumerTop responseCon.wait_for(lock, g_waitForResponse); bool isSame = false; + + ASSERT_NE(nullptr, g_consumerID) << "error: discovery failure"; + NSTopicLL * topics = NSProviderGetConsumerTopics(g_consumerID); if(!topics)