Skip to content

Commit

Permalink
prov/efa: Add unit tests for efa_rma
Browse files Browse the repository at this point in the history
Signed-off-by: Jessie Yang <[email protected]>
  • Loading branch information
jiaxiyan authored and shijin-aws committed Dec 17, 2024
1 parent 2d4ac0e commit ebca5ec
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 1 deletion.
3 changes: 2 additions & 1 deletion prov/efa/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ nodist_prov_efa_test_efa_unit_test_SOURCES = \
prov/efa/test/efa_unit_test_mr.c \
prov/efa/test/efa_unit_test_rdm_peer.c \
prov/efa/test/efa_unit_test_pke.c \
prov/efa/test/efa_unit_test_msg.c
prov/efa/test/efa_unit_test_msg.c \
prov/efa/test/efa_unit_test_rma.c


efa_CPPFLAGS += -I$(top_srcdir)/include -I$(top_srcdir)/prov/efa/test $(cmocka_CPPFLAGS)
Expand Down
16 changes: 16 additions & 0 deletions prov/efa/test/efa_unit_test_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ void efa_unit_test_construct_tmsg(struct fi_msg_tagged *tmsg, struct iovec *iov,
tmsg->ignore = ignore;
}

void efa_unit_test_construct_msg_rma(struct fi_msg_rma *msg, struct iovec *iov,
void **desc, size_t iov_count,
fi_addr_t addr, struct fi_rma_iov *rma_iov,
size_t rma_iov_count, void *context,
uint64_t data)
{
msg->msg_iov = iov;
msg->desc = desc;
msg->iov_count = iov_count;
msg->addr = addr;
msg->rma_iov = rma_iov;
msg->rma_iov_count = rma_iov_count;
msg->context = context;
msg->data = data;
}

struct fi_info *efa_unit_test_alloc_hints(enum fi_ep_type ep_type)
{
struct fi_info *hints;
Expand Down
15 changes: 15 additions & 0 deletions prov/efa/test/efa_unit_test_mocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ int efa_mock_ibv_post_recv(struct ibv_qp *qp, struct ibv_recv_wr *wr,
return mock();
}

void efa_mock_ibv_wr_rdma_read_save_wr(struct ibv_qp_ex *qp, uint32_t rkey,
uint64_t remote_addr)
{
g_ibv_submitted_wr_id_vec[g_ibv_submitted_wr_id_cnt] = (void *)qp->wr_id;
g_ibv_submitted_wr_id_cnt++;
}

void efa_mock_ibv_wr_rdma_write_imm_save_wr(struct ibv_qp_ex *qp, uint32_t rkey,
uint64_t remote_addr,
__be32 imm_data)
{
g_ibv_submitted_wr_id_vec[g_ibv_submitted_wr_id_cnt] = (void *) qp->wr_id;
g_ibv_submitted_wr_id_cnt++;
}

struct efa_unit_test_mocks g_efa_unit_test_mocks = {
.local_host_id = 0,
.peer_host_id = 0,
Expand Down
7 changes: 7 additions & 0 deletions prov/efa/test/efa_unit_test_mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ bool efa_mock_efa_device_support_unsolicited_write_recv(void);
int efa_mock_ibv_post_recv(struct ibv_qp *qp, struct ibv_recv_wr *wr,
struct ibv_recv_wr **bad_wr);

void efa_mock_ibv_wr_rdma_read_save_wr(struct ibv_qp_ex *qp, uint32_t rkey,
uint64_t remote_addr);

void efa_mock_ibv_wr_rdma_write_imm_save_wr(struct ibv_qp_ex *qp, uint32_t rkey,
uint64_t remote_addr,
__be32 imm_data);

struct efa_unit_test_mocks
{
uint64_t local_host_id;
Expand Down
273 changes: 273 additions & 0 deletions prov/efa/test/efa_unit_test_rma.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
/* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-only */
/* SPDX-FileCopyrightText: Copyright Amazon.com, Inc. or its affiliates. All
* rights reserved. */

#include "efa_unit_tests.h"
#include "ofi_util.h"

extern struct fi_ops_rma efa_rma_ops;

static void test_efa_rma_prep(struct efa_resource *resource, fi_addr_t *addr)
{
struct ibv_qp_ex *ibv_qpx;
struct efa_ep_addr raw_addr;
struct efa_base_ep *base_ep;
size_t raw_addr_len = sizeof(raw_addr);
int ret;

efa_unit_test_resource_construct(resource, FI_EP_RDM);
resource->ep->rma = &efa_rma_ops;

base_ep = container_of(resource->ep, struct efa_base_ep, util_ep.ep_fid);
ibv_qpx = base_ep->qp->ibv_qp_ex;
ibv_qpx->wr_start = &efa_mock_ibv_wr_start_no_op;
/* this mock will save the send work request (wr) in a global list */
ibv_qpx->wr_rdma_read = &efa_mock_ibv_wr_rdma_read_save_wr;
ibv_qpx->wr_rdma_write = &efa_mock_ibv_wr_rdma_write_save_wr;
ibv_qpx->wr_rdma_write_imm = &efa_mock_ibv_wr_rdma_write_imm_save_wr;
ibv_qpx->wr_set_inline_data_list =
&efa_mock_ibv_wr_set_inline_data_list_no_op;
ibv_qpx->wr_set_sge_list = &efa_mock_ibv_wr_set_sge_list_no_op;
ibv_qpx->wr_set_ud_addr = &efa_mock_ibv_wr_set_ud_addr_no_op;
ibv_qpx->wr_complete = &efa_mock_ibv_wr_complete_no_op;

ret = fi_getname(&resource->ep->fid, &raw_addr, &raw_addr_len);
assert_int_equal(ret, 0);
raw_addr.qpn = 1;
raw_addr.qkey = 0x1234;
ret = fi_av_insert(resource->av, &raw_addr, 1, addr, 0 /* flags */,
NULL /* context */);
assert_int_equal(ret, 1);
}

void test_efa_rma_read(struct efa_resource **state)
{
struct efa_resource *resource = *state;
struct efa_unit_test_buff local_buff;
fi_addr_t src_addr;
void *desc;
int ret;
uint64_t remote_addr = 0x87654321;
uint64_t remote_key = 123456;

test_efa_rma_prep(resource, &src_addr);
efa_unit_test_buff_construct(&local_buff, resource, 4096 /* buff_size */);

desc = fi_mr_desc(local_buff.mr);

assert_int_equal(g_ibv_submitted_wr_id_cnt, 0);
ret = fi_read(resource->ep, local_buff.buff, local_buff.size, desc,
src_addr, remote_addr, remote_key, NULL /* context */);
assert_int_equal(ret, 0);
assert_int_equal(g_ibv_submitted_wr_id_cnt, 1);

efa_unit_test_buff_destruct(&local_buff);
}

void test_efa_rma_readv(struct efa_resource **state)
{
struct efa_resource *resource = *state;
struct efa_unit_test_buff local_buff;
struct iovec iov;
fi_addr_t src_addr;
void *desc;
int ret;
uint64_t remote_addr = 0x87654321;
uint64_t remote_key = 123456;

test_efa_rma_prep(resource, &src_addr);
efa_unit_test_buff_construct(&local_buff, resource, 4096 /* buff_size */);

iov.iov_base = local_buff.buff;
iov.iov_len = local_buff.size;
desc = fi_mr_desc(local_buff.mr);

assert_int_equal(g_ibv_submitted_wr_id_cnt, 0);
ret = fi_readv(resource->ep, &iov, &desc, 1, src_addr, remote_addr,
remote_key, NULL /* context */);
assert_int_equal(ret, 0);
assert_int_equal(g_ibv_submitted_wr_id_cnt, 1);

efa_unit_test_buff_destruct(&local_buff);
}

void test_efa_rma_readmsg(struct efa_resource **state)
{
struct efa_resource *resource = *state;
struct efa_unit_test_buff local_buff;
struct iovec iov;
struct fi_msg_rma msg = {0};
struct fi_rma_iov rma_iov;
fi_addr_t src_addr;
void *desc;
int ret;

test_efa_rma_prep(resource, &src_addr);
efa_unit_test_buff_construct(&local_buff, resource, 4096 /* buff_size */);

iov.iov_base = local_buff.buff;
iov.iov_len = local_buff.size;
desc = fi_mr_desc(local_buff.mr);
rma_iov.len = local_buff.size;
rma_iov.addr = 0x87654321;
rma_iov.key = 123456;
efa_unit_test_construct_msg_rma(&msg, &iov, &desc, 1, src_addr,
&rma_iov, 1, NULL, 0);

assert_int_equal(g_ibv_submitted_wr_id_cnt, 0);
ret = fi_readmsg(resource->ep, &msg, 0);
assert_int_equal(ret, 0);
assert_int_equal(g_ibv_submitted_wr_id_cnt, 1);

efa_unit_test_buff_destruct(&local_buff);
}

void test_efa_rma_write(struct efa_resource **state)
{
struct efa_resource *resource = *state;
struct efa_unit_test_buff local_buff;
fi_addr_t dest_addr;
void *desc;
int ret;
uint64_t remote_addr = 0x87654321;
uint64_t remote_key = 123456;

test_efa_rma_prep(resource, &dest_addr);
efa_unit_test_buff_construct(&local_buff, resource, 4096 /* buff_size */);

desc = fi_mr_desc(local_buff.mr);

assert_int_equal(g_ibv_submitted_wr_id_cnt, 0);
ret = fi_write(resource->ep, local_buff.buff, local_buff.size, desc,
dest_addr, remote_addr, remote_key, NULL /* context */);
assert_int_equal(ret, 0);
assert_int_equal(g_ibv_submitted_wr_id_cnt, 1);

efa_unit_test_buff_destruct(&local_buff);
}

void test_efa_rma_writev(struct efa_resource **state)
{
struct efa_resource *resource = *state;
struct efa_unit_test_buff local_buff;
struct iovec iov;
fi_addr_t dest_addr;
void *desc;
int ret;
uint64_t remote_addr = 0x87654321;
uint64_t remote_key = 123456;

test_efa_rma_prep(resource, &dest_addr);
efa_unit_test_buff_construct(&local_buff, resource, 4096 /* buff_size */);

iov.iov_base = local_buff.buff;
iov.iov_len = local_buff.size;
desc = fi_mr_desc(local_buff.mr);

assert_int_equal(g_ibv_submitted_wr_id_cnt, 0);
ret = fi_writev(resource->ep, &iov, &desc, 1, dest_addr, remote_addr,
remote_key, NULL /* context */);
assert_int_equal(ret, 0);
assert_int_equal(g_ibv_submitted_wr_id_cnt, 1);

efa_unit_test_buff_destruct(&local_buff);
}

void test_efa_rma_writemsg(struct efa_resource **state)
{
struct efa_resource *resource = *state;
struct efa_unit_test_buff local_buff;
struct iovec iov;
struct fi_msg_rma msg = {0};
struct fi_rma_iov rma_iov;
fi_addr_t dest_addr;
void *desc;
int ret;

test_efa_rma_prep(resource, &dest_addr);
efa_unit_test_buff_construct(&local_buff, resource, 4096 /* buff_size */);

iov.iov_base = local_buff.buff;
iov.iov_len = local_buff.size;
desc = fi_mr_desc(local_buff.mr);
rma_iov.len = local_buff.size;
rma_iov.addr = 0x87654321;
rma_iov.key = 123456;
efa_unit_test_construct_msg_rma(&msg, &iov, &desc, 1, dest_addr, &rma_iov,
1, NULL, 0);

assert_int_equal(g_ibv_submitted_wr_id_cnt, 0);
ret = fi_writemsg(resource->ep, &msg, 0);
assert_int_equal(ret, 0);
assert_int_equal(g_ibv_submitted_wr_id_cnt, 1);

efa_unit_test_buff_destruct(&local_buff);
}

void test_efa_rma_writedata(struct efa_resource **state)
{
struct efa_resource *resource = *state;
struct efa_unit_test_buff local_buff;
fi_addr_t dest_addr;
void *desc;
int ret;
uint64_t remote_addr = 0x87654321;
uint64_t remote_key = 123456;

test_efa_rma_prep(resource, &dest_addr);
efa_unit_test_buff_construct(&local_buff, resource, 4096 /* buff_size */);

desc = fi_mr_desc(local_buff.mr);

assert_int_equal(g_ibv_submitted_wr_id_cnt, 0);
ret = fi_writedata(resource->ep, local_buff.buff, local_buff.size, desc,
0, dest_addr, remote_addr, remote_key,
NULL /* context */);
assert_int_equal(ret, 0);
assert_int_equal(g_ibv_submitted_wr_id_cnt, 1);

efa_unit_test_buff_destruct(&local_buff);
}

void test_efa_rma_inject_write(struct efa_resource **state)
{
struct efa_resource *resource = *state;
struct efa_unit_test_buff local_buff;
fi_addr_t dest_addr;
int ret;
uint64_t remote_addr = 0x87654321;
uint64_t remote_key = 123456;

test_efa_rma_prep(resource, &dest_addr);
efa_unit_test_buff_construct(&local_buff, resource, 32 /* buff_size */);

assert_int_equal(g_ibv_submitted_wr_id_cnt, 0);
ret = fi_inject_write(resource->ep, local_buff.buff, local_buff.size,
dest_addr, remote_addr, remote_key);
assert_int_equal(ret, 0);
assert_int_equal(g_ibv_submitted_wr_id_cnt, 1);

efa_unit_test_buff_destruct(&local_buff);
}

void test_efa_rma_inject_writedata(struct efa_resource **state)
{
struct efa_resource *resource = *state;
struct efa_unit_test_buff local_buff;
fi_addr_t dest_addr;
int ret;
uint64_t remote_addr = 0x87654321;
uint64_t remote_key = 123456;

test_efa_rma_prep(resource, &dest_addr);
efa_unit_test_buff_construct(&local_buff, resource, 32 /* buff_size */);

assert_int_equal(g_ibv_submitted_wr_id_cnt, 0);
ret = fi_inject_writedata(resource->ep, local_buff.buff,
local_buff.size, 0, dest_addr, remote_addr,
remote_key);
assert_int_equal(ret, 0);
assert_int_equal(g_ibv_submitted_wr_id_cnt, 1);

efa_unit_test_buff_destruct(&local_buff);
}
9 changes: 9 additions & 0 deletions prov/efa/test/efa_unit_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ int main(void)
cmocka_unit_test_setup_teardown(test_efa_msg_fi_senddata, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
cmocka_unit_test_setup_teardown(test_efa_msg_fi_inject, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
cmocka_unit_test_setup_teardown(test_efa_msg_fi_injectdata, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
cmocka_unit_test_setup_teardown(test_efa_rma_read, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
cmocka_unit_test_setup_teardown(test_efa_rma_readv, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
cmocka_unit_test_setup_teardown(test_efa_rma_readmsg, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
cmocka_unit_test_setup_teardown(test_efa_rma_write, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
cmocka_unit_test_setup_teardown(test_efa_rma_writev, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
cmocka_unit_test_setup_teardown(test_efa_rma_writemsg, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
cmocka_unit_test_setup_teardown(test_efa_rma_writedata, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
cmocka_unit_test_setup_teardown(test_efa_rma_inject_write, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
cmocka_unit_test_setup_teardown(test_efa_rma_inject_writedata, efa_unit_test_mocks_setup, efa_unit_test_mocks_teardown),
};

cmocka_set_message_output(CM_OUTPUT_XML);
Expand Down
15 changes: 15 additions & 0 deletions prov/efa/test/efa_unit_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ void efa_unit_test_construct_tmsg(struct fi_msg_tagged *tmsg, struct iovec *iov,
void **desc, uint64_t tag,
uint64_t ignore);

void efa_unit_test_construct_msg_rma(struct fi_msg_rma *msg, struct iovec *iov,
void **desc, size_t iov_count,
fi_addr_t addr, struct fi_rma_iov *rma_iov,
size_t rma_iov_count, void *context,
uint64_t data);

void new_temp_file(char *template, size_t len);

struct efa_unit_test_buff {
Expand Down Expand Up @@ -231,6 +237,15 @@ void test_efa_msg_fi_sendmsg();
void test_efa_msg_fi_senddata();
void test_efa_msg_fi_inject();
void test_efa_msg_fi_injectdata();
void test_efa_rma_read();
void test_efa_rma_readv();
void test_efa_rma_readmsg();
void test_efa_rma_write();
void test_efa_rma_writev();
void test_efa_rma_writemsg();
void test_efa_rma_writedata();
void test_efa_rma_inject_write();
void test_efa_rma_inject_writedata();

static inline
int efa_unit_test_get_dlist_length(struct dlist_entry *head)
Expand Down

0 comments on commit ebca5ec

Please sign in to comment.