Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix existing unit test cases build issue #256

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
116 changes: 74 additions & 42 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,63 +37,95 @@ add_executable(test_webpa_rbus test_webpa_rbus.c ../source/broadband/webpa_rbus.
target_link_libraries (test_webpa_rbus ${WEBPA_COMMON_LIBS} -llibparodus -lrbus)
target_link_libraries (test_webpa_rbus gcov -Wl,--no-as-needed )

# #-------------------------------------------------------------------------------
# # test_webpa_adapter
# #-------------------------------------------------------------------------------
# add_test(NAME test_webpa_adapter COMMAND ${MEMORY_CHECK} ./test_webpa_adapter)
# add_executable(test_webpa_adapter test_webpa_adapter.c ../source/broadband/webpa_adapter.c)
# target_link_libraries (test_webpa_adapter -lwrp-c -ldbus-1 -lccsp_common -lwdmp-c -lcjson ${WEBPA_COMMON_LIBS})
#-------------------------------------------------------------------------------
# test_webpa_adapter
#-------------------------------------------------------------------------------
add_test(NAME test_webpa_adapter COMMAND ${MEMORY_CHECK} ./test_webpa_adapter)
add_executable(test_webpa_adapter test_webpa_adapter.c ../source/broadband/webpa_adapter.c)
target_link_libraries (test_webpa_adapter -lwrp-c -ldbus-1 -lccsp_common -lwdmp-c -lcjson ${WEBPA_COMMON_LIBS})
target_link_libraries (test_webpa_adapter gcov -Wl,--no-as-needed )

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

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

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

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

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

# #-------------------------------------------------------------------------------
# # test_webpa_replace
# #-------------------------------------------------------------------------------
# add_test(NAME test_webpa_replace COMMAND ${MEMORY_CHECK} ./test_webpa_replace)
# add_executable(test_webpa_replace test_webpa_replace.c mock_stack.c mock_cache.c ../source/app/libpd.c ../source/broadband/webpa_replace.c ${WEBPA_COMMON_SOURCES})
# target_link_libraries (test_webpa_replace -lwrp-c -ldbus-1 -lccsp_common -lwdmp-c -lcjson ${WEBPA_COMMON_LIBS} -llibparodus)
#-------------------------------------------------------------------------------
# test_webpa_replace
#-------------------------------------------------------------------------------
add_test(NAME test_webpa_replace COMMAND ${MEMORY_CHECK} ./test_webpa_replace)
add_executable(test_webpa_replace test_webpa_replace.c mock_stack.c mock_cache.c ../source/app/libpd.c ../source/broadband/webpa_replace.c ${WEBPA_COMMON_SOURCES})
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 )

# Code coverage

add_custom_target(coverage
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_libpd.dir/__/src --output-file test_libpd.info
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_webpa_rbus.dir/__/src --output-file test_webpa_rbus.info
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_webpa_adapter.dir/__/src --output-file test_webpa_adapter.info
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_webpa_get.dir/__/src --output-file test_webpa_get.info
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_webpa_set.dir/__/src --output-file test_webpa_set.info
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_webpa_get_attr.dir/__/src --output-file test_webpa_get_attr.info
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_webpa_set_attr.dir/__/src --output-file test_webpa_set_attr.info
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
-a test_libpd.info
-a test_webpa_rbus.info
-a test_webpa_adapter.info
-a test_webpa_get.info
-a test_webpa_set.info
-a test_webpa_get_attr.info
-a test_webpa_set_attr.info
-a test_webpa_replace.info
-a test_webpa_notification.info
--output-file coverage.info

COMMAND genhtml coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
14 changes: 14 additions & 0 deletions tests/mock_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
/*----------------------------------------------------------------------------*/
/* External Functions */
/*----------------------------------------------------------------------------*/
void clearTraceContext()

Check warning on line 44 in tests/mock_stack.c

View check run for this annotation

Codecov / codecov/patch

tests/mock_stack.c#L44

Added line #L44 was not covered by tests
{

}

rbusError_t getTraceContext(char* traceContext[])

Check warning on line 49 in tests/mock_stack.c

View check run for this annotation

Codecov / codecov/patch

tests/mock_stack.c#L49

Added line #L49 was not covered by tests
{
UNUSED(traceContext);
}

rbusError_t setTraceContext(char* traceContext[])

Check warning on line 54 in tests/mock_stack.c

View check run for this annotation

Codecov / codecov/patch

tests/mock_stack.c#L54

Added line #L54 was not covered by tests
{
UNUSED(traceContext);
}

void set_global_components(componentStruct_t **components)
{
Expand Down
4 changes: 4 additions & 0 deletions tests/mock_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define _MOCK_SATCK_H_

#include <ccsp_base_api.h>
#include <rbus/rbus.h>
#define UNUSED(x) (void )(x)
/*----------------------------------------------------------------------------*/
/* Function Prototypes */
Expand All @@ -33,6 +34,9 @@ void set_global_parameters_count(int count);
int get_global_parameters_count();
void set_global_attributes(parameterAttributeStruct_t **attributes);
parameterAttributeStruct_t ** get_global_attributes();
void clearTraceContext();
rbusError_t getTraceContext(char* traceContext[]);
rbusError_t setTraceContext(char* traceContext[]);

#endif

20 changes: 18 additions & 2 deletions tests/test_webpa_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <rbus/rbus.h>

#include "../source/include/webpa_adapter.h"
#include <cimplog/cimplog.h>
Expand All @@ -39,6 +40,16 @@
/*----------------------------------------------------------------------------*/
/* Mocks */
/*----------------------------------------------------------------------------*/
rbusError_t getTraceContext(char* traceContext[])

Check warning on line 43 in tests/test_webpa_adapter.c

View check run for this annotation

Codecov / codecov/patch

tests/test_webpa_adapter.c#L43

Added line #L43 was not covered by tests
{
UNUSED(traceContext);
}

rbusError_t setTraceContext(char* traceContext[])

Check warning on line 48 in tests/test_webpa_adapter.c

View check run for this annotation

Codecov / codecov/patch

tests/test_webpa_adapter.c#L48

Added line #L48 was not covered by tests
{
UNUSED(traceContext);
}

void getValues(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus)
{
UNUSED(paramName); UNUSED(paramCount); UNUSED(index); UNUSED(timeSpan);
Expand Down Expand Up @@ -131,6 +142,8 @@
char *reqPayload = "{ \"names\":[\"Device.DeviceInfo.Webpa.Enable\"],\"command\": \"GET\"}";
char *transactionId = "aasfsdfgeh";
char *resPayload = NULL;
headers_t *res_headers = NULL;
headers_t *req_headers = NULL;
cJSON *response = NULL, *paramArray = NULL, *resParamObj = NULL;
count = 1;
parameterList = (param_t **) malloc(sizeof(param_t*));
Expand All @@ -144,7 +157,7 @@
expect_value(getValues, paramCount, 1);
expect_value(getValues, index, 0);
expect_function_call(getValues);
processRequest(reqPayload, transactionId, &resPayload);
processRequest(reqPayload, transactionId, &resPayload, req_headers, res_headers);
WalInfo("resPayload : %s\n",resPayload);
assert_non_null(resPayload);
response = cJSON_Parse(resPayload);
Expand Down Expand Up @@ -175,6 +188,9 @@
count = 3;
char *names[MAX_PARAMETER_LEN] = {"Device.DeviceInfo.Webpa.CMC", "Device.DeviceInfo.Webpa.CID", "Device.DeviceInfo.Webpa.Version"};
char *values[MAX_PARAMETER_LEN] = {"32","abcd", "1"};
headers_t *res_headers = NULL;
headers_t *req_headers = NULL;

parameterList = (param_t **) malloc(sizeof(param_t*));
parameterList[0] = (param_t *) malloc(sizeof(param_t)*count);

Expand All @@ -190,7 +206,7 @@
expect_value(getValues, paramCount, 1);
expect_value(getValues, index, 0);
expect_function_call(getValues);
processRequest(reqPayload, transactionId, &resPayload);
processRequest(reqPayload, transactionId, &resPayload, req_headers, res_headers);
WalInfo("resPayload : %s\n",resPayload);
assert_non_null(resPayload);
response = cJSON_Parse(resPayload);
Expand Down
Loading
Loading