Skip to contentSkip to conversation

Fix various bash constructs in tests

PATCH New James Clark 1 participant 4 messages Oct 28, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Fix various bash constructs in tests

These tests were either failing or printing warnings on my Ubuntu 18 and 20 systems. I'm not sure if there is a system where /bin/sh allows bash constructs, or perf invokes bash instead of sh, but I saw that there have been similar fixes made in the past so I assume this should be done.

Adding set -e to the scripts didn't highlight these issues, so I didn't do it at this time.

For stat_bpf_counters.sh, there are further bashisms after the skip, but I couldn't get BPF working, so I only fixed it up to that point.

Applies to perf/core 624ff63abfd36

James Clark (3):
perf test: Remove bash construct from stat_bpf_counters.sh test perf tests: Remove bash construct from record+zstd_comp_decomp.sh perf tests: Remove bash constructs from stat_all_pmu.sh

 tools/perf/tests/shell/record+zstd_comp_decomp.sh | 2 +-
 tools/perf/tests/shell/stat_all_pmu.sh            | 4 ++--
 tools/perf/tests/shell/stat_bpf_counters.sh       | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.28.0
#1 lore raw

PATCH 1/3 perf test: Remove bash construct from stat_bpf_counters.sh test

Currently the test skips with an error because == only works in bash:

  $ ./perf test 91 -v
  Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc
  91: perf stat --bpf-counters test                                   :
  --- start ---
  test child forked, pid 44586
  ./tests/shell/stat_bpf_counters.sh: 26: [: -v: unexpected operator
  test child finished with -2
  ---- end ----
  perf stat --bpf-counters test: Skip

Changing == to = does the same thing, but doesn't result in an error:

./perf test 91 -v
Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc
91: perf stat --bpf-counters test :
--- start ---
test child forked, pid 45833
Skipping: --bpf-counters not supported
Error: unknown option `bpf-counters'
[...]
test child finished with -2
---- end ----
perf stat --bpf-counters test: Skip

---
 tools/perf/tests/shell/stat_bpf_counters.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/stat_bpf_counters.sh +1 -1
index 2aed20dc2262..13473aeba489 100755
@@ -23,7 +23,7 @@ compare_number()
 
 # skip if --bpf-counters is not supported
 if ! perf stat --bpf-counters true > /dev/null 2>&1; then
-	if [ "$1" == "-v" ]; then
+	if [ "$1" = "-v" ]; then
 		echo "Skipping: --bpf-counters not supported"
 		perf --no-pager stat --bpf-counters true || true
 	fi
Signature · 1 line
2.28.0
#2 lore raw

PATCH 2/3 perf tests: Remove bash construct from record+zstd_comp_decomp.sh

In reply to James Clark

Commit 463538a383a2 ("perf tests: Fix test 68 zstd compression for s390") inadvertently removed the -g flag from all platforms rather than just s390, because the [[ ]] construct fails in sh. Changing to single brackets restores testing of call graphs and removes the following error from the output:

  $ ./perf test -v 85
  85: Zstd perf.data compression/decompression                        :
  --- start ---
  test child forked, pid 50643
  Collecting compressed record file:
  ./tests/shell/record+zstd_comp_decomp.sh: 15: [[: not found
Fixes 463538a383a2 ("perf tests: Fix test 68 zstd compression for s390")
---
 tools/perf/tests/shell/record+zstd_comp_decomp.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/record+zstd_comp_decomp.sh +1 -1
index 8a168cf8bacc..49bd875d5122 100755
@@ -12,7 +12,7 @@ skip_if_no_z_record() {
 
 collect_z_record() {
 	echo "Collecting compressed record file:"
-	[[ "$(uname -m)" != s390x ]] && gflag='-g'
+	[ "$(uname -m)" != s390x ] && gflag='-g'
 	$perf_tool record -o $trace_file $gflag -z -F 5000 -- \
 		dd count=500 if=/dev/urandom of=/dev/null
 }
Signature · 1 line
2.28.0
#3 lore raw

PATCH 3/3 perf tests: Remove bash constructs from stat_all_pmu.sh

In reply to James Clark

The tests were passing but without testing and were printing the following:

  $ ./perf test -v 90
  90: perf all PMU test                                               :
  --- start ---
  test child forked, pid 51650
  Testing cpu/branch-instructions/
  ./tests/shell/stat_all_pmu.sh: 10: [:
   Performance counter stats for 'true':
             137,307      cpu/branch-instructions/

         0.001686672 seconds time elapsed

         0.001376000 seconds user
         0.000000000 seconds sys: unexpected operator

Changing the regexes to a grep works in sh and prints this:

  $ ./perf test -v 90
  90: perf all PMU test                                               :
  --- start ---
  test child forked, pid 60186
  [...]
  Testing tlb_flush.stlb_any
  test child finished with 0
  ---- end ----
  perf all PMU test: Ok
---
 tools/perf/tests/shell/stat_all_pmu.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/tests/shell/stat_all_pmu.sh +2 -2
index 2de7fd0394fd..b30dba455f36 100755
@@ -7,11 +7,11 @@ set -e
 for p in $(perf list --raw-dump pmu); do
   echo "Testing $p"
   result=$(perf stat -e "$p" true 2>&1)
-  if [[ ! "$result" =~ "$p" ]] && [[ ! "$result" =~ "<not supported>" ]]; then
+  if ! echo "$result" | grep -q "$p" && ! echo "$result" | grep -q "<not supported>" ; then
     # We failed to see the event and it is supported. Possibly the workload was
     # too small so retry with something longer.
     result=$(perf stat -e "$p" perf bench internals synthesize 2>&1)
-    if [[ ! "$result" =~ "$p" ]]; then
+    if ! echo "$result" | grep -q "$p" ; then
       echo "Event '$p' not printed in:"
       echo "$result"
       exit 1
Signature · 1 line
2.28.0