Skip to content

Commit

Permalink
Add test for efivar
Browse files Browse the repository at this point in the history
Signed-off-by: Reagan Bohan <[email protected]>
  • Loading branch information
xbjfk committed May 27, 2022
1 parent 3b57f7f commit d000ee2
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ configure_file(input : 'efivar.spec.in', output : 'efivar.spec', configuration :

subdir('src')
subdir('docs')
subdir('tests')
2 changes: 2 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ efivar = executable('efivar', efivar_sources, gen_guids, install : true, link_wi
efisecdb_sources = ['efisecdb.c', 'secdb-dump.c', 'util.c']
efisecdb = executable('efisecdb', efisecdb_sources, gen_guids, install : true, link_with : [lib_targets['efivar'], lib_targets['efisec']], include_directories : incdir)

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

pkg = import('pkgconfig')

Expand Down
63 changes: 63 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
grubenv_tests = {
'test.dmpstore.export' : ['testing export to DMPSTORE format',
'@0@ -n {grub}-GRUB_ENV -f test.dmpstore.export.result.env -D -e test.dmpstore.export.result.var'],
'test.efivar.export' : ['testing export to libefivar format',
'@0@ -n {grub}-GRUB_ENV -f test.efivar.export.result.env -e test.efivar.export.result.var'],
'test.grubenv.var.0' : ['test importing from DMPSTORE and exporting to DMPSTORE and symbolic guid-name validation',
'''
@0@ -n {grub}-GRUB_ENV -f test.grubenv.var.0.result.env -D -e test.grubenv.var.0.export.var
@0@ -i test.grubenv.var.0.export.var -e test.grubenv.var.0.result.var -D
'''],
'test.grubenv.var.1' : ['test importing from DMPSTORE and exporting to libefivar',
'''
@0@ -n {grub}-GRUB_ENV -f test.grubenv.var.1.result.env -D -e test.grubenv.var.1.export.var
@0@ -i test.grubenv.var.1.export.var -e test.grubenv.var.1.result.var
'''],
'test.grubenv.var.2' : ['test importing from libefivar and exporting to DMPSTORE and mixed-case guid-name validation',
'''
@0@ -n 91376aff-cBa6-42bE-949d-06fde81128e8-GRUB_ENV -f test.grubenv.var.2.result.env -e test.grubenv.var.2.export.var
@0@ -i test.grubenv.var.2.export.var -e test.grubenv.var.2.result.var -D
'''],
'test.grubenv.var.3' : ['test importing from libefivar and exporting to libefivar and guid-name validation',
'''
@0@ -n 91376aff-cba6-42be-949d-06fde81128e8-GRUB_ENV -f test.grubenv.var.3.result.env -e test.grubenv.var.3.export.var
@0@ -i test.grubenv.var.3.export.var -e test.grubenv.var.3.result.var
'''],
}

# TODO test grub return disabler
grub_wrapper = find_program('sh/_grubenv-test.sh')
foreach grubtest, testinfo : grubenv_tests
test(testinfo[0], grub_wrapper, args: ['grub-editenv', meson.current_source_dir(), grubtest, testinfo[1].format(efivar)])
endforeach


efivar_tests = {
'test.efivar.l' : 'testing efivar -L',
'test.bootorder.var' : 'testing with BootOrder variable dmpstore generated',
'test.conin.var' : 'testing with ConIn variable dmpstore generated',
}

foreach efivartest, testname : efivar_tests
testprog = find_program('sh/' + efivartest + '.sh')
test(testname, testprog, args: [efivar, meson.current_source_dir()])
endforeach

efisecdb_tests = {
'test.esl.dump.x509.sha256' : 'testing ESL dumping with x509 + sha256 sums',
'test.parse.db' : 'testing parsing db variable',
'test.esl.annotation' : 'testing ESL annotation with x509 + sha256 sums',
'test.esl.sha256.unsorted' : 'testing ESL creation with sha256 sums (unsorted)',
'test.esl.sha256.ascending' : 'testing ESL creation with sha256 sums (ascending)',
'test.esl.sha256.removal.descending' : 'testing ESL entry removal with sha256 sums (descending)',
'test.esl.sha256.addition.unsorted' : 'testing adding a sha256 sum to an existing ESL (unsorted)',
'test.esl.cert.addition' : 'testing ESL entry addition with x509 cert',
'test.esl.cert.removal' : 'testing ESL entry removal with x509 cert'
}

foreach efisectest, testname : efisecdb_tests = {

}

# Threading
# tester.c
14 changes: 14 additions & 0 deletions tests/sh/_grubenv-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh -eu

# Usage: editenv dir testname torun

"$1" "${3}.result.env" create
"$1" "${3}.result.env" set debug=all,-scripting,-lexer
truncate -s 512 "${3}.result.env"
eval "$4"
if grep -q "Do not edit" "${3}.result.env" ; then
cmp "${3}.result.var" "${2}/${3}.new.goal.var"
else
cmp "${3}.result.var" "${2}/${3}.old.goal.var"
fi
rm -f "${3}.result."*
5 changes: 5 additions & 0 deletions tests/sh/test.bootorder.var.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh -eu

"$1" -i "${2}/test.bootorder.var.goal.var" -e test.bootorder.var.0.result.var
"$1" -i test.bootorder.var.0.result.var -e test.bootorder.var.1.result.var -D
cmp "${2}/test.bootorder.var.goal.var" test.bootorder.var.1.result.var
5 changes: 5 additions & 0 deletions tests/sh/test.conin.var.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh -eu

"$1" -i "${2}/test.conin.var.goal.var" -e test.conin.var.0.result.var
"$1" -i test.conin.var.0.result.var -e test.conin.var.1.result.var -D
cmp "${2}/test.conin.var.goal.var" test.conin.var.1.result.var
3 changes: 3 additions & 0 deletions tests/sh/test.efivar.l.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh -eu

"$1" -L | grep -q '^{91376aff-cba6-42be-949d-06fde81128e8} {grub} efi_guid_grub GRUB$'
5 changes: 5 additions & 0 deletions tests/sh/test.esl.dump.x509.sha256.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh -eu

"$1" -i "${2}/test.esl.sha256.addition.unsorted.esl.goal" -A > test.esl.dump.x509.sha256.result.txt
cmp "${2}/test.esl.dump.x509.sha256.goal.txt" test.esl.sha256.addition.unsorted.result.txt

0 comments on commit d000ee2

Please sign in to comment.