|
1 | 1 | #!/bin/sh |
2 | 2 |
|
3 | | -# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 3 | +# Copyright (c) Qualcomm Technologies, Inc. |
4 | 4 | # SPDX-License-Identifier: BSD-3-Clause-Clear |
5 | 5 |
|
6 | | -. "${PWD}/init_env" |
7 | | -TESTNAME="CPUFreq_Validation" |
8 | | -. "$TOOLS/functestlib.sh" |
9 | | - |
10 | | -test_path=$(find_test_case_by_name "$TESTNAME") |
11 | | -log_info "-----------------------------------------------------------------------------------------" |
12 | | -log_info "-------------------Starting $TESTNAME Testcase----------------------------" |
13 | | -log_info "=== CPUFreq Frequency Walker with Validation ===" |
14 | | - |
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 | | - |
22 | | -NUM_CPUS=$(nproc) |
23 | | -printf "${YELLOW}Detected %s CPU cores.${NC}\n" "$NUM_CPUS" |
24 | | - |
25 | | -overall_pass=0 |
26 | | -status_dir="/tmp/cpufreq_status.$$" |
27 | | -mkdir -p "$status_dir" |
28 | | - |
29 | | -validate_cpu_core() { |
30 | | - local cpu=$1 |
31 | | - local core_id=$2 |
32 | | - status_file="$status_dir/core_$core_id" |
33 | | - |
34 | | - printf "${BLUE}Processing %s...${NC}\n" "$cpu" |
35 | | - |
36 | | - if [ ! -d "$cpu/cpufreq" ]; then |
37 | | - printf "${BLUE}[SKIP]${NC} %s does not support cpufreq.\n" "$cpu" |
38 | | - echo "skip" > "$status_file" |
39 | | - return |
40 | | - fi |
| 6 | +# shellcheck disable=SC2037 |
| 7 | +SCRIPT_DIR=$(CDPATH=cd -- "$(dirname "$0")" >/dev/null 2>&1 && pwd) |
41 | 8 |
|
42 | | - available_freqs=$(cat "$cpu/cpufreq/scaling_available_frequencies" 2>/dev/null) |
43 | | - |
44 | | - if [ -z "$available_freqs" ]; then |
45 | | - printf "${YELLOW}[INFO]${NC} No available frequencies for %s. Skipping...\n" "$cpu" |
46 | | - echo "skip" > "$status_file" |
47 | | - return |
48 | | - fi |
49 | | - |
50 | | - if echo "userspace" | tee "$cpu/cpufreq/scaling_governor" > /dev/null; then |
51 | | - printf "${YELLOW}[INFO]${NC} Set governor to userspace.\n" |
52 | | - else |
53 | | - printf "${RED}[ERROR]${NC} Cannot set userspace governor for %s.\n" "$cpu" |
54 | | - echo "fail" > "$status_file" |
55 | | - return |
56 | | - fi |
| 9 | +# Traverse upward to find Runner root containing utils/ |
| 10 | +RUNNER_DIR="$SCRIPT_DIR" |
| 11 | +while [ ! -d "$RUNNER_DIR/utils" ] && [ "$RUNNER_DIR" != "/" ]; do |
| 12 | + RUNNER_DIR=$(dirname "$RUNNER_DIR") |
| 13 | +done |
57 | 14 |
|
58 | | - echo "pass" > "$status_file" |
| 15 | +FUNCLIB="$RUNNER_DIR/utils/functestlib.sh" |
59 | 16 |
|
60 | | - for freq in $available_freqs; do |
61 | | - log_info "Setting $cpu to frequency $freq kHz..." |
62 | | - if echo "$freq" | tee "$cpu/cpufreq/scaling_setspeed" > /dev/null; then |
63 | | - sleep 0.2 |
64 | | - actual_freq=$(cat "$cpu/cpufreq/scaling_cur_freq") |
65 | | - if [ "$actual_freq" = "$freq" ]; then |
66 | | - printf "${GREEN}[PASS]${NC} %s set to %s kHz.\n" "$cpu" "$freq" |
67 | | - else |
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" |
70 | | - fi |
71 | | - else |
72 | | - printf "${RED}[ERROR]${NC} Failed to set %s to %s kHz.\n" "$cpu" "$freq" |
73 | | - echo "fail" > "$status_file" |
74 | | - fi |
75 | | - done |
| 17 | +if [ ! -f "$FUNCLIB" ]; then |
| 18 | + echo "Error: Could not locate functestlib.sh from $SCRIPT_DIR" >&2 |
| 19 | + exit 1 |
| 20 | +fi |
76 | 21 |
|
77 | | - echo "Restoring $cpu governor to 'ondemand'..." |
78 | | - echo "ondemand" | sudo tee "$cpu/cpufreq/scaling_governor" > /dev/null |
79 | | -} |
| 22 | +# shellcheck disable=SC1090 |
| 23 | +. "$FUNCLIB" |
80 | 24 |
|
81 | | -cpu_index=0 |
82 | | -for cpu in /sys/devices/system/cpu/cpu[0-9]*; do |
83 | | - validate_cpu_core "$cpu" "$cpu_index" & |
84 | | - cpu_index=$((cpu_index + 1)) |
85 | | -done |
| 25 | +TESTNAME="CPUFreq_Validation" |
86 | 26 |
|
87 | | -wait |
| 27 | +test_path=$(find_test_case_by_name "$TESTNAME") |
88 | 28 |
|
89 | | -log_info "" |
90 | | -log_info "=== Per-Core Test Summary ===" |
91 | | -for status_file in "$status_dir"/core_*; do |
92 | | - idx=$(basename "$status_file" | cut -d_ -f2) |
93 | | - status=$(cat "$status_file") |
94 | | - case "$status" in |
95 | | - pass) |
96 | | - printf "CPU%s: ${GREEN}[PASS]${NC}\n" "$idx" |
97 | | - ;; |
98 | | - fail) |
99 | | - printf "CPU%s: ${RED}[FAIL]${NC}\n" "$idx" |
100 | | - overall_pass=1 |
101 | | - ;; |
102 | | - skip) |
103 | | - printf "CPU%s: ${BLUE}[SKIPPED]${NC}\n" "$idx" |
104 | | - ;; |
105 | | - *) |
106 | | - printf "CPU%s: ${RED}[UNKNOWN STATUS]${NC}\n" "$idx" |
107 | | - overall_pass=1 |
108 | | - ;; |
109 | | - esac |
110 | | -done |
| 29 | +# Debug: show resolved path |
| 30 | +log_info "Resolved test_path: $test_path" |
| 31 | +if [ -z "$test_path" ]; then |
| 32 | + log_error "$TESTNAME : Could not resolve test directory." |
| 33 | + exit 1 |
| 34 | +fi |
111 | 35 |
|
112 | | -log_info "" |
113 | | -log_info "=== Overall CPUFreq Validation Result ===" |
| 36 | +# Debug: check write permission |
| 37 | +touch "$test_path/.write_check" 2>/dev/null || { |
| 38 | + log_error "Write permission denied at $test_path" |
| 39 | + exit 1 |
| 40 | + log_info "Restoring $cpu governor to 'ondemand'..." |
| 41 | +res_file="$test_path/$TESTNAME.res" |
114 | 42 | if [ "$overall_pass" -eq 0 ]; then |
115 | | - printf "${GREEN}[OVERALL PASS]${NC} All CPUs validated successfully.\n" |
116 | 43 | log_pass "$TESTNAME : Test Passed" |
117 | | - echo "$TESTNAME PASS" > "$test_path/$TESTNAME.res" |
| 44 | + log_info "Writing PASS to $res_file" |
| 45 | + echo "$TESTNAME PASS" > "$res_file" |
118 | 46 | rm -r "$status_dir" |
119 | 47 | exit 0 |
120 | 48 | else |
121 | | - printf "${RED}[OVERALL FAIL]${NC} Some CPUs failed frequency validation.\n" |
122 | 49 | log_fail "$TESTNAME : Test Failed" |
123 | | - echo "$TESTNAME FAIL" > "$test_path/$TESTNAME.res" |
| 50 | + log_info "Writing FAIL to $res_file" |
| 51 | + echo "$TESTNAME FAIL" > "$res_file" |
124 | 52 | rm -r "$status_dir" |
125 | 53 | exit 1 |
126 | 54 | fi |
|
0 commit comments