diff --git a/meson.build b/meson.build index 749ce028..f486aa86 100644 --- a/meson.build +++ b/meson.build @@ -7,3 +7,4 @@ configure_file(input : 'efivar.spec.in', output : 'efivar.spec', configuration : subdir('src') subdir('docs') +subdir('tests') diff --git a/src/meson.build b/src/meson.build index ab2ddc38..034a0062 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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') diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 00000000..8643d9bf --- /dev/null +++ b/tests/meson.build @@ -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 diff --git a/tests/sh/_grubenv-test.sh b/tests/sh/_grubenv-test.sh new file mode 100644 index 00000000..6af7df64 --- /dev/null +++ b/tests/sh/_grubenv-test.sh @@ -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."* diff --git a/tests/sh/test.bootorder.var.sh b/tests/sh/test.bootorder.var.sh new file mode 100644 index 00000000..ef334ac6 --- /dev/null +++ b/tests/sh/test.bootorder.var.sh @@ -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 diff --git a/tests/sh/test.conin.var.sh b/tests/sh/test.conin.var.sh new file mode 100644 index 00000000..773af3cc --- /dev/null +++ b/tests/sh/test.conin.var.sh @@ -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 diff --git a/tests/sh/test.efivar.l.sh b/tests/sh/test.efivar.l.sh new file mode 100644 index 00000000..7be26d59 --- /dev/null +++ b/tests/sh/test.efivar.l.sh @@ -0,0 +1,3 @@ +#!/bin/sh -eu + +"$1" -L | grep -q '^{91376aff-cba6-42be-949d-06fde81128e8} {grub} efi_guid_grub GRUB$' diff --git a/tests/sh/test.esl.dump.x509.sha256.sh b/tests/sh/test.esl.dump.x509.sha256.sh new file mode 100644 index 00000000..12f1e100 --- /dev/null +++ b/tests/sh/test.esl.dump.x509.sha256.sh @@ -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 +