Skip to content

Commit 79cc073

Browse files
committed
prov/efa: Add unit tests for RDM CQ sread
Signed-off-by: Darryl Abbate <[email protected]>
1 parent b7bf24d commit 79cc073

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

prov/efa/test/efa_unit_test_cq.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,7 @@ static void test_efa_cq_data_path_direct_status(
14671467
efa_cq = container_of(cq, struct efa_cq, util_cq.cq_fid);
14681468

14691469
assert_true(efa_cq->ibv_cq.data_path_direct_enabled == data_path_direct_enabled);
1470+
14701471
assert_int_equal(fi_close(&cq->fid), 0);
14711472

14721473
/* Recover the mocked vendor_id */
@@ -1732,7 +1733,7 @@ void test_efa_cq_sread_einval(struct efa_resource **state)
17321733
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_DIRECT_FABRIC_NAME);
17331734
efa_cq = container_of(resource->cq, struct efa_cq, util_cq.cq_fid.fid);
17341735

1735-
assert_null(efa_cq->wait_obj);
1736+
assert_int_equal(efa_cq->wait_obj, FI_WAIT_NONE);
17361737
assert_null(efa_cq->ibv_cq.channel);
17371738

17381739
ret = fi_cq_sread(resource->cq, &cq_entry, 1, NULL, 1);
@@ -2316,4 +2317,48 @@ void test_efa_cq_read_mixed_success_error(struct efa_resource **state)
23162317
will_return_maybe(efa_mock_efa_ibv_cq_start_poll_return_mock, ENOENT);
23172318
assert_int_equal(fi_close(&resource->ep->fid), 0);
23182319
resource->ep = NULL;
2319-
}
2320+
}
2321+
2322+
2323+
2324+
/**
2325+
* @brief Test fi_cq_sread() with count=0 returns -FI_EINVAL
2326+
*/
2327+
void test_efa_rdm_cq_sread_invalid_count(struct efa_resource **state)
2328+
{
2329+
struct efa_resource *resource = *state;
2330+
struct fi_cq_data_entry cq_entry;
2331+
int ret;
2332+
2333+
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME);
2334+
2335+
ret = fi_cq_sread(resource->cq, &cq_entry, 0, NULL, 0);
2336+
assert_int_equal(ret, -FI_EINVAL);
2337+
2338+
will_return_maybe(efa_mock_efa_ibv_cq_start_poll_return_mock, ENOENT);
2339+
assert_int_equal(fi_close(&resource->ep->fid), 0);
2340+
resource->ep = NULL;
2341+
}
2342+
2343+
/**
2344+
* @brief Test fi_cq_sread() with wait object disabled returns -FI_EINVAL
2345+
*/
2346+
void test_efa_rdm_cq_sread_no_wait_obj(struct efa_resource **state)
2347+
{
2348+
struct efa_resource *resource = *state;
2349+
struct fi_cq_data_entry cq_entry;
2350+
int ret;
2351+
2352+
/* Open a temporary CQ with wait-none so no wait object exists */
2353+
struct fid_cq *waitless_cq = NULL;
2354+
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME);
2355+
assert_int_equal(fi_cq_open(resource->domain,
2356+
&(struct fi_cq_attr){ .wait_obj = FI_WAIT_NONE },
2357+
&waitless_cq, NULL), 0);
2358+
2359+
ret = fi_cq_sread(waitless_cq, &cq_entry, 1, NULL, 0);
2360+
assert_int_equal(ret, -FI_EINVAL);
2361+
2362+
assert_int_equal(fi_close(&waitless_cq->fid), 0);
2363+
will_return_maybe(efa_mock_efa_ibv_cq_start_poll_return_mock, ENOENT);
2364+
}

prov/efa/test/efa_unit_tests.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ static int efa_unit_test_mocks_teardown(void **state)
5353
/* Reset the contents of g_efa_hmem_info from backup */
5454
memcpy(g_efa_hmem_info, g_efa_hmem_info_backup, sizeof(g_efa_hmem_info));
5555

56+
/* Provide default mock return values for CQ operations during teardown */
57+
if (g_efa_unit_test_mocks.efa_ibv_cq_start_poll) {
58+
will_return_maybe(efa_mock_efa_ibv_cq_start_poll_return_mock, ENOENT);
59+
}
60+
5661
efa_unit_test_resource_destruct(resource);
5762

5863
efa_ibv_ah_limit_cnt_reset();
@@ -223,6 +228,8 @@ int main(void)
223228
cmocka_unit_test_setup_teardown(test_rdm_fallback_to_ibv_create_cq_ex_cq_read_ignore_forgotton_peer, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
224229
cmocka_unit_test_setup_teardown(test_ibv_cq_ex_read_ignore_removed_peer, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
225230
cmocka_unit_test_setup_teardown(test_efa_rdm_cq_before_ep_enable, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
231+
cmocka_unit_test_setup_teardown(test_efa_rdm_cq_sread_invalid_count, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
232+
cmocka_unit_test_setup_teardown(test_efa_rdm_cq_sread_no_wait_obj, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
226233
cmocka_unit_test_setup_teardown(test_efa_cq_data_path_direct_disabled_by_env, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
227234
cmocka_unit_test_setup_teardown(test_efa_cq_data_path_direct_disabled_with_old_device, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
228235
cmocka_unit_test_setup_teardown(test_efa_cq_data_path_direct_enabled_with_new_device, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),

prov/efa/test/efa_unit_tests.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ void test_ibv_cq_ex_read_recover_forgotten_peer_ah();
191191
void test_rdm_fallback_to_ibv_create_cq_ex_cq_read_ignore_forgotton_peer();
192192
void test_ibv_cq_ex_read_ignore_removed_peer();
193193
void test_efa_rdm_cq_before_ep_enable();
194+
void test_efa_rdm_cq_sread_invalid_count();
195+
void test_efa_rdm_cq_sread_no_wait_obj();
194196

195197
/* begin efa_unit_test_info.c */
196198
void test_info_open_ep_with_wrong_info();

0 commit comments

Comments
 (0)