[PATCH] selftests/intel_pstate: Add validity check for cpu min/max frequency
From: Yujie Liu
Date: Wed Apr 17 2024 - 03:36:22 EST
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
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Signed-off-by: Yujie Liu <yujie.liu@xxxxxxxxx>
---
tools/testing/selftests/intel_pstate/run.sh | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/testing/selftests/intel_pstate/run.sh b/tools/testing/selftests/intel_pstate/run.sh
index e7008f614ad7..e81758cd1fb5 100755
--- a/tools/testing/selftests/intel_pstate/run.sh
+++ b/tools/testing/selftests/intel_pstate/run.sh
@@ -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
--
2.34.1