From patchwork Fri Jan 24 13:23:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 1228841 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=idosch.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=Zzawgfm9; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 4840H56FQVz9sP3 for ; Sat, 25 Jan 2020 00:24:33 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389767AbgAXNYc (ORCPT ); Fri, 24 Jan 2020 08:24:32 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:43371 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387915AbgAXNYb (ORCPT ); Fri, 24 Jan 2020 08:24:31 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 8660421F4C; Fri, 24 Jan 2020 08:24:30 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 24 Jan 2020 08:24:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=aJ0ZJsvGAigkU0kAAyOIHN9MVsJMtw9xE0aGNsXPYkU=; b=Zzawgfm9 VODvY66/2mSL1YijwcvieDXDEElgn9fKPVjsTLsktGNLK9oGpXZHI1eyO21z8944 djUQaZSRY6KjYm3wUWNudG87MaHNhFc87O0Mj8umEsgHumyAHtlgznU/ZDL21hcx z5EVQ0gATcOeNnc5CyBkqB2PLP1I9zqx6/SeG/NUNbUk7sFR0NOUnnrDbsm5Tu3Z rBbiwegTBd+VSc8PO9Rfzv7iG1uS/cqMbg29f7WFsll44HJZzk6Hvj2syLgPyfsK lH8UaY90R5ISS+ko9L0r2w7pTnbRuLcC3GqRqcOXK0NKajRCsi9WhItYPbX/3XnD M8xutm1qkNBGqQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrvdeggdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpefkughoucfutghhihhmmhgvlhcuoehiughoshgthhesihguohhs tghhrdhorhhgqeenucfkphepjeelrddukeefrddutdejrdduvddtnecuvehluhhsthgvrh fuihiivgepuddtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehiughoshgthhesihguohhs tghhrdhorhhg X-ME-Proxy: Received: from splinter.mtl.com (bzq-79-183-107-120.red.bezeqint.net [79.183.107.120]) by mail.messagingengine.com (Postfix) with ESMTPA id 76B9A3061106; Fri, 24 Jan 2020 08:24:28 -0500 (EST) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, jiri@mellanox.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, petrm@mellanox.com, mlxsw@mellanox.com, Ido Schimmel Subject: [PATCH net-next 12/14] selftests: forwarding: lib: Add helpers for busywaiting Date: Fri, 24 Jan 2020 15:23:16 +0200 Message-Id: <20200124132318.712354-13-idosch@idosch.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200124132318.712354-1-idosch@idosch.org> References: <20200124132318.712354-1-idosch@idosch.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Petr Machata The function busywait() is handy as a safety-latched variant of a while loop. Many selftests deal specifically with counter values, and busywaiting on them is likely to be rather common (it is not quite common now, but busywait() has not been around for very long). To facilitate expressing simply what is tested, introduce two helpers: - until_counter_is(), which can be used as a predicate passed to busywait(), which holds when expression, which is itself passed as an argument to until_counter_is(), reaches a desired value. - busywait_for_counter(), which is useful for waiting until a given counter changes "by" (as opposed to "to") a certain amount. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- tools/testing/selftests/net/forwarding/lib.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 10cdfc0adca8..096340f064db 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -248,6 +248,24 @@ busywait() done } +until_counter_is() +{ + local value=$1; shift + local current=$("$@") + + echo $((current)) + ((current >= value)) +} + +busywait_for_counter() +{ + local timeout=$1; shift + local delta=$1; shift + + local base=$("$@") + busywait "$timeout" until_counter_is $((base + delta)) "$@" +} + setup_wait_dev() { local dev=$1; shift