Skip to content

Commit

Permalink
RDK-54097: Add L2 Thunder R4.4.1 tests for Analytics plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianM27 authored and Adrian Muzyka committed Dec 10, 2024
1 parent c821a16 commit 23d99aa
Show file tree
Hide file tree
Showing 14 changed files with 1,193 additions and 44 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/L2-tests-R4-4-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ jobs:
-DDS_FOUND=ON
-DPLUGIN_ANALYTICS=ON
-DPLUGIN_ANALYTICS_SIFT_BACKEND=ON
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-DPLUGIN_ANALYTICS_SIFT_2_0_ENABLED="true"
-DPLUGIN_ANALYTICS_SIFT_MAX_RANDOMISATION_WINDOW_TIME=30
-DPLUGIN_ANALYTICS_SIFT_STORE_PATH="/tmp/AnalyticsSiftStore"
-DPLUGIN_ANALYTICS_SIFT_URL="127.0.0.1:12345"
&&
cmake --build build/rdkservices -j8
&&
Expand Down
14 changes: 13 additions & 1 deletion Analytics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ set(MODULE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})

option(PLUGIN_ANALYTICS_SIFT_BACKEND "Enable Sift backend" OFF)


set(PLUGIN_ANALYTICS_STARTUPORDER "" CACHE STRING "To configure startup order of Analytics plugin")
set(PLUGIN_ANALYTICS_AUTOSTART "false" CACHE STRING "Automatically start Analytics plugin")
set(PLUGIN_ANALYTICS_DEVICE_OS_NAME "rdk" CACHE STRING "Device OS name")
Expand Down Expand Up @@ -87,6 +86,19 @@ target_link_libraries(${MODULE_NAME}
${MODULE_NAME}Backends
${MODULE_NAME}SystemTime)

if (RDK_SERVICE_L2_TEST)
target_compile_definitions(${MODULE_NAME} PRIVATE MODULE_NAME=Plugin_${PLUGIN_NAME})
target_compile_options(${MODULE_NAME} PRIVATE -Wno-error)

find_library(TESTMOCKLIB_LIBRARIES NAMES TestMocklib)
if (TESTMOCKLIB_LIBRARIES)
message ("linking mock libraries ${TESTMOCKLIB_LIBRARIES} library")
target_link_libraries(${MODULE_NAME} PRIVATE ${TESTMOCKLIB_LIBRARIES})
else (TESTMOCKLIB_LIBRARIES)
message ("Require ${TESTMOCKLIB_LIBRARIES} library")
endif (TESTMOCKLIB_LIBRARIES)
endif (RDK_SERVICES_L2_TEST)

install(TARGETS ${MODULE_NAME}
DESTINATION lib/${STORAGE_DIRECTORY}/plugins)

Expand Down
28 changes: 21 additions & 7 deletions Analytics/Implementation/AnalyticsImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,18 @@ namespace Plugin {
queueTimeout = std::chrono::milliseconds(POPULATE_DEVICE_INFO_RETRY_MS);
}

if (queueTimeout == std::chrono::milliseconds::max())
if (mActionQueue.empty())
{
mQueueCondition.wait(lock, [this] { return !mActionQueue.empty(); });
}
else
{
mQueueCondition.wait_for(lock, queueTimeout, [this] { return !mActionQueue.empty(); });
if (queueTimeout == std::chrono::milliseconds::max())
{
mQueueCondition.wait(lock, [this]
{ return !mActionQueue.empty(); });
}
else
{
mQueueCondition.wait_for(lock, queueTimeout, [this]
{ return !mActionQueue.empty(); });
}
}

Action action = {ACTION_TYPE_UNDEF, nullptr};
Expand Down Expand Up @@ -249,9 +254,18 @@ namespace Plugin {
bool AnalyticsImplementation::IsSysTimeValid()
{
bool ret = false;
// Time is valid if system time is available and time zone is set
if (mSysTime != nullptr)
{
ret = mSysTime->IsSystemTimeAvailable();
if (mSysTime->IsSystemTimeAvailable())
{
int32_t offset = 0;
SystemTime::TimeZoneAccuracy acc = mSysTime->GetTimeZoneOffset(offset);
if (acc == SystemTime::TimeZoneAccuracy::FINAL)
{
ret = true;
}
}
}

return ret;
Expand Down
17 changes: 11 additions & 6 deletions Analytics/Implementation/Backend/Sift/SiftBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ namespace WPEFramework
queueTimeout = std::chrono::milliseconds(POPULATE_CONFIG_TIMEOUT_MS);
}

if (queueTimeout == std::chrono::milliseconds::max())
{
mQueueCondition.wait(lock, [this] { return !mActionQueue.empty(); });
}
else
if (mActionQueue.empty())
{
mQueueCondition.wait_for(lock, queueTimeout, [this] { return !mActionQueue.empty(); });
if (queueTimeout == std::chrono::milliseconds::max())
{
mQueueCondition.wait(lock, [this]
{ return !mActionQueue.empty(); });
}
else
{
mQueueCondition.wait_for(lock, queueTimeout, [this]
{ return !mActionQueue.empty(); });
}
}

Action action = {ACTION_TYPE_UNDEF, nullptr};
Expand Down
11 changes: 9 additions & 2 deletions Analytics/Implementation/Backend/Sift/SiftConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#define PERSISTENT_STORE_ACCOUNT_PROFILE_NAMESPACE "accountProfile"
#define JSONRPC_THUNDER_TIMEOUT 20000
#define THUNDER_ACCESS_DEFAULT_VALUE "127.0.0.1:9998"
#define SIFT_PARTNER_ID_DFL "rdk"

namespace WPEFramework
{
Expand Down Expand Up @@ -510,6 +509,7 @@ namespace WPEFramework
mAttributes.proposition = config.Sift.PlatformDfl.Value();

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

mUploaderConfig.url = config.Sift.Url.Value();
Expand Down Expand Up @@ -621,7 +621,6 @@ namespace WPEFramework
{
LOGERR("Failed to get AuthService link");
mMutex.lock();
mAttributes.partnerId = SIFT_PARTNER_ID_DFL;
mAttributes.activated = false;
mMutex.unlock();
}
Expand Down Expand Up @@ -667,6 +666,14 @@ namespace WPEFramework
LOGINFO("Got deviceModel %s", mAttributes.deviceModel.c_str());
}

mMutex.lock();
if (result == Core::ERROR_NONE && mAttributes.partnerId.empty() && response.HasLabel("friendly_id"))
{
mAttributes.partnerId = response["friendly_id"].String();
LOGINFO("Got partnerId %s", mAttributes.partnerId.c_str());
}
mMutex.unlock();

// Get deviceFriendlyName from System.1.getFriendlyName[friendlyName]
result = systemLink->Invoke<JsonObject, JsonObject>(JSONRPC_THUNDER_TIMEOUT, "getFriendlyName", params, response);
if (result == Core::ERROR_NONE && response.HasLabel("friendlyName"))
Expand Down
36 changes: 21 additions & 15 deletions Analytics/Implementation/Backend/Sift/SiftUploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ namespace WPEFramework
case SiftUploader::UploaderState::RANDOMISATION_WINDOW_WAIT_STATE:
{
std::unique_lock<std::mutex> lock( mMutex );
mCondition.wait_for(lock, std::chrono::seconds(RandomisationWindowTimeGenerator()),
[this] () { return mStop; } );
if (mStop)
{
LOGINFO("SiftUploader Run exit");
return;
break;
}
mCondition.wait_for(lock, std::chrono::seconds(RandomisationWindowTimeGenerator()),
[this] () { return mStop; } );

mUploaderState = SiftUploader::UploaderState::COLLECT_ANALYTICS;
}
Expand Down Expand Up @@ -135,7 +134,7 @@ namespace WPEFramework

std::string resp;

uint32_t respcode;
long respcode;

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

Expand All @@ -159,18 +158,18 @@ namespace WPEFramework
{
LOGERR("No collected events to be deleted");
}

mUploaderState = UploaderState::RANDOMISATION_WINDOW_WAIT_STATE;
}
else
{
LOGERR("Failed to post analytics event - respcode: %u, response: %s", respcode, resp.c_str());
LOGERR("Failed to post analytics event - respcode: %ld, response: %s", respcode, resp.c_str());
}

if (!resp.empty())
{
validateResponse(resp, collectedEvents);
}

mUploaderState = UploaderState::RANDOMISATION_WINDOW_WAIT_STATE;
}
break;

Expand All @@ -180,36 +179,43 @@ namespace WPEFramework
}
break;
}

std::unique_lock<std::mutex> lock( mMutex );
if (mStop)
{
LOGINFO("SiftUploader Run exit");
return;
}
}
}

bool SiftUploader::PerformWaitIfRetryNeeded()
{
bool retry = false;

if (mCurrentRetryCount == mMaxRetries)
if (mCurrentRetryCount >= mMaxRetries)
{
mCurrentRetryCount = 0;
}
else
{
static auto retryTime = mMinRetryPeriod;

if (retryTime > mMaxRetryPeriod)
if (retryTime >= mMaxRetryPeriod)
{
retryTime = mMinRetryPeriod;
}

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

std::unique_lock<std::mutex> lock( mMutex );
mCondition.wait_for(lock, std::chrono::seconds(retryTime),
[this] () { return mStop; } );
if (mStop)
{
// return immediately if stop is set
return false;
}
mCondition.wait_for(lock, std::chrono::seconds(retryTime),
[this] () { return mStop; } );

if (retryTime < mMaxRetryPeriod)
{
Expand All @@ -218,7 +224,7 @@ namespace WPEFramework

++mCurrentRetryCount;

retry = true;
retry = !mStop;
}

return retry;
Expand Down Expand Up @@ -374,11 +380,11 @@ namespace WPEFramework
return size * nmemb;
}

uint32_t SiftUploader::PostJson(const std::string &url, const std::string &json, std::string &response)
long SiftUploader::PostJson(const std::string &url, const std::string &json, std::string &response)
{
CURL *curl;
CURLcode res;
uint32_t retHttpCode = 0;
long retHttpCode = 0;

if (url.empty() || json.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion Analytics/Implementation/Backend/Sift/SiftUploader.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace WPEFramework
void updateEventDeviceInfoIfRequired(JsonObject &event) const;
void validateResponse(const std::string &response, const std::vector<std::string> &events) const;

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

SiftStorePtr mStorePtr;
std::string mUrl;
Expand Down
20 changes: 9 additions & 11 deletions Analytics/Implementation/SystemTime/SystemTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,11 @@ namespace WPEFramework

SystemTime::TimeZoneAccuracy SystemTime::GetTimeZoneOffset(int32_t &offsetSec)
{
std::string tz;
std::string accuracyString;
bool isTimeAvailable = false;
{
std::lock_guard<std::mutex> guard(mLock);
tz = mTimeZone;
accuracyString = mTimeZoneAccuracyString;
isTimeAvailable = mIsSystemTimeAvailable;
}
std::lock_guard<std::mutex> guard(mLock);

if (isTimeAvailable)
if (mIsSystemTimeAvailable)
{
std::pair<SystemTime::TimeZoneAccuracy, int32_t> tzParsed = ParseTimeZone(tz, accuracyString);
std::pair<SystemTime::TimeZoneAccuracy, int32_t> tzParsed = ParseTimeZone(mTimeZone, mTimeZoneAccuracyString);
offsetSec = tzParsed.second;
return tzParsed.first;
}
Expand Down Expand Up @@ -221,6 +213,12 @@ namespace WPEFramework
mIsSystemTimeAvailable = false;
}
}
else
{
LOGERR("getTimeStatus not available, assuming time is OK");
std::lock_guard<std::mutex> guard(mLock);
mIsSystemTimeAvailable = true;
}
}

void SystemTime::UpdateTimeZone()
Expand Down
5 changes: 5 additions & 0 deletions Tests/L2Tests/L2TestsPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ endif()
if(PLUGIN_SYSTEMMODE)
set(SRC_FILES ${SRC_FILES} tests/SystemMode_L2Test.cpp)
endif()

if (PLUGIN_ANALYTICS)
set(SRC_FILES ${SRC_FILES} tests/Analytics_L2Test.cpp)
endif()

add_library(${MODULE_NAME} SHARED ${SRC_FILES})

set_target_properties(${MODULE_NAME} PROPERTIES
Expand Down
Loading

0 comments on commit 23d99aa

Please sign in to comment.