blob: e8c0d27b381bb2d8e4e2bb914185158e0f188d39 [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
61test_delete()
62{
63 local attrs='\x07\x00\x00\x00'
64 local file=$efivarfs_mount/$FUNCNAME-$test_guid
65
66 printf "$attrs\x00" > $file
67
68 if [ ! -e $file ]; then
69 echo "$file couldn't be created" >&2
70 exit 1
71 fi
72
73 rm $file
74
75 if [ -e $file ]; then
76 echo "$file couldn't be deleted" >&2
77 exit 1
78 fi
79
80}
81
82# test that we can remove a variable by issuing a write with only
83# attributes specified
84test_zero_size_delete()
85{
86 local attrs='\x07\x00\x00\x00'
87 local file=$efivarfs_mount/$FUNCNAME-$test_guid
88
89 printf "$attrs\x00" > $file
90
91 if [ ! -e $file ]; then
92 echo "$file does not exist" >&2
93 exit 1
94 fi
95
96 printf "$attrs" > $file
97
98 if [ -e $file ]; then
99 echo "$file should have been deleted" >&2
100 exit 1
101 fi
102}
103
104test_open_unlink()
105{
106 local file=$efivarfs_mount/$FUNCNAME-$test_guid
107 ./open-unlink $file
108}
109
110check_prereqs
111
112rc=0
113
114run_test test_create
115run_test test_delete
116run_test test_zero_size_delete
117run_test test_open_unlink
118
119exit $rc