mm: rename alloc_pages_exact_node() to __alloc_pages_node()
[linux/fpc-iii.git] / tools / testing / selftests / efivarfs / efivarfs.sh
blob77edcdcc016bbe9e891dbee8ce27c5824caaae63
1 #!/bin/bash
3 efivarfs_mount=/sys/firmware/efi/efivars
4 test_guid=210be57c-9849-4fc7-a635-e6382d1aec27
6 check_prereqs()
8 local msg="skip all tests:"
10 if [ $UID != 0 ]; then
11 echo $msg must be run as root >&2
12 exit 0
15 if ! grep -q "^\S\+ $efivarfs_mount efivarfs" /proc/mounts; then
16 echo $msg efivarfs is not mounted on $efivarfs_mount >&2
17 exit 0
21 run_test()
23 local test="$1"
25 echo "--------------------"
26 echo "running $test"
27 echo "--------------------"
29 if [ "$(type -t $test)" = 'function' ]; then
30 ( $test )
31 else
32 ( ./$test )
35 if [ $? -ne 0 ]; then
36 echo " [FAIL]"
37 rc=1
38 else
39 echo " [PASS]"
43 test_create()
45 local attrs='\x07\x00\x00\x00'
46 local file=$efivarfs_mount/$FUNCNAME-$test_guid
48 printf "$attrs\x00" > $file
50 if [ ! -e $file ]; then
51 echo "$file couldn't be created" >&2
52 exit 1
55 if [ $(stat -c %s $file) -ne 5 ]; then
56 echo "$file has invalid size" >&2
57 exit 1
61 test_create_empty()
63 local file=$efivarfs_mount/$FUNCNAME-$test_guid
65 : > $file
67 if [ ! -e $file ]; then
68 echo "$file can not be created without writing" >&2
69 exit 1
73 test_create_read()
75 local file=$efivarfs_mount/$FUNCNAME-$test_guid
76 ./create-read $file
79 test_delete()
81 local attrs='\x07\x00\x00\x00'
82 local file=$efivarfs_mount/$FUNCNAME-$test_guid
84 printf "$attrs\x00" > $file
86 if [ ! -e $file ]; then
87 echo "$file couldn't be created" >&2
88 exit 1
91 rm $file
93 if [ -e $file ]; then
94 echo "$file couldn't be deleted" >&2
95 exit 1
100 # test that we can remove a variable by issuing a write with only
101 # attributes specified
102 test_zero_size_delete()
104 local attrs='\x07\x00\x00\x00'
105 local file=$efivarfs_mount/$FUNCNAME-$test_guid
107 printf "$attrs\x00" > $file
109 if [ ! -e $file ]; then
110 echo "$file does not exist" >&2
111 exit 1
114 printf "$attrs" > $file
116 if [ -e $file ]; then
117 echo "$file should have been deleted" >&2
118 exit 1
122 test_open_unlink()
124 local file=$efivarfs_mount/$FUNCNAME-$test_guid
125 ./open-unlink $file
128 # test that we can create a range of filenames
129 test_valid_filenames()
131 local attrs='\x07\x00\x00\x00'
132 local ret=0
134 local file_list="abc dump-type0-11-1-1362436005 1234 -"
135 for f in $file_list; do
136 local file=$efivarfs_mount/$f-$test_guid
138 printf "$attrs\x00" > $file
140 if [ ! -e $file ]; then
141 echo "$file could not be created" >&2
142 ret=1
143 else
144 rm $file
146 done
148 exit $ret
151 test_invalid_filenames()
153 local attrs='\x07\x00\x00\x00'
154 local ret=0
156 local file_list="
157 -1234-1234-1234-123456789abc
159 foo-bar
160 -foo-
161 foo-barbazba-foob-foob-foob-foobarbazfoo
162 foo-------------------------------------
163 -12345678-1234-1234-1234-123456789abc
164 a-12345678=1234-1234-1234-123456789abc
165 a-12345678-1234=1234-1234-123456789abc
166 a-12345678-1234-1234=1234-123456789abc
167 a-12345678-1234-1234-1234=123456789abc
168 1112345678-1234-1234-1234-123456789abc"
170 for f in $file_list; do
171 local file=$efivarfs_mount/$f
173 printf "$attrs\x00" 2>/dev/null > $file
175 if [ -e $file ]; then
176 echo "Creating $file should have failed" >&2
177 rm $file
178 ret=1
180 done
182 exit $ret
185 check_prereqs
187 rc=0
189 run_test test_create
190 run_test test_create_empty
191 run_test test_create_read
192 run_test test_delete
193 run_test test_zero_size_delete
194 run_test test_open_unlink
195 run_test test_valid_filenames
196 run_test test_invalid_filenames
198 exit $rc