Skip to content

Commit b7f0a50

Browse files
committed
run.sh: add robust path resolution for testkit compatibility
- Updated all run.sh scripts to dynamically locate testkit root using utils/ and suites/ markers - Replaced hardcoded relative paths with SCRIPT_DIR and ROOT_DIR detection logic - Ensures consistent behavior across local, CI, and target environments - Retains compatibility with functestlib.sh and init_env Signed-off-by: Srikanth Muppandam <[email protected]>
1 parent a046ab3 commit b7f0a50

File tree

30 files changed

+1077
-278
lines changed

30 files changed

+1077
-278
lines changed

Runner/suites/Kernel/FunctionalArea/baseport/BWMON/run.sh

100755100644
Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,41 @@
33
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
44
# SPDX-License-Identifier: BSD-3-Clause-Clear
55

6-
# Import test suite definitions
7-
. "${PWD}"/init_env
8-
TESTNAME="BWMON"
6+
# Robustly find and source init_env
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
INIT_ENV=""
9+
SEARCH="$SCRIPT_DIR"
10+
while [ "$SEARCH" != "/" ]; do
11+
if [ -f "$SEARCH/init_env" ]; then
12+
INIT_ENV="$SEARCH/init_env"
13+
break
14+
fi
15+
SEARCH=$(dirname "$SEARCH")
16+
done
17+
18+
if [ -z "$INIT_ENV" ]; then
19+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
20+
exit 1
21+
fi
922

10-
#import test functions library
11-
. "${TOOLS}"/functestlib.sh
23+
# Only source if not already loaded (idempotent)
24+
if [ -z "$__INIT_ENV_LOADED" ]; then
25+
# shellcheck disable=SC1090
26+
. "$INIT_ENV"
27+
fi
28+
# Always source functestlib.sh, using $TOOLS exported by init_env
29+
# shellcheck disable=SC1090,SC1091
30+
. "$TOOLS/functestlib.sh"
31+
32+
TESTNAME="BWMON"
1233
test_path=$(find_test_case_by_name "$TESTNAME")
13-
log_info "--------------------------------------------------------------------------"
34+
cd "$test_path" || exit 1
35+
# shellcheck disable=SC2034
36+
res_file="./$TESTNAME.res"
37+
38+
log_info "-----------------------------------------------------------------------------------------"
1439
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
40+
log_info "=== Test Initialization ==="
1541

1642
log_info "Checking if dependency binary is available"
1743
check_dependencies bw_mem
@@ -56,9 +82,9 @@ done
5682

5783
if $incremented; then
5884
log_pass "$TESTNAME : Test Passed"
59-
echo "$TESTNAME PASS" > $test_path/$TESTNAME.res
85+
echo "$TESTNAME PASS" > "$res_file"
6086
else
6187
log_fail "$TESTNAME : Test Failed"
62-
echo "$TESTNAME FAIL" > $test_path/$TESTNAME.res
88+
echo "$TESTNAME FAIL" > "$res_file"
6389
fi
6490
log_info "-------------------Completed $TESTNAME Testcase----------------------------"

Runner/suites/Kernel/FunctionalArea/baseport/Buses/run.sh

100755100644
Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,53 @@
22

33
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
44
# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
# Robustly find and source init_env
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
INIT_ENV=""
8+
SEARCH="$SCRIPT_DIR"
9+
while [ "$SEARCH" != "/" ]; do
10+
if [ -f "$SEARCH/init_env" ]; then
11+
INIT_ENV="$SEARCH/init_env"
12+
break
13+
fi
14+
SEARCH=$(dirname "$SEARCH")
15+
done
516

6-
# Import test suite definitions
7-
. "${PWD}"/init_env
8-
TESTNAME="Buses"
17+
if [ -z "$INIT_ENV" ]; then
18+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
19+
exit 1
20+
fi
21+
22+
# Only source if not already loaded (idempotent)
23+
if [ -z "$__INIT_ENV_LOADED" ]; then
24+
# shellcheck disable=SC1090
25+
. "$INIT_ENV"
26+
fi
27+
# Always source functestlib.sh, using $TOOLS exported by init_env
28+
# shellcheck disable=SC1090,SC1091
29+
. "$TOOLS/functestlib.sh"
930

10-
#import test functions library
11-
. "${TOOLS}"/functestlib.sh
31+
TESTNAME="Buses"
1232
test_path=$(find_test_case_by_name "$TESTNAME")
33+
cd "$test_path" || exit 1
34+
# shellcheck disable=SC2034
35+
res_file="./$TESTNAME.res"
36+
1337
log_info "-----------------------------------------------------------------------------------------"
1438
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
39+
log_info "=== Test Initialization ==="
1540

1641
log_info "Checking if dependency binary is available"
1742
check_dependencies i2c-msm-test
1843

1944
log_info "running i2c binary"
2045
output=$(i2c-msm-test -v -D /dev/i2c-0 -l | grep "ret:1")
2146

22-
2347
if echo "$output" | grep -q "Reading"; then
2448
log_pass "$TESTNAME : Test Passed"
25-
echo "$TESTNAME PASS" > $test_path/$TESTNAME.res
49+
echo "$TESTNAME PASS" > "$res_file"
2650
else
2751
log_fail "$TESTNAME : Test Failed"
28-
echo "$TESTNAME FAIL" > $test_path/$TESTNAME.res
52+
echo "$TESTNAME FAIL" > "$res_file"
2953
fi
3054
log_info "-------------------Completed $TESTNAME Testcase----------------------------"

Runner/suites/Kernel/FunctionalArea/baseport/CPUFreq_Validation/run.sh

100755100644
Lines changed: 98 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,86 @@
33
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
44
# SPDX-License-Identifier: BSD-3-Clause-Clear
55

6-
. "${PWD}/init_env"
7-
TESTNAME="CPUFreq_Validation"
6+
# Robustly find and source init_env
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
INIT_ENV=""
9+
SEARCH="$SCRIPT_DIR"
10+
while [ "$SEARCH" != "/" ]; do
11+
if [ -f "$SEARCH/init_env" ]; then
12+
INIT_ENV="$SEARCH/init_env"
13+
break
14+
fi
15+
SEARCH=$(dirname "$SEARCH")
16+
done
17+
18+
if [ -z "$INIT_ENV" ]; then
19+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
20+
exit 1
21+
fi
22+
23+
# Only source if not already loaded (idempotent)
24+
if [ -z "$__INIT_ENV_LOADED" ]; then
25+
# shellcheck disable=SC1090
26+
. "$INIT_ENV"
27+
fi
28+
# Always source functestlib.sh, using $TOOLS exported by init_env
29+
# shellcheck disable=SC1090,SC1091
830
. "$TOOLS/functestlib.sh"
931

32+
TESTNAME="CPUFreq_Validation"
1033
test_path=$(find_test_case_by_name "$TESTNAME")
34+
cd "$test_path" || exit 1
35+
# shellcheck disable=SC2034
36+
res_file="./$TESTNAME.res"
37+
1138
log_info "-----------------------------------------------------------------------------------------"
1239
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
13-
log_info "=== CPUFreq Frequency Walker with Validation ==="
14-
15-
# Color codes (ANSI escape sequences)
16-
GREEN="\033[32m"
17-
RED="\033[31m"
18-
YELLOW="\033[33m"
19-
BLUE="\033[34m"
20-
NC="\033[0m"
40+
log_info "=== CPUFreq Frequency Walker with Retry and Cleanup ==="
2141

2242
NUM_CPUS=$(nproc)
23-
printf "${YELLOW}Detected %s CPU cores.${NC}\n" "$NUM_CPUS"
43+
log_info "Detected $NUM_CPUS CPU cores."
2444

2545
overall_pass=0
2646
status_dir="/tmp/cpufreq_status.$$"
2747
mkdir -p "$status_dir"
2848

2949
validate_cpu_core() {
30-
local cpu=$1
31-
local core_id=$2
32-
status_file="$status_dir/core_$core_id"
50+
local cpu="$1"
51+
local core_id="$2"
52+
local status_file="$status_dir/core_$core_id"
53+
echo "unknown" > "$status_file"
3354

34-
printf "${BLUE}Processing %s...${NC}\n" "$cpu"
55+
log_info "Processing $cpu..."
56+
57+
local cpu_num
58+
cpu_num=$(basename "$cpu" | tr -dc '0-9')
59+
if [ -f "/sys/devices/system/cpu/cpu$cpu_num/online" ]; then
60+
echo 1 > "/sys/devices/system/cpu/cpu$cpu_num/online"
61+
fi
3562

3663
if [ ! -d "$cpu/cpufreq" ]; then
37-
printf "${BLUE}[SKIP]${NC} %s does not support cpufreq.\n" "$cpu"
64+
log_info "[SKIP] $cpu does not support cpufreq."
3865
echo "skip" > "$status_file"
3966
return
4067
fi
4168

42-
available_freqs=$(cat "$cpu/cpufreq/scaling_available_frequencies" 2>/dev/null)
43-
69+
local freqs_file="$cpu/cpufreq/scaling_available_frequencies"
70+
read -r available_freqs < "$freqs_file" 2>/dev/null
4471
if [ -z "$available_freqs" ]; then
45-
printf "${YELLOW}[INFO]${NC} No available frequencies for %s. Skipping...\n" "$cpu"
72+
log_info "[SKIP] No available frequencies for $cpu"
4673
echo "skip" > "$status_file"
4774
return
4875
fi
4976

50-
if echo "userspace" | tee "$cpu/cpufreq/scaling_governor" > /dev/null; then
51-
printf "${YELLOW}[INFO]${NC} Set governor to userspace.\n"
77+
local original_governor
78+
original_governor=$(cat "$cpu/cpufreq/scaling_governor" 2>/dev/null)
79+
80+
if echo "userspace" > "$cpu/cpufreq/scaling_governor"; then
81+
log_info "[INFO] Set governor to userspace."
82+
sync
83+
sleep 0.5
5284
else
53-
printf "${RED}[ERROR]${NC} Cannot set userspace governor for %s.\n" "$cpu"
85+
log_error "Cannot set userspace governor for $cpu."
5486
echo "fail" > "$status_file"
5587
return
5688
fi
@@ -59,23 +91,46 @@ validate_cpu_core() {
5991

6092
for freq in $available_freqs; do
6193
log_info "Setting $cpu to frequency $freq kHz..."
62-
if echo "$freq" | tee "$cpu/cpufreq/scaling_setspeed" > /dev/null; then
94+
95+
echo "$freq" > "$cpu/cpufreq/scaling_min_freq" 2>/dev/null
96+
echo "$freq" > "$cpu/cpufreq/scaling_max_freq" 2>/dev/null
97+
98+
if ! echo "$freq" > "$cpu/cpufreq/scaling_setspeed" 2>/dev/null; then
99+
log_error "[SKIP] Kernel rejected freq $freq for $cpu"
100+
continue
101+
fi
102+
103+
retry=0
104+
success=0
105+
while [ "$retry" -lt 5 ]; do
106+
cur=$(cat "$cpu/cpufreq/scaling_cur_freq")
107+
if [ "$cur" = "$freq" ]; then
108+
log_info "[PASS] $cpu set to $freq kHz."
109+
success=1
110+
break
111+
fi
63112
sleep 0.2
64-
actual_freq=$(cat "$cpu/cpufreq/scaling_cur_freq")
65-
if [ "$actual_freq" = "$freq" ]; then
66-
printf "${GREEN}[PASS]${NC} %s set to %s kHz.\n" "$cpu" "$freq"
113+
retry=$((retry + 1))
114+
done
115+
116+
if [ "$success" -eq 0 ]; then
117+
log_info "[RETRY] Re-attempting to set $cpu to $freq kHz..."
118+
echo "$freq" > "$cpu/cpufreq/scaling_setspeed"
119+
sleep 0.3
120+
cur=$(cat "$cpu/cpufreq/scaling_cur_freq")
121+
if [ "$cur" = "$freq" ]; then
122+
log_info "[PASS-after-retry] $cpu set to $freq kHz."
67123
else
68-
printf "${RED}[FAIL]${NC} Tried to set %s to %s kHz, but current is %s kHz.\n" "$cpu" "$freq" "$actual_freq"
124+
log_error "[FAIL] $cpu failed to set $freq kHz twice. Current: $cur"
69125
echo "fail" > "$status_file"
70126
fi
71-
else
72-
printf "${RED}[ERROR]${NC} Failed to set %s to %s kHz.\n" "$cpu" "$freq"
73-
echo "fail" > "$status_file"
74127
fi
75128
done
76129

77-
echo "Restoring $cpu governor to 'ondemand'..."
78-
echo "ondemand" | sudo tee "$cpu/cpufreq/scaling_governor" > /dev/null
130+
log_info "Restoring $cpu governor to '$original_governor'..."
131+
echo "$original_governor" > "$cpu/cpufreq/scaling_governor"
132+
echo 0 > "$cpu/cpufreq/scaling_min_freq" 2>/dev/null
133+
echo 0 > "$cpu/cpufreq/scaling_max_freq" 2>/dev/null
79134
}
80135

81136
cpu_index=0
@@ -93,36 +148,34 @@ for status_file in "$status_dir"/core_*; do
93148
status=$(cat "$status_file")
94149
case "$status" in
95150
pass)
96-
printf "CPU%s: ${GREEN}[PASS]${NC}\n" "$idx"
151+
log_info "CPU$idx: [PASS]"
97152
;;
98153
fail)
99-
printf "CPU%s: ${RED}[FAIL]${NC}\n" "$idx"
154+
log_error "CPU$idx: [FAIL]"
100155
overall_pass=1
101156
;;
102157
skip)
103-
printf "CPU%s: ${BLUE}[SKIPPED]${NC}\n" "$idx"
158+
log_info "CPU$idx: [SKIPPED]"
104159
;;
105160
*)
106-
printf "CPU%s: ${RED}[UNKNOWN STATUS]${NC}\n" "$idx"
161+
log_error "CPU$idx: [UNKNOWN STATUS]"
107162
overall_pass=1
108163
;;
109164
esac
110165
done
111166

112167
log_info ""
113168
log_info "=== Overall CPUFreq Validation Result ==="
169+
114170
if [ "$overall_pass" -eq 0 ]; then
115-
printf "${GREEN}[OVERALL PASS]${NC} All CPUs validated successfully.\n"
116171
log_pass "$TESTNAME : Test Passed"
117-
echo "$TESTNAME PASS" > "$test_path/$TESTNAME.res"
118-
rm -r "$status_dir"
119-
exit 0
172+
echo "$TESTNAME PASS" > "$res_file"
120173
else
121-
printf "${RED}[OVERALL FAIL]${NC} Some CPUs failed frequency validation.\n"
122174
log_fail "$TESTNAME : Test Failed"
123-
echo "$TESTNAME FAIL" > "$test_path/$TESTNAME.res"
124-
rm -r "$status_dir"
125-
exit 1
175+
echo "$TESTNAME FAIL" > "$res_file"
126176
fi
127177

128-
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
178+
rm -r "$status_dir"
179+
sync
180+
sleep 1
181+
exit "$overall_pass"

0 commit comments

Comments
 (0)