Skip to content
61 changes: 37 additions & 24 deletions source/bulkdata/profilexconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions source/test/bulkdata/profilexconfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Loading