Skip to content

Commit 5905ace

Browse files
committed
Add test for efivar
Signed-off-by: Reagan Bohan <xbjfk.github@gmail.com>
1 parent 3b57f7f commit 5905ace

8 files changed

Lines changed: 98 additions & 0 deletions

File tree

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ configure_file(input : 'efivar.spec.in', output : 'efivar.spec', configuration :
77

88
subdir('src')
99
subdir('docs')
10+
subdir('tests')

src/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ efivar = executable('efivar', efivar_sources, gen_guids, install : true, link_wi
8888
efisecdb_sources = ['efisecdb.c', 'secdb-dump.c', 'util.c']
8989
efisecdb = executable('efisecdb', efisecdb_sources, gen_guids, install : true, link_with : [lib_targets['efivar'], lib_targets['efisec']], include_directories : incdir)
9090

91+
tester_sources = ['test/tester.c']
92+
tester = executable('tester', tester_sources, gen_guids, link_with : lib_targets['efivar'], include_directories : incdir)
9193

9294
pkg = import('pkgconfig')
9395

tests/meson.build

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
grubenv_tests = {
2+
'test.dmpstore.export' : ['testing export to DMPSTORE format',
3+
'@0@ -n {grub}-GRUB_ENV -f test.dmpstore.export.result.env -D -e test.dmpstore.export.result.var'],
4+
'test.efivar.export' : ['testing export to libefivar format',
5+
'@0@ -n {grub}-GRUB_ENV -f test.efivar.export.result.env -e test.efivar.export.result.var'],
6+
'test.grubenv.var.0' : ['test importing from DMPSTORE and exporting to DMPSTORE and symbolic guid-name validation',
7+
'''
8+
@0@ -n {grub}-GRUB_ENV -f test.grubenv.var.0.result.env -D -e test.grubenv.var.0.export.var
9+
@0@ -i test.grubenv.var.0.export.var -e test.grubenv.var.0.result.var -D
10+
'''],
11+
'test.grubenv.var.1' : ['test importing from DMPSTORE and exporting to libefivar',
12+
'''
13+
@0@ -n {grub}-GRUB_ENV -f test.grubenv.var.1.result.env -D -e test.grubenv.var.1.export.var
14+
@0@ -i test.grubenv.var.1.export.var -e test.grubenv.var.1.result.var
15+
'''],
16+
'test.grubenv.var.2' : ['test importing from libefivar and exporting to DMPSTORE and mixed-case guid-name validation',
17+
'''
18+
@0@ -n 91376aff-cBa6-42bE-949d-06fde81128e8-GRUB_ENV -f test.grubenv.var.2.result.env -e test.grubenv.var.2.export.var
19+
@0@ -i test.grubenv.var.2.export.var -e test.grubenv.var.2.result.var -D
20+
'''],
21+
'test.grubenv.var.3' : ['test importing from libefivar and exporting to libefivar and guid-name validation',
22+
'''
23+
@0@ -n 91376aff-cba6-42be-949d-06fde81128e8-GRUB_ENV -f test.grubenv.var.3.result.env -e test.grubenv.var.3.export.var
24+
@0@ -i test.grubenv.var.3.export.var -e test.grubenv.var.3.result.var
25+
'''],
26+
}
27+
28+
# TODO test grub return disabler
29+
grub_wrapper = find_program('sh/_grubenv-test.sh')
30+
foreach grubtest, testinfo : grubenv_tests
31+
test(testinfo[0], grub_wrapper, args: ['grub-editenv', meson.current_source_dir(), grubtest, testinfo[1].format(efivar)])
32+
endforeach
33+
34+
35+
efivar_tests = {
36+
'test.efivar.l' : 'testing efivar -L',
37+
'test.bootorder.var' : 'testing with BootOrder variable dmpstore generated',
38+
'test.conin.var' : 'testing with ConIn variable dmpstore generated',
39+
}
40+
41+
foreach efivartest, testname : efivar_tests
42+
testprog = find_program('sh/' + efivartest + '.sh')
43+
test(testname, testprog, args: [efivar, meson.current_source_dir()])
44+
endforeach
45+
46+
efisecdb_tests = {
47+
'test.esl.dump.x509.sha256' : 'testing ESL dumping with x509 + sha256 sums',
48+
'test.parse.db' : 'testing parsing db variable',
49+
'test.esl.annotation' : 'testing ESL annotation with x509 + sha256 sums',
50+
'test.esl.sha256.unsorted' : 'testing ESL creation with sha256 sums (unsorted)',
51+
'test.esl.sha256.ascending' : 'testing ESL creation with sha256 sums (ascending)',
52+
'test.esl.sha256.removal.descending' : 'testing ESL entry removal with sha256 sums (descending)',
53+
'test.esl.sha256.addition.unsorted' : 'testing adding a sha256 sum to an existing ESL (unsorted)',
54+
'test.esl.cert.addition' : 'testing ESL entry addition with x509 cert',
55+
'test.esl.cert.removal' : 'testing ESL entry removal with x509 cert'
56+
}
57+
58+
foreach efisectest, testname : efisecdb_tests = {
59+
60+
}
61+
62+
# Threading
63+
# tester.c

tests/sh/_grubenv-test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh -eu
2+
3+
# Usage: editenv dir testname torun
4+
5+
"$1" "${3}.result.env" create
6+
"$1" "${3}.result.env" set debug=all,-scripting,-lexer
7+
truncate -s 512 "${3}.result.env"
8+
eval "$4"
9+
if grep -q "Do not edit" "${3}.result.env" ; then
10+
cmp "${3}.result.var" "${2}/${3}.new.goal.var"
11+
else
12+
cmp "${3}.result.var" "${2}/${3}.old.goal.var"
13+
fi
14+
rm -f "${3}.result."*

tests/sh/test.bootorder.var.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh -eu
2+
3+
"$1" -i "${2}/test.bootorder.var.goal.var" -e test.bootorder.var.0.result.var
4+
"$1" -i test.bootorder.var.0.result.var -e test.bootorder.var.1.result.var -D
5+
cmp "${2}/test.bootorder.var.goal.var" test.bootorder.var.1.result.var

tests/sh/test.conin.var.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh -eu
2+
3+
"$1" -i "${2}/test.conin.var.goal.var" -e test.conin.var.0.result.var
4+
"$1" -i test.conin.var.0.result.var -e test.conin.var.1.result.var -D
5+
cmp "${2}/test.conin.var.goal.var" test.conin.var.1.result.var

tests/sh/test.efivar.l.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh -eu
2+
3+
"$1" -L | grep -q '^{91376aff-cba6-42be-949d-06fde81128e8} {grub} efi_guid_grub GRUB$'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh -eu
2+
3+
"$1" -i "${2}/test.esl.sha256.addition.unsorted.esl.goal" -A > test.esl.dump.x509.sha256.result.txt
4+
cmp "${2}/test.esl.dump.x509.sha256.goal.txt" test.esl.sha256.addition.unsorted.result.txt
5+

0 commit comments

Comments
 (0)