Skip to content
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

RDKB-57275 : MAPT-Unification unit test Implementation #78

Closed
Closed
7 changes: 4 additions & 3 deletions source/test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ RdkWanManager_gtest_bin_CPPFLAGS = -I$(PKG_CONFIG_SYSROOT_DIR)$(includedir)/gtes
RdkWanManager_gtest_bin_LDFLAGS = -lgtest -lgmock -lgcov

#TODO:Compiling all files due to limited time. This should be modified to compile only the required files
RdkWanManager_gtest_bin_SOURCES = ../WanManager/wanmgr_core.c ../WanManager/wanmgr_controller.c ../WanManager/wanmgr_data.c ../WanManager/wanmgr_sysevents.c ../WanManager/wanmgr_interface_sm.c ../WanManager/wanmgr_utils.c ../WanManager/wanmgr_net_utils.c ../WanManager/wanmgr_dhcpv6_apis.c ../WanManager/wanmgr_ipc.c ../WanManager/wanmgr_policy_autowan_impl.c ../WanManager/wanmgr_policy_auto_impl.c ../WanManager/dm_pack_datamodel.c ../WanManager/wanmgr_wan_failover.c ../WanManager/wanmgr_policy_parallel_scan_impl.c ../WanManager/wanmgr_dhcp_legacy_apis.c ../TR-181/middle_layer_src/wanmgr_rbus_handler_apis.c ../TR-181/middle_layer_src/wanmgr_rdkbus_utils.c ../TR-181/middle_layer_src/wanmgr_rdkbus_apis.c \
#RdkWanManager_gtest_bin_SOURCES = ../WanManager/wanmgr_core.c ../WanManager/wanmgr_controller.c ../WanManager/wanmgr_data.c ../WanManager/wanmgr_sysevents.c ../WanManager/wanmgr_interface_sm.c ../WanManager/wanmgr_utils.c ../WanManager/wanmgr_net_utils.c ../WanManager/wanmgr_dhcpv6_apis.c ../WanManager/wanmgr_ipc.c ../WanManager/wanmgr_policy_autowan_impl.c ../WanManager/wanmgr_policy_auto_impl.c ../WanManager/dm_pack_datamodel.c ../WanManager/wanmgr_wan_failover.c ../WanManager/wanmgr_policy_parallel_scan_impl.c ../WanManager/wanmgr_dhcp_legacy_apis.c ../TR-181/middle_layer_src/wanmgr_rbus_handler_apis.c ../TR-181/middle_layer_src/wanmgr_rdkbus_utils.c ../TR-181/middle_layer_src/wanmgr_rdkbus_apis.c ../WanManager/DHCPv6cMsgHandler/dhcpv6c_msg_apis.c

RdkWanManager_gtest_bin_SOURCES = ../WanManager/wanmgr_core.c ../WanManager/wanmgr_controller.c ../WanManager/wanmgr_data.c ../WanManager/wanmgr_sysevents.c ../WanManager/wanmgr_interface_sm.c ../WanManager/wanmgr_utils.c ../WanManager/wanmgr_net_utils.c ../WanManager/wanmgr_dhcpv6_apis.c ../WanManager/wanmgr_ipc.c ../WanManager/wanmgr_policy_auto_impl.c ../WanManager/wanmgr_wan_failover.c ../WanManager/wanmgr_policy_parallel_scan_impl.c ../WanManager/wanmgr_dhcp_legacy_apis.c ../TR-181/middle_layer_src/wanmgr_rbus_handler_apis.c ../TR-181/middle_layer_src/wanmgr_rdkbus_utils.c ../TR-181/middle_layer_src/wanmgr_rdkbus_apis.c ../WanManager/DHCPv6cMsgHandler/dhcpv6c_msg_apis.c \
gtest_main.cpp RdkWanManagerTest.cpp Test_wanmgr_rbus_handler_apis.cpp

# TODO: Partially added RdkbGmock libs. Complete this once all mocks are available.
RdkWanManager_gtest_bin_LDADD = -lrdkloggers -lapi_dhcpv4c -lnanomsg -lwebconfig_framework -lmsgpackc -ldhcp_client_utils -lsyscfg -lsysevent -lpthread \
-lmock_privilege -lmock_rbus -lmock_secure_wrapper -lccsp_common -lmock_platform_hal

-lmock_privilege -lmock_rbus -lmock_secure_wrapper -lmock_ccsp_common -lmock_platform_hal -lmock_psm

71 changes: 49 additions & 22 deletions source/test/RdkWanManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ CapMock * g_capMock = nullptr;
AnscMemoryMock * g_anscMemoryMock = nullptr;
MessageBusMock * g_messagebusMock = nullptr;
PlatformHalMock *g_platformHALMock =nullptr;
PsmMock *g_psmMock = nullptr;
AnscTaskMock *g_anscTaskMock = nullptr;
SysInfoRepositoryMock * g_sysInfoRepositoryMock = nullptr;
AnscTimerSchedulerMock * g_anscTimerSchedulerMock = nullptr;
AnscCryptoMock* g_anscCryptoMock = nullptr;
AnscXmlMock *g_anscXmlMock = nullptr;
AnscFileIOMock* g_anscFileIOMock = nullptr;
AnscCoMock *g_anscCoMock= nullptr;
DslhDmagntExportedMock* g_dslhDmagntExportedMock = nullptr;
CcspDmApiMock* g_ccspDmApiMock = nullptr;
UserRuntimeMock *g_userRuntimeMock = nullptr;
AnscDebugMock * g_anscDebugMock = NULL;
TraceMock * g_traceMock = NULL;
FileIOMock * g_fileIOMock = NULL;
BaseAPIMock * g_baseapiMock = NULL;
UserTimeMock * g_usertimeMock = NULL;
AnscWrapperApiMock * g_anscWrapperApiMock = NULL;



WanMgrBase::WanMgrBase()
{
Expand All @@ -57,12 +76,30 @@ void WanMgrBase::SetUp()
<< " Test Case Name: " << UnitTest::GetInstance()->current_test_info()->name() << endl;

mockWanMgr = &mockWanUtils;
g_baseapiMock = &mockedbaseapi;
g_traceMock = &mockedTrace;
g_fileIOMock = &mockedFileIO;
g_ccspDmApiMock = &mockccspDmApiMock;
g_anscFileIOMock = &mockAnscFileIOMock;
g_rbusMock = &mockedRbus;
g_securewrapperMock = &mockSecurewrapperMock;
g_capMock = &mockCap;
g_anscMemoryMock = &mockAnscMemory;
g_messagebusMock = &mockMessagebus;
g_platformHALMock = &mockPlatformHAL;
g_psmMock = &mockPSM;
g_anscTaskMock = &mockanscTaskMock;
g_sysInfoRepositoryMock = &mocksysInfoRepositoryMock;
g_anscTimerSchedulerMock = &mockanscTimerSchedulerMock;
g_anscCryptoMock = &mockanscCryptoMock;
g_anscXmlMock = &mockAnscXml;
g_anscCoMock = &mockedAnscCo;
g_dslhDmagntExportedMock = &mockdslhDmagntExported;
g_userRuntimeMock = &mockedUserRuntime;
g_anscDebugMock = &mockedAnscDebug;
g_anscWrapperApiMock = &mockedanscWrapperApi;
g_usertimeMock = &mockedUserTime;

//Initialise mutex attributes
pthread_mutexattr_t muttex_attr;
pthread_mutexattr_init(&muttex_attr);
Expand All @@ -71,7 +108,7 @@ void WanMgrBase::SetUp()

//init mock interfaces
WanMgr_IfaceCtrl_Data_t* pWanIfaceCtrl = &(gWanMgrDataBase.IfaceCtrl);
pWanIfaceCtrl->pIface = (WanMgr_Iface_Data_t*) AnscAllocateMemory( sizeof(WanMgr_Iface_Data_t) * MAX_WAN_INTERFACE_ENTRY);
pWanIfaceCtrl->pIface = (WanMgr_Iface_Data_t*) malloc( sizeof(WanMgr_Iface_Data_t) * MAX_WAN_INTERFACE_ENTRY);
memset( pWanIfaceCtrl->pIface, 0, ( sizeof(WanMgr_Iface_Data_t) * MAX_WAN_INTERFACE_ENTRY ) );
pWanIfaceCtrl->ulTotalNumbWanInterfaces = 4;
for(int idx = 0 ; idx < pWanIfaceCtrl->ulTotalNumbWanInterfaces; idx++ )
Expand All @@ -81,8 +118,10 @@ void WanMgrBase::SetUp()
WanMgr_IfaceData_Init(pIfaceData, idx);
for(int i=0; i< pIfaceData->data.NoOfVirtIfs; i++)
{
DML_VIRTUAL_IFACE* p_VirtIf = (DML_VIRTUAL_IFACE *) AnscAllocateMemory( sizeof(DML_VIRTUAL_IFACE) );
DML_VIRTUAL_IFACE* p_VirtIf = (DML_VIRTUAL_IFACE *) malloc( sizeof(DML_VIRTUAL_IFACE) );
memset( p_VirtIf, 0, sizeof(DML_VIRTUAL_IFACE) );
WanMgr_VirtIface_Init(p_VirtIf, i);
p_VirtIf->next = NULL;
WanMgr_AddVirtualToList(&(pIfaceData->data.VirtIfList), p_VirtIf);
}
strncpy(pIfaceData->data.AliasName, ifaceName[idx][1].c_str(),sizeof(pIfaceData->data.AliasName));
Expand All @@ -104,15 +143,12 @@ void WanMgrBase::TearDown()
{
WanMgr_Iface_Data_t* pIfaceData = &(pWanIfaceCtrl->pIface[idx]);

for(int i=0; i< pIfaceData->data.NoOfVirtIfs; i++)
DML_VIRTUAL_IFACE* virIface = pIfaceData->data.VirtIfList;
while(virIface != NULL)
{
DML_VIRTUAL_IFACE* virIface = pIfaceData->data.VirtIfList;
while(virIface != NULL)
{
DML_VIRTUAL_IFACE* temp = virIface;
virIface = virIface->next;
free(temp);
}
DML_VIRTUAL_IFACE* temp = virIface;
virIface = virIface->next;
free(temp);
}
}
free(pWanIfaceCtrl->pIface);
Expand Down Expand Up @@ -212,6 +248,7 @@ TEST_F(WanMgrBase, TestConfigureTADWithDnsIpv4)
TEST_F(WanMgrBase, TestConfigureTADWithDnsIpv6)
{
//TODO : Set correct expecttations
EXPECT_CALL(mockedRbus, rbusObject_Init(testing::_, testing::_)).Times(testing::AnyNumber());
EXPECT_CALL(mockedRbus, rbusValue_Init(testing::_)).Times(testing::AnyNumber());
EXPECT_CALL(mockedRbus, rbusValue_SetString(testing::_, testing::_)).Times(testing::AnyNumber());
EXPECT_CALL(mockedRbus, rbusObject_SetValue(testing::_, testing::_, testing::_)).Times(testing::AnyNumber());
Expand Down Expand Up @@ -307,6 +344,7 @@ extern "C" ANSC_STATUS wanmgr_handle_dhcpv4_event_data(DML_VIRTUAL_IFACE* pVirtI
mockWanMgr->wanmgr_handle_dhcpv4_event_data(pVirtIf);
}
}
#ifdef ENABLE_FEATURE_TELEMETRY2_0
/*
* Unit test for the WanMgr_TelemetryEventTrigger() function.
*
Expand All @@ -321,9 +359,6 @@ extern "C" ANSC_STATUS wanmgr_handle_dhcpv4_event_data(DML_VIRTUAL_IFACE* pVirtI

TEST_F(WanfailOver, TelemetryFailOverOSuccess)
{
#ifndef ENABLE_FEATURE_TELEMETRY2_0
GTEST_SKIP() << "Skipping "<< UnitTest::GetInstance()->current_test_info()->name() <<"test ENABLE_FEATURE_TELEMETRY2_0 is not enabled";
#endif
//Start the FailOver Timer for telemetry
memset(&(FWController.FailOverTimer), 0, sizeof(struct timespec));
clock_gettime(CLOCK_MONOTONIC_RAW, &(FWController.FailOverTimer));
Expand All @@ -349,9 +384,6 @@ TEST_F(WanfailOver, TelemetryFailOverOSuccess)
*/
TEST_F(WanfailOver, TelemetryRestoreSuccess)
{
#ifndef ENABLE_FEATURE_TELEMETRY2_0
GTEST_SKIP() << "Skipping "<< UnitTest::GetInstance()->current_test_info()->name() <<"test ENABLE_FEATURE_TELEMETRY2_0 is not enabled";
#endif
//Start the FailOver Timer for telemetry
memset(&(FWController.FailOverTimer), 0, sizeof(struct timespec));
clock_gettime(CLOCK_MONOTONIC_RAW, &(FWController.FailOverTimer));
Expand All @@ -376,9 +408,6 @@ TEST_F(WanfailOver, TelemetryRestoreSuccess)
*/
TEST_F(WanfailOver, TelemetryRestoreFail)
{
#ifndef ENABLE_FEATURE_TELEMETRY2_0
GTEST_SKIP() << "Skipping "<< UnitTest::GetInstance()->current_test_info()->name() <<"test ENABLE_FEATURE_TELEMETRY2_0 is not enabled";
#endif
EXPECT_CALL(mockWanUtils,t2_event_d(StrCmpLen("WAN_RESTORE_FAIL_COUNT", strlen("WAN_RESTORE_FAIL_COUNT")), Eq(1)))
.Times(1);
FWController.TelemetryEvent = WAN_RESTORE_FAIL;
Expand All @@ -397,12 +426,10 @@ TEST_F(WanfailOver, TelemetryRestoreFail)
*/
TEST_F(WanfailOver, TelemetryFailOverFail)
{
#ifndef ENABLE_FEATURE_TELEMETRY2_0
GTEST_SKIP() << "Skipping "<< UnitTest::GetInstance()->current_test_info()->name() <<"test ENABLE_FEATURE_TELEMETRY2_0 is not enabled";
#endif
EXPECT_CALL(mockWanUtils,t2_event_d(StrCmpLen("WAN_FAILOVER_FAIL_COUNT", strlen("WAN_FAILOVER_FAIL_COUNT")), Eq(1)))
.Times(1);
FWController.TelemetryEvent = WAN_FAILOVER_FAIL;
WanMgr_TelemetryEventTrigger(&FWController);
}

#endif
42 changes: 41 additions & 1 deletion source/test/RdkWanManagerTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@
#include <mocks/mock_securewrapper.h>
#include <mocks/mock_ansc_memory.h>
#include <mocks/mock_cap.h>
#include <mocks/mock_psm.h>
#include <mocks/mock_ansc_task.h>
#include <mocks/mock_SysInfoRepository.h>
#include <mocks/mock_ansc_timer_scheduler.h>
#include <mocks/mock_ansc_crypto.h>
#include <mocks/mock_ansc_xml.h>
#include <mocks/mock_ansc_file_io.h>
#include <mocks/mock_ansc_co.h>
#include <mocks/mock_dslh_dmagnt_exported.h>
#include <mocks/mock_ccsp_dmapi.h>
#include <mocks/mock_user_runtime.h>
#include <mocks/mock_ansc_debug.h>
#include <mocks/mock_trace.h>
#include <mocks/mock_file_io.h>
#include <mocks/mock_base_api.h>
#include <mocks/mock_usertime.h>
#include <mocks/mock_ansc_wrapper_api.h>



#include "wanmgr_interface_sm.h"

using namespace std;
Expand All @@ -38,6 +58,9 @@ using ::testing::Eq;
using ::testing::StrEq;
using ::testing::IsNull;
using ::testing::NotNull;
using ::testing::SetArgReferee;
using ::testing::SetArgPointee;
using ::testing::DoAll;

class MockWanMgr
{
Expand All @@ -64,12 +87,29 @@ class WanMgrBase : public ::testing::Test

MockWanMgr mockWanUtils;
rbusMock mockedRbus;

AnscCoMock mockedAnscCo;
SecureWrapperMock mockSecurewrapperMock;
CapMock mockCap;
AnscMemoryMock mockAnscMemory;
MessageBusMock mockMessagebus;
PlatformHalMock mockPlatformHAL;
PsmMock mockPSM;
AnscTaskMock mockanscTaskMock;
SysInfoRepositoryMock mocksysInfoRepositoryMock;
AnscTimerSchedulerMock mockanscTimerSchedulerMock;
AnscCryptoMock mockanscCryptoMock;
AnscXmlMock mockAnscXml;
AnscFileIOMock mockAnscFileIOMock;
DslhDmagntExportedMock mockdslhDmagntExported;
CcspDmApiMock mockccspDmApiMock;
UserRuntimeMock mockedUserRuntime;
AnscDebugMock mockedAnscDebug;
TraceMock mockedTrace;
FileIOMock mockedFileIO;
BaseAPIMock mockedbaseapi;
UserTimeMock mockedUserTime;
AnscWrapperApiMock mockedanscWrapperApi;


WanMgrBase();

Expand Down
58 changes: 38 additions & 20 deletions source/test/Test_wanmgr_rbus_handler_apis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class RbusHandlerTest : public WanMgrBase
{
WanMgr_Iface_Data_t* pIfaceData = &(pWanIfaceCtrl->pIface[idx]);

strncpy(pIfaceData->data.VirtIfList->IP.Ipv4Data.ip, "9.9.9.9",sizeof(pIfaceData->data.VirtIfList->IP.Ipv4Data.ip));
strncpy(pIfaceData->data.VirtIfList->IP.Ipv6Data.address, "2a02:c7f:8253:3900::1",sizeof(pIfaceData->data.VirtIfList->IP.Ipv6Data.address));
strncpy(pIfaceData->data.VirtIfList->IP.Ipv6Data.sitePrefix, "2a02:c7f:8253:3900::1",sizeof(pIfaceData->data.VirtIfList->IP.Ipv6Data.sitePrefix));
strncpy(pIfaceData->data.VirtIfList->IP.Ipv4Data.ip, "9.9.9.9",sizeof(pIfaceData->data.VirtIfList->IP.Ipv4Data.ip)-1);
strncpy(pIfaceData->data.VirtIfList->IP.Ipv6Data.address, "2a02:c7f:8253:3900::1",sizeof(pIfaceData->data.VirtIfList->IP.Ipv6Data.address)-1);
strncpy(pIfaceData->data.VirtIfList->IP.Ipv6Data.sitePrefix, "2a02:c7f:8253:3900::1",sizeof(pIfaceData->data.VirtIfList->IP.Ipv6Data.sitePrefix)-1);
}
}

Expand All @@ -61,36 +61,54 @@ class RbusHandlerTest : public WanMgrBase
}
};


TEST_F(RbusHandlerTest, InterfaceGetHandlerIPV6Address)
{
rbusHandle_t handle = nullptr;
rbusProperty_t property = nullptr;
rbusGetHandlerOptions_t *opts = nullptr;
std::string DmlName = "Device.X_RDK_WanManager.Interface.1.VirtualInterface.1.IP.IPv6Address";

EXPECT_CALL(mockedRbus, rbusValue_Init(_)).Times(1);
EXPECT_CALL(mockedRbus, rbusValue_SetString(_,StrEq("2a02:c7f:8253:3900::1"))).Times(1);
EXPECT_CALL(mockedRbus, rbusProperty_SetValue(_,_)).Times(1);
rbusProperty_t property = reinterpret_cast<rbusProperty_t>(0x1234);
rbusGetHandlerOptions_t opts;
rbusValue_t value = reinterpret_cast<rbusValue_t>(0x5678);


EXPECT_CALL(mockedRbus, rbusProperty_GetName(property))
.Times(1)
.WillOnce(Return(DmlName.c_str()));


EXPECT_CALL(mockedRbus, rbusValue_Init(_))
.Times(1)
.WillOnce(DoAll(SetArgPointee<0>(value), Return(value)));

EXPECT_CALL(mockedRbus, rbusValue_SetString(value,StrEq("2a02:c7f:8253:3900::1"))).Times(1);
EXPECT_CALL(mockedRbus, rbusProperty_SetValue(property,value)).Times(1);
EXPECT_CALL(mockedRbus, rbusValue_Release(_)).Times(1);
EXPECT_CALL(mockedRbus, rbusProperty_GetName(Eq(nullptr))).Times(1).WillOnce(Return(DmlName.c_str()));

EXPECT_EQ(RBUS_ERROR_SUCCESS, WanMgr_Interface_GetHandler(handle, property, opts));
rbusError_t result = WanMgr_Interface_GetHandler(handle, property, &opts);
EXPECT_EQ(result, RBUS_ERROR_SUCCESS);


}

TEST_F(RbusHandlerTest, InterfaceGetHandlerIPV4Address)
{
rbusHandle_t handle = nullptr;
rbusProperty_t property = nullptr;
rbusGetHandlerOptions_t *opts = nullptr;
std::string DmlName = "Device.X_RDK_WanManager.Interface.1.VirtualInterface.1.IP.IPv4Address";
rbusProperty_t property = reinterpret_cast<rbusProperty_t>(0x1234);
rbusGetHandlerOptions_t opts;
rbusValue_t value = reinterpret_cast<rbusValue_t>(0x5678);

EXPECT_CALL(mockedRbus, rbusProperty_GetName(property))
.Times(1)
.WillOnce(Return(DmlName.c_str()));

EXPECT_CALL(mockedRbus, rbusValue_Init(_))
.Times(1)
.WillOnce(DoAll(SetArgPointee<0>(value), Return(value)));

EXPECT_CALL(mockedRbus, rbusValue_Init(_)).Times(1);
EXPECT_CALL(mockedRbus, rbusValue_SetString(value,StrEq("9.9.9.9"))).Times(1);
EXPECT_CALL(mockedRbus, rbusProperty_SetValue(property,value)).Times(1);
EXPECT_CALL(mockedRbus, rbusValue_Release(_)).Times(1);
EXPECT_CALL(mockedRbus, rbusProperty_SetValue(_,_)).Times(1);
EXPECT_CALL(mockedRbus, rbusValue_SetString(_,StrEq("9.9.9.9"))).Times(1);
EXPECT_CALL(mockedRbus, rbusProperty_GetName(Eq(nullptr))).Times(1).WillOnce(Return(DmlName.c_str()));

EXPECT_EQ(RBUS_ERROR_SUCCESS, WanMgr_Interface_GetHandler(handle, property, opts));

rbusError_t result = WanMgr_Interface_GetHandler(handle, property, &opts);
EXPECT_EQ(result, RBUS_ERROR_SUCCESS);
}