blob: 6b9fb1378159fba8e328afef01ce1fc85360e5a8 [file] [log] [blame]
Leon Romanovsky51940842015-11-08 14:39:44 +02001/**
2 * Copyright (C) 2015 Mellanox Technologies Ltd. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29#ifndef _IBVERBS_VERBS_TEST_
30#define _IBVERBS_VERBS_TEST_
31#include "common.h"
32#include <infiniband/verbs.h>
Leon Romanovsky51940842015-11-08 14:39:44 +020033
34/**
35 * Base class for ibverbs test fixtures.
36 * Initialize and close ibverbs.
37 */
38class verbs_test : public testing::Test {
39protected:
40 virtual void SetUp() {
41 int num_devices = 0;
42 int i = 0;
43
Leon Romanovsky51940842015-11-08 14:39:44 +020044 /*
45 * First you must retrieve the list of available IB devices on the local host.
46 * Every device in this list contains both a name and a GUID.
47 * For example the device names can be: mthca0, mlx4_1.
48 */
49 dev_list = ibv_get_device_list(&num_devices);
Artemy Kovalyovfc636ed2016-11-27 13:16:39 +020050 ASSERT_TRUE(dev_list != NULL) << "error: " << errno;
Leon Romanovsky51940842015-11-08 14:39:44 +020051 ASSERT_TRUE(num_devices);
52
53 /*
54 * Iterate over the device list, choose a device according to its GUID or name
55 * and open it.
56 */
57 for (i = 0; i < num_devices; ++i) {
58 if (!strncmp(ibv_get_device_name(dev_list[i]),
59 gtest_dev_name, strlen(gtest_dev_name))) {
60 ibv_dev = dev_list[i];
61 break;
62 }
63 }
64 ASSERT_TRUE(ibv_dev != NULL);
65
66 ibv_ctx = ibv_open_device(ibv_dev);
67 ASSERT_TRUE(ibv_ctx != NULL);
68 }
69
70 virtual void TearDown() {
71
72 /*
73 * Destroy objects in the reverse order you created them:
74 * Delete QP
75 * Delete CQ
76 * Deregister MR
77 * Deallocate PD
78 * Close device
79 */
80 ibv_close_device(ibv_ctx);
81 ibv_free_device_list(dev_list);
82 }
83
84protected:
85 struct ibv_device **dev_list;
86 struct ibv_device *ibv_dev;
87 struct ibv_context *ibv_ctx;
Leon Romanovskybe68d5a2015-11-10 12:16:55 +020088
89 // Set it to be TRUE, if the test should be skipped
90 bool skip_this_test;
Leon Romanovsky51940842015-11-08 14:39:44 +020091};
Leon Romanovsky5a9676d2015-11-11 08:37:09 +020092
93#pragma pack( push, 1 )
94struct test_entry {
95 int lid; /* LID of the IB port */
96 int qpn; /* QP number */
97 int psn;
98 uint32_t rkey; /* Remote key */
99 uintptr_t vaddr; /* Buffer address */
100
101 union ibv_gid gid; /* GID of the IB port */
102};
103#pragma pack( pop )
104
105struct test_context {
106 struct ibv_context *context; /* Device context */
107 struct ibv_pd *pd; /* Protection domain (PD) */
108 struct ibv_mr *mr; /* Memory region (MR) */
109 struct ibv_cq *scq; /* Send completion queue (sCQ) */
110 struct ibv_cq *rcq; /* Receive completion queue (rCQ) */
111 struct ibv_qp *qp; /* Queue pair (QP) */
112 struct ibv_cq *mcq; /* Managed completion queue (mCQ) */
113 struct ibv_qp *mqp; /* Managed queue pair (mQP) */
114 struct ibv_ah *ah; /* Address handle (AH) */
115 struct ibv_wc *wc; /* Work completion array */
116 void *net_buf; /* Memory buffer pointer, used for RDMA and send */
117 void *buf; /* Local memory buffer */
118 int size;
119 int cq_tx_depth;
120 int cq_rx_depth;
121 int qp_tx_depth;
122 int qp_rx_depth;
123 int port;
124 struct test_entry my_info; /* Local information */
125 struct test_entry peer_info; /* Remote information */
126
127 void *last_result;
128 const char *str_input;
129 int pending;
130};
131
Leon Romanovsky51940842015-11-08 14:39:44 +0200132#endif //_IBVERBS_VERBS_TEST_