linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
To: acme@kernel.org, jolsa@kernel.org, irogers@google.com,
	namhyung@kernel.org
Cc: linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	maddy@linux.ibm.com, atrajeev@linux.vnet.ibm.com,
	kjain@linux.ibm.com, disgoel@linux.vnet.ibm.com
Subject: [PATCH V2 05/26] tools/perf/tests: Fix shellcheck issue for stat_bpf_counters_cgrp.sh testcase
Date: Sun,  9 Jul 2023 23:57:39 +0530	[thread overview]
Message-ID: <20230709182800.53002-6-atrajeev@linux.vnet.ibm.com> (raw)
In-Reply-To: <20230709182800.53002-1-atrajeev@linux.vnet.ibm.com>

From: Kajol Jain <kjain@linux.ibm.com>

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.

Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---
 .../tests/shell/stat_bpf_counters_cgrp.sh     | 28 ++++++++-----------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh b/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh
index d724855d097c..a74440a00b6b 100755
--- a/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh
+++ b/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh
@@ -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
-- 
2.39.1


  parent reply	other threads:[~2023-07-09 18:28 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-09 18:27 [PATCH V2 00/26] tools/perf: Fix shellcheck coding/formatting issues of perf tool shell scripts Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 01/26] tools/perf/tests: Fix shellcheck warnings for trace+probe_vfs_getname.sh Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 02/26] tools/perf/tests: Fix shellcheck warning for probe_vfs_getname.sh testcase Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 03/26] tools/perf/tests: Fix shellcheck warning for record_offcpu.sh testcase Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 04/26] tools/perf/tests: Fix shellcheck issue for lock_contention.sh testcase Athira Rajeev
2023-07-09 18:27 ` Athira Rajeev [this message]
2023-07-09 18:27 ` [PATCH V2 06/26] tools/perf/tests: fix test_arm_spe_fork.sh signal case issues Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 07/26] tools/perf/tests: Fix unused variable references in stat+csv_summary.sh testcase Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 08/26] tools/perf/tests: fix shellcheck warning for test_perf_data_converter_json.sh testcase Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 09/26] tools/perf/tests: Fix shellcheck issue for stat_bpf_counters.sh testcase Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 10/26] tools/perf/tests: Fix shellcheck issues in tests/shell/stat+shadow_stat.sh tetscase Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 11/26] tools/perf/tests: Fix shellcheck warning for asm_pure_loop.sh shell script Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 12/26] tools/perf/tests: Fix shellcheck warning for memcpy_thread_16k_10.sh " Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 13/26] tools/perf/tests: Fix shellcheck warning for probe.sh " Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 14/26] tools/perf/trace: Fix shellcheck issue for arch_errno_names.sh script Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 15/26] tools/perf: Fix shellcheck issue for check-headers.sh script Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 16/26] tools/perf/tests: Fix shellcheck warnings for thread_loop_check_tid_10.sh Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 17/26] tools/perf/tests: Fix shellcheck warnings for unroll_loop_thread_10.sh Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 18/26] tools/perf/tests: Fix shellcheck warnings for lib/probe_vfs_getname.sh Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 19/26] tools/perf/tests: Fix the shellcheck warnings in lib/waiting.sh Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 20/26] tools/perf/trace: Fix x86_arch_prctl.sh to address shellcheck warnings Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 21/26] tools/perf/arch/x86: Fix syscalltbl.sh " Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 22/26] tools/perf/tests/shell: Fix the shellcheck warnings in record+zstd_comp_decomp.sh Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 23/26] tools/shell/coresight: Fix shellcheck warning for thread_loop_check_tid_2.sh shell script Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 24/26] tools/perf/tests/shell/lib: Fix shellcheck warning for stat_output.sh " Athira Rajeev
2023-07-09 18:27 ` [PATCH V2 25/26] tools/perf/tests/shell: Fix shellcheck warning for stat+std_output.sh testcase Athira Rajeev
2023-07-09 18:28 ` [PATCH V2 26/26] tools/perf/tests: " Athira Rajeev
2023-07-19  6:17 ` [PATCH V2 00/26] tools/perf: Fix shellcheck coding/formatting issues of perf tool shell scripts kajoljain
2023-07-19 17:46   ` Ian Rogers
2023-07-20  5:12     ` Athira Rajeev
2023-07-20  5:18       ` kajoljain
2023-07-25  5:50         ` Athira Rajeev
2023-07-28 19:04           ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230709182800.53002-6-atrajeev@linux.vnet.ibm.com \
    --to=atrajeev@linux.vnet.ibm.com \
    --cc=acme@kernel.org \
    --cc=disgoel@linux.vnet.ibm.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kjain@linux.ibm.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).