perf tests shell: Fixed shellcheck warnings
authorSamir Mulani <samir@linux.vnet.ibm.com>
Tue, 13 Jun 2023 16:41:40 +0000 (22:11 +0530)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 14 Jun 2023 02:40:34 +0000 (23:40 -0300)
Fixed the shellcheck warnings in buildid.sh, record+probe_libc_inet_pton.sh
and record+script_probe_vfs_getname.sh perf shell scripts:

1. Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
2. Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.
3. Used * argument to avoid the argument mixes string and array
4. Resolved issue for variable refernce, where the variable is
   being used before it has been initialized.
5. Resolved word splitting issue (syntax error).
6. The "err" variable has been removed from buildid.sh since
   it is not used anywhere in the code.

Signed-off-by: Samir Mulani <samir@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-13-atrajeev@linux.vnet.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/buildid.sh
tools/perf/tests/shell/record+probe_libc_inet_pton.sh
tools/perf/tests/shell/record+script_probe_vfs_getname.sh

index 0ce22ea0a7f136ae2e3df37b0b34428772c8c316..3383ca3399d4c59c6cc4a8497b6d2ab291e7b85c 100755 (executable)
@@ -83,12 +83,12 @@ check()
        # in case of pe-file.exe file
        echo $1 | grep ".exe"
        if [ $? -eq 0 ]; then
-               if [ -x $1  -a ! -x $file ]; then
+               if [ -x $1 ] && [ ! -x $file ]; then
                        echo "failed: file ${file} executable does not exist"
                        exit 1
                fi
 
-               if [ ! -x $file -a ! -e $file ]; then
+               if [ ! -x $file ] && [ ! -e $file ]; then
                        echo "failed: file ${file} does not exist"
                        exit 1
                fi
@@ -136,10 +136,10 @@ test_record()
        log_err=$(mktemp /tmp/perf.log.err.XXX)
        perf="perf --buildid-dir ${build_id_dir}"
 
-       echo "running: perf record $@"
-       ${perf} record --buildid-all -o ${data} $@ 1>${log_out} 2>${log_err}
+       echo "running: perf record $*"
+       ${perf} record --buildid-all -o ${data} "$@" 1>${log_out} 2>${log_err}
        if [ $? -ne 0 ]; then
-               echo "failed: record $@"
+               echo "failed: record $*"
                echo "see log: ${log_err}"
                exit 1
        fi
@@ -172,4 +172,4 @@ if [ ${run_pe} -eq 1 ]; then
        rm -r ${wineprefix}
 fi
 
-exit ${err}
+exit 0
index bbb5b3d185fac0b73a7c08263a87e8e89c4c5625..0934fb0cd68f400f0bf69e19946ec596b84c06af 100755 (executable)
@@ -10,8 +10,8 @@
 # SPDX-License-Identifier: GPL-2.0
 # Arnaldo Carvalho de Melo <acme@kernel.org>, 2017
 
-. $(dirname $0)/lib/probe.sh
-. $(dirname $0)/lib/probe_vfs_getname.sh
+. "$(dirname "$0")/lib/probe.sh"
+. "$(dirname "$0")/lib/probe_vfs_getname.sh"
 
 libc=$(grep -w libc /proc/self/maps | head -1 | sed -r 's/.*[[:space:]](\/.*)/\1/g')
 nm -Dg $libc 2>/dev/null | fgrep -q inet_pton || exit 254
@@ -23,7 +23,7 @@ add_libc_inet_pton_event() {
        event_name=$(perf probe -f -x $libc -a inet_pton 2>&1 | tail -n +2 | head -n -5 | \
                        grep -P -o "$event_pattern(?=[[:space:]]\(on inet_pton in $libc\))")
 
-       if [ $? -ne 0 -o -z "$event_name" ] ; then
+       if [ $? -ne 0 ] || [ -z "$event_name" ] ; then
                printf "FAIL: could not add event\n"
                return 1
        fi
index 1341437e1bd99bbbe16243c931bb8671457a4d89..7f664f1889d9ced128d0baf354e85db979adf0f3 100755 (executable)
@@ -9,11 +9,11 @@
 # SPDX-License-Identifier: GPL-2.0
 # Arnaldo Carvalho de Melo <acme@kernel.org>, 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"
 
 record_open_file() {
        echo "Recording open file:"