diff mbox series

[1/4] perf test: Fix non-bash issue with stat bpf counters

Message ID 20210617184216.2075588-1-irogers@google.com (mailing list archive)
State Not Applicable
Headers show
Series [1/4] perf test: Fix non-bash issue with stat bpf counters | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Ian Rogers June 17, 2021, 6:42 p.m. UTC
$(( .. )) is a bash feature but the test's interpreter is !/bin/sh,
switch the code to use expr.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/tests/shell/stat_bpf_counters.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Arnaldo Carvalho de Melo June 17, 2021, 7:18 p.m. UTC | #1
Em Thu, Jun 17, 2021 at 11:42:13AM -0700, Ian Rogers escreveu:
> $(( .. )) is a bash feature but the test's interpreter is !/bin/sh,
> switch the code to use expr.


Thanks, applied to perf/urgent.

- Arnaldo

 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/tests/shell/stat_bpf_counters.sh | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/tests/shell/stat_bpf_counters.sh b/tools/perf/tests/shell/stat_bpf_counters.sh
> index 22eb31e48ca7..2f9948b3d943 100755
> --- a/tools/perf/tests/shell/stat_bpf_counters.sh
> +++ b/tools/perf/tests/shell/stat_bpf_counters.sh
> @@ -11,9 +11,9 @@ compare_number()
>         second_num=$2
>  
>         # upper bound is first_num * 110%
> -       upper=$(( $first_num + $first_num / 10 ))
> +       upper=$(expr $first_num + $first_num / 10 )
>         # lower bound is first_num * 90%
> -       lower=$(( $first_num - $first_num / 10 ))
> +       lower=$(expr $first_num - $first_num / 10 )
>  
>         if [ $second_num -gt $upper ] || [ $second_num -lt $lower ]; then
>                 echo "The difference between $first_num and $second_num are greater than 10%."
> -- 
> 2.32.0.288.g62a8d224e6-goog
>
Stephen Rothwell June 20, 2021, 9:55 p.m. UTC | #2
Hi Ian,

On Thu, 17 Jun 2021 11:42:13 -0700 Ian Rogers <irogers@google.com> wrote:
>
> $(( .. )) is a bash feature but the test's interpreter is !/bin/sh,
> switch the code to use expr.

The $(( .. )) syntax is specified in POSIX (see
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04),
so unless this caused an actual problem, this change is unnecessary.
Ian Rogers June 21, 2021, 9:30 p.m. UTC | #3
On Sun, Jun 20, 2021 at 2:55 PM Stephen Rothwell <sfr@canb.auug.org.au> wrote:
>
> Hi Ian,
>
> On Thu, 17 Jun 2021 11:42:13 -0700 Ian Rogers <irogers@google.com> wrote:
> >
> > $(( .. )) is a bash feature but the test's interpreter is !/bin/sh,
> > switch the code to use expr.
>
> The $(( .. )) syntax is specified in POSIX (see
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04),
> so unless this caused an actual problem, this change is unnecessary.

Agreed. The issue I was seeing was:

./tests/shell/stat_bpf_counters.sh: line 14: <not + <not / 10 : syntax
error: operand expected (error token is "<not + <not / 10 ")

but that syntax error is caused by running the test within a
hypervisor. I'll resend the patch set with this one dropped.

Thanks,
Ian

> --
> Cheers,
> Stephen Rothwell
diff mbox series

Patch

diff --git a/tools/perf/tests/shell/stat_bpf_counters.sh b/tools/perf/tests/shell/stat_bpf_counters.sh
index 22eb31e48ca7..2f9948b3d943 100755
--- a/tools/perf/tests/shell/stat_bpf_counters.sh
+++ b/tools/perf/tests/shell/stat_bpf_counters.sh
@@ -11,9 +11,9 @@  compare_number()
        second_num=$2
 
        # upper bound is first_num * 110%
-       upper=$(( $first_num + $first_num / 10 ))
+       upper=$(expr $first_num + $first_num / 10 )
        # lower bound is first_num * 90%
-       lower=$(( $first_num - $first_num / 10 ))
+       lower=$(expr $first_num - $first_num / 10 )
 
        if [ $second_num -gt $upper ] || [ $second_num -lt $lower ]; then
                echo "The difference between $first_num and $second_num are greater than 10%."