| 1 |
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) |
| 2 |
# Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file |
| 3 |
""" |
| 4 |
Test module for pyverbs' pd module. |
| 5 |
""" |
| 6 |
import random |
| 7 |
|
| 8 |
from tests.base import PyverbsAPITestCase |
| 9 |
from pyverbs.pd import PD |
| 10 |
|
| 11 |
|
| 12 |
class PDTest(PyverbsAPITestCase): |
| 13 |
""" |
| 14 |
Test various functionalities of the PD class. |
| 15 |
""" |
| 16 |
def test_alloc_pd(self): |
| 17 |
""" |
| 18 |
Test ibv_alloc_pd() |
| 19 |
""" |
| 20 |
with PD(self.ctx): |
| 21 |
pass |
| 22 |
|
| 23 |
def test_dealloc_pd(self): |
| 24 |
""" |
| 25 |
Test ibv_dealloc_pd() |
| 26 |
""" |
| 27 |
with PD(self.ctx) as pd: |
| 28 |
pd.close() |
| 29 |
|
| 30 |
def test_multiple_pd_creation(self): |
| 31 |
""" |
| 32 |
Test multiple creations and destructions of a PD object |
| 33 |
""" |
| 34 |
for i in range(random.randint(1, 200)): |
| 35 |
with PD(self.ctx) as pd: |
| 36 |
pd.close() |
| 37 |
|
| 38 |
def test_destroy_pd_twice(self): |
| 39 |
""" |
| 40 |
Test bad flow cases in destruction of a PD object |
| 41 |
""" |
| 42 |
with PD(self.ctx) as pd: |
| 43 |
# Pyverbs supports multiple destruction of objects, we are |
| 44 |
# not expecting an exception here. |
| 45 |
pd.close() |
| 46 |
pd.close() |