Skip to contentSkip to conversation

selftests/intel_pstate: Add validity check for cpu min/max frequency

PATCH New Yujie Liu 1 participant 1 message Apr 17, 2024 Kselftest

lore
Share & tools
lore

Yujie Liu

author
#0 lore raw

PATCH 1/1 selftests/intel_pstate: Add validity check for cpu min/max frequency

If libcpupower is not properly installed somehow, the cpupower tool cannot work, and cpu min_freq and max_freq are not correctly assigned, but the code can still keep going and gives an "ok" result at last, which seems not to be the expected behavior of this test.

tools/testing/selftests/intel_pstate# make run_tests
TAP version 13
1..1
# selftests: intel_pstate: run.sh
# cpupower: error while loading shared libraries: libcpupower.so.1: cannot open shared object file: No such file or directory # ./run.sh: line 90: / 1000: syntax error: operand expected (error token is "/ 1000")
# cpupower: error while loading shared libraries: libcpupower.so.1: cannot open shared object file: No such file or directory # ./run.sh: line 92: / 1000: syntax error: operand expected (error token is "/ 1000")
# ========================================================================
# The marketing frequency of the cpu is 3400 MHz
# The maximum frequency of the cpu is MHz
# The minimum frequency of the cpu is MHz
# Target Actual Difference MSR(0x199) max_perf_pct
ok 1 selftests: intel_pstate: run.sh

Fix this by adding null checks as well as [ $var -eq $var ] checks to confirm that both min_freq and max_freq are valid integers. The fixed result will have a "# SKIP" suffix and looks like:

tools/testing/selftests/intel_pstate# make run_tests
TAP version 13
1..1
# selftests: intel_pstate: run.sh
# cpupower: error while loading shared libraries: libcpupower.so.1: cannot open shared object file: No such file or directory # ./run.sh: line 90: / 1000: syntax error: operand expected (error token is "/ 1000")
# cpupower: error while loading shared libraries: libcpupower.so.1: cannot open shared object file: No such file or directory # ./run.sh: line 92: / 1000: syntax error: operand expected (error token is "/ 1000")
# Cannot get cpu frequency info
ok 1 selftests: intel_pstate: run.sh # SKIP

---
 tools/testing/selftests/intel_pstate/run.sh | 5 +++++
 1 file changed, 5 insertions(+)
tools/testing/selftests/intel_pstate/run.sh +5 -0
index e7008f614ad7..e81758cd1fb5 100755
@@ -91,6 +91,11 @@ min_freq=$(($_min_freq / 1000))
 _max_freq=$(cpupower frequency-info -l | tail -1 | awk ' { print $2 } ')
 max_freq=$(($_max_freq / 1000))
 
+{ [ $min_freq ] && [ $min_freq -eq $min_freq ] &&
+  [ $max_freq ] && [ $max_freq -eq $max_freq ]; } || {
+        echo "Cannot get cpu frequency info"
+        exit $ksft_skip
+}
 
 [ $EVALUATE_ONLY -eq 0 ] && for freq in `seq $max_freq -100 $min_freq`
 do
Signature · 1 line
2.34.1