Skip to content

RDK-60610: Adding L1 unit test cases for commonlib,reportgen#254

Open
rosemarybennyy wants to merge 1 commit intodevelopfrom
topic/RDK-60610
Open

RDK-60610: Adding L1 unit test cases for commonlib,reportgen#254
rosemarybennyy wants to merge 1 commit intodevelopfrom
topic/RDK-60610

Conversation

@rosemarybennyy
Copy link
Contributor

Reason for change: Adding L1 unit test cases for reportgenand commonlib
Test Procedure: Tested and verified
Risks: Medium
Priority: P1

Copilot AI review requested due to automatic review settings February 3, 2026 15:34
@rosemarybennyy rosemarybennyy requested a review from a team as a code owner February 3, 2026 15:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds additional L1 unit tests for reportgen and commonlib behavior, including error/edge branches that were previously untested.

Changes:

  • Added reportgen unit tests covering realloc-failure handling in prepareHttpUrl, additional trim/regex branches in encodeParamResultInJSON, and a positive regex-match path for applyRegexToValue via callback.
  • Added commonlib unit tests for t2_event_* cache-enabled/disabled paths and additional getParamValue boolean handling.
  • Introduced #ifdef GTEST_ENABLE helper hooks in telemetry_busmessage_sender.c to expose internal state and a callback to the internal event-marker population function for testing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
source/test/reportgen/reportgenTest.cpp Adds new reportgen unit tests, including realloc-failure injection and additional regex/trim coverage.
source/test/commonlib/TelemetryBusMsgSender.cpp Adds commonlib unit tests for event sending paths and boolean parameter retrieval, plus use of new test hooks.
source/commonlib/telemetry_busmessage_sender.c Adds GTEST-only exported helpers to access internal flags and the internal marker-list function for unit tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI commented Feb 11, 2026

@shibu-kv I've opened a new pull request, #261, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI review requested due to automatic review settings February 11, 2026 19:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +412 to +425
CURL* curl = (CURL*) 0xffee;
char* profile = strdup("RDK_Profile");

// Prepare the expectations for Curl and our mock functions
EXPECT_CALL(*m_reportgenMock, curl_easy_init())
.Times(1)
.WillOnce(Return(curl));
EXPECT_CALL(*m_reportgenMock, curl_easy_escape(_,_,_))
.Times(1)
.WillOnce(Return(profile));
EXPECT_CALL(*m_reportgenMock, curl_free(profile))
.Times(1);
EXPECT_CALL(*m_reportgenMock, curl_easy_cleanup(curl))
.Times(1);
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In prepareHttpUrl_ReallocFails, profile is allocated via strdup but never freed. Since curl_free is mocked, it won’t actually free this memory unless you add an action (e.g., invoke free) or explicitly free(profile) after the call. This keeps the test leak-free under sanitizers/valgrind.

Copilot uses AI. Check for mistakes.
Reason for change: Adding L1 unit test cases for reportgenand commonlib
Test Procedure:  Tested and verified
Risks: Medium
Priority: P1

Signed-off-by: Rose Mary Benny <RoseMary_Benny@comcast.com>
Copilot AI review requested due to automatic review settings February 27, 2026 20:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +293 to +311
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;
EXPECT_EQ(ret, T2ERROR_SUCCESS);
}
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t2_event_d_iscachingenabled_true_1 directly calls test_get_isRbusEnabled_ptr() / test_get_isT2Ready_ptr(), but those helper declarations are wrapped in #ifdef GTEST_ENABLE while this test itself is not. If GTEST_ENABLE isn’t defined in a given test build, this will fail to compile. Please wrap this test in the same #ifdef GTEST_ENABLE block (or remove the dependency on those helpers).

Copilot uses AI. Check for mistakes.
return nullptr;
}
if (!real_realloc_fptr) {
real_realloc_fptr = (void*(*)(void*, size_t))dlsym(RTLD_NEXT, "realloc");
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test interposes realloc() and uses dlsym(RTLD_NEXT, "realloc"), but the result is never checked for NULL. If dlsym fails (static link, unusual loader behavior, missing symbol), real_realloc_fptr stays NULL and the next call will crash when invoked. Please add a defensive check (and a clear failure path) if dlsym returns NULL, or use a safer allocation-failure injection strategy scoped to the unit under test.

Suggested change
real_realloc_fptr = (void*(*)(void*, size_t))dlsym(RTLD_NEXT, "realloc");
real_realloc_fptr = (void*(*)(void*, size_t))dlsym(RTLD_NEXT, "realloc");
if (!real_realloc_fptr) {
/* Failed to resolve the real realloc; abort tests to avoid
* calling through a NULL function pointer. */
abort();
}

Copilot uses AI. Check for mistakes.
Comment on lines +243 to +258
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);
}
Copy link

Copilot AI Feb 27, 2026

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 (because rbus_getUint returns an error), so report_or_cache_data() will spawn a background thread via pthread_create(cacheEventToFile, ...). The fixture TearDown() calls t2_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., return RBUS_ERROR_SUCCESS and set t2ReadyStatus to include T2_STATE_COMPONENT_READY), or stub out pthread_create/cacheEventToFile and join/disable the thread.

Copilot uses AI. Check for mistakes.
Comment on lines +260 to +274
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);
}
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test also forces the caching path (via rbus_getUint error), which spawns the async cacheEventToFile thread. That can race with t2_uninit() in TearDown() and cause nondeterministic failures. Consider adjusting mocks so isCachingRequired() returns false, or stub/join the caching thread for deterministic unit tests.

Copilot uses AI. Check for mistakes.
Comment on lines +276 to +292
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);
}
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here rbus_getUint returns success but sets *value = 0, which makes (t2ReadyStatus & T2_STATE_COMPONENT_READY) == 0 and therefore triggers caching + pthread_create(cacheEventToFile, ...). As written, this can race with t2_uninit() in TearDown() (mutex destruction while the caching thread runs). To keep the test deterministic, set *value to include T2_STATE_COMPONENT_READY (e.g., 1) and/or stub out the caching thread.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants