Skip to content

Commit f18b9ed

Browse files
RDK-60805: Adding L1 unit test cases for reportprofiles
Reason for change: Adding L1 unit test cases for reportprofiles Test Procedure: Tested and verified Risks: Medium Priority: P1 Signed-off-by: Rose Mary Benny <RoseMary_Benny@comcast.com>
1 parent e1191b8 commit f18b9ed

File tree

6 files changed

+283
-55
lines changed

6 files changed

+283
-55
lines changed

source/bulkdata/reportprofiles.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ void ReportProfiles_ProcessReportProfilesBlob(cJSON *profiles_root, bool rprofil
907907
{
908908
getMarkerCompRbusSub(false);
909909
}
910+
910911
// Populate profile hash map for current configuration
911912
for( profileIndex = 0; profileIndex < profiles_count; profileIndex++ )
912913
{
@@ -976,7 +977,6 @@ void ReportProfiles_ProcessReportProfilesBlob(cJSON *profiles_root, bool rprofil
976977
T2Error("Failed to remove previous report profile from the disk\n");
977978
}
978979
}
979-
980980
if(isRbusEnabled())
981981
{
982982
unregisterDEforCompEventList();
@@ -1064,7 +1064,6 @@ void ReportProfiles_ProcessReportProfilesBlob(cJSON *profiles_root, bool rprofil
10641064
}
10651065
}
10661066
}
1067-
10681067
if (rm_flag)
10691068
{
10701069
removeProfileFromDisk(DirPath, MSGPACK_REPORTPROFILES_PERSISTENT_FILE);

source/test/bulkdata/Makefile.am

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ AUTOMAKE_OPTIONS = subdir-objects
2727

2828
ACLOCAL_AMFLAGS = -I m4
2929

30-
bin_PROGRAMS = profile_gtest.bin datamodel_gtest.bin t2markers_gtest.bin profilexconf_gtest.bin
30+
bin_PROGRAMS = profile_gtest.bin datamodel_gtest.bin t2markers_gtest.bin profilexconf_gtest.bin reportprofiles_gtest.bin
3131

3232
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
3333

@@ -59,3 +59,30 @@ profile_gtest_bin_SOURCES = gtest_main.cpp ../mocks/SystemMock.cpp ../mocks/File
5959

6060
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
6161

62+
# Test binary for reportprofiles.c
63+
64+
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
65+
66+
reportprofiles_gtest_bin_SOURCES = \
67+
gtest_main.cpp \
68+
../mocks/SystemMock.cpp \
69+
../mocks/FileioMock.cpp \
70+
../mocks/rdklogMock.cpp \
71+
../mocks/rbusMock.cpp \
72+
../mocks/rdkconfigMock.cpp \
73+
../mocks/VectorMock.cpp \
74+
SchedulerMock.cpp \
75+
reportprofileMock.cpp \
76+
../../bulkdata/reportprofiles.c \
77+
reportprofilesTest.cpp \
78+
../../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
79+
80+
reportprofiles_gtest_bin_LDFLAGS = \
81+
-L/usr/src/googletest/googletest/lib/.libs \
82+
-L/usr/src/googletest/googlemock/lib/.libs \
83+
-lgmock -lgtest -lpthread \
84+
-lcjson -lmsgpackc -lglib-2.0 \
85+
-lrt -lcurl
86+
87+
reportprofiles_gtest_bin_LDFLAGS += -Wl,--wrap=isRbusEnabled
88+

source/test/bulkdata/profileTest.cpp

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,28 @@ TEST_F(ProfileTest, UninitProfileList_Success) {
225225
EXPECT_EQ(uninitProfileList(), T2ERROR_SUCCESS);
226226
}
227227

228+
TEST_F(ProfileTest, ReportProfiles_uninit) {
229+
EXPECT_CALL(*g_vectorMock, Vector_Create(_))
230+
.Times(::testing::AtMost(3))
231+
.WillRepeatedly(Return(T2ERROR_SUCCESS));
232+
EXPECT_CALL(*g_vectorMock, Vector_PushBack(_, _))
233+
.Times(::testing::AtMost(1))
234+
.WillRepeatedly(Return(T2ERROR_SUCCESS));
235+
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
236+
.Times(::testing::AtMost(3))
237+
.WillRepeatedly(Return(0));
238+
EXPECT_CALL(*g_vectorMock, Vector_At(_, _))
239+
.Times(::testing::AtMost(2))
240+
.WillRepeatedly(Return(nullptr));
241+
EXPECT_CALL(*g_schedulerMock, uninitScheduler())
242+
.Times(::testing::AtMost(1));
243+
EXPECT_CALL(*g_schedulerMock, unregisterProfileFromScheduler(_))
244+
.Times(::testing::AtMost(5))
245+
.WillRepeatedly(Return(T2ERROR_SUCCESS));
246+
247+
EXPECT_EQ(ReportProfiles_uninit(), T2ERROR_FAILURE);
248+
}
249+
228250
// Test getProfileCount
229251
TEST_F(ProfileTest, GetProfileCount_NotInitialized) {
230252
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
@@ -759,6 +781,14 @@ TEST_F(ProfileTest, ReportProfiles_deleteProfileXConf) {
759781
}
760782
#endif
761783

784+
TEST_F(ProfileTest, ReportProfiles_deleteProfileXConf) {
785+
ProfileXConf profile;
786+
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
787+
.Times(::testing::AtMost(1))
788+
.WillRepeatedly(Return(0)); // Return 1 to indicate only one profile (no duplicates)
789+
EXPECT_EQ(ReportProfiles_deleteProfileXConf(&profile), T2ERROR_SUCCESS);
790+
}
791+
762792
TEST_F(ProfileTest, ReportProfiles_deleteProfile) {
763793
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
764794
.Times(::testing::AtMost(2))
@@ -810,7 +840,16 @@ TEST_F(ProfileTest, RemovePreRPfromDisk) {
810840
EXPECT_EQ(RemovePreRPfromDisk("/tmp", &dummy), T2ERROR_SUCCESS);
811841
}
812842

813-
#if 0
843+
TEST_F(ProfileTest, RemovePreRPfromDisk_FailsIfDirNull) {
844+
hash_map_t dummy;
845+
// Mock opendir to return NULL to simulate failure
846+
EXPECT_CALL(*g_fileIOMock, opendir(_))
847+
.Times(1)
848+
.WillOnce(Return(nullptr));
849+
// readdir and closedir should NOT be called in this branch
850+
EXPECT_EQ(RemovePreRPfromDisk("/tmp", &dummy), T2ERROR_FAILURE);
851+
}
852+
814853
TEST_F(ProfileTest, deleteAllReportProfiles) {
815854
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
816855
.Times(::testing::AtMost(1))
@@ -819,58 +858,7 @@ TEST_F(ProfileTest, deleteAllReportProfiles) {
819858
.WillRepeatedly(Return(T2ERROR_SUCCESS));
820859
EXPECT_EQ(deleteAllReportProfiles(), T2ERROR_SUCCESS);
821860
}
822-
#endif
823861

824-
#if 0
825-
TEST_F(ProfileTest, isMtlsEnabled) {
826-
char status[8] = "true";
827-
EXPECT_CALL(*g_rbusMock, rbus_get(_,_,_))
828-
.Times(::testing::AtMost(2))
829-
.WillRepeatedly(Return(RBUS_ERROR_SUCCESS));
830-
EXPECT_CALL(*g_rbusMock, rbusValue_GetType(_))
831-
.Times(::testing::AtMost(2))
832-
.WillRepeatedly(Return(RBUS_BOOLEAN));
833-
EXPECT_CALL(*g_rbusMock, rbusValue_GetBoolean(_))
834-
.Times(::testing::AtMost(2))
835-
.WillRepeatedly(Return(RBUS_ERROR_SUCCESS));
836-
EXPECT_CALL(*g_rbusMock, rbusValue_Release(_))
837-
.Times(::testing::AtMost(2))
838-
.WillRepeatedly(Return());
839-
EXPECT_CALL(*g_rbusMock, rbusValue_ToString(_,_,_))
840-
.Times(::testing::AtMost(1))
841-
.WillRepeatedly(Return(status));
842-
EXPECT_TRUE(isMtlsEnabled());
843-
}
844-
#endif
845-
846-
#if 0
847-
TEST_F(ProfileTest, ReportProfiles_uninit) {
848-
EXPECT_CALL(*g_vectorMock, Vector_Create(_))
849-
.Times(::testing::AtMost(3)) // 1 for local test configlist, 1 for global profileList, 1 for configList in loadReportProfilesFromDisk
850-
.WillRepeatedly(Return(T2ERROR_SUCCESS));
851-
EXPECT_CALL(*g_vectorMock, Vector_PushBack(_, _))
852-
.Times(::testing::AtMost(1))
853-
.WillRepeatedly(Return(T2ERROR_SUCCESS));
854-
EXPECT_CALL(*g_vectorMock, Vector_Size(_))
855-
.Times(::testing::AtMost(3)) // May be called multiple times - in deleteAllProfiles, etc.
856-
.WillRepeatedly(Return(0)); // Return 0 to indicate no profiles (avoid unregister calls)
857-
EXPECT_CALL(*g_vectorMock, Vector_At(_, _))
858-
.Times(::testing::AtMost(2)) // May be called if profiles exist
859-
.WillRepeatedly(Return(nullptr));
860-
861-
// Scheduler mock expectations - uninitScheduler is definitely called
862-
EXPECT_CALL(*g_schedulerMock, uninitScheduler())
863-
.Times(::testing::AtMost(1));
864-
865-
// unregisterProfileFromScheduler may be called for each profile during deleteAllProfiles
866-
// Using AtMost to handle cases where profiles exist
867-
EXPECT_CALL(*g_schedulerMock, unregisterProfileFromScheduler(_))
868-
.Times(::testing::AtMost(5)) // Allow up to 5 calls in case profiles exist
869-
.WillRepeatedly(Return(T2ERROR_SUCCESS));
870-
871-
EXPECT_EQ(ReportProfiles_uninit(), T2ERROR_SUCCESS);
872-
}
873-
#endif
874862
#endif
875863

876864
#if 1
@@ -1097,6 +1085,7 @@ TEST_F(ProfileTest, DeleteProfile) {
10971085
profile->isUpdated = false;
10981086

10991087
ProfileXConf_set(profile);
1088+
EXPECT_EQ(ReportProfiles_setProfileXConf(profile),T2ERROR_FAILURE);
11001089
EXPECT_EQ(ProfileXConf_delete(profile), T2ERROR_FAILURE);
11011090
ProfileXConf_uninit();
11021091
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2020 Comcast Cable Communications Management, LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
#include <stdbool.h>
19+
#include <cjson/cJSON.h>
20+
#include "test/bulkdata/reportprofileMock.h"
21+
22+
23+
24+
// Mock Method
25+
26+
extern "C" bool __wrap_isRbusEnabled()
27+
{
28+
if (!g_reportprofileMock)
29+
{
30+
return false;
31+
}
32+
return g_reportprofileMock->isRbusEnabled();
33+
}
34+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2020 Comcast Cable Communications Management, LLC
3+
** Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
* SPDX-License-Identifier: Apache-2.0
16+
*/
17+
//#ifndef SOURCE_TEST_MOCKS_SYSTEMMOCK_H_
18+
//#define SOURCE_TEST_MOCKS_SYSTEMMOCK_H_
19+
20+
#include <gtest/gtest.h>
21+
#include <gmock/gmock.h>
22+
23+
24+
#include "telemetry2_0.h"
25+
26+
class reportprofileMock
27+
{
28+
public:
29+
30+
MOCK_METHOD(bool, isRbusEnabled, (), ());
31+
};
32+
33+
extern reportprofileMock *g_reportprofileMock;

0 commit comments

Comments
 (0)