From patchwork Mon Aug 19 06:58:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noa Osherovich X-Patchwork-Id: 11100345 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 5DCA818EC for ; Mon, 19 Aug 2019 06:58:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CEF628590 for ; Mon, 19 Aug 2019 06:58:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B3C4285AB; Mon, 19 Aug 2019 06:58:38 +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 B3841285B0 for ; Mon, 19 Aug 2019 06:58:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726808AbfHSG6f (ORCPT ); Mon, 19 Aug 2019 02:58:35 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:53153 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726550AbfHSG6e (ORCPT ); Mon, 19 Aug 2019 02:58:34 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from noaos@mellanox.com) with ESMTPS (AES256-SHA encrypted); 19 Aug 2019 09:58:31 +0300 Received: from reg-l-vrt-059-007.mtl.labs.mlnx (reg-l-vrt-059-007.mtl.labs.mlnx [10.135.59.7]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x7J6wUNI004602; Mon, 19 Aug 2019 09:58:30 +0300 From: Noa Osherovich To: dledford@redhat.com, jgg@mellanox.com, leonro@mellanox.com Cc: linux-rdma@vger.kernel.org, Noa Osherovich , Maxim Chicherin Subject: [PATCH rdma-core 06/14] tests: TrafficResources class Date: Mon, 19 Aug 2019 09:58:19 +0300 Message-Id: <20190819065827.26921-7-noaos@mellanox.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190819065827.26921-1-noaos@mellanox.com> References: <20190819065827.26921-1-noaos@mellanox.com> MIME-Version: 1.0 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 Basic traffic aggregation object which contains MR, CQ and QP. It also provides common control path functions to create these objects. Signed-off-by: Maxim Chicherin Signed-off-by: Noa Osherovich --- tests/base.py | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/utils.py | 20 ++++++++++++ 2 files changed, 105 insertions(+) diff --git a/tests/base.py b/tests/base.py index e141b83dea0e..54ebac27d522 100644 --- a/tests/base.py +++ b/tests/base.py @@ -4,10 +4,15 @@ import unittest import random +from pyverbs.pyverbs_error import PyverbsError, PyverbsRDMAError +from pyverbs.qp import QPCap, QPInitAttr, QPAttr, QP +from tests.utils import wc_status_to_str from pyverbs.device import Context import pyverbs.device as d import pyverbs.enums as e from pyverbs.pd import PD +from pyverbs.cq import CQ +from pyverbs.mr import MR class PyverbsAPITestCase(unittest.TestCase): @@ -144,3 +149,83 @@ class BaseResources(object): self.gid_index = gid_index self.pd = PD(self.ctx) self.ib_port = ib_port + + +class TrafficResources(BaseResources): + """ + Basic traffic class. It provides the basic RDMA resources and operations + needed for traffic. + """ + def __init__(self, dev_name, ib_port, gid_index): + """ + Initializes a TrafficResources object with the given values and creates + basic RDMA resources. + :param dev_name: Device name to be used + :param ib_port: IB port of the device to use + :param gid_index: Which GID index to use + """ + super(TrafficResources, self).__init__(dev_name=dev_name, + ib_port=ib_port, + gid_index=gid_index) + self.psn = random.getrandbits(24) + self.msg_size = 1024 + self.num_msgs = 1000 + self.port_attr = None + self.mr = None + self.cq = None + self.qp = None + self.rqpn = 0 + self.rpsn = 0 + self.init_resources() + + @property + def qpn(self): + return self.qp.qp_num + + def init_resources(self): + """ + Initializes a CQ, MR and an RC QP. + :return: None + """ + self.port_attr = self.ctx.query_port(self.ib_port) + self.create_cq() + self.create_mr() + self.create_qp() + + def create_cq(self): + """ + Initializes self.cq with a CQ of depth - defined by each + test. + :return: None + """ + self.cq = CQ(self.ctx, self.num_msgs, None, None, 0) + + def create_mr(self): + """ + Initializes self.mr with an MR of length - defined by each + test. + :return: None + """ + self.mr = MR(self.pd, self.msg_size, e.IBV_ACCESS_LOCAL_WRITE) + + def create_qp(self): + """ + Initializes self.qp with an RC QP. + :return: None + """ + qp_caps = QPCap(max_recv_wr=self.num_msgs) + qp_init_attr = QPInitAttr(qp_type=e.IBV_QPT_RC, scq=self.cq, + rcq=self.cq, cap=qp_caps) + qp_attr = QPAttr(port_num=self.ib_port) + self.qp = QP(self.pd, qp_init_attr, qp_attr) + + def pre_run(self, rpsn, rqpn): + """ + Modify the QP's state to RTS and fill receive queue with work + requests. + This method is not implemented in this class. + :param rpsn: Remote PSN + :param rqpn: Remote QPN + :return: None + """ + raise NotImplementedError() diff --git a/tests/utils.py b/tests/utils.py index c84865a10a40..30166f41d555 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -221,3 +221,23 @@ def random_qp_init_attr_ex(attr_ex, attr, qpt=None): qia = QPInitAttrEx(qp_type=qpt, cap=qp_cap, sq_sig_all=sig, comp_mask=mask, create_flags=cflags, max_tso_header=max_tso) return qia + + +def wc_status_to_str(status): + try: + return \ + {0: 'Success', 1: 'Local length error', + 2: 'local QP operation error', 3: 'Local EEC operation error', + 4: 'Local protection error', 5: 'WR flush error', + 6: 'Memory window bind error', 7: 'Bad response error', + 8: 'Local access error', 9: 'Remote invalidate request error', + 10: 'Remote access error', 11: 'Remote operation error', + 12: 'Retry exceeded', 13: 'RNR retry exceeded', + 14: 'Local RDD violation error', + 15: 'Remote invalidate RD request error', + 16: 'Remote aort error', 17: 'Invalidate EECN error', + 18: 'Invalidate EEC state error', 19: 'Fatal error', + 20: 'Response timeout error', 21: 'General error'}[status] + except KeyError: + return 'Unknown WC status ({s})'.format(s=status) +