Debian Codegraph @

prov/efa/test/efa_unit_test_domain.c

raw
1 /* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-only */
2 /* SPDX-FileCopyrightText: Copyright Amazon.com, Inc. or its affiliates. All rights reserved. */
3
4 #include "efa_unit_tests.h"
5
6 /**
7 * @brief Verify the info type in struct efa_domain for efa RDM path
8 *
9 * @param[in] state struct efa_resource that is managed by the framework
10 */
11 void test_efa_domain_info_type_efa_rdm(struct efa_resource **state)
12 {
13 struct efa_resource *resource = *state;
14 struct efa_domain *efa_domain;
15
16 efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME);
17 efa_domain = container_of(resource->domain, struct efa_domain, util_domain.domain_fid);
18 assert(efa_domain->info_type == EFA_INFO_RDM);
19 }
20
21 /**
22 * @brief Verify the info type in struct efa_domain for efa direct path
23 *
24 * @param[in] state struct efa_resource that is managed by the framework
25 */
26 void test_efa_domain_info_type_efa_direct(struct efa_resource **state)
27 {
28 struct efa_resource *resource = *state;
29 struct efa_domain *efa_domain;
30
31 efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_DIRECT_FABRIC_NAME);
32 efa_domain = container_of(resource->domain, struct efa_domain, util_domain.domain_fid);
33 assert(efa_domain->info_type == EFA_INFO_DIRECT);
34 }
35
36 /* test fi_open_ops with a wrong name */
37 void test_efa_domain_open_ops_wrong_name(struct efa_resource **state)
38 {
39 struct efa_resource *resource = *state;
40 int ret;
41 struct fi_efa_ops_domain *efa_domain_ops;
42
43 efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME);
44
45 ret = fi_open_ops(&resource->domain->fid, "arbitrary name", 0, (void **)&efa_domain_ops, NULL);
46 assert_int_equal(ret, -FI_EINVAL);
47 }
48
49 static
50 void test_efa_domain_open_ops_mr_query_common(
51 struct efa_resource *resource,
52 int expected_ret,
53 uint16_t expected_ic_id_validity,
54 uint16_t expected_recv_ic_id,
55 uint16_t expected_rdma_read_ic_id,
56 uint16_t expected_rdma_recv_ic_id)
57 {
58 int ret;
59 struct fi_efa_ops_domain *efa_domain_ops;
60 struct fi_efa_mr_attr efa_mr_attr = {0};
61 struct efa_mr mr = {0};
62 struct fid_mr mr_fid = {0};
63
64 mr.mr_fid = mr_fid;
65 mr.ibv_mr = NULL;
66
67 ret = fi_open_ops(&resource->domain->fid, FI_EFA_DOMAIN_OPS, 0, (void **)&efa_domain_ops, NULL);
68 assert_int_equal(ret, 0);
69
70 ret = efa_domain_ops->query_mr(&mr.mr_fid, &efa_mr_attr);
71 assert_int_equal(ret, expected_ret);
72
73 if (expected_ret == -FI_ENOSYS)
74 return;
75
76 assert_true(efa_mr_attr.ic_id_validity == expected_ic_id_validity);
77
78 if (efa_mr_attr.ic_id_validity & FI_EFA_MR_ATTR_RECV_IC_ID)
79 assert_true(efa_mr_attr.recv_ic_id == expected_recv_ic_id);
80
81 if (efa_mr_attr.ic_id_validity & FI_EFA_MR_ATTR_RDMA_READ_IC_ID)
82 assert_true(efa_mr_attr.rdma_read_ic_id == expected_rdma_read_ic_id);
83
84 if (efa_mr_attr.ic_id_validity & FI_EFA_MR_ATTR_RDMA_RECV_IC_ID)
85 assert_true(efa_mr_attr.rdma_recv_ic_id == expected_rdma_recv_ic_id);
86 }
87
88 #if HAVE_EFADV_QUERY_MR
89
90 void test_efa_domain_open_ops_mr_query(struct efa_resource **state)
91 {
92 struct efa_resource *resource = *state;
93
94 efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME);
95
96 /* set recv_ic_id as 0 */
97 g_efa_unit_test_mocks.efadv_query_mr = &efa_mock_efadv_query_mr_recv_ic_id_0;
98
99 test_efa_domain_open_ops_mr_query_common(
100 resource,
101 0,
102 FI_EFA_MR_ATTR_RECV_IC_ID,
103 0,
104 0 /* ignored */,
105 0 /* ignored */);
106
107 /* set rdma_read_ic_id as 1 */
108 g_efa_unit_test_mocks.efadv_query_mr = &efa_mock_efadv_query_mr_rdma_read_ic_id_1;
109
110 test_efa_domain_open_ops_mr_query_common(
111 resource,
112 0,
113 FI_EFA_MR_ATTR_RDMA_READ_IC_ID,
114 0 /* ignored */,
115 1,
116 0 /* ignored */);
117
118 /* set rdma_recv_ic_id as 2 */
119 g_efa_unit_test_mocks.efadv_query_mr = &efa_mock_efadv_query_mr_rdma_recv_ic_id_2;
120
121 test_efa_domain_open_ops_mr_query_common(
122 resource,
123 0,
124 FI_EFA_MR_ATTR_RDMA_RECV_IC_ID,
125 0 /* ignored */,
126 0 /* ignored */,
127 2);
128
129 /* set recv_ic_id as 0, rdma_read_ic_id as 1 */
130 g_efa_unit_test_mocks.efadv_query_mr = &efa_mock_efadv_query_mr_recv_and_rdma_read_ic_id_0_1;
131
132 test_efa_domain_open_ops_mr_query_common(
133 resource,
134 0,
135 FI_EFA_MR_ATTR_RECV_IC_ID | FI_EFA_MR_ATTR_RDMA_READ_IC_ID,
136 0,
137 1,
138 0 /* ignored */);
139 }
140
141 #else
142
143 void test_efa_domain_open_ops_mr_query(struct efa_resource **state)
144 {
145 struct efa_resource *resource = *state;
146
147 efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME);
148
149 test_efa_domain_open_ops_mr_query_common(
150 resource,
151 -FI_ENOSYS,
152 0, /* ignored */
153 0, /* ignored */
154 1, /* ignored */
155 0 /* ignored */);
156 }
157
158 #endif /* HAVE_EFADV_QUERY_MR */