2 # SPDX-License-Identifier: GPL-2.0
4 efivarfs_mount
=/sys
/firmware
/efi
/efivars
5 test_guid
=210be57c-9849-4fc7-a635-e6382d1aec27
9 local msg
="skip all tests:"
11 if [ $UID != 0 ]; then
12 echo $msg must be run as root
>&2
16 if ! grep -q "^\S\+ $efivarfs_mount efivarfs" /proc
/mounts
; then
17 echo $msg efivarfs is not mounted on
$efivarfs_mount >&2
26 echo "--------------------"
28 echo "--------------------"
30 if [ "$(type -t $test)" = 'function' ]; then
46 local attrs
='\x07\x00\x00\x00'
47 local file=$efivarfs_mount/$FUNCNAME-$test_guid
49 printf "$attrs\x00" > $file
51 if [ ! -e $file ]; then
52 echo "$file couldn't be created" >&2
56 if [ $
(stat
-c %s
$file) -ne 5 ]; then
57 echo "$file has invalid size" >&2
64 local file=$efivarfs_mount/$FUNCNAME-$test_guid
68 if [ ! -e $file ]; then
69 echo "$file can not be created without writing" >&2
76 local file=$efivarfs_mount/$FUNCNAME-$test_guid
82 local attrs
='\x07\x00\x00\x00'
83 local file=$efivarfs_mount/$FUNCNAME-$test_guid
85 printf "$attrs\x00" > $file
87 if [ ! -e $file ]; then
88 echo "$file couldn't be created" >&2
99 echo "$file couldn't be deleted" >&2
105 # test that we can remove a variable by issuing a write with only
106 # attributes specified
107 test_zero_size_delete
()
109 local attrs
='\x07\x00\x00\x00'
110 local file=$efivarfs_mount/$FUNCNAME-$test_guid
112 printf "$attrs\x00" > $file
114 if [ ! -e $file ]; then
115 echo "$file does not exist" >&2
120 printf "$attrs" > $file
122 if [ -e $file ]; then
123 echo "$file should have been deleted" >&2
130 local file=$efivarfs_mount/$FUNCNAME-$test_guid
134 # test that we can create a range of filenames
135 test_valid_filenames
()
137 local attrs
='\x07\x00\x00\x00'
140 local file_list
="abc dump-type0-11-1-1362436005 1234 -"
141 for f
in $file_list; do
142 local file=$efivarfs_mount/$f-$test_guid
144 printf "$attrs\x00" > $file
146 if [ ! -e $file ]; then
147 echo "$file could not be created" >&2
151 if [ $?
-ne 0 ]; then
161 test_invalid_filenames
()
163 local attrs
='\x07\x00\x00\x00'
167 -1234-1234-1234-123456789abc
171 foo-barbazba-foob-foob-foob-foobarbazfoo
172 foo-------------------------------------
173 -12345678-1234-1234-1234-123456789abc
174 a-12345678=1234-1234-1234-123456789abc
175 a-12345678-1234=1234-1234-123456789abc
176 a-12345678-1234-1234=1234-123456789abc
177 a-12345678-1234-1234-1234=123456789abc
178 1112345678-1234-1234-1234-123456789abc"
180 for f
in $file_list; do
181 local file=$efivarfs_mount/$f
183 printf "$attrs\x00" 2>/dev
/null
> $file
185 if [ -e $file ]; then
186 echo "Creating $file should have failed" >&2
188 if [ $?
-ne 0 ]; then
204 run_test test_create_empty
205 run_test test_create_read
207 run_test test_zero_size_delete
208 run_test test_open_unlink
209 run_test test_valid_filenames
210 run_test test_invalid_filenames