diff --git a/source/test/Makefile.am b/source/test/Makefile.am index a06ed977..5301c37e 100644 --- a/source/test/Makefile.am +++ b/source/test/Makefile.am @@ -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 diff --git a/source/test/RdkWanManagerTest.cpp b/source/test/RdkWanManagerTest.cpp index bad180cc..179cd2d2 100644 --- a/source/test/RdkWanManagerTest.cpp +++ b/source/test/RdkWanManagerTest.cpp @@ -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() { @@ -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); @@ -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++ ) @@ -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)); @@ -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); @@ -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()); @@ -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. * @@ -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)); @@ -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)); @@ -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; @@ -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 diff --git a/source/test/RdkWanManagerTest.h b/source/test/RdkWanManagerTest.h index dd65126f..d42c3741 100644 --- a/source/test/RdkWanManagerTest.h +++ b/source/test/RdkWanManagerTest.h @@ -28,6 +28,26 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + #include "wanmgr_interface_sm.h" using namespace std; @@ -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 { @@ -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(); diff --git a/source/test/Test_wanmgr_rbus_handler_apis.cpp b/source/test/Test_wanmgr_rbus_handler_apis.cpp index d2a25862..04b57a55 100644 --- a/source/test/Test_wanmgr_rbus_handler_apis.cpp +++ b/source/test/Test_wanmgr_rbus_handler_apis.cpp @@ -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); } } @@ -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(0x1234); + rbusGetHandlerOptions_t opts; + rbusValue_t value = reinterpret_cast(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(0x1234); + rbusGetHandlerOptions_t opts; + rbusValue_t value = reinterpret_cast(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); }