diff mbox series

[rdma-core,10/19] pyverbs: Add unittests for memory window control path

Message ID 20190224130638.31848-11-noaos@mellanox.com (mailing list archive)
State Not Applicable
Headers show
Series Pyverbs additions | expand

Commit Message

Noa Osherovich Feb. 24, 2019, 1:06 p.m. UTC
This patch tests creation and destruction of memory window.

Signed-off-by: Noa Osherovich <noaos@mellanox.com>
---
 pyverbs/tests/mr.py | 41 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/pyverbs/tests/mr.py b/pyverbs/tests/mr.py
index 409cd41e3c06..c97c6ac38d6d 100644
--- a/pyverbs/tests/mr.py
+++ b/pyverbs/tests/mr.py
@@ -3,11 +3,11 @@ 
 import unittest
 import random
 
-from pyverbs.pyverbs_error import PyverbsRDMAError
+from pyverbs.pyverbs_error import PyverbsRDMAError, PyverbsError
 from pyverbs.base import PyverbsRDMAErrno
 import pyverbs.tests.utils as u
+from pyverbs.mr import MR, MW
 import pyverbs.device as d
-from pyverbs.mr import MR
 from pyverbs.pd import PD
 import pyverbs.enums as e
 
@@ -144,3 +144,40 @@  class mr_test(unittest.TestCase):
                     with MR(pd, length, u.get_access_flags()) as mr:
                         buf = mr.buf
 
+
+class mw_test(unittest.TestCase):
+    """
+    Test various functionalities of the MW class.
+    """
+    def test_reg_mw(self):
+        """ Test ibv_alloc_mw() """
+        lst = d.get_device_list()
+        for dev in lst:
+            with d.Context(name=dev.name.decode()) as ctx:
+                with PD(ctx) as pd:
+                    with MW(pd, random.choice([e.IBV_MW_TYPE_1, e.IBV_MW_TYPE_2])) as mw:
+                        pass
+
+    def test_dereg_mw(self):
+        """ Test ibv_dealloc_mw() """
+        lst = d.get_device_list()
+        for dev in lst:
+            with d.Context(name=dev.name.decode()) as ctx:
+                with PD(ctx) as pd:
+                    with MW(pd, random.choice([e.IBV_MW_TYPE_1, e.IBV_MW_TYPE_2])) as mw:
+                        mw.close()
+
+    def test_reg_mw_wrong_type(self):
+        """ Test ibv_alloc_mw() """
+        lst = d.get_device_list()
+        for dev in lst:
+            with d.Context(name=dev.name.decode()) as ctx:
+                with PD(ctx) as pd:
+                    try:
+                        mw_type =random.randint(3, 100)
+                        mw = MW(pd, mw_type)
+                    except PyverbsRDMAError as e:
+                        pass
+                    else:
+                        raise PyverbsError('Created a MW with type {t}'.\
+                                           format(t=mw_type))