From patchwork Sun Feb 24 13:06:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noa Osherovich X-Patchwork-Id: 10827939 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA6311575 for ; Sun, 24 Feb 2019 13:08:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 087392B4A6 for ; Sun, 24 Feb 2019 13:08:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F12E02846C; Sun, 24 Feb 2019 13:08:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D15B92B4FD for ; Sun, 24 Feb 2019 13:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726865AbfBXNIy (ORCPT ); Sun, 24 Feb 2019 08:08:54 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:50507 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728248AbfBXNIx (ORCPT ); Sun, 24 Feb 2019 08:08:53 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from noaos@mellanox.com) with ESMTPS (AES256-SHA encrypted); 24 Feb 2019 15:06:49 +0200 Received: from reg-l-vrt-059-009.mtl.labs.mlnx (reg-l-vrt-059-009.mtl.labs.mlnx [10.135.59.9]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x1OD6mfZ026210; Sun, 24 Feb 2019 15:06:48 +0200 From: Noa Osherovich To: leonro@mellanox.com, jgg@mellanox.com, dledford@redhat.com Cc: linux-rdma@vger.kernel.org, Noa Osherovich Subject: [PATCH rdma-core 05/19] pyverbs: Add unittests for PD class Date: Sun, 24 Feb 2019 15:06:24 +0200 Message-Id: <20190224130638.31848-6-noaos@mellanox.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190224130638.31848-1-noaos@mellanox.com> References: <20190224130638.31848-1-noaos@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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()