-
Notifications
You must be signed in to change notification settings - Fork 21
RDK-60610: Adding L1 unit test cases for commonlib,reportgen #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ extern "C" { | |
| #include "telemetry_busmessage_sender.h" | ||
|
|
||
| T2ERROR getParamValue(const char* paramName, char **paramValue); | ||
| void *cacheEventToFile(void *arg); | ||
| } | ||
| #include "../mocks/rbusMock.h" | ||
| #include "../mocks/SystemMock.h" | ||
|
|
@@ -64,6 +65,15 @@ class TelemetryBusmessageSenderTest : public ::testing::Test { | |
| } | ||
| }; | ||
|
|
||
| #ifdef GTEST_ENABLE | ||
| extern "C" { | ||
| typedef T2ERROR (*doPopulateEventMarkerListFunc)(void); | ||
| doPopulateEventMarkerListFunc getDoPopulateEventMarkerListCallback(void); | ||
| bool* test_get_isRbusEnabled_ptr(void); | ||
| bool* test_get_isT2Ready_ptr(void); | ||
| } | ||
| #endif | ||
|
|
||
| // Positive test: Init and Uninit | ||
| TEST_F(TelemetryBusmessageSenderTest, InitAndUninit) { | ||
| t2_init((char*)"test_component"); | ||
|
|
@@ -230,6 +240,75 @@ TEST_F(TelemetryBusmessageSenderTest, t2_event_s_iscachingenabled_false) | |
| EXPECT_EQ(ret, T2ERROR_SUCCESS); | ||
| } | ||
|
|
||
| TEST_F(TelemetryBusmessageSenderTest, t2_event_d_iscachingenabled_false) | ||
| { | ||
| t2_init((char*)"sysint"); | ||
| EXPECT_CALL(*g_systemMock, access(_,_)) | ||
| .WillRepeatedly(Return(-1)); | ||
| EXPECT_CALL(*g_rbusMock, rbus_getUint(_, _, _)) | ||
| .Times(1) | ||
| .WillOnce([](rbusHandle_t handle, const char* name, uint32_t* value) { | ||
| *value = 0; | ||
| return RBUS_ERROR_BUS_ERROR; | ||
| }); | ||
|
|
||
| int ret; | ||
| ret = t2_event_d("marker", 13); | ||
| EXPECT_EQ(ret, T2ERROR_SUCCESS); | ||
| } | ||
|
|
||
| TEST_F(TelemetryBusmessageSenderTest, t2_event_f_iscachingenabled_false) | ||
| { | ||
| t2_init((char*)"sysint"); | ||
| EXPECT_CALL(*g_systemMock, access(_,_)) | ||
| .WillRepeatedly(Return(-1)); | ||
| EXPECT_CALL(*g_rbusMock, rbus_getUint(_, _, _)) | ||
| .Times(1) | ||
| .WillOnce([](rbusHandle_t handle, const char* name, uint32_t* value) { | ||
| *value = 0; | ||
| return RBUS_ERROR_BUS_ERROR; | ||
| }); | ||
| int ret; | ||
| ret = t2_event_f("marker", 123.456); | ||
| EXPECT_EQ(ret, T2ERROR_SUCCESS); | ||
| } | ||
|
Comment on lines
+260
to
+274
|
||
|
|
||
| TEST_F(TelemetryBusmessageSenderTest, t2_event_d_iscachingenabled_true) | ||
| { | ||
| t2_init((char*)"sysint"); | ||
|
|
||
| EXPECT_CALL(*g_systemMock, access(_,_)) | ||
| .WillRepeatedly(Return(-1)); // Accept any number of calls | ||
|
|
||
| EXPECT_CALL(*g_rbusMock, rbus_getUint(_, _, _)) | ||
| .Times(1) | ||
| .WillOnce([](rbusHandle_t handle, const char* name, uint32_t* value) { | ||
| *value = 0; | ||
| return RBUS_ERROR_SUCCESS; // <-- Simulate SUCCESS | ||
| }); | ||
|
|
||
| int ret = t2_event_d("marker", 13); | ||
| EXPECT_EQ(ret, T2ERROR_SUCCESS); | ||
| } | ||
|
Comment on lines
+276
to
+292
|
||
| TEST_F(TelemetryBusmessageSenderTest, t2_event_d_iscachingenabled_true_1) | ||
| { | ||
| t2_init((char*)"sysinit"); | ||
|
|
||
| EXPECT_CALL(*g_systemMock, access(_,_)) | ||
| .WillRepeatedly(Return(-1)); // Accept any number of calls | ||
| EXPECT_CALL(*g_rbusMock, rbus_getUint(_, _, _)) | ||
| .Times(1) | ||
| .WillOnce([](rbusHandle_t handle, const char* name, uint32_t* value) { | ||
| *value = 1; | ||
| return RBUS_ERROR_SUCCESS; // <-- Simulate SUCCESS | ||
| }); | ||
| *test_get_isRbusEnabled_ptr() = false; | ||
| *test_get_isT2Ready_ptr() = true; | ||
| int ret = t2_event_d("marker", 13); | ||
|
|
||
| *test_get_isRbusEnabled_ptr() = true; | ||
shibu-kv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| EXPECT_EQ(ret, T2ERROR_SUCCESS); | ||
| } | ||
|
Comment on lines
+293
to
+311
|
||
|
|
||
| TEST_F(TelemetryBusmessageSenderTest, getParameterValue_success) | ||
| { | ||
|
|
@@ -270,6 +349,40 @@ TEST_F(TelemetryBusmessageSenderTest, getParameterValue_success_boolean) | |
|
|
||
| EXPECT_EQ(T2ERROR_SUCCESS, getParamValue("Device.DeviceInfo.SerialNumber", ¶mValue)); | ||
| } | ||
|
|
||
| TEST_F(TelemetryBusmessageSenderTest, getParameterValue_failure_boolean) | ||
| { | ||
| char* paramValue = NULL; | ||
| t2_init((char*)"test_component"); | ||
|
|
||
| EXPECT_CALL(*g_rbusMock, rbus_get(_, _, _)) | ||
| .Times(1) | ||
| .WillOnce(Return(RBUS_ERROR_SUCCESS)); | ||
| EXPECT_CALL(*g_rbusMock, rbusValue_GetType(_)) | ||
| .Times(1) | ||
| .WillOnce(Return(RBUS_BOOLEAN)); | ||
| EXPECT_CALL(*g_rbusMock, rbusValue_GetBoolean(_)) | ||
| .Times(1) | ||
| .WillOnce(Return(false)); | ||
| EXPECT_CALL(*g_rbusMock, rbusValue_Release(_)) | ||
| .Times(1); | ||
|
|
||
| EXPECT_EQ(T2ERROR_SUCCESS, getParamValue("Device.DeviceInfo.SerialNumber", ¶mValue)); | ||
| } | ||
shibu-kv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #ifdef GTEST_ENABLE | ||
| TEST_F(TelemetryBusmessageSenderTest, doPopulateEventMarkerList_ReturnsEarlyIfRbusDisabled) { | ||
| t2_init((char*)"test_component"); | ||
|
|
||
| *test_get_isRbusEnabled_ptr() = false; | ||
|
|
||
| auto cb = getDoPopulateEventMarkerListCallback(); | ||
| T2ERROR ret = cb(); | ||
| EXPECT_EQ(ret, T2ERROR_SUCCESS); | ||
| *test_get_isRbusEnabled_ptr() = true; | ||
| } | ||
| #endif | ||
|
|
||
| /* | ||
| TEST_F(TelemetryBusmessageSenderTest, filtered_event_send_1) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test setup makes
isCachingRequired()return true (becauserbus_getUintreturns an error), soreport_or_cache_data()will spawn a background thread viapthread_create(cacheEventToFile, ...). The fixtureTearDown()callst2_uninit()which destroys mutexes and can race with that thread, making the test flaky/UB. Please avoid triggering the caching path in unit tests (e.g., returnRBUS_ERROR_SUCCESSand sett2ReadyStatusto includeT2_STATE_COMPONENT_READY), or stub outpthread_create/cacheEventToFileand join/disable the thread.