[PATCH rdma-core 2/2] tests: Add a test for completion events

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a test which runs RC/UD traffic and uses a completion channel.
Add support for utils method poll_cq to use the completion channel
when a CQ has one.
This commit also fixes a bug in poll_cq - only the last polled CQEs
were returned to the user.

Signed-off-by: Noa Osherovich <noaos@xxxxxxxxxxxx>
Reviewed-by: Edward Srouji <edwards@xxxxxxxxxxxx>
---
 tests/CMakeLists.txt    |  1 +
 tests/test_cq_events.py | 45 +++++++++++++++++++++++++++++++++++++++++
 tests/utils.py          | 11 +++++++---
 3 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 tests/test_cq_events.py

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6d702425886c..8d946349bd67 100755
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -7,6 +7,7 @@ rdma_python_test(tests
   test_addr.py
   base.py
   test_cq.py
+  test_cq_events.py
   test_cqex.py
   test_device.py
   test_mr.py
diff --git a/tests/test_cq_events.py b/tests/test_cq_events.py
new file mode 100644
index 000000000000..bcb3f7d158ee
--- /dev/null
+++ b/tests/test_cq_events.py
@@ -0,0 +1,45 @@
+from tests.base import RCResources, UDResources
+from tests.base import RDMATestCase
+from tests.utils import traffic
+
+from pyverbs.cq import CQ, CompChannel
+
+
+def create_cq_with_comp_channel(agr_obj):
+    agr_obj.comp_channel = CompChannel(agr_obj.ctx)
+    agr_obj.cq = CQ(agr_obj.ctx, agr_obj.num_msgs, None, agr_obj.comp_channel)
+    agr_obj.cq.req_notify()
+
+
+class CqEventsUD(UDResources):
+    def create_cq(self):
+        create_cq_with_comp_channel(self)
+
+
+class CqEventsRC(RCResources):
+    def create_cq(self):
+        create_cq_with_comp_channel(self)
+
+
+class CqEventsTestCase(RDMATestCase):
+    def setUp(self):
+        super().setUp()
+        self.iters = 100
+        self.qp_dict = {'ud': CqEventsUD, 'rc': CqEventsRC}
+
+    def create_players(self, qp_type):
+        client = self.qp_dict[qp_type](self.dev_name, self.ib_port,
+                                       self.gid_index)
+        server = self.qp_dict[qp_type](self.dev_name, self.ib_port,
+                                       self.gid_index)
+        client.pre_run(server.psn, server.qpn)
+        server.pre_run(client.psn, client.qpn)
+        return client, server
+
+    def test_cq_events_ud(self):
+        client, server = self.create_players('ud')
+        traffic(client, server, self.iters, self.gid_index, self.ib_port)
+
+    def test_cq_events_rc(self):
+        client, server = self.create_players('rc')
+        traffic(client, server, self.iters, self.gid_index, self.ib_port)
diff --git a/tests/utils.py b/tests/utils.py
index c45170dbd329..d59ab54eec19 100755
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -332,14 +332,19 @@ def poll_cq(cq, count=1):
     :return: An array of work completions of length <count>, None
              when events are used
     """
-    wcs = None
+    wcs = []
+    channel = cq.comp_channel
     while count > 0:
-        nc, wcs = cq.poll(count)
-        for wc in wcs:
+        if channel:
+            channel.get_cq_event(cq)
+            cq.req_notify()
+        nc, tmp_wcs = cq.poll(count)
+        for wc in tmp_wcs:
             if wc.status != e.IBV_WC_SUCCESS:
                 raise PyverbsRDMAError('Completion status is {s}'.
                                        format(s=wc_status_to_str(wc.status)))
         count -= nc
+        wcs.extend(tmp_wcs)
     return wcs
 
 
-- 
2.21.0





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux