perf test: Improve shellcheck source directives
James Clark
reviewercover perf test: Improve shellcheck source directives
I was hacking away when I got blocked by a shellcheck warning about an unassigned variable, despite that variable being assigned in a sourced file and having visibly correct source= directive.
Confusingly two things turned out to be relevant to this. One is that -a doesn't make shellcheck follow "external" paths, which these are treated as. You need -x for that. Secondly, the source= directives don't cause it to follow the path either, they just suppress a warning message about dynamic paths in versions of shellcheck before 0.7.2. This warning can be silenced with "source=/dev/null" and doesn't require any particular path to be provided if -x isn't used.
---
James Clark (2):
perf test: Remove redundant shellcheck source paths perf build: Follow sourced files when running shellcheck
tools/perf/Makefile.perf | 2 +- tools/perf/tests/shell/annotate.sh | 1 - tools/perf/tests/shell/base_probe/test_adding_kernel.sh | 1 - tools/perf/tests/shell/diff.sh | 1 - tools/perf/tests/shell/inject_aslr.sh | 1 - tools/perf/tests/shell/jitdump-python.sh | 1 - tools/perf/tests/shell/list.sh | 1 - tools/perf/tests/shell/pipe_test.sh | 1 - tools/perf/tests/shell/probe_vfs_getname.sh | 2 -- tools/perf/tests/shell/python-use.sh | 1 - tools/perf/tests/shell/record+probe_libc_inet_pton.sh | 2 -- tools/perf/tests/shell/record+script_probe_vfs_getname.sh | 2 -- tools/perf/tests/shell/record.sh | 2 -- tools/perf/tests/shell/record_weak_term.sh | 1 - tools/perf/tests/shell/script_dlfilter.sh | 1 - tools/perf/tests/shell/stat+csv_output.sh | 1 - tools/perf/tests/shell/stat+json_output.sh | 1 - tools/perf/tests/shell/stat+std_output.sh | 1 - tools/perf/tests/shell/stat_metrics_values.sh | 1 - tools/perf/tests/shell/test_arm_callgraph_fp.sh | 1 - tools/perf/tests/shell/test_brstack.sh | 1 - tools/perf/tests/shell/test_data_symbol.sh | 1 - tools/perf/tests/shell/test_intel_pt.sh | 1 - tools/perf/tests/shell/test_perf_data_converter_json.sh | 1 - tools/perf/tests/shell/test_test_junit_output.sh | 1 - tools/perf/tests/shell/test_uprobe_from_different_cu.sh | 1 - tools/perf/tests/shell/trace+probe_vfs_getname.sh | 1 - tools/perf/tests/shell/trace_btf_enum.sh | 1 - tools/perf/tests/shell/trace_btf_general.sh | 1 - tools/perf/tests/shell/trace_exit_race.sh | 1 - tools/perf/tests/shell/trace_record_replay.sh | 2 -- tools/perf/tests/shell/trace_summary.sh | 1 - 32 files changed, 1 insertion(+), 37 deletions(-)
---
base-commit: 9453bc6a69ef43755f1c28d5688cacdd69fa16bd
change-id: 20260921-james-perf-shellcheck-source-f48df891cd4f
Best regards,
Signature · 1 line
James Clark <[email protected]>
James Clark
reviewerPATCH 1/2 perf test: Remove redundant shellcheck source paths
The minimum required shellcheck version treats paths with leading variables as starting from the script's current directory, so shellcheck is able to source all of these files without needing the extra directives:
v0.7.2 - 2021-04-19
Changed
* SC1090: A leading $x/ or $(x)/ is now treated as ./ when locating files
Remove them to avoid future copy pasting and confusion that they are required. Because the paths weren't actually followed, they didn't have to be accurate and accepted any string to silence the warning.
--- tools/perf/tests/shell/annotate.sh | 1 - tools/perf/tests/shell/base_probe/test_adding_kernel.sh | 1 - tools/perf/tests/shell/diff.sh | 1 - tools/perf/tests/shell/inject_aslr.sh | 1 - tools/perf/tests/shell/jitdump-python.sh | 1 - tools/perf/tests/shell/list.sh | 1 - tools/perf/tests/shell/pipe_test.sh | 1 - tools/perf/tests/shell/probe_vfs_getname.sh | 2 -- tools/perf/tests/shell/python-use.sh | 1 - tools/perf/tests/shell/record+probe_libc_inet_pton.sh | 2 -- tools/perf/tests/shell/record+script_probe_vfs_getname.sh | 2 -- tools/perf/tests/shell/record.sh | 2 -- tools/perf/tests/shell/record_weak_term.sh | 1 - tools/perf/tests/shell/script_dlfilter.sh | 1 - tools/perf/tests/shell/stat+csv_output.sh | 1 - tools/perf/tests/shell/stat+json_output.sh | 1 - tools/perf/tests/shell/stat+std_output.sh | 1 - tools/perf/tests/shell/stat_metrics_values.sh | 1 - tools/perf/tests/shell/test_arm_callgraph_fp.sh | 1 - tools/perf/tests/shell/test_brstack.sh | 1 - tools/perf/tests/shell/test_data_symbol.sh | 1 - tools/perf/tests/shell/test_intel_pt.sh | 1 - tools/perf/tests/shell/test_perf_data_converter_json.sh | 1 - tools/perf/tests/shell/test_test_junit_output.sh | 1 - tools/perf/tests/shell/test_uprobe_from_different_cu.sh | 1 - tools/perf/tests/shell/trace+probe_vfs_getname.sh | 1 - tools/perf/tests/shell/trace_btf_enum.sh | 1 - tools/perf/tests/shell/trace_btf_general.sh | 1 - tools/perf/tests/shell/trace_exit_race.sh | 1 - tools/perf/tests/shell/trace_record_replay.sh | 2 -- tools/perf/tests/shell/trace_summary.sh | 1 - 31 files changed, 36 deletions(-)
tools/perf/tests/shell/annotate.sh +0 -1
@@ -6,7 +6,6 @@ set -e shelldir=$(dirname "$0") -# shellcheck source=lib/perf_has_symbol.sh . "${shelldir}"/lib/perf_has_symbol.sh testsym="noploop"
tools/perf/tests/shell/base_probe/test_adding_kernel.sh +0 -1
@@ -19,7 +19,6 @@ TEST_RESULT=0 # include working environment . "$DIR_PATH/../common/init.sh" -# shellcheck source=lib/probe_vfs_getname.sh . "$DIR_PATH/../lib/probe_vfs_getname.sh" TEST_PROBE=${TEST_PROBE:-"inode_permission"}
tools/perf/tests/shell/diff.sh +0 -1
@@ -11,7 +11,6 @@ perfdata3=$(mktemp /tmp/__perf_test.perf.data.XXXXX) testprog="perf test -w thloop" shelldir=$(dirname "$0") -# shellcheck source=lib/perf_has_symbol.sh . "${shelldir}"/lib/perf_has_symbol.sh testsym="test_loop"
tools/perf/tests/shell/inject_aslr.sh +0 -1
@@ -6,7 +6,6 @@ set -e set -o pipefail shelldir=$(dirname "$0") -# shellcheck source=lib/perf_has_symbol.sh . "${shelldir}"/lib/perf_has_symbol.sh sym="noploop"
tools/perf/tests/shell/jitdump-python.sh +0 -1
@@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-2.0 SHELLDIR=$(dirname $0) -# shellcheck source=lib/setup_python.sh . "${SHELLDIR}"/lib/setup_python.sh OUTPUT=$(${PYTHON} -Xperf_jit -c 'import os, sys; print(os.getpid(), sys.is_stack_trampoline_active())' 2> /dev/null)
tools/perf/tests/shell/list.sh +0 -1
@@ -5,7 +5,6 @@ set -e shelldir=$(dirname "$0") -# shellcheck source=lib/setup_python.sh . "${shelldir}"/lib/setup_python.sh list_output=$(mktemp /tmp/__perf_test.list_output.json.XXXXX)
tools/perf/tests/shell/pipe_test.sh +0 -1
@@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-2.0 shelldir=$(dirname "$0") -# shellcheck source=lib/perf_has_symbol.sh . "${shelldir}"/lib/perf_has_symbol.sh sym="noploop"
tools/perf/tests/shell/probe_vfs_getname.sh +0 -2
@@ -4,13 +4,11 @@ # SPDX-License-Identifier: GPL-2.0 # Arnaldo Carvalho de Melo <[email protected]>, 2017 -# shellcheck source=lib/probe.sh . "$(dirname $0)"/lib/probe.sh skip_if_no_perf_probe || exit 2 [ "$(id -u)" = 0 ] || exit 2 -# shellcheck source=lib/probe_vfs_getname.sh . "$(dirname $0)"/lib/probe_vfs_getname.sh add_probe_vfs_getname
tools/perf/tests/shell/python-use.sh +0 -1
@@ -5,7 +5,6 @@ set -e shelldir=$(dirname "$0") -# shellcheck source=lib/setup_python.sh . "${shelldir}"/lib/setup_python.sh MODULE_DIR=$(dirname "$(which perf)")/python
tools/perf/tests/shell/record+probe_libc_inet_pton.sh +0 -2
@@ -10,9 +10,7 @@ # SPDX-License-Identifier: GPL-2.0 # Arnaldo Carvalho de Melo <[email protected]>, 2017 -# shellcheck source=lib/probe.sh . "$(dirname "$0")/lib/probe.sh" -# shellcheck source=lib/probe_vfs_getname.sh . "$(dirname "$0")/lib/probe_vfs_getname.sh" libc=$(grep -w libc /proc/self/maps | head -1 | sed -r 's/.*[[:space:]](\/.*)/\1/g')
tools/perf/tests/shell/record+script_probe_vfs_getname.sh +0 -2
@@ -9,13 +9,11 @@ # SPDX-License-Identifier: GPL-2.0 # Arnaldo Carvalho de Melo <[email protected]>, 2017 -# shellcheck source=lib/probe.sh . "$(dirname "$0")/lib/probe.sh" skip_if_no_perf_probe || exit 2 [ "$(id -u)" = 0 ] || exit 2 -# shellcheck source=lib/probe_vfs_getname.sh . "$(dirname "$0")/lib/probe_vfs_getname.sh" record_open_file() {
tools/perf/tests/shell/record.sh +0 -2
@@ -8,10 +8,8 @@ shelldir=$(dirname "$0") . "${shelldir}"/lib/perf_record.sh -# shellcheck source=lib/waiting.sh . "${shelldir}"/lib/waiting.sh -# shellcheck source=lib/perf_has_symbol.sh . "${shelldir}"/lib/perf_has_symbol.sh testsym="test_loop"
tools/perf/tests/shell/record_weak_term.sh +0 -1
@@ -5,7 +5,6 @@ set -e shelldir=$(dirname "$0") -# shellcheck source=lib/setup_python.sh . "${shelldir}"/lib/setup_python.sh # Find the first event with a specified period, such as
tools/perf/tests/shell/script_dlfilter.sh +0 -1
@@ -5,7 +5,6 @@ set -e shelldir=$(dirname "$0") -# shellcheck source=lib/setup_python.sh . "${shelldir}"/lib/setup_python.sh # skip if there's no compiler
tools/perf/tests/shell/stat+csv_output.sh +0 -1
@@ -6,7 +6,6 @@ set -e -# shellcheck source=lib/stat_output.sh . "$(dirname $0)"/lib/stat_output.sh csv_sep=@
tools/perf/tests/shell/stat+json_output.sh +0 -1
@@ -9,7 +9,6 @@ set -e skip_test=0 shelldir=$(dirname "$0") -# shellcheck source=lib/setup_python.sh . "${shelldir}"/lib/setup_python.sh pythonchecker=$(dirname $0)/lib/perf_json_output_lint.py
tools/perf/tests/shell/stat+std_output.sh +0 -1
@@ -6,7 +6,6 @@ set -e -# shellcheck source=lib/stat_output.sh . "$(dirname $0)"/lib/stat_output.sh stat_output=$(mktemp /tmp/__perf_test.stat_output.std.XXXXX)
tools/perf/tests/shell/stat_metrics_values.sh +0 -1
@@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-2.0 shelldir=$(dirname "$0") -# shellcheck source=lib/setup_python.sh . "${shelldir}"/lib/setup_python.sh grep -q GenuineIntel /proc/cpuinfo || { echo Skipping non-Intel; exit 2; }
tools/perf/tests/shell/test_arm_callgraph_fp.sh +0 -1
@@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-2.0 shelldir=$(dirname "$0") -# shellcheck source=lib/perf_has_symbol.sh . "${shelldir}"/lib/perf_has_symbol.sh if [ "$(uname -m)" != "aarch64" ]; then
tools/perf/tests/shell/test_brstack.sh +0 -1
@@ -5,7 +5,6 @@ # German Gomez <[email protected]>, 2022 shelldir=$(dirname "$0") -# shellcheck source=lib/perf_has_symbol.sh . "${shelldir}"/lib/perf_has_symbol.sh # skip the test if the hardware doesn't support branch stack sampling
tools/perf/tests/shell/test_data_symbol.sh +0 -1
@@ -6,7 +6,6 @@ shelldir=$(dirname "$0") -# shellcheck source=lib/perf_has_symbol.sh . "${shelldir}"/lib/perf_has_symbol.sh skip_if_no_mem_event() {
tools/perf/tests/shell/test_intel_pt.sh +0 -1
@@ -8,7 +8,6 @@ set -e perf list pmu | grep -q 'intel_pt//' || exit 2 shelldir=$(dirname "$0") -# shellcheck source=lib/waiting.sh . "${shelldir}"/lib/waiting.sh skip_cnt=0
tools/perf/tests/shell/test_perf_data_converter_json.sh +0 -1
@@ -7,7 +7,6 @@ set -e err=0 shelldir=$(dirname "$0") -# shellcheck source=lib/setup_python.sh . "${shelldir}"/lib/setup_python.sh perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
tools/perf/tests/shell/test_test_junit_output.sh +0 -1
@@ -7,7 +7,6 @@ set -e err=0 shelldir=$(dirname "$0") -# shellcheck source=lib/setup_python.sh . "${shelldir}"/lib/setup_python.sh result=$(mktemp /tmp/__perf_test.output.xml.XXXXX)
tools/perf/tests/shell/test_uprobe_from_different_cu.sh +0 -1
@@ -4,7 +4,6 @@ set -e -# shellcheck source=lib/probe.sh . "$(dirname $0)"/lib/probe.sh skip_if_no_perf_probe || exit 2
tools/perf/tests/shell/trace+probe_vfs_getname.sh +0 -1
@@ -10,7 +10,6 @@ # SPDX-License-Identifier: GPL-2.0 # Arnaldo Carvalho de Melo <[email protected]>, 2017 -# shellcheck source=lib/probe.sh . "$(dirname $0)"/lib/probe.sh skip_if_no_perf_probe || exit 2
tools/perf/tests/shell/trace_btf_enum.sh +0 -1
@@ -9,7 +9,6 @@ non_syscall="timer:hrtimer_start" TESTPROG="perf test -w landlock" -# shellcheck source=lib/probe.sh . "$(dirname $0)"/lib/probe.sh skip_if_no_perf_trace || exit 2 [ "$(id -u)" = 0 ] || exit 2
tools/perf/tests/shell/trace_btf_general.sh +0 -1
@@ -4,7 +4,6 @@ err=0 -# shellcheck source=lib/probe.sh . "$(dirname $0)"/lib/probe.sh file1=$(mktemp /tmp/file1_XXXX)
tools/perf/tests/shell/trace_exit_race.sh +0 -1
@@ -6,7 +6,6 @@ # lost. Specifically, trace the exiting syscall of "true" 10 times and ensure # the output contains 10 correct lines. -# shellcheck source=lib/probe.sh . "$(dirname $0)"/lib/probe.sh skip_if_no_perf_trace || exit 2
tools/perf/tests/shell/trace_record_replay.sh +0 -2
@@ -4,9 +4,7 @@ # Check that perf trace works with record and replay -# shellcheck source=lib/probe.sh . "$(dirname $0)"/lib/probe.sh -# shellcheck source=lib/perf_record.sh . "$(dirname $0)"/lib/perf_record.sh skip_if_no_perf_trace || exit 2
tools/perf/tests/shell/trace_summary.sh +0 -1
@@ -4,7 +4,6 @@ # Check that perf trace works with various summary mode -# shellcheck source=lib/probe.sh . "$(dirname $0)"/lib/probe.sh skip_if_no_perf_trace || exit 2
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 1/2] perf test: Remove redundant shellcheck source paths
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
The minimum required shellcheck version treats paths with leading variables as starting from the script's current directory, so shellcheck is able to source all of these files without needing the extra directives:
v0.7.2 - 2021-04-19
Quoted 8 lines
Changed
* SC1090: A leading $x/ or $(x)/ is now treated as ./ when locating filesRemove them to avoid future copy pasting and confusion that they are required. Because the paths weren't actually followed, they didn't have to be accurate and accepted any string to silence the warning.
Signed-off-by James Clark <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260921-james-perf-shellcheck-source-v1-0-adcfc107c997@linaro.org?part=1
James Clark
reviewerPATCH 2/2 perf build: Follow sourced files when running shellcheck
In reply to James ClarkShellcheck follows sourced scripts when -a is provided, but only when that file is also provided on the command line along with the one being checked. We only ever provide one file at a time to shellcheck, so -a does nothing.
Improve coverage by following sources using the script's directory as the base path.
--- tools/perf/Makefile.perf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.perf +1 -1
@@ -258,7 +258,7 @@ ifneq ($(SHELLCHECK),) sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \< 072), 1) SHELLCHECK := else - SHELLCHECK := $(SHELLCHECK) -s bash -a -S warning + SHELLCHECK := $(SHELLCHECK) -s bash -a -S warning -x -P SCRIPTDIR endif endif
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 2/2] perf build: Follow sourced files when running shellcheck
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
Shellcheck follows sourced scripts when -a is provided, but only when that file is also provided on the command line along with the one being checked. We only ever provide one file at a time to shellcheck, so -a does nothing.
Improve coverage by following sources using the script's directory as the base path.
Signed-off-by James Clark <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260921-james-perf-shellcheck-source-v1-0-adcfc107c997@linaro.org?part=2
Quoted 12 lines · James Clark
I was hacking away when I got blocked by a shellcheck warning about an unassigned variable, despite that variable being assigned in a sourced file and having visibly correct source= directive.
Confusingly two things turned out to be relevant to this. One is that -a doesn't make shellcheck follow "external" paths, which these are treated as. You need -x for that. Secondly, the source= directives don't cause it to follow the path either, they just suppress a warning message about dynamic paths in versions of shellcheck before 0.7.2. This warning can be silenced with "source=/dev/null" and doesn't require any particular path to be provided if -x isn't used.
Quoted 5 lines
Signed-off-by James Clark <[email protected]>---
James Clark (2):
perf test: Remove redundant shellcheck source paths perf build: Follow sourced files when running shellcheck
Thanks,
Namhyung
Quoted 42 lines
tools/perf/Makefile.perf | 2 +- tools/perf/tests/shell/annotate.sh | 1 - tools/perf/tests/shell/base_probe/test_adding_kernel.sh | 1 - tools/perf/tests/shell/diff.sh | 1 - tools/perf/tests/shell/inject_aslr.sh | 1 - tools/perf/tests/shell/jitdump-python.sh | 1 - tools/perf/tests/shell/list.sh | 1 - tools/perf/tests/shell/pipe_test.sh | 1 - tools/perf/tests/shell/probe_vfs_getname.sh | 2 -- tools/perf/tests/shell/python-use.sh | 1 - tools/perf/tests/shell/record+probe_libc_inet_pton.sh | 2 -- tools/perf/tests/shell/record+script_probe_vfs_getname.sh | 2 -- tools/perf/tests/shell/record.sh | 2 -- tools/perf/tests/shell/record_weak_term.sh | 1 - tools/perf/tests/shell/script_dlfilter.sh | 1 - tools/perf/tests/shell/stat+csv_output.sh | 1 - tools/perf/tests/shell/stat+json_output.sh | 1 - tools/perf/tests/shell/stat+std_output.sh | 1 - tools/perf/tests/shell/stat_metrics_values.sh | 1 - tools/perf/tests/shell/test_arm_callgraph_fp.sh | 1 - tools/perf/tests/shell/test_brstack.sh | 1 - tools/perf/tests/shell/test_data_symbol.sh | 1 - tools/perf/tests/shell/test_intel_pt.sh | 1 - tools/perf/tests/shell/test_perf_data_converter_json.sh | 1 - tools/perf/tests/shell/test_test_junit_output.sh | 1 - tools/perf/tests/shell/test_uprobe_from_different_cu.sh | 1 - tools/perf/tests/shell/trace+probe_vfs_getname.sh | 1 - tools/perf/tests/shell/trace_btf_enum.sh | 1 - tools/perf/tests/shell/trace_btf_general.sh | 1 - tools/perf/tests/shell/trace_exit_race.sh | 1 - tools/perf/tests/shell/trace_record_replay.sh | 2 -- tools/perf/tests/shell/trace_summary.sh | 1 - 32 files changed, 1 insertion(+), 37 deletions(-)---
base-commit:9453bc6a69ef43755f1c28d5688cacdd69fa16bd
change-id: 20260921-james-perf-shellcheck-source-f48df891cd4fBest regards,
Signature · 1 line
James Clark <[email protected]>
Quoted 9 lines · Namhyung Kim
Quoted 7 lines · James Clark
Confusingly two things turned out to be relevant to this. One is that -a doesn't make shellcheck follow "external" paths, which these are treated as. You need -x for that. Secondly, the source= directives don't cause it to follow the path either, they just suppress a warning message about dynamic paths in versions of shellcheck before 0.7.2. This warning can be silenced with "source=/dev/null" and doesn't require any particular path to be provided if -x isn't used.
Quoted 5 lines
Quoted 3 lines
James Clark (2):
perf test: Remove redundant shellcheck source paths perf build: Follow sourced files when running shellcheckAcked-by Namhyung Kim <[email protected]>
Thanks, applied to perf-tools-next, for v7.4.
- Arnaldo