Skip to content

Commit 50ef88b

Browse files
mwasilewvnarapar
authored andcommitted
CPU frequency changes to support sh
Made few changes for the script to work for sh. The previous change works for bash. Hence modified to work with sh Added back local variables as per review comment Signed-off-by: Vamsee Narapareddi <[email protected]>
1 parent 8eea185 commit 50ef88b

File tree

1 file changed

+48
-49
lines changed
  • Runner/suites/Kernel/FunctionalArea/baseport/CPUFreq_Validation

1 file changed

+48
-49
lines changed

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

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#!/bin/sh
55

66
. "$(pwd)/init_env"
7-
# CPUFreq Validator: Parallel, Colorized
8-
/var/Runner/init_env
97
TESTNAME="CPUFreq_Validation"
108
. "$TOOLS/functestlib.sh"
119

@@ -14,120 +12,121 @@ log_info "----------------------------------------------------------------------
1412
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
1513
log_info "=== CPUFreq Frequency Walker with Validation ==="
1614

17-
# Color codes
18-
GREEN="\e[32m"
19-
RED="\e[31m"
20-
YELLOW="\e[33m"
21-
BLUE="\e[34m"
22-
NC="\e[0m" # No Color
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"
2321

2422
NUM_CPUS=$(nproc)
25-
echo -e "${YELLOW}Detected $NUM_CPUS CPU cores.${NC}"
23+
printf "${YELLOW}Detected %s CPU cores.${NC}\n" "$NUM_CPUS"
2624

27-
overall_pass=true
28-
declare -A core_status
25+
overall_pass=0
26+
status_dir="/tmp/cpufreq_status.$$"
27+
mkdir -p "$status_dir"
2928

3029
validate_cpu_core() {
3130
local cpu=$1
3231
local core_id=$2
32+
status_file="$status_dir/core_$core_id"
3333

34-
echo -e "${BLUE}Processing $cpu...${NC}"
34+
printf "${BLUE}Processing %s...${NC}\n" "$cpu"
3535

3636
if [ ! -d "$cpu/cpufreq" ]; then
37-
echo -e "${BLUE}[SKIP]${NC} $cpu does not support cpufreq."
38-
core_status["$core_id"]="skip"
37+
printf "${BLUE}[SKIP]${NC} %s does not support cpufreq.\n" "$cpu"
38+
echo "skip" > "$status_file"
3939
return
4040
fi
4141

4242
available_freqs=$(cat "$cpu/cpufreq/scaling_available_frequencies" 2>/dev/null)
4343

4444
if [ -z "$available_freqs" ]; then
45-
echo -e "${YELLOW}[INFO]${NC} No available frequencies for $cpu. Skipping..."
46-
core_status["$core_id"]="skip"
45+
printf "${YELLOW}[INFO]${NC} No available frequencies for %s. Skipping...\n" "$cpu"
46+
echo "skip" > "$status_file"
4747
return
4848
fi
4949

50-
# Set governor to userspace
5150
if echo "userspace" | tee "$cpu/cpufreq/scaling_governor" > /dev/null; then
52-
echo -e "${YELLOW}[INFO]${NC} Set governor to userspace."
51+
printf "${YELLOW}[INFO]${NC} Set governor to userspace.\n"
5352
else
54-
echo -e "${RED}[ERROR]${NC} Cannot set userspace governor for $cpu."
55-
core_status["$core_id"]="fail"
53+
printf "${RED}[ERROR]${NC} Cannot set userspace governor for %s.\n" "$cpu"
54+
echo "fail" > "$status_file"
5655
return
5756
fi
5857

59-
core_status["$core_id"]="pass" # Assume pass unless a failure happens
58+
echo "pass" > "$status_file"
6059

6160
for freq in $available_freqs; do
6261
log_info "Setting $cpu to frequency $freq kHz..."
63-
if echo $freq | tee "$cpu/cpufreq/scaling_setspeed" > /dev/null; then
62+
if echo "$freq" | tee "$cpu/cpufreq/scaling_setspeed" > /dev/null; then
6463
sleep 0.2
6564
actual_freq=$(cat "$cpu/cpufreq/scaling_cur_freq")
66-
if [ "$actual_freq" == "$freq" ]; then
67-
echo -e "${GREEN}[PASS]${NC} $cpu set to $freq kHz."
65+
if [ "$actual_freq" = "$freq" ]; then
66+
printf "${GREEN}[PASS]${NC} %s set to %s kHz.\n" "$cpu" "$freq"
6867
else
69-
echo -e "${RED}[FAIL]${NC} Tried to set $cpu to $freq kHz, but current is $actual_freq kHz."
70-
core_status["$core_id"]="fail"
68+
printf "${RED}[FAIL]${NC} Tried to set %s to %s kHz, but current is %s kHz.\n" "$cpu" "$freq" "$actual_freq"
69+
echo "fail" > "$status_file"
7170
fi
7271
else
73-
echo -e "${RED}[ERROR]${NC} Failed to set $cpu to $freq kHz."
74-
core_status["$core_id"]="fail"
72+
printf "${RED}[ERROR]${NC} Failed to set %s to %s kHz.\n" "$cpu" "$freq"
73+
echo "fail" > "$status_file"
7574
fi
7675
done
7776

78-
# Restore governor
7977
echo "Restoring $cpu governor to 'ondemand'..."
8078
echo "ondemand" | sudo tee "$cpu/cpufreq/scaling_governor" > /dev/null
8179
}
8280

83-
# Launch validation per CPU in parallel
8481
cpu_index=0
8582
for cpu in /sys/devices/system/cpu/cpu[0-9]*; do
8683
validate_cpu_core "$cpu" "$cpu_index" &
87-
((cpu_index++))
84+
cpu_index=$((cpu_index + 1))
8885
done
8986

90-
# Wait for all background jobs to finish
9187
wait
9288

93-
# Summary
9489
log_info ""
9590
log_info "=== Per-Core Test Summary ==="
96-
for idx in "${!core_status[@]}"; do
97-
status=${core_status[$idx]}
91+
for status_file in "$status_dir"/core_*; do
92+
idx=$(basename "$status_file" | cut -d_ -f2)
93+
status=$(cat "$status_file")
9894
case "$status" in
9995
pass)
100-
echo -e "CPU$idx: ${GREEN}[PASS]${NC}"
96+
printf "CPU%s: ${GREEN}[PASS]${NC}\n" "$idx"
10197
;;
10298
fail)
103-
echo -e "CPU$idx: ${RED}[FAIL]${NC}"
104-
overall_pass=false
99+
printf "CPU%s: ${RED}[FAIL]${NC}\n" "$idx"
100+
overall_pass=1
105101
;;
106102
skip)
107-
echo -e "CPU$idx: ${BLUE}[SKIPPED]${NC}"
103+
printf "CPU%s: ${BLUE}[SKIPPED]${NC}\n" "$idx"
108104
;;
109105
*)
110-
echo -e "CPU$idx: ${RED}[UNKNOWN STATUS]${NC}"
111-
overall_pass=false
106+
printf "CPU%s: ${RED}[UNKNOWN STATUS]${NC}\n" "$idx"
107+
overall_pass=1
112108
;;
113109
esac
114110
done
115111

116-
# Overall result
117112
log_info ""
118113
log_info "=== Overall CPUFreq Validation Result ==="
119-
if $overall_pass; then
120-
echo -e "${GREEN}[OVERALL PASS]${NC} All CPUs validated successfully."
121-
log_pass "$TESTNAME : Test Passed"
122-
echo "$TESTNAME : Test Passed" > $test_path/$TESTNAME.res
114+
if [ "$overall_pass" -eq 0 ]; then
115+
printf "${GREEN}[OVERALL PASS]${NC} All CPUs validated successfully.\n"
116+
log_pass "$TESTNAME : Test Passed"
123117
echo "$TESTNAME PASS" > "$test_path/$TESTNAME.res"
118+
rm -r "$status_dir"
124119
exit 0
125120
else
126-
echo -e "${RED}[OVERALL FAIL]${NC} Some CPUs failed frequency validation."
127-
log_fail "$TESTNAME : Test Failed"
128-
echo "$TESTNAME : Test Failed" > $test_path/$TESTNAME.res
121+
printf "${RED}[OVERALL FAIL]${NC} Some CPUs failed frequency validation.\n"
122+
log_fail "$TESTNAME : Test Failed"
129123
echo "$TESTNAME FAIL" > "$test_path/$TESTNAME.res"
124+
rm -r "$status_dir"
130125
exit 1
126+
<<<<<<< HEAD
131127
fi
132128

133129
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
130+
=======
131+
fi
132+
>>>>>>> 7acac23 (CPU frequency changes to support sh)

0 commit comments

Comments
 (0)