Skip to content

Commit

Permalink
RDK-51273: Added basic L1 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianM27 committed Sep 19, 2024
1 parent c2ac695 commit 3d7b039
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 63 deletions.
53 changes: 15 additions & 38 deletions .github/workflows/L1-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,6 @@ jobs:
coverage: without-coverage

steps:
- name: Set up cache
# Cache Thunder/ThunderInterfaces.
# https://github.com/actions/cache
# https://docs.github.com/en/rest/actions/cache
# Modify the key if changing the list.
if: ${{ !env.ACT }}
id: cache
uses: actions/cache@v3
with:
path: |
build/Thunder
build/ThunderInterfaces
build/ThunderTools
install
!install/etc/WPEFramework/plugins
!install/usr/bin/RdkServicesL1Test
!install/usr/include/gmock
!install/usr/include/gtest
!install/usr/lib/libgmockd.a
!install/usr/lib/libgmock_maind.a
!install/usr/lib/libgtestd.a
!install/usr/lib/libgtest_maind.a
!install/usr/lib/cmake/GTest
!install/usr/lib/pkgconfig/gmock.pc
!install/usr/lib/pkgconfig/gmock_main.pc
!install/usr/lib/pkgconfig/gtest.pc
!install/usr/lib/pkgconfig/gtest_main.pc
!install/usr/lib/wpeframework/plugins
key: ${{ runner.os }}-${{ env.THUNDER_REF }}-${{ env.INTERFACES_REF }}-3

- name: Set up Python
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -91,15 +61,18 @@ jobs:
sudo ninja -C build install
- name: Checkout Thunder
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: rdkcentral/Thunder
path: Thunder
ref: ${{env.THUNDER_REF}}

- name: Checkout rdkservices
uses: actions/checkout@v3
with:
path: rdkservices

- name: Build Thunder
if: steps.cache.outputs.cache-hit != 'true'
run: >
cmake
-S "${{github.workspace}}/Thunder/Tools"
Expand Down Expand Up @@ -128,15 +101,21 @@ jobs:
cmake --install build/Thunder
- name: Checkout ThunderInterfaces
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: rdkcentral/ThunderInterfaces
path: ThunderInterfaces
ref: ${{env.INTERFACES_REF}}

- name: Apply patches ThunderInterfaces
run: >
cd "${{github.workspace}}/ThunderInterfaces"
&&
git apply "${{github.workspace}}/rdkservices/Tests/L1Tests/patches/0001-Add-IAnalytics-interface-R2.patch"
&&
cd ..
- name: Build ThunderInterfaces
if: steps.cache.outputs.cache-hit != 'true'
run: >
cmake
-S "${{github.workspace}}/ThunderInterfaces"
Expand All @@ -149,10 +128,6 @@ jobs:
&&
cmake --install build/ThunderInterfaces
- name: Checkout rdkservices
uses: actions/checkout@v3
with:
path: rdkservices
- name: Generate external headers
# Empty headers to mute errors
Expand Down Expand Up @@ -290,6 +265,8 @@ jobs:
-DPLUGIN_TEXTTOSPEECH=ON
-DPLUGIN_SYSTEMAUDIOPLAYER=ON
-DPLUGIN_MIRACAST=ON
-DPLUGIN_ANALYTICS=ON
-DPLUGIN_ANALYTICS_SIFT_BACKEND=ON
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
&&
cmake --build build/rdkservices -j8
Expand Down
25 changes: 25 additions & 0 deletions Analytics/Analytics.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,31 @@
"result": {
"$ref": "#/common/result"
}
},
"setSessionId" : {
"summary": "Set the session ID for the analytics events",
"params": {
"type":"object",
"properties": {
"sessionId":{
"summary": "Session ID",
"type": "string",
"example": "1234567890"
}
},
"required": [
"sessionId"
]
},
"result": {
"$ref": "#/common/result"
}
},
"setTimeReady" : {
"summary": "Let the analytics plugin know that the system time is ready and valid",
"result": {
"$ref": "#/common/result"
}
}
}
}
33 changes: 20 additions & 13 deletions Analytics/AnalyticsJsonRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,19 @@ namespace Plugin {
uint64_t uptimeTimestamp = (parameters.HasLabel("uptimeTimestamp"))? parameters["uptimeTimestamp"].Number() : 0;
string eventPayload = parameters["eventPayload"].String();

result = mAnalytics->SendEvent(eventName,
eventVersion,
eventSource,
eventSourceVersion,
cetListIterator,
epochTimestamp,
uptimeTimestamp,
eventPayload);
if (mAnalytics != nullptr) {
result = mAnalytics->SendEvent(eventName,
eventVersion,
eventSource,
eventSourceVersion,
cetListIterator,
epochTimestamp,
uptimeTimestamp,
eventPayload);
}

cetListIterator->Release();
returnResponse(result);
returnResponse(result == Core::ERROR_NONE);
}

// Method: setSessionId - Set the session ID
Expand All @@ -104,9 +107,11 @@ namespace Plugin {

string sessionId = parameters["sessionId"].String();

result = mAnalytics->SetSessionId(sessionId);
if (mAnalytics != nullptr) {
result = mAnalytics->SetSessionId(sessionId);
}

returnResponse(result);
returnResponse(result == Core::ERROR_NONE);
}

// Method: setTimeReady - Set the time ready
Expand All @@ -119,9 +124,11 @@ namespace Plugin {

uint32_t result = Core::ERROR_NONE;

result = mAnalytics->SetTimeReady();
if (mAnalytics != nullptr) {
result = mAnalytics->SetTimeReady();
}

returnResponse(result);
returnResponse(result == Core::ERROR_NONE);
}

}
Expand Down
24 changes: 12 additions & 12 deletions Analytics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ set(PLUGIN_ANALYTICS_SIFT_URL "" CACHE STRING "Sift URL")
message("Setup ${MODULE_NAME} v${MODULE_VERSION}")

find_package(${NAMESPACE}Plugins REQUIRED)
find_package(${NAMESPACE}Definitions REQUIRED)
find_package(CompileSettingsDebug CONFIG REQUIRED)
find_package(DS)
find_package(IARMBus)

add_library(${MODULE_NAME} SHARED
Analytics.cpp
Expand All @@ -74,18 +78,14 @@ set_target_properties(${MODULE_NAME} PROPERTIES

target_compile_definitions(${MODULE_NAME} PRIVATE MODULE_NAME=Plugin_${PLUGIN_NAME})

find_package(DS)
if (DS_FOUND)
find_package(IARMBus)
add_definitions(-DDS_FOUND)
target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS})
target_include_directories(${MODULE_NAME} PRIVATE ${DS_INCLUDE_DIRS})
target_include_directories(${MODULE_NAME} PRIVATE ../helpers)
target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES} ${OEMHAL_LIBRARIES}
-lpthread -lglib-2.0 -ldbus-1 ${IARMBUS_LIBRARIES} ${MODULE_NAME}Backends)
else (DS_FOUND)
target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins)
endif(DS_FOUND)
target_link_libraries(${MODULE_NAME}
PRIVATE
CompileSettingsDebug::CompileSettingsDebug
${NAMESPACE}Plugins::${NAMESPACE}Plugins
${NAMESPACE}Definitions::${NAMESPACE}Definitions
${DS_LIBRARIES}
${IARMBUS_LIBRARIES}
${MODULE_NAME}Backends)

install(TARGETS ${MODULE_NAME}
DESTINATION lib/${STORAGE_DIRECTORY}/plugins)
Expand Down
3 changes: 3 additions & 0 deletions Tests/L1Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ include_directories(../../LocationSync
../../Miracast/MiracastService/P2P
../../Miracast/MiracastPlayer
../../Miracast/MiracastPlayer/RTSP
../../Analytics
)
link_directories(../../LocationSync
../../SecurityAgent
Expand Down Expand Up @@ -141,6 +142,7 @@ link_directories(../../LocationSync
../../TextToSpeech
../../SystemAudioPlayer
../../Miracast
../../Analytics
)

target_link_libraries(${PROJECT_NAME}
Expand Down Expand Up @@ -185,6 +187,7 @@ target_link_libraries(${PROJECT_NAME}
${NAMESPACE}SystemAudioPlayer
${NAMESPACE}MiracastService
${NAMESPACE}MiracastPlayer
${NAMESPACE}Analytics
)

target_include_directories(${PROJECT_NAME}
Expand Down
59 changes: 59 additions & 0 deletions Tests/L1Tests/patches/0001-Add-IAnalytics-interface-R2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
From 9a2398b7bc356f341e25c414e45b6919df135d58 Mon Sep 17 00:00:00 2001
From: Adrian Muzyka <[email protected]>
Date: Thu, 19 Sep 2024 12:34:27 +0200
Subject: [PATCH] Add IAnalytics interface R2

---
interfaces/IAnalytics.h | 27 +++++++++++++++++++++++++++
interfaces/Ids.h | 1 +
2 files changed, 28 insertions(+)
create mode 100644 interfaces/IAnalytics.h

diff --git a/interfaces/IAnalytics.h b/interfaces/IAnalytics.h
new file mode 100644
index 0000000..19f5a3a
--- /dev/null
+++ b/interfaces/IAnalytics.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include "Module.h"
+
+// @stubgen:include <com/IRPCIterator.h>
+
+namespace WPEFramework {
+namespace Exchange {
+
+ struct EXTERNAL IAnalytics : virtual public Core::IUnknown {
+ enum { ID = ID_ANALYTICS };
+
+ virtual ~IAnalytics() override = default;
+
+ virtual uint32_t SendEvent(const string& eventName /* @in */,
+ const string& eventVersion /* @in */,
+ const string& eventSource /* @in */,
+ const string& eventSourceVersion /* @in */,
+ RPC::IStringIterator* const& cetList /* @in */,
+ const uint64_t& epochTimestamp /* @in */,
+ const uint64_t& uptimeTimestamp /* @in */,
+ const string& eventPayload /* @in */ ) = 0;
+ virtual uint32_t SetSessionId(const string& id /* @in */) = 0;
+ virtual uint32_t SetTimeReady() = 0;
+ };
+}
+}
diff --git a/interfaces/Ids.h b/interfaces/Ids.h
index 7ef9a42..fa5c1dd 100644
--- a/interfaces/Ids.h
+++ b/interfaces/Ids.h
@@ -288,6 +288,7 @@ namespace Exchange {
ID_DTV_TRANSPORT,
ID_TEXT_TO_SPEECH,
ID_TEXT_TO_SPEECH_NOTIFICATION,
+ ID_ANALYTICS,

};
}
--
2.25.1

49 changes: 49 additions & 0 deletions Tests/L1Tests/tests/test_Analytics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <gtest/gtest.h>

#include "Analytics.h"

using namespace WPEFramework;

class AnalyticsTest : public ::testing::Test {
protected:
Core::ProxyType<Plugin::Analytics> plugin;
Core::JSONRPC::Handler& handler;
Core::JSONRPC::Connection connection;
string response;

AnalyticsTest()
: plugin(Core::ProxyType<Plugin::Analytics>::Create())
, handler(*(plugin))
, connection(1, 0)
{
}
virtual ~AnalyticsTest() = default;
};

TEST_F(AnalyticsTest, RegisteredMethods)
{
EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("sendEvent")));
EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setSessionId")));
EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setTimeReady")));
}

TEST_F(AnalyticsTest, sendEvent)
{
EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendEvent"), _T("{\"eventName\":\"tile_impression\", \"eventVersion\":\"1\", \"eventSource\":\"ImmerseUI\", \"eventSourceVersion\":\"1.2\", \"cetList\":[\"cet1\",\"cet2\",\"cet3\"], \"eventPayload\": { \"event_trigger\": \"user_key_select\"}}"), response));
EXPECT_EQ(response, string("{\"success\":true}"));
}

TEST_F(AnalyticsTest, setSessionId)
{
EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setSessionId"), _T("{\"sessionId\":\"123456789\"}"), response));
EXPECT_EQ(response, string("{\"success\":true}"));
}

TEST_F(AnalyticsTest, setTimeReady)
{
EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setTimeReady"), _T("{}"), response));
EXPECT_EQ(response, string("{\"success\":true}"));
}



2 changes: 2 additions & 0 deletions l1tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,5 @@ set(PLUGIN_MAINTENANCEMANAGER ON)
set(PLUGIN_PACKAGER ON)
set(DS_FOUND ON)
set(PLUGIN_SYSTEMAUDIOPLAYER ON)
set(PLUGIN_ANALYTICS ON)
set(PLUGIN_ANALYTICS_SIFT_BACKEND ON)

0 comments on commit 3d7b039

Please sign in to comment.