forked from linux-rdma/rdma-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 and SRQ are created in order to verify the usage of the allocators. Signed-off-by: Edward Srouji <edwards@mellanox.com> Reviewed-by: Noa Osherovich <noaos@mellanox.com>
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# 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 | ||
import pyverbs.mem_alloc as mem | ||
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(unittest.TestCase): | ||
def __init__(self, methodName='runTest', dev_name=None): | ||
super().__init__(methodName) | ||
self.dev_name = dev_name | ||
|
||
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 = mem.posix_memalign(size, alignment) | ||
return p | ||
|
||
def free_p_func(pd, context, ptr, resource_type): | ||
mem.free(ptr) | ||
|
||
self._create_parent_domain_with_allocators(alloc_p_func, free_p_func) | ||
self._create_rdma_objects() | ||
self.pd_res.parent_domain.close() |