| 1 |
from tests.base import RCResources, UDResources, XRCResources, RDMATestCase, \ |
| 2 |
PyverbsAPITestCase |
| 3 |
from pyverbs.pyverbs_error import PyverbsRDMAError |
| 4 |
from pyverbs.cq import CqInitAttrEx, CQEX |
| 5 |
from pyverbs.libibverbs_enums import ibv_access_flags, ibv_raw_packet_caps, ibv_create_cq_wc_flags, \ |
| 6 |
ibv_cq_init_attr_mask, ibv_create_cq_attr_flags, IBV_WC_STANDARD_FLAGS |
| 7 |
from pyverbs.mr import MR |
| 8 |
import tests.utils as u |
| 9 |
import unittest |
| 10 |
import errno |
| 11 |
|
| 12 |
|
| 13 |
def create_ex_cq(res): |
| 14 |
""" |
| 15 |
Create an Extended CQ using res's context and assign it to res's cq member. |
| 16 |
IBV_WC_STANDARD_FLAGS is used for WC flags to avoid support differences |
| 17 |
between devices. |
| 18 |
:param res: An instance of TrafficResources |
| 19 |
""" |
| 20 |
wc_flags = IBV_WC_STANDARD_FLAGS |
| 21 |
cia = CqInitAttrEx(cqe=2000, wc_flags=wc_flags) |
| 22 |
try: |
| 23 |
res.cq = CQEX(res.ctx, cia) |
| 24 |
except PyverbsRDMAError as ex: |
| 25 |
if ex.error_code == errno.EOPNOTSUPP: |
| 26 |
raise unittest.SkipTest('Create Extended CQ is not supported') |
| 27 |
raise ex |
| 28 |
|
| 29 |
class CqExUD(UDResources): |
| 30 |
def create_cq(self): |
| 31 |
create_ex_cq(self) |
| 32 |
|
| 33 |
def create_mr(self): |
| 34 |
self.mr = MR(self.pd, self.msg_size + self.GRH_SIZE, |
| 35 |
ibv_access_flags.IBV_ACCESS_LOCAL_WRITE) |
| 36 |
|
| 37 |
|
| 38 |
class CqExRC(RCResources): |
| 39 |
def create_cq(self): |
| 40 |
create_ex_cq(self) |
| 41 |
|
| 42 |
|
| 43 |
class CqExXRC(XRCResources): |
| 44 |
def create_cq(self): |
| 45 |
create_ex_cq(self) |
| 46 |
|
| 47 |
|
| 48 |
class CqExTestCase(RDMATestCase): |
| 49 |
""" |
| 50 |
Run traffic over the existing UD, RC and XRC infrastructure, but use |
| 51 |
ibv_cq_ex instead of legacy ibv_cq |
| 52 |
""" |
| 53 |
def setUp(self): |
| 54 |
super().setUp() |
| 55 |
self.iters = 100 |
| 56 |
|
| 57 |
def test_ud_traffic_cq_ex(self): |
| 58 |
self.create_players(CqExUD) |
| 59 |
u.traffic(**self.traffic_args, is_cq_ex=True) |
| 60 |
|
| 61 |
def test_rc_traffic_cq_ex(self): |
| 62 |
self.create_players(CqExRC) |
| 63 |
u.traffic(**self.traffic_args, is_cq_ex=True) |
| 64 |
|
| 65 |
def test_xrc_traffic_cq_ex(self): |
| 66 |
self.create_players(CqExXRC) |
| 67 |
u.xrc_traffic(self.client, self.server, is_cq_ex=True) |
| 68 |
|
| 69 |
|
| 70 |
class CQEXAPITest(PyverbsAPITestCase): |
| 71 |
""" |
| 72 |
Test the API of the CQEX class. |
| 73 |
""" |
| 74 |
def setUp(self): |
| 75 |
super().setUp() |
| 76 |
self.max_cqe = self.attr.max_cqe |
| 77 |
|
| 78 |
def test_create_cq_ex(self): |
| 79 |
""" |
| 80 |
Test ibv_create_cq_ex() |
| 81 |
""" |
| 82 |
cq_init_attrs_ex = CqInitAttrEx(cqe=10, wc_flags=0, comp_mask=0, flags=0) |
| 83 |
if self.attr_ex.raw_packet_caps & ibv_raw_packet_caps.IBV_RAW_PACKET_CAP_CVLAN_STRIPPING: |
| 84 |
cq_init_attrs_ex.wc_flags = ibv_create_cq_wc_flags.IBV_WC_EX_WITH_CVLAN |
| 85 |
CQEX(self.ctx, cq_init_attrs_ex) |
| 86 |
|
| 87 |
for flag in list(ibv_create_cq_wc_flags): |
| 88 |
cq_init_attrs_ex.wc_flags = flag |
| 89 |
try: |
| 90 |
cq_ex = CQEX(self.ctx, cq_init_attrs_ex) |
| 91 |
cq_ex.close() |
| 92 |
except PyverbsRDMAError as ex: |
| 93 |
if ex.error_code != errno.EOPNOTSUPP: |
| 94 |
raise ex |
| 95 |
|
| 96 |
cq_init_attrs_ex.wc_flags = 0 |
| 97 |
cq_init_attrs_ex.comp_mask = ibv_cq_init_attr_mask.IBV_CQ_INIT_ATTR_MASK_FLAGS |
| 98 |
attr_flags = list(ibv_create_cq_attr_flags) |
| 99 |
for flag in attr_flags: |
| 100 |
cq_init_attrs_ex.flags = flag |
| 101 |
try: |
| 102 |
cq_ex = CQEX(self.ctx, cq_init_attrs_ex) |
| 103 |
cq_ex.close() |
| 104 |
except PyverbsRDMAError as ex: |
| 105 |
if ex.error_code != errno.EOPNOTSUPP: |
| 106 |
raise ex |
| 107 |
|
| 108 |
def test_create_cq_ex_bad_flow(self): |
| 109 |
""" |
| 110 |
Test ibv_create_cq_ex() with wrong comp_vector / number of cqes |
| 111 |
""" |
| 112 |
cq_attrs_ex = CqInitAttrEx(cqe=self.max_cqe + 1, wc_flags=0, comp_mask=0, flags=0) |
| 113 |
with self.assertRaises(PyverbsRDMAError) as ex: |
| 114 |
CQEX(self.ctx, cq_attrs_ex) |
| 115 |
if ex.exception.error_code == errno.EOPNOTSUPP: |
| 116 |
raise unittest.SkipTest('Create Extended CQ is not supported') |
| 117 |
self.assertEqual(ex.exception.error_code, errno.EINVAL) |
| 118 |
|
| 119 |
cq_attrs_ex = CqInitAttrEx(10, wc_flags=0, comp_mask=0, flags=0) |
| 120 |
cq_attrs_ex.comp_vector = self.ctx.num_comp_vectors + 1 |
| 121 |
with self.assertRaises(PyverbsRDMAError) as ex: |
| 122 |
CQEX(self.ctx, cq_attrs_ex) |
| 123 |
self.assertEqual(ex.exception.error_code, errno.EINVAL) |