Skip to content

Commit b97dad6

Browse files
committed
shellcheck: fix cleanup and quoting in CPU_affinity runner
Update Runner/suites/Kernel/Scheduler/CPU_affinity/run.sh to: - clean up the background task through an exit trap - quote TASK_PID in taskset and chrt calls - remove unreachable trailing lines after the final PASS/FAIL exit path This preserves the intended task cleanup behavior while addressing ShellCheck SC2086 and SC2317 findings. Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
1 parent e2005a1 commit b97dad6

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

  • Runner/suites/Kernel/Scheduler/CPU_affinity

Runner/suites/Kernel/Scheduler/CPU_affinity/run.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ cd "$test_path" || exit 1
3333
# shellcheck disable=SC2034
3434
res_file="./$TESTNAME.res"
3535

36+
TASK_PID=""
37+
trap '[ -n "${TASK_PID:-}" ] && kill "$TASK_PID" 2>/dev/null || true' EXIT INT TERM
38+
3639
log_info "----------------------------------------------------"
3740
log_info "-------- Starting $TESTNAME Functional Test --------"
3841

@@ -59,14 +62,14 @@ TASK_PID=$!
5962
sleep 2
6063

6164
log_info "Checking CPU affinity of task $TASK_PID..."
62-
CPU_AFFINITY=$(taskset -p $TASK_PID | awk -F: '{print $2}' | xargs)
65+
CPU_AFFINITY=$(taskset -p "$TASK_PID" | awk -F: '{print $2}' | xargs)
6366
log_info "CPU affinity: $CPU_AFFINITY"
6467

6568
log_info "Setting affinity to CPU 0"
66-
taskset -pc 0 $TASK_PID > /dev/null
69+
taskset -pc 0 "$TASK_PID" > /dev/null
6770
sleep 1
6871

69-
NEW_AFFINITY=$(taskset -p $TASK_PID | awk -F: '{print $2}' | xargs)
72+
NEW_AFFINITY=$(taskset -p "$TASK_PID" | awk -F: '{print $2}' | xargs)
7073
if [ "$NEW_AFFINITY" = "1" ]; then
7174
log_pass "Successfully set CPU affinity"
7275
echo "$TESTNAME PASS" > "$res_file"
@@ -76,7 +79,7 @@ else
7679
fi
7780

7881
log_info "Checking scheduling policy of task..."
79-
SCHED_POLICY=$(chrt -p $TASK_PID | grep "scheduling policy" | awk -F: '{print $2}' | xargs)
82+
SCHED_POLICY=$(chrt -p "$TASK_PID" | grep "scheduling policy" | awk -F: '{print $2}' | xargs)
8083
log_info "Scheduling Policy: $SCHED_POLICY"
8184

8285
if echo "$SCHED_POLICY" | grep -q "SCHED_OTHER"; then
@@ -88,7 +91,3 @@ else
8891
echo "$TESTNAME FAIL" > "$res_file"
8992
exit 1
9093
fi
91-
92-
kill $TASK_PID
93-
echo "$TESTNAME PASS" > $test_path/$TESTNAME.res
94-
log_info "-------- Completed $TESTNAME Functional Test --------"

0 commit comments

Comments
 (0)