perf tests lock_contention: Fix shellscript errors
authorAbhirup Deb <abhirupdeb@linux.vnet.ibm.com>
Tue, 13 Jun 2023 16:41:39 +0000 (22:11 +0530)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 14 Jun 2023 02:40:33 +0000 (23:40 -0300)
Use quotes around variables to prevent POSIX word expansion, use
uppercase for signals(INT, TERM, EXIT) to avoid mixed/lower case naming
of signals and replace "==" with "=" as "==" is not supported by POSIX
shell.

Signed-off-by: Abhirup Deb <abhirupdeb@linux.vnet.ibm.com>
Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: linuxppc-dev@lists.ozlabs.org
Link: https://lore.kernel.org/r/20230613164145.50488-12-atrajeev@linux.vnet.ibm.com
Signed-off-by: Anushree Mathur <anushree.mathur2@ibm.com>
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/shell/lock_contention.sh

index be5fcaf..f2cc187 100755 (executable)
@@ -11,14 +11,14 @@ result=$(mktemp /tmp/__perf_test.result.XXXXX)
 cleanup() {
        rm -f ${perfdata}
        rm -f ${result}
-       trap - exit term int
+       trap - EXIT TERM INT
 }
 
 trap_cleanup() {
        cleanup
        exit ${err}
 }
-trap trap_cleanup exit term int
+trap trap_cleanup EXIT TERM INT
 
 check() {
        if [ `id -u` != 0 ]; then
@@ -40,8 +40,8 @@ test_record()
        perf lock record -o ${perfdata} -- perf bench sched messaging > /dev/null 2>&1
        # the output goes to the stderr and we expect only 1 output (-E 1)
        perf lock contention -i ${perfdata} -E 1 -q 2> ${result}
-       if [ $(cat "${result}" | wc -l) != "1" ]; then
-               echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l)
+       if [ "$(cat "${result}" | wc -l)" != "1" ]; then
+               echo "[Fail] Recorded result count is not 1:" "$(cat "${result}" | wc -l)"
                err=1
                exit
        fi
@@ -58,8 +58,8 @@ test_bpf()
 
        # the perf lock contention output goes to the stderr
        perf lock con -a -b -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
-       if [ $(cat "${result}" | wc -l) != "1" ]; then
-               echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l)
+       if [ "$(cat "${result}" | wc -l)" != "1" ]; then
+               echo "[Fail] BPF result count is not 1:" "$(cat "${result}" | wc -l)"
                err=1
                exit
        fi
@@ -70,8 +70,8 @@ test_record_concurrent()
        echo "Testing perf lock record and perf lock contention at the same time"
        perf lock record -o- -- perf bench sched messaging 2> /dev/null | \
        perf lock contention -i- -E 1 -q 2> ${result}
-       if [ $(cat "${result}" | wc -l) != "1" ]; then
-               echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l)
+       if [ "$(cat "${result}" | wc -l)" != "1" ]; then
+               echo "[Fail] Recorded result count is not 1:" "$(cat "${result}" | wc -l)"
                err=1
                exit
        fi
@@ -81,8 +81,8 @@ test_aggr_task()
 {
        echo "Testing perf lock contention --threads"
        perf lock contention -i ${perfdata} -t -E 1 -q 2> ${result}
-       if [ $(cat "${result}" | wc -l) != "1" ]; then
-               echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l)
+       if [ "$(cat "${result}" | wc -l)" != "1" ]; then
+               echo "[Fail] Recorded result count is not 1:" "$(cat "${result}" | wc -l)"
                err=1
                exit
        fi
@@ -93,8 +93,8 @@ test_aggr_task()
 
        # the perf lock contention output goes to the stderr
        perf lock con -a -b -t -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
-       if [ $(cat "${result}" | wc -l) != "1" ]; then
-               echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l)
+       if [ "$(cat "${result}" | wc -l)" != "1" ]; then
+               echo "[Fail] BPF result count is not 1:" "$(cat "${result}" | wc -l)"
                err=1
                exit
        fi
@@ -104,8 +104,8 @@ test_aggr_addr()
 {
        echo "Testing perf lock contention --lock-addr"
        perf lock contention -i ${perfdata} -l -E 1 -q 2> ${result}
-       if [ $(cat "${result}" | wc -l) != "1" ]; then
-               echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l)
+       if [ "$(cat "${result}" | wc -l)" != "1" ]; then
+               echo "[Fail] Recorded result count is not 1:" "$(cat "${result}" | wc -l)"
                err=1
                exit
        fi
@@ -116,8 +116,8 @@ test_aggr_addr()
 
        # the perf lock contention output goes to the stderr
        perf lock con -a -b -l -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
-       if [ $(cat "${result}" | wc -l) != "1" ]; then
-               echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l)
+       if [ "$(cat "${result}" | wc -l)" != "1" ]; then
+               echo "[Fail] BPF result count is not 1:" "$(cat "${result}" | wc -l)"
                err=1
                exit
        fi
@@ -127,8 +127,8 @@ test_type_filter()
 {
        echo "Testing perf lock contention --type-filter (w/ spinlock)"
        perf lock contention -i ${perfdata} -Y spinlock -q 2> ${result}
-       if [ $(grep -c -v spinlock "${result}") != "0" ]; then
-               echo "[Fail] Recorded result should not have non-spinlocks:" $(cat "${result}")
+       if [ "$(grep -c -v spinlock "${result}")" != "0" ]; then
+               echo "[Fail] Recorded result should not have non-spinlocks:" "$(cat "${result}")"
                err=1
                exit
        fi
@@ -138,8 +138,8 @@ test_type_filter()
        fi
 
        perf lock con -a -b -Y spinlock -q -- perf bench sched messaging > /dev/null 2> ${result}
-       if [ $(grep -c -v spinlock "${result}") != "0" ]; then
-               echo "[Fail] BPF result should not have non-spinlocks:" $(cat "${result}")
+       if [ "$(grep -c -v spinlock "${result}")" != "0" ]; then
+               echo "[Fail] BPF result should not have non-spinlocks:" "$(cat "${result}")"
                err=1
                exit
        fi
@@ -149,7 +149,7 @@ test_lock_filter()
 {
        echo "Testing perf lock contention --lock-filter (w/ tasklist_lock)"
        perf lock contention -i ${perfdata} -l -q 2> ${result}
-       if [ $(grep -c tasklist_lock "${result}") != "1" ]; then
+       if [ "$(grep -c tasklist_lock "${result}")" != "1" ]; then
                echo "[Skip] Could not find 'tasklist_lock'"
                return
        fi
@@ -159,8 +159,8 @@ test_lock_filter()
        # find out the type of tasklist_lock
        local type=$(head -1 "${result}" | awk '{ print $8 }' | sed -e 's/:.*//')
 
-       if [ $(grep -c -v "${type}" "${result}") != "0" ]; then
-               echo "[Fail] Recorded result should not have non-${type} locks:" $(cat "${result}")
+       if [ "$(grep -c -v "${type}" "${result}")" != "0" ]; then
+               echo "[Fail] Recorded result should not have non-${type} locks:" "$(cat "${result}")"
                err=1
                exit
        fi
@@ -170,8 +170,8 @@ test_lock_filter()
        fi
 
        perf lock con -a -b -L tasklist_lock -q -- perf bench sched messaging > /dev/null 2> ${result}
-       if [ $(grep -c -v "${type}" "${result}") != "0" ]; then
-               echo "[Fail] BPF result should not have non-${type} locks:" $(cat "${result}")
+       if [ "$(grep -c -v "${type}" "${result}")" != "0" ]; then
+               echo "[Fail] BPF result should not have non-${type} locks:" "$(cat "${result}")"
                err=1
                exit
        fi
@@ -181,14 +181,14 @@ test_stack_filter()
 {
        echo "Testing perf lock contention --callstack-filter (w/ unix_stream)"
        perf lock contention -i ${perfdata} -v -q 2> ${result}
-       if [ $(grep -c unix_stream "${result}") == "0" ]; then
+       if [ "$(grep -c unix_stream "${result}")" = "0" ]; then
                echo "[Skip] Could not find 'unix_stream'"
                return
        fi
 
        perf lock contention -i ${perfdata} -E 1 -S unix_stream -q 2> ${result}
-       if [ $(cat "${result}" | wc -l) != "1" ]; then
-               echo "[Fail] Recorded result should have a lock from unix_stream:" $(cat "${result}")
+       if [ "$(cat "${result}" | wc -l)" != "1" ]; then
+               echo "[Fail] Recorded result should have a lock from unix_stream:" "$(cat "${result}")"
                err=1
                exit
        fi
@@ -198,8 +198,8 @@ test_stack_filter()
        fi
 
        perf lock con -a -b -S unix_stream -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
-       if [ $(cat "${result}" | wc -l) != "1" ]; then
-               echo "[Fail] BPF result should have a lock from unix_stream:" $(cat "${result}")
+       if [ "$(cat "${result}" | wc -l)" != "1" ]; then
+               echo "[Fail] BPF result should have a lock from unix_stream:" "$(cat "${result}")"
                err=1
                exit
        fi
@@ -209,14 +209,14 @@ test_aggr_task_stack_filter()
 {
        echo "Testing perf lock contention --callstack-filter with task aggregation"
        perf lock contention -i ${perfdata} -v -q 2> ${result}
-       if [ $(grep -c unix_stream "${result}") == "0" ]; then
+       if [ "$(grep -c unix_stream "${result}")" = "0" ]; then
                echo "[Skip] Could not find 'unix_stream'"
                return
        fi
 
        perf lock contention -i ${perfdata} -t -E 1 -S unix_stream -q 2> ${result}
-       if [ $(cat "${result}" | wc -l) != "1" ]; then
-               echo "[Fail] Recorded result should have a task from unix_stream:" $(cat "${result}")
+       if [ "$(cat "${result}" | wc -l)" != "1" ]; then
+               echo "[Fail] Recorded result should have a task from unix_stream:" "$(cat "${result}")"
                err=1
                exit
        fi
@@ -226,8 +226,8 @@ test_aggr_task_stack_filter()
        fi
 
        perf lock con -a -b -t -S unix_stream -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
-       if [ $(cat "${result}" | wc -l) != "1" ]; then
-               echo "[Fail] BPF result should have a task from unix_stream:" $(cat "${result}")
+       if [ "$(cat "${result}" | wc -l)" != "1" ]; then
+               echo "[Fail] BPF result should have a task from unix_stream:" "$(cat "${result}")"
                err=1
                exit
        fi