From a23316a2affbba8e04314847360aff8853505d88 Mon Sep 17 00:00:00 2001 From: Deepak M <114924314+dm097@users.noreply.github.com> Date: Wed, 8 Nov 2023 22:20:37 +0530 Subject: [PATCH] RDKB-51761 : Test Suite Enhancements (#175) * RDKB-51761 Test scenario to cover multiple rbus_open() call Reason for change: Need to cover test app and unit test to have a test cases which covers multiple rbus_open() with same component name without rbus_close() call. The test scenario should also cover regDataElements, rbus_set, rbus_get, addrow and methodinvoke after doing multiple rbus_open() function call Test Procedure: Start rtrouted and ./rbus_test.sh Risks: Medium Priority: P1 Signed-off-by: Deepak_m * RDKB-51761 Test scenario to cover multiple rbus_open() call Reason for change: Need to cover test app and unit test to have a test cases which covers multiple rbus_open() with same component name without rbus_close() call. The test scenario should also cover regDataElements, rbus_set, rbus_get, addrow and methodinvoke after doing multiple rbus_open() function call Test Procedure: Start rtrouted and ./rbus_test.sh Risks: Medium Priority: P1 Signed-off-by: Deepak_m * RDKB-51761 Test scenario to cover multiple rbus_open() call Reason for change: Need to cover test app and unit test to have a test cases which covers multiple rbus_open() with same component name without rbus_close() call. The test scenario should also cover regDataElements, rbus_set, rbus_get, addrow and methodinvoke after doing multiple rbus_open() function call Test Procedure: Start rtrouted and ./rbus_test.sh Risks: Medium Priority: P1 Signed-off-by: Deepak_m * RDKB-51761 Test scenario to cover multiple rbus_open() call Reason for change: Need to cover test app and unit test to have a test cases which covers multiple rbus_open() with same component name without rbus_close() call. The test scenario should also cover regDataElements, rbus_set, rbus_get, addrow and methodinvoke after doing multiple rbus_open() function call Test Procedure: Start rtrouted and ./rbus_test.sh Risks: Medium Priority: P1 Signed-off-by: Deepak_m * Update unit_tests.yml RDKB-51761 Test scenario to cover multiple rbus_open() call Reason for change: added unit tests verified on GitHub yml Test Procedure: very unit_tests.yml success Risks: Medium Priority: P1 --------- Signed-off-by: Deepak_m --- .github/workflows/unit_tests.yml | 21 ++ sampleapps/CMakeLists.txt | 10 - src/rbus/rbus.c | 22 ++ src/rbus/rbus_handle.c | 23 ++ src/rbus/rbus_handle.h | 1 + test/rbus/CMakeLists.txt | 149 +++++++++++- .../multiConsumerThreadsForSingleEvent.c | 0 .../multiProviderThreadsForSingleEvent.c | 0 .../multiRbusOpenConsumer.c | 180 ++++++++++++++ .../rbusOpenSubRbusOpenConsumer.c | 132 ++++++++++ .../multiRbusOpenMethodConsumer.c | 225 ++++++++++++++++++ .../multiRbusOpenMethodProvider.c | 215 +++++++++++++++++ .../multiRbusOpenProvider.c | 158 ++++++++++++ .../rbusOpenRegRbusOpenProvider.c | 125 ++++++++++ .../multiRbusOpenRbusGetConsumer.c | 106 +++++++++ .../multiRbusOpenRbusGetProvider.c | 177 ++++++++++++++ .../multiRbusOpenRbusSetConsumer.c | 106 +++++++++ test/rbus/rbus_test.sh | 53 ++++- 18 files changed, 1691 insertions(+), 12 deletions(-) rename sampleapps/consumer/rbusThreadConsumer.c => test/rbus/multiConsumerThreadsForSingleEvent/multiConsumerThreadsForSingleEvent.c (100%) rename sampleapps/provider/rbusThreadProvider.c => test/rbus/multiProviderThreadsForSingleEvent/multiProviderThreadsForSingleEvent.c (100%) create mode 100644 test/rbus/multiRbusOpenConsumer/multiRbusOpenConsumer.c create mode 100644 test/rbus/multiRbusOpenConsumer/rbusOpenSubRbusOpenConsumer.c create mode 100644 test/rbus/multiRbusOpenMethodConsumer/multiRbusOpenMethodConsumer.c create mode 100644 test/rbus/multiRbusOpenMethodProvider/multiRbusOpenMethodProvider.c create mode 100644 test/rbus/multiRbusOpenProvider/multiRbusOpenProvider.c create mode 100644 test/rbus/multiRbusOpenProvider/rbusOpenRegRbusOpenProvider.c create mode 100644 test/rbus/multiRbusOpenRbusGetConsumer/multiRbusOpenRbusGetConsumer.c create mode 100644 test/rbus/multiRbusOpenRbusGetProvider/multiRbusOpenRbusGetProvider.c create mode 100644 test/rbus/multiRbusOpenRbusSetConsumer/multiRbusOpenRbusSetConsumer.c diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 44f66b89..0fa2c2ca 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -63,6 +63,27 @@ jobs: export LD_LIBRARY_PATH=$PREFIX/lib nohup ./bin/rbusTestProvider >/tmp/plog.txt & ./bin/rbusTestConsumer -a + - name: Run multiRbusOpenSubscribe Unit test + run: | + cd install/usr + export PREFIX=$PWD + export LD_LIBRARY_PATH=$PREFIX/lib + nohup ./bin/multiRbusOpenProvider >/tmp/log_multiRbusOpenProvider.txt & + ./bin/multiRbusOpenConsumer + - name: Run multiRbusOpenGet Unit test + run: | + cd install/usr + export PREFIX=$PWD + export LD_LIBRARY_PATH=$PREFIX/lib + nohup ./bin/multiRbusOpenRbusGetProvider >/tmp/log_multiRbusOpenRbusGetProvider.txt & + ./bin/multiRbusOpenRbusGetConsumer + - name: Run multiRbusOpenSet Unit test + run: | + cd install/usr + export PREFIX=$PWD + export LD_LIBRARY_PATH=$PREFIX/lib + nohup ./bin/multiRbusOpenRbusGetProvider >/tmp/log_multiRbusOpenRbusSetProvider.txt & + ./bin/multiRbusOpenRbusSetConsumer - name: Stop rtrouted run: | killall -9 rtrouted diff --git a/sampleapps/CMakeLists.txt b/sampleapps/CMakeLists.txt index d1a5cfee..5b76e996 100644 --- a/sampleapps/CMakeLists.txt +++ b/sampleapps/CMakeLists.txt @@ -125,14 +125,6 @@ add_executable(rbusOpenTelemetry consumer/rbusOpenTelemetry.c) add_dependencies(rbusOpenTelemetry rbus) target_link_libraries(rbusOpenTelemetry rbus) -add_executable(rbusThreadProvider provider/rbusThreadProvider.c) -add_dependencies(rbusThreadProvider rbus) -target_link_libraries(rbusThreadProvider rbus) - -add_executable(rbusThreadConsumer consumer/rbusThreadConsumer.c) -add_dependencies(rbusThreadConsumer rbus) -target_link_libraries(rbusThreadConsumer rbus) - add_executable(rbusRawDataProvider provider/rbusRawDataProvider.c) add_dependencies(rbusRawDataProvider rbus) target_link_libraries(rbusRawDataProvider rbus) @@ -159,8 +151,6 @@ install (TARGETS rbusCSIProvider rbusCSIConsumer rbusDirectConsumer - rbusThreadProvider - rbusThreadConsumer rbusRawDataProvider RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/rbus/rbus.c b/src/rbus/rbus.c index 87683dfa..8686aa62 100644 --- a/src/rbus/rbus.c +++ b/src/rbus/rbus.c @@ -108,6 +108,16 @@ } \ } +#define VERIFY_HANDLE(HANDLE) \ +{ \ + VERIFY_NULL(HANDLE); \ + rbusHandle_t pTmp = (rbusHandle_t) HANDLE; \ + if (!rbusHandleList_IsValidHandle(pTmp)) \ + { \ + RBUSLOG_ERROR("handle is invalid"); \ + return RBUS_ERROR_INVALID_HANDLE; \ + } \ +} //********************************************************************************// //******************************* STRUCTURES *************************************// @@ -2907,6 +2917,7 @@ rbusError_t rbus_closeDirect(rbusHandle_t handle) rbusError_t rbus_close(rbusHandle_t handle) { + VERIFY_HANDLE(handle); rbusError_t ret = RBUS_ERROR_SUCCESS; rbusCoreError_t err = RBUSCORE_SUCCESS; struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle; @@ -3021,6 +3032,7 @@ rbusError_t rbus_regDataElements( rbusDataElement_t *elements) { int i; + VERIFY_HANDLE(handle); rbusError_t rc = RBUS_ERROR_SUCCESS; rbusCoreError_t err = RBUSCORE_SUCCESS; struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle; @@ -3120,6 +3132,7 @@ rbusError_t rbus_unregDataElements( int numDataElements, rbusDataElement_t *elements) { + VERIFY_HANDLE(handle); struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle; int i; @@ -3207,6 +3220,7 @@ rbusError_t rbus_get(rbusHandle_t handle, char const* name, rbusValue_t* value) { rbusError_t errorcode = RBUS_ERROR_SUCCESS; rbusCoreError_t err = RBUSCORE_SUCCESS; + VERIFY_HANDLE(handle); rbusMessage request, response; int ret = -1; struct _rbusHandle* handleInfo = (struct _rbusHandle*) handle; @@ -3674,6 +3688,7 @@ rbusError_t rbus_set(rbusHandle_t handle, char const* name,rbusValue_t value, rb { rbusError_t errorcode = RBUS_ERROR_INVALID_INPUT; rbusCoreError_t err = RBUSCORE_SUCCESS; + VERIFY_HANDLE(handle); rbusMessage setRequest, setResponse; struct _rbusHandle* handleInfo = (struct _rbusHandle*) handle; @@ -4830,6 +4845,7 @@ rbusError_t rbusEvent_Subscribe( int timeout) { rbusError_t errorcode; + VERIFY_HANDLE(handle); struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle; VERIFY_NULL(handle); @@ -4855,6 +4871,7 @@ rbusError_t rbusEvent_SubscribeAsync( int timeout) { rbusError_t errorcode; + VERIFY_HANDLE(handle); struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle; VERIFY_NULL(handle); @@ -4876,6 +4893,7 @@ rbusError_t rbusEvent_Unsubscribe( rbusHandle_t handle, char const* eventName) { + VERIFY_HANDLE(handle); struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle; rbusEventSubscriptionInternal_t* subInternal; @@ -4942,6 +4960,7 @@ rbusError_t rbusEvent_UnsubscribeRawData( rbusHandle_t handle, char const* eventName) { + VERIFY_HANDLE(handle); struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle; char rawDataTopic[RBUS_MAX_NAME_LENGTH] = {0}; rbusEventSubscriptionInternal_t* subInternal; @@ -4992,6 +5011,7 @@ rbusError_t rbusEvent_SubscribeEx( int timeout) { rbusError_t errorcode = RBUS_ERROR_SUCCESS; + VERIFY_HANDLE(handle); struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle; int i; @@ -5559,6 +5579,7 @@ rbusError_t rbusMethod_Invoke( rbusObject_t inParams, rbusObject_t* outParams) { + VERIFY_HANDLE(handle); struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle; VERIFY_NULL(handle); VERIFY_NULL(methodName); @@ -5610,6 +5631,7 @@ rbusError_t rbusMethod_InvokeAsync( rbusMethodAsyncRespHandler_t callback, int timeout) { + VERIFY_HANDLE(handle); struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle; pthread_t pid; rbusMethodInvokeAsyncData_t* data; diff --git a/src/rbus/rbus_handle.c b/src/rbus/rbus_handle.c index 603c2c5d..7610232c 100644 --- a/src/rbus/rbus_handle.c +++ b/src/rbus/rbus_handle.c @@ -24,6 +24,29 @@ static rtVector gHandleList = NULL; #define VERIFY_NULL(T,R) if(NULL == T){ RBUSLOG_ERROR(#T" is NULL"); R; } +bool rbusHandleList_IsValidHandle(struct _rbusHandle* handle) +{ + struct _rbusHandle* tmphandle = NULL; + if (handle == NULL) + { + return false; + } + int i; + if(gHandleList) + { + int len = rtVector_Size(gHandleList); + for(i = 0; i < len; i++) + { + tmphandle = (struct _rbusHandle*)rtVector_At(gHandleList, i); + if(tmphandle == handle) + { + return true; + } + } + } + return false; +} + void rbusHandleList_Add(struct _rbusHandle* handle) { VERIFY_NULL(handle,return); diff --git a/src/rbus/rbus_handle.h b/src/rbus/rbus_handle.h index 69972375..a6fe01e4 100644 --- a/src/rbus/rbus_handle.h +++ b/src/rbus/rbus_handle.h @@ -67,6 +67,7 @@ struct _rbusHandle pthread_mutex_t handle_subsMutex; }; +bool rbusHandleList_IsValidHandle(struct _rbusHandle* handle); void rbusHandleList_Add(struct _rbusHandle* handle); void rbusHandleList_Remove(struct _rbusHandle* handle); bool rbusHandleList_IsEmpty(); diff --git a/test/rbus/CMakeLists.txt b/test/rbus/CMakeLists.txt index 71833197..9e5f9ed7 100644 --- a/test/rbus/CMakeLists.txt +++ b/test/rbus/CMakeLists.txt @@ -21,6 +21,7 @@ include_directories(${PROJECT_SOURCE_DIR}/include) include_directories(${PROJECT_SOURCE_DIR}/src/rtmessage) include_directories(${PROJECT_SOURCE_DIR}/src/core) include_directories(${PROJECT_SOURCE_DIR}/src/rbus) +include_directories(${PROJECT_SOURCE_DIR}/test/rbus/common) add_executable(rbusTestProvider provider/rbusTestProvider.c @@ -29,6 +30,44 @@ add_executable(rbusTestProvider add_dependencies(rbusTestProvider rbus) target_link_libraries(rbusTestProvider rbus) +add_executable(multiRbusOpenProvider + multiRbusOpenProvider/multiRbusOpenProvider.c + common/runningParamHelper.c + common/testValueHelper.c) +add_dependencies(multiRbusOpenProvider rbus) +target_link_libraries(multiRbusOpenProvider rbus) + +add_executable(multiRbusOpenMethodProvider + multiRbusOpenMethodProvider/multiRbusOpenMethodProvider.c + common/runningParamHelper.c + common/testValueHelper.c) +add_dependencies(multiRbusOpenMethodProvider rbus) +target_link_libraries(multiRbusOpenMethodProvider rbus) + +add_executable(rbusOpenRegRbusOpenProvider + multiRbusOpenProvider/rbusOpenRegRbusOpenProvider.c + common/runningParamHelper.c + common/testValueHelper.c) +add_dependencies(rbusOpenRegRbusOpenProvider rbus) +target_link_libraries(rbusOpenRegRbusOpenProvider rbus) + +add_executable(multiRbusOpenRbusGetProvider + multiRbusOpenRbusGetProvider/multiRbusOpenRbusGetProvider.c + common/runningParamHelper.c + common/testValueHelper.c) +add_dependencies(multiRbusOpenRbusGetProvider rbus) +target_link_libraries(multiRbusOpenRbusGetProvider rbus) + +add_executable(multiProviderThreadsForSingleEvent + multiProviderThreadsForSingleEvent/multiProviderThreadsForSingleEvent.c) +add_dependencies(multiProviderThreadsForSingleEvent rbus) +target_link_libraries(multiProviderThreadsForSingleEvent rbus) + +add_executable(multiConsumerThreadsForSingleEvent + multiConsumerThreadsForSingleEvent/multiConsumerThreadsForSingleEvent.c) +add_dependencies(multiConsumerThreadsForSingleEvent rbus) +target_link_libraries(multiConsumerThreadsForSingleEvent rbus) + add_executable(rbusTestConsumer consumer/rbusTestConsumer.c consumer/elementTree.c @@ -48,9 +87,117 @@ add_executable(rbusTestConsumer common/testValueHelper.c) add_dependencies(rbusTestConsumer rbus) target_link_libraries(rbusTestConsumer rbus) + +add_executable(multiRbusOpenConsumer + multiRbusOpenConsumer/multiRbusOpenConsumer.c + consumer/elementTree.c + consumer/valueAPI.c + consumer/propertyAPI.c + consumer/objectAPI.c + consumer/value.c + consumer/valueChange.c + consumer/subscribe.c + consumer/subscribeEx.c + consumer/tables.c + consumer/events.c + consumer/methods.c + consumer/filter.c + consumer/partialPath.c + common/runningParamHelper.c + common/testValueHelper.c) +add_dependencies(multiRbusOpenConsumer rbus) +target_link_libraries(multiRbusOpenConsumer rbus) + +add_executable(multiRbusOpenMethodConsumer + multiRbusOpenMethodConsumer/multiRbusOpenMethodConsumer.c + consumer/elementTree.c + consumer/valueAPI.c + consumer/propertyAPI.c + consumer/objectAPI.c + consumer/value.c + consumer/valueChange.c + consumer/subscribe.c + consumer/subscribeEx.c + consumer/tables.c + consumer/events.c + consumer/methods.c + consumer/filter.c + consumer/partialPath.c + common/runningParamHelper.c + common/testValueHelper.c) +add_dependencies(multiRbusOpenMethodConsumer rbus) +target_link_libraries(multiRbusOpenMethodConsumer rbus) + +add_executable(rbusOpenSubRbusOpenConsumer + multiRbusOpenConsumer/rbusOpenSubRbusOpenConsumer.c + consumer/elementTree.c + consumer/valueAPI.c + consumer/propertyAPI.c + consumer/objectAPI.c + consumer/value.c + consumer/valueChange.c + consumer/subscribe.c + consumer/subscribeEx.c + consumer/tables.c + consumer/events.c + consumer/methods.c + consumer/filter.c + consumer/partialPath.c + common/runningParamHelper.c + common/testValueHelper.c) +add_dependencies(rbusOpenSubRbusOpenConsumer rbus) +target_link_libraries(rbusOpenSubRbusOpenConsumer rbus) + +add_executable(multiRbusOpenRbusGetConsumer + multiRbusOpenRbusGetConsumer/multiRbusOpenRbusGetConsumer.c + consumer/elementTree.c + consumer/valueAPI.c + consumer/propertyAPI.c + consumer/objectAPI.c + consumer/value.c + consumer/valueChange.c + consumer/subscribe.c + consumer/subscribeEx.c + consumer/tables.c + consumer/events.c + consumer/methods.c + consumer/filter.c + consumer/partialPath.c + common/runningParamHelper.c + common/testValueHelper.c) +add_dependencies(multiRbusOpenRbusGetConsumer rbus) +target_link_libraries(multiRbusOpenRbusGetConsumer rbus) + +add_executable(multiRbusOpenRbusSetConsumer + multiRbusOpenRbusSetConsumer/multiRbusOpenRbusSetConsumer.c + consumer/elementTree.c + consumer/valueAPI.c + consumer/propertyAPI.c + consumer/objectAPI.c + consumer/value.c + consumer/valueChange.c + consumer/subscribe.c + consumer/subscribeEx.c + consumer/tables.c + consumer/events.c + consumer/methods.c + consumer/filter.c + consumer/partialPath.c + common/runningParamHelper.c + common/testValueHelper.c) +add_dependencies(multiRbusOpenRbusSetConsumer rbus) +target_link_libraries(multiRbusOpenRbusSetConsumer rbus) + + set (CMAKE_C_FLAGS "-Wno-overflow ${CMAKE_C_FLAGS}") -install (TARGETS rbusTestProvider rbusTestConsumer +install (TARGETS + multiRbusOpenConsumer multiRbusOpenProvider + multiRbusOpenMethodProvider multiRbusOpenMethodConsumer + multiRbusOpenRbusGetProvider multiRbusOpenRbusGetConsumer multiRbusOpenRbusSetConsumer + multiProviderThreadsForSingleEvent multiConsumerThreadsForSingleEvent + rbusOpenRegRbusOpenProvider rbusOpenSubRbusOpenConsumer + rbusTestProvider rbusTestConsumer RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES rbus_test.sh diff --git a/sampleapps/consumer/rbusThreadConsumer.c b/test/rbus/multiConsumerThreadsForSingleEvent/multiConsumerThreadsForSingleEvent.c similarity index 100% rename from sampleapps/consumer/rbusThreadConsumer.c rename to test/rbus/multiConsumerThreadsForSingleEvent/multiConsumerThreadsForSingleEvent.c diff --git a/sampleapps/provider/rbusThreadProvider.c b/test/rbus/multiProviderThreadsForSingleEvent/multiProviderThreadsForSingleEvent.c similarity index 100% rename from sampleapps/provider/rbusThreadProvider.c rename to test/rbus/multiProviderThreadsForSingleEvent/multiProviderThreadsForSingleEvent.c diff --git a/test/rbus/multiRbusOpenConsumer/multiRbusOpenConsumer.c b/test/rbus/multiRbusOpenConsumer/multiRbusOpenConsumer.c new file mode 100644 index 00000000..da35a31f --- /dev/null +++ b/test/rbus/multiRbusOpenConsumer/multiRbusOpenConsumer.c @@ -0,0 +1,180 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file + * the following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int runtime = 60; + +static void eventReceiveHandler( + rbusHandle_t handle, + rbusEvent_t const* event, + rbusEventSubscription_t* subscription) +{ + (void)handle; + + rbusValue_t newValue = rbusObject_GetValue(event->data, "value"); + rbusValue_t oldValue = rbusObject_GetValue(event->data, "oldValue"); + rbusValue_t byValue = rbusObject_GetValue(event->data, "by"); + rbusValue_t filter = rbusObject_GetValue(event->data, "filter"); + + printf("Consumer receiver ValueChange event for param %s\n", event->name); + + if(newValue) + printf(" New Value: %d\n", rbusValue_GetInt32(newValue)); + + if(oldValue) + printf(" Old Value: %d\n", rbusValue_GetInt32(oldValue)); + + if(byValue) + printf(" By component: %s\n", rbusValue_GetString(byValue, NULL)); + + if(filter) + printf(" Filter: %d\n", rbusValue_GetBoolean(filter)); + + if(subscription->userData) + printf(" User data: %s\n", (char*)subscription->userData); +} + +int main(int argc, char *argv[]) +{ + (void)(argc); + (void)(argv); + + int rc1 = RBUS_ERROR_SUCCESS; + int rc2 = RBUS_ERROR_SUCCESS; + rbusHandle_t handle1; + rbusHandle_t handle2; + rbusFilter_t filter; + rbusValue_t filterValue; + rbusEventSubscription_t subscription = {"Device.Provider1.Param1", NULL, 0, 0, eventReceiveHandler, NULL, NULL, NULL, false}; + + rc1 = rbus_open(&handle1, "multiRbusOpenConsumer"); + if(rc1 != RBUS_ERROR_SUCCESS) + { + printf("consumer: rbus_open handle1 failed: %d\n", rc1); + goto exit1; + } + + rc2 = rbus_open(&handle2, "multiRbusOpenConsumer"); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("consumer: rbus_open handle2 failed: %d\n", rc2); + goto exit2; + } + + printf("handle1 and handle2 Subscribing to Device.Provider1.Param1\n"); + /* subscribe to all value change events on property "Device.Provider1.Param1" */ + rc1 = rbusEvent_Subscribe( + handle1, + "Device.Provider1.Param1", + eventReceiveHandler, + "My User Data", + 0); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("consumer: rbusEvent_Subscribe handle1 failed with err:%d\n", rc1); + } + + sleep(1); + rc2 = rbusEvent_Subscribe( + handle2, + "Device.Provider1.Param1", + eventReceiveHandler, + "My User Data", + 0); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("consumer: rbusEvent_Subscribe handle2 failed with err:%d\n", rc2); + } + + sleep(15); + + printf("Unsubscribing Device.Provider1.Param1 handles\n"); + + rc1 = rbusEvent_Unsubscribe( + handle1, + "Device.Provider1.Param1"); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("Unsubscribing handle1 err:%d\n", rc1); + } + + rc2 = rbusEvent_Unsubscribe( + handle2, + "Device.Provider1.Param1"); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("Unsubscribing handle2 failed :%d\n", rc2); + } + + /* subscribe using filter to value change events on property "Device.Provider1.Param1" + setting filter to: value >= 5. + */ + + rbusValue_Init(&filterValue); + rbusValue_SetInt32(filterValue, 5); + + rbusFilter_InitRelation(&filter, RBUS_FILTER_OPERATOR_GREATER_THAN, filterValue); + + subscription.filter = filter; + + printf("Subscribing to Device.Provider1.Param1 with filter > 5\n"); + + rc1 = rbusEvent_SubscribeEx(handle1, &subscription, 1, 0); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("subscribeEx handle1 err :%d\n", rc1); + } + + rc2 = rbusEvent_SubscribeEx(handle2, &subscription, 1, 0); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("subscribeEx handle2 failed :%d\n", rc2); + } + + rbusValue_Release(filterValue); + rbusFilter_Release(filter); + + sleep(25); + rc2 = rbus_close(handle2); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("consumer: rbus_close handle2 err: %d\n", rc2); + } + +exit2: + rc1 = rbus_close(handle1); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("consumer: rbus_close handle1 failed: %d\n", rc1); + } +exit1: + return rc2; +} + + diff --git a/test/rbus/multiRbusOpenConsumer/rbusOpenSubRbusOpenConsumer.c b/test/rbus/multiRbusOpenConsumer/rbusOpenSubRbusOpenConsumer.c new file mode 100644 index 00000000..3526bbf2 --- /dev/null +++ b/test/rbus/multiRbusOpenConsumer/rbusOpenSubRbusOpenConsumer.c @@ -0,0 +1,132 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file + * the following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int runtime = 60; + +char componentName[] = "RbusOpenRegRbusOpenConsumer"; + +static void eventReceiveHandler( + rbusHandle_t handle, + rbusEvent_t const* event, + rbusEventSubscription_t* subscription) +{ + (void)handle; + + rbusValue_t newValue = rbusObject_GetValue(event->data, "value"); + rbusValue_t oldValue = rbusObject_GetValue(event->data, "oldValue"); + rbusValue_t byValue = rbusObject_GetValue(event->data, "by"); + rbusValue_t filter = rbusObject_GetValue(event->data, "filter"); + + printf("Consumer receiver ValueChange event for param %s\n", event->name); + + if(newValue) + printf(" New Value: %d\n", rbusValue_GetInt32(newValue)); + + if(oldValue) + printf(" Old Value: %d\n", rbusValue_GetInt32(oldValue)); + + if(byValue) + printf(" By component: %s\n", rbusValue_GetString(byValue, NULL)); + + if(filter) + printf(" Filter: %d\n", rbusValue_GetBoolean(filter)); + + if(subscription->userData) + printf(" User data: %s\n", (char*)subscription->userData); +} + +int main(int argc, char *argv[]) +{ + (void)(argc); + (void)(argv); + + int rc = RBUS_ERROR_SUCCESS; + rbusHandle_t handle; + rbusFilter_t filter; + rbusValue_t filterValue; + rbusEventSubscription_t subscription = {"Device.Provider1.Param1", NULL, 0, 0, eventReceiveHandler, NULL, NULL, NULL, false}; + + rc = rbus_open(&handle, componentName); + if(rc != RBUS_ERROR_SUCCESS) + { + printf("consumer: rbus_open failed: %d\n", rc); + return -1; + } + + printf("Subscribing to Device.Provider1.Param1\n"); + /* subscribe to all value change events on property "Device.Provider1.Param1" */ + rc = rbusEvent_Subscribe( + handle, + "Device.Provider1.Param1", + eventReceiveHandler, + "My User Data", + 0); + + sleep(5); + rc = rbus_open(&handle, componentName); + if(rc != RBUS_ERROR_SUCCESS) + { + printf("consumer: rbus_open failed: %d\n", rc); + return -1; + } + + + sleep(15); + + printf("Unsubscribing Device.Provider1.Param1\n"); + + rbusEvent_Unsubscribe( + handle, + "Device.Provider1.Param1"); + + /* subscribe using filter to value change events on property "Device.Provider1.Param1" + setting filter to: value >= 5. + */ + + rbusValue_Init(&filterValue); + rbusValue_SetInt32(filterValue, 5); + + rbusFilter_InitRelation(&filter, RBUS_FILTER_OPERATOR_GREATER_THAN, filterValue); + + subscription.filter = filter; + + printf("Subscribing to Device.Provider1.Param1 with filter > 5\n"); + + rc = rbusEvent_SubscribeEx(handle, &subscription, 1, 0); + + rbusValue_Release(filterValue); + rbusFilter_Release(filter); + + sleep(25); + + return rc; +} + + diff --git a/test/rbus/multiRbusOpenMethodConsumer/multiRbusOpenMethodConsumer.c b/test/rbus/multiRbusOpenMethodConsumer/multiRbusOpenMethodConsumer.c new file mode 100644 index 00000000..f19c6071 --- /dev/null +++ b/test/rbus/multiRbusOpenMethodConsumer/multiRbusOpenMethodConsumer.c @@ -0,0 +1,225 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file + * the following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void asyncMethodHandler( + rbusHandle_t handle, + char const* methodName, + rbusError_t error, + rbusObject_t params) +{ + (void)handle; + + printf("asyncMethodHandler called: %s\n error=%d", methodName, error); + if(error == RBUS_ERROR_SUCCESS) + { + rbusObject_fwrite(params, 1, stdout); + } +} + +int main(int argc, char *argv[]) +{ + rbusHandle_t handle1; + rbusHandle_t handle2; + rbusObject_t inParams1; + rbusObject_t inParams2; + rbusObject_t outParams1; + rbusObject_t outParams2; + rbusValue_t value1; + rbusValue_t value2; + int rc1 = RBUS_ERROR_SUCCESS; + int rc2 = RBUS_ERROR_SUCCESS; + + (void)(argc); + (void)(argv); + + printf("multiRbusOpenMethodConsumer: start\n"); + + rc1 = rbus_open(&handle1, "multiRbusOpenMethodConsumer"); + if(rc1 != RBUS_ERROR_SUCCESS) + { + printf("multiRbusOpenMethodConsumer: First rbus_open for handle1 failed: %d\n", rc1); + goto exit1; + } + + rc2 = rbus_open(&handle2, "multiRbusOpenMethodConsumer"); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("multiRbusOpenMethodConsumer: Second rbus_open for handle2 failed: %d\n", rc2); + goto exit2; + } + + rbusObject_Init(&inParams1, NULL); + + rbusValue_Init(&value1); + rbusValue_SetString(value1, "param_value_1"); + rbusObject_SetValue(inParams1, "param1", value1); + rbusValue_Release(value1); + + rbusValue_Init(&value1); + rbusValue_SetInt32(value1, 2); + rbusObject_SetValue(inParams1, "param2", value1); + rbusValue_Release(value1); + + rbusObject_Init(&inParams2, NULL); + + rbusValue_Init(&value2); + rbusValue_SetString(value2, "param_value_2"); + rbusObject_SetValue(inParams2, "param3", value2); + rbusValue_Release(value2); + + rbusValue_Init(&value2); + rbusValue_SetInt32(value2, 2); + rbusObject_SetValue(inParams2, "param4", value2); + rbusValue_Release(value2); + + rc1 = rbusMethod_Invoke(handle1, "Device.Methods.SimpleMethod()", inParams1, &outParams1); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("multiRbusOpenMethodConsumer: rbusMethod_Invoke(Device.Methods.SimpleMethod()) using handle1 return err:%d\n", rc1); + } + rc2 = rbusMethod_Invoke(handle2, "Device.Methods.SimpleMethod()", inParams2, &outParams2); + if(rc1 != RBUS_ERROR_SUCCESS) + { + printf("multiRbusOpenMethodConsumer: rbusMethod_Invoke(Device.Methods.SimpleMethod()) using handle2 return err:%d\n", rc2); + } + + if(rc1 == RBUS_ERROR_SUCCESS) + { + rbusObject_fwrite(outParams1, 1, stdout); + rbusObject_Release(outParams1); + } + if(rc2 == RBUS_ERROR_SUCCESS) + { + rbusObject_fwrite(outParams2, 1, stdout); + rbusObject_Release(outParams2); + } + rbusObject_Release(inParams1); + rbusObject_Release(inParams2); + + /*Test to check the Outparams error msg handling + This testcase reads the provider specific error code and prints it. + This test is expected to return error */ + + printf("\n This is a negative test to check the error values generated by the Provider \n"); + rc1 = rbusMethod_Invoke(handle1, "Device.Methods.SimpleMethod1()", NULL, &outParams1); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("multiRbusOpenMethodConsumer: rbusMethod_Invoke(Device.Methods.SimpleMethod1()) using handle1 return err:%d\n", rc1); + } + + rc2 = rbusMethod_Invoke(handle2, "Device.Methods.SimpleMethod1()", NULL, &outParams2); + if(rc1 != RBUS_ERROR_SUCCESS) + { + printf("DEEPAK multiRbusOpenMethodConsumer: rbusMethod_Invoke(Device.Methods.SimpleMethod1()) using handle2 %s:%d\n", + rc2 == RBUS_ERROR_SUCCESS ? "success" : "fail",rc2); + } + printf("multiRbusOpenMethodConsumer: rbusMethod_Invoke(Device.Methods.SimpleMethod1()) using handle2 %s:%d\n", + rc2 == RBUS_ERROR_SUCCESS ? "success" : "fail",rc2); + + if(rc1 != RBUS_ERROR_SUCCESS) + { + rbusObject_fwrite(outParams1, 1, stdout); + rbusObject_Release(outParams1); + } + + if(rc2 != RBUS_ERROR_SUCCESS) + { + rbusObject_fwrite(outParams2, 1, stdout); + rbusObject_Release(outParams2); + } + + printf("\n\n"); + rbusObject_Init(&inParams1, NULL); + + rbusValue_Init(&value1); + rbusValue_SetBoolean(value1, true); + rbusObject_SetValue(inParams1, "enable", value1); + rbusValue_Release(value1); + + rbusValue_Init(&value1); + rbusValue_SetString(value1, "power on"); + rbusObject_SetValue(inParams1, "status", value1); + rbusValue_Release(value1); + + printf("\n\n"); + rbusObject_Init(&inParams2, NULL); + + rbusValue_Init(&value2); + rbusValue_SetBoolean(value2, true); + rbusObject_SetValue(inParams2, "enable", value2); + rbusValue_Release(value2); + + rbusValue_Init(&value2); + rbusValue_SetString(value2, "power on"); + rbusObject_SetValue(inParams2, "status", value2); + rbusValue_Release(value2); + + rc1 = rbusMethod_InvokeAsync(handle1, "Device.Methods.AsyncMethod()", inParams1, asyncMethodHandler, 0); + + + printf("multiRbusOpenMethodConsumer: rbusMethod_InvokeAsync(Device.Methods.AsyncMethod()) for handle1 %s with err :%d\n", rc1 == RBUS_ERROR_INVALID_HANDLE ? "success" : "fail",rc1); + + rc2 = rbusMethod_InvokeAsync(handle2, "Device.Methods.AsyncMethod()", inParams2, asyncMethodHandler, 0); + printf("multiRbusOpenMethodConsumer: rbusMethod_InvokeAsync(Device.Methods.AsyncMethod()) for handle2 %s:%d\n", + rc2 == RBUS_ERROR_SUCCESS ? "success" : "fail",rc2); + + + rc2 = rbusMethod_Invoke(handle2, "Device.Methods.AsyncMethod()", inParams2, &outParams2); + printf("multiRbusOpenMethodConsumer negative Test: rbusMethod_Invoke(Device.Methods.AsyncMethod()) using handle2 %s with return:%d\n", rc2 == RBUS_ERROR_SUCCESS ? "success" : "fail",rc2); + + if(rc2 == RBUS_ERROR_SUCCESS) + { + rbusObject_fwrite(outParams2, 1, stdout); + rbusObject_Release(outParams2); + } + + sleep(10); + + rc2 = rbus_close(handle2); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("multiRbusOpenMethodConsumer: rbus_close handle2 failed: %d\n", rc2); + } + +exit2: + rc1 = rbus_close(handle1); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("multiRbusOpenMethodConsumer: rbus_close handle1 err: %d\n", rc1); + } +exit1: + rbusObject_Release(inParams1); + rbusObject_Release(inParams2); + + printf("multiRbusOpenMethodConsumer: exit\n"); + return rc2; +} + + diff --git a/test/rbus/multiRbusOpenMethodProvider/multiRbusOpenMethodProvider.c b/test/rbus/multiRbusOpenMethodProvider/multiRbusOpenMethodProvider.c new file mode 100644 index 00000000..24a77597 --- /dev/null +++ b/test/rbus/multiRbusOpenMethodProvider/multiRbusOpenMethodProvider.c @@ -0,0 +1,215 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file + * the following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int loopFor = 40; +rbusHandle_t handle1; +rbusHandle_t handle2; + +typedef struct MethodData +{ + rbusMethodAsyncHandle_t asyncHandle; + rbusObject_t inParams; +}MethodData; + +static void* asyncMethodFunc(void *p) +{ + MethodData* data; + rbusObject_t outParams; + rbusValue_t value; + rbusError_t err; + + printf("%s enter\n", __FUNCTION__); + + sleep(20); + + data = p; + + rbusValue_Init(&value); + rbusValue_SetString(value, "Async Method Response"); + + rbusObject_Init(&outParams, NULL); + rbusObject_SetValue(outParams, "value", value); + rbusValue_Release(value); + + printf("%s sending response\n", __FUNCTION__); + err = rbusMethod_SendAsyncResponse(data->asyncHandle, RBUS_ERROR_SUCCESS, outParams); + if(err != RBUS_ERROR_SUCCESS) + { + printf("%s rbusMethod_SendAsyncResponse failed err:%d\n", __FUNCTION__, err); + } + + rbusObject_Release(data->inParams); + rbusObject_Release(outParams); + + free(data); + + printf("%s exit\n", __FUNCTION__); + + return NULL; +} + +static rbusError_t methodHandler(rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusObject_t outParams, rbusMethodAsyncHandle_t asyncHandle) +{ + (void)handle; + rbusValue_t value; + + printf("methodHandler called: %s\n", methodName); + rbusObject_fwrite(inParams, 1, stdout); + + if(strcmp(methodName, "Device.Methods.SimpleMethod()") == 0) + { + rbusValue_Init(&value); + rbusValue_SetString(value, "Simple Method Response"); + rbusObject_SetValue(outParams, "value", value); + rbusValue_Release(value); + + return RBUS_ERROR_SUCCESS; + } + else if(strcmp(methodName, "Device.Methods.SimpleMethod1()") == 0) + { + rbusValue_t value1,value2; + rbusValue_Init(&value1); + rbusValue_SetInt32(value1, 56789); + rbusObject_SetValue(outParams, "error_code", value1); + rbusValue_Release(value1); + + rbusValue_Init(&value2); + rbusValue_SetString(value2, "Provider Specific Error Code"); + rbusObject_SetValue(outParams, "error_string", value2); + rbusValue_Release(value2); + + return RBUS_ERROR_INVALID_METHOD; + + } + else if(strcmp(methodName, "Device.Methods.AsyncMethod()") == 0) + { + pthread_t pid; + MethodData* data = rt_malloc(sizeof(MethodData)); + data->asyncHandle = asyncHandle; + data->inParams = inParams; + + rbusObject_Retain(inParams); + + if(pthread_create(&pid, NULL, asyncMethodFunc, data) || pthread_detach(pid)) + { + printf("%s failed to spawn thread\n", __FUNCTION__); + return RBUS_ERROR_BUS_ERROR; + } + + return RBUS_ERROR_ASYNC_RESPONSE; + } + else + { + return RBUS_ERROR_BUS_ERROR; + } +} + + +int main(int argc, char *argv[]) +{ + (void)(argc); + (void)(argv); + + int rc1 = RBUS_ERROR_SUCCESS; + int rc2 = RBUS_ERROR_SUCCESS; + + char componentName[] = "multiRbusOpenMethodProvider"; + + rbusDataElement_t dataElements[3] = { + {"Device.Methods.SimpleMethod()", RBUS_ELEMENT_TYPE_METHOD, {NULL, NULL, NULL, NULL, NULL, methodHandler}}, + {"Device.Methods.SimpleMethod1()", RBUS_ELEMENT_TYPE_METHOD, {NULL, NULL, NULL, NULL, NULL, methodHandler}}, + {"Device.Methods.AsyncMethod()", RBUS_ELEMENT_TYPE_METHOD, {NULL, NULL, NULL, NULL, NULL, methodHandler}} + }; + + printf("multiRbusOpenMethodProvider: start\n"); + + rc1 = rbus_open(&handle1, componentName); + if(rc1 != RBUS_ERROR_SUCCESS) + { + printf("provider: First rbus_open of handle1 err: %d\n", rc1); + goto exit2; + } + + rc2 = rbus_open(&handle2, componentName); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("provider: Second rbus_open of handle2 err: %d\n", rc2); + goto exit1; + } + + rc1 = rbus_regDataElements(handle1, 3, dataElements); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("provider: rbus_regDataElements handle1 err: %d\n", rc1); + } + + rc2 = rbus_regDataElements(handle2, 3, dataElements); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("provider: rbus_regDataElements handle2 err: %d\n", rc2); + } + + + while (loopFor != 0) + { + printf("provider: exiting in %d seconds\n", loopFor); + sleep(1); + loopFor--; + } + + rc1 = rbus_unregDataElements(handle1, 3, dataElements); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("provider: rbus_unregDataElements handle1 err: %d\n", rc1); + } + + rc2 = rbus_unregDataElements(handle2, 3, dataElements); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("provider: rbus_unregDataElements handle2 err: %d\n", rc2); + } + + rc2 = rbus_close(handle2); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("provider: rbus_close handle2 err: %d\n", rc2); + } +exit1: + rc1 = rbus_close(handle1); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("provider: rbus_close handle1 err: %d\n", rc1); + } + +exit2: + printf("multiRbusOpenMethodProvider: exit\n"); + return rc2; +} diff --git a/test/rbus/multiRbusOpenProvider/multiRbusOpenProvider.c b/test/rbus/multiRbusOpenProvider/multiRbusOpenProvider.c new file mode 100644 index 00000000..0b6c51db --- /dev/null +++ b/test/rbus/multiRbusOpenProvider/multiRbusOpenProvider.c @@ -0,0 +1,158 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file + * the following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//TODO handle filter matching + +int runtime = 70; + +rbusError_t eventSubHandler(rbusHandle_t handle, rbusEventSubAction_t action, const char* eventName, rbusFilter_t filter, int32_t interval, bool* autoPublish) + { + (void)handle; + (void)filter; + (void)interval; + + printf( + "eventSubHandler called:\n" \ + "\taction=%s\n" \ + "\teventName=%s\n", + action == RBUS_EVENT_ACTION_SUBSCRIBE ? "subscribe" : "unsubscribe", + eventName); + + *autoPublish = true; + return RBUS_ERROR_SUCCESS; + } + +rbusError_t getHandler(rbusHandle_t handle, rbusProperty_t property, rbusGetHandlerOptions_t* opts) +{ + char const* name = rbusProperty_GetName(property); + (void)handle; + (void)opts; + + /*fake a value change every 'myfreq' times this function is called*/ + static int32_t mydata = 0; /*the actual value to send back*/ + static int32_t mydelta = 1; /*how much to change the value by*/ + static int32_t mycount = 0; /*number of times this function called*/ + static int32_t myfreq = 2; /*number of times this function called before changing value*/ + static int32_t mymin = 0, mymax=7; /*keep value between mymin and mymax*/ + + rbusValue_t value; + + mycount++; + + if((mycount % myfreq) == 0) + { + mydata += mydelta; + if(mydata == mymax) + mydelta = -1; + else if(mydata == mymin) + mydelta = 1; + } + + printf("Called get handler for [%s] val=[%d]\n", name, mydata); + + rbusValue_Init(&value); + rbusValue_SetInt32(value, mydata); + rbusProperty_SetValue(property, value); + rbusValue_Release(value); + + return RBUS_ERROR_SUCCESS; +} + +int main(int argc, char *argv[]) +{ + (void)(argc); + (void)(argv); + + rbusHandle_t handle1 = NULL; + rbusHandle_t handle2 = NULL; + int rc1 = RBUS_ERROR_SUCCESS; + int rc2 = RBUS_ERROR_SUCCESS; + + char componentName[] = "multiRbusOpenProvider"; + + rbusDataElement_t dataElements[1] = {{"Device.Provider1.Param1", RBUS_ELEMENT_TYPE_PROPERTY, {getHandler, NULL, NULL, NULL, eventSubHandler, NULL}}}; + + printf("provider: start\n"); + rc1 = rbus_open(&handle1, componentName); + if(rc1 != RBUS_ERROR_SUCCESS) + { + printf("provider: First rbus_open handle1 err: %d\n", rc1); + goto exit1; + } + + printf("provider0: handle1:%p: %d\n", (void*)handle1,rc1); + rc2 = rbus_open(&handle2, componentName); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("provider: Second rbus_open handle2 err: %d\n", rc2); + goto exit2; + } + + printf("provider1: handle1:%p: %d\n", (void*)handle1,rc1); + rc1 = rbus_regDataElements(handle1, 1, dataElements); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("provider: rbus_regDataElements handle1 err: %d\n", rc1); + } + rc2 = rbus_regDataElements(handle2, 1, dataElements); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("provider: rbus_regDataElements handle2 err: %d\n", rc2); + } + + sleep(runtime); + + rc1 = rbus_unregDataElements(handle1, 1, dataElements); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("provider: rbus_unregDataElements handle1 err: %d\n", rc1); + } + + rc2 = rbus_unregDataElements(handle2, 1, dataElements); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("provider: rbus_unregDataElements handle2 err: %d\n", rc2); + } + + rc2 = rbus_close(handle2); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("provider: rbus_close handle2 err: %d\n", rc2); + } +exit2: + rc1 = rbus_close(handle1); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("provider: rbus_close handle1 err: %d\n", rc1); + } +exit1: + printf("provider: exit with :%d and %d\n",rc1,rc2); + return rc2; +} diff --git a/test/rbus/multiRbusOpenProvider/rbusOpenRegRbusOpenProvider.c b/test/rbus/multiRbusOpenProvider/rbusOpenRegRbusOpenProvider.c new file mode 100644 index 00000000..66dfed14 --- /dev/null +++ b/test/rbus/multiRbusOpenProvider/rbusOpenRegRbusOpenProvider.c @@ -0,0 +1,125 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file + * the following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//TODO handle filter matching + +int runtime = 70; + +rbusError_t eventSubHandler(rbusHandle_t handle, rbusEventSubAction_t action, const char* eventName, rbusFilter_t filter, int32_t interval, bool* autoPublish) + { + (void)handle; + (void)filter; + (void)interval; + + printf( + "eventSubHandler called:\n" \ + "\taction=%s\n" \ + "\teventName=%s\n", + action == RBUS_EVENT_ACTION_SUBSCRIBE ? "subscribe" : "unsubscribe", + eventName); + + *autoPublish = true; + return RBUS_ERROR_SUCCESS; + } + +rbusError_t getHandler(rbusHandle_t handle, rbusProperty_t property, rbusGetHandlerOptions_t* opts) +{ + char const* name = rbusProperty_GetName(property); + (void)handle; + (void)opts; + + /*fake a value change every 'myfreq' times this function is called*/ + static int32_t mydata = 0; /*the actual value to send back*/ + static int32_t mydelta = 1; /*how much to change the value by*/ + static int32_t mycount = 0; /*number of times this function called*/ + static int32_t myfreq = 2; /*number of times this function called before changing value*/ + static int32_t mymin = 0, mymax=7; /*keep value between mymin and mymax*/ + + rbusValue_t value; + + mycount++; + + if((mycount % myfreq) == 0) + { + mydata += mydelta; + if(mydata == mymax) + mydelta = -1; + else if(mydata == mymin) + mydelta = 1; + } + + printf("Called get handler for [%s] val=[%d]\n", name, mydata); + + rbusValue_Init(&value); + rbusValue_SetInt32(value, mydata); + rbusProperty_SetValue(property, value); + rbusValue_Release(value); + + return RBUS_ERROR_SUCCESS; +} + +int main(int argc, char *argv[]) +{ + (void)(argc); + (void)(argv); + + rbusHandle_t handle; + int rc = RBUS_ERROR_SUCCESS; + + char componentName[] = "RbusOpenRegRbusOpenProvider"; + + rbusDataElement_t dataElements[1] = {{"Device.Provider1.Param1", RBUS_ELEMENT_TYPE_PROPERTY, {getHandler, NULL, NULL, NULL, eventSubHandler, NULL}}}; + + printf("provider: start\n"); + + rc = rbus_open(&handle, componentName); + if(rc != RBUS_ERROR_SUCCESS) + { + printf("provider: rbus_open failed: %d\n", rc); + goto exit2; + } + + rc = rbus_regDataElements(handle, 1, dataElements); + if(rc != RBUS_ERROR_SUCCESS) + { + printf("provider: rbus_regDataElements failed: %d\n", rc); + goto exit2; + } + + sleep(5); + rc = rbus_open(&handle, componentName); + sleep(runtime); + + rbus_unregDataElements(handle, 1, dataElements); + +exit2: + printf("provider: exit\n"); + return rc; +} diff --git a/test/rbus/multiRbusOpenRbusGetConsumer/multiRbusOpenRbusGetConsumer.c b/test/rbus/multiRbusOpenRbusGetConsumer/multiRbusOpenRbusGetConsumer.c new file mode 100644 index 00000000..7ae71c3f --- /dev/null +++ b/test/rbus/multiRbusOpenRbusGetConsumer/multiRbusOpenRbusGetConsumer.c @@ -0,0 +1,106 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file + * the following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + rbusHandle_t handle1; + rbusHandle_t handle2; + int rc1 = RBUS_ERROR_SUCCESS; + int rc2 = RBUS_ERROR_SUCCESS; + + (void)(argc); + (void)(argv); + + printf("constumer: start\n"); + + rc1 = rbus_open(&handle1, "multiRbusOpenRbusGetConsumer"); + if(rc1 != RBUS_ERROR_SUCCESS) + { + printf("consumer: First rbus_open for handle1 err: %d\n", rc1); + goto exit1; + } + + rc2 = rbus_open(&handle2, "multiRbusOpenRbusGetConsumer"); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("consumer: Second rbus_open for handle2 err: %d\n", rc2); + goto exit2; + } + + rbusValue_t value; + TestValueProperty data = { RBUS_INT32, "Device.multiRbusOpenGetTestProvider.Value.RBUS_INT32", {NULL} }; + + printf("#################### getINT32Value ######################\n"); + + printf("_test_multiRbusOpen rbus_get %s\n", data.name); + + rc1 = rbus_get(handle1, data.name, &value); + + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("_test_Value rbus_get failed err:%d\n", rc1); + } + + rc2 = rbus_get(handle2, data.name, &value); + + if(rc2 == RBUS_ERROR_SUCCESS) + { + printf(">>>>>>>>>>>>>>>>>>>>>>>>rbus_get handle2 test success %s >>>>>>>>>>>>>>>>>>>>>>>>>\n", data.name); + rbusValue_Release(value); + } + else + { + printf("_test_Value rbus_get failed err:%d\n", rc2); + } + + printf("consumer: multiRbusOpenRbusGetConsumer %s with handle2\n", + rc2 == RBUS_ERROR_SUCCESS ? "success" : "fail"); + + sleep(5); + + rc2 = rbus_close(handle2); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("consumer: rbus_close handle2 err: %d\n", rc2); + } + +exit2: + rc1 = rbus_close(handle1); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("consumer: rbus_close handle1 err: %d\n", rc1); + } +exit1: + printf("consumer: exit\n"); + return rc2; +} + + diff --git a/test/rbus/multiRbusOpenRbusGetProvider/multiRbusOpenRbusGetProvider.c b/test/rbus/multiRbusOpenRbusGetProvider/multiRbusOpenRbusGetProvider.c new file mode 100644 index 00000000..7a1af668 --- /dev/null +++ b/test/rbus/multiRbusOpenRbusGetProvider/multiRbusOpenRbusGetProvider.c @@ -0,0 +1,177 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file + * the following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int loopFor = 30; +rbusHandle_t handle1; +rbusHandle_t handle2; + +typedef struct MethodData +{ + rbusMethodAsyncHandle_t asyncHandle; + rbusObject_t inParams; +}MethodData; + +rbusError_t multiRbusProvider_SampleDataGetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHandlerOptions_t* opts); +rbusError_t multiRbusProvider_SampleDataSetHandler(rbusHandle_t handle, rbusProperty_t property, rbusSetHandlerOptions_t* opts); + +int main(int argc, char *argv[]) +{ + (void)(argc); + (void)(argv); + + int rc1 = RBUS_ERROR_SUCCESS; + int rc2 = RBUS_ERROR_SUCCESS; + + char componentName[] = "multiRbusOpenRbusGetProvider"; + + rbusDataElement_t dataElements = {"Device.multiRbusOpenGetTestProvider.Value.RBUS_INT32", RBUS_ELEMENT_TYPE_PROPERTY, {multiRbusProvider_SampleDataGetHandler, multiRbusProvider_SampleDataSetHandler, NULL, NULL, NULL, NULL}}; + + printf("provider: start\n"); + + rc1 = rbus_open(&handle1, componentName); + if(rc1 != RBUS_ERROR_SUCCESS) + { + printf("provider: First rbus_open for handle1 err: %d\n", rc1); + goto exit1; + } + + rc2 = rbus_open(&handle2, componentName); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("provider: Second rbus_open for handle2 err: %d\n", rc2); + goto exit2; + } + + rc1 = rbus_regDataElements(handle1, 1, &dataElements); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("provider: rbus_regDataElements for handle1 err: %d\n", rc1); + } + + rc2 = rbus_regDataElements(handle2, 1, &dataElements); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("provider: rbus_regDataElements for handle2 err: %d\n", rc2); + } + + + while (loopFor != 0) + { + printf("provider: exiting in %d seconds\n", loopFor); + sleep(1); + loopFor--; + } + + rc1 = rbus_unregDataElements(handle1, 1, &dataElements); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("provider: rbus_unregDataElements for handle1 err: %d\n", rc1); + } + rc2 = rbus_unregDataElements(handle2, 1, &dataElements); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("provider: rbus_unregDataElements for handle2 err: %d\n", rc2); + } + + rc2 = rbus_close(handle2); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("consumer: rbus_close handle2 err: %d\n", rc2); + } + +exit2: + rc1 = rbus_close(handle1); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("consumer: rbus_close handle1 err: %d\n", rc1); + } +exit1: + printf("provider: exit\n"); + return rc2; +} + + +rbusError_t multiRbusProvider_SampleDataSetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusSetHandlerOptions_t* opts) +{ + (void)handle; + (void)opts; + + char const* name = rbusProperty_GetName(prop); + rbusValue_t value = rbusProperty_GetValue(prop); + rbusValueType_t type = rbusValue_GetType(value); + + if(strcmp(name, "Device.multiRbusOpenGetTestProvider.Value.RBUS_INT32") == 0) + { + if (type != RBUS_INT32) + { + printf("%s Called Set handler with wrong data type\n", name); + return RBUS_ERROR_INVALID_INPUT; + } + else + { + rbusProperty_SetValue(prop, value); + //printf("%s Called Set handler with value = %d\n", name, rbusValue_GetInt32(value)); + } + } + + return RBUS_ERROR_SUCCESS; +} + + +rbusError_t multiRbusProvider_SampleDataGetHandler(rbusHandle_t handle, rbusProperty_t property, rbusGetHandlerOptions_t* opts) +{ + (void)handle; + (void)opts; + rbusValue_t value; + int intData = 0; + char const* name; + + rbusValue_Init(&value); + name = rbusProperty_GetName(property); + + if(strcmp(name, "Device.multiRbusOpenGetTestProvider.Value.RBUS_INT32") == 0) + { + intData += 101; + printf("Called get handler for [%s] & value is %d\n", name, intData); + rbusValue_SetInt32(value, intData); + } + else + { + printf("Cant Handle [%s]\n", name); + return RBUS_ERROR_INVALID_INPUT; + } + + rbusProperty_SetValue(property, value); + rbusValue_Release(value); + + return RBUS_ERROR_SUCCESS; +} + diff --git a/test/rbus/multiRbusOpenRbusSetConsumer/multiRbusOpenRbusSetConsumer.c b/test/rbus/multiRbusOpenRbusSetConsumer/multiRbusOpenRbusSetConsumer.c new file mode 100644 index 00000000..04b4b5fb --- /dev/null +++ b/test/rbus/multiRbusOpenRbusSetConsumer/multiRbusOpenRbusSetConsumer.c @@ -0,0 +1,106 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file + * the following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + rbusHandle_t handle1; + rbusHandle_t handle2; + int rc1 = RBUS_ERROR_SUCCESS; + int rc2 = RBUS_ERROR_SUCCESS; + + (void)(argc); + (void)(argv); + + printf("constumer: start\n"); + + rc1 = rbus_open(&handle1, "multiRbusOpenRbusSetConsumer"); + if(rc1 != RBUS_ERROR_SUCCESS) + { + printf("consumer: First rbus_open with handle1 err: %d\n", rc1); + goto exit1; + } + + rc2 = rbus_open(&handle2, "multiRbusOpenRbusSetConsumer"); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("consumer: Second rbus_open with handle2 err: %d\n", rc2); + goto exit2; + } + + TestValueProperty data = { RBUS_INT32, "Device.multiRbusOpenGetTestProvider.Value.RBUS_INT32", {NULL} }; + rbusValue_t value; + rbusValue_Init(&value); + char *endptr = NULL; + int32_t tmpI32 = strtol ("99", &endptr, 10); + rbusValue_SetInt32(value, tmpI32); + printf("#################### setINT32Value ######################\n"); + + printf("_test_multiRbusOpen rbus_set %s\n", data.name); + + rc1 = rbus_set(handle1, data.name, value, NULL); + + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("_test_Value rbus_set err:%d\n", rc1); + } + sleep(1); + + rc2 = rbus_set(handle2, data.name, value, NULL); + + if(rc2 == RBUS_ERROR_SUCCESS) + { + printf(">>>>>>>>>>>>>>>>>>>>>>>> test rbus set with handle2 success %s >>>>>>>>>>>>>>>>>>>>>>>>>\n", data.name); + } + else + { + printf("_test_Value rbus_set with handle2 err:%d\n", rc2); + } + + sleep(10); + rc2 = rbus_close(handle2); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("consumer: rbus_close handle2 err: %d\n", rc2); + } + +exit2: + rc1 = rbus_close(handle1); + if(rc1 != RBUS_ERROR_INVALID_HANDLE) + { + printf("consumer: rbus_close handle1 err: %d\n", rc1); + } +exit1: + rbusValue_Release(value); + printf("consumer: exit\n"); + return rc2; +} + + diff --git a/test/rbus/rbus_test.sh b/test/rbus/rbus_test.sh index f6b7d371..716588a7 100644 --- a/test/rbus/rbus_test.sh +++ b/test/rbus/rbus_test.sh @@ -32,6 +32,58 @@ echo "test will complete in about $duration seconds" wait +logmultiRbusOpenMethodProvider=/tmp/log.multiRbusOpenMethodProvider +logmultiRbusOpenMethodConsumer=/tmp/log.multiRbusOpenMethodConsumer + +echo "Multi RbusOpen with Method Invoke test will complete in about 90 seconds" + +./multiRbusOpenMethodProvider > $logmultiRbusOpenMethodProvider 2>&1 & +./multiRbusOpenMethodConsumer > $logmultiRbusOpenMethodConsumer 2>&1 & + +#wait + +logRbusOpenProvider=/tmp/log.multiRbusOpenprovider +logRbusOpenConsumer=/tmp/log.multiRbusOpenconsumer + +echo "Multi RbusOpen with Register and subscribe test will complete in about 80 seconds" +./multiRbusOpenProvider > $logRbusOpenProvider & +./multiRbusOpenConsumer > $logRbusOpenConsumer & + +wait + +logRbusOpenRegRbusOpenProvider=/tmp/log.rbusOpenRegRbusOpenProvider +logRbusOpenSubRbusOpenConsumer=/tmp/log.rbusOpenSubRbusOpenConsumer + +echo "Multi Rbus Open Register and Subscribe Negative test will complete in about 75 seconds" +./rbusOpenRegRbusOpenProvider > $logRbusOpenRegRbusOpenProvider 2>&1 & +./rbusOpenSubRbusOpenConsumer > $logRbusOpenSubRbusOpenConsumer 2>&1 & + +wait + +logmultiRbusOpenRbusGetProvider=/tmp/log.multiRbusOpenRbusGetProvider +logmultiRbusOpenRbusGetConsumer=/tmp/log.multiRbusOpenRbusGetConsumer + +echo "multi rbus open register and subscribe negative test will complete in about 30 seconds" +./multiRbusOpenRbusGetProvider > $logmultiRbusOpenRbusGetProvider 2>&1 & +./multiRbusOpenRbusGetConsumer > $logmultiRbusOpenRbusGetConsumer 2>&1 & + +wait + +logmultiRbusOpenRbusSetProvider=/tmp/log.multiRbusOpenRbusSetProvider +logmultiRbusOpenRbusSetConsumer=/tmp/log.multiRbusOpenRbusSetConsumer + +echo "multi rbus open register and subscribe negative test will complete in about 30 seconds" +./multiRbusOpenRbusGetProvider > $logmultiRbusOpenRbusSetProvider 2>&1 & +./multiRbusOpenRbusSetConsumer > $logmultiRbusOpenRbusSetConsumer 2>&1 & + +#wait + +#logMultiProviderThreadsForSingleEvent=/tmp/log.multiProviderThreadsForSingleEvent +#logMultiConsumerThreadsForSingleEvent=/tmp/log.multiConsumerThreadsForSingleEvent + +#echo "multiProvider and multiConsumer Threads For a SingleEvent long duration" +#./multiProviderThreadsForSingleEvent > logMultiProviderThreadsForSingleEvent & +#./multiConsumerThreadsForSingleEvent > logMultiConsumerThreadsForSingleEvent & #result=`diff -rupN <(grep _test_ $logConsumer) <(echo "$expected_results")` #if [ -n "$result" ]; then # echo "The following tests failed:" @@ -39,7 +91,6 @@ wait #else # echo "All tests passed" #fi - echo "Done."