Skip to contentSkip to conversation

tools/perf: Fix shellcheck coding/formatting issues of perf tool shell scripts

PATCH Superseded Athira Rajeev 3 participants 26 messages Jun 21, 2023 – Jun 27, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover tools/perf: Fix shellcheck coding/formatting issues of perf tool shell scripts

Patchset covers a set of fixes for coding/formatting issues observed while running shellcheck tool on the perf shell scripts.

This cleanup is a pre-requisite to include a build option for shellcheck discussed here: https://www.spinics.net/lists/linux-perf-users/msg25553.html
First set of patches were posted here:
https://lore.kernel.org/linux-perf-users/[email protected]/T/#t

This patchset covers remaining set of shell scripts which needs fix. Patch 1 is resubmission of patch 6 from the initial series. Patch 15, 16 and 22 touches code from tools/perf/trace/beauty. Other patches are fixes for scripts from tools/perf/tests.

Akanksha J N (1):
tools/perf/tests: Fix shellcheck warnings for
trace+probe_vfs_getname.sh

Athira Rajeev (11):
tools/perf/tests: fix test_arm_spe_fork.sh signal case issues tools/perf/tests: Fix unused variable references in
stat+csv_summary.sh testcase
tools/perf/tests: fix shellcheck warning for
test_perf_data_converter_json.sh testcase
tools/perf/tests: Fix shellcheck issue for stat_bpf_counters.sh
testcase
tools/perf/tests: Fix shellcheck issues in
tests/shell/stat+shadow_stat.sh tetscase
tools/perf/tests: Fix shellcheck warnings for

    thread_loop_check_tid_10.sh

tools/perf/tests: Fix shellcheck warnings for unroll_loop_thread_10.sh tools/perf/tests: Fix shellcheck warnings for lib/probe_vfs_getname.sh tools/perf/tests: Fix the shellcheck wanrings in lib/waiting.sh tools/perf/trace: Fix x86_arch_prctl.sh to address shellcheck warnings tools/perf/arch/x86: Fix syscalltbl.sh to address shellcheck warnings

Kajol Jain (10):
tools/perf/tests: Fix shellcheck warning for probe_vfs_getname.sh
testcase
tools/perf/tests: Fix shellcheck warning for record_offcpu.sh testcase tools/perf/tests: Fix shellcheck issue for lock_contention.sh testcase tools/perf/tests: Fix shellcheck issue for stat_bpf_counters_cgrp.sh
testcase
tools/perf/tests: Fix shellcheck warning for asm_pure_loop.sh shell
script
tools/perf/tests: Fix shellcheck warning for memcpy_thread_16k_10.sh
shell script
tools/perf/tests: Fix shellcheck warning for coresight.sh shell script tools/perf/tests: Fix shellcheck warning for probe.sh shell script tools/perf/trace: Fix shellcheck issue for arch_errno_names.sh script tools/perf: Fix shellcheck issue for check-headers.sh script

 .../arch/x86/entry/syscalls/syscalltbl.sh     |  2 +-
 tools/perf/check-headers.sh                   |  6 ++--
 .../tests/shell/coresight/asm_pure_loop.sh    |  2 +-
 .../shell/coresight/memcpy_thread_16k_10.sh   |  2 +-
 .../coresight/thread_loop_check_tid_10.sh     |  2 +-
 .../shell/coresight/unroll_loop_thread_10.sh  |  2 +-
 tools/perf/tests/shell/lib/coresight.sh       |  3 +-
 tools/perf/tests/shell/lib/probe.sh           |  1 +
 .../perf/tests/shell/lib/probe_vfs_getname.sh |  5 ++--
 tools/perf/tests/shell/lib/waiting.sh         |  1 +
 tools/perf/tests/shell/lock_contention.sh     | 12 ++++----
 tools/perf/tests/shell/probe_vfs_getname.sh   |  4 +--
 tools/perf/tests/shell/record_offcpu.sh       |  6 ++--
 tools/perf/tests/shell/stat+csv_summary.sh    |  4 +--
 tools/perf/tests/shell/stat+shadow_stat.sh    |  4 +--
 tools/perf/tests/shell/stat_bpf_counters.sh   |  4 +--
 .../tests/shell/stat_bpf_counters_cgrp.sh     | 28 ++++++++-----------
 tools/perf/tests/shell/test_arm_spe_fork.sh   |  2 +-
 .../shell/test_perf_data_converter_json.sh    |  2 +-
 .../tests/shell/trace+probe_vfs_getname.sh    |  6 ++--
 tools/perf/trace/beauty/arch_errno_names.sh   | 15 ++++------
 tools/perf/trace/beauty/x86_arch_prctl.sh     |  6 ++--
 22 files changed, 58 insertions(+), 61 deletions(-)
Signature · 1 line
2.39.1
#1 lore raw

PATCH 1/22 tools/perf/tests: Fix shellcheck warnings for trace+probe_vfs_getname.sh

From: Akanksha J N <[email protected]>

Running shellcheck -S on probe_vfs_getname.sh, throws below warnings:

Before fix:

$ shellcheck -S warning trace+probe_vfs_getname.sh
	In trace+probe_vfs_getname.sh line 13:
	. $(dirname $0)/lib/probe.sh
	  ^-----------^ SC2046 (warning): Quote this to prevent word splitting.

	In trace+probe_vfs_getname.sh line 18:
	. $(dirname $0)/lib/probe_vfs_getname.sh
	  ^-----------^ SC2046 (warning): Quote this to prevent word splitting.

	In trace+probe_vfs_getname.sh line 21:
		evts=$(echo $(perf list syscalls:sys_enter_open* 2>/dev/null | grep -E 'open(at)? ' | sed -r 's/.*sys_enter_([a-z]+) +\[.*$/\1/') | sed 's/ /,/')
		            ^-- SC2046 (warning): Quote this to prevent word splitting.

Fix the shellcheck warnings by adding quotes to prevent word splitting.

---
 tools/perf/tests/shell/trace+probe_vfs_getname.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/tests/shell/trace+probe_vfs_getname.sh +3 -3
index 0a4bac3dd77e..db2ff141f703 100755
@@ -10,15 +10,15 @@
 # SPDX-License-Identifier: GPL-2.0
 # Arnaldo Carvalho de Melo <[email protected]>, 2017
 
-. $(dirname $0)/lib/probe.sh
+. "$(dirname $0)"/lib/probe.sh
 
 skip_if_no_perf_probe || exit 2
 skip_if_no_perf_trace || exit 2
 
-. $(dirname $0)/lib/probe_vfs_getname.sh
+. "$(dirname $0)"/lib/probe_vfs_getname.sh
 
 trace_open_vfs_getname() {
-	evts=$(echo $(perf list syscalls:sys_enter_open* 2>/dev/null | grep -E 'open(at)? ' | sed -r 's/.*sys_enter_([a-z]+) +\[.*$/\1/') | sed 's/ /,/')
+	evts="$(echo "$(perf list syscalls:sys_enter_open* 2>/dev/null | grep -E 'open(at)? ' | sed -r 's/.*sys_enter_([a-z]+) +\[.*$/\1/')" | sed ':a;N;s:\n:,:g')"
 	perf trace -e $evts touch $file 2>&1 | \
 	grep -E " +[0-9]+\.[0-9]+ +\( +[0-9]+\.[0-9]+ ms\): +touch\/[0-9]+ open(at)?\((dfd: +CWD, +)?filename: +${file}, +flags: CREAT\|NOCTTY\|NONBLOCK\|WRONLY, +mode: +IRUGO\|IWUGO\) += +[0-9]+$"
 }
Signature · 1 line
2.39.1
#2 lore raw

PATCH 2/22 tools/perf/tests: Fix shellcheck warning for probe_vfs_getname.sh testcase

In reply to Athira Rajeev

From: Kajol Jain <[email protected]>

Running shellcheck on probe_vfs_getname.sh throws below warning:

In tests/shell/probe_vfs_getname.sh line 7:
. $(dirname $0)/lib/probe.sh
^-----------^ SC2046 (warning): Quote this to prevent word splitting.

In tests/shell/probe_vfs_getname.sh line 11:
. $(dirname $0)/lib/probe_vfs_getname.sh
^-----------^ SC2046 (warning): Quote this to prevent word splitting.

Fixed the warning by adding quotes to avoid word splitting.

ShellCheck result with patch:

    # shellcheck -S warning probe_vfs_getname.sh
    #
---
 tools/perf/tests/shell/probe_vfs_getname.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/tests/shell/probe_vfs_getname.sh +2 -2
index 5d1b63d3f3e1..871243d6d03a 100755
@@ -4,11 +4,11 @@
 # SPDX-License-Identifier: GPL-2.0
 # Arnaldo Carvalho de Melo <[email protected]>, 2017
 
-. $(dirname $0)/lib/probe.sh
+. "$(dirname $0)"/lib/probe.sh
 
 skip_if_no_perf_probe || exit 2
 
-. $(dirname $0)/lib/probe_vfs_getname.sh
+. "$(dirname $0)"/lib/probe_vfs_getname.sh
 
 add_probe_vfs_getname || skip_if_no_debuginfo
 err=$?
Signature · 1 line
2.39.1
#3 lore raw

PATCH 3/22 tools/perf/tests: Fix shellcheck warning for record_offcpu.sh testcase

In reply to Athira Rajeev

From: Kajol Jain <[email protected]>

Running shellcheck on record_offcpu.sh throws below warning:

In tests/shell/record_offcpu.sh line 13:
trap - exit term int
^--^ SC3049 (warning): In POSIX sh, using lower/mixed case for signal names is undefined.
^--^ SC3049 (warning): In POSIX sh, using lower/mixed case for signal names is undefined.
^-^ SC3049 (warning): In POSIX sh, using lower/mixed case for signal names is undefined.

In tests/shell/record_offcpu.sh line 20:
trap trap_cleanup exit term int
^--^ SC3049 (warning): In POSIX sh, using lower/mixed case for signal names is undefined.
^--^ SC3049 (warning): In POSIX sh, using lower/mixed case for signal names is undefined.
^-^ SC3049 (warning): In POSIX sh, using lower/mixed case for signal names is undefined.

In tests/shell/record_offcpu.sh line 25:
if [ id -u != 0 ]
^-----^ SC2046 (warning): Quote this to prevent word splitting.

Fixed the warnings by:
- Capitalize signals(INT, TERM, EXIT) to avoid mixed/lower case naming of signals.
- Adding quotes to avoid word splitting.

Result from shellcheck after patch changes:

     $ shellcheck -S warning record_offcpu.sh
     $
---
 tools/perf/tests/shell/record_offcpu.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/tests/shell/record_offcpu.sh +3 -3
index f062ae9a95e1..a0d14cd0aa79 100755
@@ -10,19 +10,19 @@ perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
 cleanup() {
   rm -f ${perfdata}
   rm -f ${perfdata}.old
-  trap - exit term int
+  trap - EXIT TERM INT
 }
 
 trap_cleanup() {
   cleanup
   exit 1
 }
-trap trap_cleanup exit term int
+trap trap_cleanup EXIT TERM INT
 
 test_offcpu_priv() {
   echo "Checking off-cpu privilege"
 
-  if [ `id -u` != 0 ]
+  if [ "$(id -u)" != 0 ]
   then
     echo "off-cpu test [Skipped permission]"
     err=2
Signature · 1 line
2.39.1
#4 lore raw

PATCH 4/22 tools/perf/tests: Fix shellcheck issue for lock_contention.sh testcase

In reply to Athira Rajeev

From: Kajol Jain <[email protected]>

Running shellcheck on lock_contention.sh generates below warning:

In tests/shell/lock_contention.sh line 24:

	if [ `id -u` != 0 ]; then
             ^-----^ SC2046 (warning): Quote this to prevent word splitting.

In tests/shell/lock_contention.sh line 160:

	local type=$(head -1 "${result}" | awk '{ print $8 }' | sed -e 's/:.*//')
        ^--------^ SC3043 (warning): In POSIX sh, 'local' is undefined.
              ^--^ SC2155 (warning): Declare and assign separately to avoid masking return values.
                   ^-- SC2046 (warning): Quote this to prevent word splitting.

Fixed above warnings by:
- Adding quotes to avoid word splitting.
- Fixing shellcheck warnings for local usage, by prefixing function name to the variable.

---
 tools/perf/tests/shell/lock_contention.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/tests/shell/lock_contention.sh +6 -6
index f2cc187b6186..51421f02fb02 100755
@@ -21,7 +21,7 @@ trap_cleanup() {
 trap trap_cleanup EXIT TERM INT
 
 check() {
-	if [ `id -u` != 0 ]; then
+	if [ "$(id -u)" != 0 ]; then
 		echo "[Skip] No root permission"
 		err=2
 		exit
@@ -157,10 +157,10 @@ test_lock_filter()
 	perf lock contention -i ${perfdata} -L tasklist_lock -q 2> ${result}
 
 	# find out the type of tasklist_lock
-	local type=$(head -1 "${result}" | awk '{ print $8 }' | sed -e 's/:.*//')
+	test_lock_filter_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 "${test_lock_filter_type}" "${result}")" != "0" ]; then
+		echo "[Fail] Recorded result should not have non-${test_lock_filter_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 "${test_lock_filter_type}" "${result}")" != "0" ]; then
+		echo "[Fail] BPF result should not have non-${test_lock_filter_type} locks:" "$(cat "${result}")"
 		err=1
 		exit
 	fi
Signature · 1 line
2.39.1
#5 lore raw

PATCH 5/22 tools/perf/tests: Fix shellcheck issue for stat_bpf_counters_cgrp.sh testcase

In reply to Athira Rajeev

From: Kajol Jain <[email protected]>

Running shellcheck on lock_contention.sh generates below warning:

In stat_bpf_counters_cgrp.sh line 28:

	if [ -d /sys/fs/cgroup/system.slice -a -d /sys/fs/cgroup/user.slice ]; then
                                            ^-- SC2166 (warning): Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

In stat_bpf_counters_cgrp.sh line 34:

	local self_cgrp=$(grep perf_event /proc/self/cgroup | cut -d: -f3)
        ^-------------^ SC3043 (warning): In POSIX sh, 'local' is undefined.
              ^-------^ SC2155 (warning): Declare and assign separately to avoid masking return values.
                        ^-- SC2046 (warning): Quote this to prevent word splitting.

In stat_bpf_counters_cgrp.sh line 51:

	local output
        ^----------^ SC3043 (warning): In POSIX sh, 'local' is undefined.

In stat_bpf_counters_cgrp.sh line 65:

	local output
        ^----------^ SC3043 (warning): In POSIX sh, 'local' is undefined.

Fixed above warnings by:
- Changing the expression [p -a q] to [p] && [q].
- Fixing shellcheck warnings for local usage, by prefixing function name to the variable.

---
 .../tests/shell/stat_bpf_counters_cgrp.sh     | 28 ++++++++-----------
 1 file changed, 12 insertions(+), 16 deletions(-)
tools/perf/tests/shell/stat_bpf_counters_cgrp.sh +12 -16
index d724855d097c..a74440a00b6b 100755
@@ -25,22 +25,22 @@ check_bpf_counter()
 find_cgroups()
 {
 	# try usual systemd slices first
-	if [ -d /sys/fs/cgroup/system.slice -a -d /sys/fs/cgroup/user.slice ]; then
+	if [ -d /sys/fs/cgroup/system.slice ] && [ -d /sys/fs/cgroup/user.slice ]; then
 		test_cgroups="system.slice,user.slice"
 		return
 	fi
 
 	# try root and self cgroups
-	local self_cgrp=$(grep perf_event /proc/self/cgroup | cut -d: -f3)
-	if [ -z ${self_cgrp} ]; then
+	find_cgroups_self_cgrp=$(grep perf_event /proc/self/cgroup | cut -d: -f3)
+	if [ -z ${find_cgroups_self_cgrp} ]; then
 		# cgroup v2 doesn't specify perf_event
-		self_cgrp=$(grep ^0: /proc/self/cgroup | cut -d: -f3)
+		find_cgroups_self_cgrp=$(grep ^0: /proc/self/cgroup | cut -d: -f3)
 	fi
 
-	if [ -z ${self_cgrp} ]; then
+	if [ -z ${find_cgroups_self_cgrp} ]; then
 		test_cgroups="/"
 	else
-		test_cgroups="/,${self_cgrp}"
+		test_cgroups="/,${find_cgroups_self_cgrp}"
 	fi
 }
 
@@ -48,13 +48,11 @@ find_cgroups()
 # Just check if it runs without failure and has non-zero results.
 check_system_wide_counted()
 {
-	local output
-
-	output=$(perf stat -a --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, sleep 1  2>&1)
-	if echo ${output} | grep -q -F "<not "; then
+	check_system_wide_counted_output=$(perf stat -a --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, sleep 1  2>&1)
+	if echo ${check_system_wide_counted_output} | grep -q -F "<not "; then
 		echo "Some system-wide events are not counted"
 		if [ "${verbose}" = "1" ]; then
-			echo ${output}
+			echo ${check_system_wide_counted_output}
 		fi
 		exit 1
 	fi
@@ -62,13 +60,11 @@ check_system_wide_counted()
 
 check_cpu_list_counted()
 {
-	local output
-
-	output=$(perf stat -C 1 --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, taskset -c 1 sleep 1  2>&1)
-	if echo ${output} | grep -q -F "<not "; then
+	check_cpu_list_counted_output=$(perf stat -C 1 --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, taskset -c 1 sleep 1  2>&1)
+	if echo ${check_cpu_list_counted_output} | grep -q -F "<not "; then
 		echo "Some CPU events are not counted"
 		if [ "${verbose}" = "1" ]; then
-			echo ${output}
+			echo ${check_cpu_list_counted_output}
 		fi
 		exit 1
 	fi
Signature · 1 line
2.39.1
#6 lore raw

PATCH 6/22 tools/perf/tests: fix test_arm_spe_fork.sh signal case issues

In reply to Athira Rajeev

Running shellcheck -S on test_arm_spe_fork.sh throws below warnings:

In tests/shell/test_arm_spe_fork.sh line 25:
trap cleanup_files exit term int
^--^ SC3049 (warning): In POSIX sh, using lower/mixed case for signal names is undefined.
^--^ SC3049 (warning): In POSIX sh, using lower/mixed case for signal names is undefined.
^-^ SC3049 (warning): In POSIX sh, using lower/mixed case for signal names is undefined.

Fixed this issue by using uppercase for "EXIT", "TERM" and "INIT" signals to avoid using lower/mixed case for signal names as input.

---
 tools/perf/tests/shell/test_arm_spe_fork.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/test_arm_spe_fork.sh +1 -1
index fad361675a1d..1a7e6a82d0e3 100755
@@ -22,7 +22,7 @@ cleanup_files()
 	rm -f ${PERF_DATA}
 }
 
-trap cleanup_files exit term int
+trap cleanup_files EXIT TERM INT
 
 echo "Recording workload..."
 perf record -o ${PERF_DATA} -e arm_spe/period=65536/ -vvv -- $TEST_PROGRAM > ${PERF_RECORD_LOG} 2>&1 &
Signature · 1 line
2.39.1
#7 lore raw

PATCH 7/22 tools/perf/tests: Fix unused variable references in stat+csv_summary.sh testcase

In reply to Athira Rajeev

Running shellcheck on stat+csv_summary.sh throws below warnings:

In tests/shell/stat+csv_summary.sh line 26:
while read num event run pct
^-^ SC2034 (warning): num appears unused. Verify use (or export if used externally).
^---^ SC2034 (warning): event appears unused. Verify use (or export if used externally).
^-^ SC2034 (warning): run appears unused. Verify use (or export if used externally).
^-^ SC2034 (warning): pct appears unused. Verify use (or export if used externally).

These variables are intentioanlly unused since they are needed to parse through the output. Use "_" as a prefix for these throw away variables.

---
 tools/perf/tests/shell/stat+csv_summary.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/tests/shell/stat+csv_summary.sh +2 -2
index 5571ff75eb42..8bae9c8a835e 100755
@@ -10,7 +10,7 @@ set -e
 #
 perf stat -e cycles  -x' ' -I1000 --interval-count 1 --summary 2>&1 | \
 grep -e summary | \
-while read summary num event run pct
+while read summary _num _event _run _pct
 do
 	if [ $summary != "summary" ]; then
 		exit 1
@@ -23,7 +23,7 @@ done
 #
 perf stat -e cycles  -x' ' -I1000 --interval-count 1 --summary --no-csv-summary 2>&1 | \
 grep -e summary | \
-while read num event run pct
+while read _num _event _run _pct
 do
 	exit 1
 done
Signature · 1 line
2.39.1
#8 lore raw

PATCH 8/22 tools/perf/tests: fix shellcheck warning for test_perf_data_converter_json.sh testcase

In reply to Athira Rajeev

Running shellcheck on test_perf_data_converter_json.sh throws below warning:

In tests/shell/test_perf_data_converter_json.sh line 42:
if [ $(cat "${result}" | wc -l) -gt "0" ] ; then

                ^------------------------^ SC2046 (warning): Quote this to prevent word splitting.

Fixed the warning by adding quotes to avoid word splitting.

ShellCheck result with patch:

    # shellcheck -S warning test_perf_data_converter_json.sh
    #
---
 tools/perf/tests/shell/test_perf_data_converter_json.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/test_perf_data_converter_json.sh +1 -1
index 72ac6c83231c..6ded58f98f55 100755
@@ -39,7 +39,7 @@ test_json_converter_command()
 	echo "Testing Perf Data Convertion Command to JSON"
 	perf record -o "$perfdata" -F 99 -g -- perf test -w noploop > /dev/null 2>&1
 	perf data convert --to-json "$result" --force -i "$perfdata" >/dev/null 2>&1
-	if [ $(cat "${result}" | wc -l) -gt "0" ] ; then
+	if [ "$(cat ${result} | wc -l)" -gt "0" ] ; then
 		echo "Perf Data Converter Command to JSON [SUCCESS]"
 	else
 		echo "Perf Data Converter Command to JSON [FAILED]"
Signature · 1 line
2.39.1
#9 lore raw

PATCH 9/22 tools/perf/tests: Fix shellcheck issue for stat_bpf_counters.sh testcase

In reply to Athira Rajeev

Running shellcheck on stat_bpf_counter.sh generates below warning:

In tests/shell/stat_bpf_counters.sh line 34:
if [ "$base_cycles" == "<not" ]; then

                       ^-- SC3014 (warning): In POSIX sh, == in place of = is undefined.

In tests/shell/stat_bpf_counters.sh line 39:
if [ "$bpf_cycles" == "<not" ]; then

                      ^-- SC3014 (warning): In POSIX sh, == in place of = is undefined.

Fix this by using "=" instead of "==" to work for
all shells.

---
 tools/perf/tests/shell/stat_bpf_counters.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/tests/shell/stat_bpf_counters.sh +2 -2
index 13473aeba489..513cd1e58e0e 100755
@@ -31,12 +31,12 @@ if ! perf stat --bpf-counters true > /dev/null 2>&1; then
 fi
 
 base_cycles=$(perf stat --no-big-num -e cycles -- perf bench sched messaging -g 1 -l 100 -t 2>&1 | awk '/cycles/ {print $1}')
-if [ "$base_cycles" == "<not" ]; then
+if [ "$base_cycles" = "<not" ]; then
 	echo "Skipping: cycles event not counted"
 	exit 2
 fi
 bpf_cycles=$(perf stat --no-big-num --bpf-counters -e cycles -- perf bench sched messaging -g 1 -l 100 -t 2>&1 | awk '/cycles/ {print $1}')
-if [ "$bpf_cycles" == "<not" ]; then
+if [ "$bpf_cycles" = "<not" ]; then
 	echo "Failed: cycles not counted with --bpf-counters"
 	exit 1
 fi
Signature · 1 line
2.39.1
#10 lore raw

PATCH 10/22 tools/perf/tests: Fix shellcheck issues in tests/shell/stat+shadow_stat.sh tetscase

In reply to Athira Rajeev

Running shellcheck on stat+shadow_stat.sh generates below warning:

In tests/shell/stat+shadow_stat.sh line 48:
while read cpu num evt hash ipc rest
^--^ SC2034 (warning): hash appears unused. Verify use (or export if used externally).

This variable is intentioanlly unused since it is
needed to parse through the output. Use "_" as a
prefix for this throw away variable.

---
 tools/perf/tests/shell/stat+shadow_stat.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/tests/shell/stat+shadow_stat.sh +2 -2
index 0e9cba84e757..a1918a15e36a 100755
@@ -14,7 +14,7 @@ test_global_aggr()
 {
 	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
+	while read num evt _hash ipc rest
 	do
 		# skip not counted events
 		if [ "$num" = "<not" ]; then
@@ -45,7 +45,7 @@ test_no_aggr()
 {
 	perf stat -a -A --no-big-num -e cycles,instructions sleep 1  2>&1 | \
 	grep ^CPU | \
-	while read cpu num evt hash ipc rest
+	while read cpu num evt _hash ipc rest
 	do
 		# skip not counted events
 		if [ "$num" = "<not" ]; then
Signature · 1 line
2.39.1
#11 lore raw

PATCH 11/22 tools/perf/tests: Fix shellcheck warning for asm_pure_loop.sh shell script

In reply to Athira Rajeev

From: Kajol Jain <[email protected]>

Running shellcheck on asm_pure_loop.sh throws below warning:

In coresight/asm_pure_loop.sh line 8:
. $(dirname $0)/../lib/coresight.sh
^-----------^ SC2046 (warning): Quote this to prevent word splitting.

Fixed the warning by adding quotes to avoid word splitting.

ShellCheck result with patch:

    # shellcheck -S warning coresight/asm_pure_loop.sh
    #
---
 tools/perf/tests/shell/coresight/asm_pure_loop.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/coresight/asm_pure_loop.sh +1 -1
index 569e9d46162b..779bc8608e1e 100755
@@ -5,7 +5,7 @@
 # Carsten Haitzler <[email protected]>, 2021
 
 TEST="asm_pure_loop"
-. $(dirname $0)/../lib/coresight.sh
+. "$(dirname $0)"/../lib/coresight.sh
 ARGS=""
 DATV="out"
 DATA="$DATD/perf-$TEST-$DATV.data"
Signature · 1 line
2.39.1
#12 lore raw

PATCH 12/22 tools/perf/tests: Fix shellcheck warning for memcpy_thread_16k_10.sh shell script

In reply to Athira Rajeev

From: Kajol Jain <[email protected]>

Running shellcheck on memcpy_thread_16k_10.sh throws below warning:

In memcpy_thread_16k_10.sh line 8:
. $(dirname $0)/../lib/coresight.sh
^-----------^ SC2046 (warning): Quote this to prevent word splitting.

Fixed the warning by adding quotes to avoid word splitting.

ShellCheck result with patch:

    # shellcheck -S warning coresight/memcpy_thread_16k_10.sh
    #
---
 tools/perf/tests/shell/coresight/memcpy_thread_16k_10.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/coresight/memcpy_thread_16k_10.sh +1 -1
index d21ba8545938..08a44e52ce9b 100755
@@ -5,7 +5,7 @@
 # Carsten Haitzler <[email protected]>, 2021
 
 TEST="memcpy_thread"
-. $(dirname $0)/../lib/coresight.sh
+. "$(dirname $0)"/../lib/coresight.sh
 ARGS="16 10 1"
 DATV="16k_10"
 DATA="$DATD/perf-$TEST-$DATV.data"
Signature · 1 line
2.39.1
#13 lore raw

PATCH 13/22 tools/perf/tests: Fix shellcheck warning for coresight.sh shell script

In reply to Athira Rajeev

From: Kajol Jain <[email protected]>

Running shellcheck on coresight.sh throws below warning:

In lib/coresight.sh line 1:
^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

In lib/coresight.sh line 13:
PERFRECOPT="$PERFRECMEM -e cs_etm//u"
^--------^ SC2034 (warning): PERFRECOPT appears unused. Verify use (or export if used externally).

Fixed the warnings by:
- Adding shell directive
- Using export for PERFRECOPT variable

---
 tools/perf/tests/shell/lib/coresight.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/lib/coresight.sh +2 -1
index 6c3d34ec64d8..c7d97a0186c7 100644
@@ -1,3 +1,4 @@
+#!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 # Carsten Haitzler <[email protected]>, 2021
 
@@ -10,7 +11,7 @@
 
 # perf record options for the perf tests to use
 PERFRECMEM="-m ,16M"
-PERFRECOPT="$PERFRECMEM -e cs_etm//u"
+export PERFRECOPT="$PERFRECMEM -e cs_etm//u"
 
 TOOLS=$(dirname $0)
 DIR="$TOOLS/$TEST"
Signature · 1 line
2.39.1
#15 lore raw

PATCH 14/22 tools/perf/tests: Fix shellcheck warning for probe.sh shell script

In reply to Athira Rajeev

From: Kajol Jain <[email protected]>

Running shellcheck on probe.sh throws below warning:

In lib/probe.sh line 1:
^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

Fixed the warnings by adding shell directive.

---
 tools/perf/tests/shell/lib/probe.sh | 1 +
 1 file changed, 1 insertion(+)
tools/perf/tests/shell/lib/probe.sh +1 -0
index 51e3f60baba0..5aa6e2ec5734 100644
@@ -1,3 +1,4 @@
+#!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 # Arnaldo Carvalho de Melo <[email protected]>, 2017
 
Signature · 1 line
2.39.1
#16 lore raw

PATCH 15/22 tools/perf/trace: Fix shellcheck issue for arch_errno_names.sh script

In reply to Athira Rajeev

From: Kajol Jain <[email protected]>

Running shellcheck on arch_errno_names.sh generates below warning:

In arch_errno_names.sh line 20:

	local arch="$1"
        ^--------^ SC3043 (warning): In POSIX sh, 'local' is undefined.

......

In arch_errno_names.sh line 61:

	local arch
        ^--------^ SC3043 (warning): In POSIX sh, 'local' is undefined.

In arch_errno_names.sh line 67:

		printf '\t\treturn errno_to_name__%s(err);\n' $(arch_string "$arch")
                                                              ^--------------------^ SC2046 (warning): Quote this to prevent word splitting.

In arch_errno_names.sh line 69:

	printf '\treturn errno_to_name__%s(err);\n' $(arch_string "$default")
                                                    ^-----------------------^ SC2046 (warning): Quote this to prevent word splitting.

Fixed the warnings by:
- Fixing shellcheck warnings for local usage, by removing local from the variable names
- Adding quotes to avoid word splitting

---
 tools/perf/trace/beauty/arch_errno_names.sh | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
tools/perf/trace/beauty/arch_errno_names.sh +6 -9
index 37c53bac5f56..cc09dcaa891e 100755
@@ -17,8 +17,7 @@ arch_string()
 
 asm_errno_file()
 {
-	local arch="$1"
-	local header
+	arch="$1"
 
 	header="$toolsdir/arch/$arch/include/uapi/asm/errno.h"
 	if test -r "$header"; then
@@ -30,8 +29,7 @@ asm_errno_file()
 
 create_errno_lookup_func()
 {
-	local arch=$(arch_string "$1")
-	local nr name
+	arch=$(arch_string "$1")
 
 	printf "static const char *errno_to_name__%s(int err)\n{\n\tswitch (err) {\n" $arch
 
@@ -44,8 +42,8 @@ create_errno_lookup_func()
 
 process_arch()
 {
-	local arch="$1"
-	local asm_errno=$(asm_errno_file "$arch")
+	arch="$1"
+	asm_errno=$(asm_errno_file "$arch")
 
 	$gcc $CFLAGS $include_path -E -dM -x c $asm_errno \
 		|grep -hE '^#define[[:blank:]]+(E[^[:blank:]]+)[[:blank:]]+([[:digit:]]+).*' \
@@ -56,9 +54,8 @@ process_arch()
 
 create_arch_errno_table_func()
 {
-	local archlist="$1"
-	local default="$2"
-	local arch
+	archlist="$1"
+	default="$2"
 
 	printf 'const char *arch_syscalls__strerrno(const char *arch, int err)\n'
 	printf '{\n'
Signature · 1 line
2.39.1
#17 lore raw

PATCH 16/22 tools/perf: Fix shellcheck issue for check-headers.sh script

In reply to Athira Rajeev

From: Kajol Jain <[email protected]>

Running shellcheck on check-headers.sh generates below warning:

In check-headers.sh line 126:
check_2 "tools/$file" "$file" $*
^-- SC2048 (warning): Use "$@" (with quotes) to prevent whitespace problems.

In check-headers.sh line 134:
check_2 "tools/perf/trace/beauty/$file" "$file" $*
^-- SC2048 (warning): Use "$@" (with quotes) to prevent whitespace problems.

In check-headers.sh line 186:
cd tools/perf
^-----------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

Fixed the warnings by:
- Using "$@" instead of $*
- Adding exit condition with cd command

---
 tools/perf/check-headers.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/check-headers.sh +3 -3
index a0f1d8adce60..4314c9197850 100755
@@ -123,7 +123,7 @@ check () {
 
   shift
 
-  check_2 "tools/$file" "$file" $*
+  check_2 "tools/$file" "$file" "$@"
 }
 
 beauty_check () {
@@ -131,7 +131,7 @@ beauty_check () {
 
   shift
 
-  check_2 "tools/perf/trace/beauty/$file" "$file" $*
+  check_2 "tools/perf/trace/beauty/$file" "$file" "$@"
 }
 
 # Check if we have the kernel headers (tools/perf/../../include), else
@@ -183,7 +183,7 @@ done
 check_2 tools/perf/util/hashmap.h tools/lib/bpf/hashmap.h
 check_2 tools/perf/util/hashmap.c tools/lib/bpf/hashmap.c
 
-cd tools/perf
+cd tools/perf || exit
 
 if [ ${#FAILURES[@]} -gt 0 ]
 then
Signature · 1 line
2.39.1
#19 lore raw

PATCH 18/22 tools/perf/tests: Fix shellcheck warnings for unroll_loop_thread_10.sh

In reply to Athira Rajeev

Fix the shellcheck warnings for unroll_loop_thread_10.sh Add quotes to prevent word splitting which are caused by unquoted command expansions.

---
 tools/perf/tests/shell/coresight/unroll_loop_thread_10.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/coresight/unroll_loop_thread_10.sh +1 -1
index f48c85230b15..7304e3d3a6ff 100755
@@ -5,7 +5,7 @@
 # Carsten Haitzler <[email protected]>, 2021
 
 TEST="unroll_loop_thread"
-. $(dirname $0)/../lib/coresight.sh
+. "$(dirname $0)"/../lib/coresight.sh
 ARGS="10"
 DATV="10"
 DATA="$DATD/perf-$TEST-$DATV.data"
Signature · 1 line
2.39.1
#20 lore raw

PATCH 19/22 tools/perf/tests: Fix shellcheck warnings for lib/probe_vfs_getname.sh

In reply to Athira Rajeev

Running shellcheck on probe_vfs_getname fails with below warning:

In ./tools/perf/tests/shell/lib/probe_vfs_getname.sh line 1:
# Arnaldo Carvalho de Melo <[email protected]>, 2017
^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

In ./tools/perf/tests/shell/lib/probe_vfs_getname.sh line 14:
local verbose=$1

           ^-----------^ SC3043 (warning): In POSIX sh, 'local' is undefined.

Fix this:
- by adding shebang in the beginning of the file and
- rename variable verbose to "add_probe_verbose" after removing local

---
 tools/perf/tests/shell/lib/probe_vfs_getname.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/tests/shell/lib/probe_vfs_getname.sh +3 -2
index 60c5e34f90c4..bf4c1fb71c4b 100644
@@ -1,3 +1,4 @@
+#!/bin/sh
 # Arnaldo Carvalho de Melo <[email protected]>, 2017
 
 perf probe -l 2>&1 | grep -q probe:vfs_getname
@@ -10,11 +11,11 @@ cleanup_probe_vfs_getname() {
 }
 
 add_probe_vfs_getname() {
-	local verbose=$1
+	add_probe_verbose=$1
 	if [ $had_vfs_getname -eq 1 ] ; then
 		line=$(perf probe -L getname_flags 2>&1 | grep -E 'result.*=.*filename;' | sed -r 's/[[:space:]]+([[:digit:]]+)[[:space:]]+result->uptr.*/\1/')
 		perf probe -q       "vfs_getname=getname_flags:${line} pathname=result->name:string" || \
-		perf probe $verbose "vfs_getname=getname_flags:${line} pathname=filename:ustring"
+		perf probe $add_probe_verbose "vfs_getname=getname_flags:${line} pathname=filename:ustring"
 	fi
 }
 
Signature · 1 line
2.39.1
#23 lore raw

PATCH 22/22 tools/perf/arch/x86: Fix syscalltbl.sh to address shellcheck warnings

In reply to Athira Rajeev

Running shellcheck on syscalltbl.sh generates below warning:

In ./tools/perf/arch/x86/entry/syscalls/syscalltbl.sh line 27:
while read nr abi name entry compat; do
^-^ SC2034 (warning): abi appears unused. Verify use (or export if used externally).
^----^ SC2034 (warning): compat appears unused. Verify use (or export if used externally).

These variables are intentioanlly unused since they are needed to parse through the output. Use "_" as a prefix for these throw away variables.

---
 tools/perf/arch/x86/entry/syscalls/syscalltbl.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/arch/x86/entry/syscalls/syscalltbl.sh +1 -1
index fa526a993845..59d7914ed6bb 100755
@@ -24,7 +24,7 @@ sorted_table=$(mktemp /tmp/syscalltbl.XXXXXX)
 grep '^[0-9]' "$in" | sort -n > $sorted_table
 
 max_nr=0
-while read nr abi name entry compat; do
+while read nr _abi name entry _compat; do
     if [ $nr -ge 512 ] ; then # discard compat sycalls
         break
     fi
Signature · 1 line
2.39.1
#22 lore raw

PATCH 21/22 tools/perf/trace: Fix x86_arch_prctl.sh to address shellcheck warnings

In reply to Athira Rajeev

Running shellcheck on x86_arch_prctl.sh generates below warning:

In ./tools/perf/trace/beauty/x86_arch_prctl.sh line 10:

      	local idx=$1
        ^-------^ SC3043 (warning): In POSIX sh, 'local' is undefined.

In ./tools/perf/trace/beauty/x86_arch_prctl.sh line 11:

	local prefix=$2
        ^----------^ SC3043 (warning): In POSIX sh, 'local' is undefined.

In ./tools/perf/trace/beauty/x86_arch_prctl.sh line 12:

	local first_entry=$3
        ^---------------^ SC3043 (warning): In POSIX sh, 'local' is undefined.

Fix this by removing local since these are variables used only in specific function

---
 tools/perf/trace/beauty/x86_arch_prctl.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/trace/beauty/x86_arch_prctl.sh +3 -3
index fd5c740512c5..b1596df251f0 100755
@@ -7,9 +7,9 @@
 prctl_arch_header=${x86_header_dir}/prctl.h
 
 print_range () {
-	local idx=$1
-	local prefix=$2
-	local first_entry=$3
+	idx=$1
+	prefix=$2
+	first_entry=$3
 
 	printf "#define x86_arch_prctl_codes_%d_offset %s\n" $idx $first_entry
 	printf "static const char *x86_arch_prctl_codes_%d[] = {\n" $idx
Signature · 1 line
2.39.1
#18 lore raw

PATCH 17/22 tools/perf/tests: Fix shellcheck warnings for thread_loop_check_tid_10.sh

In reply to Athira Rajeev

Fix the shellcheck warnings for thread_loop_check_tid_10.sh

In ./tools/perf/tests/shell/coresight/thread_loop_check_tid_10.sh line 8:
. $(dirname $0)/../lib/coresight.sh

     ^-----------^ SC2046 (warning): Quote this to prevent word splitting.

Add quotes to prevent word splitting which are caused by unquoted command expansions.

---
 tools/perf/tests/shell/coresight/thread_loop_check_tid_10.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/coresight/thread_loop_check_tid_10.sh +1 -1
index 7c13636fc778..c83a200dede4 100755
@@ -5,7 +5,7 @@
 # Carsten Haitzler <[email protected]>, 2021
 
 TEST="thread_loop"
-. $(dirname $0)/../lib/coresight.sh
+. "$(dirname $0)"/../lib/coresight.sh
 ARGS="10 1"
 DATV="check-tid-10th"
 DATA="$DATD/perf-$TEST-$DATV.data"
Signature · 1 line
2.39.1
#21 lore raw

PATCH 20/22 tools/perf/tests: Fix the shellcheck wanrings in lib/waiting.sh

In reply to Athira Rajeev

Running shellcheck in "lib/waiting.sh" generates below warning:

In ./tools/perf/tests/shell/lib/waiting.sh line 1:
# SPDX-License-Identifier: GPL-2.0
^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

Fix this by adding shebang in the beginning of the script.

---
 tools/perf/tests/shell/lib/waiting.sh | 1 +
 1 file changed, 1 insertion(+)
tools/perf/tests/shell/lib/waiting.sh +1 -0
index e7a39134a68e..bdd5a7c71591 100644
@@ -1,3 +1,4 @@
+#!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 
 tenths=date\ +%s%1N
Signature · 1 line
2.39.1
maintainer
#24 lore raw
In reply to Athira Rajeev

Hello,

Quoted 9 lines · Athira Rajeev

Patchset covers a set of fixes for coding/formatting issues observed while running shellcheck tool on the perf shell scripts.

This cleanup is a pre-requisite to include a build option for shellcheck discussed here: https://www.spinics.net/lists/linux-perf-users/msg25553.html
First set of patches were posted here:
https://lore.kernel.org/linux-perf-users/[email protected]/T/#t

Quoted 4 lines

This patchset covers remaining set of shell scripts which needs fix. Patch 1 is resubmission of patch 6 from the initial series. Patch 15, 16 and 22 touches code from tools/perf/trace/beauty. Other patches are fixes for scripts from tools/perf/tests.

Thanks for this work. But it seems there are some issues even after applying this series.

  $ for F in $(find tests/shell/ -perm -o=x -name '*.sh'); do
Quoted 1 line

shellcheck $F; done | grep -c -e '(info)' -e '(warning)'

29

  $ for F in $(find tests/shell/ -perm -o=x -name '*.sh'); do
Quoted 1 line

shellcheck $F; done | grep ^In

In tests/shell/pipe_test.sh line 10:
In tests/shell/pipe_test.sh line 15:
In tests/shell/pipe_test.sh line 20:
In tests/shell/pipe_test.sh line 21:
In tests/shell/pipe_test.sh line 26:
In tests/shell/pipe_test.sh line 27:
In tests/shell/pipe_test.sh line 33:
In tests/shell/record+zstd_comp_decomp.sh line 16:
In tests/shell/record+zstd_comp_decomp.sh line 22:
In tests/shell/record+zstd_comp_decomp.sh line 27:
In tests/shell/record+zstd_comp_decomp.sh line 28:
In tests/shell/record+zstd_comp_decomp.sh line 29:
In tests/shell/record+zstd_comp_decomp.sh line 30:
In tests/shell/record+zstd_comp_decomp.sh line 36:
In tests/shell/coresight/thread_loop_check_tid_2.sh line 8:
In tests/shell/coresight/thread_loop_check_tid_2.sh line 11:
In tests/shell/coresight/thread_loop_check_tid_2.sh line 14:

Also unfortunately there's some update in the shell tests. Please rebase onto the perf-tools-next.

Thanks,
Namhyung

Quoted 66 lines

Akanksha J N (1):
tools/perf/tests: Fix shellcheck warnings for
trace+probe_vfs_getname.sh

Athira Rajeev (11):
tools/perf/tests: fix test_arm_spe_fork.sh signal case issues tools/perf/tests: Fix unused variable references in
stat+csv_summary.sh testcase
tools/perf/tests: fix shellcheck warning for
test_perf_data_converter_json.sh testcase
tools/perf/tests: Fix shellcheck issue for stat_bpf_counters.sh
testcase
tools/perf/tests: Fix shellcheck issues in
tests/shell/stat+shadow_stat.sh tetscase
tools/perf/tests: Fix shellcheck warnings for

    thread_loop_check_tid_10.sh

tools/perf/tests: Fix shellcheck warnings for unroll_loop_thread_10.sh tools/perf/tests: Fix shellcheck warnings for lib/probe_vfs_getname.sh tools/perf/tests: Fix the shellcheck wanrings in lib/waiting.sh tools/perf/trace: Fix x86_arch_prctl.sh to address shellcheck warnings tools/perf/arch/x86: Fix syscalltbl.sh to address shellcheck warnings

Kajol Jain (10):
tools/perf/tests: Fix shellcheck warning for probe_vfs_getname.sh
testcase
tools/perf/tests: Fix shellcheck warning for record_offcpu.sh testcase tools/perf/tests: Fix shellcheck issue for lock_contention.sh testcase tools/perf/tests: Fix shellcheck issue for stat_bpf_counters_cgrp.sh
testcase
tools/perf/tests: Fix shellcheck warning for asm_pure_loop.sh shell
script
tools/perf/tests: Fix shellcheck warning for memcpy_thread_16k_10.sh
shell script
tools/perf/tests: Fix shellcheck warning for coresight.sh shell script tools/perf/tests: Fix shellcheck warning for probe.sh shell script tools/perf/trace: Fix shellcheck issue for arch_errno_names.sh script tools/perf: Fix shellcheck issue for check-headers.sh script

 .../arch/x86/entry/syscalls/syscalltbl.sh     |  2 +-
 tools/perf/check-headers.sh                   |  6 ++--
 .../tests/shell/coresight/asm_pure_loop.sh    |  2 +-
 .../shell/coresight/memcpy_thread_16k_10.sh   |  2 +-
 .../coresight/thread_loop_check_tid_10.sh     |  2 +-
 .../shell/coresight/unroll_loop_thread_10.sh  |  2 +-
 tools/perf/tests/shell/lib/coresight.sh       |  3 +-
 tools/perf/tests/shell/lib/probe.sh           |  1 +
 .../perf/tests/shell/lib/probe_vfs_getname.sh |  5 ++--
 tools/perf/tests/shell/lib/waiting.sh         |  1 +
 tools/perf/tests/shell/lock_contention.sh     | 12 ++++----
 tools/perf/tests/shell/probe_vfs_getname.sh   |  4 +--
 tools/perf/tests/shell/record_offcpu.sh       |  6 ++--
 tools/perf/tests/shell/stat+csv_summary.sh    |  4 +--
 tools/perf/tests/shell/stat+shadow_stat.sh    |  4 +--
 tools/perf/tests/shell/stat_bpf_counters.sh   |  4 +--
 .../tests/shell/stat_bpf_counters_cgrp.sh     | 28 ++++++++-----------
 tools/perf/tests/shell/test_arm_spe_fork.sh   |  2 +-
 .../shell/test_perf_data_converter_json.sh    |  2 +-
 .../tests/shell/trace+probe_vfs_getname.sh    |  6 ++--
 tools/perf/trace/beauty/arch_errno_names.sh   | 15 ++++------
 tools/perf/trace/beauty/x86_arch_prctl.sh     |  6 ++--
 22 files changed, 58 insertions(+), 61 deletions(-)

--
2.39.1

#25 lore raw
Quoted 49 lines · Namhyung Kim

Hello,

Quoted 9 lines · Athira Rajeev

Patchset covers a set of fixes for coding/formatting issues observed while running shellcheck tool on the perf shell scripts.

This cleanup is a pre-requisite to include a build option for shellcheck discussed here: https://www.spinics.net/lists/linux-perf-users/msg25553.html
First set of patches were posted here:
https://lore.kernel.org/linux-perf-users/[email protected]/T/#t

Quoted 4 lines

This patchset covers remaining set of shell scripts which needs fix. Patch 1 is resubmission of patch 6 from the initial series. Patch 15, 16 and 22 touches code from tools/perf/trace/beauty. Other patches are fixes for scripts from tools/perf/tests.

Thanks for this work. But it seems there are some issues even after applying this series.

 $ for F in $(find tests/shell/ -perm -o=x -name '*.sh'); do
Quoted 1 line

shellcheck $F; done | grep -c -e '(info)' -e '(warning)'

29

 $ for F in $(find tests/shell/ -perm -o=x -name '*.sh'); do
Quoted 1 line

shellcheck $F; done | grep ^In

In tests/shell/pipe_test.sh line 10:
In tests/shell/pipe_test.sh line 15:
In tests/shell/pipe_test.sh line 20:
In tests/shell/pipe_test.sh line 21:
In tests/shell/pipe_test.sh line 26:
In tests/shell/pipe_test.sh line 27:
In tests/shell/pipe_test.sh line 33:
In tests/shell/record+zstd_comp_decomp.sh line 16:
In tests/shell/record+zstd_comp_decomp.sh line 22:
In tests/shell/record+zstd_comp_decomp.sh line 27:
In tests/shell/record+zstd_comp_decomp.sh line 28:
In tests/shell/record+zstd_comp_decomp.sh line 29:
In tests/shell/record+zstd_comp_decomp.sh line 30:
In tests/shell/record+zstd_comp_decomp.sh line 36:
In tests/shell/coresight/thread_loop_check_tid_2.sh line 8:
In tests/shell/coresight/thread_loop_check_tid_2.sh line 11:
In tests/shell/coresight/thread_loop_check_tid_2.sh line 14:

Quoted 2 lines

Also unfortunately there's some update in the shell tests. Please rebase onto the perf-tools-next.

Hi Namhyung

Thanks for checking. Will send an updated version on top of perf-tools-next

Thanks
Athira

Quoted 70 lines

Thanks,
Namhyung

Quoted 65 lines

Akanksha J N (1):
tools/perf/tests: Fix shellcheck warnings for
trace+probe_vfs_getname.sh

Athira Rajeev (11):
tools/perf/tests: fix test_arm_spe_fork.sh signal case issues tools/perf/tests: Fix unused variable references in
stat+csv_summary.sh testcase
tools/perf/tests: fix shellcheck warning for
test_perf_data_converter_json.sh testcase
tools/perf/tests: Fix shellcheck issue for stat_bpf_counters.sh
testcase
tools/perf/tests: Fix shellcheck issues in
tests/shell/stat+shadow_stat.sh tetscase
tools/perf/tests: Fix shellcheck warnings for
thread_loop_check_tid_10.sh
tools/perf/tests: Fix shellcheck warnings for unroll_loop_thread_10.sh tools/perf/tests: Fix shellcheck warnings for lib/probe_vfs_getname.sh tools/perf/tests: Fix the shellcheck wanrings in lib/waiting.sh tools/perf/trace: Fix x86_arch_prctl.sh to address shellcheck warnings tools/perf/arch/x86: Fix syscalltbl.sh to address shellcheck warnings

Kajol Jain (10):
tools/perf/tests: Fix shellcheck warning for probe_vfs_getname.sh
testcase
tools/perf/tests: Fix shellcheck warning for record_offcpu.sh testcase tools/perf/tests: Fix shellcheck issue for lock_contention.sh testcase tools/perf/tests: Fix shellcheck issue for stat_bpf_counters_cgrp.sh
testcase
tools/perf/tests: Fix shellcheck warning for asm_pure_loop.sh shell
script
tools/perf/tests: Fix shellcheck warning for memcpy_thread_16k_10.sh
shell script
tools/perf/tests: Fix shellcheck warning for coresight.sh shell script tools/perf/tests: Fix shellcheck warning for probe.sh shell script tools/perf/trace: Fix shellcheck issue for arch_errno_names.sh script tools/perf: Fix shellcheck issue for check-headers.sh script

.../arch/x86/entry/syscalls/syscalltbl.sh     |  2 +-
tools/perf/check-headers.sh                   |  6 ++--
.../tests/shell/coresight/asm_pure_loop.sh    |  2 +-
.../shell/coresight/memcpy_thread_16k_10.sh   |  2 +-
.../coresight/thread_loop_check_tid_10.sh     |  2 +-
.../shell/coresight/unroll_loop_thread_10.sh  |  2 +-
tools/perf/tests/shell/lib/coresight.sh       |  3 +-
tools/perf/tests/shell/lib/probe.sh           |  1 +
.../perf/tests/shell/lib/probe_vfs_getname.sh |  5 ++--
tools/perf/tests/shell/lib/waiting.sh         |  1 +
tools/perf/tests/shell/lock_contention.sh     | 12 ++++----
tools/perf/tests/shell/probe_vfs_getname.sh   |  4 +--
tools/perf/tests/shell/record_offcpu.sh       |  6 ++--
tools/perf/tests/shell/stat+csv_summary.sh    |  4 +--
tools/perf/tests/shell/stat+shadow_stat.sh    |  4 +--
tools/perf/tests/shell/stat_bpf_counters.sh   |  4 +--
.../tests/shell/stat_bpf_counters_cgrp.sh     | 28 ++++++++-----------
tools/perf/tests/shell/test_arm_spe_fork.sh   |  2 +-
.../shell/test_perf_data_converter_json.sh    |  2 +-
.../tests/shell/trace+probe_vfs_getname.sh    |  6 ++--
tools/perf/trace/beauty/arch_errno_names.sh   | 15 ++++------
tools/perf/trace/beauty/x86_arch_prctl.sh     |  6 ++--
22 files changed, 58 insertions(+), 61 deletions(-)

--
2.39.1

#14 lore raw

Re: [PATCH 13/22] tools/perf/tests: Fix shellcheck warning for coresight.sh shell script

In reply to Athira Rajeev
Quoted 26 lines · Athira Rajeev

From: Kajol Jain <[email protected]>

Running shellcheck on coresight.sh throws below warning:

In lib/coresight.sh line 1:
^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

In lib/coresight.sh line 13:
PERFRECOPT="$PERFRECMEM -e cs_etm//u"
^--------^ SC2034 (warning): PERFRECOPT appears unused. Verify use (or export if used externally).

Fixed the warnings by:
- Adding shell directive
- Using export for PERFRECOPT variable

---
 tools/perf/tests/shell/lib/coresight.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/lib/coresight.sh +0 -0
index 6c3d34ec64d8..c7d97a0186c7 100644

tools/perf/tests/shell/lib/coresight.sh line 1

Quoted 1 line
tools/perf/tests/shell/lib/coresight.sh +1 -0
@@ -1,3 +1,4 @@
+#!/bin/bash

There is a comment a couple of lines below this that says the shebang was excluded for a reason. It's probably worth leaving it excluded or updating the comment.

tools/perf/tests/shell/lib/coresight.sh line 14

Quoted 9 lines
tools/perf/tests/shell/lib/coresight.sh +1 -1
 # SPDX-License-Identifier: GPL-2.0
 # Carsten Haitzler <[email protected]>, 2021
 
@@ -10,7 +11,7 @@
 
 # perf record options for the perf tests to use
 PERFRECMEM="-m ,16M"
-PERFRECOPT="$PERFRECMEM -e cs_etm//u"
+export PERFRECOPT="$PERFRECMEM -e cs_etm//u"

This might silence the warning, but there are other variables like DATD that are used in the sub-test scripts in the same way. They just don't trigger the warning because they're also used in the top level one.

I think this change makes the code more misleading than solving any problems. The coresight.sh script is sourced in the same process as the sub tests so exporting variables isn't needed which is why it already works without this change.

Quoted 3 lines
tools/perf/tests/shell/lib/coresight.sh +0 -0
 TOOLS=$(dirname $0)
 DIR="$TOOLS/$TEST"