From patchwork Sat Jun 30 00:47:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 10497777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DF66C602CC for ; Sat, 30 Jun 2018 00:48:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C063B295AC for ; Sat, 30 Jun 2018 00:48:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3878295B0; Sat, 30 Jun 2018 00:48:16 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 2B3D0295AC for ; Sat, 30 Jun 2018 00:48:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935829AbeF3AsP (ORCPT ); Fri, 29 Jun 2018 20:48:15 -0400 Received: from mail-db5eur01on0040.outbound.protection.outlook.com ([104.47.2.40]:59431 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934248AbeF3AsO (ORCPT ); Fri, 29 Jun 2018 20:48:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bw71T+vGc6ZdJnDzoqbhEFg19KK4s28QjdNCgvQLJZ0=; b=h42VjapIpuzN9TKjVD4MTkveT8ggRithvhsQu+Z6+H8ITEjFzsQGzdRvktQ//L4/l34sXm22I1qW+y0sMFdgofZJ73/E5H+z9xAxT9SQubXwjJdC+Bx440rIflbW4MnyRRNkZjpn7YlHDqJuMcJ1OhrY7Qv0f5Pff9zzITmyOPA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; Received: from t540p (89.176.83.59) by VI1PR05MB4191.eurprd05.prod.outlook.com (2603:10a6:803:4e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.906.25; Sat, 30 Jun 2018 00:48:11 +0000 From: Petr Machata To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: jiri@mellanox.com, idosch@mellanox.com, shuah@kernel.org, davem@davemloft.net Subject: [PATCH net-next 04/13] selftests: forwarding: Add devlink_lib.sh In-Reply-To: References: Message-Id: Date: Sat, 30 Jun 2018 02:47:08 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 X-Originating-IP: [89.176.83.59] X-ClientProxiedBy: DB6PR07CA0011.eurprd07.prod.outlook.com (2603:10a6:6:2d::21) To VI1PR05MB4191.eurprd05.prod.outlook.com (2603:10a6:803:4e::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7744b8bd-3d00-42cd-a351-08d5de232840 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(48565401081)(5600052)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:VI1PR05MB4191; X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB4191; 3:YryeER/qcwFV+ALdXXUTfaa1HpdO5g5CelPpmq1xdfoswto+lFi3XUaYEonGjJm4IWOFGop890pKav3XC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PpiR0V2a+O6yWpMJx6YGtV4tDX3rguravlqVV4cugmwc0PNDX8WmbACXJSxPao2MhkKFU1uQyB39LoEoBsqPhri/IMNBi766hhoPKDfSKigmN6mU912v/52Os4oMqfTquYpdTejoWZkajZQuBCcXWLcatO6IQwPhBKiBAUwQ0dVyyDC2S5mnvR1VUO27a61z/KliWkQbjAZxTi8mlwpzkBW6oq9bVNI3PvcemFo8Cfo8J7kN7SGbGyFcCdFisxQoJewdQQGsS4upeLDwU+KKRe; 4:tOVnIOFqKRYaZvwgyYfKC31tCwIZXb0+iH1wwCYgNjAN9LUXpk/iawZ8AbD/15OExduhfEMMvnH3RnHMj+4d6huLdksnWu29uUsIHGbw+I41ANAX+XMMhSZseUlepM4WeA7PnysXpEdHzXo/IOJnXLmTgWM8ydnEfLo4i9PXtjXb2WYSTQgzVpCkLdnzgxAXXdY5/+qRrfZYa47OsWK3KonDxHGzE2jcdlm6DOs7cGXtyTsnOQf+7BqQgkLi3jjdhw0oboT1Vg77INia243LhA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:VI1PR05MB4191; BCL:0; PCL:0; RULEID:; SRVR:VI1PR05MB4191; X-Forefront-PRVS: 0719EC6A9A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(346002)(366004)(39860400002)(396003)(136003)(189003)(199004)(86362001)(478600001)(476003)(486006)(68736007)(956004)(2616005)(6116002)(6496006)(2906002)(66066001)(52116002)(3846002)(47776003)(76176011)(53936002)(5660300001)(4326008)(14444005)(446003)(11346002)(51416003)(6486002)(36756003)(48376002)(118296001)(386003)(50466002)(16526019)(105586002)(186003)(26005)(106356001)(97736004)(25786009)(8936002)(316002)(6666003)(81166006)(7736002)(16586007)(8676002)(305945005)(58126008)(81156014); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR05MB4191; H:t540p; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR05MB4191; 23:zp7DpYe/WYwzwYg9/0YAHsV2R4NWZmX05dzkpFIWl?= =?us-ascii?Q?FpbTXhG5aopGk+8Mfeg15WkkMbnLtdmcPxWsblYUbVcUReEns9zZkCKt0nTx?= =?us-ascii?Q?gAZSz2de62dXus0jc8Rz2YMWypniWDpUnuLnz+KAlrbBS9Qgvp1c90sawygS?= =?us-ascii?Q?WcLU8zDA7w4FfW59z/GCnzXdEiV7EiYE3PMi45KB06D8R7vZ57+3Lynpcvoy?= =?us-ascii?Q?niYAJESS59Td4h4+PbG3b95SLxGD3x3Q6eLCbC/QocVQsNS+gN56iHkaSAcU?= =?us-ascii?Q?mdlqJBAD5kba9MIFfKHD0+asUB4s9PcAgKi3NthsY5irurxik9Dz9F/A5mUq?= =?us-ascii?Q?WvhB+ls7+j/6YmNz5bzckpn05vJd6zxELinfMso+gH4iyMGBg5GHIXi8N5Ba?= =?us-ascii?Q?wReDrvA1eTyXfxR/qPhJg9UONCnjUPpFTDecK39pJNTxExAM59kuV1g94dt8?= =?us-ascii?Q?Gk8XcOUsNrHvx+01YF37KUPWF/7hOjzLG4vKcbY53bPSk5ay8xPFWu451v3O?= =?us-ascii?Q?8BBcu7Dt7a4064TpBtMHfm9irTEd0sOyzpondZftS8I+C/FS45jx1OJZv3wr?= =?us-ascii?Q?wpiY6hzkJFjq/wJUO9KiHom4JJtDxqmHxqzHrv0XZr4VDyBPJo3rJCFVd6bk?= =?us-ascii?Q?bAe90bMMo62fEopB15XESiG6Xs1rbXWTDDK7W+yMEbmbq4ZnN6O+tMoIz5vj?= =?us-ascii?Q?DGUupbrlLNyuN0V88Pee9dthgqgwLRDlAo37yLp822x6BGHDoycAiZpYsuDa?= =?us-ascii?Q?i7my8p5IIVULDTPUeEd5MKMAgT/OpNhitJdR1Hvf8Qc0YWoAawDTbZWnwqXz?= =?us-ascii?Q?buZq9BNQIAJagh9NP7g1DTPN49HxkOcEAuVOmOuYBe7TdX227rbHjpU5uHB1?= =?us-ascii?Q?vy2uWmab6mhVhJa3ceDADOweybMSUQ/YEIbAVzEBQlRROqFqdXupJerYNa/K?= =?us-ascii?Q?yKEZkgUydVQYSAm6XiT8BvTs26ncyLCrxzIvSS7mvjiIQLChc1PvL+0EnmKR?= =?us-ascii?Q?WipmdlqFi7b4Z00v/kSjSV6bdsJnwfselS6YvmtnboQh8OKEldK7dGvT3a+z?= =?us-ascii?Q?dEpEm9g+ZqfCySwlxG4jfVr7vU8BM8NQUmHMNYxt/zlw/I6d+rr3/OuUS2kd?= =?us-ascii?Q?cYmh62hm5svddGAr2VsTazMwE+sm6fx1yZtuw0IK7NHFOzpa4H7hA=3D=3D?= X-Microsoft-Antispam-Message-Info: VQaUxJX2WMpiOmn2NFOtFfEYGow0Q+W0/0/+3DsFMCo4hCdDvZpdragcGvSwOgOiIBP+l3V62H8DpMC0A1I8YmwLyFUbl+F0MfCt3caQQTnQyiz3QhS1cB5myOZrk5lHUb5w0Tvvir1am23Av7yZAdleJK3shss4JIRp7ujw8Cw0T92wvEKEvZxGC74J7rEBk7i3gRlbhi/MqK+WBKFAZZuXjAWv86OOBqlvrxKUefILNWUneF5o1egq3Co82qdXy4c8eN5YyqWOVcGzHkgwYhRMgzJO9Aqqqd+6C8SFrZEZMEu5k7n+2i6XDoLVwQQPHAe2EGxbUBffq28wyJxcmBZJCW3YtN9sCmhDgfD94/Y= X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB4191; 6:NTZ4kQckJhykMiK9KK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X X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2018 00:48:11.5313 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7744b8bd-3d00-42cd-a351-08d5de232840 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB4191 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This helper library contains wrappers to devlink functionality agnostic to the underlying device. Signed-off-by: Yuval Mintz [petrm@mellanox.com: Split this out from another patch.] Signed-off-by: Petr Machata --- .../selftests/net/forwarding/devlink_lib.sh | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tools/testing/selftests/net/forwarding/devlink_lib.sh diff --git a/tools/testing/selftests/net/forwarding/devlink_lib.sh b/tools/testing/selftests/net/forwarding/devlink_lib.sh new file mode 100644 index 000000000000..5ab1e5f43022 --- /dev/null +++ b/tools/testing/selftests/net/forwarding/devlink_lib.sh @@ -0,0 +1,108 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +############################################################################## +# Source library + +relative_path="${BASH_SOURCE%/*}" +if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then + relative_path="." +fi + +source "$relative_path/lib.sh" + +############################################################################## +# Defines + +DEVLINK_DEV=$(devlink port show | grep "${NETIFS[p1]}" | \ + grep -v "${NETIFS[p1]}[0-9]" | cut -d" " -f1 | \ + rev | cut -d"/" -f2- | rev) +if [ -z "$DEVLINK_DEV" ]; then + echo "SKIP: ${NETIFS[p1]} has no devlink device registered for it" + exit 1 +fi +if [[ "$(echo $DEVLINK_DEV | grep -c pci)" -eq 0 ]]; then + echo "SKIP: devlink device's bus is not PCI" + exit 1 +fi + +DEVLINK_VIDDID=$(lspci -s $(echo $DEVLINK_DEV | cut -d"/" -f2) \ + -n | cut -d" " -f3) + +############################################################################## +# Sanity checks + +devlink -j resource show "$DEVLINK_DEV" &> /dev/null +if [ $? -ne 0 ]; then + echo "SKIP: iproute2 too old, missing devlink resource support" + exit 1 +fi + +############################################################################## +# Devlink helpers + +devlink_resource_names_to_path() +{ + local resource + local path="" + + for resource in "${@}"; do + if [ "$path" == "" ]; then + path="$resource" + else + path="${path}/$resource" + fi + done + + echo "$path" +} + +devlink_resource_get() +{ + local name=$1 + local resource_name=.[][\"$DEVLINK_DEV\"] + + resource_name="$resource_name | .[] | select (.name == \"$name\")" + + shift + for resource in "${@}"; do + resource_name="${resource_name} | .[\"resources\"][] | \ + select (.name == \"$resource\")" + done + + devlink -j resource show "$DEVLINK_DEV" | jq "$resource_name" +} + +devlink_resource_size_get() +{ + local size=$(devlink_resource_get "$@" | jq '.["size_new"]') + + if [ "$size" == "null" ]; then + devlink_resource_get "$@" | jq '.["size"]' + else + echo "$size" + fi +} + +devlink_resource_size_set() +{ + local new_size=$1 + local path + + shift + path=$(devlink_resource_names_to_path "$@") + devlink resource set "$DEVLINK_DEV" path "$path" size "$new_size" + check_err $? "Failed setting path $path to size $size" +} + +devlink_reload() +{ + local still_pending + + devlink dev reload "$DEVLINK_DEV" &> /dev/null + check_err $? "Failed reload" + + still_pending=$(devlink resource show "$DEVLINK_DEV" | \ + grep -c "size_new") + check_err $still_pending "Failed reload - There are still unset sizes" +}