From patchwork Sun Mar 24 14:10:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noa Osherovich X-Patchwork-Id: 10867443 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 348111390 for ; Sun, 24 Mar 2019 14:11:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 207BA2940A for ; Sun, 24 Mar 2019 14:11:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14C75294B6; Sun, 24 Mar 2019 14:11:27 +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 865662940A for ; Sun, 24 Mar 2019 14:11:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726877AbfCXOLZ (ORCPT ); Sun, 24 Mar 2019 10:11:25 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:53733 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726317AbfCXOLZ (ORCPT ); Sun, 24 Mar 2019 10:11:25 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from noaos@mellanox.com) with ESMTPS (AES256-SHA encrypted); 24 Mar 2019 16:11:21 +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 x2OEAxHu028186; Sun, 24 Mar 2019 16:11:21 +0200 From: Noa Osherovich To: leon@kernel.org, jgg@mellanox.com, dledford@redhat.com Cc: linux-rdma@vger.kernel.org, Noa Osherovich Subject: [PATCH rdma-core 2/6] pyverbs: Add unittests for completion-related classes Date: Sun, 24 Mar 2019 16:10:36 +0200 Message-Id: <20190324141040.22204-3-noaos@mellanox.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190324141040.22204-1-noaos@mellanox.com> References: <20190324141040.22204-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 Add unittests for creation and destruction of CQ an CompChannel: - Creation and deletion of a CompChannel (good flow). - Creation and deletion of a CQ (good flow), with and without a completion channel. - Bad flow checks: Verify failure for illegal comp_vector / cqe number. Signed-off-by: Noa Osherovich Reviewed-by: Maor Gottlieb Reviewed-by: Leon Romanovsky --- pyverbs/CMakeLists.txt | 1 + pyverbs/tests/cq.py | 130 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 pyverbs/tests/cq.py diff --git a/pyverbs/CMakeLists.txt b/pyverbs/CMakeLists.txt index ef5114594e20..d83f77317ecb 100644 --- a/pyverbs/CMakeLists.txt +++ b/pyverbs/CMakeLists.txt @@ -19,6 +19,7 @@ rdma_python_module(pyverbs rdma_python_test(pyverbs/tests tests/__init__.py + tests/cq.py tests/device.py tests/mr.py tests/pd.py diff --git a/pyverbs/tests/cq.py b/pyverbs/tests/cq.py new file mode 100644 index 000000000000..afe732e5e93c --- /dev/null +++ b/pyverbs/tests/cq.py @@ -0,0 +1,130 @@ +# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) +# Copyright (c) 2019, Mellanox Technologies. All rights reserved. See COPYING file +""" +Test module for pyverbs' cq module. +""" +import unittest +import random + +from pyverbs.pyverbs_error import PyverbsError +from pyverbs.cq import CompChannel, CQ +import pyverbs.device as d +import pyverbs.enums as e + + +class CQTest(unittest.TestCase): + """ + Test various functionalities of the CQ class. + """ + + @staticmethod + def test_create_cq(): + """ + Test ibv_create_cq() + """ + lst = d.get_device_list() + for dev in lst: + with d.Context(name=dev.name.decode()) as ctx: + cqes = get_num_cqes(ctx) + comp_vector = random.randint(0, ctx.num_comp_vectors - 1) + if random.choice([True, False]): + with CompChannel(ctx) as cc: + with CQ(ctx, cqes, None, cc, comp_vector): + pass + else: + with CQ(ctx, cqes, None, None, comp_vector): + pass + + @staticmethod + def test_create_cq_bad_flow(): + """ + Test ibv_create_cq() with a wrong comp_vector / cqe number + """ + lst = d.get_device_list() + for dev in lst: + with d.Context(name=dev.name.decode()) as ctx: + cqes = get_num_cqes(ctx) + comp_vector = random.randint(ctx.num_comp_vectors, 100) + try: + if random.choice([True, False]): + with CompChannel(ctx) as cc: + with CQ(ctx, cqes, None, cc, comp_vector): + pass + else: + with CQ(ctx, cqes, None, None, comp_vector): + pass + except PyverbsError as e: + assert 'Failed to create a CQ' in e.args[0] + assert 'Invalid argument' in e.args[0] + else: + raise PyverbsError( + 'Created a CQ with comp_vector={n} while device\'s num_comp_vectors={nc}'. + format(n=comp_vector, nc=ctx.num_comp_vectors)) + max_cqe = ctx.query_device().max_cqe + cqes = random.randint(max_cqe + 1, max_cqe + 100) + try: + if random.choice([True, False]): + with CompChannel(ctx) as cc: + with CQ(ctx, cqes, None, cc, 0): + pass + else: + with CQ(ctx, cqes, None, None, 0): + pass + except PyverbsError as err: + assert 'Failed to create a CQ' in err.args[0] + assert 'Invalid argument' in err.args[0] + else: + raise PyverbsError( + 'Created a CQ with cqe={n} while device\'s max_cqe={nc}'. + format(n=cqes, nc=max_cqe)) + + @staticmethod + def test_destroy_cq(): + """ + Test ibv_destroy_cq() + """ + lst = d.get_device_list() + for dev in lst: + with d.Context(name=dev.name.decode()) as ctx: + cqes = get_num_cqes(ctx) + comp_vector = random.randint(0, ctx.num_comp_vectors - 1) + if random.choice([True, False]): + with CompChannel(ctx) as cc: + cq = CQ(ctx, cqes, None, cc, comp_vector) + else: + cq = CQ(ctx, cqes, None, None, comp_vector) + cq.close() + + +class CCTest(unittest.TestCase): + """ + Test various functionalities of the Completion Channel class. + """ + + @staticmethod + def test_create_comp_channel(): + """ + Test ibv_create_comp_channel() + """ + lst = d.get_device_list() + for dev in lst: + with d.Context(name=dev.name.decode()) as ctx: + with CompChannel(ctx): + pass + + @staticmethod + def test_destroy_comp_channel(): + """ + Test ibv_destroy_comp_channel() + """ + lst = d.get_device_list() + for dev in lst: + with d.Context(name=dev.name.decode()) as ctx: + cc = CompChannel(ctx) + cc.close() + + +def get_num_cqes(ctx): + attr = ctx.query_device() + max_cqe = attr.max_cqe + return random.randint(0, max_cqe)