[PATCH rdma-core 05/19] pyverbs: Add unittests for PD class

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

 



This patch adds tests for the PD related API.
Bad flow of PD creation using an already freed context is not
possible since it generated a segmentation fault in rdma-core.
Other bad flows are checked.

Signed-off-by: Noa Osherovich <noaos@xxxxxxxxxxxx>
---
 pyverbs/CMakeLists.txt |  1 +
 pyverbs/tests/pd.py    | 70 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)
 create mode 100644 pyverbs/tests/pd.py

diff --git a/pyverbs/CMakeLists.txt b/pyverbs/CMakeLists.txt
index 794edee1f19f..c1e7dceb8d9c 100644
--- a/pyverbs/CMakeLists.txt
+++ b/pyverbs/CMakeLists.txt
@@ -18,6 +18,7 @@ rdma_python_module(pyverbs
 rdma_python_test(pyverbs/tests
   tests/__init__.py
   tests/device.py
+  tests/pd.py
   )
 
 rdma_internal_binary(
diff --git a/pyverbs/tests/pd.py b/pyverbs/tests/pd.py
new file mode 100644
index 000000000000..c80f0b6df80e
--- /dev/null
+++ b/pyverbs/tests/pd.py
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
+# Copyright (c) 2019, Mellanox Technologies. All rights reserved.  See COPYING file
+
+import unittest
+import random
+
+from pyverbs.base import PyverbsRDMAErrno
+import pyverbs.device as d
+from pyverbs.pd import PD
+
+
+class pd_test(unittest.TestCase):
+    """
+    Test various functionalities of the PD class.
+    """
+    def test_alloc_pd(self):
+        """
+        Test ibv_alloc_pd()
+        """
+        lst = d.get_device_list()
+        for dev in lst:
+            with d.Context(name=dev.name.decode()) as ctx:
+                with PD(ctx):
+                    pass
+
+    def test_dealloc_pd(self):
+        """
+        Test ibv_dealloc_pd()
+        """
+        lst = d.get_device_list()
+        for dev in lst:
+            with d.Context(name=dev.name.decode()) as ctx:
+                with PD(ctx) as pd:
+                    pd.close()
+
+    def test_multiple_pd_creation(self):
+        """
+        Test multiple creations and destructions of a PD object
+        """
+        lst = d.get_device_list()
+        for dev in lst:
+            with d.Context(name=dev.name.decode()) as ctx:
+                for i in range(random.randint(1, 200)):
+                    with PD(ctx) as pd:
+                        pd.close()
+
+    def test_create_pd_none_ctx(self):
+        """
+        Verify that PD can't be created with a None context
+        """
+        try:
+            pd = PD(None)
+        except TypeError as te:
+            assert 'expected pyverbs.device.Context' in te.args[0]
+            assert 'got NoneType' in te.args[0]
+        else:
+            raise PyverbsRDMAErrno('Created a PD with None context')
+
+    def test_destroy_pd_twice(self):
+        """
+        Test bad flow cases in destruction of a PD object
+        """
+        lst = d.get_device_list()
+        for dev in lst:
+            with d.Context(name=dev.name.decode()) as ctx:
+                with PD(ctx) as pd:
+                    # Pyverbs supports multiple destruction of objects, we are
+                    # not expecting an exception here.
+                    pd.close()
+                    pd.close()
-- 
2.17.2




[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