Skip to content

Commit af91914

Browse files
adrianM27goruklu
authored andcommitted
RDK-54097: Add L2 Thunder R4.4.1 tests for Analytics plugin with fixes
1 parent 724e5fa commit af91914

File tree

16 files changed

+1042
-88
lines changed

16 files changed

+1042
-88
lines changed

.github/workflows/L2-tests-R4-4-1.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ jobs:
280280
-DDS_FOUND=ON
281281
-DPLUGIN_ANALYTICS=ON
282282
-DPLUGIN_ANALYTICS_SIFT_BACKEND=ON
283-
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
283+
-DPLUGIN_ANALYTICS_SIFT_2_0_ENABLED="true"
284+
-DPLUGIN_ANALYTICS_SIFT_MAX_RANDOMISATION_WINDOW_TIME=15
285+
-DPLUGIN_ANALYTICS_SIFT_STORE_PATH="/tmp/AnalyticsSiftStore"
286+
-DPLUGIN_ANALYTICS_SIFT_URL="127.0.0.1:12345"
284287
&&
285288
cmake --build build/rdkservices -j8
286289
&&

Analytics/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ set(MODULE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
3030

3131
option(PLUGIN_ANALYTICS_SIFT_BACKEND "Enable Sift backend" OFF)
3232

33-
3433
set(PLUGIN_ANALYTICS_STARTUPORDER "" CACHE STRING "To configure startup order of Analytics plugin")
3534
set(PLUGIN_ANALYTICS_AUTOSTART "false" CACHE STRING "Automatically start Analytics plugin")
3635
set(PLUGIN_ANALYTICS_DEVICE_OS_NAME "rdk" CACHE STRING "Device OS name")
@@ -87,6 +86,19 @@ target_link_libraries(${MODULE_NAME}
8786
${MODULE_NAME}Backends
8887
${MODULE_NAME}SystemTime)
8988

89+
if (RDK_SERVICE_L2_TEST)
90+
target_compile_definitions(${MODULE_NAME} PRIVATE MODULE_NAME=Plugin_${PLUGIN_NAME})
91+
target_compile_options(${MODULE_NAME} PRIVATE -Wno-error)
92+
93+
find_library(TESTMOCKLIB_LIBRARIES NAMES TestMocklib)
94+
if (TESTMOCKLIB_LIBRARIES)
95+
message ("linking mock libraries ${TESTMOCKLIB_LIBRARIES} library")
96+
target_link_libraries(${MODULE_NAME} PRIVATE ${TESTMOCKLIB_LIBRARIES})
97+
else (TESTMOCKLIB_LIBRARIES)
98+
message ("Require ${TESTMOCKLIB_LIBRARIES} library")
99+
endif (TESTMOCKLIB_LIBRARIES)
100+
endif (RDK_SERVICES_L2_TEST)
101+
90102
install(TARGETS ${MODULE_NAME}
91103
DESTINATION lib/${STORAGE_DIRECTORY}/plugins)
92104

Analytics/Implementation/AnalyticsImplementation.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,18 @@ namespace Plugin {
162162
queueTimeout = std::chrono::milliseconds(POPULATE_DEVICE_INFO_RETRY_MS);
163163
}
164164

165-
if (queueTimeout == std::chrono::milliseconds::max())
165+
if (mActionQueue.empty())
166166
{
167-
mQueueCondition.wait(lock, [this] { return !mActionQueue.empty(); });
168-
}
169-
else
170-
{
171-
mQueueCondition.wait_for(lock, queueTimeout, [this] { return !mActionQueue.empty(); });
167+
if (queueTimeout == std::chrono::milliseconds::max())
168+
{
169+
mQueueCondition.wait(lock, [this]
170+
{ return !mActionQueue.empty(); });
171+
}
172+
else
173+
{
174+
mQueueCondition.wait_for(lock, queueTimeout, [this]
175+
{ return !mActionQueue.empty(); });
176+
}
172177
}
173178

174179
Action action = {ACTION_TYPE_UNDEF, nullptr};
@@ -249,9 +254,18 @@ namespace Plugin {
249254
bool AnalyticsImplementation::IsSysTimeValid()
250255
{
251256
bool ret = false;
257+
// Time is valid if system time is available and time zone is set
252258
if (mSysTime != nullptr)
253259
{
254-
ret = mSysTime->IsSystemTimeAvailable();
260+
if (mSysTime->IsSystemTimeAvailable())
261+
{
262+
int32_t offset = 0;
263+
SystemTime::TimeZoneAccuracy acc = mSysTime->GetTimeZoneOffset(offset);
264+
if (acc == SystemTime::TimeZoneAccuracy::FINAL)
265+
{
266+
ret = true;
267+
}
268+
}
255269
}
256270

257271
return ret;

Analytics/Implementation/Backend/Sift/SiftBackend.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,18 @@ namespace WPEFramework
9696
queueTimeout = std::chrono::milliseconds(POPULATE_CONFIG_TIMEOUT_MS);
9797
}
9898

99-
if (queueTimeout == std::chrono::milliseconds::max())
100-
{
101-
mQueueCondition.wait(lock, [this] { return !mActionQueue.empty(); });
102-
}
103-
else
99+
if (mActionQueue.empty())
104100
{
105-
mQueueCondition.wait_for(lock, queueTimeout, [this] { return !mActionQueue.empty(); });
101+
if (queueTimeout == std::chrono::milliseconds::max())
102+
{
103+
mQueueCondition.wait(lock, [this]
104+
{ return !mActionQueue.empty(); });
105+
}
106+
else
107+
{
108+
mQueueCondition.wait_for(lock, queueTimeout, [this]
109+
{ return !mActionQueue.empty(); });
110+
}
106111
}
107112

108113
Action action = {ACTION_TYPE_UNDEF, nullptr};
@@ -169,6 +174,7 @@ namespace WPEFramework
169174
{
170175
configValid = false;
171176
}
177+
172178
lock.unlock();
173179

174180
switch (action.type)

Analytics/Implementation/Backend/Sift/SiftConfig.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#define PERSISTENT_STORE_ACCOUNT_PROFILE_NAMESPACE "accountProfile"
3131
#define JSONRPC_THUNDER_TIMEOUT 20000
3232
#define THUNDER_ACCESS_DEFAULT_VALUE "127.0.0.1:9998"
33-
#define SIFT_PARTNER_ID_DFL "rdk"
3433

3534
namespace WPEFramework
3635
{
@@ -510,6 +509,7 @@ namespace WPEFramework
510509
mAttributes.proposition = config.Sift.PlatformDfl.Value();
511510

512511
mStoreConfig.path = config.Sift.StorePath.Value();
512+
SYSLOG(Logging::Startup, ("Sift Store Path: %s", mStoreConfig.path.c_str()));
513513
mStoreConfig.eventsLimit = config.Sift.EventsLimit.Value();
514514

515515
mUploaderConfig.url = config.Sift.Url.Value();
@@ -621,7 +621,6 @@ namespace WPEFramework
621621
{
622622
LOGERR("Failed to get AuthService link");
623623
mMutex.lock();
624-
mAttributes.partnerId = SIFT_PARTNER_ID_DFL;
625624
mAttributes.activated = false;
626625
mMutex.unlock();
627626
}
@@ -667,6 +666,14 @@ namespace WPEFramework
667666
LOGINFO("Got deviceModel %s", mAttributes.deviceModel.c_str());
668667
}
669668

669+
mMutex.lock();
670+
if (result == Core::ERROR_NONE && mAttributes.partnerId.empty() && response.HasLabel("friendly_id"))
671+
{
672+
mAttributes.partnerId = response["friendly_id"].String();
673+
LOGINFO("Got partnerId %s", mAttributes.partnerId.c_str());
674+
}
675+
mMutex.unlock();
676+
670677
// Get deviceFriendlyName from System.1.getFriendlyName[friendlyName]
671678
result = systemLink->Invoke<JsonObject, JsonObject>(JSONRPC_THUNDER_TIMEOUT, "getFriendlyName", params, response);
672679
if (result == Core::ERROR_NONE && response.HasLabel("friendlyName"))

Analytics/Implementation/Backend/Sift/SiftUploader.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,12 @@ namespace WPEFramework
8383
case SiftUploader::UploaderState::RANDOMISATION_WINDOW_WAIT_STATE:
8484
{
8585
std::unique_lock<std::mutex> lock( mMutex );
86-
mCondition.wait_for(lock, std::chrono::seconds(RandomisationWindowTimeGenerator()),
87-
[this] () { return mStop; } );
8886
if (mStop)
8987
{
90-
LOGINFO("SiftUploader Run exit");
91-
return;
88+
break;
9289
}
90+
mCondition.wait_for(lock, std::chrono::seconds(RandomisationWindowTimeGenerator()),
91+
[this] () { return mStop; } );
9392

9493
mUploaderState = SiftUploader::UploaderState::COLLECT_ANALYTICS;
9594
}
@@ -122,7 +121,7 @@ namespace WPEFramework
122121
}
123122
else
124123
{
125-
LOGINFO("No events collected from analytics Store");
124+
// No events to be sent, so go back to the randomisation window wait state
126125
mUploaderState = UploaderState::RANDOMISATION_WINDOW_WAIT_STATE;
127126
break;
128127
}
@@ -135,7 +134,7 @@ namespace WPEFramework
135134

136135
std::string resp;
137136

138-
uint32_t respcode;
137+
long respcode;
139138

140139
LOGINFO("Posting analytics events: %s", jsonEventPayload.c_str());
141140

@@ -159,18 +158,18 @@ namespace WPEFramework
159158
{
160159
LOGERR("No collected events to be deleted");
161160
}
162-
163-
mUploaderState = UploaderState::RANDOMISATION_WINDOW_WAIT_STATE;
164161
}
165162
else
166163
{
167-
LOGERR("Failed to post analytics event - respcode: %u, response: %s", respcode, resp.c_str());
164+
LOGERR("Failed to post analytics event - respcode: %ld, response: %s", respcode, resp.c_str());
168165
}
169166

170167
if (!resp.empty())
171168
{
172169
validateResponse(resp, collectedEvents);
173170
}
171+
172+
mUploaderState = UploaderState::RANDOMISATION_WINDOW_WAIT_STATE;
174173
}
175174
break;
176175

@@ -180,36 +179,43 @@ namespace WPEFramework
180179
}
181180
break;
182181
}
182+
183+
std::unique_lock<std::mutex> lock( mMutex );
184+
if (mStop)
185+
{
186+
LOGINFO("SiftUploader Run exit");
187+
return;
188+
}
183189
}
184190
}
185191

186192
bool SiftUploader::PerformWaitIfRetryNeeded()
187193
{
188194
bool retry = false;
189195

190-
if (mCurrentRetryCount == mMaxRetries)
196+
if (mCurrentRetryCount >= mMaxRetries)
191197
{
192198
mCurrentRetryCount = 0;
193199
}
194200
else
195201
{
196202
static auto retryTime = mMinRetryPeriod;
197203

198-
if (retryTime > mMaxRetryPeriod)
204+
if (retryTime >= mMaxRetryPeriod)
199205
{
200206
retryTime = mMinRetryPeriod;
201207
}
202208

203209
LOGINFO("Failed posting retry wait time: %d seconds, with retries completed: %d", retryTime, mCurrentRetryCount);
204210

205211
std::unique_lock<std::mutex> lock( mMutex );
206-
mCondition.wait_for(lock, std::chrono::seconds(retryTime),
207-
[this] () { return mStop; } );
208212
if (mStop)
209213
{
210214
// return immediately if stop is set
211215
return false;
212216
}
217+
mCondition.wait_for(lock, std::chrono::seconds(retryTime),
218+
[this] () { return mStop; } );
213219

214220
if (retryTime < mMaxRetryPeriod)
215221
{
@@ -218,7 +224,7 @@ namespace WPEFramework
218224

219225
++mCurrentRetryCount;
220226

221-
retry = true;
227+
retry = !mStop;
222228
}
223229

224230
return retry;
@@ -264,10 +270,6 @@ namespace WPEFramework
264270
LOGINFO("Got no events from the analytics store");
265271
}
266272
}
267-
else
268-
{
269-
LOGINFO("No events available to be collected from analytics store");
270-
}
271273

272274
return success;
273275
}
@@ -374,11 +376,11 @@ namespace WPEFramework
374376
return size * nmemb;
375377
}
376378

377-
uint32_t SiftUploader::PostJson(const std::string &url, const std::string &json, std::string &response)
379+
long SiftUploader::PostJson(const std::string &url, const std::string &json, std::string &response)
378380
{
379381
CURL *curl;
380382
CURLcode res;
381-
uint32_t retHttpCode = 0;
383+
long retHttpCode = 0;
382384

383385
if (url.empty() || json.empty())
384386
{

Analytics/Implementation/Backend/Sift/SiftUploader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace WPEFramework
6868
void updateEventDeviceInfoIfRequired(JsonObject &event) const;
6969
void validateResponse(const std::string &response, const std::vector<std::string> &events) const;
7070

71-
static uint32_t PostJson(const std::string& url, const std::string& json, std::string &response);
71+
static long PostJson(const std::string& url, const std::string& json, std::string &response);
7272

7373
SiftStorePtr mStorePtr;
7474
std::string mUrl;

Analytics/Implementation/LocalStore/DatabaseConnection.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ namespace WPEFramework {
108108
// Handle result from DB query
109109
if (DB_OK == queryRet) {
110110
// Note that row data could be large and therefore cannot log query
111-
LOGINFO("Database %s query succeeded", mDatabaseName.c_str());
112111
ret = true;
113112
} else {
114113
LOGERR("Database %s query failed errmsg: %s db err code %d",
@@ -151,10 +150,6 @@ namespace WPEFramework {
151150
if (DB_OK == queryRet) {
152151
// Executes a query to get how many rows in the table were affected
153152
modifiedRows = DB_CHANGES(mDataBaseHandle);
154-
155-
LOGINFO("Database %s query succeeded %d rows modified",
156-
mDatabaseName.c_str(),
157-
modifiedRows);
158153
ret = true;
159154
} else {
160155
LOGERR("Database %s query failed errmsg: %s db err code %d",
@@ -195,9 +190,6 @@ namespace WPEFramework {
195190
// Handle result from DB query
196191
if (DB_OK == queryRet) {
197192
ret = true;
198-
LOGINFO("Database %s query succeeded with %d results",
199-
mDatabaseName.c_str(),
200-
result.NumRows());
201193
table = result;
202194
} else {
203195
LOGERR("Database %s query failed with error: %s db err code %d",
@@ -223,7 +215,6 @@ namespace WPEFramework {
223215

224216
if (query) {
225217
ret = DB_OK;
226-
LOGINFO("Database %s query executed", query -> mDatabaseName.c_str());
227218
} else {
228219
LOGERR("Database query executed with no data");
229220
}
@@ -256,7 +247,6 @@ namespace WPEFramework {
256247

257248
ret = DB_OK;
258249

259-
LOGINFO("Database query executed");
260250
} else {
261251
LOGERR("Database invalid query, cannot get results");
262252
}

Analytics/Implementation/LocalStore/LocalStore.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ namespace WPEFramework
136136
// get count from number of rows
137137
count.second = table.NumRows();
138138
}
139-
else
140-
{
141-
LOGERR("Failed to get entries count, query %s", query.c_str());
142-
}
143139
}
144140
else
145141
{

0 commit comments

Comments
 (0)