-
Notifications
You must be signed in to change notification settings - Fork 653
/
test_qp.py
373 lines (351 loc) · 18.1 KB
/
test_qp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
# Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file
"""
Test module for pyverbs' qp module.
"""
import unittest
import random
import errno
import os
from pyverbs.pyverbs_error import PyverbsRDMAError
from pyverbs.qp import QPInitAttr, QPAttr, QP
from tests.base import PyverbsAPITestCase
import pyverbs.enums as e
from pyverbs.pd import PD
from pyverbs.cq import CQ
import tests.utils as u
class QPTest(PyverbsAPITestCase):
"""
Test various functionalities of the QP class.
"""
def test_create_qp_no_attr_connected(self):
"""
Test QP creation via ibv_create_qp without a QPAttr object proivded.
Checked QP types are RC and UC.
"""
for ctx, attr, attr_ex in self.devices:
with PD(ctx) as pd:
with CQ(ctx, 100, None, None, 0) as cq:
qia = get_qp_init_attr(cq, attr)
qia.qp_type = e.IBV_QPT_RC
try:
with QP(pd, qia) as qp:
assert qp.qp_state == e.IBV_QPS_RESET, 'RC QP should have been in RESET'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with RC attrs is not supported')
raise ex
qia.qp_type = e.IBV_QPT_UC
try:
with QP(pd, qia) as qp:
assert qp.qp_state == e.IBV_QPS_RESET, 'UC QP should have been in RESET'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with UC attrs is not supported')
raise ex
def test_create_qp_no_attr(self):
"""
Test QP creation via ibv_create_qp without a QPAttr object proivded.
Checked QP types are Raw Packet and UD. Raw Packet is skipped for
non-root users / Infiniband link layer.
"""
for ctx, attr, attr_ex in self.devices:
with PD(ctx) as pd:
with CQ(ctx, 100, None, None, 0) as cq:
for i in range(1, attr.phys_port_cnt + 1):
qia = get_qp_init_attr(cq, attr)
qia.qp_type = e.IBV_QPT_UD
with QP(pd, qia) as qp:
assert qp.qp_state == e.IBV_QPS_RESET, 'UD QP should have been in RESET'
if u.is_eth(ctx, i) and u.is_root():
qia.qp_type = e.IBV_QPT_RAW_PACKET
try:
with QP(pd, qia) as qp:
assert qp.qp_state == e.IBV_QPS_RESET, 'Raw Packet QP should have been in RESET'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest("Create Raw Packet QP is not supported")
raise ex
def test_create_qp_with_attr_connected(self):
"""
Test QP creation via ibv_create_qp without a QPAttr object proivded.
Checked QP types are RC and UC.
"""
for ctx, attr, attr_ex in self.devices:
with PD(ctx) as pd:
with CQ(ctx, 100, None, None, 0) as cq:
qia = get_qp_init_attr(cq, attr)
qia.qp_type = e.IBV_QPT_RC
try:
with QP(pd, qia, QPAttr()) as qp:
assert qp.qp_state == e.IBV_QPS_INIT, 'RC QP should have been in INIT'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with RC is not supported')
raise ex
qia.qp_type = e.IBV_QPT_UC
try:
with QP(pd, qia, QPAttr()) as qp:
assert qp.qp_state == e.IBV_QPS_INIT, 'UC QP should have been in INIT'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with UC attrs is not supported')
raise ex
def test_create_qp_with_attr(self):
"""
Test QP creation via ibv_create_qp with a QPAttr object proivded.
Checked QP types are Raw Packet and UD. Raw Packet is skipped for
non-root users / Infiniband link layer.
"""
for ctx, attr, attr_ex in self.devices:
with PD(ctx) as pd:
with CQ(ctx, 100, None, None, 0) as cq:
for i in range(1, attr.phys_port_cnt + 1):
qpts = [e.IBV_QPT_UD, e.IBV_QPT_RAW_PACKET] \
if u.is_eth(ctx, i) else [e.IBV_QPT_UD]
qia = get_qp_init_attr(cq, attr)
qia.qp_type = e.IBV_QPT_UD
with QP(pd, qia, QPAttr()) as qp:
assert qp.qp_state == e.IBV_QPS_RTS, 'UD QP should have been in RTS'
if u.is_eth(ctx, i) and u.is_root():
qia.qp_type = e.IBV_QPT_RAW_PACKET
try:
with QP(pd, qia, QPAttr()) as qp:
assert qp.qp_state == e.IBV_QPS_RTS, 'Raw Packet QP should have been in RTS'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest("Create Raw Packet QP is not supported")
raise ex
def test_create_qp_ex_no_attr_connected(self):
"""
Test QP creation via ibv_create_qp_ex without a QPAttr object proivded.
Checked QP types are RC and UC.
"""
for ctx, attr, attr_ex in self.devices:
with PD(ctx) as pd:
with CQ(ctx, 100, None, None, 0) as cq:
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex, e.IBV_QPT_RC)
try:
with QP(ctx, qia) as qp:
assert qp.qp_state == e.IBV_QPS_RESET, 'RC QP should have been in RESET'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex, e.IBV_QPT_UC)
try:
with QP(ctx, qia) as qp:
assert qp.qp_state == e.IBV_QPS_RESET, 'UC QP should have been in RESET'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
def test_create_qp_ex_no_attr(self):
"""
Test QP creation via ibv_create_qp_ex without a QPAttr object proivded.
Checked QP types are Raw Packet and UD. Raw Packet is skipped for
non-root users / Infiniband link layer.
"""
for ctx, attr, attr_ex in self.devices:
with PD(ctx) as pd:
with CQ(ctx, 100, None, None, 0) as cq:
for i in range(1, attr.phys_port_cnt + 1):
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex,
e.IBV_QPT_UD)
try:
with QP(ctx, qia) as qp:
assert qp.qp_state == e.IBV_QPS_RESET, 'UD QP should have been in RESET'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
if u.is_eth(ctx, i) and u.is_root():
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex,
e.IBV_QPT_RAW_PACKET)
try:
with QP(ctx, qia) as qp:
assert qp.qp_state == e.IBV_QPS_RESET, 'Raw Packet QP should have been in RESET'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
def test_create_qp_ex_with_attr_connected(self):
"""
Test QP creation via ibv_create_qp_ex with a QPAttr object proivded.
Checked QP type are RC and UC.
"""
for ctx, attr, attr_ex in self.devices:
with PD(ctx) as pd:
with CQ(ctx, 100, None, None, 0) as cq:
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex,
e.IBV_QPT_RC)
try:
with QP(ctx, qia, QPAttr()) as qp:
assert qp.qp_state == e.IBV_QPS_INIT, 'RC QP should have been in INIT'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex,
e.IBV_QPT_UC)
try:
with QP(ctx, qia, QPAttr()) as qp:
assert qp.qp_state == e.IBV_QPS_INIT, 'UC QP should have been in INIT'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
def test_create_qp_ex_with_attr(self):
"""
Test QP creation via ibv_create_qp_ex with a QPAttr object proivded.
Checked QP types are Raw Packet and UD. Raw Packet is skipped for
non-root users / Infiniband link layer.
"""
for ctx, attr, attr_ex in self.devices:
with PD(ctx) as pd:
with CQ(ctx, 100, None, None, 0) as cq:
for i in range(1, attr.phys_port_cnt + 1):
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex,
e.IBV_QPT_UD)
try:
with QP(ctx, qia, QPAttr()) as qp:
assert qp.qp_state == e.IBV_QPS_RTS, 'UD QP should have been in RTS'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
if u.is_eth(ctx, i) and u.is_root():
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex,
e.IBV_QPT_RAW_PACKET)
try:
with QP(ctx, qia, QPAttr()) as qp:
assert qp.qp_state == e.IBV_QPS_RTS, 'Raw Packet QP should have been in RTS'
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
def test_query_qp(self):
"""
Queries a QP after creation. Verifies that its properties are as
expected.
"""
for ctx, attr, attr_ex in self.devices:
with PD(ctx) as pd:
with CQ(ctx, 100, None, None, 0) as cq:
for i in range(1, attr.phys_port_cnt + 1):
qpts = get_qp_types(ctx, i)
for qpt in qpts:
# Extended QP
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex,
qpt)
caps = qia.cap # Save them to verify values later
try:
qp = QP(ctx, qia)
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
qp_attr, qp_init_attr = qp.query(e.IBV_QP_STATE |
e.IBV_QP_CAP)
verify_qp_attrs(caps, e.IBV_QPS_RESET, qp_init_attr,
qp_attr)
# Legacy QP
qia = get_qp_init_attr(cq, attr)
qia.qp_type = qpt
caps = qia.cap # Save them to verify values later
qp = QP(pd, qia)
qp_attr, qp_init_attr = qp.query(e.IBV_QP_STATE |
e.IBV_QP_CAP)
verify_qp_attrs(caps, e.IBV_QPS_RESET, qp_init_attr,
qp_attr)
def test_modify_qp(self):
"""
Queries a QP after calling modify(). Verifies that its properties are
as expected.
"""
for ctx, attr, attr_ex in self.devices:
with PD(ctx) as pd:
with CQ(ctx, 100, None, None, 0) as cq:
# Extended QP
qia = get_qp_init_attr_ex(cq, pd, attr, attr_ex, e.IBV_QPT_UD)
try:
qp = QP(ctx, qia)
except PyverbsRDMAError as ex:
if ex.error_code == errno.EOPNOTSUPP:
raise unittest.SkipTest('Create QP with extended attrs is not supported')
raise ex
qa = QPAttr()
qa.qkey = 0x123
qp.to_init(qa)
qp_attr, qp_iattr = qp.query(e.IBV_QP_QKEY)
assert qp_attr.qkey == qa.qkey, 'Extended QP, QKey is not as expected'
qp.to_rtr(qa)
qa.sq_psn = 0x45
qp.to_rts(qa)
qp_attr, qp_iattr = qp.query(e.IBV_QP_SQ_PSN)
assert qp_attr.sq_psn == qa.sq_psn, 'Extended QP, SQ PSN is not as expected'
qa.qp_state = e.IBV_QPS_RESET
qp.modify(qa, e.IBV_QP_STATE)
assert qp.qp_state == e.IBV_QPS_RESET, 'Extended QP, QP state is not as expected'
# Legacy QP
qia = get_qp_init_attr(cq, attr)
qp = QP(pd, qia)
qa = QPAttr()
qa.qkey = 0x123
qp.to_init(qa)
qp_attr, qp_iattr = qp.query(e.IBV_QP_QKEY)
assert qp_attr.qkey == qa.qkey, 'Legacy QP, QKey is not as expected'
qp.to_rtr(qa)
qa.sq_psn = 0x45
qp.to_rts(qa)
qp_attr, qp_iattr = qp.query(e.IBV_QP_SQ_PSN)
assert qp_attr.sq_psn == qa.sq_psn, 'Legacy QP, SQ PSN is not as expected'
qa.qp_state = e.IBV_QPS_RESET
qp.modify(qa, e.IBV_QP_STATE)
assert qp.qp_state == e.IBV_QPS_RESET, 'Legacy QP, QP state is not as expected'
def get_qp_types(ctx, port_num):
"""
Returns a list of the commonly used QP types. Raw Packet QP will not be
included if link layer is not Ethernet or it current user is not root.
:param ctx: The device's Context, to query the port's link layer
:param port_num: Port number to query
:return: An array of QP types that can be created on this port
"""
qpts = [e.IBV_QPT_RC, e.IBV_QPT_UC, e.IBV_QPT_UD]
if u.is_eth(ctx, port_num) and u.is_root():
qpts.append(e.IBV_QPT_RAW_PACKET)
return qpts
def verify_qp_attrs(orig_cap, state, init_attr, attr):
assert state == attr.cur_qp_state
assert orig_cap.max_send_wr <= init_attr.cap.max_send_wr
assert orig_cap.max_recv_wr <= init_attr.cap.max_recv_wr
assert orig_cap.max_send_sge <= init_attr.cap.max_send_sge
assert orig_cap.max_recv_sge <= init_attr.cap.max_recv_sge
assert orig_cap.max_inline_data <= init_attr.cap.max_inline_data
def get_qp_init_attr(cq, attr):
"""
Creates a QPInitAttr object with a QP type of the provided <qpts> array and
other random values.
:param cq: CQ to be used as send and receive CQ
:param attr: Device attributes for capability checks
:return: An initialized QPInitAttr object
"""
qp_cap = u.random_qp_cap(attr)
sig = random.randint(0, 1)
return QPInitAttr(scq=cq, rcq=cq, cap=qp_cap, sq_sig_all=sig)
def get_qp_init_attr_ex(cq, pd, attr, attr_ex, qpt):
"""
Creates a QPInitAttrEx object with a QP type of the provided <qpts> array
and other random values.
:param cq: CQ to be used as send and receive CQ
:param pd: A PD object to use
:param attr: Device attributes for capability checks
:param attr_ex: Extended device attributes for capability checks
:param qpt: QP type
:return: An initialized QPInitAttrEx object
"""
qia = u.random_qp_init_attr_ex(attr_ex, attr, qpt)
qia.send_cq = cq
qia.recv_cq = cq
qia.pd = pd # Only XRCD can be created without a PD
return qia