Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tests daemon: Address shellcheck warnings

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

Result from shellcheck:
# shellcheck -S warning daemon.sh
local line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
^-------^ SC2155: Declare and assign separately to avoid masking return values.

trap "echo 'FAILED: Signal caught'; daemon_exit ${config}; exit 1" SIGINT SIGTERM
^-------^ SC2064: Use single quotes, otherwise this expands now rather than when signalled.

count=`ls ${base}/session-test/ | grep perf.data | wc -l`
^-- SC2010: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.

if [ ${size} != "OK" -o ${type} != "OK" ]; then
^-- SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.

Fixed above warnings by:
- declaring and assigning local variables separately
- To fix SC2010, instead of using "ls | grep", used glob to allow non-alphanumeric filenames
- Used single quotes to prevent expanding.

Result from shellcheck after patch changes:
$ shellcheck -S warning daemon.sh
$ echo $?
0

Signed-off-by: Shirisha G <shirisha@linux.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-5-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>

authored by

Shirisha G and committed by
Arnaldo Carvalho de Melo
5bd35dfb 1bb17b4c

+75 -38
+75 -38
tools/perf/tests/shell/daemon.sh
··· 11 11 local lock=$5 12 12 local up=$6 13 13 14 - local line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'` 15 - local line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'` 16 - local line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'` 17 - local line_lock=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'` 18 - local line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'` 14 + local line_name 15 + line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'` 16 + local line_base 17 + line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'` 18 + local line_output 19 + line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'` 20 + local line_lock 21 + line_lock=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'` 22 + local line_up 23 + line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'` 19 24 20 25 if [ "${name}" != "${line_name}" ]; then 21 26 echo "FAILED: wrong name" ··· 59 54 local ack=$7 60 55 local up=$8 61 56 62 - local line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'` 63 - local line_run=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'` 64 - local line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'` 65 - local line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'` 66 - local line_control=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'` 67 - local line_ack=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $7 }'` 68 - local line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $8 }'` 57 + local line_name 58 + line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'` 59 + local line_run 60 + line_run=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $3 }'` 61 + local line_base 62 + line_base=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $4 }'` 63 + local line_output 64 + line_output=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $5 }'` 65 + local line_control 66 + line_control=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $6 }'` 67 + local line_ack 68 + line_ack=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $7 }'` 69 + local line_up 70 + line_up=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $8 }'` 69 71 70 72 if [ "${name}" != "${line_name}" ]; then 71 73 echo "FAILED: wrong name" ··· 114 102 { 115 103 local config=$1 116 104 117 - local line=`perf daemon --config ${config} -x: | head -1` 118 - local pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'` 105 + local line 106 + line=`perf daemon --config ${config} -x: | head -1` 107 + local pid 108 + pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'` 119 109 120 110 # Reset trap handler. 121 111 trap - SIGINT SIGTERM ··· 137 123 perf daemon start --config ${config} 138 124 139 125 # Clean up daemon if interrupted. 140 - trap "echo 'FAILED: Signal caught'; daemon_exit ${config}; exit 1" SIGINT SIGTERM 126 + trap 'echo "FAILED: Signal caught"; daemon_exit "${config}"; exit 1' SIGINT SIGTERM 141 127 142 128 # wait for the session to ping 143 129 local state="FAIL" ··· 158 144 { 159 145 echo "test daemon list" 160 146 161 - local config=$(mktemp /tmp/perf.daemon.config.XXX) 162 - local base=$(mktemp -d /tmp/perf.daemon.base.XXX) 147 + local config 148 + config=$(mktemp /tmp/perf.daemon.config.XXX) 149 + local base 150 + base=$(mktemp -d /tmp/perf.daemon.base.XXX) 163 151 164 152 cat <<EOF > ${config} 165 153 [daemon] ··· 181 165 182 166 # check first line 183 167 # pid:daemon:base:base/output:base/lock 184 - local line=`perf daemon --config ${config} -x: | head -1` 168 + local line 169 + line=`perf daemon --config ${config} -x: | head -1` 185 170 check_line_first ${line} daemon ${base} ${base}/output ${base}/lock "0" 186 171 187 172 # check 1st session 188 173 # pid:size:-e cpu-clock:base/size:base/size/output:base/size/control:base/size/ack:0 189 - local line=`perf daemon --config ${config} -x: | head -2 | tail -1` 174 + local line 175 + line=`perf daemon --config ${config} -x: | head -2 | tail -1` 190 176 check_line_other "${line}" size "-e cpu-clock -m 1 sleep 10" ${base}/session-size \ 191 177 ${base}/session-size/output ${base}/session-size/control \ 192 178 ${base}/session-size/ack "0" 193 179 194 180 # check 2nd session 195 181 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0 196 - local line=`perf daemon --config ${config} -x: | head -3 | tail -1` 182 + local line 183 + line=`perf daemon --config ${config} -x: | head -3 | tail -1` 197 184 check_line_other "${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \ 198 185 ${base}/session-time/output ${base}/session-time/control \ 199 186 ${base}/session-time/ack "0" ··· 212 193 { 213 194 echo "test daemon reconfig" 214 195 215 - local config=$(mktemp /tmp/perf.daemon.config.XXX) 216 - local base=$(mktemp -d /tmp/perf.daemon.base.XXX) 196 + local config 197 + config=$(mktemp /tmp/perf.daemon.config.XXX) 198 + local base 199 + base=$(mktemp -d /tmp/perf.daemon.base.XXX) 217 200 218 201 # prepare config 219 202 cat <<EOF > ${config} ··· 236 215 237 216 # check 2nd session 238 217 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0 239 - local line=`perf daemon --config ${config} -x: | head -3 | tail -1` 218 + local line 219 + line=`perf daemon --config ${config} -x: | head -3 | tail -1` 240 220 check_line_other "${line}" time "-e task-clock -m 1 sleep 10" ${base}/session-time \ 241 221 ${base}/session-time/output ${base}/session-time/control ${base}/session-time/ack "0" 242 - local pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'` 222 + local pid 223 + pid=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $1 }'` 243 224 244 225 # prepare new config 245 226 local config_new=${config}.new ··· 272 249 273 250 # check reconfigured 2nd session 274 251 # pid:time:-e task-clock:base/time:base/time/output:base/time/control:base/time/ack:0 275 - local line=`perf daemon --config ${config} -x: | head -3 | tail -1` 252 + local line 253 + line=`perf daemon --config ${config} -x: | head -3 | tail -1` 276 254 check_line_other "${line}" time "-e cpu-clock -m 1 sleep 10" ${base}/session-time \ 277 255 ${base}/session-time/output ${base}/session-time/control ${base}/session-time/ack "0" 278 256 ··· 300 276 state=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'` 301 277 done 302 278 303 - local one=`perf daemon --config ${config} -x: | wc -l` 279 + local one 280 + one=`perf daemon --config ${config} -x: | wc -l` 304 281 305 282 if [ ${one} -ne "1" ]; then 306 283 echo "FAILED: wrong list output" ··· 337 312 { 338 313 echo "test daemon stop" 339 314 340 - local config=$(mktemp /tmp/perf.daemon.config.XXX) 341 - local base=$(mktemp -d /tmp/perf.daemon.base.XXX) 315 + local config 316 + config=$(mktemp /tmp/perf.daemon.config.XXX) 317 + local base 318 + base=$(mktemp -d /tmp/perf.daemon.base.XXX) 342 319 343 320 # prepare config 344 321 cat <<EOF > ${config} ··· 359 332 # start daemon 360 333 daemon_start ${config} size 361 334 362 - local pid_size=`perf daemon --config ${config} -x: | head -2 | tail -1 | awk 'BEGIN { FS = ":" } ; { print $1 }'` 363 - local pid_time=`perf daemon --config ${config} -x: | head -3 | tail -1 | awk 'BEGIN { FS = ":" } ; { print $1 }'` 335 + local pid_size 336 + pid_size=`perf daemon --config ${config} -x: | head -2 | tail -1 | 337 + awk 'BEGIN { FS = ":" } ; { print $1 }'` 338 + local pid_time 339 + pid_time=`perf daemon --config ${config} -x: | head -3 | tail -1 | 340 + awk 'BEGIN { FS = ":" } ; { print $1 }'` 364 341 365 342 # check that sessions are running 366 343 if [ ! -d "/proc/${pid_size}" ]; then ··· 395 364 { 396 365 echo "test daemon signal" 397 366 398 - local config=$(mktemp /tmp/perf.daemon.config.XXX) 399 - local base=$(mktemp -d /tmp/perf.daemon.base.XXX) 367 + local config 368 + config=$(mktemp /tmp/perf.daemon.config.XXX) 369 + local base 370 + base=$(mktemp -d /tmp/perf.daemon.base.XXX) 400 371 401 372 # prepare config 402 373 cat <<EOF > ${config} ··· 422 389 daemon_exit ${config} 423 390 424 391 # count is 2 perf.data for signals and 1 for perf record finished 425 - count=`ls ${base}/session-test/ | grep perf.data | wc -l` 392 + count=`ls ${base}/session-test/*perf.data* | wc -l` 426 393 if [ ${count} -ne 3 ]; then 427 394 error=1 428 395 echo "FAILED: perf data no generated" ··· 436 403 { 437 404 echo "test daemon ping" 438 405 439 - local config=$(mktemp /tmp/perf.daemon.config.XXX) 440 - local base=$(mktemp -d /tmp/perf.daemon.base.XXX) 406 + local config 407 + config=$(mktemp /tmp/perf.daemon.config.XXX) 408 + local base 409 + base=$(mktemp -d /tmp/perf.daemon.base.XXX) 441 410 442 411 # prepare config 443 412 cat <<EOF > ${config} ··· 461 426 size=`perf daemon ping --config ${config} --session size | awk '{ print $1 }'` 462 427 type=`perf daemon ping --config ${config} --session time | awk '{ print $1 }'` 463 428 464 - if [ ${size} != "OK" -o ${type} != "OK" ]; then 429 + if [ ${size} != "OK" ] || [ ${type} != "OK" ]; then 465 430 error=1 466 431 echo "FAILED: daemon ping failed" 467 432 fi ··· 477 442 { 478 443 echo "test daemon lock" 479 444 480 - local config=$(mktemp /tmp/perf.daemon.config.XXX) 481 - local base=$(mktemp -d /tmp/perf.daemon.base.XXX) 445 + local config 446 + config=$(mktemp /tmp/perf.daemon.config.XXX) 447 + local base 448 + base=$(mktemp -d /tmp/perf.daemon.base.XXX) 482 449 483 450 # prepare config 484 451 cat <<EOF > ${config}