Skip to content

Commit

Permalink
Additional test cases for webpa_notification
Browse files Browse the repository at this point in the history
  • Loading branch information
suvi-123 committed Dec 21, 2023
1 parent edd7f95 commit a8d77f7
Show file tree
Hide file tree
Showing 6 changed files with 822 additions and 22 deletions.
6 changes: 5 additions & 1 deletion source/broadband/include/webpa_notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/*----------------------------------------------------------------------------*/
Expand Down
8 changes: 4 additions & 4 deletions source/broadband/webpa_notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -935,7 +935,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 +985,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 +1261,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
2 changes: 1 addition & 1 deletion source/broadband/webpa_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void getValues(const char *paramName[], const unsigned int paramCount, int index
{
ret = getParamValues(ParamGroup[cnt1].parameterName, ParamGroup[cnt1].parameterCount, ParamGroup[cnt1].comp_name, ParamGroup[cnt1].dbus_path, timeSpan, index, startIndex, paramArr,&retCount);
startIndex = startIndex + retCount;
}
}
else
{
startIndex = 0;
Expand Down
15 changes: 13 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST -D_ANSC_LINUX")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage -O0")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -O0")
set (WEBPA_COMMON_LIBS gcov -lcunit -lcimplog -lwrp-c -lpthread -lmsgpackc -lnanomsg -Wl,--no-as-needed -lcjson -ltrower-base64 -lssl -lcrypto -lrt -luuid -lm -lcmocka)
set (WEBPA_COMMON_LIBS gcov -lcimplog -lwrp-c -lpthread -lmsgpackc -lnanomsg -Wl,--no-as-needed -lcjson -ltrower-base64 -lssl -lcrypto -lrt -luuid -lm -lcmocka)
set (WEBPA_COMMON_SOURCES ../source/broadband/webpa_adapter.c ../source/broadband/webpa_internal.c ../source/broadband/webpa_parameter.c ../source/broadband/webpa_attribute.c ../source/broadband/webpa_notification.c)
set (WEBPA_TABLE_SOURCES ../source/broadband/webpa_replace.c ../source/broadband/webpa_table.c)
link_directories ( ${LIBRARY_DIR} )
Expand All @@ -34,7 +34,7 @@ target_link_libraries (test_libpd gcov -Wl,--no-as-needed )
#-------------------------------------------------------------------------------
add_test(NAME test_webpa_rbus COMMAND ${MEMORY_CHECK} ./test_webpa_rbus)
add_executable(test_webpa_rbus test_webpa_rbus.c ../source/broadband/webpa_rbus.c)
target_link_libraries (test_webpa_rbus ${WEBPA_COMMON_LIBS} -llibparodus -lrbus)
target_link_libraries (test_webpa_rbus ${WEBPA_COMMON_LIBS} -llibparodus -lrbus -lcunit)
target_link_libraries (test_webpa_rbus gcov -Wl,--no-as-needed )

#-------------------------------------------------------------------------------
Expand Down 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_notification_cunit
#-------------------------------------------------------------------------------
add_test(NAME test_webpa_notification_cunit COMMAND ${MEMORY_CHECK} ./test_webpa_notification_cunit)
add_executable(test_webpa_notification_cunit test_webpa_notification_cunit.c mock_cache.c ../source/app/libpd.c ${WEBPA_COMMON_SOURCES} ${WEBPA_TABLE_SOURCES})
target_link_libraries (test_webpa_notification_cunit -lwrp-c -ldbus-1 -lccsp_common -lwdmp-c -lcjson ${WEBPA_COMMON_LIBS} -llibparodus -lcunit)
target_link_libraries (test_webpa_notification_cunit gcov -Wl,--no-as-needed )

# Code coverage

add_custom_target(coverage
Expand All @@ -114,6 +122,8 @@ COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_webpa_replace.dir/__/src --output-file test_webpa_replace.info
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_notification_cunit.dir/__/src --output-file test_webpa_notification_cunit.info

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

COMMAND genhtml coverage.info
Expand Down
Loading

0 comments on commit a8d77f7

Please sign in to comment.