Skip to content

Commit 8ffe772

Browse files
SSapkalshuahkh
authored andcommitted
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/[email protected] Reported-by: Narasimhan V <[email protected]> Signed-off-by: Swapnil Sapkal <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent ab4b004 commit 8ffe772

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tools/testing/selftests/cpufreq/cpufreq.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ read_cpufreq_files_in_dir()
5252
for file in $files; do
5353
if [ -f $1/$file ]; then
5454
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
5663
else
5764
printf "\n"
5865
read_cpufreq_files_in_dir "$1/$file"
@@ -83,10 +90,10 @@ update_cpufreq_files_in_dir()
8390

8491
for file in $files; do
8592
if [ -f $1/$file ]; then
86-
# file is writable ?
87-
local wfile=$(ls -l $1/$file | awk '$1 ~ /^.*w.*/ { print $NF; }')
93+
# file is readable and writable ?
94+
local rwfile=$(ls -l $1/$file | awk '$1 ~ /^.*rw.*/ { print $NF; }')
8895

89-
if [ ! -z $wfile ]; then
96+
if [ ! -z $rwfile ]; then
9097
# scaling_setspeed is a special file and we
9198
# should skip updating it
9299
if [ $file != "scaling_setspeed" ]; then

0 commit comments

Comments
 (0)