From 4be5f83be960f7b35e6e3d4e04162ba1b3da8578 Mon Sep 17 00:00:00 2001 From: suvi-123 Date: Sun, 17 Dec 2023 22:51:51 +0530 Subject: [PATCH] Additional test cases for webpa_notification --- source/broadband/include/webpa_notification.h | 7 +- source/broadband/webpa_internal.c | 30 +- source/broadband/webpa_notification.c | 106 ++-- source/broadband/webpa_parameter.c | 54 +- tests/test_webpa_notification.c | 595 +++++++++++++++++- 5 files changed, 702 insertions(+), 90 deletions(-) diff --git a/source/broadband/include/webpa_notification.h b/source/broadband/include/webpa_notification.h index 1c8fc803..e1cabfc0 100644 --- a/source/broadband/include/webpa_notification.h +++ b/source/broadband/include/webpa_notification.h @@ -91,7 +91,11 @@ 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 */ /*----------------------------------------------------------------------------*/ @@ -131,4 +135,5 @@ WDMP_STATUS validate_conn_client_notify_data(char *notify_param_name, char* inte * @return status. */ WDMP_STATUS validate_webpa_notification_data(char *notify_param_name, char *write_id); +static void notifyCallback(NotifyData *notifyData); diff --git a/source/broadband/webpa_internal.c b/source/broadband/webpa_internal.c index fa5a19c7..97139946 100644 --- a/source/broadband/webpa_internal.c +++ b/source/broadband/webpa_internal.c @@ -442,30 +442,30 @@ int getComponentDetails(char *parameterName,char ***compName,char ***dbusPath, i #endif snprintf(dst_pathname_cr, sizeof(dst_pathname_cr),"%s%s", l_Subsystem, CCSP_DBUS_INTERFACE_CR); walStrncpy(tempParamName, parameterName,sizeof(tempParamName)); - WalPrint("======= start of getComponentDetails ========\n"); + WalInfo("======= start of getComponentDetails ========\n"); if(cachingStatus == 1) { - WalPrint("Component caching is ready, fetch component details from cache\n"); + WalInfo("Component caching is ready, fetch component details from cache\n"); index = getComponentInfoFromCache(tempParamName, objectName, tempCompName, tempDbusPath); } else { - WalPrint("Component caching is not yet ready, fetch component details from stack\n"); + WalInfo("Component caching is not yet ready, fetch component details from stack\n"); index = -1; } - WalPrint("index : %d\n",index); + WalInfo("index : %d\n",index); // Cannot identify the component from cache, make DBUS call to fetch component if(index == -1 || ComponentValArray[index].comp_size > 2 || SubComponentValArray[index].comp_size >= 2) //comp size anything > 2 and sub comp size >1 . TCCBR-5475 allows dbus calls when sub comp size>1. { - WalPrint("in if for size >2\n"); + WalInfo("in if for size >2\n"); // GET Component for parameter from stack if(index > 0 && ComponentValArray[index].comp_size > 2) { - WalPrint("ComponentValArray[index].comp_size : %d\n",ComponentValArray[index].comp_size); + WalInfo("ComponentValArray[index].comp_size : %d\n",ComponentValArray[index].comp_size); } else if(index > 0 && SubComponentValArray[index].comp_size >= 2) { - WalPrint("SubComponentValArray[index].comp_size : %d\n",SubComponentValArray[index].comp_size); + WalInfo("SubComponentValArray[index].comp_size : %d\n",SubComponentValArray[index].comp_size); } retIndex = IndexMpa_WEBPAtoCPE(tempParamName); if(retIndex == -1) @@ -485,11 +485,11 @@ int getComponentDetails(char *parameterName,char ***compName,char ***dbusPath, i *error = 1; return ret; } - WalPrint("Get component for parameterName : %s from stack\n",tempParamName); + WalInfo("Get component for parameterName : %s from stack\n",tempParamName); ret = CcspBaseIf_discComponentSupportingNamespace(bus_handle, dst_pathname_cr, tempParamName, l_Subsystem, &ppComponents, &size); - WalPrint("size : %d, ret : %d\n",size,ret); + WalInfo("size : %d, ret : %d\n",size,ret); if (ret == CCSP_SUCCESS) { @@ -535,7 +535,7 @@ int getComponentDetails(char *parameterName,char ***compName,char ***dbusPath, i { WalPrint("(*compName)[%d] : %s, (*dbusPath)[%d] : %s\n",i,(*compName)[i],i, (*dbusPath)[i]); } - WalPrint("======= End of getComponentDetails ret =%d ========\n",ret); + WalInfo("======= End of getComponentDetails ret =%d ========\n",ret); return CCSP_SUCCESS; } @@ -544,7 +544,7 @@ void prepareParamGroups(ParamCompList **ParamGroup,int paramCount,int cnt1,char int cnt2 =0, subParamCount =0,matchFlag = 0, tempCount=0; tempCount =*compCount; ParamCompList *localParamGroup = *ParamGroup; - WalPrint("============ start of prepareParamGroups ===========\n"); + WalInfo("============ start of prepareParamGroups ===========\n"); if(*ParamGroup == NULL) { WalPrint("ParamCompList is null initializing\n"); @@ -609,7 +609,7 @@ void prepareParamGroups(ParamCompList **ParamGroup,int paramCount,int cnt1,char } *compCount = tempCount; *ParamGroup = localParamGroup; - WalPrint("============ End of prepareParamGroups compCount =%d===========\n",*compCount); + WalInfo("============ End of prepareParamGroups compCount =%d===========\n",*compCount); } @@ -813,7 +813,7 @@ void IndexMpa_CPEtoWEBPA(char **ppParameterName) IndexMap[j].WebPaInstanceNumber, restDmlString); WAL_FREE(pParameterName); - WalPrint("pDmIntString : %s\n",pDmIntString); + WalInfo("pDmIntString : %s\n",pDmIntString); *ppParameterName = pDmIntString; return; } @@ -839,8 +839,10 @@ char * getParameterValue(char *paramName) char *paramValue = (char *) malloc(sizeof(char)*64); paramCount = sizeof(getParamList)/sizeof(getParamList[0]); param_t **parametervalArr = (param_t **) malloc(sizeof(param_t *) * paramCount); - + WalInfo("-----------before getValues----------\n"); getValues(getParamList, paramCount, 0, NULL,¶metervalArr, &count, &ret); + WalInfo("-----------After getValues----------\n"); + if (ret == WDMP_SUCCESS ) { diff --git a/source/broadband/webpa_notification.c b/source/broadband/webpa_notification.c index 64c5d26c..f0ee72be 100644 --- a/source/broadband/webpa_notification.c +++ b/source/broadband/webpa_notification.c @@ -31,7 +31,7 @@ #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_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" @@ -258,7 +258,7 @@ void initNotifyTask(int status) } else { - WalPrint("notifyTask Thread created Successfully\n"); + WalInfo("notifyTask Thread created Successfully\n"); } } @@ -385,19 +385,20 @@ void ccspWebPaValueChangedCB(parameterSigStruct_t* val, int size, void* user_dat int RegisterNotifyCB(notifyCB cb) { + WalInfo("Inside RegisterNotifyCB\n"); notifyCbFn = cb; return 1; } void * getNotifyCB() { - WalPrint("Inside getNotifyCB\n"); + WalInfo("Inside getNotifyCB\n"); return notifyCbFn; } void processTransactionNotification(char transId[]) { - WalPrint("processTransactionNotification\n"); + WalInfo("processTransactionNotification\n"); if (NULL == notifyCbFn) { WalError("Fatal: notifyCbFn is NULL\n"); @@ -406,8 +407,8 @@ void processTransactionNotification(char transId[]) else { - WalPrint("transId : %s\n",transId); - WalPrint("Allocate memory to NotifyData \n"); + WalInfo("transId : %s\n",transId); + WalInfo("Allocate memory to NotifyData \n"); NotifyData *notifyDataPtr = (NotifyData *) malloc(sizeof(NotifyData) * 1); memset(notifyDataPtr,0,sizeof(NotifyData)); @@ -415,7 +416,7 @@ void processTransactionNotification(char transId[]) notifyDataPtr->u.status = (TransData*) malloc(sizeof(TransData)); notifyDataPtr->u.status->transId = (char *)malloc(sizeof(char) * (strlen(transId)+1)); walStrncpy(notifyDataPtr->u.status->transId, transId, (strlen(transId)+1)); - WalPrint("notifyDataPtr->u.status->transId : %s\n",notifyDataPtr->u.status->transId); + WalInfo("notifyDataPtr->u.status->transId : %s\n",notifyDataPtr->u.status->transId); (*notifyCbFn)(notifyDataPtr); } } @@ -444,11 +445,11 @@ void sendConnectedClientNotification(char * macId, char *status, char *interface node->hostname = (char *)(malloc(sizeof(char) * strlen(hostname) + 1)); strncpy(node->hostname, hostname, strlen(hostname) + 1); - WalPrint("node->nodeMacId : %s node->status: %s node->interface: %s node->hostname: %s\n",node->nodeMacId,node->status, node->interface, node->hostname); + WalInfo("node->nodeMacId : %s node->status: %s node->interface: %s node->hostname: %s\n",node->nodeMacId,node->status, node->interface, node->hostname); } notifyDataPtr->u.node = node; - + WalInfo("Before notifyDataPtr\n"); (*notifyCbFn)(notifyDataPtr); } @@ -481,15 +482,19 @@ void processDeviceManageableNotification() */ void loadCfgFile() { + WalInfo("Inside loadCfgFile\n"); FILE *fp; cJSON *webpa_cfg = NULL; char *cfg_file_content = NULL, *temp_ptr = NULL; int ch_count = 0; int flag = 0; size_t sz; + WalInfo("Before fopen\n"); fp = fopen(WEBPA_CFG_FILE, "r"); + WalInfo("After fopen\n"); if (fp == NULL) { + perror("Error opening file"); WalError("Failed to open cfg file in read mode creating new file %s\n", WEBPA_CFG_FILE); fp = fopen(WEBPA_CFG_FILE, "w"); if (fp == NULL) @@ -520,7 +525,7 @@ void loadCfgFile() return WDMP_FAILURE; } cfg_file_content[ch_count] ='\0'; - WalPrint("cfg_file_content : \n%s\n",cfg_file_content); + WalInfo("cfg_file_content : \n%s\n",cfg_file_content); fclose(fp); if(flag == 0) @@ -529,13 +534,14 @@ void loadCfgFile() if(webpa_cfg) { - WalPrint("**********Loading Webpa Config***********\n"); + WalInfo("**********Loading Webpa Config***********\n"); if(cJSON_GetObjectItem(webpa_cfg, WEBPA_CFG_FIRMWARE_VER) != NULL) { + WalInfo("After if\n"); temp_ptr = cJSON_GetObjectItem(webpa_cfg, WEBPA_CFG_FIRMWARE_VER)->valuestring; strncpy(webPaCfg.oldFirmwareVersion, temp_ptr, strlen(temp_ptr)+1); - WalPrint("oldFirmwareVersion : %s\n", webPaCfg.oldFirmwareVersion); + WalInfo("oldFirmwareVersion : %s\n", webPaCfg.oldFirmwareVersion); } else { @@ -557,7 +563,9 @@ void loadCfgFile() fclose(fp); } } + WalInfo("Before free\n"); free(cfg_file_content); + WalInfo("After free\n"); } /** @@ -795,7 +803,7 @@ void getDeviceMac() int retryCount = 0; int backoffRetryTime = 0; int c=2; - + WalInfo("Inside getDeviceMac\n"); if(strlen(deviceMAC) == 0) { do @@ -847,9 +855,15 @@ void getDeviceMac() static void *notifyTask(void *status) { pthread_detach(pthread_self()); + WalInfo("Before getDeviceMac\n"); getDeviceMac(); + WalInfo("After getDeviceMac\n"); + WalInfo("Before loadCfgFile\n"); + loadCfgFile(); + WalInfo("After loadCfgFile\n"); processDeviceStatusNotification(*(int *)status); + WalInfo("Before RegisterNotifyCB\n"); RegisterNotifyCB(¬ifyCallback); sendNotificationForFactoryReset(); FactoryResetCloudSyncTask(); @@ -857,7 +871,7 @@ static void *notifyTask(void *status) setInitialNotify(); handleNotificationEvents(); WAL_FREE(status); - WalPrint("notifyTask ended!\n"); + WalInfo("notifyTask ended!\n"); return NULL; } @@ -985,7 +999,8 @@ 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+" ); + WalInfo("----------Inside addOrUpdateFirmwareVerToConfigFile---------\n"); if( fileRead == NULL ) { WalError( "Error opening file in read mode\n" ); @@ -1030,19 +1045,19 @@ static WDMP_STATUS addOrUpdateFirmwareVerToConfigFile(char *value) if( cfgValObj != NULL) { cJSON_ReplaceItemInObject(json, WEBPA_CFG_FIRMWARE_VER, cJSON_CreateString(value)); - WalPrint("Updated current firmware in config file %s\n",value); + WalInfo("Updated current firmware in config file %s\n",value); } else { cJSON_AddStringToObject(json, WEBPA_CFG_FIRMWARE_VER, value); - WalPrint("Firmware version is not available in webpa_cfg.json, adding %s as %s\n",WEBPA_CFG_FIRMWARE_VER,value); + WalInfo("Firmware version is not available in webpa_cfg.json, adding %s as %s\n",WEBPA_CFG_FIRMWARE_VER,value); } cJsonOut = cJSON_Print(json); configUpdateStatus = writeToJson(cJsonOut); if (configUpdateStatus == 0) { - WalPrint("Updated current Firmware version to config file\n"); + WalInfo("Updated current Firmware version to config file\n"); WAL_FREE(cJsonOut); cJSON_Delete(json); WAL_FREE(data); @@ -1050,7 +1065,7 @@ static WDMP_STATUS addOrUpdateFirmwareVerToConfigFile(char *value) } else { - WalPrint("Unable to update Firmware version to config file\n"); + WalInfo("Unable to update Firmware version to config file\n"); } WAL_FREE(cJsonOut); cJSON_Delete(json); @@ -1128,20 +1143,23 @@ void processNotification(NotifyData *notifyData) char *reason = NULL; snprintf(device_id, sizeof(device_id), "mac:%s", deviceMAC); - WalPrint("Device_id %s\n", device_id); + WalInfo("Device_id %s\n", device_id); cJSON_AddStringToObject(notifyPayload, "device_id", device_id); - + WalInfo("After cJSON_AddStringToObject\n"); dest = (char*) malloc(sizeof(char) * WEBPA_NOTIFY_EVENT_MAX_LENGTH); if (dest != NULL) { if (notifyData != NULL) { + WalInfo("Inside notifyData\n"); switch (notifyData->type) { + WalInfo("Inside switch\n"); case PARAM_NOTIFY: { + WalInfo("Inside PARAM_NOTIFY\n"); strcpy(dest, "event:SYNC_NOTIFICATION"); ret = processParamNotification(notifyData->u.notify, &cmc, &cid); @@ -1153,7 +1171,7 @@ void processNotification(NotifyData *notifyData) } cJSON_AddNumberToObject(notifyPayload, "cmc", cmc); cJSON_AddStringToObject(notifyPayload, "cid", cid); - OnboardLog("%s/%d/%s\n",dest,cmc,cid); + WalInfo("%s/%d/%s\n",dest,cmc,cid); //Added delay of 5s to fix wifi captive portal issue where sync notifications are sent before wifi updates the parameter values in device DB WalInfo("Sleeping for 5 sec before sending SYNC_NOTIFICATION\n"); sleep(5); @@ -1162,7 +1180,7 @@ void processNotification(NotifyData *notifyData) case FACTORY_RESET: { - WalPrint("----- Inside FACTORY_RESET type -----\n"); + WalInfo("----- Inside FACTORY_RESET type -----\n"); strcpy(dest, "event:SYNC_NOTIFICATION"); @@ -1173,7 +1191,7 @@ void processNotification(NotifyData *notifyData) free(dest); return; } - WalPrint("Framing notifyPayload for Factory reset\n"); + WalInfo("Framing notifyPayload for Factory reset\n"); cJSON_AddNumberToObject(notifyPayload, "cmc", cmc); cJSON_AddStringToObject(notifyPayload, "cid", cid); cJSON_AddStringToObject(notifyPayload, "reboot_reason", (NULL != reboot_reason) ? reboot_reason : "NULL"); @@ -1182,7 +1200,7 @@ void processNotification(NotifyData *notifyData) case FIRMWARE_UPGRADE: { - WalPrint("----- Inside FIRMWARE_UPGRADE type -----\n"); + WalInfo("----- Inside FIRMWARE_UPGRADE type -----\n"); strcpy(dest, "event:SYNC_NOTIFICATION"); @@ -1202,7 +1220,7 @@ void processNotification(NotifyData *notifyData) case CONNECTED_CLIENT_NOTIFY: { - WalPrint("Processing connected client notification\n"); + WalInfo("Processing connected client notification\n"); processConnectedClientNotification(notifyData->u.node, device_id, &version, &nodeMacId, &timeStamp, &dest); @@ -1237,6 +1255,7 @@ void processNotification(NotifyData *notifyData) case TRANS_STATUS: { + WalInfo("Inside TRANS_STATUS"); strcpy(dest, "event:transaction-status"); cJSON_AddStringToObject(notifyPayload, "state", "complete"); @@ -1256,12 +1275,14 @@ void processNotification(NotifyData *notifyData) case DEVICE_STATUS: { + WalInfo("-----Inside DEVICE_STATUS-----\n"); strBootTime = getParameterValue(DEVICE_BOOT_TIME); if(notifyData->u.device->status != 0) { reason = (char *)malloc(sizeof(char)*MAX_REASON_LENGTH); mapComponentStatusToGetReason(notifyData->u.device->status, reason); - OnboardLog("%s\n",reason); + WalInfo("--------Before reason-------\n"); + WalInfo("%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); @@ -1272,13 +1293,13 @@ void processNotification(NotifyData *notifyData) snprintf(dest, WEBPA_NOTIFY_EVENT_MAX_LENGTH, "event:device-status/%s/operational/%s", device_id,(NULL != strBootTime)?strBootTime:"unknown"); cJSON_AddStringToObject(notifyPayload, "status", "operational"); } - WalPrint("dest: %s\n",dest); + WalInfo("dest: %s\n",dest); cJSON_AddStringToObject(notifyPayload,"boot-time", (NULL != strBootTime)?strBootTime:"unknown"); if (strBootTime != NULL) { WAL_FREE(strBootTime); } - OnboardLog("%s\n",dest); + WalInfo("%s\n",dest); } break; @@ -1287,7 +1308,7 @@ void processNotification(NotifyData *notifyData) } stringifiedNotifyPayload = cJSON_PrintUnformatted(notifyPayload); - WalPrint("stringifiedNotifyPayload %s\n", stringifiedNotifyPayload); + WalInfo("stringifiedNotifyPayload %s\n", stringifiedNotifyPayload); if (stringifiedNotifyPayload != NULL && strlen(device_id) != 0) @@ -1295,15 +1316,14 @@ void processNotification(NotifyData *notifyData) source = (char*) malloc(sizeof(char) * sizeof(device_id)); walStrncpy(source, device_id, sizeof(device_id)); sendNotification(stringifiedNotifyPayload, source, dest); - WalPrint("After sendNotification\n"); + WalInfo("After sendNotification\n"); } - WalPrint("Freeing notifyData ....\n"); + WalInfo("Freeing notifyData ....\n"); freeNotifyMessage(notifyData); - WalPrint("notifyData is freed.\n"); + WalInfo("notifyData is freed.\n"); } - - free(dest); + WalInfo("Before free\n"); } cJSON_Delete(notifyPayload); } @@ -1318,8 +1338,10 @@ static WDMP_STATUS processParamNotification(ParamNotify *paramNotify, char strNewCMC[20] = { '\0' }; unsigned int oldCMC, newCMC; WDMP_STATUS status = WDMP_FAILURE; - + WalInfo("-----------before getParameterValue----------\n"); strCMC = getParameterValue(PARAM_CMC); + WalInfo("----------After getParameterValue-----------\n"); + if (strCMC != NULL) { oldCMC = atoi(strCMC); @@ -1330,13 +1352,13 @@ static WDMP_STATUS processParamNotification(ParamNotify *paramNotify, WAL_FREE(strCMC); if (newCMC != oldCMC) { - WalPrint("NewCMC and OldCMC not equal.\n"); + WalInfo("NewCMC and OldCMC not equal.\n"); sprintf(strNewCMC, "%d", newCMC); status = setParameterValue(PARAM_CMC, strNewCMC, WDMP_UINT); if (status == WDMP_SUCCESS) { - WalPrint("Successfully set newCMC value %s\n", strNewCMC); + WalInfo("Successfully set newCMC value %s\n", strNewCMC); strCID = getParameterValue(PARAM_CID); if (strCID != NULL) { @@ -1373,14 +1395,14 @@ static WDMP_STATUS processParamNotification(ParamNotify *paramNotify, */ void processDeviceStatusNotification(int status) { - WalPrint("processDeviceStatusNotification\n"); + WalInfo("processDeviceStatusNotification\n"); NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData)); memset(notifyData,0,sizeof(NotifyData)); notifyData->type = DEVICE_STATUS; notifyData->u.device = (DeviceStatus*) malloc(sizeof(DeviceStatus)); notifyData->u.device->status = status; - WalPrint("notifyData->u.device->status : %d\n",notifyData->u.device->status); + WalInfo("notifyData->u.device->status : %d\n",notifyData->u.device->status); processNotification(notifyData); } @@ -1396,9 +1418,9 @@ static WDMP_STATUS processFactoryResetNotification(ParamNotify *paramNotify, uns unsigned int oldCMC,newCMC; WDMP_STATUS status = WDMP_FAILURE; - WalPrint("Inside processFactoryResetNotification ..\n"); + WalInfo("Inside processFactoryResetNotification ..\n"); dbCID = getParameterValue(PARAM_CID); - WalPrint("dbCID value is %s\n", dbCID); + WalInfo("dbCID value is %s\n", dbCID); strCMC = getParameterValue(PARAM_CMC); reboot_reason = getParameterValue(PARAM_REBOOT_REASON); diff --git a/source/broadband/webpa_parameter.c b/source/broadband/webpa_parameter.c index 7893da4e..72afbdc9 100644 --- a/source/broadband/webpa_parameter.c +++ b/source/broadband/webpa_parameter.c @@ -71,47 +71,50 @@ void getValues(const char *paramName[], const unsigned int paramCount, int index ParamCompList *ParamGroup = NULL; char **compName = NULL; char **dbusPath = NULL; - WalPrint("------------- getValues -------------\n"); + WalInfo("------------- getValues -------------\n"); for(cnt1 = 0; cnt1 < paramCount; cnt1++) { - WalPrint("paramName[%d] : %s\n",cnt1,paramName[cnt1]); + WalInfo("paramName[%d] : %s\n",cnt1,paramName[cnt1]); // Get the matching component index from cache walStrncpy(parameterName,paramName[cnt1],sizeof(parameterName)); // To get list of component name and dbuspath + WalInfo("----------Before getComponentDetails---------\n"); ret = getComponentDetails(parameterName,&compName,&dbusPath,&error,&count); + WalInfo("----------After getComponentDetails---------\n"); + if(error == 1) { break; } - WalPrint("parameterName: %s count: %d\n",parameterName,count); + WalInfo("parameterName: %s count: %d\n",parameterName,count); for(i = 0; i < count; i++) { - WalPrint("compName[%d] : %s, dbusPath[%d] : %s\n", i,compName[i],i, dbusPath[i]); + WalInfo("compName[%d] : %s, dbusPath[%d] : %s\n", i,compName[i],i, dbusPath[i]); prepareParamGroups(&ParamGroup,paramCount,cnt1,parameterName,compName[i],dbusPath[i],&compCount); } free_componentDetails(compName,dbusPath,count); }//End of for loop - WalPrint("Number of parameter groups : %d\n",compCount); + WalInfo("Number of parameter groups : %d\n",compCount); if(error != 1) { isLargeWildCard = 0; - WalPrint("compCount : %d paramCount: %d\n",compCount,paramCount); + WalInfo("compCount : %d paramCount: %d\n",compCount,paramCount); if(compCount > paramCount) { - WalPrint("compCount is greater than paramCount\n"); + WalInfo("compCount is greater than paramCount\n"); isLargeWildCard = 1; } for(cnt1 = 0; cnt1 < compCount; cnt1++) { - WalPrint("------------- Parameter group -------------\n"); - WalPrint("ParamGroup[%d].comp_name :%s, ParamGroup[%d].dbus_path :%s, ParamGroup[%d].parameterCount :%d\n",cnt1,ParamGroup[cnt1].comp_name, cnt1,ParamGroup[cnt1].dbus_path, cnt1,ParamGroup[cnt1].parameterCount); + WalInfo("------------- Parameter group -------------\n"); + WalInfo("ParamGroup[%d].comp_name :%s, ParamGroup[%d].dbus_path :%s, ParamGroup[%d].parameterCount :%d\n",cnt1,ParamGroup[cnt1].comp_name, cnt1,ParamGroup[cnt1].dbus_path, cnt1,ParamGroup[cnt1].parameterCount); for(cnt2 = 0; cnt2 < ParamGroup[cnt1].parameterCount; cnt2++) { - WalPrint("ParamGroup[%d].parameterName :%s\n",cnt1,ParamGroup[cnt1].parameterName[cnt2]); + WalInfo("ParamGroup[%d].parameterName :%s\n",cnt1,ParamGroup[cnt1].parameterName[cnt2]); } if(!strcmp(ParamGroup[cnt1].comp_name,RDKB_WIFI_FULL_COMPONENT_NAME) && applySettingsFlag == TRUE) @@ -121,20 +124,25 @@ void getValues(const char *paramName[], const unsigned int paramCount, int index OnboardLog("WiFi component is busy\n"); break; } - WalPrint("index: %d startIndex: %d\n",index, startIndex); + WalInfo("index: %d startIndex: %d\n",index, startIndex); if(isLargeWildCard == 1) { + WalInfo("----------Before getParamValues\n--------"); ret = getParamValues(ParamGroup[cnt1].parameterName, ParamGroup[cnt1].parameterCount, ParamGroup[cnt1].comp_name, ParamGroup[cnt1].dbus_path, timeSpan, index, startIndex, paramArr,&retCount); + WalInfo("----------After getParamValues\n--------"); + startIndex = startIndex + retCount; } else { startIndex = 0; + WalInfo("----------Before getParamValues--------\n"); ret = getParamValues(ParamGroup[cnt1].parameterName, ParamGroup[cnt1].parameterCount, ParamGroup[cnt1].comp_name, ParamGroup[cnt1].dbus_path, timeSpan, index, startIndex, paramArr,&retCount); + WalInfo("----------After getParamValues--------\n"); index = index + ParamGroup[cnt1].parameterCount; } - WalPrint("After getParamValues index = %d ,startIndex : %d retCount = %d\n",index,startIndex,retCount); + WalInfo("After getParamValues index = %d ,startIndex : %d retCount = %d\n",index,startIndex,retCount); if(ret != CCSP_SUCCESS) { WalError("Get Atomic Values call failed for ParamGroup[%d]->comp_name :%s ret: %d\n",cnt1,ParamGroup[cnt1].comp_name,ret); @@ -426,14 +434,14 @@ static int getParamValues(char *parameterNames[], int paramCount, char *CompName int ret = 0, val_size = 0, cnt=0, retIndex=0, error=0; char **parameterNamesLocal = NULL; parameterValStruct_t **parameterval = NULL; - WalPrint(" ------ Start of getParamValues ----\n"); + WalInfo(" ------ Start of getParamValues ----\n"); parameterNamesLocal = (char **) malloc(sizeof(char *) * paramCount); memset(parameterNamesLocal,0,(sizeof(char *) * paramCount)); // Initialize names array with converted index for (cnt = 0; cnt < paramCount; cnt++) { - WalPrint("Before Mapping parameterNames[%d] : %s\n",cnt,parameterNames[cnt]); + WalInfo("Before Mapping parameterNames[%d] : %s\n",cnt,parameterNames[cnt]); parameterNamesLocal[cnt] = (char *) malloc(sizeof(char) * (strlen(parameterNames[cnt]) + 1)); strcpy(parameterNamesLocal[cnt],parameterNames[cnt]); @@ -457,7 +465,7 @@ static int getParamValues(char *parameterNames[], int paramCount, char *CompName break; } - WalPrint("After mapping parameterNamesLocal[%d] : %s\n",cnt,parameterNamesLocal[cnt]); + WalInfo("After mapping parameterNamesLocal[%d] : %s\n",cnt,parameterNamesLocal[cnt]); } if(error != 1) @@ -468,19 +476,23 @@ static int getParamValues(char *parameterNames[], int paramCount, char *CompName #ifdef FEATURE_SUPPORT_WEBCONFIG if(strstr(parameterNamesLocal[0],RDKB_PARAM_WEBCONFIG) != NULL) { + WalInfo("------Before getWebpaParameterValues\n"); ret = getWebConfigParameterValues(parameterNamesLocal, paramCount, &val_size, ¶meterval); } else #endif { + WalInfo("------Before getWebpaParameterValues\n"); ret = getWebpaParameterValues(parameterNamesLocal, paramCount, &val_size, ¶meterval); } } else { + WalInfo("------Before CcspBaseIf_getParameterValues\n"); ret = CcspBaseIf_getParameterValues(bus_handle,CompName,dbusPath,parameterNamesLocal,paramCount, &val_size, ¶meterval); + WalInfo("------After CcspBaseIf_getParameterValues\n"); } - WalPrint("----- After GPV ret = %d------\n",ret); + WalInfo("----- After GPV ret = %d------\n",ret); if (ret != CCSP_SUCCESS) { WalError("Error:Failed to GetValue for parameters ret: %d\n", ret); @@ -488,7 +500,7 @@ static int getParamValues(char *parameterNames[], int paramCount, char *CompName } else { - WalPrint("val_size : %d\n",val_size); + WalInfo("val_size : %d\n",val_size); if (val_size > 0) { if((paramCount == val_size) && (parameterNamesLocal[0][strlen(parameterNamesLocal[0])-1] != '.')) @@ -496,7 +508,7 @@ static int getParamValues(char *parameterNames[], int paramCount, char *CompName for (cnt = 0; cnt < val_size; cnt++) { (*paramArr)[paramIndex] = (param_t *) malloc(sizeof(param_t)); - WalPrint("Stack:> success: %s %s %d \n",parameterval[cnt][0].parameterName,parameterval[cnt][0].parameterValue, parameterval[cnt][0].type); + WalInfo("Stack:> success: %s %s %d \n",parameterval[cnt][0].parameterName,parameterval[cnt][0].parameterValue, parameterval[cnt][0].type); IndexMpa_CPEtoWEBPA(¶meterval[cnt][0].parameterName); IndexMpa_CPEtoWEBPA(¶meterval[cnt][0].parameterValue); @@ -522,10 +534,10 @@ static int getParamValues(char *parameterNames[], int paramCount, char *CompName for (cnt = 0; cnt < val_size; cnt++) { - WalPrint("Stack:> success: %s %s %d \n",parameterval[cnt][0].parameterName,parameterval[cnt][0].parameterValue, parameterval[cnt][0].type); + WalInfo("Stack:> success: %s %s %d \n",parameterval[cnt][0].parameterName,parameterval[cnt][0].parameterValue, parameterval[cnt][0].type); IndexMpa_CPEtoWEBPA(¶meterval[cnt][0].parameterName); IndexMpa_CPEtoWEBPA(¶meterval[cnt][0].parameterValue); - WalPrint("B4 assignment\n"); + WalInfo("B4 assignment\n"); (*paramArr)[paramIndex][cnt+startIndex].name = parameterval[cnt][0].parameterName; (*paramArr)[paramIndex][cnt+startIndex].value = parameterval[cnt][0].parameterValue; (*paramArr)[paramIndex][cnt+startIndex].type = parameterval[cnt][0].type; @@ -535,7 +547,7 @@ static int getParamValues(char *parameterNames[], int paramCount, char *CompName } else if(val_size == 0 && ret == CCSP_SUCCESS) { - WalPrint("No child elements found\n"); + WalInfo("No child elements found\n"); } *TotalParams = val_size; diff --git a/tests/test_webpa_notification.c b/tests/test_webpa_notification.c index 0406abe6..39246a3d 100644 --- a/tests/test_webpa_notification.c +++ b/tests/test_webpa_notification.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "../source/include/webpa_adapter.h" @@ -31,7 +32,7 @@ #include #include #include -#include +//#include #include #include "mock_stack.h" @@ -39,6 +40,7 @@ #define PARAM_FIRMWARE_VERSION "Device.DeviceInfo.X_CISCO_COM_FirmwareName" #define DEVICE_BOOT_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_BootTime" + extern componentStruct_t **getDeviceInfoCompDetails(); extern void loadCfgFile(); extern void set_global_cloud_status(char*); @@ -91,12 +93,15 @@ int pthread_cond_timedwait(pthread_cond_t *cloud_con, pthread_mutex_t *cloud_mut return (int) mock(); } -FILE* fopen(const char* pathname, const char* mode) +/*FILE* fopen(const char* pathname, const char* mode) { UNUSED(pathname); UNUSED(mode); function_called(); + // FILE *fp = NULL; return (FILE*) mock(); + //return fp; } +*/ int getWebpaParameterValues(char **parameterNames, int paramCount, int *val_size, parameterValStruct_t ***val) { UNUSED(parameterNames); UNUSED(paramCount); UNUSED(val_size); UNUSED(val); @@ -109,7 +114,7 @@ int setWebpaParameterValues(parameterValStruct_t *val, int paramCount, char **fa return (int) mock(); } -unsigned int sleep(unsigned int seconds) +/*unsigned int sleep(unsigned int seconds) { struct timespec delay; @@ -120,6 +125,8 @@ unsigned int sleep(unsigned int seconds) return seconds; } +*/ + /*----------------------------------------------------------------------------*/ /* Tests */ @@ -262,8 +269,6 @@ void test_firmware_upgrade_notification() will_return(get_global_values, cmcList); will_return(get_global_parameters_count, 1); - will_return(fopen, NULL); - expect_function_call(fopen); expect_function_call(CcspBaseIf_getParameterValues); will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); expect_value(CcspBaseIf_getParameterValues, size, 1); @@ -597,10 +602,6 @@ void test_FR_notify_cloud_status_empty_mac() void err_loadCfgFile() { - will_return(fopen, NULL); - expect_function_call(fopen); - will_return(fopen, NULL); - expect_function_call(fopen); loadCfgFile(); } @@ -707,7 +708,7 @@ void test_processNotification() node->hostname = strdup("wifi"); notifyData->u.node = node; - parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); version[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); version[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); version[0]->parameterValue =strdup("123456"); @@ -738,6 +739,564 @@ void test_processNotification() expect_function_call(libparodus_send); processNotification(notifyData); } + +void test_processNotification_PARAM_NOTIFY() +{ + strcpy(deviceMAC, "14cfe2142112"); + NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData)); + memset(notifyData,0,sizeof(NotifyData)); + + notifyData->type = PARAM_NOTIFY; + + NodeData * node = NULL; + notifyData->u.notify = (ParamNotify*)malloc(sizeof(ParamNotify)); + if (notifyData->u.notify != NULL) + { + notifyData->u.notify->paramName = PARAM_FIRMWARE_VERSION; + notifyData->u.notify->oldValue = "abcd"; + notifyData->u.notify->newValue = "dcba"; + notifyData->u.notify->type = WDMP_STRING; + notifyData->u.notify->changeSource = CHANGED_BY_WEBPA; + } + node = (NodeData *) malloc(sizeof(NodeData) * 1); + memset(node, 0, sizeof(NodeData)); + node->nodeMacId = strdup("14cfe2142144"); + node->status = strdup("Connected"); + node->interface = strdup("eth0"); + node->hostname = strdup("wifi"); + notifyData->u.node = node; + + parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + version[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + version[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); + version[0]->parameterValue =strdup("123456"); + version[0]->type = ccsp_string; + + parameterValStruct_t **version2 = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + version2[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + version2[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); + version2[0]->parameterValue =strdup("123456"); + version2[0]->type = ccsp_string; + + parameterValStruct_t **systemTime = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + systemTime[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + systemTime[0]->parameterName = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_SystemTime"); + systemTime[0]->parameterValue =strdup("546543280"); + systemTime[0]->type = ccsp_string; + getCompDetails(); + + will_return(get_global_values, version); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(get_global_values, version2); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(get_global_faultParam, NULL); + will_return(CcspBaseIf_setParameterValues, CCSP_SUCCESS); + expect_function_call(CcspBaseIf_setParameterValues); + expect_value(CcspBaseIf_setParameterValues, size, 1); + + will_return(get_global_values, systemTime); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(libparodus_send, (intptr_t)0); + expect_function_call(libparodus_send); + processNotification(notifyData); +} + +void test_processNotification_DEVICE_STATUS_PAM_FAILED() +{ + strcpy(deviceMAC, "14cfe2142112"); + NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData)); + memset(notifyData,0,sizeof(NotifyData)); + + notifyData->type = DEVICE_STATUS; + + notifyData->u.device = (ParamNotify*)malloc(sizeof(ParamNotify)); + if (notifyData->u.device != NULL) + { + notifyData->u.device->status = 1; + } + + parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + version[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + version[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); + version[0]->parameterValue =strdup("123456"); + version[0]->type = ccsp_string; + + will_return(get_global_components, getDeviceInfoCompDetails()); + will_return(get_global_component_size, 1); + expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + expect_function_call(free_componentStruct_t); + + will_return(get_global_values, version); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(libparodus_send, (intptr_t)0); + expect_function_call(libparodus_send); + + processNotification(notifyData); + +} + +void test_processNotification_DEVICE_STATUS_success() +{ + strcpy(deviceMAC, "14cfe2142112"); + NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData)); + memset(notifyData,0,sizeof(NotifyData)); + + notifyData->type = DEVICE_STATUS; + + notifyData->u.device = (ParamNotify*)malloc(sizeof(ParamNotify)); + if (notifyData->u.device != NULL) + { + notifyData->u.device->status = 0; + } + + parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + version[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + version[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); + version[0]->parameterValue =strdup("123456"); + version[0]->type = ccsp_string; + + will_return(get_global_components, getDeviceInfoCompDetails()); + will_return(get_global_component_size, 1); + expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + expect_function_call(free_componentStruct_t); + + will_return(get_global_values, version); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(libparodus_send, (intptr_t)0); + expect_function_call(libparodus_send); + + processNotification(notifyData); + +} + +void test_processNotification_DEVICE_STATUS_epon_fail() +{ + strcpy(deviceMAC, "14cfe2142112"); + NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData)); + memset(notifyData,0,sizeof(NotifyData)); + + notifyData->type = DEVICE_STATUS; + + notifyData->u.device = (ParamNotify*)malloc(sizeof(ParamNotify)); + if (notifyData->u.device != NULL) + { + notifyData->u.device->status = 2; + } + + parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + version[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + version[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); + version[0]->parameterValue =strdup("123456"); + version[0]->type = ccsp_string; + + will_return(get_global_components, getDeviceInfoCompDetails()); + will_return(get_global_component_size, 1); + expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + expect_function_call(free_componentStruct_t); + + will_return(get_global_values, version); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(libparodus_send, (intptr_t)0); + expect_function_call(libparodus_send); + + processNotification(notifyData); +} + +void test_processNotification_DEVICE_STATUS_cm_fail() +{ + strcpy(deviceMAC, "14cfe2142112"); + NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData)); + memset(notifyData,0,sizeof(NotifyData)); + + notifyData->type = DEVICE_STATUS; + + notifyData->u.device = (ParamNotify*)malloc(sizeof(ParamNotify)); + if (notifyData->u.device != NULL) + { + notifyData->u.device->status = 3; + } + + parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + version[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + version[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); + version[0]->parameterValue =strdup("123456"); + version[0]->type = ccsp_string; + + will_return(get_global_components, getDeviceInfoCompDetails()); + will_return(get_global_component_size, 1); + expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + expect_function_call(free_componentStruct_t); + + will_return(get_global_values, version); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(libparodus_send, (intptr_t)0); + expect_function_call(libparodus_send); + + processNotification(notifyData); +} + +void test_processNotification_DEVICE_STATUS_psm_fail() +{ + strcpy(deviceMAC, "14cfe2142112"); + NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData)); + memset(notifyData,0,sizeof(NotifyData)); + + notifyData->type = DEVICE_STATUS; + + notifyData->u.device = (ParamNotify*)malloc(sizeof(ParamNotify)); + if (notifyData->u.device != NULL) + { + notifyData->u.device->status = 4; + } + + parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + version[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + version[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); + version[0]->parameterValue =strdup("123456"); + version[0]->type = ccsp_string; + + will_return(get_global_components, getDeviceInfoCompDetails()); + will_return(get_global_component_size, 1); + expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + expect_function_call(free_componentStruct_t); + + will_return(get_global_values, version); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(libparodus_send, (intptr_t)0); + expect_function_call(libparodus_send); + + processNotification(notifyData); +} + +void test_processNotification_DEVICE_STATUS_wifi_fail() +{ + strcpy(deviceMAC, "14cfe2142112"); + NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData)); + memset(notifyData,0,sizeof(NotifyData)); + + notifyData->type = DEVICE_STATUS; + + notifyData->u.device = (ParamNotify*)malloc(sizeof(ParamNotify)); + if (notifyData->u.device != NULL) + { + notifyData->u.device->status = 5; + } + + parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + version[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + version[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); + version[0]->parameterValue =strdup("123456"); + version[0]->type = ccsp_string; + + will_return(get_global_components, getDeviceInfoCompDetails()); + will_return(get_global_component_size, 1); + expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + expect_function_call(free_componentStruct_t); + + will_return(get_global_values, version); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(libparodus_send, (intptr_t)0); + expect_function_call(libparodus_send); + + processNotification(notifyData); +} + +void test_processNotification_DEVICE_STATUS_fail() +{ + strcpy(deviceMAC, "14cfe2142112"); + NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData)); + memset(notifyData,0,sizeof(NotifyData)); + + notifyData->type = DEVICE_STATUS; + + notifyData->u.device = (ParamNotify*)malloc(sizeof(ParamNotify)); + if (notifyData->u.device != NULL) + { + notifyData->u.device->status = 6; + } + + parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + version[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + version[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); + version[0]->parameterValue =strdup("123456"); + version[0]->type = ccsp_string; + + will_return(get_global_components, getDeviceInfoCompDetails()); + will_return(get_global_component_size, 1); + expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + expect_function_call(free_componentStruct_t); + + will_return(get_global_values, version); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(libparodus_send, (intptr_t)0); + expect_function_call(libparodus_send); + + processNotification(notifyData); +} + +int writeFile(const char* fileName, const char* content) { + FILE* file = fopen(fileName, "w"); + if (file == NULL) { + perror("Error opening file"); + return 1; // Return an error code + } + + fprintf(file, "%s\n", content); + + fclose(file); + + WalInfo("Content written to %s\n", fileName); + + return 0; // Return success +} + +/*void test_processTransactionNotification() +{ + const char* testTransId = "12345"; + NotifyData* notifyData = (NotifyData*)malloc(sizeof(NotifyData)); + if (notifyData != NULL) + { + notifyData->type = PARAM_NOTIFY; + notifyData->u.notify = (ParamNotify*)malloc(sizeof(ParamNotify)); + if (notifyData->u.notify != NULL) + { + notifyData->u.notify->paramName = PARAM_FIRMWARE_VERSION; + notifyData->u.notify->oldValue = "abcd"; + notifyData->u.notify->newValue = "dcba"; + notifyData->u.notify->type = WDMP_STRING; + notifyData->u.notify->changeSource = CHANGED_BY_WEBPA; + } + else + { + WalError("Memory allocation failed\n"); + free(notifyData); + notifyData = NULL; + } + notifyData->type = TRANS_STATUS; + notifyData->u.status = (TransData*)malloc(sizeof(TransData)); + if (notifyData->u.status != NULL) + { + notifyData->u.status->transId = "12345"; + } + else + { + WalError("Memory allocation failed\n"); + free(notifyData); + notifyData = NULL; + } + } + strcpy(deviceMAC, "14cfe2142112"); + + const char* fileContent = "{\n\"oldFirmwareVersion\": \"CGM4331COM_DEV_23Q4_sprint_20231121134451sdy\"\n}"; + int result = writeFile(WEBPA_CFG_FILE, fileContent); + + strcpy(deviceMAC, "14cfe2142112"); + //NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData)); + //memset(notifyData,0,sizeof(NotifyData)); + + notifyData->type = DEVICE_STATUS; + + notifyData->u.device = (ParamNotify*)malloc(sizeof(ParamNotify)); + if (notifyData->u.device != NULL) + { + notifyData->u.device->status = 1; + } + + parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + version[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + version[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); + version[0]->parameterValue =strdup("123456"); + version[0]->type = ccsp_string; + + will_return(get_global_components, getDeviceInfoCompDetails()); + will_return(get_global_component_size, 1); + expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + expect_function_call(free_componentStruct_t); + + + //getCompDetails(); + //will_return(get_global_components, list); + //will_return(get_global_component_size, 1); + //expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + //will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + //expect_function_call(free_componentStruct_t); + + initNotifyTask(0); + //RegisterNotifyCB(¬ifyCallback); + //will_return(pthread_cond_signal, 1); + //expect_function_call(pthread_cond_signal); + //sleep(250); + //processTransactionNotification(testTransId); +} + +void test_sendConnectedClientNotification() +{ + char *macid = "abcdef123"; + char *status = "success"; + char *interface = "12345abc"; + char *name = "hostname"; + + sendConnectedClientNotification(macid,status,interface,name); + +} +*/ + +/*void test_initNotifyTask() +{ + strcpy(deviceMAC, "14cfe2142112"); + NotifyData *notifyData = (NotifyData *)malloc(sizeof(NotifyData)); + memset(notifyData,0,sizeof(NotifyData)); + + notifyData->type = DEVICE_STATUS; + + notifyData->u.device = (ParamNotify*)malloc(sizeof(ParamNotify)); + if (notifyData->u.device != NULL) + { + notifyData->u.device->status = 0; + } + + parameterValStruct_t **version = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + version[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)); + version[0]->parameterName = strdup("Device.Hosts.X_RDKCENTRAL-COM_HostVersionId"); + version[0]->parameterValue =strdup("123456"); + version[0]->type = ccsp_string; + + will_return(get_global_components, getDeviceInfoCompDetails()); + will_return(get_global_component_size, 1); + expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + expect_function_call(free_componentStruct_t); + + will_return(get_global_values, version); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(libparodus_send, (intptr_t)0); + expect_function_call(libparodus_send); + initNotifyTask(0); + sleep(100); +}*/ + +void test_addOrUpdateFirmwareVerToConfigFile() +{ + getCompDetails(); + strcpy(deviceMAC, "14cfe2142112"); + const char* fileContent = "{\n\"oldFirmwareVersion\": \"CGM4331COM_DEV_23Q4_sprint_20231121134451sdy\"\n}"; + int result = writeFile(WEBPA_CFG_FILE, fileContent); + + parameterValStruct_t **firmwareList = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + firmwareList[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)*1); + firmwareList[0]->parameterName = strndup(PARAM_FIRMWARE_VERSION,MAX_PARAMETER_LEN); + firmwareList[0]->parameterValue = strndup("TG1459_20170901Syd",MAX_PARAMETER_LEN); + firmwareList[0]->type = ccsp_string; + + parameterValStruct_t **cmcList = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + cmcList[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)*1); + cmcList[0]->parameterName = strndup(PARAM_CMC,MAX_PARAMETER_LEN); + cmcList[0]->parameterValue = strndup("12",MAX_PARAMETER_LEN); + cmcList[0]->type = ccsp_int; + + parameterValStruct_t **cmcList1 = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + cmcList1[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)*1); + cmcList1[0]->parameterName = strndup(PARAM_CMC,MAX_PARAMETER_LEN); + cmcList1[0]->parameterValue = strndup("32",MAX_PARAMETER_LEN); + cmcList1[0]->type = ccsp_int; + + parameterValStruct_t **cidList = (parameterValStruct_t **) malloc(sizeof(parameterValStruct_t*)); + cidList[0] = (parameterValStruct_t *) malloc(sizeof(parameterValStruct_t)*1); + cidList[0]->parameterName = strndup(PARAM_CID,MAX_PARAMETER_LEN); + cidList[0]->parameterValue = strndup("abcd",MAX_PARAMETER_LEN); + cidList[0]->type = ccsp_string; + + will_return(get_global_components, getDeviceInfoCompDetails()); + will_return(get_global_component_size, 1); + expect_function_call(CcspBaseIf_discComponentSupportingNamespace); + will_return(CcspBaseIf_discComponentSupportingNamespace, CCSP_SUCCESS); + expect_function_call(free_componentStruct_t); + + will_return(get_global_values, firmwareList); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(get_global_values, cmcList); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(get_global_values, cidList); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(get_global_values, cmcList1); + will_return(get_global_parameters_count, 1); + expect_function_call(CcspBaseIf_getParameterValues); + will_return(CcspBaseIf_getParameterValues, CCSP_SUCCESS); + expect_value(CcspBaseIf_getParameterValues, size, 1); + + will_return(get_global_faultParam, NULL); + will_return(CcspBaseIf_setParameterValues, CCSP_SUCCESS); + expect_function_call(CcspBaseIf_setParameterValues); + expect_value(CcspBaseIf_setParameterValues, size, 1); + + will_return(libparodus_send, (intptr_t)0); + expect_function_call(libparodus_send); + sendNotificationForFirmwareUpgrade(); +} /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ @@ -745,12 +1304,12 @@ void test_processNotification() int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test(test_device_status_notification), + /*cmocka_unit_test(test_device_status_notification), cmocka_unit_test(test_factory_reset_notification), cmocka_unit_test(test_FR_cloud_sync_notification), cmocka_unit_test(test_firmware_upgrade_notification), cmocka_unit_test(err_loadCfgFile), - cmocka_unit_test(test_transaction_status_notification), + cmocka_unit_test(test_transaction_status_notification), cmocka_unit_test(test_FR_cloud_sync_notification_retry), cmocka_unit_test(test_FR_notify_cloud_status_retry), cmocka_unit_test(test_FR_notify_cloud_status_empty_mac), @@ -758,6 +1317,18 @@ int main(void) cmocka_unit_test(err_manageable_notification), cmocka_unit_test(test_factory_reset_notification_with_cmc_512), cmocka_unit_test(test_processNotification), + cmocka_unit_test(test_processNotification_PARAM_NOTIFY), + cmocka_unit_test(test_processNotification_DEVICE_STATUS_PAM_FAILED), + cmocka_unit_test(test_processNotification_DEVICE_STATUS_success), + cmocka_unit_test(test_processNotification_DEVICE_STATUS_epon_fail), + cmocka_unit_test(test_processNotification_DEVICE_STATUS_cm_fail), + cmocka_unit_test(test_processNotification_DEVICE_STATUS_psm_fail), + cmocka_unit_test(test_processNotification_DEVICE_STATUS_wifi_fail), + cmocka_unit_test(test_processNotification_DEVICE_STATUS_fail), + //cmocka_unit_test(test_processTransactionNotification), + //cmocka_unit_test(test_sendConnectedClientNotification), + //cmocka_unit_test(test_initNotifyTask) + */cmocka_unit_test(test_addOrUpdateFirmwareVerToConfigFile), }; numLoops = 1;