| 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 |
#include "efa_av.h" |
| 6 |
|
| 7 |
/** |
| 8 |
* @brief Only works on nodes with EFA devices |
| 9 |
* This test calls fi_av_insert() twice with the same raw address, |
| 10 |
* and verifies that returned fi_addr is the same and |
| 11 |
* ibv_create_ah only gets called once. |
| 12 |
* |
| 13 |
* @param[in] state struct efa_resource that is managed by the framework |
| 14 |
*/ |
| 15 |
void test_av_insert_duplicate_raw_addr(struct efa_resource **state) |
| 16 |
{ |
| 17 |
struct efa_resource *resource = *state; |
| 18 |
struct efa_ep_addr raw_addr = {0}; |
| 19 |
size_t raw_addr_len = sizeof(struct efa_ep_addr); |
| 20 |
fi_addr_t addr1, addr2; |
| 21 |
int err, num_addr; |
| 22 |
|
| 23 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 24 |
g_efa_unit_test_mocks.ibv_create_ah = &efa_mock_ibv_create_ah_check_mock; |
| 25 |
|
| 26 |
err = fi_getname(&resource->ep->fid, &raw_addr, &raw_addr_len); |
| 27 |
assert_int_equal(err, 0); |
| 28 |
raw_addr.qpn = 1; |
| 29 |
raw_addr.qkey = 0x1234; |
| 30 |
|
| 31 |
/* the following will_return ensures ibv_create_ah is called exactly once */ |
| 32 |
will_return(efa_mock_ibv_create_ah_check_mock, 0); |
| 33 |
|
| 34 |
num_addr = fi_av_insert(resource->av, &raw_addr, 1, &addr1, 0 /* flags */, NULL /* context */); |
| 35 |
assert_int_equal(num_addr, 1); |
| 36 |
|
| 37 |
num_addr = fi_av_insert(resource->av, &raw_addr, 1, &addr2, 0 /* flags */, NULL /* context */); |
| 38 |
assert_int_equal(num_addr, 1); |
| 39 |
assert_int_equal(addr1, addr2); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* @brief Only works on nodes with EFA devices |
| 44 |
* This test calls fi_av_insert() twice with two difference raw address with same GID, |
| 45 |
* and verifies that returned fi_addr is different and ibv_create_ah only gets called once. |
| 46 |
* this is because libfabric EFA provider has a cache for address handle (AH). |
| 47 |
* |
| 48 |
* @param[in] state struct efa_resource that is managed by the framework |
| 49 |
*/ |
| 50 |
void test_av_insert_duplicate_gid(struct efa_resource **state) |
| 51 |
{ |
| 52 |
struct efa_resource *resource = *state; |
| 53 |
struct efa_ep_addr raw_addr = {0}; |
| 54 |
size_t raw_addr_len = sizeof(struct efa_ep_addr); |
| 55 |
fi_addr_t addr1, addr2; |
| 56 |
int err, num_addr; |
| 57 |
|
| 58 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 59 |
g_efa_unit_test_mocks.ibv_create_ah = &efa_mock_ibv_create_ah_check_mock; |
| 60 |
|
| 61 |
err = fi_getname(&resource->ep->fid, &raw_addr, &raw_addr_len); |
| 62 |
assert_int_equal(err, 0); |
| 63 |
raw_addr.qpn = 1; |
| 64 |
raw_addr.qkey = 0x1234; |
| 65 |
|
| 66 |
/* the following will_return ensures ibv_create_ah is called exactly once */ |
| 67 |
will_return(efa_mock_ibv_create_ah_check_mock, 0); |
| 68 |
|
| 69 |
num_addr = fi_av_insert(resource->av, &raw_addr, 1, &addr1, 0 /* flags */, NULL /* context */); |
| 70 |
assert_int_equal(num_addr, 1); |
| 71 |
|
| 72 |
raw_addr.qpn = 2; |
| 73 |
raw_addr.qkey = 0x5678; |
| 74 |
num_addr = fi_av_insert(resource->av, &raw_addr, 1, &addr2, 0 /* flags */, NULL /* context */); |
| 75 |
assert_int_equal(num_addr, 1); |
| 76 |
assert_int_not_equal(addr1, addr2); |
| 77 |
} |