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.
18 local msg
="skip all tests:"
20 if [ $UID != 0 ]; then
21 echo $msg must be run as root
>&2
25 if ! grep -q "^\S\+ $efivarfs_mount efivarfs" /proc
/mounts
; then
26 echo $msg efivarfs is not mounted on
$efivarfs_mount >&2
35 echo "--------------------"
37 echo "--------------------"
39 if [ "$(type -t $test)" = 'function' ]; then
55 local attrs
='\x07\x00\x00\x00'
56 local file=$efivarfs_mount/$FUNCNAME-$test_guid
58 printf "$attrs\x00" > $file
60 if [ ! -e $file ]; then
61 echo "$file couldn't be created" >&2
65 if [ $
(stat
-c %s
$file) -ne 5 ]; then
66 echo "$file has invalid size" >&2
75 local file=$efivarfs_mount/$FUNCNAME-$test_guid
79 if [ ! -e $file ]; then
80 echo "$file can not be created without writing" >&2
88 local file=$efivarfs_mount/$FUNCNAME-$test_guid
91 echo "create and read $file failed"
100 local attrs
='\x07\x00\x00\x00'
101 local file=$efivarfs_mount/$FUNCNAME-$test_guid
103 printf "$attrs\x00" > $file
105 if [ ! -e $file ]; then
106 echo "$file couldn't be created" >&2
112 if [ -e $file ]; then
113 echo "$file couldn't be deleted" >&2
119 # test that we can remove a variable by issuing a write with only
120 # attributes specified
121 test_zero_size_delete
()
123 local attrs
='\x07\x00\x00\x00'
124 local file=$efivarfs_mount/$FUNCNAME-$test_guid
126 printf "$attrs\x00" > $file
128 if [ ! -e $file ]; then
129 echo "$file does not exist" >&2
134 printf "$attrs" > $file
136 if [ -e $file ]; then
137 echo "$file should have been deleted" >&2
144 local file=$efivarfs_mount/$FUNCNAME-$test_guid
148 # test that we can create a range of filenames
149 test_valid_filenames
()
151 local attrs
='\x07\x00\x00\x00'
154 local file_list
="abc dump-type0-11-1-1362436005 1234 -"
155 for f
in $file_list; do
156 local file=$efivarfs_mount/$f-$test_guid
158 printf "$attrs\x00" > $file
160 if [ ! -e $file ]; then
161 echo "$file could not be created" >&2
171 test_invalid_filenames
()
173 local attrs
='\x07\x00\x00\x00'
177 -1234-1234-1234-123456789abc
181 foo-barbazba-foob-foob-foob-foobarbazfoo
182 foo-------------------------------------
183 -12345678-1234-1234-1234-123456789abc
184 a-12345678=1234-1234-1234-123456789abc
185 a-12345678-1234=1234-1234-123456789abc
186 a-12345678-1234-1234=1234-123456789abc
187 a-12345678-1234-1234-1234=123456789abc
188 1112345678-1234-1234-1234-123456789abc"
190 for f
in $file_list; do
191 local file=$efivarfs_mount/$f
193 printf "$attrs\x00" 2>/dev
/null
> $file
195 if [ -e $file ]; then
196 echo "Creating $file should have failed" >&2
210 run_test test_create_empty
211 run_test test_create_read
213 run_test test_zero_size_delete
214 run_test test_open_unlink
215 run_test test_valid_filenames
216 run_test test_invalid_filenames