Skip to content

Commit dff6d2a

Browse files
Cypresslinshuahkh
authored andcommitted
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>
1 parent 8ce72dc commit dff6d2a

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

‎tools/testing/selftests/efivarfs/efivarfs.sh‎

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ test_guid=210be57c-9849-4fc7-a635-e6382d1aec27
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 @@ test_create()
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,16 +80,14 @@ test_create_empty()
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
80-
if [ -f $file]; then
81-
chattr -i $file
82-
rm -rf $file
83-
fi
8489
./create-read $file
90+
file_cleanup $file
8591
}
8692

8793
test_delete()
@@ -96,11 +102,7 @@ test_delete()
96102
exit 1
97103
fi
98104

99-
rm $file 2>/dev/null
100-
if [ $? -ne 0 ]; then
101-
chattr -i $file
102-
rm $file
103-
fi
105+
file_cleanup $file
104106

105107
if [ -e $file ]; then
106108
echo "$file couldn't be deleted" >&2
@@ -154,11 +156,7 @@ test_valid_filenames()
154156
echo "$file could not be created" >&2
155157
ret=1
156158
else
157-
rm $file 2>/dev/null
158-
if [ $? -ne 0 ]; then
159-
chattr -i $file
160-
rm $file
161-
fi
159+
file_cleanup $file
162160
fi
163161
done
164162

@@ -191,11 +189,7 @@ test_invalid_filenames()
191189

192190
if [ -e $file ]; then
193191
echo "Creating $file should have failed" >&2
194-
rm $file 2>/dev/null
195-
if [ $? -ne 0 ]; then
196-
chattr -i $file
197-
rm $file
198-
fi
192+
file_cleanup $file
199193
ret=1
200194
fi
201195
done

0 commit comments

Comments
 (0)