diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index d715666a..5c95d12b 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -64,13 +64,13 @@ jobs: mkdir _install mkdir _install/lib cp ${RBUS_INSTALL_DIR}/usr/lib/librbus* _install/lib - build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output make all + build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output make all test - - name: Test - working-directory: build + # ARGS=-VV make test # use this version for debugging + + - name: Stop rtrouted run: | - # ARGS=-VV make test # use this version for debugging - make test + killall -9 rtrouted - name: Merge GCOV Reports for Sonarcloud working-directory: build diff --git a/source/broadband/webpa_rbus.c b/source/broadband/webpa_rbus.c index d0819edb..4219a57b 100644 --- a/source/broadband/webpa_rbus.c +++ b/source/broadband/webpa_rbus.c @@ -43,7 +43,7 @@ WDMP_STATUS webpaRbusInit(const char *pComponentName) return WDMP_SUCCESS; } -static void webpaRbus_Uninit() +void webpaRbus_Uninit() { rbus_close(rbus_handle); } diff --git a/source/include/webpa_rbus.h b/source/include/webpa_rbus.h index d8b69124..06300023 100644 --- a/source/include/webpa_rbus.h +++ b/source/include/webpa_rbus.h @@ -15,6 +15,7 @@ bool isRbusEnabled(); bool isRbusInitialized(); WDMP_STATUS webpaRbusInit(const char *pComponentName); +void webpaRbus_Uninit(); rbusError_t setTraceContext(char* traceContext[]); rbusError_t getTraceContext(char* traceContext[]); rbusError_t clearTraceContext(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ecf33bc0..a540bc4c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,6 +29,14 @@ add_executable(test_libpd test_libpd.c ../source/app/libpd.c) target_link_libraries (test_libpd -lwrp-c ${WEBPA_COMMON_LIBS} -llibparodus) target_link_libraries (test_libpd gcov -Wl,--no-as-needed ) +#------------------------------------------------------------------------------- +# test_webpa_rbus +#------------------------------------------------------------------------------- +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 gcov -Wl,--no-as-needed ) + # #------------------------------------------------------------------------------- # # test_webpa_adapter # #------------------------------------------------------------------------------- diff --git a/tests/test_webpa_rbus.c b/tests/test_webpa_rbus.c new file mode 100644 index 00000000..b41253ef --- /dev/null +++ b/tests/test_webpa_rbus.c @@ -0,0 +1,140 @@ +#include +#include + +#include "../source/include/webpa_rbus.h" +rbusHandle_t handle; + +// Test case for isRbusEnabled +void test_isRbusEnabled_success() +{ + WalInfo("\n**************************************************\n"); + bool result = isRbusEnabled(); + CU_ASSERT_TRUE(result); +} + +// Test case for isRbusInitialized success +void test_isRbusInitialized_success() +{ + WalInfo("\n**************************************************\n"); + webpaRbusInit("componentName"); + bool result = isRbusInitialized(); + printf("The bool value is %d\n", result); + + CU_ASSERT_TRUE(result); + webpaRbus_Uninit(); +} + +void test_webpaRbusInit_success() +{ + WalInfo("\n**************************************************\n"); + int result = webpaRbusInit("component"); + CU_ASSERT_EQUAL(result, 0); + webpaRbus_Uninit(); +} + +//Successcase for setTraceContext +void test_setTraceContext_success() +{ + WalInfo("\n**************************************************\n"); + rbusError_t rc = RBUS_ERROR_BUS_ERROR; + char* traceContext[2]; + + //allocating moemory for each element + traceContext[0] = strdup("randomvalueone"); + traceContext[1] = strdup("randomvaluetwo"); + rc = setTraceContext(traceContext); + CU_ASSERT_EQUAL(0,rc); + free(traceContext[0]); + free(traceContext[1]); +} + +//traceContext header NULL +void test_setTraceContext_header_NULL() +{ + WalInfo("\n**************************************************\n"); + rbusError_t rc = RBUS_ERROR_BUS_ERROR; + char* traceContext[2]; + traceContext[0] = NULL; + traceContext[1] = NULL; + rc = setTraceContext(traceContext); + CU_ASSERT_EQUAL(1,rc); +} + +//traceContext header empty +void test_setTraceContext_header_empty() +{ + WalInfo("\n**************************************************\n"); + rbusError_t rc = RBUS_ERROR_BUS_ERROR; + char* traceContext[2]; + traceContext[0] = ""; + traceContext[1] = ""; + rc = setTraceContext(traceContext); + CU_ASSERT_EQUAL(1,rc); +} + +void test_getTraceContext_success() +{ + WalInfo("\n**************************************************\n"); + rbusError_t rc = RBUS_ERROR_BUS_ERROR; + char* traceContext[2]; + + //allocating moemory for each element + traceContext[0] = strdup("randomvalueone"); + traceContext[1] = strdup("randomvaluetwo"); + rc = setTraceContext(traceContext); + CU_ASSERT_EQUAL(0,rc); + + getTraceContext(traceContext); + CU_ASSERT_EQUAL(0,rc); + clearTraceContext(); +} + +void test_getTraceContext_empty() +{ + WalInfo("\n**************************************************\n"); + rbusError_t rc = RBUS_ERROR_BUS_ERROR; + char* traceContext[2]; + + getTraceContext(traceContext); + CU_ASSERT_EQUAL(1,rc); +} + +void add_suites( CU_pSuite *suite ) +{ + *suite = CU_add_suite( "tests", NULL, NULL ); + CU_add_test( *suite, "test isRbusEnabled_success", test_isRbusEnabled_success); + CU_add_test( *suite, "test isRbusInitialized_success", test_isRbusInitialized_success); + CU_add_test( *suite, "test webpaRbusInit_success", test_webpaRbusInit_success); + CU_add_test( *suite, "test setTraceContext_success", test_setTraceContext_success); + CU_add_test( *suite, "test setTraceContext_header_NULL", test_setTraceContext_header_NULL); + CU_add_test( *suite, "test setTraceContext_header_empty", test_setTraceContext_header_empty); + CU_add_test( *suite, "test getTraceContext_success", test_getTraceContext_success); + CU_add_test( *suite, "test getTraceContext_empty", test_getTraceContext_empty); +} + + +int main( int argc, char *argv[] ) +{ + unsigned rv = 1; + CU_pSuite suite = NULL; + + (void ) argc; + (void ) argv; + + if( CUE_SUCCESS == CU_initialize_registry() ) { + add_suites( &suite ); + + if( NULL != suite ) { + CU_basic_set_mode( CU_BRM_VERBOSE ); + CU_basic_run_tests(); + printf( "\n" ); + CU_basic_show_failures( CU_get_failure_list() ); + printf( "\n\n" ); + rv = CU_get_number_of_tests_failed(); + } + CU_cleanup_registry(); + } + return rv; +} + +