From patchwork Sun Mar 24 14:10:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noa Osherovich X-Patchwork-Id: 10867449 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 00BB013B5 for ; Sun, 24 Mar 2019 14:11:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E12082940A for ; Sun, 24 Mar 2019 14:11:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5A97294B6; Sun, 24 Mar 2019 14:11:31 +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 6F7652940A for ; Sun, 24 Mar 2019 14:11:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726889AbfCXOLa (ORCPT ); Sun, 24 Mar 2019 10:11:30 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:53762 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726811AbfCXOLa (ORCPT ); Sun, 24 Mar 2019 10:11:30 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from noaos@mellanox.com) with ESMTPS (AES256-SHA encrypted); 24 Mar 2019 16:11:24 +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 x2OEAxHw028186; Sun, 24 Mar 2019 16:11:24 +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 4/6] pyverbs: Add unittests for extended completion-related classes Date: Sun, 24 Mar 2019 16:10:38 +0200 Message-Id: <20190324141040.22204-5-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 extended CQ control path: - Creation and deletion of an extended 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/tests/cq.py | 81 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/pyverbs/tests/cq.py b/pyverbs/tests/cq.py index afe732e5e93c..4c1cea2b5296 100644 --- a/pyverbs/tests/cq.py +++ b/pyverbs/tests/cq.py @@ -6,8 +6,8 @@ Test module for pyverbs' cq module. import unittest import random +from pyverbs.cq import CompChannel, CQ, CqInitAttrEx, CQEX from pyverbs.pyverbs_error import PyverbsError -from pyverbs.cq import CompChannel, CQ import pyverbs.device as d import pyverbs.enums as e @@ -124,7 +124,86 @@ class CCTest(unittest.TestCase): cc.close() +class CQEXTest(unittest.TestCase): + """ + Test various functionalities of the CQEX class. + """ + + @staticmethod + def test_create_cq_ex(): + """ + Test ibv_create_cq_ex() + """ + lst = d.get_device_list() + for dev in lst: + with d.Context(name=dev.name.decode()) as ctx: + with CQEX(ctx, get_attrs_ex(ctx)): + pass + + @staticmethod + def test_create_cq_ex_bad_flow(): + """ + Test ibv_create_cq_ex() with wrong comp_vector / number of cqes + """ + lst = d.get_device_list() + for dev in lst: + with d.Context(name=dev.name.decode()) as ctx: + attrs_ex = get_attrs_ex(ctx) + max_cqe = ctx.query_device().max_cqe + attrs_ex.cqe = max_cqe + random.randint(1, 100) + try: + CQEX(ctx, attrs_ex) + except PyverbsError as e: + assert 'Failed to create extended CQ' in e.args[0] + assert ' Errno: 22' in e.args[0] + else: + raise PyverbsError( + 'Created a CQEX with {c} CQEs while device\'s max CQE={dc}'. + format(c=attrs_ex.cqe, dc=max_cqe)) + comp_channel = random.randint(ctx.num_comp_vectors, 100) + attrs_ex.comp_vector = comp_channel + attrs_ex.cqe = get_num_cqes(ctx) + try: + CQEX(ctx, attrs_ex) + except PyverbsError as e: + assert 'Failed to create extended CQ' in e.args[0] + assert ' Errno: 22' in e.args[0] + else: + raise PyverbsError( + 'Created a CQEX with comp_vector={c} while device\'s num_comp_vectors={dc}'. + format(c=comp_channel, dc=ctx.num_comp_vectors)) + + @staticmethod + def test_destroy_cq_ex(): + """ + Test ibv_destroy_cq() for extended CQs + """ + lst = d.get_device_list() + for dev in lst: + with d.Context(name=dev.name.decode()) as ctx: + with CQEX(ctx, get_attrs_ex(ctx)) as cq: + cq.close() + + def get_num_cqes(ctx): attr = ctx.query_device() max_cqe = attr.max_cqe return random.randint(0, max_cqe) + + +def get_attrs_ex(ctx): + cqe = get_num_cqes(ctx) + sample = random.sample(list(e.ibv_create_cq_wc_flags), + random.randint(0, 11)) + wc_flags = 0 + for flag in sample: + wc_flags |= flag + comp_mask = random.choice([0, e.IBV_CQ_INIT_ATTR_MASK_FLAGS]) + flags = 0 + if comp_mask is not 0: + sample = random.sample(list(e.ibv_create_cq_attr_flags), + random.randint(0, 2)) + for flag in sample: + flags |= flag + return CqInitAttrEx(cqe=cqe, wc_flags=wc_flags, comp_mask=comp_mask, + flags=flags)