[PATCH rdma-core 4/4] tests: Add a test for parent domain

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

 



From: Edward Srouji <edwards@xxxxxxxxxxxx>

The test checks parent domain creation without custom allocators, with
custom allocators that return USE_DEFAULT (indicates the driver to use
the default allocator) and custom allocators with local memory allocation.
In addition, in each case a QP is created in order to verify the usage
of the allocators.

Signed-off-by: Edward Srouji <edwards@xxxxxxxxxxxx>
Reviewd-by: Noa Osherovich <noaos@xxxxxxxxxxxx>
---
 tests/CMakeLists.txt        |  1 +
 tests/test_parent_domain.py | 86 +++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+)
 create mode 100644 tests/test_parent_domain.py

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 960276230860..4a8e4f6607c8 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -8,6 +8,7 @@ rdma_python_test(tests
   test_cq.py
   test_device.py
   test_mr.py
+  test_parent_domain.py
   test_pd.py
   test_qp.py
   test_odp.py
diff --git a/tests/test_parent_domain.py b/tests/test_parent_domain.py
new file mode 100644
index 000000000000..5731f6256d04
--- /dev/null
+++ b/tests/test_parent_domain.py
@@ -0,0 +1,86 @@
+# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
+# Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file
+"""
+Test module for Pyverbs' ParentDomain.
+"""
+from pyverbs.pd import ParentDomainInitAttr, ParentDomain, ParentDomainContext
+from pyverbs.pyverbs_error import PyverbsRDMAError
+from pyverbs.srq import SrqAttr, SrqInitAttr, SRQ
+from pyverbs.qp import QPInitAttr, QP
+from tests.base import BaseResources
+from tests.base import RDMATestCase
+from pyverbs.base import MemAlloc
+import pyverbs.device as d
+import pyverbs.enums as e
+from pyverbs.cq import CQ
+import tests.utils as u
+import unittest
+
+
+class ParentDomainRes(BaseResources):
+    def __init__(self, dev_name, ib_port=None, gid_index=None):
+        super().__init__(dev_name=dev_name, ib_port=ib_port,
+                         gid_index=gid_index)
+        # Parent Domain will be created according to the test
+        self.pd_ctx = None
+        self.parent_domain = None
+
+
+class ParentDomainTestCase(RDMATestCase):
+    def setUp(self):
+        if self.dev_name is None:
+            dev = d.get_device_list()[-1]
+            self.dev_name = dev.name.decode()
+        self.pd_res = ParentDomainRes(self.dev_name)
+
+    def _create_parent_domain_with_allocators(self, alloc_func, free_func):
+        if alloc_func and free_func:
+            self.pd_res.pd_ctx = ParentDomainContext(self.pd_res.pd, alloc_func,
+                                                     free_func)
+        pd_attr = ParentDomainInitAttr(pd=self.pd_res.pd,
+                                       pd_context=self.pd_res.pd_ctx)
+        try:
+            self.pd_res.parent_domain = ParentDomain(self.pd_res.ctx,
+                                                     attr=pd_attr)
+        except PyverbsRDMAError as ex:
+            if 'not supported' in str(ex) or 'not implemented' in str(ex):
+                raise unittest.SkipTest('Parent Domain is not supported on this device')
+            raise ex
+
+    def _create_rdma_objects(self):
+        cq = CQ(self.pd_res.ctx, 100, None, None, 0)
+        dev_attr = self.pd_res.ctx.query_device()
+        qp_cap = u.random_qp_cap(dev_attr)
+        qia = QPInitAttr(scq=cq, rcq=cq, cap=qp_cap)
+        qia.qp_type = e.IBV_QPT_RC
+        QP(self.pd_res.parent_domain, qia)
+        srq_init_attr = SrqInitAttr(SrqAttr())
+        SRQ(self.pd_res.parent_domain, srq_init_attr)
+
+    def test_without_allocators(self):
+        self._create_parent_domain_with_allocators(None, None)
+        self._create_rdma_objects()
+        self.pd_res.parent_domain.close()
+
+    def test_default_allocators(self):
+        def alloc_p_func(pd, context, size, alignment, resource_type):
+            return e._IBV_ALLOCATOR_USE_DEFAULT
+
+        def free_p_func(pd, context, ptr, resource_type):
+            return e._IBV_ALLOCATOR_USE_DEFAULT
+
+        self._create_parent_domain_with_allocators(alloc_p_func, free_p_func)
+        self._create_rdma_objects()
+        self.pd_res.parent_domain.close()
+
+    def test_mem_align_allocators(self):
+        def alloc_p_func(pd, context, size, alignment, resource_type):
+            p = MemAlloc.aligned_alloc(size, alignment)
+            return p
+
+        def free_p_func(pd, context, ptr, resource_type):
+            MemAlloc.free(ptr)
+
+        self._create_parent_domain_with_allocators(alloc_p_func, free_p_func)
+        self._create_rdma_objects()
+        self.pd_res.parent_domain.close()
-- 
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