Skip to content

Commit a042a82

Browse files
namhyungacmel
authored andcommitted
perf test: Fix shadow stat test for non-bash shells
It was using some bash-specific features and failed to parse when running with a different shell like below: root@kbl-ppc:~/kbl-ws/perf-dev/lck-9077/acme.tmp/tools/perf# ./perf test 83 -vv 83: perf stat metrics (shadow stat) test : --- start --- test child forked, pid 3922 ./tests/shell/stat+shadow_stat.sh: 19: ./tests/shell/stat+shadow_stat.sh: [[: not found ./tests/shell/stat+shadow_stat.sh: 24: ./tests/shell/stat+shadow_stat.sh: [[: not found ./tests/shell/stat+shadow_stat.sh: 30: ./tests/shell/stat+shadow_stat.sh: [[: not found (standard_in) 2: syntax error ./tests/shell/stat+shadow_stat.sh: 36: ./tests/shell/stat+shadow_stat.sh: [[: not found ./tests/shell/stat+shadow_stat.sh: 19: ./tests/shell/stat+shadow_stat.sh: [[: not found ./tests/shell/stat+shadow_stat.sh: 24: ./tests/shell/stat+shadow_stat.sh: [[: not found ./tests/shell/stat+shadow_stat.sh: 30: ./tests/shell/stat+shadow_stat.sh: [[: not found (standard_in) 2: syntax error ./tests/shell/stat+shadow_stat.sh: 36: ./tests/shell/stat+shadow_stat.sh: [[: not found ./tests/shell/stat+shadow_stat.sh: 45: ./tests/shell/stat+shadow_stat.sh: declare: not found test child finished with -1 ---- end ---- perf stat metrics (shadow stat) test: FAILED! Reported-by: Jin Yao <yao.jin@linux.intel.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Jiri Olsa <jolsa@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: David Laight <david.laight@aculab.com> Cc: Ian Rogers <irogers@google.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lore.kernel.org/lkml/20210114050609.1258820-1-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent addbdff commit a042a82

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

tools/perf/tests/shell/stat+shadow_stat.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,29 @@ perf stat -a true > /dev/null 2>&1 || exit 2
99

1010
test_global_aggr()
1111
{
12-
local cyc
13-
1412
perf stat -a --no-big-num -e cycles,instructions sleep 1 2>&1 | \
1513
grep -e cycles -e instructions | \
1614
while read num evt hash ipc rest
1715
do
1816
# skip not counted events
19-
if [[ $num == "<not" ]]; then
17+
if [ "$num" = "<not" ]; then
2018
continue
2119
fi
2220

2321
# save cycles count
24-
if [[ $evt == "cycles" ]]; then
22+
if [ "$evt" = "cycles" ]; then
2523
cyc=$num
2624
continue
2725
fi
2826

2927
# skip if no cycles
30-
if [[ -z $cyc ]]; then
28+
if [ -z "$cyc" ]; then
3129
continue
3230
fi
3331

3432
# use printf for rounding and a leading zero
35-
local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
36-
if [[ $ipc != $res ]]; then
33+
res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
34+
if [ "$ipc" != "$res" ]; then
3735
echo "IPC is different: $res != $ipc ($num / $cyc)"
3836
exit 1
3937
fi
@@ -42,32 +40,32 @@ test_global_aggr()
4240

4341
test_no_aggr()
4442
{
45-
declare -A results
46-
4743
perf stat -a -A --no-big-num -e cycles,instructions sleep 1 2>&1 | \
4844
grep ^CPU | \
4945
while read cpu num evt hash ipc rest
5046
do
5147
# skip not counted events
52-
if [[ $num == "<not" ]]; then
48+
if [ "$num" = "<not" ]; then
5349
continue
5450
fi
5551

5652
# save cycles count
57-
if [[ $evt == "cycles" ]]; then
58-
results[$cpu]=$num
53+
if [ "$evt" = "cycles" ]; then
54+
results="$results $cpu:$num"
5955
continue
6056
fi
6157

58+
cyc=${results##* $cpu:}
59+
cyc=${cyc%% *}
60+
6261
# skip if no cycles
63-
local cyc=${results[$cpu]}
64-
if [[ -z $cyc ]]; then
62+
if [ -z "$cyc" ]; then
6563
continue
6664
fi
6765

6866
# use printf for rounding and a leading zero
69-
local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
70-
if [[ $ipc != $res ]]; then
67+
res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
68+
if [ "$ipc" != "$res" ]; then
7169
echo "IPC is different for $cpu: $res != $ipc ($num / $cyc)"
7270
exit 1
7371
fi

0 commit comments

Comments
 (0)