Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions source/bulkdata/reportprofiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ void ReportProfiles_ProcessReportProfilesBlob(cJSON *profiles_root, bool rprofil
{
getMarkerCompRbusSub(false);
}

// Populate profile hash map for current configuration
for( profileIndex = 0; profileIndex < profiles_count; profileIndex++ )
{
Expand Down Expand Up @@ -976,7 +977,6 @@ void ReportProfiles_ProcessReportProfilesBlob(cJSON *profiles_root, bool rprofil
T2Error("Failed to remove previous report profile from the disk\n");
}
}

if(isRbusEnabled())
{
unregisterDEforCompEventList();
Expand Down Expand Up @@ -1064,7 +1064,6 @@ void ReportProfiles_ProcessReportProfilesBlob(cJSON *profiles_root, bool rprofil
}
}
}

if (rm_flag)
{
removeProfileFromDisk(DirPath, MSGPACK_REPORTPROFILES_PERSISTENT_FILE);
Expand Down
12 changes: 11 additions & 1 deletion source/test/bulkdata/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ AUTOMAKE_OPTIONS = subdir-objects

ACLOCAL_AMFLAGS = -I m4

bin_PROGRAMS = profile_gtest.bin datamodel_gtest.bin t2markers_gtest.bin profilexconf_gtest.bin
bin_PROGRAMS = profile_gtest.bin datamodel_gtest.bin t2markers_gtest.bin profilexconf_gtest.bin reportprofiles_gtest.bin

datamodel_gtest_bin_CPPFLAGS = -I$(PKG_CONFIG_SYSROOT_DIR)/usr/include/gtest -I$(PKG_CONFIG_SYSROOT_DIR)/usr/include/glib-2.0 -I$(PKG_CONFIG_SYSROOT_DIR)/usr/lib/x86_64-linux-gnu/glib-2.0/include -I$(PKG_CONFIG_SYSROOT_DIR)/usr/local/lib -I$(PKG_CONFIG_SYSROOT_DIR)$(includedir)/gtest -I${top_srcdir}/gtest/include -I${top_srcdir}/source/include -I${top_srcdir}/source -I${top_srcdir}/source/test/mocks -I${top_srcdir}/source/test/rbus -I${top_srcdir}/source/test/rdk_logger -I${top_srcdir}/include -I${top_srcdir}/source/utils -I${top_srcdir}/source/privacycontrol -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/rbus -I${top_srcdir}/source/dcautil -I${top_srcdir}/source/ccspinterface -I${top_srcdir}/source/reportgen -I${top_srcdir}/source/xconf-client -I${top_srcdir}/source/protocol/http -I${top_srcdir}/source/protocol/rbusMethod -I${top_srcdir}/source/t2parser -I${top_srcdir}/source/bulkdata -I${top_srcdir}/source/scheduler -I${top_srcdir}/source/ccspinterface -I${PKG_CONFIG_SYSROOT_DIR}$(includedir) -I${PKG_CONFIG_SYSROOT_DIR}/usr/src/googletest/googlemock/include -I${RDK_PROJECT_ROOT_PATH}/$(GLIB_CFLAGS) -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/glib-2.0 -I${PKG_CONFIG_SYSROOT_DIR}$(libdir)/glib-2.0/include

Expand Down Expand Up @@ -59,3 +59,13 @@ profile_gtest_bin_SOURCES = gtest_main.cpp ../mocks/SystemMock.cpp ../mocks/File

profile_gtest_bin_LDFLAGS = -L/usr/src/googletest/googletest/lib/.libs -lgcov -L/src/googletest/googlemock/lib -L/usr/src/googletest/googlemock/lib/.libs -L/usr/include/glib-2.0 -lgmock -lcjson -lcurl -lmsgpackc -lgtest -lgtest_main -lglib-2.0

# Test binary for reportprofiles.c

reportprofiles_gtest_bin_CPPFLAGS = -I$(PKG_CONFIG_SYSROOT_DIR)/usr/include/gtest -I$(PKG_CONFIG_SYSROOT_DIR)/usr/include/glib-2.0 -I$(PKG_CONFIG_SYSROOT_DIR)/usr/lib/x86_64-linux-gnu/glib-2.0/include -I$(PKG_CONFIG_SYSROOT_DIR)/usr/local/lib -I$(PKG_CONFIG_SYSROOT_DIR)$(includedir)/gtest -I${top_srcdir}/gtest/include -I${top_srcdir}/source/include -I${top_srcdir}/source -I${top_srcdir}/source/test/mocks -I${top_srcdir}/source/test/rbus -I${top_srcdir}/source/test/rdk_logger -I${top_srcdir}/include -I${top_srcdir}/source/utils -I${top_srcdir}/source/privacycontrol -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/rbus -I${top_srcdir}/source/dcautil -I${top_srcdir}/source/ccspinterface -I${top_srcdir}/source/reportgen -I${top_srcdir}/source/xconf-client -I${top_srcdir}/source/protocol/http -I${top_srcdir}/source/protocol/rbusMethod -I${top_srcdir}/source/t2parser -I${top_srcdir}/source/bulkdata -I${top_srcdir}/source/scheduler -I${top_srcdir}/source/ccspinterface -I${PKG_CONFIG_SYSROOT_DIR}$(includedir) -I${PKG_CONFIG_SYSROOT_DIR}/usr/src/googletest/googlemock/include -I${RDK_PROJECT_ROOT_PATH}/$(GLIB_CFLAGS) -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/glib-2.0 -I${PKG_CONFIG_SYSROOT_DIR}$(libdir)/glib-2.0/include

reportprofiles_gtest_bin_SOURCES = gtest_main.cpp ../mocks/SystemMock.cpp ../mocks/FileioMock.cpp ../mocks/rdklogMock.cpp ../mocks/rbusMock.cpp ../mocks/rdkconfigMock.cpp ../mocks/VectorMock.cpp SchedulerMock.cpp reportprofileMock.cpp ../../bulkdata/reportprofiles.c reportprofilesTest.cpp ../../utils/persistence.c ../../utils/t2common.c ../../utils/t2collection.c ../../utils/t2MtlsUtils.c ../../utils/t2log_wrapper.c ../../dcautil/dcautil.c ../../dcautil/dca.c ../../dcautil/legacyutils.c ../../dcautil/dcaproc.c ../../xconf-client/xconfclient.c ../../protocol/rbusMethod/rbusmethodinterface.c ../../privacycontrol/rdkservices_privacyutils.c ../../reportgen/reportgen.c ../../bulkdata/t2eventreceiver.c ../../bulkdata/t2markers.c ../../t2parser/t2parser.c ../../bulkdata/datamodel.c ../../t2parser/t2parserxconf.c ../../bulkdata/profile.c ../../bulkdata/profilexconf.c ../../ccspinterface/rbusInterface.c ../../ccspinterface/busInterface.c ../../protocol/http/curlinterface.c ../../protocol/http/multicurlinterface.c

reportprofiles_gtest_bin_LDFLAGS = -L/usr/src/googletest/googletest/lib/.libs -L/usr/src/googletest/googlemock/lib/.libs -lgmock -lgtest -lpthread -lcjson -lmsgpackc -lglib-2.0 -lrt -lcurl

reportprofiles_gtest_bin_LDFLAGS += -Wl,--wrap=isRbusEnabled

93 changes: 41 additions & 52 deletions source/test/bulkdata/profileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,28 @@ TEST_F(ProfileTest, UninitProfileList_Success) {
EXPECT_EQ(uninitProfileList(), T2ERROR_SUCCESS);
}

TEST_F(ProfileTest, ReportProfiles_uninit) {
EXPECT_CALL(*g_vectorMock, Vector_Create(_))
.Times(::testing::AtMost(3))
.WillRepeatedly(Return(T2ERROR_SUCCESS));
EXPECT_CALL(*g_vectorMock, Vector_PushBack(_, _))
.Times(::testing::AtMost(1))
.WillRepeatedly(Return(T2ERROR_SUCCESS));
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
.Times(::testing::AtMost(3))
.WillRepeatedly(Return(0));
EXPECT_CALL(*g_vectorMock, Vector_At(_, _))
.Times(::testing::AtMost(2))
.WillRepeatedly(Return(nullptr));
EXPECT_CALL(*g_schedulerMock, uninitScheduler())
.Times(::testing::AtMost(1));
EXPECT_CALL(*g_schedulerMock, unregisterProfileFromScheduler(_))
.Times(::testing::AtMost(5))
.WillRepeatedly(Return(T2ERROR_SUCCESS));

EXPECT_EQ(ReportProfiles_uninit(), T2ERROR_FAILURE);
}

// Test getProfileCount
TEST_F(ProfileTest, GetProfileCount_NotInitialized) {
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
Expand Down Expand Up @@ -759,6 +781,14 @@ TEST_F(ProfileTest, ReportProfiles_deleteProfileXConf) {
}
#endif

TEST_F(ProfileTest, ReportProfiles_deleteProfileXConf_EmptyList) {
ProfileXConf profile;
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
.Times(::testing::AtMost(1))
.WillRepeatedly(Return(0)); // Return 1 to indicate only one profile (no duplicates)
EXPECT_EQ(ReportProfiles_deleteProfileXConf(&profile), T2ERROR_SUCCESS);
}

TEST_F(ProfileTest, ReportProfiles_deleteProfile) {
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
.Times(::testing::AtMost(2))
Expand Down Expand Up @@ -810,7 +840,16 @@ TEST_F(ProfileTest, RemovePreRPfromDisk) {
EXPECT_EQ(RemovePreRPfromDisk("/tmp", &dummy), T2ERROR_SUCCESS);
}

#if 0
TEST_F(ProfileTest, RemovePreRPfromDisk_FailsIfDirNull) {
hash_map_t dummy;
// Mock opendir to return NULL to simulate failure
EXPECT_CALL(*g_fileIOMock, opendir(_))
.Times(1)
.WillOnce(Return(nullptr));
// readdir and closedir should NOT be called in this branch
EXPECT_EQ(RemovePreRPfromDisk("/tmp", &dummy), T2ERROR_FAILURE);
}

TEST_F(ProfileTest, deleteAllReportProfiles) {
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
.Times(::testing::AtMost(1))
Expand All @@ -819,58 +858,7 @@ TEST_F(ProfileTest, deleteAllReportProfiles) {
.WillRepeatedly(Return(T2ERROR_SUCCESS));
EXPECT_EQ(deleteAllReportProfiles(), T2ERROR_SUCCESS);
}
#endif

#if 0
TEST_F(ProfileTest, isMtlsEnabled) {
char status[8] = "true";
EXPECT_CALL(*g_rbusMock, rbus_get(_,_,_))
.Times(::testing::AtMost(2))
.WillRepeatedly(Return(RBUS_ERROR_SUCCESS));
EXPECT_CALL(*g_rbusMock, rbusValue_GetType(_))
.Times(::testing::AtMost(2))
.WillRepeatedly(Return(RBUS_BOOLEAN));
EXPECT_CALL(*g_rbusMock, rbusValue_GetBoolean(_))
.Times(::testing::AtMost(2))
.WillRepeatedly(Return(RBUS_ERROR_SUCCESS));
EXPECT_CALL(*g_rbusMock, rbusValue_Release(_))
.Times(::testing::AtMost(2))
.WillRepeatedly(Return());
EXPECT_CALL(*g_rbusMock, rbusValue_ToString(_,_,_))
.Times(::testing::AtMost(1))
.WillRepeatedly(Return(status));
EXPECT_TRUE(isMtlsEnabled());
}
#endif

#if 0
TEST_F(ProfileTest, ReportProfiles_uninit) {
EXPECT_CALL(*g_vectorMock, Vector_Create(_))
.Times(::testing::AtMost(3)) // 1 for local test configlist, 1 for global profileList, 1 for configList in loadReportProfilesFromDisk
.WillRepeatedly(Return(T2ERROR_SUCCESS));
EXPECT_CALL(*g_vectorMock, Vector_PushBack(_, _))
.Times(::testing::AtMost(1))
.WillRepeatedly(Return(T2ERROR_SUCCESS));
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
.Times(::testing::AtMost(3)) // May be called multiple times - in deleteAllProfiles, etc.
.WillRepeatedly(Return(0)); // Return 0 to indicate no profiles (avoid unregister calls)
EXPECT_CALL(*g_vectorMock, Vector_At(_, _))
.Times(::testing::AtMost(2)) // May be called if profiles exist
.WillRepeatedly(Return(nullptr));

// Scheduler mock expectations - uninitScheduler is definitely called
EXPECT_CALL(*g_schedulerMock, uninitScheduler())
.Times(::testing::AtMost(1));

// unregisterProfileFromScheduler may be called for each profile during deleteAllProfiles
// Using AtMost to handle cases where profiles exist
EXPECT_CALL(*g_schedulerMock, unregisterProfileFromScheduler(_))
.Times(::testing::AtMost(5)) // Allow up to 5 calls in case profiles exist
.WillRepeatedly(Return(T2ERROR_SUCCESS));

EXPECT_EQ(ReportProfiles_uninit(), T2ERROR_SUCCESS);
}
#endif
#endif

#if 1
Expand Down Expand Up @@ -1097,6 +1085,7 @@ TEST_F(ProfileTest, DeleteProfile) {
profile->isUpdated = false;

ProfileXConf_set(profile);
EXPECT_EQ(ReportProfiles_setProfileXConf(profile),T2ERROR_FAILURE);
EXPECT_EQ(ProfileXConf_delete(profile), T2ERROR_FAILURE);
ProfileXConf_uninit();
}
Expand Down
17 changes: 17 additions & 0 deletions source/test/bulkdata/reportprofileMock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdbool.h>
#include <cjson/cJSON.h>
#include "test/bulkdata/reportprofileMock.h"



// Mock Method

extern "C" bool __wrap_isRbusEnabled()
{
if (!g_reportprofileMock)
{
return false;
}
return g_reportprofileMock->isRbusEnabled();
}

16 changes: 16 additions & 0 deletions source/test/bulkdata/reportprofileMock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <gtest/gtest.h>
#include <gmock/gmock.h>


#include "telemetry2_0.h"

class reportprofileMock
{
public:

MOCK_METHOD(bool, isRbusEnabled, (), ());
};

extern reportprofileMock *g_reportprofileMock;
126 changes: 126 additions & 0 deletions source/test/bulkdata/reportprofilesTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>

extern "C" {
#include "reportprofiles.h"
#include "profile.h"
#include "t2eventreceiver.h"
#include "t2collection.h"
#include "t2log_wrapper.h"
#include "msgpack.h"
}

#include "test/mocks/SystemMock.h"
#include "test/mocks/FileioMock.h"
#include "test/mocks/rdklogMock.h"
#include "test/mocks/rbusMock.h"
#include "test/mocks/rdkconfigMock.h"
#include "test/mocks/VectorMock.h"
#include "test/bulkdata/SchedulerMock.h"
#include "reportprofileMock.h"

using namespace std;
using ::testing::_;
using ::testing::Return;
using ::testing::StrEq;
using ::testing::Invoke;
// Create global mocks if you need them just like t2markersTest.cpp
FileMock *g_fileIOMock = NULL;
SystemMock * g_systemMock = NULL;
rdklogMock *m_rdklogMock = NULL;
rbusMock *g_rbusMock = NULL;
rdkconfigMock *g_rdkconfigMock = nullptr;
extern VectorMock *g_vectorMock;
extern SchedulerMock *g_schedulerMock;
reportprofileMock* g_reportprofileMock = nullptr;
// Test fixture for reportprofiles
class reportprofilesTestFixture : public ::testing::Test {
protected:
void SetUp() override {
g_reportprofileMock = new reportprofileMock();
g_systemMock = new SystemMock();
g_fileIOMock = new FileMock();
m_rdklogMock = new rdklogMock();
g_rbusMock = new rbusMock();
g_vectorMock = new VectorMock();
}
Comment on lines +60 to +67
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

The test fixture declares g_vectorMock and g_schedulerMock as extern but doesn't initialize or clean them up in SetUp/TearDown. For consistency with profileTest.cpp (lines 60-61 and 69-70), these mocks should be initialized in SetUp and deleted in TearDown. Add g_vectorMock = new VectorMock() and g_schedulerMock = new SchedulerMock() in SetUp, and delete them (with nullptr assignment) in TearDown.

Copilot uses AI. Check for mistakes.
void TearDown() override {
delete g_reportprofileMock;
delete g_systemMock;
delete g_fileIOMock;
delete m_rdklogMock;
delete g_rbusMock;
delete g_vectorMock;
g_reportprofileMock = nullptr;
g_systemMock = nullptr;
g_fileIOMock = nullptr;
m_rdklogMock = nullptr;
g_rbusMock = nullptr;
g_vectorMock = nullptr;
Comment on lines +74 to +80
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

The test fixture declares g_vectorMock and g_schedulerMock as extern but doesn't delete them in TearDown. For consistency with profileTest.cpp (lines 69-70 and 76-77), add deletion of g_schedulerMock and setting it to nullptr in TearDown.

Suggested change
delete g_vectorMock;
g_reportprofileMock = nullptr;
g_systemMock = nullptr;
g_fileIOMock = nullptr;
m_rdklogMock = nullptr;
g_rbusMock = nullptr;
g_vectorMock = nullptr;
delete g_vectorMock;
delete g_schedulerMock;
g_reportprofileMock = nullptr;
g_systemMock = nullptr;
g_fileIOMock = nullptr;
m_rdklogMock = nullptr;
g_rbusMock = nullptr;
g_vectorMock = nullptr;
g_schedulerMock = nullptr;

Copilot uses AI. Check for mistakes.
}
};


TEST_F(reportprofilesTestFixture, ProcessMsgPackBlob_InvalidFormat) {
struct __msgpack__ msg;
msg.msgpack_blob = nullptr;
msg.msgpack_blob_size = 0;
int ret = __ReportProfiles_ProcessReportProfilesMsgPackBlob(&msg, false);
EXPECT_EQ(ret, T2ERROR_INVALID_ARGS);
}

TEST_F(reportprofilesTestFixture, ProcessReportProfilesBlob_EmptyProfile_T2_TEMP_RP) {
cJSON *root = cJSON_CreateObject();
cJSON *profiles = cJSON_CreateArray();
cJSON_AddItemToObject(root, "profiles", profiles);
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

This test case doesn't verify any behavior or outcome after calling ReportProfiles_ProcessReportProfilesBlob with an empty profiles array and T2_TEMP_RP flag. Consider adding assertions to verify the expected behavior, such as checking that the function returns without error or that no profiles are created. Without assertions, this test only verifies that the function doesn't crash.

Suggested change
cJSON_AddItemToObject(root, "profiles", profiles);
cJSON_AddItemToObject(root, "profiles", profiles);
// For temporary report profiles with an empty array, we expect that
// no vector-based delete or cleanup operations are triggered.
EXPECT_CALL(*g_vectorMock, Vector_Size(_)).Times(0);
EXPECT_CALL(*g_vectorMock, Vector_Destroy(_, _)).Times(0);

Copilot uses AI. Check for mistakes.
ReportProfiles_ProcessReportProfilesBlob(root, T2_TEMP_RP);
cJSON_Delete(root);
}

TEST_F(reportprofilesTestFixture, ProcessReportProfilesBlob_EmptyProfile_Normal) {
cJSON *root = cJSON_CreateObject();
cJSON *profiles = cJSON_CreateArray();
cJSON_AddItemToObject(root, "profiles", profiles);
EXPECT_CALL(*g_vectorMock, Vector_Size(_)).WillRepeatedly(Return(0));
EXPECT_CALL(*g_vectorMock, Vector_Destroy(_, _)).WillRepeatedly(Return(T2ERROR_SUCCESS));
ReportProfiles_ProcessReportProfilesBlob(root, T2_RP); // normal, triggers deleteAllReportProfiles
cJSON_Delete(root);
}

TEST_F(reportprofilesTestFixture, ProcessReportProfilesBlob_AddNewProfile) {
// New profile, triggers add logic and saveConfigToFile
cJSON *root = cJSON_CreateObject();
cJSON *profiles = cJSON_CreateArray();
cJSON_AddItemToObject(root, "profiles", profiles);
cJSON *profile = cJSON_CreateObject();
cJSON_AddStringToObject(profile, "name", "newprofile");
cJSON_AddStringToObject(profile, "hash", "newhash");
cJSON *value = cJSON_CreateObject();
cJSON_AddStringToObject(value, "param", "value");
cJSON_AddItemToObject(profile, "value", value);
cJSON_AddItemToArray(profiles, profile);

EXPECT_CALL(*g_reportprofileMock, isRbusEnabled())
.WillRepeatedly(Return(false));
// Expect add and saveConfigToFile, can stub if needed
EXPECT_CALL(*g_vectorMock, Vector_Size(_)).WillRepeatedly(Return(0));
EXPECT_CALL(*g_vectorMock, Vector_Destroy(_, _)).WillRepeatedly(Return(T2ERROR_SUCCESS));

DIR *dir = reinterpret_cast<DIR*>(1);

EXPECT_CALL(*g_fileIOMock, opendir(_))
.Times(::testing::AtMost(1))
.WillRepeatedly(Return(dir));
EXPECT_CALL(*g_fileIOMock, readdir(_))
.Times(::testing::AtMost(1))
.WillRepeatedly(Return((struct dirent *)NULL));
EXPECT_CALL(*g_fileIOMock, closedir(_))
.Times(::testing::AtMost(1))
.WillRepeatedly(Return(0));
ReportProfiles_ProcessReportProfilesBlob(root, T2_RP);
cJSON_Delete(root);
}
TEST_F(reportprofilesTestFixture, ProcessReportProfilesMsgPackBlob_NullBlob) {
ReportProfiles_ProcessReportProfilesMsgPackBlob(NULL,0);
}

Loading