From aa807acaab17458b728185ceb8c40217d49c84da Mon Sep 17 00:00:00 2001 From: Deepak_m Date: Tue, 7 Nov 2023 18:53:38 +0530 Subject: [PATCH] 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 --- src/rbus/rbus.c | 22 +++ src/rbus/rbus_handle.c | 23 +++ src/rbus/rbus_handle.h | 1 + .../multiRbusOpenConsumer.c | 90 +++++++-- .../multiRbusOpenMethodConsumer.c | 184 +++++++++++++----- .../multiRbusOpenMethodProvider.c | 69 +++++-- .../multiRbusOpenProvider.c | 60 ++++-- .../multiRbusOpenRbusGetConsumer.c | 53 +++-- .../multiRbusOpenRbusGetProvider.c | 60 ++++-- .../multiRbusOpenRbusSetConsumer.c | 59 ++++-- test/rbus/rbus_test.sh | 41 ++-- 11 files changed, 513 insertions(+), 149 deletions(-) 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/multiRbusOpenConsumer/multiRbusOpenConsumer.c b/test/rbus/multiRbusOpenConsumer/multiRbusOpenConsumer.c index 5904c4cb..da35a31f 100644 --- a/test/rbus/multiRbusOpenConsumer/multiRbusOpenConsumer.c +++ b/test/rbus/multiRbusOpenConsumer/multiRbusOpenConsumer.c @@ -65,36 +65,72 @@ int main(int argc, char *argv[]) (void)(argc); (void)(argv); - int rc = RBUS_ERROR_SUCCESS; - rbusHandle_t handle; + 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}; - rc = rbus_open(&handle, "multiRbusOpenConsumer"); - rc = rbus_open(&handle, "multiRbusOpenConsumer"); - if(rc != RBUS_ERROR_SUCCESS) + rc1 = rbus_open(&handle1, "multiRbusOpenConsumer"); + if(rc1 != RBUS_ERROR_SUCCESS) { - printf("consumer: rbus_open failed: %d\n", rc); - return -1; + printf("consumer: rbus_open handle1 failed: %d\n", rc1); + goto exit1; } - printf("Subscribing to Device.Provider1.Param1\n"); + 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" */ - rc = rbusEvent_Subscribe( - handle, + 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\n"); + printf("Unsubscribing Device.Provider1.Param1 handles\n"); - rbusEvent_Unsubscribe( - handle, - "Device.Provider1.Param1"); + 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. @@ -109,14 +145,36 @@ int main(int argc, char *argv[]) printf("Subscribing to Device.Provider1.Param1 with filter > 5\n"); - rc = rbusEvent_SubscribeEx(handle, &subscription, 1, 0); + 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); + } - return rc; +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/multiRbusOpenMethodConsumer/multiRbusOpenMethodConsumer.c b/test/rbus/multiRbusOpenMethodConsumer/multiRbusOpenMethodConsumer.c index 4d632afc..c0274ff7 100644 --- a/test/rbus/multiRbusOpenMethodConsumer/multiRbusOpenMethodConsumer.c +++ b/test/rbus/multiRbusOpenMethodConsumer/multiRbusOpenMethodConsumer.c @@ -45,48 +45,82 @@ static void asyncMethodHandler( int main(int argc, char *argv[]) { - rbusHandle_t handle; - rbusObject_t inParams; - rbusObject_t outParams; - rbusValue_t value; - int rc = RBUS_ERROR_SUCCESS; + 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("constumer: start\n"); + printf("multiRbusOpenMethodConsumer: start\n"); - rc = rbus_open(&handle, "multiRbusOpenMethodConsumer"); - rc = rbus_open(&handle, "multiRbusOpenMethodConsumer"); - if(rc != RBUS_ERROR_SUCCESS) + rc1 = rbus_open(&handle1, "multiRbusOpenMethodConsumer"); + if(rc1 != RBUS_ERROR_SUCCESS) { - printf("consumer: rbus_open failed: %d\n", rc); + printf("multiRbusOpenMethodConsumer: First rbus_open for handle1 failed: %d\n", rc1); goto exit1; } - rbusObject_Init(&inParams, NULL); + rc2 = rbus_open(&handle2, "multiRbusOpenMethodConsumer"); + if(rc2 != RBUS_ERROR_SUCCESS) + { + printf("multiRbusOpenMethodConsumer: Second rbus_open for handle2 failed: %d\n", rc2); + goto exit2; + } - rbusValue_Init(&value); - rbusValue_SetString(value, "param_value_1"); - rbusObject_SetValue(inParams, "param1", value); - rbusValue_Release(value); + rbusObject_Init(&inParams1, NULL); - rbusValue_Init(&value); - rbusValue_SetInt32(value, 2); - rbusObject_SetValue(inParams, "param2", value); - rbusValue_Release(value); + rbusValue_Init(&value1); + rbusValue_SetString(value1, "param_value_1"); + rbusObject_SetValue(inParams1, "param1", value1); + rbusValue_Release(value1); - rc = rbusMethod_Invoke(handle, "Device.Methods.SimpleMethod()", inParams, &outParams); + rbusValue_Init(&value1); + rbusValue_SetInt32(value1, 2); + rbusObject_SetValue(inParams1, "param2", value1); + rbusValue_Release(value1); - rbusObject_Release(inParams); + rbusObject_Init(&inParams2, NULL); - printf("consumer: rbusMethod_Invoke(Device.Methods.SimpleMethod()) %s\n", - rc == RBUS_ERROR_SUCCESS ? "success" : "fail"); + rbusValue_Init(&value2); + rbusValue_SetString(value2, "param_value_2"); + rbusObject_SetValue(inParams2, "param3", value2); + rbusValue_Release(value2); - if(rc == RBUS_ERROR_SUCCESS) + 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) { - rbusObject_fwrite(outParams, 1, stdout); - rbusObject_Release(outParams); + printf("multiRbusOpenMethodConsumer: rbusMethod_Invoke(Device.Methods.SimpleMethod()) using handle2 return err:%d\n", rc2); + } + rbusObject_Release(inParams1); + rbusObject_Release(inParams2); + + 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); } /*Test to check the Outparams error msg handling @@ -94,44 +128,98 @@ int main(int argc, char *argv[]) This test is expected to return error */ printf("\n This is a negative test to check the error values generated by the Provider \n"); - rc = rbusMethod_Invoke(handle, "Device.Methods.SimpleMethod1()", NULL, &outParams); + 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); + } - printf("consumer: rbusMethod_Invoke(Device.Methods.SimpleMethod1()) %s\n", - rc == RBUS_ERROR_SUCCESS ? "success" : "fail"); + 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(rc != RBUS_ERROR_SUCCESS) + if(rc1 != RBUS_ERROR_SUCCESS) { - rbusObject_fwrite(outParams, 1, stdout); - rbusObject_Release(outParams); + 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(&inParams, NULL); + 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); - rbusValue_Init(&value); - rbusValue_SetBoolean(value, true); - rbusObject_SetValue(inParams, "enable", value); - rbusValue_Release(value); + rc1 = rbusMethod_InvokeAsync(handle1, "Device.Methods.AsyncMethod()", inParams1, asyncMethodHandler, 0); - rbusValue_Init(&value); - rbusValue_SetString(value, "power on"); - rbusObject_SetValue(inParams, "status", value); - rbusValue_Release(value); + rbusObject_Release(inParams1); - rc = rbusMethod_InvokeAsync(handle, "Device.Methods.AsyncMethod()", inParams, 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); - rbusObject_Release(inParams); - printf("consumer: rbusMethod_Invoke(Device.Methods.AsyncMethod()) %s\n", - rc == RBUS_ERROR_SUCCESS ? "success" : "fail"); + 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); + } + rbusObject_Release(inParams2); - sleep(5); + 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: - printf("consumer: exit\n"); - return rc; + + printf("multiRbusOpenMethodConsumer: exit\n"); + return rc2; } diff --git a/test/rbus/multiRbusOpenMethodProvider/multiRbusOpenMethodProvider.c b/test/rbus/multiRbusOpenMethodProvider/multiRbusOpenMethodProvider.c index 93e59df0..24a77597 100644 --- a/test/rbus/multiRbusOpenMethodProvider/multiRbusOpenMethodProvider.c +++ b/test/rbus/multiRbusOpenMethodProvider/multiRbusOpenMethodProvider.c @@ -29,8 +29,9 @@ #include #include -int loopFor = 10; -rbusHandle_t handle; +int loopFor = 40; +rbusHandle_t handle1; +rbusHandle_t handle2; typedef struct MethodData { @@ -47,7 +48,7 @@ static void* asyncMethodFunc(void *p) printf("%s enter\n", __FUNCTION__); - sleep(3); + sleep(20); data = p; @@ -137,7 +138,8 @@ int main(int argc, char *argv[]) (void)(argc); (void)(argv); - int rc = RBUS_ERROR_SUCCESS; + int rc1 = RBUS_ERROR_SUCCESS; + int rc2 = RBUS_ERROR_SUCCESS; char componentName[] = "multiRbusOpenMethodProvider"; @@ -147,23 +149,35 @@ int main(int argc, char *argv[]) {"Device.Methods.AsyncMethod()", RBUS_ELEMENT_TYPE_METHOD, {NULL, NULL, NULL, NULL, NULL, methodHandler}} }; - printf("provider: start\n"); + printf("multiRbusOpenMethodProvider: start\n"); - rc = rbus_open(&handle, componentName); - rc = rbus_open(&handle, componentName); - if(rc != RBUS_ERROR_SUCCESS) + rc1 = rbus_open(&handle1, componentName); + if(rc1 != RBUS_ERROR_SUCCESS) { - printf("provider: rbus_open failed: %d\n", rc); + printf("provider: First rbus_open of handle1 err: %d\n", rc1); goto exit2; } - rc = rbus_regDataElements(handle, 3, dataElements); - if(rc != RBUS_ERROR_SUCCESS) + rc2 = rbus_open(&handle2, componentName); + if(rc2 != RBUS_ERROR_SUCCESS) { - printf("provider: rbus_regDataElements failed: %d\n", rc); - goto exit2; + 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); @@ -171,8 +185,31 @@ int main(int argc, char *argv[]) loopFor--; } - rbus_unregDataElements(handle, 3, dataElements); + 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("provider: exit\n"); - return rc; + printf("multiRbusOpenMethodProvider: exit\n"); + return rc2; } diff --git a/test/rbus/multiRbusOpenProvider/multiRbusOpenProvider.c b/test/rbus/multiRbusOpenProvider/multiRbusOpenProvider.c index fc6b2ffb..0b6c51db 100644 --- a/test/rbus/multiRbusOpenProvider/multiRbusOpenProvider.c +++ b/test/rbus/multiRbusOpenProvider/multiRbusOpenProvider.c @@ -90,35 +90,69 @@ int main(int argc, char *argv[]) (void)(argc); (void)(argv); - rbusHandle_t handle; - int rc = RBUS_ERROR_SUCCESS; + 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; + } - rc = rbus_open(&handle, componentName); - rc = rbus_open(&handle, componentName); - if(rc != RBUS_ERROR_SUCCESS) + printf("provider0: handle1:%p: %d\n", (void*)handle1,rc1); + rc2 = rbus_open(&handle2, componentName); + if(rc2 != RBUS_ERROR_SUCCESS) { - printf("provider: rbus_open failed: %d\n", rc); + printf("provider: Second rbus_open handle2 err: %d\n", rc2); goto exit2; } - rc = rbus_regDataElements(handle, 1, dataElements); - if(rc != RBUS_ERROR_SUCCESS) + 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 failed: %d\n", rc); - goto exit2; + 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); - rbus_unregDataElements(handle, 1, dataElements); + 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: - printf("provider: exit\n"); - return rc; + 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/multiRbusOpenRbusGetConsumer/multiRbusOpenRbusGetConsumer.c b/test/rbus/multiRbusOpenRbusGetConsumer/multiRbusOpenRbusGetConsumer.c index f6bb0579..7ae71c3f 100644 --- a/test/rbus/multiRbusOpenRbusGetConsumer/multiRbusOpenRbusGetConsumer.c +++ b/test/rbus/multiRbusOpenRbusGetConsumer/multiRbusOpenRbusGetConsumer.c @@ -31,23 +31,30 @@ int main(int argc, char *argv[]) { - rbusHandle_t handle; - int rc = RBUS_ERROR_SUCCESS; + rbusHandle_t handle1; + rbusHandle_t handle2; + int rc1 = RBUS_ERROR_SUCCESS; + int rc2 = RBUS_ERROR_SUCCESS; (void)(argc); (void)(argv); printf("constumer: start\n"); - rc = rbus_open(&handle, "multiRbusOpenRbusGetConsumer"); - rc = rbus_open(&handle, "multiRbusOpenRbusGetConsumer"); - if(rc != RBUS_ERROR_SUCCESS) + rc1 = rbus_open(&handle1, "multiRbusOpenRbusGetConsumer"); + if(rc1 != RBUS_ERROR_SUCCESS) { - printf("consumer: rbus_open failed: %d\n", rc); + printf("consumer: First rbus_open for handle1 err: %d\n", rc1); goto exit1; } - //TestValueProperty* properties; + 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} }; @@ -55,27 +62,45 @@ int main(int argc, char *argv[]) printf("_test_multiRbusOpen rbus_get %s\n", data.name); - rc = rbus_get(handle, data.name, &value); + rc1 = rbus_get(handle1, data.name, &value); - if(rc == RBUS_ERROR_SUCCESS) + if(rc1 != RBUS_ERROR_INVALID_HANDLE) { - printf(">>>>>>>>>>>>>>>>>>>>>>>> test success %s >>>>>>>>>>>>>>>>>>>>>>>>>\n", data.name); + 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", rc); + printf("_test_Value rbus_get failed err:%d\n", rc2); } - printf("consumer: multiRbusOpenRbusGetConsumer %s\n", - rc == RBUS_ERROR_SUCCESS ? "success" : "fail"); + 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 rc; + return rc2; } diff --git a/test/rbus/multiRbusOpenRbusGetProvider/multiRbusOpenRbusGetProvider.c b/test/rbus/multiRbusOpenRbusGetProvider/multiRbusOpenRbusGetProvider.c index 47839310..7a1af668 100644 --- a/test/rbus/multiRbusOpenRbusGetProvider/multiRbusOpenRbusGetProvider.c +++ b/test/rbus/multiRbusOpenRbusGetProvider/multiRbusOpenRbusGetProvider.c @@ -30,7 +30,8 @@ #include int loopFor = 30; -rbusHandle_t handle; +rbusHandle_t handle1; +rbusHandle_t handle2; typedef struct MethodData { @@ -46,7 +47,8 @@ int main(int argc, char *argv[]) (void)(argc); (void)(argv); - int rc = RBUS_ERROR_SUCCESS; + int rc1 = RBUS_ERROR_SUCCESS; + int rc2 = RBUS_ERROR_SUCCESS; char componentName[] = "multiRbusOpenRbusGetProvider"; @@ -54,21 +56,33 @@ int main(int argc, char *argv[]) printf("provider: start\n"); - rc = rbus_open(&handle, componentName); - rc = rbus_open(&handle, componentName); - if(rc != RBUS_ERROR_SUCCESS) + rc1 = rbus_open(&handle1, componentName); + if(rc1 != RBUS_ERROR_SUCCESS) { - printf("provider: rbus_open failed: %d\n", rc); - goto exit2; + printf("provider: First rbus_open for handle1 err: %d\n", rc1); + goto exit1; } - rc = rbus_regDataElements(handle, 1, &dataElements); - if(rc != RBUS_ERROR_SUCCESS) + rc2 = rbus_open(&handle2, componentName); + if(rc2 != RBUS_ERROR_SUCCESS) { - printf("provider: rbus_regDataElements failed: %d\n", rc); + 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); @@ -76,10 +90,32 @@ int main(int argc, char *argv[]) loopFor--; } - rbus_unregDataElements(handle, 1, &dataElements); + 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 rc; + return rc2; } diff --git a/test/rbus/multiRbusOpenRbusSetConsumer/multiRbusOpenRbusSetConsumer.c b/test/rbus/multiRbusOpenRbusSetConsumer/multiRbusOpenRbusSetConsumer.c index 4d034510..04b4b5fb 100644 --- a/test/rbus/multiRbusOpenRbusSetConsumer/multiRbusOpenRbusSetConsumer.c +++ b/test/rbus/multiRbusOpenRbusSetConsumer/multiRbusOpenRbusSetConsumer.c @@ -31,22 +31,30 @@ int main(int argc, char *argv[]) { - rbusHandle_t handle; - int rc = RBUS_ERROR_SUCCESS; + rbusHandle_t handle1; + rbusHandle_t handle2; + int rc1 = RBUS_ERROR_SUCCESS; + int rc2 = RBUS_ERROR_SUCCESS; (void)(argc); (void)(argv); printf("constumer: start\n"); - rc = rbus_open(&handle, "multiRbusOpenRbusSetConsumer"); - rc = rbus_open(&handle, "multiRbusOpenRbusSetConsumer"); - if(rc != RBUS_ERROR_SUCCESS) + rc1 = rbus_open(&handle1, "multiRbusOpenRbusSetConsumer"); + if(rc1 != RBUS_ERROR_SUCCESS) { - printf("consumer: rbus_open failed: %d\n", rc); + 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); @@ -57,29 +65,42 @@ int main(int argc, char *argv[]) printf("_test_multiRbusOpen rbus_set %s\n", data.name); - rc = rbus_set(handle, data.name, value, NULL); + rc1 = rbus_set(handle1, data.name, value, NULL); - if(rc == RBUS_ERROR_SUCCESS) - { - printf(">>>>>>>>>>>>>>>>>>>>>>>> test rbus set success %s >>>>>>>>>>>>>>>>>>>>>>>>>\n", data.name); - rbusValue_Release(value); - } - else + if(rc1 != RBUS_ERROR_INVALID_HANDLE) { - printf("_test_Value rbus_set failed err:%d\n", rc); + printf("_test_Value rbus_set err:%d\n", rc1); } - sleep(1); - printf("consumer: multiRbusOpenRbusGetConsumer %s\n", - rc == RBUS_ERROR_SUCCESS ? "success" : "fail"); + rc2 = rbus_set(handle2, data.name, value, NULL); - sleep(5); + 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 rc; + return rc2; } diff --git a/test/rbus/rbus_test.sh b/test/rbus/rbus_test.sh index a4efbeac..716588a7 100644 --- a/test/rbus/rbus_test.sh +++ b/test/rbus/rbus_test.sh @@ -35,11 +35,12 @@ wait logmultiRbusOpenMethodProvider=/tmp/log.multiRbusOpenMethodProvider logmultiRbusOpenMethodConsumer=/tmp/log.multiRbusOpenMethodConsumer -echo "Multi RbusOpen with Method Invoke test will complete in about 10 seconds" -./multiRbusOpenMethodProvider > $logmultiRbusOpenMethodProvider & -./multiRbusOpenMethodConsumer > $logmultiRbusOpenMethodConsumer & +echo "Multi RbusOpen with Method Invoke test will complete in about 90 seconds" -wait +./multiRbusOpenMethodProvider > $logmultiRbusOpenMethodProvider 2>&1 & +./multiRbusOpenMethodConsumer > $logmultiRbusOpenMethodConsumer 2>&1 & + +#wait logRbusOpenProvider=/tmp/log.multiRbusOpenprovider logRbusOpenConsumer=/tmp/log.multiRbusOpenconsumer @@ -51,20 +52,38 @@ echo "Multi RbusOpen with Register and subscribe test will complete in about 80 wait logRbusOpenRegRbusOpenProvider=/tmp/log.rbusOpenRegRbusOpenProvider -logRbusOpenRegRbusOpenConsumer=/tmp/log.rbusOpenRegRbusOpenConsumer +logRbusOpenSubRbusOpenConsumer=/tmp/log.rbusOpenSubRbusOpenConsumer echo "Multi Rbus Open Register and Subscribe Negative test will complete in about 75 seconds" ./rbusOpenRegRbusOpenProvider > $logRbusOpenRegRbusOpenProvider 2>&1 & -./rbusOpenRegRbusOpenConsumer > $logRbusOpenRegRbusOpenConsumer 2>&1 & +./rbusOpenSubRbusOpenConsumer > $logRbusOpenSubRbusOpenConsumer 2>&1 & wait -logMultiProviderThreadsForSingleEvent=/tmp/log.multiProviderThreadsForSingleEvent -logMultiConsumerThreadsForSingleEvent=/tmp/log.multiConsumerThreadsForSingleEvent +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 & +#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:"