Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into add_notify_test
Browse files Browse the repository at this point in the history
  • Loading branch information
suvi-123 committed Dec 21, 2023
2 parents 7425b1b + 1a060bf commit 72cfa45
Show file tree
Hide file tree
Showing 6 changed files with 568 additions and 33 deletions.
11 changes: 6 additions & 5 deletions source/broadband/include/webpa_notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
/*----------------------------------------------------------------------------*/
#define FACTORY_RESET_NOTIFY_MAX_RETRY_COUNT 5
#define XPC_CID "61f4db9"
#if defined(BUILD_YOCTO)
#define WEBPA_CFG_FILE "/nvram/webpa_cfg.json"
#else
#define WEBPA_CFG_FILE "/tmp/webpa_cfg.json"
#endif
/*----------------------------------------------------------------------------*/
/* Data Structures */
/*----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -91,11 +96,7 @@ typedef struct
* @brief Function pointer for Notification callback
*/
typedef void (*notifyCB)(NotifyData *notifyDataPtr);
#if defined(BUILD_YOCTO)
#define WEBPA_CFG_FILE "/nvram/webpa_cfg.json"
#else
#define WEBPA_CFG_FILE "/tmp/webpa_dummy.json"
#endif

/*----------------------------------------------------------------------------*/
/* Function Prototypes */
/*----------------------------------------------------------------------------*/
Expand Down
7 changes: 3 additions & 4 deletions source/broadband/webpa_notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#define PARAM_HOSTS_VERSION "Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"
#define PARAM_SYSTEM_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_SystemTime"
#define PARAM_FIRMWARE_VERSION "Device.DeviceInfo.X_CISCO_COM_FirmwareName"
//#define WEBPA_CFG_FILE "/nvram/webpa_cfg.json"
#define WEBPA_CFG_FIRMWARE_VER "oldFirmwareVersion"
#define DEVICE_BOOT_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_BootTime"
#define FP_PARAM "Device.DeviceInfo.X_RDKCENTRAL-COM_DeviceFingerPrint.Enable"
Expand Down Expand Up @@ -935,7 +934,7 @@ static void handleNotificationEvents()
}
else
{
WalPrint("handleNotificationEvents : Before pthread cond wait in consumer thread\n");
WalPrint("handleNotificationEvents : Before pthread cond wait in consumer thread\n");
pthread_cond_wait(&con, &mut);
pthread_mutex_unlock (&mut);
WalPrint("handleNotificationEvents : mutex unlock in consumer thread after cond wait\n");
Expand Down Expand Up @@ -985,7 +984,7 @@ static WDMP_STATUS addOrUpdateFirmwareVerToConfigFile(char *value)
int len;
int configUpdateStatus = -1;
size_t sz;
fileRead = fopen( WEBPA_CFG_FILE, "r+" );
fileRead = fopen( WEBPA_CFG_FILE, "r+" );
if( fileRead == NULL )
{
WalError( "Error opening file in read mode\n" );
Expand Down Expand Up @@ -1261,7 +1260,7 @@ void processNotification(NotifyData *notifyData)
{
reason = (char *)malloc(sizeof(char)*MAX_REASON_LENGTH);
mapComponentStatusToGetReason(notifyData->u.device->status, reason);
OnboardLog("%s\n",reason);
OnboardLog("%s\n",reason);
snprintf(dest, WEBPA_NOTIFY_EVENT_MAX_LENGTH, "event:device-status/%s/non-operational/%s/%s", device_id,(NULL != strBootTime)?strBootTime:"unknown",reason);
cJSON_AddStringToObject(notifyPayload, "status", "non-operational");
cJSON_AddStringToObject(notifyPayload, "reason", reason);
Expand Down
11 changes: 11 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ add_executable(test_webpa_replace test_webpa_replace.c mock_stack.c mock_cache.c
target_link_libraries (test_webpa_replace -lwrp-c -ldbus-1 -lccsp_common -lwdmp-c -lcjson ${WEBPA_COMMON_LIBS} -llibparodus)
target_link_libraries (test_webpa_replace gcov -Wl,--no-as-needed )

#-------------------------------------------------------------------------------
# test_webpa_table
#-------------------------------------------------------------------------------
add_test(NAME test_webpa_table COMMAND ${MEMORY_CHECK} ./test_webpa_table)
add_executable(test_webpa_table test_webpa_table.c mock_stack.c mock_cache.c ../source/broadband/webpa_adapter.c ../source/app/libpd.c ${WEBPA_COMMON_SOURCES} ${WEBPA_TABLE_SOURCES})
target_link_libraries (test_webpa_table -lwrp-c -ldbus-1 -lccsp_common -lwdmp-c -lcjson ${WEBPA_COMMON_LIBS} -llibparodus)
target_link_libraries (test_webpa_table gcov -Wl,--no-as-needed )

#-------------------------------------------------------------------------------
# test_webpa_notification_cunit
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -123,6 +131,8 @@ ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_webpa_replace.dir/__/src --output-fi
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_webpa_notification.dir/__/src --output-file test_webpa_notification.info
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_webpa_table.dir/__/src --output-file test_webpa_table.info
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_webpa_notification_cunit.dir/__/src --output-file test_webpa_notification_cunit.info

COMMAND lcov
Expand All @@ -135,6 +145,7 @@ COMMAND lcov
-a test_webpa_set_attr.info
-a test_webpa_replace.info
-a test_webpa_notification.info
-a test_webpa_table.info
-a test_webpa_notification_cunit.info
--output-file coverage.info

Expand Down
40 changes: 20 additions & 20 deletions tests/test_webpa_notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ unsigned int sleep(unsigned int seconds)
/*----------------------------------------------------------------------------*/
void test_device_status_notification()
{
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
parameterValStruct_t **bootTime = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*));
bootTime[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)*1);
bootTime[0]->parameterName = strndup(DEVICE_BOOT_TIME,MAX_PARAMETER_LEN);
Expand All @@ -150,7 +150,7 @@ void test_device_status_notification()
void test_factory_reset_notification()
{
getCompDetails();
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");

parameterValStruct_t **cidList = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*));
cidList[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)*1);
Expand Down Expand Up @@ -219,7 +219,7 @@ void test_factory_reset_notification()
void test_firmware_upgrade_notification()
{
getCompDetails();
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");

parameterValStruct_t **firmwareList = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*));
firmwareList[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)*1);
Expand Down Expand Up @@ -301,7 +301,7 @@ void test_FR_cloud_sync_notification()
numLoops = 2;
pthread_t threadId;
getCompDetails();
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
will_return(pthread_cond_signal, (intptr_t)0);
expect_function_call(pthread_cond_signal);

Expand Down Expand Up @@ -398,7 +398,7 @@ void test_FR_cloud_sync_notification_retry()
numLoops = 2;
pthread_t threadId;
getCompDetails();
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
will_return(pthread_cond_signal, (intptr_t)0);
expect_function_call(pthread_cond_signal);

Expand Down Expand Up @@ -478,7 +478,7 @@ void test_FR_notify_cloud_status_retry()
numLoops = 3;
pthread_t threadId;
getCompDetails();
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
will_return(pthread_cond_signal, (intptr_t)0);
expect_function_call(pthread_cond_signal);

Expand Down Expand Up @@ -635,7 +635,7 @@ void err_manageable_notification()
void test_factory_reset_notification_with_cmc_512()
{
getCompDetails();
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");

parameterValStruct_t **cidList = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*));
cidList[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)*1);
Expand Down Expand Up @@ -684,7 +684,7 @@ void test_factory_reset_notification_with_cmc_512()

void test_processNotification()
{
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData));
memset(notifyData,0,sizeof(NotifyData));

Expand Down Expand Up @@ -732,7 +732,7 @@ void test_processNotification()

void test_processNotification_PARAM_NOTIFY()
{
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData));
memset(notifyData,0,sizeof(NotifyData));

Expand Down Expand Up @@ -805,7 +805,7 @@ void test_processNotification_PARAM_NOTIFY()

void test_processNotification_DEVICE_STATUS_PAM_FAILED()
{
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData));
memset(notifyData,0,sizeof(NotifyData));

Expand Down Expand Up @@ -844,7 +844,7 @@ void test_processNotification_DEVICE_STATUS_PAM_FAILED()

void test_processNotification_DEVICE_STATUS_success()
{
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData));
memset(notifyData,0,sizeof(NotifyData));

Expand Down Expand Up @@ -883,7 +883,7 @@ void test_processNotification_DEVICE_STATUS_success()

void test_processNotification_DEVICE_STATUS_epon_fail()
{
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData));
memset(notifyData,0,sizeof(NotifyData));

Expand Down Expand Up @@ -921,7 +921,7 @@ void test_processNotification_DEVICE_STATUS_epon_fail()

void test_processNotification_DEVICE_STATUS_cm_fail()
{
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData));
memset(notifyData,0,sizeof(NotifyData));

Expand Down Expand Up @@ -959,7 +959,7 @@ void test_processNotification_DEVICE_STATUS_cm_fail()

void test_processNotification_DEVICE_STATUS_psm_fail()
{
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData));
memset(notifyData,0,sizeof(NotifyData));

Expand Down Expand Up @@ -997,7 +997,7 @@ void test_processNotification_DEVICE_STATUS_psm_fail()

void test_processNotification_DEVICE_STATUS_wifi_fail()
{
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData));
memset(notifyData,0,sizeof(NotifyData));

Expand Down Expand Up @@ -1035,7 +1035,7 @@ void test_processNotification_DEVICE_STATUS_wifi_fail()

void test_processNotification_DEVICE_STATUS_fail()
{
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData));
memset(notifyData,0,sizeof(NotifyData));

Expand Down Expand Up @@ -1072,8 +1072,8 @@ void test_processNotification_DEVICE_STATUS_fail()
}

int writeFile(const char* fileName, const char* content) {
FILE* file = fopen(fileName, "w");
if (file == NULL) {
FILE* file = open(fileName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (file != -1) {
perror("Error opening file");
return 1; // Return an error code
}
Expand All @@ -1091,7 +1091,7 @@ void test_addOrUpdateFirmwareVerToConfigFile()
{
getCompDetails();
int count = 1;
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
const char* fileContent = "{\n\"oldFirmwareVersion\": \"CGM4331COM_DEV_23Q4_sprint_20231121134451sdy\"\n}";
int result = writeFile(WEBPA_CFG_FILE, fileContent);

Expand Down Expand Up @@ -1185,7 +1185,7 @@ void test_loadCfgFile_success()
void test_getDeviceMac()
{
getCompDetails();
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
getDeviceMac();
}
/*----------------------------------------------------------------------------*/
Expand Down
9 changes: 5 additions & 4 deletions tests/test_webpa_notification_cunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ rbusError_t setTraceContext(char* traceContext[])
UNUSED(traceContext);
}


int getWebpaParameterValues(char **parameterNames, int paramCount, int *val_size, parameterValStruct_t ***val)
{
UNUSED(parameterNames); UNUSED(paramCount); UNUSED(val_size); UNUSED(val);
Expand All @@ -69,6 +68,8 @@ int setWebpaParameterValues(parameterValStruct_t *val, int paramCount, char **fa
UNUSED(faultParam); UNUSED(paramCount); UNUSED(val);
}

//TODO: This functions stops in the middle, need to look into it
#if 0
int CcspBaseIf_discComponentSupportingNamespace (void* bus_handle, const char* dst_component_id, const char *name_space, const char *subsystem_prefix, componentStruct_t ***components, int *size)
{
UNUSED(bus_handle);
Expand Down Expand Up @@ -163,15 +164,15 @@ int CcspBaseIf_setParameterAttributes(void* bus_handle, const char* dst_componen
return 100;
}

//TODO: This functions stops in the middle, need to look into it
void test_initNotifyTask()
{
numLoops = 1;
int i=1;
strcpy(deviceMAC, "14cfe2142112");
strcpy(deviceMAC, "abcdeg1234");
getDeviceMac();
initNotifyTask(0);
}
#endif

void test_validate_conn_client_notify_data()
{
Expand Down Expand Up @@ -283,7 +284,7 @@ void test_validate_webpa_notification_write_id_failure()
void add_suites( CU_pSuite *suite )
{
*suite = CU_add_suite( "tests", NULL, NULL );
CU_add_test( *suite, "test initNotifyTask", test_initNotifyTask);
//CU_add_test( *suite, "test initNotifyTask", test_initNotifyTask);
CU_add_test( *suite, "test validate_conn_client_notify_data", test_validate_conn_client_notify_data);
CU_add_test( *suite, "test validate_conn_client_param_name_failure", test_validate_conn_client_param_name_failure);
CU_add_test( *suite, "test validate_conn_client_interface_failure", test_validate_conn_client_interface_failure);
Expand Down
Loading

0 comments on commit 72cfa45

Please sign in to comment.