Skip to content
Open

test #242

Show file tree
Hide file tree
Changes from 6 commits
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
2 changes: 2 additions & 0 deletions .github/workflows/L1-Test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Unit tests RdkFirmwareUpgrader

on:
push:
branches: [ topic/* ]
pull_request:
branches: [ develop, main ]

Expand Down
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ if IS_IARMEVENT_ENABLED
librdksw_iarmIntf_la_CFLAGS += $(IARM_EVENT_FLAG)
endif

if IS_IARMEVENT_ENABLED
librdksw_fwutils_la_CFLAGS += $(IARM_EVENT_FLAG)
endif

if IS_LIBRFCAPI_ENABLED
librdksw_rfcIntf_la_CFLAGS += $(LIBRFCAPI_FLAG)
endif
Expand Down
3 changes: 1 addition & 2 deletions run_ut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ echo "-------------> Return value $rdkfwupdatemgr_main_flow"

dbus_handlers_gtest=$?
echo "-------------> Return value $dbus_handlers_gtest"

if [ "$devicestatus" = "0" ] && [ "$deviceutils" = "0" ] && [ "$mainapp" = "0" ] && [ "$rdkfw_interface" = "0" ]&& [ "$rdkFwupdateMgr_handlers" = "0" ] && [ "$dbus_handlers_gtest" = "0" ] && [ "$rdkfwupdatemgr_main_flow" = "0" ]; then
cd ../src/

Expand All @@ -77,4 +76,4 @@ if [ "$devicestatus" = "0" ] && [ "$deviceutils" = "0" ] && [ "$mainapp" = "0" ]
else
echo "L1 UNIT TEST FAILED. PLEASE CHECK AND FIX"
exit 1
fi
fi
10 changes: 10 additions & 0 deletions src/deviceutils/device_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ size_t GetAdditionalFwVerInfo( char *pAdditionalFwVerInfo, size_t szBufSize )

RETURN - number of characters copied to the output buffer.
*/
#if 0
size_t GetPDRIFileName( char *pPDRIFilename, size_t szBufSize )
{
char *pTmp;
Expand All @@ -234,7 +235,16 @@ size_t GetPDRIFileName( char *pPDRIFilename, size_t szBufSize )
}
return len;
}
#endif

size_t GetPDRIFileName( char *pPDRIFilename, size_t szBufSize )
{
size_t len = 0;
#if defined(IARM_ENABLED)
len = GetPDRIFileNameUsingMFR(pPDRIFilename, szBufSize);
#endif
Comment on lines +242 to +245
Comment on lines +242 to +245
Comment on lines +240 to +245
Comment on lines +240 to +245
Comment on lines +242 to +245
return len;
}

/* function GetInstalledBundles - gets the bundles installed on a device.
Usage: size_t GetInstalledBundles <char *pBundles> <size_t szBufSize>
Expand Down
4 changes: 4 additions & 0 deletions src/deviceutils/device_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#define GETRDMMANIFESTVERSION_IN_SCRIPT
#endif

#if defined(IARM_ENABLED)
#include "iarmInterface.h"
#endif

#ifdef GTEST_ENABLE
#include "rdkv_cdl_log_wrapper.h"
#endif
Expand Down
40 changes: 40 additions & 0 deletions src/iarmInterface/iarmInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,46 @@ bool isConnectedToInternet (void)
return isconnected;
}

size_t GetPDRIFileNameUsingMFR(char *pPDRIFilename, size_t szBufSize)
{
size_t len = 0;
IARM_Result_t ret;
IARM_Bus_MFRLib_GetSerializedData_Param_t param;
Comment on lines +321 to +325

if (pPDRIFilename == NULL) {
SWLOG_ERROR("GetPDRIFileName: Error, input argument NULL\n");
return 0;
}

SWLOG_INFO("GetPDRIFileName: Fetching PDRI image name via IARM_Bus_Call (MFRMgr)");

memset(&param, 0, sizeof(param));
param.type = mfrSERIALIZED_TYPE_PDRIVERSION;

ret = IARM_Bus_Call(
IARM_BUS_MFRLIB_NAME,
IARM_BUS_MFRLIB_API_GetSerializedData,
(void *)&param,
sizeof(param)
);

if (ret == IARM_RESULT_SUCCESS )
{
SWLOG_INFO("GetPDRIFileName: IARM_Bus_Call Success , param.bufLen : %zu\n" , (size_t)param.bufLen);
if(param.bufLen > 0 && param.bufLen < szBufSize) {
memcpy(pPDRIFilename, param.buffer, param.bufLen);
pPDRIFilename[param.bufLen] = '\0';
len = param.bufLen;
SWLOG_INFO("GetPDRIFileName: IARM_Bus_Call OK, PDRI Version = %s", pPDRIFilename);
Comment on lines +344 to +351
}
Comment on lines +347 to +352
} else {
// Error path: be explicit
SWLOG_ERROR("GetPDRIFileName: IARM_Bus_Call failed (ret=%d, bufLen=%zu). Cannot retrieve PDRI image name.", ret, (size_t)param.bufLen);

}

return len;
Comment on lines +321 to +359
}
#else

// Do nothing act as pass through function .
Expand Down
19 changes: 18 additions & 1 deletion src/include/iarmInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#if defined(IARM_ENABLED)
#ifndef GTEST_ENABLE
#include "mfrMgr.h"
#include "sysMgr.h"
#include "libIARMCore.h"
#include "libIBus.h"
Expand Down Expand Up @@ -74,6 +75,22 @@ typedef struct _IARM_BUS_SYSMgr_EventData_t{

typedef char gchar;

#ifndef IARM_BUS_MFRLIB_NAME
#define IARM_BUS_MFRLIB_NAME "IARM_BUS_MFRLIB_NAME_teststub"
#endif

#ifndef IARM_BUS_MFRLIB_API_GetSerializedData
#define IARM_BUS_MFRLIB_API_GetSerializedData 111
#endif

typedef struct {
int type;
size_t bufLen;
char buffer[256];
} IARM_Bus_MFRLib_GetSerializedData_Param_t;

#define mfrSERIALIZED_TYPE_PDRIVERSION 0

#endif
#endif

Expand Down Expand Up @@ -130,5 +147,5 @@ int term_event_handler(void);
int init_event_handler(void);
void interuptDwnl(int app_mode);
bool isConnectedToInternet (void);

size_t GetPDRIFileNameUsingMFR(char *pPDRIFilename, size_t szBufSize);
#endif /* VIDEO_IARMINTERFACE_IARMINTERFACE_H_ */
10 changes: 6 additions & 4 deletions unittest/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ rdkfw_main_gtest_SOURCES = basic_rdkv_main_gtest.cpp \
../src/deviceutils/device_api.c \
../src/deviceutils/deviceutils.c \
deviceutils/json_parse.c \
./mocks/deviceutils_mock.cpp
./mocks/deviceutils_mock.cpp \
./mocks/iarmInterface_mock.cpp

rdkfw_interface_gtest_SOURCES = fwdl_interface_gtest.cpp \
./mocks/interface_mock.cpp \
../src/rfcInterface/rfcinterface.c \
../src/iarmInterface/iarmInterface.c \
./mocks/rbus_mock.c \
../src/rbusInterface/rbusInterface.c \
deviceutils/json_parse.c
deviceutils/json_parse.c


# rdkFwupdateMgr_handlers_gtest: Tests D-Bus handler functions for daemon
Expand All @@ -79,7 +80,7 @@ rdkFwupdateMgr_handlers_gtest_SOURCES = rdkFwupdateMgr_handlers_gtest.cpp \
./mocks/deviceutils_mock.cpp \
../src/dbus/rdkFwupdateMgr_handlers.c \
../src/json_process.c \
deviceutils/json_parse.c
deviceutils/json_parse.c
# Note: All functions from rdkv_upgrade.c, chunk.c, device_status_helper.c, download_status_helper.c
# are stubbed in rdkFwupdateMgr_mock.cpp
# Note: device_api.c and deviceutils.c functions are mocked in deviceutils_mock.cpp
Expand Down Expand Up @@ -134,7 +135,8 @@ rdkfwupdatemgr_main_flow_gtest_SOURCES = rdkfwupdatemgr_main_flow_gtest.cpp \
../src/deviceutils/deviceutils.c \
deviceutils/json_parse.c \
miscellaneous_mock.cpp \
./mocks/deviceutils_mock.cpp
./mocks/deviceutils_mock.cpp \
./mocks/iarmInterface_mock.cpp
Comment on lines 134 to +139

rdkfwupdatemgr_main_flow_gtest_CPPFLAGS = $(COMMON_CPPFLAGS) -I../src/dbus $(GLIB_CFLAGS)
rdkfwupdatemgr_main_flow_gtest_LDFLAGS = $(GLIB_LIBS)
Expand Down
17 changes: 17 additions & 0 deletions unittest/deviceutils/device_api_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ TEST_F(DeviceApiTestFixture,TestName_getadditionfw_nullcheck)
{
EXPECT_EQ(GetAdditionalFwVerInfo(NULL, 0), 0);
}
#if 0
TEST_F(DeviceApiTestFixture, TestName_Success)
{
Comment on lines +178 to +180
char data[64];
// Instead of v_secure_popen, expect the MFR call:
EXPECT_CALL(*g_DeviceStatusMock, GetPDRIFileNameUsingMFR(_, _))
.Times(1)
.WillOnce([](char* out, size_t sz){
strcpy(out, "mockpdri.bin");
return strlen(out);
});

// Now call and expect correct result:
EXPECT_EQ(GetAdditionalFwVerInfo(data, sizeof(data)), strlen("mockpdri.bin"));
EXPECT_STREQ(data, "mockpdri.bin");
}
//TODO: Need to check why v_secure_popen is not returning properly
TEST_F(DeviceApiTestFixture,TestName_Success)
{
Expand All @@ -191,6 +207,7 @@ TEST_F(DeviceApiTestFixture,TestName_Success)
EXPECT_CALL(*g_DeviceUtilsMock, v_secure_popen(_, _, _)).Times(1).WillOnce(Return(fp));
EXPECT_EQ(GetAdditionalFwVerInfo(data, sizeof(data)), 0);
}
#endif
TEST(TestGetPDRIFileName, Test_pdri_Nullcheck)
{
EXPECT_EQ(GetPDRIFileName(NULL, 0), 0);
Expand Down
18 changes: 18 additions & 0 deletions unittest/mocks/device_status_helper_mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,24 @@ extern "C" void eventManager(const char *cur_event_name, const char *event_statu
return g_DeviceStatusMock->eventManager(cur_event_name, event_status);
}

extern "C" size_t GetPDRIFileNameUsingMFR(char *pPDRIFilename, size_t szBufSize)
{
if (!g_DeviceStatusMock) {
cout << "GetPDRIFileNameUsingMFR g_IarmInterfaceMock object is NULL" << endl;
return 0;
}
printf("Inside Mock Function GetPDRIFileNameUsingMFR\n");
// Give a fake file name for tests unless you want to do more in your mock object
const char *mockPDRI = "mock-PDRI-image.bin";
size_t len = strlen(mockPDRI);
if (pPDRIFilename && szBufSize > len) {
strncpy(pPDRIFilename, mockPDRI, szBufSize);
pPDRIFilename[szBufSize - 1] = '\0';
return len;
}
Comment on lines +326 to +333
Comment on lines +326 to +333
return g_DeviceStatusMock->GetPDRIFileNameUsingMFR(pPDRIFilename, szBufSize);
}

extern "C" size_t GetPDRIFileName( char *pPDRIFilename, size_t szBufSize )
{
if (!g_DeviceStatusMock)
Expand Down
2 changes: 2 additions & 0 deletions unittest/mocks/device_status_helper_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class DeviceStatusInterface
virtual int write_RFCProperty(const char *key, const char *value, RFCVALDATATYPE datatype) = 0;
virtual void uninitialize(int data) = 0;
virtual void eventManager(const char *cur_event_name, const char *event_status) = 0;
virtual size_t GetPDRIFileNameUsingMFR( char *pPDRIFilename, size_t szBufSize ) = 0;
virtual size_t GetPDRIFileName( char *pPDRIFilename, size_t szBufSize ) = 0;
virtual void updateUpgradeFlag(int action) = 0;
virtual void t2CountNotify(char *marker) = 0;
Expand Down Expand Up @@ -93,6 +94,7 @@ class DeviceStatusMock: public DeviceStatusInterface
MOCK_METHOD(void, uninitialize, (int data), ());
MOCK_METHOD(void, eventManager, (const char *cur_event_name, const char *event_status), ());
MOCK_METHOD(size_t, GetPDRIFileName, ( char *pPDRIFilename, size_t szBufSize ), ());
MOCK_METHOD(size_t, GetPDRIFileNameUsingMFR, ( char *pPDRIFilename, size_t szBufSize ), ());
MOCK_METHOD(void, updateUpgradeFlag, (int action), ());
MOCK_METHOD(void, t2CountNotify, (char *marker), ());
MOCK_METHOD(void, t2ValNotify, (char *marker, char *val), ());
Expand Down
17 changes: 17 additions & 0 deletions unittest/mocks/deviceutils_mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,23 @@ extern "C" void t2ValNotify(char *marker, char *val)
return g_DeviceUtilsMock->t2ValNotify(marker, val);
}

extern "C" size_t GetPDRIFileNameUsingMFR(char *pPDRIFilename, size_t szBufSize)
{
if (!g_DeviceUtilsMock) {
cout << "GetPDRIFileNameUsingMFR g_IarmInterfaceMock object is NULL" << endl;
return 0;
}
printf("Inside Mock Function GetPDRIFileNameUsingMFR\n");
// Give a fake file name for tests unless you want to do more in your mock object
const char *mockPDRI = "mock-PDRI-image.bin";
size_t len = strlen(mockPDRI);
if (pPDRIFilename && szBufSize > len) {
strncpy(pPDRIFilename, mockPDRI, szBufSize);
pPDRIFilename[szBufSize - 1] = '\0';
return len;
}
Comment on lines +276 to +283
Comment on lines +276 to +283
return g_DeviceUtilsMock->GetPDRIFileNameUsingMFR(pPDRIFilename, szBufSize);
Comment on lines +276 to +284
}
// ========== Mocks for external functions (moved to common_utilities) ==========
/*
extern "C" size_t GetTimezone(char *pTimezone, const char *arch, size_t szBufSize)
Expand Down
2 changes: 2 additions & 0 deletions unittest/mocks/deviceutils_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class DeviceUtilsInterface
virtual size_t GetModelNum( char *pModelNum, size_t szBufSize ) = 0;
virtual void t2CountNotify(char *marker) = 0;
virtual void t2ValNotify(char *marker, char *val) = 0;
virtual size_t GetPDRIFileNameUsingMFR( char *pPDRIFilename, size_t szBufSize ) = 0;
};

class DeviceUtilsMock: public DeviceUtilsInterface
Expand All @@ -83,5 +84,6 @@ class DeviceUtilsMock: public DeviceUtilsInterface
MOCK_METHOD(size_t, GetModelNum, ( char *pModelNum, size_t szBufSize ), ());
MOCK_METHOD(void, t2CountNotify, (char *marker), ());
MOCK_METHOD(void, t2ValNotify, (char *marker, char *val), ());
MOCK_METHOD(size_t, GetPDRIFileNameUsingMFR, ( char *pPDRIFilename, size_t szBufSize ), ());
};
#endif
44 changes: 44 additions & 0 deletions unittest/mocks/iarmInterface_mock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2023 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "iarmInterface_mock.h"
#include <iostream>
#include <cstring>

using namespace std;

// A simple global pointer for mocking; in real use you can extend this with gmock if desired
IarmInterfaceMock *g_IarmInterfaceMock = nullptr;

extern "C" size_t GetPDRIFileNameUsingMFR(char *pPDRIFilename, size_t szBufSize)
{
if (!g_IarmInterfaceMock) {
cout << "GetPDRIFileNameUsingMFR g_IarmInterfaceMock object is NULL" << endl;
return 0;
Comment on lines +25 to +32
}
printf("Inside Mock Function GetPDRIFileNameUsingMFR\n");
// Give a fake file name for tests unless you want to do more in your mock object
const char *mockPDRI = "mock-PDRI-image.bin";
size_t len = strlen(mockPDRI);
if (pPDRIFilename && szBufSize > len) {
strncpy(pPDRIFilename, mockPDRI, szBufSize);
pPDRIFilename[szBufSize - 1] = '\0';
return len;
}
Comment on lines +35 to +42
Comment on lines +35 to +42
return g_IarmInterfaceMock->GetPDRIFileNameUsingMFR(pPDRIFilename, szBufSize);
}
Comment on lines +28 to +44
15 changes: 15 additions & 0 deletions unittest/mocks/iarmInterface_mock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// File: unittest/mocks/iarmInterface_mock.h

#pragma once
#include <cstddef>

class IarmInterfaceMock {
public:
virtual ~IarmInterfaceMock() = default;
virtual size_t GetPDRIFileNameUsingMFR(char *pPDRIFilename, size_t szBufSize) {
// Default mock does nothing real
return 0;
}
};

extern IarmInterfaceMock *g_IarmInterfaceMock;
11 changes: 11 additions & 0 deletions unittest/mocks/interface_mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,14 @@ extern "C" int getJsonRpc(char *data, void *ptr)
printf("Inside Mock Function getJsonRpc\n");
return g_InterfaceMock->getJsonRpc(data, ptr);
}

extern "C" int IARM_Bus_Call(const char* ownerName, int apiId, void* param, unsigned int paramLen)
{
if(!g_InterfaceMock)
{
cout << "g_InterfaceMock object is NULL" << endl;
return -1;
}
printf("Inside Mock Function IARM_Bus_Call\n");
return g_InterfaceMock->IARM_Bus_Call(ownerName,apiId,param,paramLen);
}
3 changes: 3 additions & 0 deletions unittest/mocks/interface_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FwDlInterface
virtual int IARM_Bus_Term() = 0;
virtual int allocDowndLoadDataMem(void *ptr, int size) = 0;
virtual int getJsonRpc(char *data, void *ptr) = 0;
virtual int IARM_Bus_Call(const char* ownerName, int apiId, void* param, unsigned int paramLen) = 0;
};

class FwDlInterfaceMock: public FwDlInterface
Expand All @@ -75,6 +76,8 @@ class FwDlInterfaceMock: public FwDlInterface
MOCK_METHOD(int, IARM_Bus_Term, (), ());
MOCK_METHOD(int, allocDowndLoadDataMem, (void *ptr, int size), ());
MOCK_METHOD(int, getJsonRpc, (char *data, void *ptr), ());
MOCK_METHOD(int, IARM_Bus_Call, (const char*, int, void*, unsigned int), ());

};

#endif
Loading
Loading