From patchwork Thu Aug 22 13:49:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 821491 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2078.outbound.protection.outlook.com [40.107.92.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E97F1CBEA2; Thu, 22 Aug 2024 13:52:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334753; cv=fail; b=Oo2XtkXh9tihMrt0ln/fmcjFn2OT28xjYi7fKNDQVQ0GhIjvSQbePGPcZeoz0ebadSFdWfEpnT/kQCC+VAYNxY6EC7PsfFsW/fpBjZL/wbb5mzpI8PgABLefaiACapurT7ajnBnqf3nz4HEI716GDkpdz+fUaS6IQvgrhmY4Nqo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334753; c=relaxed/simple; bh=iDfrIeITZwXslhuF2LkeD0V7UlT6mb2V4MExpuFx8f0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZwvPKYPX5w1wpOa9CF0Fh/McunJWYgUwp0+W/roXrQ31dnOY9y3/63j+Wg8+BUDgqwgAS6u1ddktw9gYg7dKzr9qBuSEQItpAqkzO1Z1tiHw7nhC8r+iPungiyPcrTeMe7+RL8+Yosb4EeYjLYRvffclKCj3f3j4722KzlCttOE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=RGYfcJ4x; arc=fail smtp.client-ip=40.107.92.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="RGYfcJ4x" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=f/6A1N9r9g11CBrt3Vukdn053m3MLa1yEZ/i2KwLRauFd3Vau2poJMVCeKyizBBy2F9/fa/zGAa5SthBi9eAwdYqYf/bvSHda80Djpj5jenda84GaGqPkV8TiQVKZ434+Av38kFToKJC3Hh3+os/oaQIUKz0cU4YYL+94LqqGaxrp09IhIId6eb5pfFT+Dbz5P2Mwba3gv+pmKGgyzT/wrkroz1z+NYrw3VAUhXWWO/l8qb1woH/+dz+P2F0Anxf/vexR9RPUHFxNsgNNCgAimlzmQUWxXTlGRIhI+iekTmxtsa1lzWvoPt6MlrbeoNnu2/9KNpFr8O1f2kStRXrxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=USSkfRQNhMHyu7LzOzT+qdIz/P3FNXa52nXJAI62yuE=; b=pOt4rxkdUtMZKP9iSdXq5IAUnJElB/LAO649wWy+2a5KxsG34ZgV/2APt2ww1Ys3p2JqU2Ps+V4kzgKzs5wV0yN3iAtPz9wYAeuXgURJ2gb3haL+8F68YH0WIYEYstWL22gdjE+McX+nwnX8RdNonAL45d7a8D3Ds2oSvL47cC/xPCd4hyVXOJm+Fn23I5p6TZYpP3ZRpfWGTYfMQe/i1U/HOwpjW0wRuOZ0j1r11N9se3us8knutZHR3uCmTNhK6H06qB1uzE8Wskh/SOrsFMhqynhLSLT6klGNNZ+pu5NDUVIquf6R8bCu5fj5aOMXHsnb/iTi6NgIn65DsgVD7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=USSkfRQNhMHyu7LzOzT+qdIz/P3FNXa52nXJAI62yuE=; b=RGYfcJ4xUi74Fe7AVzHU4dygD7SNdy+KoTfr8AgDFBC3iN5nPr8L5fyeUcCHLWr5mbv0S/NNVRperhGLLM6Xy3ehQyPUiQWqY1LqhaothTIt/zEC5tP3wyBdvRIHX36AbmWO8Ck7oCAvr0vJcUizZFEDgceoicqVtoNKc3EoYQ0AMtu9eP6w81ayjBilbO4cfj1bz/qcYVvD/2LTapq612lCzpNR2iyuL5y3ZWWh0LulOd7lUorp71cQlLhngZ7TClAiNyV9c6179oj+B46wY1iRrYKvbfm5BxUcNedbAod09vhVbDbIbTMVJqsUlillTkrQIbBEOqYea71cONYsgw== Received: from BN9PR03CA0355.namprd03.prod.outlook.com (2603:10b6:408:f6::30) by SJ0PR12MB6736.namprd12.prod.outlook.com (2603:10b6:a03:47a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Thu, 22 Aug 2024 13:52:27 +0000 Received: from BN3PEPF0000B077.namprd04.prod.outlook.com (2603:10b6:408:f6:cafe::34) by BN9PR03CA0355.outlook.office365.com (2603:10b6:408:f6::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.19 via Frontend Transport; Thu, 22 Aug 2024 13:52:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B077.mail.protection.outlook.com (10.167.243.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11 via Frontend Transport; Thu, 22 Aug 2024 13:52:26 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 22 Aug 2024 06:52:13 -0700 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 22 Aug 2024 06:52:08 -0700 From: Petr Machata To: Shuah Khan , , CC: Jakub Kicinski , Ido Schimmel , "Petr Machata" , Amit Cohen , Benjamin Poirier , Hangbin Liu , Vladimir Oltean , Subject: [RFC PATCH net-next 1/5] selftests: forwarding: Introduce deferred commands Date: Thu, 22 Aug 2024 15:49:40 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B077:EE_|SJ0PR12MB6736:EE_ X-MS-Office365-Filtering-Correlation-Id: dd08990a-ba6f-4adc-73d8-08dcc2b1a851 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: AIshSyeF3mOb83xQH0YMZzorNqWZUpRe8mDYrOB/ugsBNf6rhpE2m2HJ88Pf/ZhzLd3zYUtlrLmx08U4LN+2qX8vkIvQpRUXMmUb01i613U2ljZRs1iorVkmEYYl5VNxILuL6MeOdZdA8zhz4BULRGHILcUwS05tjoU31DRroCJBtuhNEbB6LGljTiASgCkimzhofTRmzxOHej5AGcLNkkyfA5X+IlfBXtccC810VIIouHCvwZcE18OtdkzS3jjB5meH6PxyZj5rvaJSonSaLDDLi7XYIz9E3wmtZUZsDyibWoGJqFpaHQkXpp6x7w/GKqP4Z6CVsdAiX3pA0gLVu/6hLusFZp/f6FT29zaSV3NqwvXaIZyRQbnaFpIPMyq21nMi+QQiavsyR3bNa08b5aIWolyrlsgUepcMmMtRv0aobqfGBXPwjUzz5yP/F8TnFKm0VzyZkXy+yy1Vyn0i2gkBbLSPow61KC11l5IWtKa+yHR5bMA4vUU+okehFn3miLdxq9cQ/sSWLcQxxVtM/+Ongj4W8Hp3T6uW59GhK1pRb7LMgTNkZ5P5NpaguSVQCbtn5lDEz7tfDF2yGIb/CRSEZaskE/HqbDIwMEWTs8E9diFbkIpOV7S57N60BBDXNztXfhEL+zv4BfLglQ5gbqsDYuWhnvzN/zBw/U50kl1G+mvKdcbaaGV/s8NEq43aDHg7Gh3F1bg1eJCqA0Yy2L1aAoxG4xC6+XUEiSnSOn5eZAFtwjcs1M19h8OYLVLB4AUgoOk1W4eug7YmKj0hf5dSjyxHjx9uV2J6g4XtrRts0/HDVrrQ/dmdMp5poJyjFnQ0cdOC30vTDBTup+GlIkngfEXWgtHNfwkPUlb+gKpS9SERkw6y6/++ek7IcNcyVDrDHYZuxmh7W4a5V5k6n7wOwXLk9VyMPfdg/OId7+Kw4WDY854B7U73oWgHIzKZXPkdXrOJcaOLsgb+Gt7ZqsZeb97TaZB5Mxl0uKBOolUC+eG1t8m0XXwcVxlQm0IBIJUxXNRvrblvWy7V3PaLm18flMNFKCvHhm3AmLNIdFcpsSxT0EXUKsuD6areKl3+TXfgUPde9xQ19X5q9CmJtcJzLpASxyuONXbsANzfmN+QAZy358XqOhrEmVQvTohKEHKy1gt9mvBHtAn560SeWCHzyAF0DQa8NJVoMZD4NHleVW/crP7ztfzaMRauCHHtU2pI4RMzidq/MNEJfWHl8ktGKaE17OON0t+EOZktItw4UZaOzf53W3ApqvjLbDlJO3DqIwgkPrmXO91CZrZpdS1kWC0WUP6ib6yyNTagWkNf85MP+FMqGBUkzm0V6QP1/bW5+UBEt3C5ppUewp9OyD0UKtpGxBSlAE3nyvPRr2anyAD2SvzUiWFv6aRAD9Voln2gzdh9UP5YE/xikCmLI66I6111OgQSVd3sj3YoF4gQIdUKKNrjhnuf1xzc9doU X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2024 13:52:26.6646 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd08990a-ba6f-4adc-73d8-08dcc2b1a851 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B077.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6736 In commit 8510801a9dbd ("selftests: drv-net: add ability to schedule cleanup with defer()"), a defer helper was added to Python selftests. The idea is to keep cleanup commands close to their dirtying counterparts, thereby making it more transparent what is cleaning up what, making it harder to miss a cleanup, and make the whole cleanup business exception safe. All these benefits are applicable to bash as well, exception safety can be interpreted in terms of safety vs. a SIGINT. This patch therefore introduces a framework of several helpers that serve to schedule cleanups in bash selftests: - defer_scope_push(), defer_scope_pop(): Deferred statements can be batched together in scopes. When a scope is popped, the deferred commands schoduled in that scope are executed in the order opposite to order of their scheduling. - defer(): Schedules a defer to the most recently pushed scope (or the default scope if none was pushed.) - defer_scopes_cleanup(): Pops any unpopped scopes, including the default one. The selftests that use defer should run this in their cleanup function. This is important to get cleanups of interrupted scripts. Consistent use of defers however obviates the need for a separate cleanup function -- everything is just taken care of in defers. So this patch actually introduces a cleanup() helper in the forwarding lib.sh, which calls just pre_cleanup() and defer_scopes_cleanup(). Selftests are obviously still free to override the function. - defer_scoped_fn(): Sometimes a function would like to introduce a new defer scope, then run whatever it is that it wants to run, and then pop the scope to run the deferred cleanups. The helper defer_scoped_fn() can be used to derive from one function its wrapper that pushes a defer scope before the function is called, and pops it after it returns. The following patches will convert several selftests to this new framework. Signed-off-by: Petr Machata --- tools/testing/selftests/net/forwarding/lib.sh | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 67f38dd1f36b..21cd6a2e3344 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -1369,6 +1369,12 @@ tests_run() done } +cleanup() +{ + pre_cleanup + defer_scopes_cleanup +} + multipath_eval() { local desc="$1" @@ -1423,6 +1429,83 @@ in_ns() EOF } +# map[(defer_scope,cleanup_id) -> cleanup_command] +declare -A DEFERS +# map[defer_scope -> # cleanup_commands] +declare -a NDEFERS=(0) +DEFER_SCOPE=0 + +defer_scope_push() +{ + ((DEFER_SCOPE++)) + NDEFERS[${DEFER_SCOPE}]=0 +} + +defer_scope_pop() +{ + local defer_key + local defer_ix + + for ((defer_ix=${NDEFERS[${DEFER_SCOPE}]}; defer_ix-->0; )); do + defer_key=${DEFER_SCOPE},$defer_ix + ${DEFERS[$defer_key]} + unset DEFERS[$defer_key] + done + + NDEFERS[${DEFER_SCOPE}]=0 + ((DEFER_SCOPE--)) +} + +defer() +{ + local defer_key=${DEFER_SCOPE},${NDEFERS[${DEFER_SCOPE}]} + local defer="$@" + + DEFERS[$defer_key]="$defer" + NDEFERS[${DEFER_SCOPE}]=$((${NDEFERS[${DEFER_SCOPE}]} + 1)) +} + +defer_scopes_cleanup() +{ + while ((DEFER_SCOPE >= 0)); do + defer_scope_pop + done +} + +defer_scoped_fn() +{ + local name=$1; shift; + local mangle=__defer_scoped__ + + declare -f $name >/dev/null + if (($?)); then + echo "Cannot make non-existent function '$name' defer-scoped" \ + > /dev/stderr + exit 1 + fi + + declare -f $mangle$name + if ((! $?)); then + echo "The function '$name' appears to already be defer-scoped" \ + > /dev/stderr + exit 1 + fi + + eval "$mangle$(declare -f $name)" + local body=" + $name() { + local ret; + defer_scope_push; + $mangle$name \"\$@\"; + ret=\$?; + defer_scope_pop; + return \$ret; + } + " + unset $name + eval "$body" +} + ############################################################################## # Tests From patchwork Thu Aug 22 13:49:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 821984 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2071.outbound.protection.outlook.com [40.107.220.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD1961CCEDC; Thu, 22 Aug 2024 13:52:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334759; cv=fail; b=UocE9jDfo/Sgm9ABxBA+AsgjNLQUCyjlYkHHVg0S+gDhXjVdjU23NulgTP/F0gfTaGn+OlWP8r1XvDPPrlWDiAVCralq9fcLKgXLqI6ABbyWg/txgCweIjUC/14Ct5sayjXk4vVGW75UT4x+L6VW9wgVBcB38FqM30iCpVBWxho= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334759; c=relaxed/simple; bh=TPihotGRDiRMCeG2dXcjw3hDnzf57sBNG0BJCHqt1hg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bYDxjvpyyILuXf37XZ6JWk1O5rI5ppB4DZeGF5JSYk1jk5zkPdsONnTfUxrhxV1wnLNoeRIf/n16oXPcVZrk2Cx8TTuigcr1EDekIjW0g4iA7nqQ3ZKwHbvJNCdm5/BSyVQD/MeNg9kQlr6Tzk2PikTNqxchxgVoXwztlbqT4AU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=ilvIkLK2; arc=fail smtp.client-ip=40.107.220.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ilvIkLK2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=y8D5a7dDC1PTSDmFLeelt33waakDL74/XgK7IvSP7lvNclKNfL8WxdhihTcdvX3O6RvbU2Zm6hLbiAreaItGHbtB+Jt9rL74ifDl47WLc6JIy0IiYqVsPFhQ32F3k3EbZwsPnwgP+6R1+ENJ6WUQ5B+gJVtlLOqBTHb9/CuWORRXbfG8JpYaf/ZWigBSEwz9rUMlFInn2jWdu/btqEncxnA8bb+rrEr6YKyfYIQy8HM///jaVEgSV+8oUj4zNzvSBlAKGMt+hA417UmALUjbFJvFJ2ZdYtaEHMfqjaPco9IKHWD1rlFEpC1qrmsVXAayD1FtiwOiUhO+/gP1i+1qqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uv87u9kUDdMqg9Gnr+g8FXFozGTT0scGyYoBDsooOic=; b=pj/tkkmnPaBUcSZvbkzOxialEVsMR8QQWzIggizj/5sOAoZJpR4OR3piWmp4E6/w5pp3Z+5Yw+BupBuH8Qoppk+6eVwgHILO6peWnJ6i/UmpEYVmHBdLx3dX8WVCEEPaInEC9i2o5hnFdV+tZgbc5WWv+lncnTUs9L/Yi/o2oUpictKFxR7ajaCMuQ27Yvv6G0MgOpTcgVFjGMwNZwfsvcDNePCx+8NJkUZr98PSyPmosnVKWYREa5oAynkrPpXWW56SDwVrsWckLqjjHa2iDtFDIP4HiSkN0wDlmPXqex7uS7kXTWG8+0fD6Zr365Sy3pHvAPxyt6+S1+Ko/OvRdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uv87u9kUDdMqg9Gnr+g8FXFozGTT0scGyYoBDsooOic=; b=ilvIkLK2vCd+KOnMqFAuK5WBckg35wCDqPwSim80OETgFhGpitPDGn59QPgD6kpTMiEacSod11d8jrSzxNiH5N8uAiy5ogtT4ujg6xg/1R6p3zC+mmj5SzmjnQXkl9dfMacqdG1buDZOy6hW5Kudb42e2j37LTku0k7q+HXPwYwdDXJOD9l7ljERrSWXIjs04YIZnCxX8pLyzTiWbzWokjscTJLVWy0jPICBZO924/yQPigL1PpoZh3OpnShJHnlAaFlbidSs11OW0UzEAeDmEvUYp/1pL6sUYXV8Ie3sUrQtaOX8ykqVx+5osuKjgf+XpuGAPFoiX6GBzKE6H1YMQ== Received: from BN0PR07CA0017.namprd07.prod.outlook.com (2603:10b6:408:141::31) by LV8PR12MB9109.namprd12.prod.outlook.com (2603:10b6:408:18a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.18; Thu, 22 Aug 2024 13:52:33 +0000 Received: from BN3PEPF0000B073.namprd04.prod.outlook.com (2603:10b6:408:141:cafe::85) by BN0PR07CA0017.outlook.office365.com (2603:10b6:408:141::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.23 via Frontend Transport; Thu, 22 Aug 2024 13:52:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B073.mail.protection.outlook.com (10.167.243.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11 via Frontend Transport; Thu, 22 Aug 2024 13:52:33 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 22 Aug 2024 06:52:17 -0700 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 22 Aug 2024 06:52:13 -0700 From: Petr Machata To: Shuah Khan , , CC: Jakub Kicinski , Ido Schimmel , "Petr Machata" , Amit Cohen , Benjamin Poirier , Hangbin Liu , Vladimir Oltean , Subject: [RFC PATCH net-next 2/5] selftests: mlxsw: sch_red_core: Use defer for test cleanup Date: Thu, 22 Aug 2024 15:49:41 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B073:EE_|LV8PR12MB9109:EE_ X-MS-Office365-Filtering-Correlation-Id: 082eedee-03db-42a0-df81-08dcc2b1ac2e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: JkuWHCEiECByUw7ZROMU9/ocM03asLrRIjqzEvCdno+XoSqn+YsgOjapjnwCrKDu3EQt5rv4xYBwMKHec+Gt7G3UzovW4cqYQEiQo0NNRgDiwmZ9FKl5aN6Yf25HCa/4uNP/eaDfROc/oFKDTWKDidpFUBmXFXO8vAHHrmSXS3sxnHNzyXImigR88hvKx7A7yhmylJFyHrAwV15FXBSJgndgsE54YueJ/Wrr3AdIt2x4U+/AzMNGYxoDYYbDL3Dy0aaJ5gLphn2BMUNDr0sBcFycnJBmIkQzsp4AhSEP351/I7CpfBmWFpwzbXLCaAEBnpHROxmAVDcJAEgkSXDOjVkwC5ZRE9HqZIlTXPZHmwnSrkHgM9uW66OGX5cFONqGeO6675xJC4g8NDZwU8JQ8b3RMQgwBvCivSrNOg2BpFW3/FSpcJ7wney0G7fxqSN38Q6bnaBj2721qta/O6j/lSbJpjB1ztlYgdf1SXeyo76RsdePk31BEw1rBSdxuL6yKxEHSdQr4f+wO9ErDnf4I1rCdxCkQGL+wYE5zSxbbFSFea4T7WRdUxYPsWrwdlgn35yCB9RkHZW0egKi8NN7HXnMBLqWWf5hSEYtsbYMyoLoN6OmoFPTNz4BXB0UqBeMrNvWxKjEh7RZbarzu5gF8h/igS5SoVBRVXPOMfNpWfE3UfdPbJJ4bz7VgZJaKxTgImguzpoxTGPBcLNNAoOCRtDNY0E8AWwpNGmTwqKXupN6y0chVdjlaePQ/esJHk1Su+mAgR/qV5EgoJM75BbHUkYPXeuYzPmhyV68SMNB1Ce8nB1m1/vTcRSqteST9+QVO3gFWJU6jd2pOL/zs0+0cpX+8keIpSIAQBokhJGxkGEZqACWE3bugzRNaaFqDGkOPULNyAZQ82JQyds9CcPYlQxHLHJp2oxpbSSAXXU55SabNGSh5OFfIjnHaTYYPELNdqrpkCfIbQkXLnMlnXNB36EBiKvFxnFnYrfJv9EwErnMPurQ2KuZBpEW8Xzi1azuh8fwgoDiChqAWBy6iuHcFL9pdW7DiOxC1knLfAC8k2uAg6f2NcQgGwTQ7wmZCDmwXTX1SIixYQkZOq0l8WSjIiW1X4bOXY1Ea6d6tXB4CDTIz1rOtyzgyMrcRKES7RbVx5tPzYwIEHnTU3Oh4UOGzDYpsgRtU7GENSKCE1Q0MlKzkaDgHP0aHDqtRkumzp24/CbPe5W9VkQiCIRgxYHfblJUxlA1Y26PGo+iRVmRR5U7h3fxzeH5rxZzajwBupA5+Pn+K+WlIBK2VbFDjH99OgbGnEPIOhvd2tlXSDl3NhoLNsj/QVlWSFzuC8bcLXUyxcGkTsMtYZdjQ7+WyxOSaYTeKos4Equ/jsDo3HLZw+xnMusQIM2ZOfL+KoHIWkFoe5zZ7Hf4a3MEBDUca4Bb3sbNsDjWvqoS1TvNp8KAcjiEKjy12kibA7ki4/m5hz/m X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230040)(376014)(36860700013)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2024 13:52:33.1489 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 082eedee-03db-42a0-df81-08dcc2b1ac2e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B073.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9109 Instead of having a suite of dedicated cleanup functions, use the defer framework to schedule cleanups right as their setup functions are run. This makes a dedicated cleanup() moot, instead fall back to the lib.sh-provided one, which invokes the necessary defer cleanups as well. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- .../drivers/net/mlxsw/sch_red_core.sh | 109 ++++++------------ 1 file changed, 37 insertions(+), 72 deletions(-) diff --git a/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh b/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh index 7151b0c7bf8d..117a99fdbba5 100644 --- a/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh +++ b/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh @@ -89,39 +89,31 @@ host_create() local host=$1; shift simple_if_init $dev + defer simple_if_fini $dev + mtu_set $dev 10000 + defer mtu_restore $dev vlan_create $dev 10 v$dev $(ipaddr $host 10)/28 + defer vlan_destroy $dev 10 ip link set dev $dev.10 type vlan egress 0:0 vlan_create $dev 11 v$dev $(ipaddr $host 11)/28 + defer vlan_destroy $dev 11 ip link set dev $dev.11 type vlan egress 0:1 } -host_destroy() -{ - local dev=$1; shift - - vlan_destroy $dev 11 - vlan_destroy $dev 10 - mtu_restore $dev - simple_if_fini $dev -} - h1_create() { host_create $h1 1 } -h1_destroy() -{ - host_destroy $h1 -} - h2_create() { host_create $h2 2 + tc qdisc add dev $h2 clsact + defer tc qdisc del dev $h2 clsact # Some of the tests in this suite use multicast traffic. As this traffic # enters BR2_10 resp. BR2_11, it is flooded to all other ports. Thus @@ -139,13 +131,7 @@ h2_create() tc qdisc replace dev $h2 root handle 10: tbf rate 1gbit \ burst 128K limit 1G -} - -h2_destroy() -{ - tc qdisc del dev $h2 root handle 10: - tc qdisc del dev $h2 clsact - host_destroy $h2 + defer tc qdisc del dev $h2 root handle 10: } h3_create() @@ -153,40 +139,54 @@ h3_create() host_create $h3 3 } -h3_destroy() -{ - host_destroy $h3 -} - switch_create() { local intf local vlan ip link add dev br1_10 type bridge + defer ip link del dev br1_10 + ip link add dev br1_11 type bridge + defer ip link del dev br1_11 ip link add dev br2_10 type bridge + defer ip link del dev br2_10 + ip link add dev br2_11 type bridge + defer ip link del dev br2_11 for intf in $swp1 $swp2 $swp3 $swp4 $swp5; do ip link set dev $intf up + defer ip link set dev $intf down + mtu_set $intf 10000 + defer mtu_restore $intf done for intf in $swp1 $swp4; do for vlan in 10 11; do vlan_create $intf $vlan + defer vlan_destroy $intf $vlan + ip link set dev $intf.$vlan master br1_$vlan + defer ip link set dev $intf.$vlan nomaster + ip link set dev $intf.$vlan up + defer ip link set dev $intf.$vlan up done done for intf in $swp2 $swp3 $swp5; do for vlan in 10 11; do vlan_create $intf $vlan + defer vlan_destroy $intf $vlan + ip link set dev $intf.$vlan master br2_$vlan + defer ip link set dev $intf.$vlan nomaster + ip link set dev $intf.$vlan up + defer ip link set dev $intf.$vlan up done done @@ -201,49 +201,25 @@ switch_create() for intf in $swp3 $swp4; do tc qdisc replace dev $intf root handle 1: tbf rate 1gbit \ burst 128K limit 1G + defer tc qdisc del dev $intf root handle 1: done ip link set dev br1_10 up + defer ip link set dev br1_10 down + ip link set dev br1_11 up + defer ip link set dev br1_11 down + ip link set dev br2_10 up + defer ip link set dev br2_10 down + ip link set dev br2_11 up + defer ip link set dev br2_11 down local size=$(devlink_pool_size_thtype 0 | cut -d' ' -f 1) devlink_port_pool_th_save $swp3 8 devlink_port_pool_th_set $swp3 8 $size -} - -switch_destroy() -{ - local intf - local vlan - - devlink_port_pool_th_restore $swp3 8 - - ip link set dev br2_11 down - ip link set dev br2_10 down - ip link set dev br1_11 down - ip link set dev br1_10 down - - for intf in $swp4 $swp3; do - tc qdisc del dev $intf root handle 1: - done - - for intf in $swp5 $swp3 $swp2 $swp4 $swp1; do - for vlan in 11 10; do - ip link set dev $intf.$vlan down - ip link set dev $intf.$vlan nomaster - vlan_destroy $intf $vlan - done - - mtu_restore $intf - ip link set dev $intf down - done - - ip link del dev br2_11 - ip link del dev br2_10 - ip link del dev br1_11 - ip link del dev br1_10 + defer devlink_port_pool_th_restore $swp3 8 } setup_prepare() @@ -263,6 +239,7 @@ setup_prepare() h3_mac=$(mac_get $h3) vrf_prepare + defer vrf_cleanup h1_create h2_create @@ -270,18 +247,6 @@ setup_prepare() switch_create } -cleanup() -{ - pre_cleanup - - switch_destroy - h3_destroy - h2_destroy - h1_destroy - - vrf_cleanup -} - ping_ipv4() { ping_test $h1.10 $(ipaddr 3 10) " from host 1, vlan 10" From patchwork Thu Aug 22 13:49:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 821490 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2062.outbound.protection.outlook.com [40.107.94.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFCED1CB15E; Thu, 22 Aug 2024 13:52:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334768; cv=fail; b=SKFVBKXfgtt826CSxKZEbh//iT26XC372rSn0pF6SCu5dS43W6T63ks0rqIptLT978f6FafbUeoCPhbhxSI1x7rJdtXgwlGfHfLOfoSRYx49Z8eZNmjwRfjdgv/arktp21pE5TNC5Mu+OprH1miyEd1ed1hk/etyGiz196wm8dU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334768; c=relaxed/simple; bh=N+OgTknEiGlJ7tsxZpigeDGHbnbnl+0kvj5NRxJFmx4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HQ0B35GGTPb20/VOaysHXyZl5Hj/Roe2zDSb4fzo34URIE+w6FZAzbwrIwchCPCWAA2XtW3q4S7mCO0WyQCRr16cbFFeCo1IVMybqskQyGzbZ44W/XvLIG+Y1lsXt67pNCNmbz5s8sY5N/JFnr4Jc1KZtNQdDN5jKNI9Hi4oJFs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=SkqIRJHg; arc=fail smtp.client-ip=40.107.94.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="SkqIRJHg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DxC8UzbRxaKeCxUZLa6mIWale+j0PgprpN8CXUMEiDxG9GnUYe7hDZ5nmrNUlnqEDVp/tfvlXf5CwipX9pfeqqUJE8g+MCSfk7XLYL7YmgOJaT2p8eup5CvHaJs6lMdUsjDJOzfSk9KZwJlQAZPL95PdJxInrxwVrwrvi1OJlNH/z5eBNuL9Xe5TV6SjOHxq+OgkmdhhAl+zsxJOlhdV6ntrhpxIJwuKoBirCe5qJga28nmnAOG3a9XASLYO0337HOmuWxkF8LT1MgEbNkoQOGIRGlJOpTFBE41OxLmLvVANIK+XtBe+c7WOuOtJeciElGFBoRXqJBpqDnL6u1TAdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UmtDEl9fFfzue4lrx1mlELcjb4p8Jwr+JA7Aeb8SpNw=; b=hvJeCvBNJUOLHZIWwE1iAkAtlmUjV+9MO9buWoVrNDDmgJL0OyfmiLMHdEc2Aln9/EwwtLpk12H7NUxUxB+WgAX8C8TO4cXo6Okccmb4zEsQNpQI+vS7HBQ0xQKDW6mxgkt5d9zA5ExanzqlZsR6vdM456qYqYQbG/evwCsgmk9FUT2MXi7PV/RHtiCkJa6kYegI7ymwSojlgBMxMZipEsPI2XR1i9c5pTW3MrHgdpuPF72B0Ijf5vbd3OvhqvTzwH3Q5h7n+9uxXviHTlQ2gwbq5SDgAm1sZAWLUhsX5RQVMrGT339UH/KjghEpQcnu8R2RqRCYR8CbHPlawi1PYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UmtDEl9fFfzue4lrx1mlELcjb4p8Jwr+JA7Aeb8SpNw=; b=SkqIRJHgrPJTY+K2MnL3VgzMROoNy41cP0HLRhjOdkxBwrWuZSyD2KRMu1Fm5AHoFTfBo2cT5oCOlnMXkUJGmgfP3bXrs/9xjtqs6Odj9Mz7tDowzTFhH1km/m0izmGvzg9D/770DvzMTbvVm9UAziYT8XUsjIUPlOcQp8aoCrsYzOjzBOATRvpezQgZty/HcZNdtTnqyHLYVjRzGDUDnjPlZMD5s3lanLClC43iF4DqRxsYLJZCgzkqGp/plw25SwULFooKgfy9RzYdEJSwsKpr4jVmeY1YNBeBf+jCFsV+J1ym5Zz+zb1NhdggbhwEHUrrH/1+/VfQO7aGe3ZtSA== Received: from CYZPR14CA0019.namprd14.prod.outlook.com (2603:10b6:930:8f::10) by SJ2PR12MB8719.namprd12.prod.outlook.com (2603:10b6:a03:543::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Thu, 22 Aug 2024 13:52:40 +0000 Received: from CY4PEPF0000FCC5.namprd03.prod.outlook.com (2603:10b6:930:8f:cafe::ca) by CYZPR14CA0019.outlook.office365.com (2603:10b6:930:8f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21 via Frontend Transport; Thu, 22 Aug 2024 13:52:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000FCC5.mail.protection.outlook.com (10.167.242.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11 via Frontend Transport; Thu, 22 Aug 2024 13:52:40 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 22 Aug 2024 06:52:23 -0700 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 22 Aug 2024 06:52:18 -0700 From: Petr Machata To: Shuah Khan , , CC: Jakub Kicinski , Ido Schimmel , "Petr Machata" , Amit Cohen , Benjamin Poirier , Hangbin Liu , Vladimir Oltean , Subject: [RFC PATCH net-next 3/5] selftests: mlxsw: sch_red_core: Use defer for stopping traffic Date: Thu, 22 Aug 2024 15:49:42 +0200 Message-ID: <6dc79e54a02623f0f2bb11533be1dc230ddcecec.1724324945.git.petrm@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC5:EE_|SJ2PR12MB8719:EE_ X-MS-Office365-Filtering-Correlation-Id: 6f74e378-3c41-4387-3742-08dcc2b1b063 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: 0KawfLEU4S9VRscXXH9p8zfXfJpYWb2wo+9PZnkW1CxeoXuntoFVjZU0mXBb0IipFA+pcmuBuzVw+rUqroa3syBAa0D91Q180qjNXZlwlTbvx8I5rPuRaM4L4Vta6VUDtrvzb0gkSKcZgyt6oscCQE8RVevUSOQN+PTBUWjJvOgLDBcM4tuFlSVwrSuWmMm7FIgeLRNjokG6T3B5/xImleB2uOJpIkkc5s78lDCEgHeFfSevI1kvMNDuPaaMq9pGfSGY+UiOAKv1AOO+sBkhaQeoz4N4yax7PRnc4L5evtpw7ODskRmHFcFBQZFnXYQFSrYAA8+skZPf1Qaif+62vOLSC8YNoAnR/5QbuwSw3FQDxtenhP8nKy7rohLkxrK7dzJ3dMSdw5TXeEwGrKa21bqI6gtsiqxvbKFlC7Fx7T0qQzl/0kmfo8ff7u4Ro5finrEVrwvBbLhMq+55mTphFtUv2o39vyA7m+iA9OS2ajFDmrMAe+LNT91bsZZq53ECdDNaOig2jfsdPauM7ZsO60wCfhQDryikqP/zTTnQD94y2Z3MK5Rc2CLG3GK3+oy99S+dZwVWwH1taRKbSUOEHf5KVnu/2Ju9JuRf1PKIgtjCWu6FPJXgUL0DVcFpDDESjnc6u1w2/zK28LDBl/9H3YmfxeJ54vwXK/olqcOuoy4Udw4o/WdesauZmSZLgUCiNBGnfxVD/Piu2Qgr4gvTLj0EZL4gZ8FdK1b3NyYuzV5mXQPthS+UsF/MNN4V1y3plZBri9BJzkQwT22rmYR9/8GGAp2A0uvBJX8ccRAaLQ1iD5bUFbzFJEwEN/bO1sGaH8A1PaeooB0baeBapScHKT1AwW7crpWODZ55XoM7X2cNpQn9/fCIfwazKWBDpdIug6cQ/No5rcButnu0/Sw0K50xGr+Pv4KeXLrdHxRapJ5GkQLGOAimUwa3BRarx4EikiruD87cJ6uvio/g3ai+jIrfosVaIWibr3fq5+/ZCgB7KCUy8jiKezxvRDJOO8LhmMz2cHGzo7Z2rB2VWnYhcGemrwSXNeO8k+eEwvsi5LRpT+5A7cPQZnq85hfG4I0av2+mxTfEBhIVlv8Syr+VLsHR6nekhfkgV5Bf0qgtlwJfrrk9LNi5N4/2lEtToPounzH7Suf/+uXJa4t/4ldydtQs2L1hU/bEmX923K+88Iz+6vHCuTt2xSeFEDPBDFZmp9vv4D79EIA6Pt/TXeZzIyHNtCugfJmOxsYKoiTNdt/D+Ipj0UWgZ1HTlhLbe9W4h+hl6q0lAhSsj1EH0HaTx3fqFgPClKL8kqhTdQuxe6U6ZU8czDhQwhF87M8ci+tzylk+hxEoSJqaGBlHUW08wlqmffNVDmgor0YNHKif1uaqiU54j9W3LTrxg7dOI4I94avltilCXZqJuonOLb6qbmPFCceYRDKFhZdxePlEZdOnoqjcGUGDkwwLKH11CWBM X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2024 13:52:40.2966 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6f74e378-3c41-4387-3742-08dcc2b1b063 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC5.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8719 Tests interrupted part-way through leave behind a running mausezahn. Use defer to schedule a traffic stop after traffic is started. Mark the functions that run traffic as defer-scoped, such that the traffic is stopped right after the function returns. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- .../drivers/net/mlxsw/sch_red_core.sh | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh b/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh index 117a99fdbba5..c917b88d300e 100644 --- a/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh +++ b/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh @@ -415,6 +415,7 @@ __do_ecn_test() start_tcp_traffic $h1.$vlan $(ipaddr 1 $vlan) $(ipaddr 3 $vlan) \ $h3_mac tos=0x01 + defer stop_traffic sleep 1 ecn_test_common "$name" "$get_nmarked" $vlan $limit @@ -427,9 +428,9 @@ __do_ecn_test() check_fail $? "UDP traffic went into backlog instead of being early-dropped" log_test "TC $((vlan - 10)): $name backlog > limit: UDP early-dropped" - stop_traffic sleep 1 } +defer_scoped_fn __do_ecn_test do_ecn_test() { @@ -456,6 +457,7 @@ do_ecn_nodrop_test() start_tcp_traffic $h1.$vlan $(ipaddr 1 $vlan) $(ipaddr 3 $vlan) \ $h3_mac tos=0x01 + defer stop_traffic sleep 1 ecn_test_common "$name" get_nmarked $vlan $limit @@ -468,9 +470,9 @@ do_ecn_nodrop_test() check_err $? "UDP traffic was early-dropped instead of getting into backlog" log_test "TC $((vlan - 10)): $name backlog > limit: UDP not dropped" - stop_traffic sleep 1 } +defer_scoped_fn do_ecn_nodrop_test do_red_test() { @@ -483,6 +485,7 @@ do_red_test() # is above limit. start_tcp_traffic $h1.$vlan $(ipaddr 1 $vlan) $(ipaddr 3 $vlan) \ $h3_mac tos=0x01 + defer stop_traffic # Pushing below the queue limit should work. RET=0 @@ -506,9 +509,9 @@ do_red_test() check_err $? "backlog $backlog / $limit expected <= 10% distance" log_test "TC $((vlan - 10)): RED backlog > limit" - stop_traffic sleep 1 } +defer_scoped_fn do_red_test do_mc_backlog_test() { @@ -520,7 +523,10 @@ do_mc_backlog_test() RET=0 start_tcp_traffic $h1.$vlan $(ipaddr 1 $vlan) $(ipaddr 3 $vlan) bc + defer stop_traffic + start_tcp_traffic $h2.$vlan $(ipaddr 2 $vlan) $(ipaddr 3 $vlan) bc + defer stop_traffic qbl=$(busywait 5000 until_counter_is ">= 500000" \ get_qdisc_backlog $vlan) @@ -533,11 +539,9 @@ do_mc_backlog_test() get_mc_transmit_queue $vlan) check_err $? "MC backlog reported by qdisc not visible in ethtool" - stop_traffic - stop_traffic - log_test "TC $((vlan - 10)): Qdisc reports MC backlog" } +defer_scoped_fn do_mc_backlog_test do_mark_test() { @@ -554,6 +558,7 @@ do_mark_test() start_tcp_traffic $h1.$vlan $(ipaddr 1 $vlan) $(ipaddr 3 $vlan) \ $h3_mac tos=0x01 + defer stop_traffic # Create a bit of a backlog and observe no mirroring due to marks. qevent_rule_install_$subtest @@ -584,9 +589,9 @@ do_mark_test() log_test "TC $((vlan - 10)): marked packets $subtest'd" fi - stop_traffic sleep 1 } +defer_scoped_fn do_mark_test do_drop_test() { @@ -603,6 +608,7 @@ do_drop_test() RET=0 start_traffic $h1.$vlan $(ipaddr 1 $vlan) $(ipaddr 3 $vlan) $h3_mac + defer stop_traffic # Create a bit of a backlog and observe no mirroring due to drops. qevent_rule_install_$subtest @@ -636,9 +642,9 @@ do_drop_test() log_test "TC $((vlan - 10)): ${trigger}ped packets $subtest'd" - stop_traffic sleep 1 } +defer_scoped_fn do_drop_test qevent_rule_install_mirror() { From patchwork Thu Aug 22 13:49:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 821489 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2075.outbound.protection.outlook.com [40.107.236.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CB791CBEA9; Thu, 22 Aug 2024 13:52:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334772; cv=fail; b=u5/CZSmQMSIZ54OsvWOoLNASyXDvPkkd7+rxH4BfSX41SPNTe3joXzb4HAL82U9e54UigZn3izG8lugOgMKKG6rjrPJxSeXQVeHW0j7Gi9FGYiUJOQ1d5k5qmCepl8ofDXXmiwsXJe8M9foHJoUWnFMTATvbFKwHuqnz+AJBhL4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334772; c=relaxed/simple; bh=VC7wVbHkdziK2MFGhHW/f0rp8dFw/s9/v8lHnj7t3a0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZOOjR6DJeWjD1ir7r4zp1iqHecaCpw32jBq1xZ5LvsPyxDS/yDSkl+BiF6HzqoVz4zg8QpkMjA4anQVEZWZNx8EQt3//SZQ+fCLx0ORO5Snkbv9MRDztJlKlCkiu8ghM8tVKpjPIr9/YAvwmWrxsYvJoHFSbJfMQtn2rRqETNxw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=tdZHo/Rm; arc=fail smtp.client-ip=40.107.236.75 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="tdZHo/Rm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gbmCOcrBv9IigbW48HPyIHyx3fGmoPiTy5+NHeUMUdzzZMcsbn6ZAUEjWifPJm+ZqCs9wLy+IdSh0sTmks5m/JYqKzC6x1gnFLFXzRuADnfpJ9Qka89KcxnUd2YiN7Ljs5mj1YyBQSVPK+9Qu6V+CVPVGOt3ax04NL9ipKpMl58sNLKWzXc669XrQSG/W1hpRH0EplbxhzLAFsWbc/PrgPf7SwXGXh4fKjNuMDHTIWgLhl7CCvzFTJ1vtSm2/U7hb8I/xgwP0RQGzwhbpzjpFZaoOWRiK+LnGzf54vOZ9JahB+GWueQyvVll4BkFGjnb1vYosN8E+pa/NFMHF2FUAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GTr6B/82sRFS7ugHht5hr0b30v2oZ5qEj+8riV9jFvg=; b=rOB879buzBRY1Gex3CiKUx0idaSjw6hQ+Db/4hvMToQIiYhD0s36MTpTO0J+QKabPzL/ZMTsfWwaMV2UPGmC80VK9BmMqXkVyoBIGep7qASnzZAgls29MXjdQhv9UAjQyWDqmDjK+QkXmHyTbN17QmUuTkSIO1yzSUmrDg1d+JgXKn/eDpQ2j4ZbTQQ9U/XbN8nUAkzYHO5+bZ6lZ34c6pxIMewnIirIbqetPksNCfS28zXAbHCnr5/k4pIFFTnmclmnoykkujDIrdHXhq3j0YZXlszSwzXG+BGEbvGy/zkcOjpWbiWonITtDlafzcmaqDlhHJx+uhaBe/Ky8gX3Qg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GTr6B/82sRFS7ugHht5hr0b30v2oZ5qEj+8riV9jFvg=; b=tdZHo/RmUlZLoEL4FpwJgnTt9ko/tp9+hfDC87AtY6G8n8KVY1UzpmdFrSQI67f5HGuQdq1MdH5BsObfLvmBzd52m5HRwQTt4zH3b7hnr6Q76gUi6cIgVHpqW79jSoYmaedeacSA4DRHpJ6G4r43NSiLgWXLqXJw2CR+i4Vc/eSXAjIDpEkKgFQmclXLqc9VloTHtNEeZysxR8ANEQHemiUleNhjGCCkCTd0aUMLYUcQjqqYzTSmtVtV2Muh3PKp7Kk30qmPnyHaRZ8Qk1wPnEeQy284/PM8ASdp5JWxS0Pge3eUv0BSP/+NibRfhkqU0VBONCeaslrsOxfo8UmkNw== Received: from CH0PR03CA0379.namprd03.prod.outlook.com (2603:10b6:610:119::6) by DM4PR12MB5916.namprd12.prod.outlook.com (2603:10b6:8:69::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.16; Thu, 22 Aug 2024 13:52:42 +0000 Received: from CY4PEPF0000FCC0.namprd03.prod.outlook.com (2603:10b6:610:119:cafe::1d) by CH0PR03CA0379.outlook.office365.com (2603:10b6:610:119::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.26 via Frontend Transport; Thu, 22 Aug 2024 13:52:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000FCC0.mail.protection.outlook.com (10.167.242.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11 via Frontend Transport; Thu, 22 Aug 2024 13:52:42 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 22 Aug 2024 06:52:28 -0700 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 22 Aug 2024 06:52:23 -0700 From: Petr Machata To: Shuah Khan , , CC: Jakub Kicinski , Ido Schimmel , "Petr Machata" , Amit Cohen , Benjamin Poirier , Hangbin Liu , Vladimir Oltean , Subject: [RFC PATCH net-next 4/5] selftests: mlxsw: sch_red_*: Use defer for qdisc management Date: Thu, 22 Aug 2024 15:49:43 +0200 Message-ID: <86f5621c15804eddd7563d0ead0cf3c75c08fac0.1724324945.git.petrm@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC0:EE_|DM4PR12MB5916:EE_ X-MS-Office365-Filtering-Correlation-Id: 94dc6401-d979-4898-dd66-08dcc2b1b19b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: 5lAMbvTxonfzo0J0mkVLOlzaRMQE0Ros60/j3FpYEmQw0BTuHaAVW4TzZkgQuj3NQrqyxGVHpkYtrSGQiRIopmFQl24hEarRmBn8SjpvLBnY2AcfgDdRPJjK/bIhIuj4q+OToTbE/ufyWnIkz6ll3NBpWvPBYthYNtY8X1PPO5ASnCEmjmB9G2/G7W7ropVzBa7XEXbmLvfL9H3pgd0p8lmyKEeyoTwVVaF8vnjIWYT2rmFQbxuZ7tHdGVg+4paF/lUrywfL2EnXM7wlI/EJ6ClAkTxjni6HzCCAf8PwzwvqmPBMlGJY8sdifImCAAPlkadagfLem7BrhVgcmKhWb9+bUqZF3x4XXiqC7bmppJ5YkkKEwLhVxqd7PhDMaJDRWFZXTDRFdv4qxy1GaH5vpuAh0btJUt8VNbd/xoLRXTRwE/CrFpP8NshMG9xPeURarMfsZkrxZlJM5tA7Cw4q9jTeOpgY5qi+yiPjt/QOyXkU6nmFr9l6I0zAq75Hk30QdYK3Mkq5CF5k5VKf3RfCdC1bsKA3iO5EVY5xWeopXGyW/R4L/M19XPCHE7cml+JQvVd5E8IdmijRUxfpkx4CKV/p4eIe9iMMyv5aco6pfhSVLkBC59iirFa0iruYyjEhOdCKGNHWoRTsxUynA5HS8fH0zirbwbEeQA8Tx3rXktfprkQkY7cJ+h/bbmsrOLDbV0PplzhzUkcIF3rDyj+Uqpq1In2ktqehBwjxh/hwlFkWIiJZorb4zWsJKK+W3U+LU5qwCqJLpy52GEYlmEgU+aa6TnKt6KrPyKLAT84zYf+1wvnhdGUX9pGvOjx7393MTJzxaJodabaXyAlrnlr/jPQKON0/z1ZdDD149bUqkPhrquD08Mv7OLfAn2Ki1tFZXlCSfGicjaF7Mm84+y0eR10jLpFW0GP6UYbBafBGnPhX8Gw2wByhkgHuJ90BQeIG+kEDx/R6n4QJF+KUfXli+RdTVEQDvzm2J+/8NgI/L7ElMfK4nPRlbiRIZ6zkq2C2IczdeRPerBnaJK8sbe2MNao2JhErcHTBDRKUC4uQKtBTqkHYckeKwZZ6RFD5qXcjJ9COz0CPhrkKYhukFI7TWF2q5Y+azvIA6PeBPryuJJkRYRfPotGuHrwzNe8JfkXLUPXvRM9CS/oZ0PjL2cvwN8TpdyiJB9oOr+/AxpN6iQSf2syI3WnBRy7NWwEb+kPKCxevUhpPDtmCnLQvXqhFlq+EngNTd01W2cU4ut13taf8zUroaDAdgkjCxkeZOKpsBkmkVer4tOcLV1luBxkiAkTtf+IcQ7nKe/mLYiuhGhIWnEneAIVUy4aevoqrJM4WAK3F0Oie4azsfzb3EMLtUachpQjcW5SNShjS203VgvU8kDuQt+3DLHy1Eh+0m0seq6d8zBU4BinGbPZghM2i0Yx/idkV8pK4nKrhKZDahmcZE7iWruqfPwRl0kHcPOIl X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230040)(82310400026)(376014)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2024 13:52:42.2518 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 94dc6401-d979-4898-dd66-08dcc2b1b19b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5916 Use defer scopes to manage qdisc lifetime. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- .../drivers/net/mlxsw/sch_red_ets.sh | 32 +++++++++---------- .../drivers/net/mlxsw/sch_red_root.sh | 24 ++++++++++---- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/drivers/net/mlxsw/sch_red_ets.sh b/tools/testing/selftests/drivers/net/mlxsw/sch_red_ets.sh index 576067b207a8..87b4dc509896 100755 --- a/tools/testing/selftests/drivers/net/mlxsw/sch_red_ets.sh +++ b/tools/testing/selftests/drivers/net/mlxsw/sch_red_ets.sh @@ -80,36 +80,37 @@ uninstall_qdisc() ecn_test() { install_qdisc ecn + defer uninstall_qdisc do_ecn_test 10 $BACKLOG1 do_ecn_test 11 $BACKLOG2 - - uninstall_qdisc } +defer_scoped_fn ecn_test ecn_test_perband() { install_qdisc ecn + defer uninstall_qdisc do_ecn_test_perband 10 $BACKLOG1 do_ecn_test_perband 11 $BACKLOG2 - - uninstall_qdisc } +defer_scoped_fn ecn_test_perband ecn_nodrop_test() { install_qdisc ecn nodrop + defer uninstall_qdisc do_ecn_nodrop_test 10 $BACKLOG1 do_ecn_nodrop_test 11 $BACKLOG2 - - uninstall_qdisc } +defer_scoped_fn ecn_nodrop_test red_test() { install_qdisc + defer uninstall_qdisc # Make sure that we get the non-zero value if there is any. local cur=$(busywait 1100 until_counter_is "> 0" \ @@ -120,51 +121,50 @@ red_test() do_red_test 10 $BACKLOG1 do_red_test 11 $BACKLOG2 - - uninstall_qdisc } +defer_scoped_fn red_test mc_backlog_test() { install_qdisc + defer uninstall_qdisc # Note that the backlog numbers here do not correspond to RED # configuration, but are arbitrary. do_mc_backlog_test 10 $BACKLOG1 do_mc_backlog_test 11 $BACKLOG2 - - uninstall_qdisc } +defer_scoped_fn mc_backlog_test red_mirror_test() { install_qdisc qevent early_drop block 10 + defer uninstall_qdisc do_drop_mirror_test 10 $BACKLOG1 early_drop do_drop_mirror_test 11 $BACKLOG2 early_drop - - uninstall_qdisc } +defer_scoped_fn red_mirror_test red_trap_test() { install_qdisc qevent early_drop block 10 + defer uninstall_qdisc do_drop_trap_test 10 $BACKLOG1 early_drop do_drop_trap_test 11 $BACKLOG2 early_drop - - uninstall_qdisc } +defer_scoped_fn red_trap_test ecn_mirror_test() { install_qdisc ecn qevent mark block 10 + defer uninstall_qdisc do_mark_mirror_test 10 $BACKLOG1 do_mark_mirror_test 11 $BACKLOG2 - - uninstall_qdisc } +defer_scoped_fn ecn_mirror_test bail_on_lldpad "configure DCB" "configure Qdiscs" diff --git a/tools/testing/selftests/drivers/net/mlxsw/sch_red_root.sh b/tools/testing/selftests/drivers/net/mlxsw/sch_red_root.sh index 159108d02895..1777b79b1190 100755 --- a/tools/testing/selftests/drivers/net/mlxsw/sch_red_root.sh +++ b/tools/testing/selftests/drivers/net/mlxsw/sch_red_root.sh @@ -32,46 +32,58 @@ uninstall_qdisc() ecn_test() { install_qdisc ecn + defer uninstall_qdisc + do_ecn_test 10 $BACKLOG - uninstall_qdisc } +defer_scoped_fn ecn_test ecn_test_perband() { install_qdisc ecn + defer uninstall_qdisc + do_ecn_test_perband 10 $BACKLOG - uninstall_qdisc } +defer_scoped_fn ecn_test_perband ecn_nodrop_test() { install_qdisc ecn nodrop + defer uninstall_qdisc + do_ecn_nodrop_test 10 $BACKLOG - uninstall_qdisc } +defer_scoped_fn ecn_nodrop_test red_test() { install_qdisc + defer uninstall_qdisc + do_red_test 10 $BACKLOG - uninstall_qdisc } +defer_scoped_fn red_test mc_backlog_test() { install_qdisc + defer uninstall_qdisc + # Note that the backlog value here does not correspond to RED # configuration, but is arbitrary. do_mc_backlog_test 10 $BACKLOG - uninstall_qdisc } +defer_scoped_fn mc_backlog_test red_mirror_test() { install_qdisc qevent early_drop block 10 + defer uninstall_qdisc + do_drop_mirror_test 10 $BACKLOG - uninstall_qdisc } +defer_scoped_fn red_mirror_test bail_on_lldpad "configure DCB" "configure Qdiscs" From patchwork Thu Aug 22 13:49:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 821983 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2084.outbound.protection.outlook.com [40.107.237.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA8EE1CB15E; Thu, 22 Aug 2024 13:52:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334771; cv=fail; b=UiVIAjLm2/UGwSfUkRTABdpqsNRG6eO5f1QTC2lubofbzF/PnI+gPwEmrMgDIfLvDvdVHdXfvaI0VflXqo+dSVy4ZGU6YONALrF2CJjCPzqKx4pg0vt4uMv0JzkEI/VhJ42PhUuo0mrjHv/kanylyw2n900KKSsDsfScjCIsbvo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724334771; c=relaxed/simple; bh=CRrJJh98wkJ/3eHjWu1bO6fuVKjaUIGf7VJGUauhJko=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kReqcsoak0Z8gCEmr0zrpDlkFdLunu6oXttlqayMKtmkYYExJBICdFFWm2LVEsJuWhhOkKfGrmIYNEGvJhylI6uyUbi50JTCZ890K59PJJiQE4IlO3nj6WZkrL3Ri7xtUc7qlSR3oDQDXU9G/cUudNMnxOc/BarBvzx445y7PEE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=eS/c0CA5; arc=fail smtp.client-ip=40.107.237.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="eS/c0CA5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GiAIHGkTWSr/ILEQfMh9tlkA7OknDQWDOXj5w8nI4LikwMfeMhsXlAs/lqtjllDqehuuhjYFzmIrC/Y5uOP39IJxXeBeNCEqJB/ZcjkLR2xUDW+4idr5x3Nqfjx0XM518oKEDPKz33bZehBHpg0uU0TUTC6QnVwKrGh0dfPAg5MyEQiwcs5cQ0oaUr+wG2tHexur2b9un/HiMZh+xWtKkAWnzMKRm6xrWIFnvDLM4C3NYSkyk4sl7xo5Gy9PPrgO1YUj9y4eYc1CtaPaF0ijGDqaBzFBppWYYvIO0YG+xL3rg4EEYfLcIyt0Np6WoZDA7T/IKwZ/tnIKSJo56YT7Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LyxpSu9rOP+p/e5CbVuuJqxBVVJ4oLn92fsUgwnA6pI=; b=EwQuxnAz6m4uJOI7Q8sdb1QY6pijGUsV6/aUIi8alDjiCOBhdiRvRH0IQhg1hD3s6sqnZlQkjsMmnJh0qR7qYHidTi2F3vp822MW4rBxILhhtzbqlGAlmcucfB3KFyASaiGCqMOyVoWkJcnGAizCstFQ0BvDo6rQsxlm/TTsZYjaBdHzUJz/XeM1iEiffB1YdDqyKfkiWfGYIeQeeRNJ5NrruoWYhhnSmTD9QwOfxtI0CX2YDkUUrpknBQuwyJ70puCdyIxYoYGmRWivIsIc4qO72FY2VroZDPeak22y/bJF5t45cHV+62TsGycsWYLpqAYdO67W1mbVQp4xytqVpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LyxpSu9rOP+p/e5CbVuuJqxBVVJ4oLn92fsUgwnA6pI=; b=eS/c0CA5ZO6EXV3dcWlYh5g5HAyJPingzfUvNbC6MCKEYA+jEhDJ/B3dvxjwZB4uwJ6rz82Vg95wenj8zPPwY8Vjer0f1vFG8xWQ7zzZxS7nrkvU+GjESyyiCWPCa1eih24hhwWBYYzsz2ASZMMKkd32ONlCC0QXtFGnj+SEsCfPq0VdcB8y7AEyPQsTHNw7MkL8taszW96xtmgxSWXa8aJ0zMCXPUrtI3dVoDb7g8CTyRuNr/DiVv7X4N6CbUCcEvFlmBFDlrGMzMEVquoZMFI6irno2St2oo8+5+/LEufJxd/XDKIFkep94Hftbg1+lopemUI2BLkIqvOce+l6sg== Received: from BN9PR03CA0942.namprd03.prod.outlook.com (2603:10b6:408:108::17) by MN2PR12MB4063.namprd12.prod.outlook.com (2603:10b6:208:1dc::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Thu, 22 Aug 2024 13:52:45 +0000 Received: from BN3PEPF0000B071.namprd04.prod.outlook.com (2603:10b6:408:108:cafe::6d) by BN9PR03CA0942.outlook.office365.com (2603:10b6:408:108::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20 via Frontend Transport; Thu, 22 Aug 2024 13:52:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B071.mail.protection.outlook.com (10.167.243.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11 via Frontend Transport; Thu, 22 Aug 2024 13:52:45 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 22 Aug 2024 06:52:33 -0700 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 22 Aug 2024 06:52:28 -0700 From: Petr Machata To: Shuah Khan , , CC: Jakub Kicinski , Ido Schimmel , "Petr Machata" , Amit Cohen , Benjamin Poirier , Hangbin Liu , Vladimir Oltean , Subject: [RFC PATCH net-next 5/5] selftests: sch_tbf_core: Use defer for stopping traffic Date: Thu, 22 Aug 2024 15:49:44 +0200 Message-ID: <7dac3bd8f776741a9816efb03c672c4887765ad4.1724324945.git.petrm@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B071:EE_|MN2PR12MB4063:EE_ X-MS-Office365-Filtering-Correlation-Id: 234e8a43-31b4-4f4a-b326-08dcc2b1b369 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: 4PnpTAe/Hf0kZf4uzcq/vdYXsNQAxsixtC7/bXPjc22m+LV3WVQvA2pnYi81s4Kv/WY2yoCzsceOz5KaSQiqAYP2g068rBJGzuQCJbiJW6mR4wK3Ex2yNWNkVPeT5+Xp0ygy1rmWNZVqq/2CQFxaegAXlKvOqUN+5FjE30i2bdA0tQ/AmlFEGALQY7I8zA2Op/O8aVaquVfjHhey2zJCki7TAj5vMMKWBc0fpI79lQ+G7hUyhSCuKpEnXFGHvTQv/2RvEfdzPL+XGUPNNZxcrYETzsiujY+y5kFQvI0ZsUkCx2DrwQElsQ7XvXW/GCZfhvAbB4qNDdn/pe7mVOQdwKryYTYdVRaJEAzLo5IoovdQTYhJGrbJwej12cnNF9sMnRQ+HhqVhY943o/NA+7ilBZg6zuhpUQBNaiZC6dCbjjVP3crvAc3clMee0N2Ga8lcrFNvXYgKj6jFtx7opelVar2lUid5RQeriV5tfxNCRI979zVFwujAvQJVzU1SfQ2UMbQNsr8vuZX9hMhiUbtAk4C5+ADi44cCYvZ4f9kK52AvPkZ5EbdGbkh4RkKb6Ca2ry9irmlLGDBfflVC04sikfXNUWt3BFPafRP3L4yijm7NwY7Ig/GzkesCXhLIrtWBo97SAxX8QshPWm98ef0IHTCRbX1ft8W18YDTJaX0+ijMN20fJUMbdJmLsM71ctbmDlLlsyorYlEgqo7fcrB/a0I6fAIO/EqjuUqHHnJW4eGabr/VrENk4QSNI5A4KwYW1lHLkOEUlF6tR8qXTdMJWQWwtG4VuNo5VvsXaPm/5Mqd1Ny7dEmpESW7H7Ch8FSL+7+d5l33dpGQMRPsPJn1fXqYOodfRmukmTqZxRopfaSVUfpmWdbw2/nKpRXYhZe1rwHOgutBx00TC/0zNCf4AtpJhPaTju0uxfzVj972sncJbtriQBpxpOgWBEUshgSQK0cbHdFnGLXu3QyUBzQrvCTyuJt5hen7loxBfRfDQHQ2ce3tNATVUql3ps6AMVB0hEEttqTbveN6Ug1dDTWSfuAIYE4XSSmffq7eZqFUZQk/Y7fnWuqOV6mrw0NQ0+wWMtXHO04AYJ6awXMLu6+j5v4ZkbjvhvIiVC7Cv6l5UpvkiSClncWVr4l8l6TFfTf4CLyq2VV55JxAj1ojCvkCxiwfbwf+SKQGngA50YC8LkE9YpPmzhxy8nMJhRTIlf2zWAfuKhvv9QB6tS1DrVRNOSEsb2lATxIQAiolOtqrC29rLKiQjz3eWDFP6oMUpxXLThVDEtFbv3ottfN2Q3Fd6hRgHnvgkGZj1qOrzg7waudr3miYyu9VrGihwZ06EW+kwUFpBZ27vt8RsbiGxiekOktRzshxxlLs+5SMsHmQjrDgrfvHKLVhKep6l7Ei7fSpqpfWyoFlmdpXpCg0Q3FBUgblGNlQDzuICl4T9onleLwFJEpik7A++2Th+UXwyWy X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2024 13:52:45.2785 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 234e8a43-31b4-4f4a-b326-08dcc2b1b369 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B071.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4063 Tests interrupted part-way through leave behind a running mausezahn. Use defer to schedule a traffic stop after traffic is started. Signed-off-by: Petr Machata --- tools/testing/selftests/net/forwarding/sch_tbf_core.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/forwarding/sch_tbf_core.sh b/tools/testing/selftests/net/forwarding/sch_tbf_core.sh index 9cd884d4a5de..5d58c04e055c 100644 --- a/tools/testing/selftests/net/forwarding/sch_tbf_core.sh +++ b/tools/testing/selftests/net/forwarding/sch_tbf_core.sh @@ -213,12 +213,12 @@ do_tbf_test() local mbit=$1; shift start_traffic $h1.$vlan $(ipaddr 1 $vlan) $(ipaddr 2 $vlan) $h2_mac + defer stop_traffic sleep 5 # Wait for the burst to dwindle local t2=$(busywait_for_counter 1000 +1 tbf_get_counter $vlan) sleep 10 local t3=$(tbf_get_counter $vlan) - stop_traffic RET=0 @@ -231,3 +231,4 @@ do_tbf_test() log_test "TC $((vlan - 10)): TBF rate ${mbit}Mbit" } +defer_scoped_fn do_tbf_test