| 1 |
import unittest |
| 2 |
|
| 3 |
from tests.base import RCResources, RDMATestCase |
| 4 |
from pyverbs.srq import SrqAttr |
| 5 |
from pyverbs.libibverbs_enums import ibv_device_cap_flags, ibv_srq_attr_mask, ibv_event_type |
| 6 |
import tests.utils as u |
| 7 |
|
| 8 |
|
| 9 |
class SrqTestCase(RDMATestCase): |
| 10 |
def setUp(self): |
| 11 |
super().setUp() |
| 12 |
self.iters = 100 |
| 13 |
self.create_players(RCResources, qp_count=2, with_srq=True) |
| 14 |
|
| 15 |
def test_rc_srq_traffic(self): |
| 16 |
""" |
| 17 |
Test RC traffic with SRQ. |
| 18 |
""" |
| 19 |
u.traffic(**self.traffic_args) |
| 20 |
|
| 21 |
def test_resize_srq(self): |
| 22 |
""" |
| 23 |
Test modify_srq with IBV_SRQ_MAX_WR which allows modifying max_wr. |
| 24 |
Once modified, query the SRQ and verify that the new value is greater |
| 25 |
or equal than the requested max_wr. |
| 26 |
""" |
| 27 |
device_attr = self.server.ctx.query_device() |
| 28 |
if not device_attr.device_cap_flags & ibv_device_cap_flags.IBV_DEVICE_SRQ_RESIZE: |
| 29 |
raise unittest.SkipTest('SRQ resize is not supported') |
| 30 |
srq_query_attr = self.server.srq.query() |
| 31 |
srq_query_max_wr = srq_query_attr.max_wr |
| 32 |
srq_max_wr = min(device_attr.max_srq_wr, srq_query_max_wr*2) |
| 33 |
srq_attr = SrqAttr(max_wr=srq_max_wr) |
| 34 |
self.server.srq.modify(srq_attr, ibv_srq_attr_mask.IBV_SRQ_MAX_WR) |
| 35 |
srq_attr_modified = self.server.srq.query() |
| 36 |
self.assertGreaterEqual(srq_attr_modified.max_wr, srq_attr.max_wr, |
| 37 |
'Resize SRQ failed') |
| 38 |
|
| 39 |
def test_modify_srq_limit(self): |
| 40 |
""" |
| 41 |
Test IBV_SRQ_LIMIT modification. |
| 42 |
Add 10 wr to the SRQ and set the limit to 7, |
| 43 |
Query and verify that the SRQ limit changed to the expected value. |
| 44 |
send 4 packets from the client to the server, only 6 wr remain in the |
| 45 |
server SRQ so IBV_EVENT_SRQ_LIMIT_REACHED should be generated. |
| 46 |
Listen for income event and if one received check if it's equal to |
| 47 |
IBV_EVENT_SRQ_LIMIT_REACHED else fail. |
| 48 |
""" |
| 49 |
for _ in range(10): |
| 50 |
self.server.srq.post_recv(u.get_recv_wr(self.server)) |
| 51 |
srq_modify_attr = SrqAttr(srq_limit=7) |
| 52 |
self.server.srq.modify(srq_modify_attr, ibv_srq_attr_mask.IBV_SRQ_LIMIT) |
| 53 |
server_query = self.server.srq.query() |
| 54 |
self.assertEqual(srq_modify_attr.srq_limit, server_query.srq_limit, 'Modify SRQ failed') |
| 55 |
for _ in range(4): |
| 56 |
c_send_wr, c_sg = u.get_send_elements(self.client, False) |
| 57 |
u.send(self.client, c_send_wr) |
| 58 |
u.poll_cq(self.client.cq) |
| 59 |
u.poll_cq(self.server.cq) |
| 60 |
event = self.server.ctx.get_async_event() |
| 61 |
event.ack() |
| 62 |
self.assertEqual(event.event_type, ibv_event_type.IBV_EVENT_SRQ_LIMIT_REACHED) |