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"
8- . " $TOOLS /functestlib.sh"
6+ # Dynamically find the testkit root by walking up from script dir
7+ SCRIPT_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
8+ ROOT_DIR=" $SCRIPT_DIR "
9+
10+ while [ " $ROOT_DIR " != " /" ]; do
11+ if [ -d " $ROOT_DIR /utils" ] && [ -d " $ROOT_DIR /suites" ]; then
12+ break
13+ fi
14+ ROOT_DIR=$( dirname " $ROOT_DIR " )
15+ done
16+
17+ # Validate root detection
18+ if [ ! -d " $ROOT_DIR /utils" ] || [ ! -f " $ROOT_DIR /utils/functestlib.sh" ]; then
19+ echo " [ERROR] Could not detect testkit root (missing utils/ or functestlib.sh)" >&2
20+ exit 1
21+ fi
22+
23+ TOOLS=" $ROOT_DIR /utils"
24+ INIT_ENV=" $ROOT_DIR /init_env"
25+ FUNCLIB=" $TOOLS /functestlib.sh"
926
27+ # Source init_env if exists
28+ [ -f " $INIT_ENV " ] && . " $INIT_ENV "
29+
30+ # Source functestlib.sh
31+ . " $FUNCLIB "
32+
33+ # Export fallback for manual ./run.sh usage
34+ __RUNNER_SUITES_DIR=" ${__RUNNER_SUITES_DIR:- $ROOT_DIR / suites} "
35+
36+ cd " $ROOT_DIR " || exit 1
37+
38+ TESTNAME=" CPUFreq_Validation"
1039test_path=$( find_test_case_by_name " $TESTNAME " )
40+
1141log_info " -----------------------------------------------------------------------------------------"
1242log_info " -------------------Starting $TESTNAME Testcase----------------------------"
1343log_info " === CPUFreq Frequency Walker with Validation ==="
1444
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"
21-
2245NUM_CPUS=$( nproc)
23- printf " ${YELLOW} Detected %s CPU cores.${NC} \n " " $NUM_CPUS "
46+ log_info " Detected $NUM_CPUS CPU cores."
2447
2548overall_pass=0
2649status_dir=" /tmp/cpufreq_status.$$ "
2750mkdir -p " $status_dir "
2851
2952validate_cpu_core () {
30- local cpu=$1
31- local core_id=$2
53+ local cpu=" $1 "
54+ local core_id=" $2 "
3255 status_file=" $status_dir /core_$core_id "
3356
34- printf " ${BLUE} Processing %s ...${NC} \n " " $cpu "
57+ log_info " Processing $cpu ..."
3558
3659 if [ ! -d " $cpu /cpufreq" ]; then
37- printf " ${BLUE} [SKIP]${NC} %s does not support cpufreq.\n " " $cpu "
60+ log_info " [SKIP] $cpu does not support cpufreq."
3861 echo " skip" > " $status_file "
3962 return
4063 fi
4164
4265 available_freqs=$( cat " $cpu /cpufreq/scaling_available_frequencies" 2> /dev/null)
4366
4467 if [ -z " $available_freqs " ]; then
45- printf " ${YELLOW} [INFO]${NC} No available frequencies for %s . Skipping...\n " " $cpu "
68+ log_info " [INFO] No available frequencies for $cpu . Skipping..."
4669 echo " skip" > " $status_file "
4770 return
4871 fi
4972
50- if echo " userspace" | tee " $cpu /cpufreq/scaling_governor" > /dev/null ; then
51- printf " ${YELLOW} [INFO]${NC} Set governor to userspace.\n "
73+ if echo " userspace" > " $cpu /cpufreq/scaling_governor" ; then
74+ log_info " [INFO] Set governor to userspace."
5275 else
53- printf " ${RED} [ERROR] ${NC} Cannot set userspace governor for %s.\n " " $cpu "
76+ log_error " Cannot set userspace governor for $cpu . "
5477 echo " fail" > " $status_file "
5578 return
5679 fi
@@ -59,23 +82,23 @@ validate_cpu_core() {
5982
6083 for freq in $available_freqs ; do
6184 log_info " Setting $cpu to frequency $freq kHz..."
62- if echo " $freq " | tee " $cpu /cpufreq/scaling_setspeed" > /dev/null ; then
85+ if echo " $freq " > " $cpu /cpufreq/scaling_setspeed" ; then
6386 sleep 0.2
6487 actual_freq=$( cat " $cpu /cpufreq/scaling_cur_freq" )
6588 if [ " $actual_freq " = " $freq " ]; then
66- printf " ${GREEN} [PASS]${NC} %s set to %s kHz.\n " " $cpu " " $freq "
89+ log_info " [PASS] $cpu set to $freq kHz."
6790 else
68- printf " ${RED} [FAIL]${NC} Tried to set %s to %s kHz, but current is %s kHz.\n " " $cpu " " $freq " " $actual_freq "
91+ log_error " [FAIL] Tried to set $cpu to $freq kHz, but current is $actual_freq kHz."
6992 echo " fail" > " $status_file "
7093 fi
7194 else
72- printf " ${RED} [ERROR]${NC} Failed to set %s to %s kHz.\n " " $cpu " " $freq "
95+ log_error " [ERROR] Failed to set $cpu to $freq kHz."
7396 echo " fail" > " $status_file "
7497 fi
7598 done
7699
77- echo " Restoring $cpu governor to 'ondemand'..."
78- echo " ondemand" | sudo tee " $cpu /cpufreq/scaling_governor" > /dev/null
100+ log_info " Restoring $cpu governor to 'ondemand'..."
101+ echo " ondemand" > " $cpu /cpufreq/scaling_governor"
79102}
80103
81104cpu_index=0
@@ -93,34 +116,36 @@ for status_file in "$status_dir"/core_*; do
93116 status=$( cat " $status_file " )
94117 case " $status " in
95118 pass)
96- printf " CPU%s: ${GREEN} [PASS]${NC} \n " " $idx "
119+ log_info " CPU$idx : [PASS]"
97120 ;;
98121 fail)
99- printf " CPU%s: ${RED} [FAIL]${NC} \n " " $idx "
122+ log_error " CPU$idx : [FAIL]"
100123 overall_pass=1
101124 ;;
102125 skip)
103- printf " CPU%s: ${BLUE} [SKIPPED]${NC} \n " " $idx "
126+ log_info " CPU$idx : [SKIPPED]"
104127 ;;
105128 * )
106- printf " CPU%s: ${RED} [UNKNOWN STATUS]${NC} \n " " $idx "
129+ log_error " CPU$idx : [UNKNOWN STATUS]"
107130 overall_pass=1
108131 ;;
109132 esac
110133done
111134
112135log_info " "
113136log_info " === Overall CPUFreq Validation Result ==="
137+
138+ res_file=" $test_path /$TESTNAME .res"
114139if [ " $overall_pass " -eq 0 ]; then
115- printf " ${GREEN} [OVERALL PASS]${NC} All CPUs validated successfully.\n"
116140 log_pass " $TESTNAME : Test Passed"
117- echo " $TESTNAME PASS" > " $test_path /$TESTNAME .res"
141+ log_info " Writing PASS to $res_file "
142+ echo " $TESTNAME PASS" > " $res_file "
118143 rm -r " $status_dir "
119144 exit 0
120145else
121- printf " ${RED} [OVERALL FAIL]${NC} Some CPUs failed frequency validation.\n"
122146 log_fail " $TESTNAME : Test Failed"
123- echo " $TESTNAME FAIL" > " $test_path /$TESTNAME .res"
147+ log_info " Writing FAIL to $res_file "
148+ echo " $TESTNAME FAIL" > " $res_file "
124149 rm -r " $status_dir "
125150 exit 1
126151fi
0 commit comments