tests: run tests for each arch
Since we can sign i386 PE/COFF images, run the tests on both x86-64 and i386 binaries. We do this by moving test.pecoff to test-<arch>.pecoff, and using automake's parallel-test option to add a wrapper to each test execution. This wrapper calls each test once per arch (as defined in TEST_ARCHES), and checks for failures in any invocation. Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
This commit is contained in:
parent
e1b58d6ccb
commit
1187df3459
18 changed files with 136 additions and 59 deletions
|
@ -1,32 +1,39 @@
|
|||
|
||||
AUTOMAKE_OPTIONS = parallel-tests
|
||||
|
||||
test_key = private-key.rsa
|
||||
test_cert = public-cert.pem
|
||||
test_image = test.pecoff
|
||||
test_arches = x86_64 i386
|
||||
test_images = test-x86_64.pecoff test-i386.pecoff
|
||||
|
||||
check_PROGRAMS = test.pecoff
|
||||
check_PROGRAMS = test-x86_64.pecoff test-i386.pecoff
|
||||
check_DATA = $(test_key) $(test_cert)
|
||||
check_SCRIPTS = common.sh
|
||||
check_SCRIPTS = test-wrapper.sh
|
||||
|
||||
test_image_arch = x86-64
|
||||
test_lds = $(srcdir)/test.lds
|
||||
test_i386_pecoff_SOURCES = test.S test-i386.lds
|
||||
test_x86_64_pecoff_SOURCES = test.S test-x86_64.lds
|
||||
|
||||
test_pecoff_SOURCES =
|
||||
|
||||
test.pecoff: test.elf
|
||||
test-%.pecoff: test-%.elf
|
||||
$(OBJCOPY) -j .text -j .sdata -j .data \
|
||||
-j .dynamic -j .dynsym -j .rel \
|
||||
-j .rela -j .reloc \
|
||||
--target=efi-app-$(test_image_arch) $^ $@
|
||||
$(STRIP) $@
|
||||
|
||||
test.elf: LDFLAGS = -nostdlib -T $(test_lds) -m64
|
||||
test.elf: test.$(OBJEXT) $(test_lds)
|
||||
test-x86_64.pecoff: test_image_arch = x86-64
|
||||
test-x86_64.pecoff: test_lds = $(srcdir)/test-x86_64.lds
|
||||
test-x86_64.pecoff: ASFLAGS += -m64
|
||||
test-x86_64.pecoff: LDFLAGS += -m64
|
||||
test-i386.pecoff: test_image_arch = i386
|
||||
test-i386.pecoff: test_lds = $(srcdir)/test-i386.lds
|
||||
test-i386.pecoff: ASFLAGS += -m32
|
||||
test-i386.pecoff: LDFLAGS += -m32
|
||||
|
||||
test-%.elf: LDFLAGS = -nostdlib -T $(test_lds)
|
||||
test-%.elf: test-%.$(OBJEXT) $(test_lds)
|
||||
$(LINK) $<
|
||||
|
||||
.INTERMEDIATE: test.elf
|
||||
|
||||
test.$(OBJEXT): ASFLAGS = -m64
|
||||
test.$(OBJEXT): $(srcdir)/test.S
|
||||
test-%.$(OBJEXT): $(srcdir)/test.S
|
||||
$(COMPILE.S) -o $@ $^
|
||||
|
||||
$(test_key): Makefile
|
||||
|
@ -49,5 +56,8 @@ TESTS = sign-verify.sh \
|
|||
resign-warning.sh \
|
||||
reattach-warning.sh
|
||||
|
||||
TEST_EXTENSIONS = .sh
|
||||
SH_LOG_COMPILER = TEST_ARCHES="$(test_arches)" $(srcdir)/test-wrapper.sh
|
||||
|
||||
EXTRA_DIST = $(test_lds) test.S $(TESTS) $(check_SCRIPTS)
|
||||
CLEANFILES = $(test_key) $(test_cert) $(test_image)
|
||||
CLEANFILES = $(test_key) $(test_cert) $(test_images)
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
# Parse the data directory of a PE/COFF file and returns two hex values:
|
||||
# the file offset and size of the signature table.
|
||||
function sigtable_params() {
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
|
||||
basedir=$(cd $srcdir && pwd)
|
||||
datadir=$(pwd)
|
||||
bindir="$datadir/.."
|
||||
|
||||
sbsign=$bindir/sbsign
|
||||
sbverify=$bindir/sbverify
|
||||
sbattach=$bindir/sbattach
|
||||
|
||||
key="$datadir/private-key.rsa"
|
||||
cert="$datadir/public-cert.pem"
|
||||
image="$datadir/test.pecoff"
|
||||
|
||||
tempdir=$(mktemp --directory)
|
||||
exit_trap='rm -rf $tempdir'
|
||||
trap "$exit_trap" EXIT
|
||||
|
||||
cd "$tempdir"
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
signed="test.signed"
|
||||
sig="test.sig"
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
signed="test.signed"
|
||||
|
||||
"$sbsign" --cert "$cert" --key "$key" --output "$signed" "$image"
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
sig="test.sig"
|
||||
signed="test.signed"
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
signed="test.signed"
|
||||
sig="test.sig"
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
invsig="test.invsig"
|
||||
dd if=/dev/zero of="$invsig" bs=1 count=1k
|
||||
tmp_image=test.pecoff
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
signed="test.signed"
|
||||
|
||||
set +e
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
signed="test.signed"
|
||||
|
||||
set +e
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
signed="test.signed"
|
||||
|
||||
set +e
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
sig="test.sig"
|
||||
|
||||
"$sbsign" --cert "$cert" --key "$key" --detached --output $sig "$image"
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
signed="test.signed"
|
||||
|
||||
"$sbsign" --cert "$cert" --key "$key" --output "$signed" "$image"
|
||||
|
|
59
tests/test-i386.lds
Normal file
59
tests/test-i386.lds
Normal file
|
@ -0,0 +1,59 @@
|
|||
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
|
||||
OUTPUT_ARCH(i386)
|
||||
ENTRY(_start)
|
||||
SECTIONS
|
||||
{
|
||||
. = 0;
|
||||
ImageBase = .;
|
||||
.hash : { *(.hash) } /* this MUST come first! */
|
||||
. = ALIGN(4096);
|
||||
.eh_frame :
|
||||
{
|
||||
*(.eh_frame)
|
||||
}
|
||||
. = ALIGN(4096);
|
||||
.text :
|
||||
{
|
||||
*(.text)
|
||||
}
|
||||
. = ALIGN(4096);
|
||||
.reloc :
|
||||
{
|
||||
*(.reloc)
|
||||
}
|
||||
. = ALIGN(4096);
|
||||
.data :
|
||||
{
|
||||
*(.rodata*)
|
||||
*(.got.plt)
|
||||
*(.got)
|
||||
*(.data*)
|
||||
*(.sdata)
|
||||
/* the EFI loader doesn't seem to like a .bss section, so we stick
|
||||
it all into .data: */
|
||||
*(.sbss)
|
||||
*(.scommon)
|
||||
*(.dynbss)
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
*(.rel.local)
|
||||
}
|
||||
. = ALIGN(4096);
|
||||
.dynamic : { *(.dynamic) }
|
||||
. = ALIGN(4096);
|
||||
.rela :
|
||||
{
|
||||
*(.rela.data*)
|
||||
*(.rela.got)
|
||||
*(.rela.stab)
|
||||
}
|
||||
. = ALIGN(4096);
|
||||
.dynsym : { *(.dynsym) }
|
||||
. = ALIGN(4096);
|
||||
.dynstr : { *(.dynstr) }
|
||||
. = ALIGN(4096);
|
||||
.ignored.reloc :
|
||||
{
|
||||
*(.rela.reloc)
|
||||
}
|
||||
}
|
52
tests/test-wrapper.sh
Executable file
52
tests/test-wrapper.sh
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/bin/bash
|
||||
|
||||
# set a few global variables that may be used by the test
|
||||
basedir=$(cd $srcdir && pwd)
|
||||
datadir=$(pwd)
|
||||
bindir="$datadir/.."
|
||||
|
||||
sbsign=$bindir/sbsign
|
||||
sbverify=$bindir/sbverify
|
||||
sbattach=$bindir/sbattach
|
||||
|
||||
key="$datadir/private-key.rsa"
|
||||
cert="$datadir/public-cert.pem"
|
||||
|
||||
export basedir datadir bindir sbsign sbverify sbattach key cert
|
||||
|
||||
# 'test' needs to be an absolute path, as we will cd to a temporary
|
||||
# directory before running the test
|
||||
test="$PWD/$1"
|
||||
rc=0
|
||||
|
||||
function run_test()
|
||||
{
|
||||
test="$1"
|
||||
|
||||
# image depends on the test arch
|
||||
image="$datadir/test-$arch.pecoff"
|
||||
export image
|
||||
|
||||
# create the temporary directory...
|
||||
tempdir=$(mktemp --directory)
|
||||
|
||||
# ... and run the test in it.
|
||||
( cd "$tempdir"; $test )
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "test $(basename $test) failed on arch $arch"
|
||||
echo
|
||||
rc=1
|
||||
fi
|
||||
|
||||
rm -rf "$tempdir"
|
||||
}
|
||||
|
||||
# run test on all available arches
|
||||
for arch in $TEST_ARCHES
|
||||
do
|
||||
run_test $test
|
||||
done
|
||||
|
||||
exit $rc
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
signed="test.signed"
|
||||
|
||||
"$sbsign" --cert "$cert" --key "$key" --output "$signed" "$image"
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
. "$srcdir/common.sh"
|
||||
|
||||
signed="test.signed"
|
||||
|
||||
set +e
|
||||
|
|
Loading…
Reference in a new issue