hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/tools/testing/selftests/efivarfs/efivarfs.sh
....@@ -7,6 +7,12 @@
77 # Kselftest framework requirement - SKIP code is 4.
88 ksft_skip=4
99
10
+file_cleanup()
11
+{
12
+ chattr -i $1
13
+ rm -f $1
14
+}
15
+
1016 check_prereqs()
1117 {
1218 local msg="skip all tests:"
....@@ -58,8 +64,10 @@
5864
5965 if [ $(stat -c %s $file) -ne 5 ]; then
6066 echo "$file has invalid size" >&2
67
+ file_cleanup $file
6168 exit 1
6269 fi
70
+ file_cleanup $file
6371 }
6472
6573 test_create_empty()
....@@ -72,12 +80,19 @@
7280 echo "$file can not be created without writing" >&2
7381 exit 1
7482 fi
83
+ file_cleanup $file
7584 }
7685
7786 test_create_read()
7887 {
7988 local file=$efivarfs_mount/$FUNCNAME-$test_guid
8089 ./create-read $file
90
+ if [ $? -ne 0 ]; then
91
+ echo "create and read $file failed"
92
+ file_cleanup $file
93
+ exit 1
94
+ fi
95
+ file_cleanup $file
8196 }
8297
8398 test_delete()
....@@ -92,11 +107,7 @@
92107 exit 1
93108 fi
94109
95
- rm $file 2>/dev/null
96
- if [ $? -ne 0 ]; then
97
- chattr -i $file
98
- rm $file
99
- fi
110
+ file_cleanup $file
100111
101112 if [ -e $file ]; then
102113 echo "$file couldn't be deleted" >&2
....@@ -150,11 +161,7 @@
150161 echo "$file could not be created" >&2
151162 ret=1
152163 else
153
- rm $file 2>/dev/null
154
- if [ $? -ne 0 ]; then
155
- chattr -i $file
156
- rm $file
157
- fi
164
+ file_cleanup $file
158165 fi
159166 done
160167
....@@ -187,11 +194,7 @@
187194
188195 if [ -e $file ]; then
189196 echo "Creating $file should have failed" >&2
190
- rm $file 2>/dev/null
191
- if [ $? -ne 0 ]; then
192
- chattr -i $file
193
- rm $file
194
- fi
197
+ file_cleanup $file
195198 ret=1
196199 fi
197200 done