2 # SPDX-License-Identifier: GPL-2.0
4 efivarfs_mount
=/sys
/firmware
/efi
/efivars
5 test_guid
=210be57c-9849-4fc7-a635-e6382d1aec27
7 # Kselftest framework requirement - SKIP code is 4.
12 local msg
="skip all tests:"
14 if [ $UID != 0 ]; then
15 echo $msg must be run as root
>&2
19 if ! grep -q "^\S\+ $efivarfs_mount efivarfs" /proc
/mounts
; then
20 echo $msg efivarfs is not mounted on
$efivarfs_mount >&2
29 echo "--------------------"
31 echo "--------------------"
33 if [ "$(type -t $test)" = 'function' ]; then
49 local attrs
='\x07\x00\x00\x00'
50 local file=$efivarfs_mount/$FUNCNAME-$test_guid
52 printf "$attrs\x00" > $file
54 if [ ! -e $file ]; then
55 echo "$file couldn't be created" >&2
59 if [ $
(stat
-c %s
$file) -ne 5 ]; then
60 echo "$file has invalid size" >&2
67 local file=$efivarfs_mount/$FUNCNAME-$test_guid
71 if [ ! -e $file ]; then
72 echo "$file can not be created without writing" >&2
79 local file=$efivarfs_mount/$FUNCNAME-$test_guid
85 local attrs
='\x07\x00\x00\x00'
86 local file=$efivarfs_mount/$FUNCNAME-$test_guid
88 printf "$attrs\x00" > $file
90 if [ ! -e $file ]; then
91 echo "$file couldn't be created" >&2
101 if [ -e $file ]; then
102 echo "$file couldn't be deleted" >&2
108 # test that we can remove a variable by issuing a write with only
109 # attributes specified
110 test_zero_size_delete
()
112 local attrs
='\x07\x00\x00\x00'
113 local file=$efivarfs_mount/$FUNCNAME-$test_guid
115 printf "$attrs\x00" > $file
117 if [ ! -e $file ]; then
118 echo "$file does not exist" >&2
123 printf "$attrs" > $file
125 if [ -e $file ]; then
126 echo "$file should have been deleted" >&2
133 local file=$efivarfs_mount/$FUNCNAME-$test_guid
137 # test that we can create a range of filenames
138 test_valid_filenames
()
140 local attrs
='\x07\x00\x00\x00'
143 local file_list
="abc dump-type0-11-1-1362436005 1234 -"
144 for f
in $file_list; do
145 local file=$efivarfs_mount/$f-$test_guid
147 printf "$attrs\x00" > $file
149 if [ ! -e $file ]; then
150 echo "$file could not be created" >&2
154 if [ $?
-ne 0 ]; then
164 test_invalid_filenames
()
166 local attrs
='\x07\x00\x00\x00'
170 -1234-1234-1234-123456789abc
174 foo-barbazba-foob-foob-foob-foobarbazfoo
175 foo-------------------------------------
176 -12345678-1234-1234-1234-123456789abc
177 a-12345678=1234-1234-1234-123456789abc
178 a-12345678-1234=1234-1234-123456789abc
179 a-12345678-1234-1234=1234-123456789abc
180 a-12345678-1234-1234-1234=123456789abc
181 1112345678-1234-1234-1234-123456789abc"
183 for f
in $file_list; do
184 local file=$efivarfs_mount/$f
186 printf "$attrs\x00" 2>/dev
/null
> $file
188 if [ -e $file ]; then
189 echo "Creating $file should have failed" >&2
191 if [ $?
-ne 0 ]; then
207 run_test test_create_empty
208 run_test test_create_read
210 run_test test_zero_size_delete
211 run_test test_open_unlink
212 run_test test_valid_filenames
213 run_test test_invalid_filenames