diff mbox series

[net] selftests: openvswitch: Use bash as interpreter

Message ID 20240617-ovs-selftest-bash-v1-1-7ae6ccd3617b@kernel.org (mailing list archive)
State Accepted
Commit e2b447c9a1bba718f9c07513a1e8958209e862a1
Delegated to: Netdev Maintainers
Headers show
Series [net] selftests: openvswitch: Use bash as interpreter | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 11 of 11 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success net selftest script(s) already in Makefile
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 5 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-06-17--09-00 (tests: 657)

Commit Message

Simon Horman June 17, 2024, 8:28 a.m. UTC
openvswitch.sh makes use of substitutions of the form ${ns:0:1}, to
obtain the first character of $ns. Empirically, this is works with bash
but not dash. When run with dash these evaluate to an empty string and
printing an error to stdout.

 # dash -c 'ns=client; echo "${ns:0:1}"' 2>error
 # cat error
 dash: 1: Bad substitution
 # bash -c 'ns=client; echo "${ns:0:1}"' 2>error
 c
 # cat error

This leads to tests that neither pass nor fail.
F.e.

 TEST: arp_ping                                                      [START]
 adding sandbox 'test_arp_ping'
 Adding DP/Bridge IF: sbx:test_arp_ping dp:arpping {, , }
 create namespaces
 ./openvswitch.sh: 282: eval: Bad substitution
 TEST: ct_connect_v4                                                 [START]
 adding sandbox 'test_ct_connect_v4'
 Adding DP/Bridge IF: sbx:test_ct_connect_v4 dp:ct4 {, , }
 ./openvswitch.sh: 322: eval: Bad substitution
 create namespaces

Resolve this by making openvswitch.sh a bash script.

Fixes: 918423fda910 ("selftests: openvswitch: add an initial flow programming case")
Signed-off-by: Simon Horman <horms@kernel.org>
---
 tools/testing/selftests/net/openvswitch/openvswitch.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Przemek Kitszel June 17, 2024, 10:05 a.m. UTC | #1
On 6/17/24 10:28, Simon Horman wrote:
> openvswitch.sh makes use of substitutions of the form ${ns:0:1}, to
> obtain the first character of $ns. Empirically, this is works with bash
> but not dash. When run with dash these evaluate to an empty string and
> printing an error to stdout.
> 
>   # dash -c 'ns=client; echo "${ns:0:1}"' 2>error
>   # cat error
>   dash: 1: Bad substitution
>   # bash -c 'ns=client; echo "${ns:0:1}"' 2>error
>   c
>   # cat error
> 
> This leads to tests that neither pass nor fail.
> F.e.
> 
>   TEST: arp_ping                                                      [START]
>   adding sandbox 'test_arp_ping'
>   Adding DP/Bridge IF: sbx:test_arp_ping dp:arpping {, , }
>   create namespaces
>   ./openvswitch.sh: 282: eval: Bad substitution
>   TEST: ct_connect_v4                                                 [START]
>   adding sandbox 'test_ct_connect_v4'
>   Adding DP/Bridge IF: sbx:test_ct_connect_v4 dp:ct4 {, , }
>   ./openvswitch.sh: 322: eval: Bad substitution
>   create namespaces
> 
> Resolve this by making openvswitch.sh a bash script.
> 
> Fixes: 918423fda910 ("selftests: openvswitch: add an initial flow programming case")
> Signed-off-by: Simon Horman <horms@kernel.org>

That's good fix,
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>

sidenote: I like very much the idea to use the least powerful tool, like
sh vs bash, awk vs gawk, but it breaks when we forget what is outside of
the scope of the former/standard.
Perhaps for shell, we could convert all the selftests at once?

> ---
>   tools/testing/selftests/net/openvswitch/openvswitch.sh | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/net/openvswitch/openvswitch.sh b/tools/testing/selftests/net/openvswitch/openvswitch.sh
> index 5cae53543849..15bca0708717 100755
> --- a/tools/testing/selftests/net/openvswitch/openvswitch.sh
> +++ b/tools/testing/selftests/net/openvswitch/openvswitch.sh
> @@ -1,4 +1,4 @@
> -#!/bin/sh
> +#!/bin/bash
>   # SPDX-License-Identifier: GPL-2.0
>   #
>   # OVS kernel module self tests
> 
>
Simon Horman June 17, 2024, 10:33 a.m. UTC | #2
On Mon, Jun 17, 2024 at 12:05:11PM +0200, Przemek Kitszel wrote:
> On 6/17/24 10:28, Simon Horman wrote:
> > openvswitch.sh makes use of substitutions of the form ${ns:0:1}, to
> > obtain the first character of $ns. Empirically, this is works with bash
> > but not dash. When run with dash these evaluate to an empty string and
> > printing an error to stdout.
> > 
> >   # dash -c 'ns=client; echo "${ns:0:1}"' 2>error
> >   # cat error
> >   dash: 1: Bad substitution
> >   # bash -c 'ns=client; echo "${ns:0:1}"' 2>error
> >   c
> >   # cat error
> > 
> > This leads to tests that neither pass nor fail.
> > F.e.
> > 
> >   TEST: arp_ping                                                      [START]
> >   adding sandbox 'test_arp_ping'
> >   Adding DP/Bridge IF: sbx:test_arp_ping dp:arpping {, , }
> >   create namespaces
> >   ./openvswitch.sh: 282: eval: Bad substitution
> >   TEST: ct_connect_v4                                                 [START]
> >   adding sandbox 'test_ct_connect_v4'
> >   Adding DP/Bridge IF: sbx:test_ct_connect_v4 dp:ct4 {, , }
> >   ./openvswitch.sh: 322: eval: Bad substitution
> >   create namespaces
> > 
> > Resolve this by making openvswitch.sh a bash script.
> > 
> > Fixes: 918423fda910 ("selftests: openvswitch: add an initial flow programming case")
> > Signed-off-by: Simon Horman <horms@kernel.org>
> 
> That's good fix,
> Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
> 
> sidenote: I like very much the idea to use the least powerful tool, like
> sh vs bash, awk vs gawk, but it breaks when we forget what is outside of
> the scope of the former/standard.
> Perhaps for shell, we could convert all the selftests at once?

Thanks,

Now that you mention it, I have the same feelings.

Do we ever expect to use the minimal tools, when other
parts of the test suite depend on the enhanced ones?

...
patchwork-bot+netdevbpf@kernel.org June 18, 2024, 8:40 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 17 Jun 2024 09:28:33 +0100 you wrote:
> openvswitch.sh makes use of substitutions of the form ${ns:0:1}, to
> obtain the first character of $ns. Empirically, this is works with bash
> but not dash. When run with dash these evaluate to an empty string and
> printing an error to stdout.
> 
>  # dash -c 'ns=client; echo "${ns:0:1}"' 2>error
>  # cat error
>  dash: 1: Bad substitution
>  # bash -c 'ns=client; echo "${ns:0:1}"' 2>error
>  c
>  # cat error
> 
> [...]

Here is the summary with links:
  - [net] selftests: openvswitch: Use bash as interpreter
    https://git.kernel.org/netdev/net/c/e2b447c9a1bb

You are awesome, thank you!
David Laight June 19, 2024, 9:21 a.m. UTC | #4
From: Simon Horman
> Sent: 17 June 2024 11:34
...
> > sidenote: I like very much the idea to use the least powerful tool, like
> > sh vs bash, awk vs gawk, but it breaks when we forget what is outside of
> > the scope of the former/standard.
> > Perhaps for shell, we could convert all the selftests at once?
> 
> Thanks,
> 
> Now that you mention it, I have the same feelings.
> 
> Do we ever expect to use the minimal tools, when other
> parts of the test suite depend on the enhanced ones?

Certainly trying to avoid bash-isms seems like a good idea.
Especially in scripts where it isn't really that hard.
OTOH avoiding posix features (so the script will run on a traditional SYSV /bin/sh)
is probably excessive.

I'd use "${foo%"${foo#?}"}" to get the first character without bash-isms.
But, IIRC, one version of ash/dash made a 'pig's breakfast' of the nested
pattern match.
(Most syntax highlighters don't get the quoting right either...)

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/openvswitch/openvswitch.sh b/tools/testing/selftests/net/openvswitch/openvswitch.sh
index 5cae53543849..15bca0708717 100755
--- a/tools/testing/selftests/net/openvswitch/openvswitch.sh
+++ b/tools/testing/selftests/net/openvswitch/openvswitch.sh
@@ -1,4 +1,4 @@ 
-#!/bin/sh
+#!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 #
 # OVS kernel module self tests