From patchwork Sun Feb 24 13:06:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noa Osherovich X-Patchwork-Id: 10827949 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 B1BD113B5 for ; Sun, 24 Feb 2019 13:08:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D6F9296ED for ; Sun, 24 Feb 2019 13:08:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 920402AA01; Sun, 24 Feb 2019 13:08:59 +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 5B94E296ED for ; Sun, 24 Feb 2019 13:08:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728248AbfBXNI5 (ORCPT ); Sun, 24 Feb 2019 08:08:57 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:50560 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728308AbfBXNI4 (ORCPT ); Sun, 24 Feb 2019 08:08:56 -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 x1OD6mfi026210; Sun, 24 Feb 2019 15:06:49 +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 14/19] pyverbs: Add unittests for query port Date: Sun, 24 Feb 2019 15:06:33 +0200 Message-Id: <20190224130638.31848-15-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 Check query_port: - Good flow: Verify that the attributes' values are legal. - Bad flow: Use non-exiting port and expect a failure. Signed-off-by: Noa Osherovich --- pyverbs/tests/device.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pyverbs/tests/device.py b/pyverbs/tests/device.py index 4a5e0a794069..492448a1526b 100644 --- a/pyverbs/tests/device.py +++ b/pyverbs/tests/device.py @@ -76,6 +76,43 @@ class device_test(unittest.TestCase): attr_ex = ctx.query_device_ex() self.verify_device_attr(attr_ex.orig_attr) + @staticmethod + def verify_port_attr(attr): + assert 'Invalid' not in d.phys_state_to_str(attr.state) + assert 'Invalid' not in d.translate_mtu(attr.max_mtu) + assert 'Invalid' not in d.translate_mtu(attr.active_mtu) + assert 'Invalid' not in d.width_to_str(attr.active_width) + assert 'Invalid' not in d.speed_to_str(attr.active_speed) + assert 'Invalid' not in d.translate_link_layer(attr.link_layer) + assert attr.max_msg_sz > 0x1000 + + def test_query_port(self): + """ + Test ibv_query_port + """ + lst = d.get_device_list() + for dev in lst: + with d.Context(name=dev.name.decode()) as ctx: + num_ports = ctx.query_device().phys_port_cnt + for p in range(num_ports): + port_attr = ctx.query_port(p + 1) + self.verify_port_attr(port_attr) + + def test_query_port_bad_flow(self): + """ Verify that querying non-existing ports fails as expected """ + lst = d.get_device_list() + for dev in lst: + with d.Context(name=dev.name.decode()) as ctx: + num_ports = ctx.query_device().phys_port_cnt + try: + port = num_ports + random.randint(1, 10) + ctx.query_port(port) + except PyverbsRDMAError as e: + assert 'Failed to query port' in e.args[0] + assert 'Invalid argument' in e.args[0] + else: + raise PyverbsRDMAError('Successfully queried non-existing port {p}'.\ + format(p=port)) class dm_test(unittest.TestCase): """