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

selftests/efivarfs: clean up test files from test_create*()

Test files created by test_create() and test_create_empty() tests will
stay in the $efivarfs_mount directory until the system was rebooted.

When the tester tries to run this efivarfs test again on the same
system, the immutable characteristics in that directory will cause some
"Operation not permitted" noises, and a false-positve test result as the
file was created in previous run.
--------------------
running test_create
--------------------
./efivarfs.sh: line 59: /sys/firmware/efi/efivars/test_create-210be57c-9849-4fc7-a635-e6382d1aec27: Operation not permitted
[PASS]
--------------------
running test_create_empty
--------------------
./efivarfs.sh: line 78: /sys/firmware/efi/efivars/test_create_empty-210be57c-9849-4fc7-a635-e6382d1aec27: Operation not permitted
[PASS]
--------------------

Create a file_cleanup() to remove those test files in the end of each
test to solve this issue.

For the test_create_read, we can move the clean up task to the end of
the test to ensure the system is clean.

Also, use this function to replace the existing file removal code.

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Po-Hsu Lin and committed by
Shuah Khan
dff6d2ae 8ce72dc3

+13 -19
+13 -19
tools/testing/selftests/efivarfs/efivarfs.sh
··· 7 7 # Kselftest framework requirement - SKIP code is 4. 8 8 ksft_skip=4 9 9 10 + file_cleanup() 11 + { 12 + chattr -i $1 13 + rm -f $1 14 + } 15 + 10 16 check_prereqs() 11 17 { 12 18 local msg="skip all tests:" ··· 64 58 65 59 if [ $(stat -c %s $file) -ne 5 ]; then 66 60 echo "$file has invalid size" >&2 61 + file_cleanup $file 67 62 exit 1 68 63 fi 64 + file_cleanup $file 69 65 } 70 66 71 67 test_create_empty() ··· 80 72 echo "$file can not be created without writing" >&2 81 73 exit 1 82 74 fi 75 + file_cleanup $file 83 76 } 84 77 85 78 test_create_read() 86 79 { 87 80 local file=$efivarfs_mount/$FUNCNAME-$test_guid 88 - if [ -f $file]; then 89 - chattr -i $file 90 - rm -rf $file 91 - fi 92 81 ./create-read $file 82 + file_cleanup $file 93 83 } 94 84 95 85 test_delete() ··· 102 96 exit 1 103 97 fi 104 98 105 - rm $file 2>/dev/null 106 - if [ $? -ne 0 ]; then 107 - chattr -i $file 108 - rm $file 109 - fi 99 + file_cleanup $file 110 100 111 101 if [ -e $file ]; then 112 102 echo "$file couldn't be deleted" >&2 ··· 156 154 echo "$file could not be created" >&2 157 155 ret=1 158 156 else 159 - rm $file 2>/dev/null 160 - if [ $? -ne 0 ]; then 161 - chattr -i $file 162 - rm $file 163 - fi 157 + file_cleanup $file 164 158 fi 165 159 done 166 160 ··· 189 191 190 192 if [ -e $file ]; then 191 193 echo "Creating $file should have failed" >&2 192 - rm $file 2>/dev/null 193 - if [ $? -ne 0 ]; then 194 - chattr -i $file 195 - rm $file 196 - fi 194 + file_cleanup $file 197 195 ret=1 198 196 fi 199 197 done