Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/cpufreq: Fix cpufreq basic read and update testcases

In cpufreq basic selftests, one of the testcases is to read all cpufreq
sysfs files and print the values. This testcase assumes all the cpufreq
sysfs files have read permissions. However certain cpufreq sysfs files
(eg. stats/reset) are write only files and this testcase errors out
when it is not able to read the file.
Similarily, there is one more testcase which reads the cpufreq sysfs
file data and write it back to same file. This testcase also errors out
for sysfs files without read permission.
Fix these testcases by adding proper read permission checks.

Link: https://lore.kernel.org/r/20250430171433.10866-1-swapnil.sapkal@amd.com
Reported-by: Narasimhan V <narasimhan.v@amd.com>
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Swapnil Sapkal and committed by
Shuah Khan
8ffe7720 ab4b0040

+11 -4
+11 -4
tools/testing/selftests/cpufreq/cpufreq.sh
··· 52 52 for file in $files; do 53 53 if [ -f $1/$file ]; then 54 54 printf "$file:" 55 - cat $1/$file 55 + #file is readable ? 56 + local rfile=$(ls -l $1/$file | awk '$1 ~ /^.*r.*/ { print $NF; }') 57 + 58 + if [ ! -z $rfile ]; then 59 + cat $1/$file 60 + else 61 + printf "$file is not readable\n" 62 + fi 56 63 else 57 64 printf "\n" 58 65 read_cpufreq_files_in_dir "$1/$file" ··· 90 83 91 84 for file in $files; do 92 85 if [ -f $1/$file ]; then 93 - # file is writable ? 94 - local wfile=$(ls -l $1/$file | awk '$1 ~ /^.*w.*/ { print $NF; }') 86 + # file is readable and writable ? 87 + local rwfile=$(ls -l $1/$file | awk '$1 ~ /^.*rw.*/ { print $NF; }') 95 88 96 - if [ ! -z $wfile ]; then 89 + if [ ! -z $rwfile ]; then 97 90 # scaling_setspeed is a special file and we 98 91 # should skip updating it 99 92 if [ $file != "scaling_setspeed" ]; then