blob: 880cdd5dc63f44fb9197f09b41296b2bbde4cc5a [file] [log] [blame]
Jeremy Kerr455ce1c2013-02-27 17:05:52 -08001#!/bin/bash
2
3efivarfs_mount=/sys/firmware/efi/efivars
4test_guid=210be57c-9849-4fc7-a635-e6382d1aec27
5
6check_prereqs()
7{
8 local msg="skip all tests:"
9
10 if [ $UID != 0 ]; then
11 echo $msg must be run as root >&2
12 exit 0
13 fi
14
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
18 fi
19}
20
21run_test()
22{
23 local test="$1"
24
25 echo "--------------------"
26 echo "running $test"
27 echo "--------------------"
28
29 if [ "$(type -t $test)" = 'function' ]; then
30 ( $test )
31 else
32 ( ./$test )
33 fi
34
35 if [ $? -ne 0 ]; then
36 echo " [FAIL]"
37 rc=1
38 else
39 echo " [PASS]"
40 fi
41}
42
43test_create()
44{
45 local attrs='\x07\x00\x00\x00'
46 local file=$efivarfs_mount/$FUNCNAME-$test_guid
47
48 printf "$attrs\x00" > $file
49
50 if [ ! -e $file ]; then
51 echo "$file couldn't be created" >&2
52 exit 1
53 fi
54
55 if [ $(stat -c %s $file) -ne 5 ]; then
56 echo "$file has invalid size" >&2
57 exit 1
58 fi
59}
60
Jeremy Kerr033a1a72013-02-27 17:05:53 -080061test_create_empty()
62{
63 local file=$efivarfs_mount/$FUNCNAME-$test_guid
64
65 : > $file
66
67 if [ ! -e $file ]; then
68 echo "$file can not be created without writing" >&2
69 exit 1
70 fi
71}
72
Jeremy Kerrd974f672013-02-27 17:05:55 -080073test_create_read()
74{
75 local file=$efivarfs_mount/$FUNCNAME-$test_guid
76 ./create-read $file
77}
78
Jeremy Kerr455ce1c2013-02-27 17:05:52 -080079test_delete()
80{
81 local attrs='\x07\x00\x00\x00'
82 local file=$efivarfs_mount/$FUNCNAME-$test_guid
83
84 printf "$attrs\x00" > $file
85
86 if [ ! -e $file ]; then
87 echo "$file couldn't be created" >&2
88 exit 1
89 fi
90
91 rm $file
92
93 if [ -e $file ]; then
94 echo "$file couldn't be deleted" >&2
95 exit 1
96 fi
97
98}
99
100# test that we can remove a variable by issuing a write with only
101# attributes specified
102test_zero_size_delete()
103{
104 local attrs='\x07\x00\x00\x00'
105 local file=$efivarfs_mount/$FUNCNAME-$test_guid
106
107 printf "$attrs\x00" > $file
108
109 if [ ! -e $file ]; then
110 echo "$file does not exist" >&2
111 exit 1
112 fi
113
114 printf "$attrs" > $file
115
116 if [ -e $file ]; then
117 echo "$file should have been deleted" >&2
118 exit 1
119 fi
120}
121
122test_open_unlink()
123{
124 local file=$efivarfs_mount/$FUNCNAME-$test_guid
125 ./open-unlink $file
126}
127
128check_prereqs
129
130rc=0
131
132run_test test_create
Jeremy Kerr033a1a72013-02-27 17:05:53 -0800133run_test test_create_empty
Jeremy Kerrd974f672013-02-27 17:05:55 -0800134run_test test_create_read
Jeremy Kerr455ce1c2013-02-27 17:05:52 -0800135run_test test_delete
136run_test test_zero_size_delete
137run_test test_open_unlink
138
139exit $rc