1
1
#! /bin/sh
2
2
3
3
. " $( pwd) /init_env"
4
- # CPUFreq Validator: Parallel, Colorized
5
- /var/Runner/init_env
6
4
TESTNAME=" CPUFreq_Validation"
7
5
. " $TOOLS /functestlib.sh"
8
6
@@ -11,120 +9,115 @@ log_info "----------------------------------------------------------------------
11
9
log_info " -------------------Starting $TESTNAME Testcase----------------------------"
12
10
log_info " === CPUFreq Frequency Walker with Validation ==="
13
11
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"
20
18
21
19
NUM_CPUS=$( nproc)
22
- echo -e " ${YELLOW} Detected $NUM_CPUS CPU cores.${NC} "
20
+ printf " ${YELLOW} Detected %s CPU cores.${NC} \n " " $NUM_CPUS "
23
21
24
- overall_pass=true
25
- declare -A core_status
22
+ overall_pass=0
23
+ status_dir=" /tmp/cpufreq_status.$$ "
24
+ mkdir -p " $status_dir "
26
25
27
26
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 "
30
30
31
- echo -e " ${BLUE} Processing $cpu ...${NC} "
31
+ printf " ${BLUE} Processing %s ...${NC} \n " " $cpu "
32
32
33
33
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 "
36
36
return
37
37
fi
38
38
39
39
available_freqs=$( cat " $cpu /cpufreq/scaling_available_frequencies" 2> /dev/null)
40
40
41
41
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 "
44
44
return
45
45
fi
46
46
47
- # Set governor to userspace
48
47
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 "
50
49
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 "
53
52
return
54
53
fi
55
54
56
- core_status[ " $core_id " ]= " pass" # Assume pass unless a failure happens
55
+ echo " pass" > " $status_file "
57
56
58
57
for freq in $available_freqs ; do
59
58
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
61
60
sleep 0.2
62
61
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 "
65
64
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 "
68
67
fi
69
68
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 "
72
71
fi
73
72
done
74
73
75
- # Restore governor
76
74
echo " Restoring $cpu governor to 'ondemand'..."
77
75
echo " ondemand" | sudo tee " $cpu /cpufreq/scaling_governor" > /dev/null
78
76
}
79
77
80
- # Launch validation per CPU in parallel
81
78
cpu_index=0
82
79
for cpu in /sys/devices/system/cpu/cpu[0-9]* ; do
83
80
validate_cpu_core " $cpu " " $cpu_index " &
84
- (( cpu_index++ ))
81
+ cpu_index= $ (( cpu_index + 1 ))
85
82
done
86
83
87
- # Wait for all background jobs to finish
88
84
wait
89
85
90
- # Summary
91
86
log_info " "
92
87
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 " )
95
91
case " $status " in
96
92
pass)
97
- echo -e " CPU$idx : ${GREEN} [PASS]${NC} "
93
+ printf " CPU%s : ${GREEN} [PASS]${NC} \n " " $idx "
98
94
;;
99
95
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
102
98
;;
103
99
skip)
104
- echo -e " CPU$idx : ${BLUE} [SKIPPED]${NC} "
100
+ printf " CPU%s : ${BLUE} [SKIPPED]${NC} \n " " $idx "
105
101
;;
106
102
* )
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
109
105
;;
110
106
esac
111
107
done
112
108
113
- # Overall result
114
109
log_info " "
115
110
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"
120
114
echo " $TESTNAME PASS" > " $test_path /$TESTNAME .res"
115
+ rm -r " $status_dir "
121
116
exit 0
122
117
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"
126
120
echo " $TESTNAME FAIL" > " $test_path /$TESTNAME .res"
121
+ rm -r " $status_dir "
127
122
exit 1
128
- fi
129
-
130
- log_info " -------------------Completed $TESTNAME Testcase----------------------------"
123
+ fi
0 commit comments