grub2/0360-Make-make-check-work-on-emu.patch
Peter Jones f74b50e380 Rebase to upstream, fix a pile of bugs. The usual.
Signed-off-by: Peter Jones <pjones@redhat.com>
2013-06-12 15:37:08 -04:00

458 lines
14 KiB
Diff

From 02cf7c5e6af716ee3442d387780024c43cf84c5e Mon Sep 17 00:00:00 2001
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Date: Sat, 27 Apr 2013 02:00:16 +0200
Subject: [PATCH 360/482] Make 'make check' work on emu.
---
ChangeLog | 4 +++
grub-core/commands/parttool.c | 2 +-
grub-core/gensymlist.sh | 2 +-
grub-core/kern/dl.c | 3 +++
grub-core/kern/emu/full.c | 12 ++-------
grub-core/kern/emu/lite.c | 13 ++-------
grub-core/kern/emu/main.c | 6 -----
grub-core/normal/main.c | 2 +-
include/grub/emu/misc.h | 2 --
include/grub/misc.h | 6 ++---
tests/cdboot_test.in | 2 ++
tests/fddboot_test.in | 2 ++
tests/hddboot_test.in | 2 ++
tests/netboot_test.in | 2 ++
tests/partmap_test.in | 8 +-----
tests/util/grub-shell.in | 63 ++++++++++++++++++++++++++++++++++++++-----
16 files changed, 82 insertions(+), 49 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 237ca05..f4306c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2013-04-26 Vladimir Serbinenko <phcoder@gmail.com>
+ Make 'make check' work on emu.
+
+2013-04-26 Vladimir Serbinenko <phcoder@gmail.com>
+
Replace libcurses with our own vt100 handling for the ease of testing
and decreasing prerequisites.
diff --git a/grub-core/commands/parttool.c b/grub-core/commands/parttool.c
index 0f9b651..f144c51 100644
--- a/grub-core/commands/parttool.c
+++ b/grub-core/commands/parttool.c
@@ -179,7 +179,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
}
/* Load modules. */
- if (! grub_no_autoload)
+ if (! grub_no_modules)
{
const char *prefix;
prefix = grub_env_get ("prefix");
diff --git a/grub-core/gensymlist.sh b/grub-core/gensymlist.sh
index a13d7cc..5beaabd 100644
--- a/grub-core/gensymlist.sh
+++ b/grub-core/gensymlist.sh
@@ -59,7 +59,7 @@ EOF
| grep -v '^#' \
| sed -n \
-e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/ {"\1", \1, 1},/;p;}' \
- -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/ {"\1", \&\1, 0},/;p;}' \
+ -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/ {"\1", (void *) \&\1, 0},/;p;}' \
| sort -u
cat <<EOF
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
index c6d9ec9..641146d 100644
--- a/grub-core/kern/dl.c
+++ b/grub-core/kern/dl.c
@@ -718,6 +718,9 @@ grub_dl_load (const char *name)
if (mod)
return mod;
+ if (grub_no_modules)
+ return 0;
+
if (! grub_dl_dir) {
grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "prefix");
return 0;
diff --git a/grub-core/kern/emu/full.c b/grub-core/kern/emu/full.c
index b167a14..97d59fd 100644
--- a/grub-core/kern/emu/full.c
+++ b/grub-core/kern/emu/full.c
@@ -24,6 +24,8 @@
#include <grub/emu/misc.h>
#include <grub/disk.h>
+const int grub_no_modules = 1;
+
void
grub_register_exported_symbols (void)
{
@@ -44,12 +46,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
return GRUB_ERR_BAD_MODULE;
}
-void
-grub_emu_init (void)
-{
- grub_no_autoload = 1;
-}
-
#if defined (__ia64__) || defined (__powerpc__)
void grub_arch_dl_get_tramp_got_size (const void *ehdr __attribute__ ((unused)),
grub_size_t *tramp, grub_size_t *got)
@@ -66,7 +62,3 @@ grub_arch_dl_init_linker (void)
}
#endif
-void
-grub_emu_post_init (void)
-{
-}
diff --git a/grub-core/kern/emu/lite.c b/grub-core/kern/emu/lite.c
index 947c669..00b811b 100644
--- a/grub-core/kern/emu/lite.c
+++ b/grub-core/kern/emu/lite.c
@@ -21,6 +21,8 @@
#error "No target cpu type is defined"
#endif
+const int grub_no_modules = 0;
+
/* grub-emu-lite supports dynamic module loading, so it won't have any
embedded modules. */
void
@@ -34,14 +36,3 @@ grub_fini_all (void)
{
return;
}
-
-void
-grub_emu_init (void)
-{
- return;
-}
-
-void
-grub_emu_post_init (void)
-{
-}
diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c
index 4a88905..99ef90c 100644
--- a/grub-core/kern/emu/main.c
+++ b/grub-core/kern/emu/main.c
@@ -55,8 +55,6 @@ static jmp_buf main_env;
/* Store the prefix specified by an argument. */
static char *root_dev = NULL, *dir = NULL;
-int grub_no_autoload;
-
grub_addr_t grub_modbase = 0;
void
@@ -171,7 +169,6 @@ void grub_hostfs_init (void);
void grub_hostfs_fini (void);
void grub_host_init (void);
void grub_host_fini (void);
-void grub_emu_init (void);
int
main (int argc, char *argv[])
@@ -208,7 +205,6 @@ main (int argc, char *argv[])
}
signal (SIGINT, SIG_IGN);
- grub_emu_init ();
grub_console_init ();
grub_host_init ();
@@ -219,8 +215,6 @@ main (int argc, char *argv[])
grub_hostfs_init ();
- grub_emu_post_init ();
-
/* Make sure that there is a root device. */
if (! root_dev)
root_dev = grub_strdup ("host");
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index 9aaa3b2..2f203dd 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -263,7 +263,7 @@ grub_normal_init_page (struct grub_term_output *term)
static void
read_lists (const char *val)
{
- if (! grub_no_autoload)
+ if (! grub_no_modules)
{
read_command_list (val);
read_fs_list (val);
diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h
index 6423eb9..3c9f07e 100644
--- a/include/grub/emu/misc.h
+++ b/include/grub/emu/misc.h
@@ -44,10 +44,8 @@
extern int verbosity;
extern const char *program_name;
-void grub_emu_init (void);
void grub_init_all (void);
void grub_fini_all (void);
-void grub_emu_post_init (void);
void grub_find_zpool_from_dir (const char *dir,
char **poolname, char **poolfs);
diff --git a/include/grub/misc.h b/include/grub/misc.h
index c953a00..c191c1f 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -437,10 +437,10 @@ void grub_halt (void) __attribute__ ((noreturn));
#endif
#ifdef GRUB_MACHINE_EMU
-/* Flag to control module autoloading in normal mode. */
-extern int EXPORT_VAR(grub_no_autoload);
+/* Flag to check if module loading is available. */
+extern const int EXPORT_VAR(grub_no_modules);
#else
-#define grub_no_autoload 0
+#define grub_no_modules 0
#endif
static inline void
diff --git a/tests/cdboot_test.in b/tests/cdboot_test.in
index d9a5fb8..097964f 100644
--- a/tests/cdboot_test.in
+++ b/tests/cdboot_test.in
@@ -20,6 +20,8 @@ grubshell=@builddir@/grub-shell
. "@builddir@/grub-core/modinfo.sh"
case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
+ *-emu)
+ exit 0;;
# Flash targets
i386-qemu | i386-coreboot | mips-qemu_mips | mipsel-qemu_mips)
exit 0;;
diff --git a/tests/fddboot_test.in b/tests/fddboot_test.in
index 7734025..0866fdc 100644
--- a/tests/fddboot_test.in
+++ b/tests/fddboot_test.in
@@ -20,6 +20,8 @@ grubshell=@builddir@/grub-shell
. "@builddir@/grub-core/modinfo.sh"
case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
+ *-emu)
+ exit 0;;
# Flash targets
i386-qemu | i386-coreboot | mips-qemu_mips | mipsel-qemu_mips)
exit 0;;
diff --git a/tests/hddboot_test.in b/tests/hddboot_test.in
index e76f996..34257a3 100644
--- a/tests/hddboot_test.in
+++ b/tests/hddboot_test.in
@@ -20,6 +20,8 @@ grubshell=@builddir@/grub-shell
. "@builddir@/grub-core/modinfo.sh"
case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
+ *-emu)
+ exit 0;;
# Flash targets
i386-qemu | i386-coreboot | mips-qemu_mips | mipsel-qemu_mips)
exit 0;;
diff --git a/tests/netboot_test.in b/tests/netboot_test.in
index 8e3f8c9..aeb1db0 100644
--- a/tests/netboot_test.in
+++ b/tests/netboot_test.in
@@ -20,6 +20,8 @@ grubshell=@builddir@/grub-shell
. "@builddir@/grub-core/modinfo.sh"
case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
+ *-emu)
+ exit 0;;
# Flash targets
i386-qemu | i386-coreboot | mips-qemu_mips | mipsel-qemu_mips)
exit 0;;
diff --git a/tests/partmap_test.in b/tests/partmap_test.in
index b222fa1..2d4b54e 100644
--- a/tests/partmap_test.in
+++ b/tests/partmap_test.in
@@ -49,7 +49,7 @@ list_parts () {
outfile="$1"
shift
- echo ls | "${grubshell}" --qemu-opts="-$qemudisk ${imgfile}" \
+ echo ls | "${grubshell}" --disk="${imgfile}" \
--modules=$mod | tr -d "\n\r" > "${outfile}"
cat "${outfile}"
echo
@@ -58,23 +58,19 @@ list_parts () {
case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
mips-qemu_mips | mipsel-qemu_mips | i386-qemu | i386-multiboot | i386-coreboot | mipsel-loongson)
disk=ata0
- qemudisk=hda
;;
powerpc-ieee1275)
disk=ieee1275//pci@80000000/mac-io@4/ata-3@20000/disk@0
- qemudisk=hda
# FIXME: QEMU firmware has bugs which prevent it from accessing hard disk w/o recognised label.
exit 0
;;
sparc64-ieee1275)
disk=ieee1275//pci@1fe\,0/pci-ata@5/ide0@500/disk@0
- qemudisk=hda
# FIXME: QEMU firmware has bugs which prevent it from accessing hard disk w/o recognised label.
exit 0
;;
i386-ieee1275)
disk=ieee1275/d
- qemudisk=hdb
# FIXME: QEMU firmware has bugs which prevent it from accessing hard disk w/o recognised label.
exit 0
;;
@@ -83,11 +79,9 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
exit 0 ;;
mipsel-arc)
disk=arc/scsi0/disk0/rdisk0
- qemudisk=hda
;;
*)
disk=hd0
- qemudisk=hda
;;
esac
imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index fc52e7b..7c88018 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -44,6 +44,7 @@ Run GRUB script in a Qemu instance.
--boot=[fd|hd|cd|net] boot method for Qemu instance
--modules=MODULES pre-load specified modules MODULES
--qemu=FILE Name of qemu binary
+ --disk=FILE Attach FILE as a disk
--qemu-opts=OPTIONS extra options to pass to Qemu instance
--files=FILES add files to the image
--mkrescue-arg=ARGS additional arguments to grub-mkrescue
@@ -63,7 +64,16 @@ serial_port=com0
serial_null=
halt_cmd=halt
pseries=n
+disk=hda
case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
+ *-emu)
+ device_map=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+ boot=emu
+ console=console
+ disk=0
+ # To skip "Welcome to GRUB" and color setttings
+ trim=1
+ ;;
powerpc-ieee1275)
boot=cd
qemu=qemu-system-ppc
@@ -134,6 +144,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
qemu=qemu-system-i386
console=console
trim=1
+ disk=hdb
;;
i386-qemu)
boot=qemu
@@ -200,6 +211,28 @@ for option in "$@"; do
--qemu-opts=*)
qs=`echo "$option" | sed -e 's/--qemu-opts=//'`
qemuopts="$qemuopts $qs" ;;
+ --disk=*)
+ dsk=`echo "$option" | sed -e 's/--disk=//'`
+ if [ ${grub_modinfo_platform} = emu ]; then
+ echo "(hd$disk) $dsk" >> "$device_map"
+ disk="$((disk+1))"
+ else
+ if [ $disk = error ]; then
+ echo "Too many disks" 1>&2
+ exit 1;
+ fi
+ qemuopts="$qemuopts -$disk $dsk"
+ if [ "$disk" = hda ]; then
+ disk=hdb;
+ elif [ "$disk" = hdb ]; then
+ # CDROM is hdc
+ disk=hdd
+ elif [ "$disk" = hdd ]; then
+ # CDROM is hdc
+ disk=error
+ fi
+ fi
+ ;;
--timeout=*)
timeout=`echo "$option" | sed -e 's/--timeout=//'`
;;
@@ -244,16 +277,27 @@ fi
cfgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
cat <<EOF >${cfgfile}
grubshell=yes
-insmod serial
EOF
+
+
+if [ "${grub_modinfo_platform}" != emu ]; then
+ echo insmod serial >>${cfgfile}
+fi
+
if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = powerpc-ieee1275 ]; then
echo insmod escc >>${cfgfile}
fi
+if [ "${grub_modinfo_platform}" != emu ]; then
+ echo "serial ${serial_port}" >>${cfgfile}
+ term="serial_${serial_port}"
+else
+ term=console
+fi
+
cat <<EOF >>${cfgfile}
-serial ${serial_port}
-terminfo -g 255x255 serial_${serial_port} dumb
-terminal_input serial_${serial_port}
-terminal_output serial_${serial_port}
+terminfo -g 255x255 ${term} dumb
+terminal_input ${term}
+terminal_output ${term}
EOF
trim_head=664cbea8-132f-4770-8aa4-1696d59ac35c
@@ -270,7 +314,7 @@ do
done
cat <<EOF >>${cfgfile}
-source /boot/grub/testcase.cfg
+source \$prefix/testcase.cfg
# Stop serial output to suppress "ACPI shutdown failed" error.
EOF
if [ x$console != x ]; then
@@ -279,7 +323,7 @@ fi
echo "${halt_cmd}" >>${cfgfile}
isofile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
-if [ x$boot != xnet ]; then
+if [ x$boot != xnet ] && [ x$boot != xemu ]; then
pkgdatadir="@builddir@" sh "@builddir@/grub-mkrescue" "--grub-mkimage=${builddir}/grub-mkimage" "--grub-render-label=${builddir}/grub-render-label" "--output=${isofile}" "--override-directory=${builddir}/grub-core" \
--rom-directory="${rom_directory}" ${mkrescue_args} \
"/boot/grub/grub.cfg=${cfgfile}" "/boot/grub/testcase.cfg=${source}" \
@@ -354,6 +398,11 @@ if [ x$boot = xnet ]; then
cp "${cfgfile}" "$netdir/boot/grub/grub.cfg"
cp "${source}" "$netdir/boot/grub/testcase.cfg"
timeout -s KILL $timeout "${qemu}" ${qemuopts} -nographic ${serial_null} -serial file:/dev/stdout -monitor file:/dev/null -boot n -net "user,tftp=$netdir,bootfile=/boot/grub/${grub_modinfo_target_cpu}-${grub_modinfo_platform}/core.$netbootext" -net nic | cat | tr -d "\r" | do_trim
+elif [ x$boot = xemu ]; then
+ grubdir="$(mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")"
+ cp "${cfgfile}" "$grubdir/grub.cfg"
+ cp "${source}" "$grubdir/testcase.cfg"
+ @builddir@/grub-core/grub-emu -m "$device_map" -d "$grubdir" | tr -d "\r" | do_trim
else
timeout -s KILL $timeout "${qemu}" ${qemuopts} -nographic ${serial_null} -serial file:/dev/stdout -monitor file:/dev/null -${device} ${isofile} ${bootdev} | cat | tr -d "\r" | do_trim
fi
--
1.8.2.1