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