I got part way to fixing this using libx86emu (not libx86, that's not flexible enough).
I ended up having to mess with the autotooling quite a bit, and I think I need to add back a feature test because libx86emu is not available on all architectures. But I got the tests running and passing on amd64. I'm attaching a patch with all my changes. Not tagging this +patch because it's not finished. Ben. -- Ben Hutchings To err is human; to really foul things up requires a computer.
diff -u mbr-1.1.11/Makefile.am mbr-1.1.11/Makefile.am --- mbr-1.1.11/Makefile.am +++ mbr-1.1.11/Makefile.am @@ -4,17 +4,12 @@ AUTOCONF=autoconf2.50 AUTOHEADER=autoheader2.50 -if HAVE_VM86 SUBDIRS = harness -else -SUBDIRS = -endif sbin_PROGRAMS = install-mbr install_mbr_SOURCES = install-mbr.c mbr.S86 mbr.h install_mbr_LDADD = mbr.o y2k.o noinst_DATA = testdisk.b -noinst_SCRIPTS = wraptest AS86 = as86 LD86 = ld86 @@ -23,9 +18,12 @@ man_MANS = install-mbr.8 -TESTS = tests/inst-1 tests/inst-3 \ - tests/inst-4 tests/inst-6 tests/inst-7 tests/inst-8 -TESTS_ENVIRONMENT = sh wraptest +TESTS = tests/inst-1 tests/inst-2 tests/inst-3 \ + tests/inst-4 tests/inst-6 tests/inst-7 tests/inst-8 \ + tests/mbr-1 tests/mbr-2 tests/mbr-3 tests/mbr-4 \ + tests/mbr-5 tests/mbr-6 \ + tests/testdisk-1 tests/testdisk-2 tests/testdisk-3 \ + tests/testdisk-4 tests/testdisk-5 tests/testdisk-6 check_DATA = \ table.b \ @@ -33,8 +31,8 @@ EXTRA_DIST = table.S86 historic,v ${TESTS} ${man_MANS} -CLEANFILES = *.b *.s86 *.o86 *.lst *.sym test.* test-* \ - mbr-?.?.?.S86 +CLEANFILES = *.b *.s86 *.o86 *.lst *.sym test.* test-img test-mbr test-mbr-l \ + test-mbr-u test-new test-old test-x test-y mbr-?.?.?.S86 SUFFIXES = .b .S86 .s86 diff -u mbr-1.1.11/harness/Makefile.am mbr-1.1.11/harness/Makefile.am --- mbr-1.1.11/harness/Makefile.am +++ mbr-1.1.11/harness/Makefile.am @@ -1,7 +1,6 @@ noinst_PROGRAMS = harness harness_SOURCES = \ harness.h \ - vm86.h \ args.c \ bios.c \ event.c \ @@ -13,3 +12,5 @@ - vm86.c + x86emu.c +harness_LDADD = -lx86emu + +AM_CFLAGS = -Wall -Wstrict-prototypes -Wmissing-prototypes -g -AM_CFLAGS = -Wall -Wstrict-prototypes -Wmissing-prototypes -g -m32 diff -u mbr-1.1.11/debian/changelog mbr-1.1.11/debian/changelog --- mbr-1.1.11/debian/changelog +++ mbr-1.1.11/debian/changelog @@ -1,3 +1,16 @@ +mbr (1.1.11-5.1) UNRELEASED; urgency=medium + + * Non-maintainer upload + * Use libx86emu instead of vm86 to run tests. Closes: #792126. + * Enable running all tests on all architectures, except inst-5 and version + * Run autoreconf + * As automake now uses the test-driver script, wraptest no longer works. + Replace it with a shell library (tests/setup), sourced by each test. + * Remove specific temporary files, not test-*, so that we preserve the + test-driver script + + -- Ben Hutchings <b...@decadent.org.uk> Wed, 29 Jun 2016 22:36:54 +0200 + mbr (1.1.11-5) unstable; urgency=low * Add dh_md5sums to debian/rules, thanks to jmccrohan. Closes: #672321. diff -u mbr-1.1.11/debian/control mbr-1.1.11/debian/control --- mbr-1.1.11/debian/control +++ mbr-1.1.11/debian/control @@ -3,7 +3,7 @@ Priority: optional Maintainer: Santiago Garcia Mantinan <ma...@debian.org> Standards-Version: 3.9.3 -Build-Depends: debhelper(>= 7), bin86, util-linux (>= 2.13) | linux32 +Build-Depends: debhelper(>= 7), bin86, libx86emu-dev Package: mbr Architecture: any diff -u mbr-1.1.11/debian/rules mbr-1.1.11/debian/rules --- mbr-1.1.11/debian/rules +++ mbr-1.1.11/debian/rules @@ -1,7 +1,5 @@ #!/usr/bin/make -f -KERNEL_ARCH := $(shell linux64 uname -m) - CC := gcc -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 CFLAGS := -g -Wall -W @@ -20,24 +18,23 @@ build-indep: build-stamp -build-stamp: +configure-stamp: + AUTOMAKE='automake --add-missing' autoreconf ./configure --exec-prefix=`pwd`/debian/mbr/ --prefix=`pwd`/debian/mbr/usr + touch $@ + +build-stamp: configure-stamp $(MAKE) CC="$(CC)" LD="$(LD)" CFLAGS="$(CFLAGS)" -ifneq (,$(findstring x86_64,$(KERNEL_ARCH))) - # Limit the tests on x86_64 kernels -else ifeq (i386,$(DEB_BUILD_ARCH)) $(MAKE) check -else - # Limit the tests on non i386 -endif - touch build + touch $@ clean: dh_testdir dh_testroot dh_clean [ ! -f Makefile ] || $(MAKE) distclean - rm -f build + rm -f aclocal.m4 build compile configure harness/Makefile.in \ + Makefile.in test-driver install: build dh_testdir only in patch2: unchanged: --- mbr-1.1.11.orig/configure.in +++ mbr-1.1.11/configure.in @@ -7,10 +7,4 @@ AC_PROG_CC -dnl I'm not sure if the number of brackets needed for this is -dnl well-defined... -AM_CONDITIONAL(HAVE_VM86, [[uname -m | grep -q 'i[0-9]86']]) - -AC_CONFIG_FILES([wraptest]) - AC_OUTPUT(Makefile harness/Makefile) only in patch2: unchanged: --- mbr-1.1.11.orig/harness/x86emu.c +++ mbr-1.1.11/harness/x86emu.c @@ -0,0 +1,170 @@ +#include <asm/unistd.h> +#include <asm/vm86.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <signal.h> +#include <x86emu.h> +#include "harness.h" + +static x86emu_t *x86emu; +static int x86emu_debugging = 0; + +/* The purpose of this file is to run real mode code using libbx86emu. */ + +static void dump(void) +{ + unsigned int eflags = x86emu->x86.R_EFLG; + /* Format: + * eax:00000000 ebx:00000000 ecx:00000000 edx:00000000 PC:0000:00000000 + * esi:00000000 edi:00000000 ebp:00000000 efl:00000000 SP:0000:00000000 + * ds:0000 es:0000 fs:0000 gs:0000 + */ + outputf("eax:%08x ebx:%08x ecx:%08x edx:%08x PC:%04x:%08x\n", + x86emu->x86.R_EAX, x86emu->x86.R_EBX, x86emu->x86.R_ECX, x86emu->x86.R_EDX, + x86emu->x86.R_CS, x86emu->x86.R_EIP); + outputf("esi:%08x edi:%08x ebp:%08x efl:%08x SP:%04x:%08x\n", + x86emu->x86.R_ESI, x86emu->x86.R_EDI, x86emu->x86.R_EBP, eflags, + x86emu->x86.R_SS, x86emu->x86.R_ESP); + outputf("ds:%04x es:%04x fs:%04x gs:%04x", + x86emu->x86.R_DS, x86emu->x86.R_ES, x86emu->x86.R_FS, x86emu->x86.R_GS); + outputf(" FLAGS: %s %s %s %s %s %s %s %s %s\n", + (eflags & F_CF ? "C" : "c"), + (eflags & F_PF ? "P" : "p"), + (eflags & F_AF ? "A" : "a"), + (eflags & F_ZF ? "Z" : "z"), + (eflags & F_SF ? "S" : "s"), + (eflags & F_TF ? "T" : "t"), + (eflags & F_IF ? "I" : "i"), + (eflags & F_DF ? "D" : "d"), + (eflags & F_OF ? "O" : "o")); +} + +static void x86emu_to_vm86_regs(const x86emu_t *x86emu, struct vm86plus_struct *vm86) +{ + vm86->regs.ebx = x86emu->x86.R_EBX; + vm86->regs.ecx = x86emu->x86.R_ECX; + vm86->regs.edx = x86emu->x86.R_EDX; + vm86->regs.esi = x86emu->x86.R_ESI; + vm86->regs.edi = x86emu->x86.R_EDI; + vm86->regs.ebp = x86emu->x86.R_EBP; + vm86->regs.eax = x86emu->x86.R_EAX; + vm86->regs.eip = x86emu->x86.R_EIP; + vm86->regs.cs = x86emu->x86.R_CS; + vm86->regs.eflags = x86emu->x86.R_EFLG; + vm86->regs.esp = x86emu->x86.R_ESP; + vm86->regs.es = x86emu->x86.R_ES; + vm86->regs.ds = x86emu->x86.R_DS; + vm86->regs.fs = x86emu->x86.R_FS; + vm86->regs.gs = x86emu->x86.R_GS; +} + +static void vm86_to_x86emu_regs(const struct vm86plus_struct *vm86, x86emu_t *x86emu) +{ + x86emu->x86.R_EBX = vm86->regs.ebx; + x86emu->x86.R_ECX = vm86->regs.ecx; + x86emu->x86.R_EDX = vm86->regs.edx; + x86emu->x86.R_ESI = vm86->regs.esi; + x86emu->x86.R_EDI = vm86->regs.edi; + x86emu->x86.R_EBP = vm86->regs.ebp; + x86emu->x86.R_EAX = vm86->regs.eax; + x86emu->x86.R_EIP = vm86->regs.eip; + x86emu->x86.R_CS = vm86->regs.cs; + x86emu->x86.R_EFLG = vm86->regs.eflags; + x86emu->x86.R_ESP = vm86->regs.esp; + x86emu->x86.R_ES = vm86->regs.es; + x86emu->x86.R_DS = vm86->regs.ds; + x86emu->x86.R_FS = vm86->regs.fs; + x86emu->x86.R_GS = vm86->regs.gs; +} + +static int intr_handler(x86emu_t *x86emu, u8 num, unsigned type) +{ + struct vm86plus_struct vm86 = {}; + int handled = 0; + + x86emu_to_vm86_regs(x86emu, &vm86); + + tick(); + switch (num) + { + case 0x10: + handled = handle_int_10(&vm86); + break; + + case 0x13: + handled = handle_int_13(&vm86); + break; + + case 0x16: + handled = handle_int_16(&vm86); + break; + + case 0x1a: + handled = handle_int_1a(&vm86); + break; + + case 0xf2: + return 1; + + case 0xe4: /* Exit */ + handle_int_e4(&vm86); + vm86_to_x86emu_regs(&vm86, x86emu); + dump(); + x86emu_stop(x86emu); + return 1; + } + + vm86_to_x86emu_regs(&vm86, x86emu); + + if (!handled) { + outputf("INT 0x%x at %04x:%04x\n", num, x86emu->x86.R_CS, x86emu->x86.R_EIP); + dump(); + } + + return handled; +} + +void vm86_run() +{ + unsigned addr; + + if (!x86emu) + { + x86emu = x86emu_new(X86EMU_PERM_RWX | X86EMU_PERM_VALID, X86EMU_PERM_RW); + for (addr = 0; addr < (1 << 20); addr += X86EMU_PAGE_SIZE) + x86emu_set_page(x86emu, addr, (void *)addr); + x86emu_set_intr_handler(x86emu, intr_handler); + } + + if (x86emu_debugging) + { + outputf("Entering real mode emulation at %04x:%04x.\n", + x86emu->x86.R_CS, x86emu->x86.R_EIP); + dump(); + } + + if (x86emu->x86.R_EFLG & F_TF) { + /* TF is not emulated properly, so set maximum number of instructions */ + x86emu->max_instr = 1; + x86emu_run(x86emu, X86EMU_RUN_MAX_INSTR); + } else { + x86emu_run(x86emu, 0); + } +} + +void set_pc(unsigned long cs, unsigned long ip) +{ + x86emu->x86.R_CS = cs; + x86emu->x86.R_IP = ip; +} + +void vm86_debug() +{ + x86emu_debugging = 1; +} + +void vm86_step() +{ + x86emu->x86.R_EFLG |= F_TF; +} diff -u mbr-1.1.11/tests/inst-1 mbr-1.1.11/tests/inst-1 --- mbr-1.1.11/tests/inst-1 +++ mbr-1.1.11/tests/inst-1 @@ -1,6 +1,7 @@ #! /bin/sh # Basic installation tests. set -e +. tests/setup dd if=/dev/zero of=test-old bs=510 count=1 2>/dev/null printf '\125\252' >>test-old only in patch2: unchanged: --- mbr-1.1.11.orig/tests/inst-2 +++ mbr-1.1.11/tests/inst-2 @@ -1,5 +1,6 @@ #! /bin/sh # Test the -I option without -r +. tests/setup dd if=test-old of=test-mbr 2>/dev/null do_install -I mbr-1.1.2.b -d 0xf0 -t 249 -p 1 -i s -e 3 test-mbr dd if=test-mbr of=test-new 2>/dev/null only in patch2: unchanged: --- mbr-1.1.11.orig/tests/inst-3 +++ mbr-1.1.11/tests/inst-3 @@ -1,5 +1,6 @@ #! /bin/sh # Test the new --y2k options +. tests/setup dd if=test-old of=test-mbr 2>/dev/null do_install -y -d 0xb3 -t 132 -p 3 -i n -e 14 test-mbr do_install -l test-mbr >test-y only in patch2: unchanged: --- mbr-1.1.11.orig/tests/inst-4 +++ mbr-1.1.11/tests/inst-4 @@ -1,5 +1,5 @@ #! /bin/sh - +. tests/setup dd if=test-old of=test-mbr 2>/dev/null do_install -f /dev/zero -l -e+ >test-y cat <<EOF >test-x only in patch2: unchanged: --- mbr-1.1.11.orig/tests/inst-5 +++ mbr-1.1.11/tests/inst-5 @@ -1,6 +1,7 @@ #! /bin/sh set -e # Test installing old versions. +. tests/setup cat <<EOF >test-x Version: 0 Compatible: 0 only in patch2: unchanged: --- mbr-1.1.11.orig/tests/inst-6 +++ mbr-1.1.11/tests/inst-6 @@ -1,5 +1,5 @@ #! /bin/sh - +. tests/setup # BUG: The -y option is not maintained from one version to another. dd if=test-old of=test-mbr 2>/dev/null only in patch2: unchanged: --- mbr-1.1.11.orig/tests/inst-7 +++ mbr-1.1.11/tests/inst-7 @@ -1,5 +1,5 @@ #! /bin/sh - +. tests/setup # BUG: running install-mbr -t 20 --list /dev/hda changes the mbr, # while running install-mbr -y --list /dev/hda doesn't) only in patch2: unchanged: --- mbr-1.1.11.orig/tests/inst-8 +++ mbr-1.1.11/tests/inst-8 @@ -1,5 +1,5 @@ #! /bin/sh - +. tests/setup # BUG: running install-mbr -I y2k.b /dev/hda fails. We should fail if # the Y2K setting is explicitly requested. only in patch2: unchanged: --- mbr-1.1.11.orig/tests/mbr-1 +++ mbr-1.1.11/tests/mbr-1 @@ -5,6 +5,7 @@ # Timeout: 9 # Interrupt: Shift / Key # Enable: 1 +. tests/setup do_install -d 0x80 -p 3 -t 9 -isk -e1 test-mbr # Boots the default cat <<EOF >test-x only in patch2: unchanged: --- mbr-1.1.11.orig/tests/mbr-2 +++ mbr-1.1.11/tests/mbr-2 @@ -1,5 +1,6 @@ #! /bin/sh # Check floppy booting. Small disk interface. +. tests/setup cat <<EOF >test-x Version: 2 Compatible: 2 only in patch2: unchanged: --- mbr-1.1.11.orig/tests/mbr-3 +++ mbr-1.1.11/tests/mbr-3 @@ -1,5 +1,6 @@ #! /bin/sh # Check the large disk interface, boots partition 3. +. tests/setup do_install -d 0x80 -p 3 -t 5 -isk -e1 test-mbr # Boots partition 3. cat <<EOF >test-x only in patch2: unchanged: --- mbr-1.1.11.orig/tests/mbr-4 +++ mbr-1.1.11/tests/mbr-4 @@ -1,5 +1,6 @@ #! /bin/sh # Check interrupted booting, boots floppy. +. tests/setup cat <<EOF >test-x Version: 2 Compatible: 2 only in patch2: unchanged: --- mbr-1.1.11.orig/tests/mbr-5 +++ mbr-1.1.11/tests/mbr-5 @@ -1,5 +1,6 @@ #! /bin/sh # Check long delays, boots partition 2. +. tests/setup cat <<EOF >test-x Version: 2 Compatible: 2 only in patch2: unchanged: --- mbr-1.1.11.orig/tests/mbr-6 +++ mbr-1.1.11/tests/mbr-6 @@ -1,5 +1,6 @@ #! /bin/sh # Check long delays, boots floppy. +. tests/setup cat <<EOF >test-x Version: 2 Compatible: 2 only in patch2: unchanged: --- mbr-1.1.11.orig/tests/setup +++ mbr-1.1.11/tests/setup @@ -0,0 +1,20 @@ +do_cmp () { + local X Y ; X=$1 ; Y=$2 ; shift ; shift + dd if=$X of=test-x "$@" 2>/dev/null + dd if=$Y of=test-y "$@" 2>/dev/null + cmp test-x test-y +} + +do_install () { + ./install-mbr "$@" +} + +harness () { + harness/harness "$@" +} + +rm -f test-img test-mbr test-mbr-l test-mbr-u test-new test-old test-x test-y + +dd if=/dev/zero of=test-old bs=510 count=1 2>/dev/null +printf '\125\252' >>test-old +dd if=table.b of=test-mbr bs=512 count=1 2>/dev/null only in patch2: unchanged: --- mbr-1.1.11.orig/tests/testdisk-1 +++ mbr-1.1.11/tests/testdisk-1 @@ -5,6 +5,7 @@ # Timeout: 9 # Interrupt: Shift / Key # Enable: 1 +. tests/setup do_install -I testdisk.b -d 0x80 -p 3 -t 9 -isk -e1 test-mbr # Boots the default cat <<EOF >test-x only in patch2: unchanged: --- mbr-1.1.11.orig/tests/testdisk-2 +++ mbr-1.1.11/tests/testdisk-2 @@ -1,5 +1,6 @@ #! /bin/sh # Check floppy booting. Small disk interface. +. tests/setup cat <<EOF >test-x Version: 2 Compatible: 2 only in patch2: unchanged: --- mbr-1.1.11.orig/tests/testdisk-3 +++ mbr-1.1.11/tests/testdisk-3 @@ -1,5 +1,6 @@ #! /bin/sh # Check the large disk interface, boots partition 3. +. tests/setup do_install -I testdisk.b -d 0x80 -p 3 -t 5 -isk -e1 test-mbr # Boots partition 3. cat <<EOF >test-x only in patch2: unchanged: --- mbr-1.1.11.orig/tests/testdisk-4 +++ mbr-1.1.11/tests/testdisk-4 @@ -1,5 +1,6 @@ #! /bin/sh # Check interrupted booting, boots floppy. +. tests/setup cat <<EOF >test-x Version: 2 Compatible: 2 only in patch2: unchanged: --- mbr-1.1.11.orig/tests/testdisk-5 +++ mbr-1.1.11/tests/testdisk-5 @@ -1,5 +1,6 @@ #! /bin/sh # Check long delays, boots partition 2. +. tests/setup cat <<EOF >test-x Version: 2 Compatible: 2 only in patch2: unchanged: --- mbr-1.1.11.orig/tests/testdisk-6 +++ mbr-1.1.11/tests/testdisk-6 @@ -1,5 +1,6 @@ #! /bin/sh # Check long delays, boots floppy. +. tests/setup cat <<EOF >test-x Version: 2 Compatible: 2 only in patch2: unchanged: --- mbr-1.1.11.orig/tests/version +++ mbr-1.1.11/tests/version @@ -1,4 +1,5 @@ #! /bin/sh +. tests/setup function check_version { md5sum mbr-$1.b >test-y echo "$2 mbr-$1.b" >test-x
signature.asc
Description: This is a digitally signed message part