diff --git a/source/bulkdata/profilexconf.c b/source/bulkdata/profilexconf.c index c2c1d874..41abe597 100644 --- a/source/bulkdata/profilexconf.c +++ b/source/bulkdata/profilexconf.c @@ -113,6 +113,29 @@ static void freeConfig(void *data) } } +static void publishReportUploadStatusForResult(T2ERROR ret) +{ + pthread_mutex_lock(&xconfProfileLock); + bool localIsOnDemandReport = isOnDemandReport; + bool localIsAbortTriggered = isAbortTriggered; + isAbortTriggered = false; + pthread_mutex_unlock(&xconfProfileLock); + + if(!localIsOnDemandReport) + { + return; + } + + if(ret == T2ERROR_FAILURE) + { + publishReportUploadStatus(localIsAbortTriggered ? "ABORTED" : "FAILURE"); + } + else + { + publishReportUploadStatus("SUCCESS"); + } +} + static void freeProfileXConf() { if(singleProfile != NULL) @@ -548,30 +571,7 @@ static void* CollectAndReportXconf(void* data) } // Notify status of upload in case of on demand report upload. - if(isOnDemandReport) - { - if(ret == T2ERROR_FAILURE) - { - if(isAbortTriggered) - { - publishReportUploadStatus("ABORTED"); - } - else - { - publishReportUploadStatus("FAILURE"); - } - } - else - { - publishReportUploadStatus("SUCCESS"); - } - } - - // Reset the abort trigger flags - if(isAbortTriggered == true) - { - isAbortTriggered = false ; - } + publishReportUploadStatusForResult(ret); /* CRITICAL SECTION START: Re-acquire xconfProfileLock before updating profile state. * pthread_cond_wait requires us to hold xconfProfileLock, so we acquire it here @@ -1186,6 +1186,19 @@ T2ERROR ProfileXConf_storeMarkerEvent(T2Event *eventInfo) return T2ERROR_SUCCESS; } #ifdef GTEST_ENABLE +void test_setReportUploadStatusState(bool isOnDemand, bool isAbort) +{ + pthread_mutex_lock(&xconfProfileLock); + isOnDemandReport = isOnDemand; + isAbortTriggered = isAbort; + pthread_mutex_unlock(&xconfProfileLock); +} + +void test_publishReportUploadStatusForResult(T2ERROR ret) +{ + publishReportUploadStatusForResult(ret); +} + void test_set_reportThreadExits(bool value) { reportThreadExits = value; diff --git a/source/test/bulkdata/profilexconfTest.cpp b/source/test/bulkdata/profilexconfTest.cpp index 7ab28d2d..e2ad1068 100644 --- a/source/test/bulkdata/profilexconfTest.cpp +++ b/source/test/bulkdata/profilexconfTest.cpp @@ -55,6 +55,9 @@ using ::testing::Invoke; using ::testing::SetArgPointee; using ::testing::DoAll; +extern "C" void test_setReportUploadStatusState(bool isOnDemand, bool isAbort); +extern "C" void test_publishReportUploadStatusForResult(T2ERROR ret); + rbusMock* g_rbusMock = nullptr; SystemMock* g_systemMock = nullptr; FileMock* g_fileIOMock = nullptr; @@ -548,6 +551,29 @@ TEST_F(profileXconfTestFixture, ReportProfiles_storeMarkerEvent_success_2) free(eventInfo); } +TEST_F(profileXconfTestFixture, ProfileXConf_OnDemandStatusSnapshot) +{ + testing::InSequence sequence; + EXPECT_CALL(*g_profileXConfMock, publishReportUploadStatus(StrEq("ABORTED"))) + .Times(1); + EXPECT_CALL(*g_profileXConfMock, publishReportUploadStatus(StrEq("FAILURE"))) + .Times(1); + + test_setReportUploadStatusState(true, true); + test_publishReportUploadStatusForResult(T2ERROR_FAILURE); + test_publishReportUploadStatusForResult(T2ERROR_FAILURE); + test_setReportUploadStatusState(false, false); +} + +TEST_F(profileXconfTestFixture, ProfileXConf_NonOnDemandStatusIsIgnored) +{ + EXPECT_CALL(*g_profileXConfMock, publishReportUploadStatus(_)) + .Times(0); + + test_setReportUploadStatusState(false, true); + test_publishReportUploadStatusForResult(T2ERROR_FAILURE); +} + //ProfileXConf_notifyTimeout Test the timeout of the profile /* TEST_F(profileXconfTestFixture, ProfileXConf_notifyTimeout)