Skip to content

Commit bc8b5d9

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

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

prov/efa/test/efa_unit_test_cq.c

Lines changed: 43 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 */
@@ -1719,7 +1720,7 @@ void test_efa_cq_sread_einval(struct efa_resource **state)
17191720
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_DIRECT_FABRIC_NAME);
17201721
efa_cq = container_of(resource->cq, struct efa_cq, util_cq.cq_fid.fid);
17211722

1722-
assert_null(efa_cq->wait_obj);
1723+
assert_int_equal(efa_cq->wait_obj, FI_WAIT_NONE);
17231724
assert_null(efa_cq->ibv_cq.channel);
17241725

17251726
ret = fi_cq_sread(resource->cq, &cq_entry, 1, NULL, 1);
@@ -2303,4 +2304,44 @@ void test_efa_cq_read_mixed_success_error(struct efa_resource **state)
23032304
will_return_maybe(efa_mock_efa_ibv_cq_start_poll_return_mock, ENOENT);
23042305
assert_int_equal(fi_close(&resource->ep->fid), 0);
23052306
resource->ep = NULL;
2306-
}
2307+
}
2308+
2309+
2310+
2311+
/**
2312+
* @brief Test fi_cq_sread() with count=0 returns -FI_EINVAL
2313+
*/
2314+
void test_efa_rdm_cq_sread_invalid_count(struct efa_resource **state)
2315+
{
2316+
struct efa_resource *resource = *state;
2317+
struct fi_cq_data_entry cq_entry;
2318+
int ret;
2319+
2320+
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME);
2321+
2322+
ret = fi_cq_sread(resource->cq, &cq_entry, 0, NULL, 0);
2323+
assert_int_equal(ret, -FI_EINVAL);
2324+
2325+
will_return_maybe(efa_mock_efa_ibv_cq_start_poll_return_mock, ENOENT);
2326+
assert_int_equal(fi_close(&resource->ep->fid), 0);
2327+
resource->ep = NULL;
2328+
}
2329+
2330+
/**
2331+
* @brief Test fi_cq_sread() with no wait object returns -FI_ENOSYS
2332+
*/
2333+
void test_efa_rdm_cq_sread_no_wait_obj(struct efa_resource **state)
2334+
{
2335+
struct efa_resource *resource = *state;
2336+
struct fi_cq_data_entry cq_entry;
2337+
int ret;
2338+
2339+
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME);
2340+
2341+
ret = fi_cq_sread(resource->cq, &cq_entry, 1, NULL, 0);
2342+
assert_int_equal(ret, -FI_ENOSYS);
2343+
2344+
will_return_maybe(efa_mock_efa_ibv_cq_start_poll_return_mock, ENOENT);
2345+
assert_int_equal(fi_close(&resource->ep->fid), 0);
2346+
resource->ep = NULL;
2347+
}

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();
@@ -222,6 +227,8 @@ int main(void)
222227
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),
223228
cmocka_unit_test_setup_teardown(test_ibv_cq_ex_read_ignore_removed_peer, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
224229
cmocka_unit_test_setup_teardown(test_efa_rdm_cq_before_ep_enable, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
230+
cmocka_unit_test_setup_teardown(test_efa_rdm_cq_sread_invalid_count, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
231+
cmocka_unit_test_setup_teardown(test_efa_rdm_cq_sread_no_wait_obj, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
225232
cmocka_unit_test_setup_teardown(test_efa_cq_data_path_direct_disabled_by_env, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
226233
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),
227234
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)