perf test: Fix shadow stat test for non-bash shells
[linux-2.6-microblaze.git] / tools / perf / tests / shell / stat+shadow_stat.sh
index 249dfe4..ebebd35 100755 (executable)
@@ -9,31 +9,29 @@ perf stat -a true > /dev/null 2>&1 || exit 2
 
 test_global_aggr()
 {
-       local cyc
-
        perf stat -a --no-big-num -e cycles,instructions sleep 1  2>&1 | \
        grep -e cycles -e instructions | \
        while read num evt hash ipc rest
        do
                # skip not counted events
-               if [[ $num == "<not" ]]; then
+               if [ "$num" = "<not" ]; then
                        continue
                fi
 
                # save cycles count
-               if [[ $evt == "cycles" ]]; then
+               if [ "$evt" = "cycles" ]; then
                        cyc=$num
                        continue
                fi
 
                # skip if no cycles
-               if [[ -z $cyc ]]; then
+               if [ -z "$cyc" ]; then
                        continue
                fi
 
                # use printf for rounding and a leading zero
-               local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
-               if [[ $ipc != $res ]]; then
+               res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
+               if [ "$ipc" != "$res" ]; then
                        echo "IPC is different: $res != $ipc  ($num / $cyc)"
                        exit 1
                fi
@@ -42,32 +40,32 @@ test_global_aggr()
 
 test_no_aggr()
 {
-       declare -A results
-
        perf stat -a -A --no-big-num -e cycles,instructions sleep 1  2>&1 | \
        grep ^CPU | \
        while read cpu num evt hash ipc rest
        do
                # skip not counted events
-               if [[ $num == "<not" ]]; then
+               if [ "$num" = "<not" ]; then
                        continue
                fi
 
                # save cycles count
-               if [[ $evt == "cycles" ]]; then
-                       results[$cpu]=$num
+               if [ "$evt" = "cycles" ]; then
+                       results="$results $cpu:$num"
                        continue
                fi
 
+               cyc=${results##* $cpu:}
+               cyc=${cyc%% *}
+
                # skip if no cycles
-               local cyc=${results[$cpu]}
-               if [[ -z $cyc ]]; then
+               if [ -z "$cyc" ]; then
                        continue
                fi
 
                # use printf for rounding and a leading zero
-               local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
-               if [[ $ipc != $res ]]; then
+               res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
+               if [ "$ipc" != "$res" ]; then
                        echo "IPC is different for $cpu: $res != $ipc  ($num / $cyc)"
                        exit 1
                fi