Skip to content

Commit 5c24a4f

Browse files
committed
CPU frequency changes to support sh
1 parent b487d7c commit 5c24a4f

File tree

1 file changed

+47
-54
lines changed
  • Runner/suites/Kernel/FunctionalArea/baseport/CPUFreq_Validation

1 file changed

+47
-54
lines changed
Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/bin/sh
22

33
. "$(pwd)/init_env"
4-
# CPUFreq Validator: Parallel, Colorized
5-
/var/Runner/init_env
64
TESTNAME="CPUFreq_Validation"
75
. "$TOOLS/functestlib.sh"
86

@@ -11,120 +9,115 @@ log_info "----------------------------------------------------------------------
119
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
1210
log_info "=== CPUFreq Frequency Walker with Validation ==="
1311

14-
# Color codes
15-
GREEN="\e[32m"
16-
RED="\e[31m"
17-
YELLOW="\e[33m"
18-
BLUE="\e[34m"
19-
NC="\e[0m" # No Color
12+
# Color codes (ANSI escape sequences)
13+
GREEN="\033[32m"
14+
RED="\033[31m"
15+
YELLOW="\033[33m"
16+
BLUE="\033[34m"
17+
NC="\033[0m"
2018

2119
NUM_CPUS=$(nproc)
22-
echo -e "${YELLOW}Detected $NUM_CPUS CPU cores.${NC}"
20+
printf "${YELLOW}Detected %s CPU cores.${NC}\n" "$NUM_CPUS"
2321

24-
overall_pass=true
25-
declare -A core_status
22+
overall_pass=0
23+
status_dir="/tmp/cpufreq_status.$$"
24+
mkdir -p "$status_dir"
2625

2726
validate_cpu_core() {
28-
local cpu=$1
29-
local core_id=$2
27+
cpu=$1
28+
core_id=$2
29+
status_file="$status_dir/core_$core_id"
3030

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

3333
if [ ! -d "$cpu/cpufreq" ]; then
34-
echo -e "${BLUE}[SKIP]${NC} $cpu does not support cpufreq."
35-
core_status["$core_id"]="skip"
34+
printf "${BLUE}[SKIP]${NC} %s does not support cpufreq.\n" "$cpu"
35+
echo "skip" > "$status_file"
3636
return
3737
fi
3838

3939
available_freqs=$(cat "$cpu/cpufreq/scaling_available_frequencies" 2>/dev/null)
4040

4141
if [ -z "$available_freqs" ]; then
42-
echo -e "${YELLOW}[INFO]${NC} No available frequencies for $cpu. Skipping..."
43-
core_status["$core_id"]="skip"
42+
printf "${YELLOW}[INFO]${NC} No available frequencies for %s. Skipping...\n" "$cpu"
43+
echo "skip" > "$status_file"
4444
return
4545
fi
4646

47-
# Set governor to userspace
4847
if echo "userspace" | tee "$cpu/cpufreq/scaling_governor" > /dev/null; then
49-
echo -e "${YELLOW}[INFO]${NC} Set governor to userspace."
48+
printf "${YELLOW}[INFO]${NC} Set governor to userspace.\n"
5049
else
51-
echo -e "${RED}[ERROR]${NC} Cannot set userspace governor for $cpu."
52-
core_status["$core_id"]="fail"
50+
printf "${RED}[ERROR]${NC} Cannot set userspace governor for %s.\n" "$cpu"
51+
echo "fail" > "$status_file"
5352
return
5453
fi
5554

56-
core_status["$core_id"]="pass" # Assume pass unless a failure happens
55+
echo "pass" > "$status_file"
5756

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

75-
# Restore governor
7674
echo "Restoring $cpu governor to 'ondemand'..."
7775
echo "ondemand" | sudo tee "$cpu/cpufreq/scaling_governor" > /dev/null
7876
}
7977

80-
# Launch validation per CPU in parallel
8178
cpu_index=0
8279
for cpu in /sys/devices/system/cpu/cpu[0-9]*; do
8380
validate_cpu_core "$cpu" "$cpu_index" &
84-
((cpu_index++))
81+
cpu_index=$((cpu_index + 1))
8582
done
8683

87-
# Wait for all background jobs to finish
8884
wait
8985

90-
# Summary
9186
log_info ""
9287
log_info "=== Per-Core Test Summary ==="
93-
for idx in "${!core_status[@]}"; do
94-
status=${core_status[$idx]}
88+
for status_file in "$status_dir"/core_*; do
89+
idx=$(basename "$status_file" | cut -d_ -f2)
90+
status=$(cat "$status_file")
9591
case "$status" in
9692
pass)
97-
echo -e "CPU$idx: ${GREEN}[PASS]${NC}"
93+
printf "CPU%s: ${GREEN}[PASS]${NC}\n" "$idx"
9894
;;
9995
fail)
100-
echo -e "CPU$idx: ${RED}[FAIL]${NC}"
101-
overall_pass=false
96+
printf "CPU%s: ${RED}[FAIL]${NC}\n" "$idx"
97+
overall_pass=1
10298
;;
10399
skip)
104-
echo -e "CPU$idx: ${BLUE}[SKIPPED]${NC}"
100+
printf "CPU%s: ${BLUE}[SKIPPED]${NC}\n" "$idx"
105101
;;
106102
*)
107-
echo -e "CPU$idx: ${RED}[UNKNOWN STATUS]${NC}"
108-
overall_pass=false
103+
printf "CPU%s: ${RED}[UNKNOWN STATUS]${NC}\n" "$idx"
104+
overall_pass=1
109105
;;
110106
esac
111107
done
112108

113-
# Overall result
114109
log_info ""
115110
log_info "=== Overall CPUFreq Validation Result ==="
116-
if $overall_pass; then
117-
echo -e "${GREEN}[OVERALL PASS]${NC} All CPUs validated successfully."
118-
log_pass "$TESTNAME : Test Passed"
119-
echo "$TESTNAME : Test Passed" > $test_path/$TESTNAME.res
111+
if [ "$overall_pass" -eq 0 ]; then
112+
printf "${GREEN}[OVERALL PASS]${NC} All CPUs validated successfully.\n"
113+
log_pass "$TESTNAME : Test Passed"
120114
echo "$TESTNAME PASS" > "$test_path/$TESTNAME.res"
115+
rm -r "$status_dir"
121116
exit 0
122117
else
123-
echo -e "${RED}[OVERALL FAIL]${NC} Some CPUs failed frequency validation."
124-
log_fail "$TESTNAME : Test Failed"
125-
echo "$TESTNAME : Test Failed" > $test_path/$TESTNAME.res
118+
printf "${RED}[OVERALL FAIL]${NC} Some CPUs failed frequency validation.\n"
119+
log_fail "$TESTNAME : Test Failed"
126120
echo "$TESTNAME FAIL" > "$test_path/$TESTNAME.res"
121+
rm -r "$status_dir"
127122
exit 1
128-
fi
129-
130-
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
123+
fi

0 commit comments

Comments
 (0)