Skip to content

Commit

Permalink
Add multi-progress test with handle creation
Browse files Browse the repository at this point in the history
  • Loading branch information
soumagne committed Oct 16, 2023
1 parent 410f88d commit d49d868
Showing 1 changed file with 145 additions and 0 deletions.
145 changes: 145 additions & 0 deletions Testing/unit/hg/test_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ hg_test_rpc_no_req(hg_context_t *context, hg_handle_t handle, hg_cb_t callback);
static hg_return_t
hg_test_rpc_no_req_cb(const struct hg_cb_info *callback_info);

static HG_THREAD_RETURN_TYPE
hg_test_rpc_multi_progress_create(void *arg);

static hg_return_t
hg_test_rpc_no_req_create(
hg_context_t *context, hg_addr_t addr, hg_cb_t callback);

static hg_return_t
hg_test_rpc_no_req_create_cb(const struct hg_cb_info *callback_info);

/*******************/
/* Local Variables */
/*******************/
Expand Down Expand Up @@ -634,6 +644,34 @@ hg_test_rpc_multi_progress(void *arg)
return tret;
}

/*---------------------------------------------------------------------------*/
static HG_THREAD_RETURN_TYPE
hg_test_rpc_multi_progress_create(void *arg)
{
struct hg_test_multi_thread *thread_arg =
(struct hg_test_multi_thread *) arg;
struct hg_unit_info *info = thread_arg->info;
hg_thread_ret_t tret = (hg_thread_ret_t) 0;
hg_return_t ret;
int i;

HG_TEST_CHECK_ERROR(info->handle_max < thread_arg->thread_id, done, ret,
HG_INVALID_PARAM, "Handle max is too low (%zu)", info->handle_max);

for (i = 0; i < 100; i++) {
ret = hg_test_rpc_no_req_create(
info->context, info->target_addr, hg_test_rpc_no_req_create_cb);
HG_TEST_CHECK_HG_ERROR(done, ret,
"hg_test_rpc_no_req_create() failed (%s)", HG_Error_to_string(ret));
}

done:
thread_arg->ret = ret;

hg_thread_exit(tret);
return tret;
}

/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_rpc_no_req(hg_context_t *context, hg_handle_t handle, hg_cb_t callback)
Expand Down Expand Up @@ -679,6 +717,57 @@ hg_test_rpc_no_req(hg_context_t *context, hg_handle_t handle, hg_cb_t callback)
return ret;
}

/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_rpc_no_req_create(
hg_context_t *context, hg_addr_t addr, hg_cb_t callback)
{
hg_return_t ret;
hg_handle_t handle;
rpc_handle_t rpc_open_handle = {.cookie = 100};
struct forward_no_req_cb_args forward_cb_args = {
.done = HG_ATOMIC_VAR_INIT(0),
.rpc_handle = &rpc_open_handle,
.ret = HG_SUCCESS};
rpc_open_in_t in_struct = {
.handle = rpc_open_handle, .path = HG_TEST_RPC_PATH};

ret = HG_Create(context, addr, hg_test_rpc_open_id_g, &handle);
HG_TEST_CHECK_HG_ERROR(
error, ret, "HG_Create() failed (%s)", HG_Error_to_string(ret));

ret = HG_Forward(handle, callback, &forward_cb_args, &in_struct);
HG_TEST_CHECK_HG_ERROR(
error, ret, "HG_Forward() failed (%s)", HG_Error_to_string(ret));

do {
unsigned int actual_count = 0;

do {
ret = HG_Trigger(context, 0, 100, &actual_count);
} while ((ret == HG_SUCCESS) && actual_count);
HG_TEST_CHECK_ERROR_NORET(ret != HG_SUCCESS && ret != HG_TIMEOUT, error,
"HG_Trigger() failed (%s)", HG_Error_to_string(ret));

if (hg_atomic_get32(&forward_cb_args.done))
break;

ret = HG_Progress(context, 0);
} while (ret == HG_SUCCESS || ret == HG_TIMEOUT);
HG_TEST_CHECK_ERROR_NORET(ret != HG_SUCCESS && ret != HG_TIMEOUT, error,
"HG_Progress() failed (%s)", HG_Error_to_string(ret));

ret = forward_cb_args.ret;
HG_TEST_CHECK_HG_ERROR(
error, ret, "Error in HG callback (%s)", HG_Error_to_string(ret));

return HG_SUCCESS;

error:

return ret;
}

/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_rpc_no_req_cb(const struct hg_cb_info *callback_info)
Expand Down Expand Up @@ -725,6 +814,54 @@ hg_test_rpc_no_req_cb(const struct hg_cb_info *callback_info)
return HG_SUCCESS;
}

/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_rpc_no_req_create_cb(const struct hg_cb_info *callback_info)
{
hg_handle_t handle = callback_info->info.forward.handle;
struct forward_no_req_cb_args *args =
(struct forward_no_req_cb_args *) callback_info->arg;
int rpc_open_ret;
int rpc_open_event_id;
rpc_open_out_t rpc_open_out_struct;
hg_return_t ret = callback_info->ret;

HG_TEST_CHECK_HG_ERROR(done, ret, "Error in HG callback (%s)",
HG_Error_to_string(callback_info->ret));

/* Get output */
ret = HG_Get_output(handle, &rpc_open_out_struct);
HG_TEST_CHECK_HG_ERROR(
done, ret, "HG_Get_output() failed (%s)", HG_Error_to_string(ret));

/* Get output parameters */
rpc_open_ret = rpc_open_out_struct.ret;
rpc_open_event_id = rpc_open_out_struct.event_id;
HG_TEST_LOG_DEBUG("rpc_open returned: %d with event_id: %d", rpc_open_ret,
rpc_open_event_id);
(void) rpc_open_ret;
HG_TEST_CHECK_ERROR(rpc_open_event_id != (int) args->rpc_handle->cookie,
free, ret, HG_FAULT, "Cookie did not match RPC response");

free:
if (ret != HG_SUCCESS)
(void) HG_Free_output(handle, &rpc_open_out_struct);
else {
/* Free output */
ret = HG_Free_output(handle, &rpc_open_out_struct);
HG_TEST_CHECK_HG_ERROR(
done, ret, "HG_Free_output() failed (%s)", HG_Error_to_string(ret));
}

HG_Destroy(handle);

done:
args->ret = ret;
hg_atomic_set32(&args->done, 1);

return HG_SUCCESS;
}

/*---------------------------------------------------------------------------*/
int
main(int argc, char *argv[])
Expand Down Expand Up @@ -877,6 +1014,14 @@ main(int argc, char *argv[])
"hg_test_rpc_launch_threads() failed (%s)", HG_Error_to_string(hg_ret));
HG_PASSED();

/* RPC test from multiple threads with concurrent progress */
HG_TEST("concurrent progress w/create");
hg_ret =
hg_test_rpc_launch_threads(&info, hg_test_rpc_multi_progress_create);
HG_TEST_CHECK_HG_ERROR(error, hg_ret,
"hg_test_rpc_launch_threads() failed (%s)", HG_Error_to_string(hg_ret));
HG_PASSED();

/* RPC test with multiple handles to multiple target contexts */
if (info.hg_test_info.na_test_info.max_contexts) {
hg_uint8_t i,
Expand Down

0 comments on commit d49d868

Please sign in to comment.