From: Petr Machata <petrm@nvidia.com>
To: Paolo Abeni <pabeni@redhat.com>
Cc: Petr Machata <petrm@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, Shuah Khan <shuah@kernel.org>,
Benjamin Poirier <bpoirier@nvidia.com>,
Hangbin Liu <liuhangbin@gmail.com>,
Vladimir Oltean <vladimir.oltean@nxp.com>,
"Ido Schimmel" <idosch@nvidia.com>,
Przemek Kitszel <przemyslaw.kitszel@intel.com>,
<mlxsw@nvidia.com>
Subject: Re: [PATCH net-next 01/10] selftests: net: lib: Introduce deferred commands
Date: Tue, 15 Oct 2024 11:06:35 +0200 [thread overview]
Message-ID: <87ttddhg03.fsf@nvidia.com> (raw)
In-Reply-To: <0b947dd2-5891-457c-8511-52781764857d@redhat.com>
Paolo Abeni <pabeni@redhat.com> writes:
> Hi,
>
> On 10/9/24 14:06, Petr Machata wrote:
>> diff --git a/tools/testing/selftests/net/lib/sh/defer.sh b/tools/testing/selftests/net/lib/sh/defer.sh
>> new file mode 100644
>> index 000000000000..8d205c3f0445
>> --- /dev/null
>> +++ b/tools/testing/selftests/net/lib/sh/defer.sh
>> @@ -0,0 +1,115 @@
>> +#!/bin/bash
>> +# SPDX-License-Identifier: GPL-2.0
>> +
>> +# map[(scope_id,track,cleanup_id) -> cleanup_command]
>> +# track={d=default | p=priority}
>> +declare -A __DEFER__JOBS
>> +
>> +# map[(scope_id,track) -> # cleanup_commands]
>> +declare -A __DEFER__NJOBS
>> +
>> +# scope_id of the topmost scope.
>> +__DEFER__SCOPE_ID=0
>> +
>> +__defer__ndefer_key()
>> +{
>> + local track=$1; shift
>
> Minor nit: IMHO the trailing shift is here a bit confusing: it let me
> think about other arguments, which are not really expected.
This is IMHO how a function header should look like:
function()
{
local foo=$1; shift
local bar=$1; shift
local baz=$1; shift
...
}
Because it lets you reorder the arguments freely just by reordering the
lines, copy argument subsets to other functions without risking
forgetting / screwing up renumbering, etc. It's easy to parse visually
as well. If the function uses "$@" as rest argument, it will contain the
rest by default. It's just a very convenient notation overall. Vast
majority of net/lib.sh and net/forwarding/lib.sh use this.
>> +__defer__schedule()
>> +{
>> + local track=$1; shift
>> + local ndefers=$(__defer__ndefers $track)
>> + local ndefers_key=$(__defer__ndefer_key $track)
>> + local defer_key=$(__defer__defer_key $track $ndefers)
>> + local defer="$@"
>> +
>> + __DEFER__JOBS[$defer_key]="$defer"
>> + __DEFER__NJOBS[$ndefers_key]=$((${__DEFER__NJOBS[$ndefers_key]} + 1))
>
> '${__DEFER__NJOBS[$ndefers_key]}' is actually '$ndefers', right? If so
> it would be better to reuse the avail variable.
I figured I would leave it all spelled out, because the left hand side
needs to be, and having the same expression on both sides makes it clear
that this is just an X++ sort of a deal.
next prev parent reply other threads:[~2024-10-15 9:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 12:06 [PATCH net-next 00/10] selftests: net: Introduce deferred commands Petr Machata
2024-10-09 12:06 ` [PATCH net-next 01/10] selftests: net: lib: " Petr Machata
2024-10-15 8:22 ` Paolo Abeni
2024-10-15 9:06 ` Petr Machata [this message]
2024-10-09 12:06 ` [PATCH net-next 02/10] selftests: forwarding: Add a fallback cleanup() Petr Machata
2024-10-09 12:06 ` [PATCH net-next 03/10] selftests: forwarding: lib: Allow passing PID to stop_traffic() Petr Machata
2024-10-09 12:06 ` [PATCH net-next 04/10] selftests: RED: Use defer for test cleanup Petr Machata
2024-10-15 8:14 ` Paolo Abeni
2024-10-15 9:03 ` Petr Machata
2024-10-09 12:06 ` [PATCH net-next 05/10] selftests: TBF: " Petr Machata
2024-10-09 12:06 ` [PATCH net-next 06/10] selftests: ETS: " Petr Machata
2024-10-09 12:06 ` [PATCH net-next 07/10] selftests: mlxsw: qos_mc_aware: " Petr Machata
2024-10-09 12:06 ` [PATCH net-next 08/10] selftests: mlxsw: qos_ets_strict: " Petr Machata
2024-10-09 12:06 ` [PATCH net-next 09/10] selftests: mlxsw: qos_max_descriptors: " Petr Machata
2024-10-09 12:06 ` [PATCH net-next 10/10] selftests: mlxsw: devlink_trap_police: " Petr Machata
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ttddhg03.fsf@nvidia.com \
--to=petrm@nvidia.com \
--cc=bpoirier@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=liuhangbin@gmail.com \
--cc=mlxsw@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=shuah@kernel.org \
--cc=vladimir.oltean@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.