Skip to content

Commit

Permalink
RDKB-51761 Test scenario to cover multiple rbus_open() call
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dm097 committed Nov 7, 2023
1 parent 688c410 commit aa807ac
Show file tree
Hide file tree
Showing 11 changed files with 513 additions and 149 deletions.
22 changes: 22 additions & 0 deletions src/rbus/rbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *************************************//
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3120,6 +3132,7 @@ rbusError_t rbus_unregDataElements(
int numDataElements,
rbusDataElement_t *elements)
{
VERIFY_HANDLE(handle);
struct _rbusHandle* handleInfo = (struct _rbusHandle*)handle;
int i;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions src/rbus/rbus_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/rbus/rbus_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
90 changes: 74 additions & 16 deletions test/rbus/multiRbusOpenConsumer/multiRbusOpenConsumer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}


Loading

0 comments on commit aa807ac

Please sign in to comment.