| 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 |
#ifndef EFA_UNIT_TESTS_H |
| 5 |
#define EFA_UNIT_TESTS_H |
| 6 |
|
| 7 |
#define _GNU_SOURCE |
| 8 |
|
| 9 |
#define MR_MODE_BITS FI_MR_VIRT_ADDR | FI_MR_ALLOCATED | FI_MR_PROV_KEY | FI_MR_LOCAL |
| 10 |
|
| 11 |
#include <stdlib.h> |
| 12 |
#include <stdint.h> |
| 13 |
#include <stdarg.h> |
| 14 |
#include <stddef.h> |
| 15 |
#include <setjmp.h> |
| 16 |
#include <cmocka.h> |
| 17 |
#include "stdio.h" |
| 18 |
#include "efa.h" |
| 19 |
#include "efa_unit_test_mocks.h" |
| 20 |
|
| 21 |
extern struct efa_mock_ibv_send_wr_list g_ibv_send_wr_list; |
| 22 |
extern struct efa_unit_test_mocks g_efa_unit_test_mocks; |
| 23 |
extern struct efa_env efa_env; |
| 24 |
|
| 25 |
struct efa_resource { |
| 26 |
struct fi_info *hints; |
| 27 |
struct fi_info *info; |
| 28 |
struct fid_fabric *fabric; |
| 29 |
struct fid_domain *domain; |
| 30 |
struct fid_ep *ep; |
| 31 |
struct fid_eq *eq; |
| 32 |
struct fid_av *av; |
| 33 |
struct fid_cq *cq; |
| 34 |
}; |
| 35 |
|
| 36 |
struct fi_info *efa_unit_test_alloc_hints(enum fi_ep_type ep_type, char *fabric_name); |
| 37 |
struct fi_info *efa_unit_test_alloc_hints_hmem(enum fi_ep_type ep_type, char *fabric_name); |
| 38 |
|
| 39 |
void efa_unit_test_resource_construct(struct efa_resource *resource, enum fi_ep_type ep_type, char *fabric_name); |
| 40 |
void efa_unit_test_resource_construct_ep_not_enabled( |
| 41 |
struct efa_resource *resource, enum fi_ep_type ep_type, char *fabric_name); |
| 42 |
void efa_unit_test_resource_construct_no_cq_and_ep_not_enabled( |
| 43 |
struct efa_resource *resource, enum fi_ep_type ep_type, char *fabric_name); |
| 44 |
void efa_unit_test_resource_construct_with_hints(struct efa_resource *resource, |
| 45 |
enum fi_ep_type ep_type, |
| 46 |
uint32_t fi_version, struct fi_info *hints, |
| 47 |
bool enable_ep, bool open_cq); |
| 48 |
|
| 49 |
void efa_unit_test_resource_construct_rdm_shm_disabled(struct efa_resource *resource); |
| 50 |
|
| 51 |
void efa_unit_test_resource_destruct(struct efa_resource *resource); |
| 52 |
|
| 53 |
void efa_unit_test_construct_msg(struct fi_msg *msg, struct iovec *iov, |
| 54 |
size_t iov_count, fi_addr_t addr, |
| 55 |
void *context, uint64_t data, |
| 56 |
void **desc); |
| 57 |
|
| 58 |
void efa_unit_test_construct_tmsg(struct fi_msg_tagged *tmsg, struct iovec *iov, |
| 59 |
size_t iov_count, fi_addr_t addr, |
| 60 |
void *context, uint64_t data, |
| 61 |
void **desc, uint64_t tag, |
| 62 |
uint64_t ignore); |
| 63 |
|
| 64 |
void efa_unit_test_construct_msg_rma(struct fi_msg_rma *msg, struct iovec *iov, |
| 65 |
void **desc, size_t iov_count, |
| 66 |
fi_addr_t addr, struct fi_rma_iov *rma_iov, |
| 67 |
size_t rma_iov_count, void *context, |
| 68 |
uint64_t data); |
| 69 |
|
| 70 |
void new_temp_file(char *template, size_t len); |
| 71 |
|
| 72 |
struct efa_unit_test_buff { |
| 73 |
uint8_t *buff; |
| 74 |
size_t size; |
| 75 |
struct fid_mr *mr; |
| 76 |
}; |
| 77 |
|
| 78 |
struct efa_unit_test_eager_rtm_pkt_attr { |
| 79 |
uint32_t msg_id; |
| 80 |
uint32_t connid; |
| 81 |
}; |
| 82 |
|
| 83 |
struct efa_unit_test_handshake_pkt_attr { |
| 84 |
uint32_t connid; |
| 85 |
uint64_t host_id; |
| 86 |
uint32_t device_version; |
| 87 |
}; |
| 88 |
|
| 89 |
int efa_device_construct(struct efa_device *efa_device, |
| 90 |
int device_idx, |
| 91 |
struct ibv_device *ibv_device); |
| 92 |
|
| 93 |
void efa_unit_test_buff_construct(struct efa_unit_test_buff *buff, struct efa_resource *resource, size_t buff_size); |
| 94 |
|
| 95 |
void efa_unit_test_buff_destruct(struct efa_unit_test_buff *buff); |
| 96 |
|
| 97 |
void efa_unit_test_eager_msgrtm_pkt_construct(struct efa_rdm_pke *pkt_entry, struct efa_unit_test_eager_rtm_pkt_attr *attr); |
| 98 |
|
| 99 |
void efa_unit_test_handshake_pkt_construct(struct efa_rdm_pke *pkt_entry, struct efa_unit_test_handshake_pkt_attr *attr); |
| 100 |
|
| 101 |
struct efa_rdm_ope *efa_unit_test_alloc_txe(struct efa_resource *resource, uint32_t op); |
| 102 |
|
| 103 |
struct efa_rdm_ope *efa_unit_test_alloc_rxe(struct efa_resource *resource, uint32_t op); |
| 104 |
|
| 105 |
/* test cases */ |
| 106 |
|
| 107 |
/* begin efa_unit_test_av.c */ |
| 108 |
void test_av_insert_duplicate_raw_addr(); |
| 109 |
void test_av_insert_duplicate_gid(); |
| 110 |
/* end efa_unit_test_av.c */ |
| 111 |
|
| 112 |
void test_efa_device_construct_error_handling(); |
| 113 |
void test_efa_rdm_ep_ignore_missing_host_id_file(); |
| 114 |
void test_efa_rdm_ep_has_valid_host_id(); |
| 115 |
void test_efa_rdm_ep_ignore_short_host_id(); |
| 116 |
void test_efa_rdm_ep_ignore_non_hex_host_id(); |
| 117 |
void test_efa_rdm_ep_handshake_receive_and_send_valid_host_ids_with_connid(); |
| 118 |
void test_efa_rdm_ep_handshake_receive_and_send_valid_host_ids_without_connid(); |
| 119 |
void test_efa_rdm_ep_handshake_receive_valid_peer_host_id_and_do_not_send_local_host_id(); |
| 120 |
void test_efa_rdm_ep_handshake_receive_without_peer_host_id_and_do_not_send_local_host_id(); |
| 121 |
void test_efa_rdm_ep_getopt_undersized_optlen(); |
| 122 |
void test_efa_rdm_ep_getopt_oversized_optlen(); |
| 123 |
void test_efa_rdm_ep_pkt_pool_flags(); |
| 124 |
void test_efa_rdm_ep_pkt_pool_page_alignment(); |
| 125 |
void test_efa_rdm_ep_dc_atomic_queue_before_handshake(); |
| 126 |
void test_efa_rdm_ep_dc_send_queue_before_handshake(); |
| 127 |
void test_efa_rdm_ep_dc_send_queue_limit_before_handshake(); |
| 128 |
void test_efa_rdm_ep_write_queue_before_handshake(); |
| 129 |
void test_efa_rdm_ep_read_queue_before_handshake(); |
| 130 |
void test_efa_rdm_ep_trigger_handshake(); |
| 131 |
void test_efa_rdm_read_copy_pkt_pool_128_alignment(); |
| 132 |
void test_efa_rdm_ep_send_with_shm_no_copy(); |
| 133 |
void test_efa_rdm_ep_rma_without_caps(); |
| 134 |
void test_efa_rdm_ep_atomic_without_caps(); |
| 135 |
void test_efa_rdm_ep_setopt_shared_memory_permitted(); |
| 136 |
void test_efa_rdm_ep_enable_qp_in_order_aligned_128_bytes_good(); |
| 137 |
void test_efa_rdm_ep_enable_qp_in_order_aligned_128_bytes_bad(); |
| 138 |
void test_efa_rdm_ep_user_zcpy_rx_disabled(); |
| 139 |
void test_efa_rdm_ep_user_disable_p2p_zcpy_rx_disabled(); |
| 140 |
void test_efa_rdm_ep_user_zcpy_rx_unhappy_due_to_sas(); |
| 141 |
void test_efa_rdm_ep_user_p2p_not_supported_zcpy_rx_happy(); |
| 142 |
void test_efa_rdm_ep_user_zcpy_rx_unhappy_due_to_no_mr_local(); |
| 143 |
void test_efa_rdm_ep_close_discard_posted_recv(); |
| 144 |
void test_efa_rdm_ep_zcpy_recv_cancel(); |
| 145 |
void test_efa_rdm_ep_zcpy_recv_eagain(); |
| 146 |
void test_efa_rdm_ep_post_handshake_error_handling_pke_exhaustion(); |
| 147 |
void test_efa_rdm_ep_rx_refill_threshold_smaller_than_rx_size(); |
| 148 |
void test_efa_rdm_ep_rx_refill_threshold_larger_than_rx_size(); |
| 149 |
void test_efa_rdm_ep_support_unsolicited_write_recv(); |
| 150 |
void test_efa_rdm_ep_rma_inconsistent_unsolicited_write_recv(); |
| 151 |
void test_efa_rdm_ep_default_sizes(); |
| 152 |
void test_dgram_cq_read_empty_cq(); |
| 153 |
void test_ibv_cq_ex_read_empty_cq(); |
| 154 |
void test_ibv_cq_ex_read_failed_poll(); |
| 155 |
void test_rdm_cq_create_error_handling(); |
| 156 |
void test_rdm_cq_read_bad_send_status_unresponsive_receiver(); |
| 157 |
void test_rdm_cq_read_bad_send_status_unresponsive_receiver_missing_peer_host_id(); |
| 158 |
void test_rdm_cq_read_bad_send_status_unreachable_receiver(); |
| 159 |
void test_rdm_cq_read_bad_send_status_invalid_qpn(); |
| 160 |
void test_rdm_cq_read_bad_send_status_message_too_long(); |
| 161 |
void test_ibv_cq_ex_read_bad_recv_status(); |
| 162 |
void test_ibv_cq_ex_read_bad_recv_rdma_with_imm_status_use_unsolicited_recv(); |
| 163 |
void test_ibv_cq_ex_read_bad_recv_rdma_with_imm_status_use_solicited_recv(); |
| 164 |
void test_ibv_cq_ex_read_recover_forgotten_peer_ah(); |
| 165 |
void test_rdm_fallback_to_ibv_create_cq_ex_cq_read_ignore_forgotton_peer(); |
| 166 |
void test_ibv_cq_ex_read_ignore_removed_peer(); |
| 167 |
|
| 168 |
/* begin efa_unit_test_info.c */ |
| 169 |
void test_info_open_ep_with_wrong_info(); |
| 170 |
void test_info_rdm_attributes(); |
| 171 |
void test_info_dgram_attributes(); |
| 172 |
void test_info_direct_attributes_no_rma(); |
| 173 |
void test_info_direct_attributes_rma(); |
| 174 |
void test_info_direct_hmem_support_p2p(); |
| 175 |
void test_info_tx_rx_msg_order_rdm_order_none(); |
| 176 |
void test_info_tx_rx_msg_order_rdm_order_sas(); |
| 177 |
void test_info_tx_rx_msg_order_dgram_order_none(); |
| 178 |
void test_info_tx_rx_msg_order_dgram_order_sas(); |
| 179 |
void test_info_max_order_size_dgram_with_atomic(); |
| 180 |
void test_info_max_order_size_rdm_with_atomic_no_order(); |
| 181 |
void test_info_max_order_size_rdm_with_atomic_order(); |
| 182 |
void test_info_tx_rx_op_flags_rdm(); |
| 183 |
void test_info_tx_rx_size_rdm(); |
| 184 |
void test_info_check_shm_info_hmem(); |
| 185 |
void test_info_check_shm_info_op_flags(); |
| 186 |
void test_info_check_shm_info_threading(); |
| 187 |
void test_info_check_hmem_cuda_support_on_api_lt_1_18(); |
| 188 |
void test_info_check_hmem_cuda_support_on_api_ge_1_18(); |
| 189 |
void test_info_check_no_hmem_support_when_not_requested(); |
| 190 |
void test_info_direct_unsupported(); |
| 191 |
void test_info_direct_ordering(); |
| 192 |
void test_efa_hmem_info_update_neuron(); |
| 193 |
void test_efa_hmem_info_disable_p2p_neuron(); |
| 194 |
void test_efa_hmem_info_disable_p2p_cuda(); |
| 195 |
void test_efa_nic_select_all_devices_matches(); |
| 196 |
void test_efa_nic_select_first_device_matches(); |
| 197 |
void test_efa_nic_select_first_device_with_surrounding_comma_matches(); |
| 198 |
void test_efa_nic_select_first_device_first_letter_no_match(); |
| 199 |
void test_efa_nic_select_empty_device_no_match(); |
| 200 |
void test_efa_use_device_rdma_env1_opt1(); |
| 201 |
void test_efa_use_device_rdma_env0_opt0(); |
| 202 |
void test_efa_use_device_rdma_env1_opt0(); |
| 203 |
void test_efa_use_device_rdma_env0_opt1(); |
| 204 |
void test_efa_use_device_rdma_opt1(); |
| 205 |
void test_efa_use_device_rdma_opt0(); |
| 206 |
void test_efa_use_device_rdma_env1(); |
| 207 |
void test_efa_use_device_rdma_env0(); |
| 208 |
void test_efa_use_device_rdma_opt_old(); |
| 209 |
/* end efa_unit_test_info.c */ |
| 210 |
|
| 211 |
void test_efa_srx_min_multi_recv_size(); |
| 212 |
void test_efa_srx_cq(); |
| 213 |
void test_efa_srx_lock(); |
| 214 |
void test_efa_srx_unexp_pkt(); |
| 215 |
void test_efa_rnr_queue_and_resend(); |
| 216 |
void test_efa_rdm_ope_prepare_to_post_send_with_no_enough_tx_pkts(); |
| 217 |
void test_efa_rdm_ope_prepare_to_post_send_host_memory(); |
| 218 |
void test_efa_rdm_ope_prepare_to_post_send_host_memory_align128(); |
| 219 |
void test_efa_rdm_ope_prepare_to_post_send_cuda_memory(); |
| 220 |
void test_efa_rdm_ope_prepare_to_post_send_cuda_memory_align128(); |
| 221 |
void test_efa_rdm_ope_post_write_0_byte(); |
| 222 |
void test_efa_rdm_rxe_post_local_read_or_queue_unhappy(); |
| 223 |
void test_efa_rdm_rxe_post_local_read_or_queue_happy(); |
| 224 |
void test_efa_rdm_txe_handle_error_write_cq(); |
| 225 |
void test_efa_rdm_txe_handle_error_not_write_cq(); |
| 226 |
void test_efa_rdm_rxe_handle_error_write_cq(); |
| 227 |
void test_efa_rdm_rxe_handle_error_not_write_cq(); |
| 228 |
void test_efa_rdm_rxe_map(); |
| 229 |
void test_efa_rdm_msg_send_to_local_peer_with_null_desc(); |
| 230 |
void test_efa_fork_support_request_initialize_when_ibv_fork_support_is_needed(); |
| 231 |
void test_efa_fork_support_request_initialize_when_ibv_fork_support_is_unneeded(); |
| 232 |
void test_efa_rdm_peer_get_runt_size_no_enough_runt(); |
| 233 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_smaller_than_alignment(); |
| 234 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_exceeding_total_len(); |
| 235 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_normal(); |
| 236 |
void test_efa_rdm_peer_get_runt_size_host_memory_smaller_than_alignment(); |
| 237 |
void test_efa_rdm_peer_get_runt_size_host_memory_exceeding_total_len(); |
| 238 |
void test_efa_rdm_peer_get_runt_size_host_memory_normal(); |
| 239 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_128_multiple_alignment(); |
| 240 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_non_128_multiple_alignment(); |
| 241 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_smaller_than_128_alignment(); |
| 242 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_exceeding_total_len_128_alignment(); |
| 243 |
void test_efa_rdm_peer_select_readbase_rtm_no_runt(); |
| 244 |
void test_efa_rdm_peer_select_readbase_rtm_do_runt(); |
| 245 |
void test_efa_rdm_pke_get_available_copy_methods_align128(); |
| 246 |
|
| 247 |
/* begin efa_unit_test_domain.c */ |
| 248 |
void test_efa_domain_info_type_efa_direct(); |
| 249 |
void test_efa_domain_info_type_efa_rdm(); |
| 250 |
void test_efa_domain_open_ops_wrong_name(); |
| 251 |
void test_efa_domain_open_ops_mr_query(); |
| 252 |
/* end efa_unit_test_domain.c */ |
| 253 |
|
| 254 |
void test_efa_rdm_cq_ibv_cq_poll_list_same_tx_rx_cq_single_ep(); |
| 255 |
void test_efa_rdm_cq_ibv_cq_poll_list_separate_tx_rx_cq_single_ep(); |
| 256 |
void test_efa_rdm_cq_post_initial_rx_pkts(); |
| 257 |
void test_efa_rdm_cntr_ibv_cq_poll_list_same_tx_rx_cq_single_ep(); |
| 258 |
void test_efa_rdm_cntr_ibv_cq_poll_list_separate_tx_rx_cq_single_ep(); |
| 259 |
void test_efa_rdm_cntr_post_initial_rx_pkts(); |
| 260 |
void test_efa_rdm_peer_reorder_expected_msg_id(); |
| 261 |
void test_efa_rdm_peer_reorder_smaller_msg_id(); |
| 262 |
void test_efa_rdm_peer_reorder_larger_msg_id(); |
| 263 |
void test_efa_rdm_peer_reorder_overflow_msg_id(); |
| 264 |
void test_efa_rdm_peer_move_overflow_pke_to_recvwin(); |
| 265 |
void test_efa_rdm_peer_keep_pke_in_overflow_list(); |
| 266 |
void test_efa_rdm_peer_append_overflow_pke_to_recvwin(); |
| 267 |
void test_efa_rdm_pke_handle_longcts_rtm_send_completion(); |
| 268 |
void test_efa_rdm_pke_release_rx_list(); |
| 269 |
void test_efa_rdm_pke_alloc_rta_rxe(); |
| 270 |
void test_efa_rdm_pke_alloc_rtw_rxe(); |
| 271 |
void test_efa_rdm_pke_alloc_rtr_rxe(); |
| 272 |
void test_efa_msg_fi_recv(); |
| 273 |
void test_efa_msg_fi_recvv(); |
| 274 |
void test_efa_msg_fi_recvmsg(); |
| 275 |
void test_efa_msg_fi_send(); |
| 276 |
void test_efa_msg_fi_sendv(); |
| 277 |
void test_efa_msg_fi_sendmsg(); |
| 278 |
void test_efa_msg_fi_senddata(); |
| 279 |
void test_efa_msg_fi_inject(); |
| 280 |
void test_efa_msg_fi_injectdata(); |
| 281 |
void test_efa_rma_read(); |
| 282 |
void test_efa_rma_readv(); |
| 283 |
void test_efa_rma_readmsg(); |
| 284 |
void test_efa_rma_write(); |
| 285 |
void test_efa_rma_writev(); |
| 286 |
void test_efa_rma_writemsg(); |
| 287 |
void test_efa_rma_writedata(); |
| 288 |
void test_efa_rma_inject_write(); |
| 289 |
void test_efa_rma_inject_writedata(); |
| 290 |
void test_efa_rma_writemsg_with_inject(); |
| 291 |
void test_efa_cq_read_no_completion(); |
| 292 |
void test_efa_cq_read_send_success(); |
| 293 |
void test_efa_cq_read_senddata_success(); |
| 294 |
void test_efa_cq_read_read_success(); |
| 295 |
void test_efa_cq_read_write_success(); |
| 296 |
void test_efa_cq_read_writedata_success(); |
| 297 |
void test_efa_cq_read_recv_success(); |
| 298 |
void test_efa_cq_read_recv_rdma_with_imm_success(); |
| 299 |
void test_efa_cq_read_send_failure(); |
| 300 |
void test_efa_cq_read_recv_failure(); |
| 301 |
void test_efa_cq_recv_rdma_with_imm_failure(); |
| 302 |
void test_efa_ep_open(); |
| 303 |
void test_efa_ep_cancel(); |
| 304 |
void test_efa_ep_getopt(); |
| 305 |
void test_efa_ep_setopt_use_device_rdma(); |
| 306 |
void test_efa_ep_setopt_hmem_p2p(); |
| 307 |
void test_efa_ep_setopt_rnr_retry(); |
| 308 |
void test_efa_ep_setopt_sizes(); |
| 309 |
void test_efa_ep_bind_and_enable(); |
| 310 |
void test_efa_cntr_ibv_cq_poll_list_same_tx_rx_cq_single_ep(); |
| 311 |
void test_efa_cntr_ibv_cq_poll_list_separate_tx_rx_cq_single_ep(); |
| 312 |
|
| 313 |
/* begin efa_unit_test_mr.c */ |
| 314 |
void test_efa_rdm_mr_reg_host_memory(); |
| 315 |
void test_efa_rdm_mr_reg_cuda_memory(); |
| 316 |
void test_efa_direct_mr_reg_no_gdrcopy(); |
| 317 |
/* end efa_unit_test_mr.c */ |
| 318 |
|
| 319 |
static inline |
| 320 |
int efa_unit_test_get_dlist_length(struct dlist_entry *head) |
| 321 |
{ |
| 322 |
int i = 0; |
| 323 |
struct dlist_entry *item; |
| 324 |
|
| 325 |
dlist_foreach(head, item) { |
| 326 |
i++; |
| 327 |
} |
| 328 |
|
| 329 |
return i; |
| 330 |
} |
| 331 |
#endif |