diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:29:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:29:51 +0000 |
commit | 6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e (patch) | |
tree | 32451fa3cdd9321fb2591fada9891b2cb70a9cd1 /tests | |
parent | Initial commit. (diff) | |
download | grub2-upstream/2.06.tar.xz grub2-upstream/2.06.zip |
Adding upstream version 2.06.upstream/2.06upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
110 files changed, 6413 insertions, 0 deletions
diff --git a/tests/ahci_test.in b/tests/ahci_test.in new file mode 100644 index 0000000..7df5604 --- /dev/null +++ b/tests/ahci_test.in @@ -0,0 +1,53 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # PLATFORM: Don't mess with real devices when OS is active + *-emu) + exit 0;; + # FIXME: qemu gets bonito DMA wrong + mipsel-loongson) + exit 0;; + # PLATFORM: no AHCI on ARC and qemu-mips platforms + mips*-arc | mips*-qemu_mips) + exit 0;; + # FIXME: No native drivers are available for those + powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi) + exit 0;; +esac + +imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 + +echo "hello" > "$outfile" + +tar cf "$imgfile" "$outfile" + +if [ "$(echo "nativedisk; source '(ahci0)/$outfile';" | "${grubshell}" --qemu-opts="-drive id=disk,file=$imgfile,if=none -device ahci,id=ahci -device ide-drive,drive=disk,bus=ahci.0 " | tail -n 1)" != "Hello World" ]; then + rm "$imgfile" + rm "$outfile" + exit 1 +fi + +rm "$imgfile" +rm "$outfile" + + diff --git a/tests/btrfs_test.in b/tests/btrfs_test.in new file mode 100644 index 0000000..0c9bf3a --- /dev/null +++ b/tests/btrfs_test.in @@ -0,0 +1,25 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.btrfs >/dev/null 2>&1; then + echo "mkfs.btrfs not installed; cannot test btrfs." + exit 77 +fi + +"@builddir@/grub-fs-tester" btrfs +"@builddir@/grub-fs-tester" btrfs_zlib +"@builddir@/grub-fs-tester" btrfs_lzo +"@builddir@/grub-fs-tester" btrfs_zstd +"@builddir@/grub-fs-tester" btrfs_raid0 +"@builddir@/grub-fs-tester" btrfs_raid1 +"@builddir@/grub-fs-tester" btrfs_single +"@builddir@/grub-fs-tester" btrfs_raid10 diff --git a/tests/cdboot_test.in b/tests/cdboot_test.in new file mode 100644 index 0000000..75acdfe --- /dev/null +++ b/tests/cdboot_test.in @@ -0,0 +1,39 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # PLATFORM: emu is different + *-emu) + exit 0;; + # PLATFORM: Flash targets + i386-qemu | i386-coreboot | mips-qemu_mips | mipsel-qemu_mips) + exit 0;; + # FIXME: currently grub-shell uses only -kernel for loongson + mipsel-loongson) + exit 0;; + # FIXME: OFW fails to open CD-ROM + i386-ieee1275) + exit 0;; +esac + +if [ "$(echo hello | "${grubshell}" --boot=cd)" != "Hello World" ]; then + exit 1 +fi diff --git a/tests/cmp_unit_test.c b/tests/cmp_unit_test.c new file mode 100644 index 0000000..e537841 --- /dev/null +++ b/tests/cmp_unit_test.c @@ -0,0 +1,226 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2012 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <string.h> +#include <grub/test.h> +#include <grub/misc.h> + +GRUB_MOD_LICENSE ("GPLv3+"); + +#define MSG "cmp test failed" + +/* Functional test main method. */ +static void +cmp_test (void) +{ + const char *s1 = "a"; + const char *s2 = "aa"; + const char *s3 = "รข"; + + grub_test_assert (grub_strlen (s1) == 1, MSG); + grub_test_assert (grub_strlen (s2) == 2, MSG); + grub_test_assert (grub_strlen (s3) == 2, MSG); + + grub_test_assert (grub_strcmp (s1, s1) == 0, MSG); + grub_test_assert (grub_strcmp (s1, s2) < 0, MSG); + grub_test_assert (grub_strcmp (s1, s3) < 0, MSG); + + grub_test_assert (grub_strcmp (s2, s1) > 0, MSG); + grub_test_assert (grub_strcmp (s2, s2) == 0, MSG); + grub_test_assert (grub_strcmp (s2, s3) < 0, MSG); + + grub_test_assert (grub_strcmp (s3, s1) > 0, MSG); + grub_test_assert (grub_strcmp (s3, s2) > 0, MSG); + grub_test_assert (grub_strcmp (s3, s3) == 0, MSG); + + grub_test_assert (grub_strcasecmp (s1, s1) == 0, MSG); + grub_test_assert (grub_strcasecmp (s1, s2) < 0, MSG); + grub_test_assert (grub_strcasecmp (s1, s3) < 0, MSG); + + grub_test_assert (grub_strcasecmp (s2, s1) > 0, MSG); + grub_test_assert (grub_strcasecmp (s2, s2) == 0, MSG); + grub_test_assert (grub_strcasecmp (s2, s3) < 0, MSG); + + grub_test_assert (grub_strcasecmp (s3, s1) > 0, MSG); + grub_test_assert (grub_strcasecmp (s3, s2) > 0, MSG); + grub_test_assert (grub_strcasecmp (s3, s3) == 0, MSG); + + grub_test_assert (grub_memcmp (s1, s1, 2) == 0, MSG); + grub_test_assert (grub_memcmp (s1, s2, 2) < 0, MSG); + grub_test_assert (grub_memcmp (s1, s3, 2) < 0, MSG); + + grub_test_assert (grub_memcmp (s2, s1, 2) > 0, MSG); + grub_test_assert (grub_memcmp (s2, s2, 2) == 0, MSG); + grub_test_assert (grub_memcmp (s2, s3, 2) < 0, MSG); + + grub_test_assert (grub_memcmp (s3, s1, 2) > 0, MSG); + grub_test_assert (grub_memcmp (s3, s2, 2) > 0, MSG); + grub_test_assert (grub_memcmp (s3, s3, 2) == 0, MSG); + + grub_test_assert (grub_memcmp (s1, s1, 1) == 0, MSG); + grub_test_assert (grub_memcmp (s1, s2, 1) == 0, MSG); + grub_test_assert (grub_memcmp (s1, s3, 1) < 0, MSG); + + grub_test_assert (grub_memcmp (s2, s1, 1) == 0, MSG); + grub_test_assert (grub_memcmp (s2, s2, 1) == 0, MSG); + grub_test_assert (grub_memcmp (s2, s3, 1) < 0, MSG); + + grub_test_assert (grub_memcmp (s3, s1, 1) > 0, MSG); + grub_test_assert (grub_memcmp (s3, s2, 1) > 0, MSG); + grub_test_assert (grub_memcmp (s3, s3, 1) == 0, MSG); + + grub_test_assert (grub_strncmp (s1, s1, 2) == 0, MSG); + grub_test_assert (grub_strncmp (s1, s2, 2) < 0, MSG); + grub_test_assert (grub_strncmp (s1, s3, 2) < 0, MSG); + + grub_test_assert (grub_strncmp (s2, s1, 2) > 0, MSG); + grub_test_assert (grub_strncmp (s2, s2, 2) == 0, MSG); + grub_test_assert (grub_strncmp (s2, s3, 2) < 0, MSG); + + grub_test_assert (grub_strncmp (s3, s1, 2) > 0, MSG); + grub_test_assert (grub_strncmp (s3, s2, 2) > 0, MSG); + grub_test_assert (grub_strncmp (s3, s3, 2) == 0, MSG); + + grub_test_assert (grub_strncmp (s1, s1, 1) == 0, MSG); + grub_test_assert (grub_strncmp (s1, s2, 1) == 0, MSG); + grub_test_assert (grub_strncmp (s1, s3, 1) < 0, MSG); + + grub_test_assert (grub_strncmp (s2, s1, 1) == 0, MSG); + grub_test_assert (grub_strncmp (s2, s2, 1) == 0, MSG); + grub_test_assert (grub_strncmp (s2, s3, 1) < 0, MSG); + + grub_test_assert (grub_strncmp (s3, s1, 1) > 0, MSG); + grub_test_assert (grub_strncmp (s3, s2, 1) > 0, MSG); + grub_test_assert (grub_strncmp (s3, s3, 1) == 0, MSG); + + grub_test_assert (grub_strncasecmp (s1, s1, 2) == 0, MSG); + grub_test_assert (grub_strncasecmp (s1, s2, 2) < 0, MSG); + grub_test_assert (grub_strncasecmp (s1, s3, 2) < 0, MSG); + + grub_test_assert (grub_strncasecmp (s2, s1, 2) > 0, MSG); + grub_test_assert (grub_strncasecmp (s2, s2, 2) == 0, MSG); + grub_test_assert (grub_strncasecmp (s2, s3, 2) < 0, MSG); + + grub_test_assert (grub_strncasecmp (s3, s1, 2) > 0, MSG); + grub_test_assert (grub_strncasecmp (s3, s2, 2) > 0, MSG); + grub_test_assert (grub_strncasecmp (s3, s3, 2) == 0, MSG); + + grub_test_assert (grub_strncasecmp (s1, s1, 1) == 0, MSG); + grub_test_assert (grub_strncasecmp (s1, s2, 1) == 0, MSG); + grub_test_assert (grub_strncasecmp (s1, s3, 1) < 0, MSG); + + grub_test_assert (grub_strncasecmp (s2, s1, 1) == 0, MSG); + grub_test_assert (grub_strncasecmp (s2, s2, 1) == 0, MSG); + grub_test_assert (grub_strncasecmp (s2, s3, 1) < 0, MSG); + + grub_test_assert (grub_strncasecmp (s3, s1, 1) > 0, MSG); + grub_test_assert (grub_strncasecmp (s3, s2, 1) > 0, MSG); + grub_test_assert (grub_strncasecmp (s3, s3, 1) == 0, MSG); + + grub_test_assert (strlen (s1) == 1, MSG); + grub_test_assert (strlen (s2) == 2, MSG); + grub_test_assert (strlen (s3) == 2, MSG); + + grub_test_assert (strcmp (s1, s1) == 0, MSG); + grub_test_assert (strcmp (s1, s2) < 0, MSG); + grub_test_assert (strcmp (s1, s3) < 0, MSG); + + grub_test_assert (strcmp (s2, s1) > 0, MSG); + grub_test_assert (strcmp (s2, s2) == 0, MSG); + grub_test_assert (strcmp (s2, s3) < 0, MSG); + + grub_test_assert (strcmp (s3, s1) > 0, MSG); + grub_test_assert (strcmp (s3, s2) > 0, MSG); + grub_test_assert (strcmp (s3, s3) == 0, MSG); + + grub_test_assert (memcmp (s1, s1, 2) == 0, MSG); + grub_test_assert (memcmp (s1, s2, 2) < 0, MSG); + grub_test_assert (memcmp (s1, s3, 2) < 0, MSG); + + grub_test_assert (memcmp (s2, s1, 2) > 0, MSG); + grub_test_assert (memcmp (s2, s2, 2) == 0, MSG); + grub_test_assert (memcmp (s2, s3, 2) < 0, MSG); + + grub_test_assert (memcmp (s3, s1, 2) > 0, MSG); + grub_test_assert (memcmp (s3, s2, 2) > 0, MSG); + grub_test_assert (memcmp (s3, s3, 2) == 0, MSG); + + grub_test_assert (memcmp (s1, s1, 1) == 0, MSG); + grub_test_assert (memcmp (s1, s2, 1) == 0, MSG); + grub_test_assert (memcmp (s1, s3, 1) < 0, MSG); + + grub_test_assert (memcmp (s2, s1, 1) == 0, MSG); + grub_test_assert (memcmp (s2, s2, 1) == 0, MSG); + grub_test_assert (memcmp (s2, s3, 1) < 0, MSG); + + grub_test_assert (memcmp (s3, s1, 1) > 0, MSG); + grub_test_assert (memcmp (s3, s2, 1) > 0, MSG); + grub_test_assert (memcmp (s3, s3, 1) == 0, MSG); + + grub_test_assert (strncmp (s1, s1, 2) == 0, MSG); + grub_test_assert (strncmp (s1, s2, 2) < 0, MSG); + grub_test_assert (strncmp (s1, s3, 2) < 0, MSG); + + grub_test_assert (strncmp (s2, s1, 2) > 0, MSG); + grub_test_assert (strncmp (s2, s2, 2) == 0, MSG); + grub_test_assert (strncmp (s2, s3, 2) < 0, MSG); + + grub_test_assert (strncmp (s3, s1, 2) > 0, MSG); + grub_test_assert (strncmp (s3, s2, 2) > 0, MSG); + grub_test_assert (strncmp (s3, s3, 2) == 0, MSG); + + grub_test_assert (strncmp (s1, s1, 1) == 0, MSG); + grub_test_assert (strncmp (s1, s2, 1) == 0, MSG); + grub_test_assert (strncmp (s1, s3, 1) < 0, MSG); + + grub_test_assert (strncmp (s2, s1, 1) == 0, MSG); + grub_test_assert (strncmp (s2, s2, 1) == 0, MSG); + grub_test_assert (strncmp (s2, s3, 1) < 0, MSG); + + grub_test_assert (strncmp (s3, s1, 1) > 0, MSG); + grub_test_assert (strncmp (s3, s2, 1) > 0, MSG); + grub_test_assert (strncmp (s3, s3, 1) == 0, MSG); + + grub_test_assert (strncasecmp (s1, s1, 2) == 0, MSG); + grub_test_assert (strncasecmp (s1, s2, 2) < 0, MSG); + grub_test_assert (strncasecmp (s1, s3, 2) < 0, MSG); + + grub_test_assert (strncasecmp (s2, s1, 2) > 0, MSG); + grub_test_assert (strncasecmp (s2, s2, 2) == 0, MSG); + grub_test_assert (strncasecmp (s2, s3, 2) < 0, MSG); + + grub_test_assert (strncasecmp (s3, s1, 2) > 0, MSG); + grub_test_assert (strncasecmp (s3, s2, 2) > 0, MSG); + grub_test_assert (strncasecmp (s3, s3, 2) == 0, MSG); + + grub_test_assert (strncasecmp (s1, s1, 1) == 0, MSG); + grub_test_assert (strncasecmp (s1, s2, 1) == 0, MSG); + grub_test_assert (strncasecmp (s1, s3, 1) < 0, MSG); + + grub_test_assert (strncasecmp (s2, s1, 1) == 0, MSG); + grub_test_assert (strncasecmp (s2, s2, 1) == 0, MSG); + grub_test_assert (strncasecmp (s2, s3, 1) < 0, MSG); + + grub_test_assert (strncasecmp (s3, s1, 1) > 0, MSG); + grub_test_assert (strncasecmp (s3, s2, 1) > 0, MSG); + grub_test_assert (strncasecmp (s3, s3, 1) == 0, MSG); +} + +/* Register example_test method as a functional test. */ +GRUB_UNIT_TEST ("cmp_test", cmp_test); diff --git a/tests/core_compress_test.in b/tests/core_compress_test.in new file mode 100644 index 0000000..9d216eb --- /dev/null +++ b/tests/core_compress_test.in @@ -0,0 +1,36 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # FIXME: Only mips currently supports configurable core compression + *-emu | i386-* | x86_64-* | sparc64-* | ia64-*) + exit 0 + ;; +esac + + +if [ "$(echo hello | "${grubshell}" --grub-mkimage-extra=--compress=xz)" != "Hello World" ]; then + exit 1 +fi + +if [ "$(echo hello | "${grubshell}" --grub-mkimage-extra=--compress=none)" != "Hello World" ]; then + exit 1 +fi diff --git a/tests/cpio_test.in b/tests/cpio_test.in new file mode 100644 index 0000000..5742cf1 --- /dev/null +++ b/tests/cpio_test.in @@ -0,0 +1,16 @@ +#!@BUILD_SHEBANG@ + +set -e + +if ! which cpio >/dev/null 2>&1; then + echo "cpio not installed; cannot test cpio." + exit 77 +fi + +"@builddir@/grub-fs-tester" cpio_bin +"@builddir@/grub-fs-tester" cpio_odc +"@builddir@/grub-fs-tester" cpio_newc +"@builddir@/grub-fs-tester" cpio_crc +"@builddir@/grub-fs-tester" cpio_ustar +"@builddir@/grub-fs-tester" cpio_hpbin +"@builddir@/grub-fs-tester" cpio_hpodc diff --git a/tests/date_unit_test.c b/tests/date_unit_test.c new file mode 100644 index 0000000..99774f1 --- /dev/null +++ b/tests/date_unit_test.c @@ -0,0 +1,76 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2013 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <time.h> +#include <stdlib.h> + +#include <grub/misc.h> +#include <grub/datetime.h> +#include <grub/test.h> + +static void +date_test (grub_int32_t v) +{ + struct grub_datetime dt; + time_t t = v; + struct tm *g; + int w; + + g = gmtime (&t); + + grub_unixtime2datetime (v, &dt); + + w = grub_get_weekday (&dt); + + grub_test_assert (g->tm_sec == dt.second, "time %d bad second: %d vs %d", v, + g->tm_sec, dt.second); + grub_test_assert (g->tm_min == dt.minute, "time %d bad minute: %d vs %d", v, + g->tm_min, dt.minute); + grub_test_assert (g->tm_hour == dt.hour, "time %d bad hour: %d vs %d", v, + g->tm_hour, dt.hour); + grub_test_assert (g->tm_mday == dt.day, "time %d bad day: %d vs %d", v, + g->tm_mday, dt.day); + grub_test_assert (g->tm_mon + 1 == dt.month, "time %d bad month: %d vs %d", v, + g->tm_mon + 1, dt.month); + grub_test_assert (g->tm_year + 1900 == dt.year, + "time %d bad year: %d vs %d", v, + g->tm_year + 1900, dt.year); + grub_test_assert (g->tm_wday == w, "time %d bad week day: %d vs %d", v, + g->tm_wday, w); +} + +static void +date_test_iter (void) +{ + grub_int32_t tests[] = { -1, 0, +1, -2133156255, GRUB_INT32_MIN, + GRUB_INT32_MAX }; + unsigned i; + + for (i = 0; i < ARRAY_SIZE (tests); i++) + date_test (tests[i]); + srand (42); + for (i = 0; i < 1000000; i++) + { + grub_int32_t x = rand (); + date_test (x); + date_test (-x); + } +} + +GRUB_UNIT_TEST ("date_unit_test", date_test_iter); diff --git a/tests/dfly-mbr-mbexample.dfly.img.gz b/tests/dfly-mbr-mbexample.dfly.img.gz Binary files differnew file mode 100644 index 0000000..b63595d --- /dev/null +++ b/tests/dfly-mbr-mbexample.dfly.img.gz diff --git a/tests/dfly-mbr-mbexample.mbr.img.gz b/tests/dfly-mbr-mbexample.mbr.img.gz Binary files differnew file mode 100644 index 0000000..add2b13 --- /dev/null +++ b/tests/dfly-mbr-mbexample.mbr.img.gz diff --git a/tests/ehci_test.in b/tests/ehci_test.in new file mode 100644 index 0000000..b197f8c --- /dev/null +++ b/tests/ehci_test.in @@ -0,0 +1,51 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # PLATFORM: Don't mess with real devices when OS is active + *-emu) + exit 0;; + # FIXME: qemu gets bonito DMA wrong + mipsel-loongson) + exit 0;; + # PLATFORM: no USB on ARC and qemu-mips platforms + mips*-arc | mips*-qemu_mips) + exit 0;; + # FIXME: No native drivers are available for those + powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi) + exit 0;; +esac + +imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 + +echo "hello" > "$outfile" + +tar cf "$imgfile" "$outfile" + +if [ "$(echo "nativedisk; source '(usb0)/$outfile';" | "${grubshell}" --qemu-opts="-device ich9-usb-ehci1 -drive id=my_usb_disk,file=$imgfile,if=none -device usb-storage,drive=my_usb_disk" | tail -n 1)" != "Hello World" ]; then + rm "$imgfile" + rm "$outfile" + exit 1 +fi + +rm "$imgfile" +rm "$outfile" diff --git a/tests/example_grub_script_test.in b/tests/example_grub_script_test.in new file mode 100644 index 0000000..93a90a1 --- /dev/null +++ b/tests/example_grub_script_test.in @@ -0,0 +1,3 @@ +#! @builddir@/grub-shell-tester --modules=echo + +echo "hello world" diff --git a/tests/example_scripted_test.in b/tests/example_scripted_test.in new file mode 100644 index 0000000..783b7f1 --- /dev/null +++ b/tests/example_scripted_test.in @@ -0,0 +1,4 @@ +#!@BUILD_SHEBANG@ +set -e + +true diff --git a/tests/example_unit_test.c b/tests/example_unit_test.c new file mode 100644 index 0000000..36bfac9 --- /dev/null +++ b/tests/example_unit_test.c @@ -0,0 +1,38 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +/* Unit tests are normal programs, so they can include C library. */ +#include <string.h> + +/* All tests need to include test.h for GRUB testing framework. */ +#include <grub/test.h> + +/* Unit test main method. */ +static void +example_test (void) +{ + /* Check if 1st argument is true and report with default error message. */ + grub_test_assert (1 == 1, "1 equal 1 expected"); + + /* Check if 1st argument is true and report with custom error message. */ + grub_test_assert (2 == 2, "2 equal 2 expected"); + grub_test_assert (2 != 3, "2 matches %d", 3); +} + +/* Register example_test method as a unit test. */ +GRUB_UNIT_TEST ("example_unit_test", example_test); diff --git a/tests/exfat_test.in b/tests/exfat_test.in new file mode 100644 index 0000000..cd3cd4c --- /dev/null +++ b/tests/exfat_test.in @@ -0,0 +1,18 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.exfat >/dev/null 2>&1; then + echo "mkfs.exfat not installed; cannot test exFAT." + exit 77 +fi + +"@builddir@/grub-fs-tester" exfat diff --git a/tests/ext234_test.in b/tests/ext234_test.in new file mode 100644 index 0000000..4f1eb52 --- /dev/null +++ b/tests/ext234_test.in @@ -0,0 +1,33 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.ext2 >/dev/null 2>&1; then + echo "mkfs.ext2 not installed; cannot test ext2." + exit 77 +fi + +if ! which mkfs.ext3 >/dev/null 2>&1; then + echo "mkfs.ext3 not installed; cannot test ext3." + exit 77 +fi + +if ! which mkfs.ext4 >/dev/null 2>&1; then + echo "mkfs.ext4 not installed; cannot test ext4." + exit 77 +fi + +"@builddir@/grub-fs-tester" ext2_old +"@builddir@/grub-fs-tester" ext2 +"@builddir@/grub-fs-tester" ext3 +"@builddir@/grub-fs-tester" ext4 +"@builddir@/grub-fs-tester" ext4_metabg +"@builddir@/grub-fs-tester" ext4_encrypt diff --git a/tests/f2fs_test.in b/tests/f2fs_test.in new file mode 100644 index 0000000..1ea77c8 --- /dev/null +++ b/tests/f2fs_test.in @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.f2fs >/dev/null 2>&1; then + echo "mkfs.f2fs not installed; cannot test f2fs." + exit 77 +fi + + +"@builddir@/grub-fs-tester" f2fs diff --git a/tests/fat_test.in b/tests/fat_test.in new file mode 100644 index 0000000..b6b4748 --- /dev/null +++ b/tests/fat_test.in @@ -0,0 +1,22 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.vfat >/dev/null 2>&1; then + echo "mkfs.vfat not installed; cannot test FAT." + exit 77 +fi + +"@builddir@/grub-fs-tester" vfat16a +"@builddir@/grub-fs-tester" vfat12a +"@builddir@/grub-fs-tester" vfat12 +"@builddir@/grub-fs-tester" vfat16 +"@builddir@/grub-fs-tester" vfat32 diff --git a/tests/fddboot_test.in b/tests/fddboot_test.in new file mode 100644 index 0000000..2d7dfc8 --- /dev/null +++ b/tests/fddboot_test.in @@ -0,0 +1,51 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # PLATFORM: emu is different + *-emu) + exit 0;; + # PLATFORM: Flash targets + i386-qemu | i386-coreboot | mips-qemu_mips | mipsel-qemu_mips) + exit 0;; + # FIXME: currently grub-shell uses only -kernel for loongson + mipsel-loongson) + exit 0;; + # FIXME: We don't support EFI floppy boot in grub-mkrescue + *-efi) + exit 0;; + # FIXME: no floppy support + i386-multiboot) + exit 0;; + # FIXME: QEMU firmware crashes when trying to boot from floppy + sparc64-ieee1275) + exit 0;; + # FIXME: QEMU doesn't emulate SCSI floppies + mipsel-arc | mips-arc) + exit 0;; + # PLATFORM: powerpc doesn't boot from floppy except OldWorld Macs which we don't support anyway + powerpc-ieee1275) + exit 0;; +esac + +if [ "$(echo hello | "${grubshell}" --boot=fd --mkrescue-arg="--compress=xz --fonts= --locales= --themes= -no-pad")" != "Hello World" ]; then + exit 1 +fi diff --git a/tests/file_filter/file b/tests/file_filter/file new file mode 100644 index 0000000..64650ac --- /dev/null +++ b/tests/file_filter/file @@ -0,0 +1 @@ +Hello, user! diff --git a/tests/file_filter/file.gz b/tests/file_filter/file.gz Binary files differnew file mode 100644 index 0000000..a07ffcb --- /dev/null +++ b/tests/file_filter/file.gz diff --git a/tests/file_filter/file.gz.sig b/tests/file_filter/file.gz.sig Binary files differnew file mode 100644 index 0000000..602e618 --- /dev/null +++ b/tests/file_filter/file.gz.sig diff --git a/tests/file_filter/file.lzop b/tests/file_filter/file.lzop Binary files differnew file mode 100644 index 0000000..5f5a971 --- /dev/null +++ b/tests/file_filter/file.lzop diff --git a/tests/file_filter/file.lzop.sig b/tests/file_filter/file.lzop.sig Binary files differnew file mode 100644 index 0000000..7c68dcf --- /dev/null +++ b/tests/file_filter/file.lzop.sig diff --git a/tests/file_filter/file.xz b/tests/file_filter/file.xz Binary files differnew file mode 100644 index 0000000..151a980 --- /dev/null +++ b/tests/file_filter/file.xz diff --git a/tests/file_filter/file.xz.sig b/tests/file_filter/file.xz.sig Binary files differnew file mode 100644 index 0000000..5756924 --- /dev/null +++ b/tests/file_filter/file.xz.sig diff --git a/tests/file_filter/keys b/tests/file_filter/keys Binary files differnew file mode 100644 index 0000000..1afa713 --- /dev/null +++ b/tests/file_filter/keys diff --git a/tests/file_filter/keys.pub b/tests/file_filter/keys.pub Binary files differnew file mode 100644 index 0000000..61d4e7a --- /dev/null +++ b/tests/file_filter/keys.pub diff --git a/tests/file_filter/test.cfg b/tests/file_filter/test.cfg new file mode 100644 index 0000000..4308aac --- /dev/null +++ b/tests/file_filter/test.cfg @@ -0,0 +1,6 @@ +trust /keys.pub +set check_signatures=enforce +cat /file.gz +cat /file.xz +cat /file.lzop +set check_signatures= diff --git a/tests/file_filter_test.in b/tests/file_filter_test.in new file mode 100644 index 0000000..ed6abcb --- /dev/null +++ b/tests/file_filter_test.in @@ -0,0 +1,76 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2014 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +filters="gzio xzio lzopio pgp" +modules="cat mpi" + +for mod in $(cut -d ' ' -f 2 "@builddir@/grub-core/crypto.lst" | sort -u); do + modules="$modules $mod" +done + +for file in file.gz file.xz file.lzop file.gz.sig file.xz.sig file.lzop.sig keys.pub; do + files="$files /$file=@srcdir@/tests/file_filter/$file" +done + +# GRUB cat command adds extra newline after file +result="Hello, user! + +Hello, user! + +Hello, user!" + +out="$("${grubshell}" --modules="$modules $filters" --files="$files" "@srcdir@/tests/file_filter/test.cfg")" +if [ "$out" != "$result" ]; then + echo LOCAL FAIL + echo "$out" + exit 1 +fi + +# Taken from netboot_test +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # PLATFORM: emu is different + *-emu) + exit 0;; + # PLATFORM: Flash targets + i386-qemu | i386-coreboot | mips-qemu_mips | mipsel-qemu_mips) + exit 0;; + # FIXME: currently grub-shell uses only -kernel for loongson + mipsel-loongson) + exit 0;; + # FIXME: no rtl8139 support + i386-multiboot) + exit 0;; + # FIXME: We don't fully support netboot on ARC + *-arc) + exit 0;; + # FIXME: Many QEMU firmware have no netboot capability + *-efi | i386-ieee1275 | powerpc-ieee1275 | sparc64-ieee1275) + exit 0;; +esac + +out="$("${grubshell}" --boot=net --modules="$modules $filters" --files="$files" "@srcdir@/tests/file_filter/test.cfg")" +if [ "$out" != "$result" ]; then + echo NET FAIL + echo "$out" + exit 1 +fi + +exit 0 diff --git a/tests/gettext_strings_test.in b/tests/gettext_strings_test.in new file mode 100644 index 0000000..813999e --- /dev/null +++ b/tests/gettext_strings_test.in @@ -0,0 +1,20 @@ +#!@BUILD_SHEBANG@ + +cd '@srcdir@' + +tdir="$(mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")" + +xgettext -f po/POTFILES.in -L C -o "$tdir/"skip.pot -x po/grub.pot --keyword=grub_util_info --keyword=grub_dprintf:1,2 --keyword=grub_register_command --keyword=grub_register_extcmd --keyword=grub_efiemu_resolve_symbol --keyword=grub_efiemu_register_symbol --keyword=grub_dl_load --keyword=grub_crypto_lookup_md_by_name --keyword=grub_crypto_lookup_cipher_by_name --keyword=grub_efiemu_resolve_symbol --keyword=alias --keyword=grub_ieee1275_get_property:2 --keyword=grub_ieee1275_find_device --keyword=grub_ieee1275_get_integer_property:2 --keyword=INIT_IEEE1275_COMMON:2 --keyword=grub_boot_time --keyword=grub_env_get --keyword=grub_env_set --keyword=grub_register_variable_hook --keyword=grub_fatal --keyword=__asm__ --keyword=volatile --keyword=__volatile__ --keyword=grub_error:2 --from-code=iso-8859-1 +xgettext -f po/POTFILES.in -L C -o "$tdir/"skip2.pot -x po/grub.pot --keyword=volatile:2 --keyword=__volatile__:2 --keyword=grub_dprintf:2 --from-code=iso-8859-1 +xgettext -f po/POTFILES.in -L C -o "$tdir/"skip3.pot -x po/grub.pot --keyword=volatile:3 --keyword=__volatile__:3 --from-code=iso-8859-1 + +cat po/POTFILES.in | xargs grep -hE -o "( | ){\"[a-z0-9\-]*\",[[:space:]]*('.'|[0-9]|-[0-9])," |sed "s,[[:space:]]*{\",,g;s,\"\,[[:space:]]*\('.'\|[0-9]\|-[0-9]\)\,,,g" | awk '{ print "msgid \"" $0 "\"\nmsgstr \"\"" ; }' > "$tdir/"opts.pot +cat po/POTFILES.in | xargs grep -hE -o "[[:space:]]*\.name[[:space:]]*=[[:space:]]*\"[a-zA-Z0-9 ()]*\"" |sed "s,[[:space:]]*\.name[[:space:]]*=[[:space:]]*\",,g;s,\",,g" | awk '{ print "msgid \"" $0 "\"\nmsgstr \"\"" ; }' > "$tdir/"name.pot + +out="$(cat po/POTFILES.in | grep -v '\(colors.c\|lsefisystab.c\|lsefimmap.c\|lssal.c\|hdparm.c\|sendkey.c\|lsacpi.c\|lspci.c\|usbtest.c\|legacy_parse.c\|/libgcrypt/\|hfs.c\|/efi\.c$\|gnulib\|tests/\|util/ieee1275/ofpath.c\|minilzo.c\|terminfo.c\|setpci.c\|bin2h.c\|cb_timestamps.c\|grub-pe2elf.c\|getroot_[a-z]*.c\|getroot.c\|arc/init.c\|color.c\|grub-mklayout.c\|gentrigtables.c\|lzodefs.h\|lsefi.c\|cbls.c\|/zfs\.h$\|grub-macho2img.c\|syslinux_parse.c\|lvm.c\|efidisk.c\|grub-mkfont.c\|reiserfs.c\|LzmaEnc.c\)' | xgettext -f - -L C -o - -x po/grub.pot -x "$tdir/"skip.pot -x "$tdir/"skip2.pot -x "$tdir/"skip3.pot -x "$tdir/"opts.pot -x "$tdir/"name.pot -x po/exclude.pot -a --from-code=iso-8859-1)" +rm -rf "$tdir" +if [ x"$out" != x ]; then + echo "$out" + exit 1; +fi + diff --git a/tests/grub_cmd_date.in b/tests/grub_cmd_date.in new file mode 100644 index 0000000..f7c9ca0 --- /dev/null +++ b/tests/grub_cmd_date.in @@ -0,0 +1,29 @@ +#! @BUILD_SHEBANG@ +set -e + +. "@builddir@/grub-core/modinfo.sh" + +# FIXME: OpenBIOS on sparc64 doesn't implement RTC +if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = sparc64-ieee1275 ]; then + exit 0 +fi + +pdt="$(date -u +%s)" +dt=`echo date | @builddir@/grub-shell | sed 's, [A-Z][a-z]*$,,'` +dtg="$(date -u -d "$dt" +%s)" +ndt="$(date -u +%s)" + +if [ $pdt -gt $dtg ] || [ $dtg -gt $ndt ]; then + echo "Date not in range: $pdt <= $dtg <= $ndt" + exit 1 +fi + +pdt="$(date -u +%s)" +dt=`echo 'insmod datehook; echo $YEAR-$MONTH-$DAY $HOUR:$MINUTE:$SECOND' | @builddir@/grub-shell` +dtg="$(date -u -d "$dt" +%s)" +ndt="$(date -u +%s)" + +if [ $pdt -gt $dtg ] || [ $dtg -gt $ndt ]; then + echo "Date not in range: $pdt <= $dtg <= $ndt" + exit 1 +fi diff --git a/tests/grub_cmd_echo.in b/tests/grub_cmd_echo.in new file mode 100644 index 0000000..9026967 --- /dev/null +++ b/tests/grub_cmd_echo.in @@ -0,0 +1,41 @@ +#! @builddir@/grub-shell-tester +# +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +echo +echo -n + +echo foo +echo foo bar + +echo -n foo + +echo -e "foo\nbar" + +echo -n -e "foo\nbar" + +echo foo -n +echo foo -n -e + +echo ------- + +if test -n "$grubshell"; then insmod regexp; fi + +echo '*' +echo "*" + +foo="*" +echo "$foo" diff --git a/tests/grub_cmd_regexp.in b/tests/grub_cmd_regexp.in new file mode 100644 index 0000000..6520bd6 --- /dev/null +++ b/tests/grub_cmd_regexp.in @@ -0,0 +1,42 @@ +#! @BUILD_SHEBANG@ +set -e + +# Run GRUB script in a Qemu instance +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +cmd='regexp -s version "vm-(.*)" vm-1.2.3; echo $version' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != 1.2.3; then echo "error: $cmd" >&2; exit 1; fi + +cmd='regexp -s 1:version "vm-(.*)" vm-1.2.3; echo $version' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != 1.2.3; then echo "error: $cmd" >&2; exit 1; fi + +cmd='regexp -s 0:match "vm-(.*)" vm-1.2.3; echo $match' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != vm-1.2.3; then echo "error: $cmd" >&2; exit 1; fi + +cmd='regexp -s 2:match "vm-(.*)" vm-1.2.3; echo $match' +v=`echo "$cmd" | @builddir@/grub-shell` +if test -n "$v"; then echo "error: $cmd" >&2; exit 1; fi + +cmd='regexp -s match "\\\((.*)\\\)" (hd0,msdos1); echo $match' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != "hd0,msdos1"; then echo "error: $cmd" >&2; exit 1; fi + +cmd='regexp -s match "hd([0-9]+)" hd0; echo $match' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != "0"; then echo "error: $cmd" >&2; exit 1; fi diff --git a/tests/grub_cmd_set_date.in b/tests/grub_cmd_set_date.in new file mode 100644 index 0000000..aac120a --- /dev/null +++ b/tests/grub_cmd_set_date.in @@ -0,0 +1,35 @@ +#! @BUILD_SHEBANG@ +set -e + +. "@builddir@/grub-core/modinfo.sh" + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # FIXME: OpenBIOS on sparc64 doesn't implement RTC + sparc64-ieee1275) + exit 0;; + # PLATFORM: ARC doesn't provide any way to set time + *-arc) + exit 0;; + # PLATFORM: EMU doesn't provide any way to set time + # Even if it did we'd need some kind of sandbox to avoid + # modifying real system time. + *-emu) + exit 0;; +esac + +out=$(cat <<EOF | @builddir@/grub-shell +insmod datehook +date +if [ \$YEAR = 2004 -a \$MONTH = 4 -a \$DAY = 4 -a \$HOUR = 20 -a \$MINUTE = 47 ]; then + hello + halt +fi +date 2004-04-04 20:47:00 +reboot +EOF +) + +if [ "$(echo "$out" | tail -n 1)" != "Hello World" ]; then + echo "Test failed: $out" + exit 1 +fi diff --git a/tests/grub_cmd_sleep.in b/tests/grub_cmd_sleep.in new file mode 100644 index 0000000..8797f66 --- /dev/null +++ b/tests/grub_cmd_sleep.in @@ -0,0 +1,25 @@ +#! @BUILD_SHEBANG@ +set -e + +. "@builddir@/grub-core/modinfo.sh" + +# FIXME: OpenBIOS on sparc64 doesn't implement RTC +if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = sparc64-ieee1275 ]; then + exit 0 +fi + +# Compare RTC with interval timer. +# Not 100% proper but should check that timer is running ok +dt=`echo 'date; sleep 10; date' | @builddir@/grub-shell` +dt1="$(date -u -d "$(echo "$dt" | head -n 1 | sed 's, [A-Z][a-z]*$,,')" +%s)" +dt2="$(date -u -d "$(echo "$dt" | tail -n 1 | sed 's, [A-Z][a-z]*$,,')" +%s)" + +# Ignore QEMU bug +if [ "${grub_modinfo_target_cpu}" = arm ] && [ $((dt2 - dt1)) -ge 15 ] && [ $((dt2 - dt1)) -le 17 ]; then + exit 0; +fi + +if [ $((dt2 - dt1)) -gt 11 ] || [ $((dt2 - dt1)) -lt 9 ]; then + echo "Interval not in range $dt2-$dt1 != 10" + exit 1 +fi diff --git a/tests/grub_cmd_test.in b/tests/grub_cmd_test.in new file mode 100644 index 0000000..3399eb2 --- /dev/null +++ b/tests/grub_cmd_test.in @@ -0,0 +1,67 @@ +#! @BUILD_SHEBANG@ + +# create a randome file +empty="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +non_empty="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +cat >$non_empty <<EOF +hello world! +EOF + +. "@builddir@/grub-core/modinfo.sh" + +if [ x"${grub_modinfo_platform}" = xemu ]; then + grub_empty="(host)$empty" + grub_non_empty="(host)$non_empty" + grub_dir="(host)${TMPDIR:-/tmp}" +else + grub_empty="/boot/empty" + grub_non_empty="/boot/non_empty" + grub_dir="/boot/grub" +fi + + +outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +@builddir@/grub-shell --files=$grub_empty=$empty --files=$grub_non_empty=$non_empty>$outfile <<EOF +if ! test -f $grub_empty; then + echo FAIL1 +fi +if ! test -e $grub_empty; then + echo FAIL2 +fi +if test -d $grub_empty; then + echo FAIL3 +fi +if ! test -d $grub_dir; then + echo FAIL4 +fi +if test -s $grub_empty; then + echo FAIL5 +fi +if ! test -s $grub_non_empty; then + echo FAIL6 +fi +if test -f $grub_empty -a foo = bar; then + echo FAIL7 +fi +if test -e $grub_empty -a foo = bar; then + echo FAIL8 +fi +if test -s $grub_non_empty -a foo = bar; then + echo FAIL9 +fi +if test -d $grub_dir -a foo = bar; then + echo FAIL10 +fi + +EOF + +rm -f "$empty" "$non_empty" + +if grep FAIL "$outfile" > /dev/null 2>&1; then + echo "GRUB test command file tests failed." + cat "$outfile" + exit 1 +else + rm -f "${outfile}" + exit 0 +fi diff --git a/tests/grub_cmd_tr.in b/tests/grub_cmd_tr.in new file mode 100644 index 0000000..bed469c --- /dev/null +++ b/tests/grub_cmd_tr.in @@ -0,0 +1,62 @@ +#! @BUILD_SHEBANG@ -e + +# Run GRUB script in a Qemu instance +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +# +# Translating a string argument +# +cmd='tr 12345 abcde a1b2c3d4e5' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != aabbccddee; then echo "error: $cmd [$v]" >&2; exit 1; fi + +cmd='tr -U abcdABCD' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != ABCDABCD; then echo "error: $cmd [$v]" >&2; exit 1; fi + +cmd='tr -D ABCDabcd' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != abcdabcd; then echo "error: $cmd [$v]" >&2; exit 1; fi + +# +# Translating a variable value +# +cmd='foo=12345678; tr -s foo 1234 abcd; echo $foo' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != abcd5678; then echo "error: $cmd [$v]" >&2; exit 1; fi + +cmd='foo=abcdEFGH; tr -U -s foo; echo $foo' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != ABCDEFGH; then echo "error: $cmd [$v]" >&2; exit 1; fi + +cmd='foo=abcdEFGH; tr -D -s foo; echo $foo' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != abcdefgh; then echo "error: $cmd [$v]" >&2; exit 1; fi + +# +# Setting a variable from string argument +# +cmd='foo=12345678; tr -s foo 1234 abcd a1b2c3d4e5; echo $foo' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != aabbccdde5; then echo "error: $cmd [$v]" >&2; exit 1; fi + +cmd='foo=abcdEFGH; tr -U -s foo xyz; echo $foo' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != XYZ; then echo "error: $cmd [$v]" >&2; exit 1; fi + +cmd='foo=abcdEFGH; tr -D -s foo XYZ; echo $foo' +v=`echo "$cmd" | @builddir@/grub-shell` +if test "$v" != xyz; then echo "error: $cmd [$v]" >&2; exit 1; fi diff --git a/tests/grub_func_test.in b/tests/grub_func_test.in new file mode 100644 index 0000000..c67f9e4 --- /dev/null +++ b/tests/grub_func_test.in @@ -0,0 +1,21 @@ +#! @BUILD_SHEBANG@ +set -e + +. "@builddir@/grub-core/modinfo.sh" + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # PLATFORM: Max RAM is 256M + mips-qemu_mips | mipsel-qemu_mips) + mem=256M;; + *) + mem=512M;; +esac + +# Increase memory as some of tests are high-resolution and need a lot of memory. +out=`echo all_functional_test | @builddir@/grub-shell --timeout=3600 --files="/boot/grub/fonts/unicode.pf2"="@builddir@/"unicode.pf2 --qemu-opts="-m $mem"` + +if [ "$(echo "$out" | tail -n 1)" != "ALL TESTS PASSED" ]; then + echo "Functional test failure: $out" + exit 1 +fi + diff --git a/tests/grub_script_blanklines.in b/tests/grub_script_blanklines.in new file mode 100644 index 0000000..bd87354 --- /dev/null +++ b/tests/grub_script_blanklines.in @@ -0,0 +1,15 @@ +#! @BUILD_SHEBANG@ +set -e + +@builddir@/grub-script-check <<EOF +# comment 1 + +command1 arg1 + +command2 arg2 + + + +last command +# comment 2 +EOF diff --git a/tests/grub_script_blockarg.in b/tests/grub_script_blockarg.in new file mode 100644 index 0000000..6ea9b8c --- /dev/null +++ b/tests/grub_script_blockarg.in @@ -0,0 +1,41 @@ +#! @BUILD_SHEBANG@ + +# Run GRUB script in a Qemu instance +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +error_if_not () { + if test "$1" != "$2"; then + echo "[$1]" != "[$2]" + exit 1 + fi +} + +cmd='test_blockarg { true }' +v=`echo "$cmd" | @builddir@/grub-shell` +error_if_not "$v" '{ true }' + +tmp=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 +cmd='test_blockarg { test_blockarg { true } }' +echo "$cmd" | @builddir@/grub-shell >$tmp +error_if_not "`head -n1 $tmp|tail -n1`" '{ test_blockarg { true } }' +error_if_not "`head -n2 $tmp|tail -n1`" '{ true }' + +cmd='test_blockarg { test_blockarg { test_blockarg { true } }; test_blockarg { true } }' +echo "$cmd" | @builddir@/grub-shell >$tmp +error_if_not "`head -n1 $tmp|tail -n1`" '{ test_blockarg { test_blockarg { true } }; test_blockarg { true } }' +error_if_not "`head -n2 $tmp|tail -n1`" '{ test_blockarg { true } }' +error_if_not "`head -n3 $tmp|tail -n1`" '{ true }' +error_if_not "`head -n4 $tmp|tail -n1`" '{ true }' diff --git a/tests/grub_script_break.in b/tests/grub_script_break.in new file mode 100644 index 0000000..bf265e8 --- /dev/null +++ b/tests/grub_script_break.in @@ -0,0 +1,86 @@ +#! @builddir@/grub-shell-tester +# +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +# break without any arguments +for i in 1 2 3 4 5 6 7 8 9 10 +do + echo $i + if test "$i" = 5 + then + break + fi +done + +# break with one +for i in 1 2 3 4 5 6 7 8 9 10 +do + echo $i + if test "$i" = 5 + then + break 1 + fi +done + +# break with loop count +for i in 1 2 3 4 5 +do + for j in a b c d e f + do + echo "$i $j" + if test "$i" = 3 + then + if test "$j" = d + then + break 2 + fi + fi + done +done + +# break into middle loop +for i in 1 2 3 4 5 +do + for j in a b c d e f + do + echo "$i $j" + if test "$i" = 3 + then + if test "$j" = d + then + break 1 + fi + fi + done +done + +# while and until loops +a= +while test "$a" != "aaaaaaa" +do + a="a$a" + for i in 1 2 3 4 + do + b= + until test "$b" = "bbbbb" + do + b="b$b" + echo "$a $i $b" + if test "$i" = 3; then echo "break 2"; break 2; fi + done + done +done + diff --git a/tests/grub_script_comments.in b/tests/grub_script_comments.in new file mode 100644 index 0000000..f212cc1 --- /dev/null +++ b/tests/grub_script_comments.in @@ -0,0 +1,28 @@ +#! @builddir@/grub-shell-tester +# +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +echo a###b +echo a# #b + +echo # +echo \# + +echo '#' +echo "#" + +echo '\#' +echo "\#" diff --git a/tests/grub_script_continue.in b/tests/grub_script_continue.in new file mode 100644 index 0000000..4c28ce4 --- /dev/null +++ b/tests/grub_script_continue.in @@ -0,0 +1,86 @@ +#! @builddir@/grub-shell-tester +# +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +# continue without any arguments +for i in 1 2 3 4 5 6 7 8 9 10 +do + if test "$i" = 5 + then + continue + fi + echo $i +done + +# continue with one +for i in 1 2 3 4 5 6 7 8 9 10 +do + if test "$i" = 5 + then + continue 1 + fi + echo $i +done + +# continue with loop count +for i in 1 2 3 4 5 +do + for j in a b c d e f + do + if test "$i" = 3 + then + if test "$j" = d + then + continue 2 + fi + echo "$i $j" + fi + done +done + +# continue into middle loop +for i in 1 2 3 4 5 +do + for j in a b c d e f + do + if test "$i" = 3 + then + if test "$j" = d + then + continue 1 + fi + echo "$i $j" + fi + done +done + +# while and until loops +a= +while test "$a" != "aaaaaaa" +do + a="a$a" + for i in 1 2 3 4 + do + b= + until test "$b" = "bbbbb" + do + b="b$b" + if test "$i" = 3; then echo "continue 2"; continue 2; fi + echo "$a $i $b" + done + done +done + diff --git a/tests/grub_script_dollar.in b/tests/grub_script_dollar.in new file mode 100644 index 0000000..392fe2e --- /dev/null +++ b/tests/grub_script_dollar.in @@ -0,0 +1,6 @@ +#! @BUILD_SHEBANG@ +set -e + +@builddir@/grub-script-check << EOF +echo "\\\$" +EOF diff --git a/tests/grub_script_echo1.in b/tests/grub_script_echo1.in new file mode 100644 index 0000000..3a07972 --- /dev/null +++ b/tests/grub_script_echo1.in @@ -0,0 +1,183 @@ +#! @builddir@/grub-shell-tester + +# Run GRUB script in a Qemu instance +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +# simple arguments +echo one two three +echo "one two three" +echo 'one two three' + echo "one two three" + echo "one two three" + echo "one two three" + +# empty arguments +echo a "" b +echo a '' b + +echo a $foo b +echo a ${foo} b + +echo a "$foo" b +echo a "${foo}" b + +# multi-part arguments +echo one"two"three +echo one${two}three +echo one"two"$three + +echo one'two'three +echo one${two}three +echo one'two'$three + +echo one'two'three"four"five${six}seven$eight + + +foo=bar +echo $foo ${foo} +echo "$foo" "${foo}" +echo '$foo' '${foo}' +echo a$foob a${foo}b +echo ab"cd"ef$foo'gh'ij${foo}kl\ mn\"op\'qr\$st\(uv\<wx\>yz\) + +foo=c +bar=h +echo e"$foo"${bar}o +e"$foo"${bar}o hello world + +foo=echo +$foo 1234 + +echo "one +" +echo "one +\"" +echo "one +two" + +echo one"two +"three +echo one"two +\""three +echo one"two +\"three\" +four" + + +echo 'one +' +echo 'one +\' +echo 'one +two' +echo one'two +' +echo one'two +\' +echo one'two +\'three + +echo "one\ +" +echo "one\ +\"" +echo "one\ +two" + +# echo "one\ +# two" +# echo 'one\ +# two' +# echo foo\ +# bar +# \ +# echo foo +# echo "one +# +# two" + +echo "one + " +echo "one + \"" +echo "one + two" + +echo one"two + "three +echo one"two + \""three +echo one"two +\"three\" + four" + +echo 'one + ' +echo 'one + \' +echo 'one + two' +echo one'two + ' +echo one'two + \' +echo one'two + \'three + +echo "one\ + " +echo "one\ + \"" +echo "one\ + two" + +echo one \ + two + +echo one x\ + two + +echo one x\ +"x" two +echo one x\ +'x' two +echo one x\ +\\ two + +echo one x\ +\ +x + +echo one x\ + + + +echo one x\ +; + +echo one x\ +$var + + +if test x$grubshell = xyes; then insmod regexp; fi +echo /boot/grub/i386-pc/normal.mod +echo x\\y +echo x\*y +echo x\\ +echo x\\\\ +echo x\\\\y + + diff --git a/tests/grub_script_echo_keywords.in b/tests/grub_script_echo_keywords.in new file mode 100644 index 0000000..a6383f0 --- /dev/null +++ b/tests/grub_script_echo_keywords.in @@ -0,0 +1,3 @@ +#! @builddir@/grub-shell-tester + +echo if then else fi for do done diff --git a/tests/grub_script_escape_comma.in b/tests/grub_script_escape_comma.in new file mode 100644 index 0000000..eff3179 --- /dev/null +++ b/tests/grub_script_escape_comma.in @@ -0,0 +1,18 @@ +#! @builddir@/grub-shell-tester + +x=1\\,1 +echo $x +y='$' +echo $y +z='\' +echo $z +t='\*' +echo $t +u='$' +echo $u +v='\?' +echo $v + + +echo \\ + diff --git a/tests/grub_script_eval.in b/tests/grub_script_eval.in new file mode 100644 index 0000000..c97b78d --- /dev/null +++ b/tests/grub_script_eval.in @@ -0,0 +1,6 @@ +#! @builddir@/grub-shell-tester + +eval echo "Hello world" +valname=tst +eval $valname=hi +echo $tst
\ No newline at end of file diff --git a/tests/grub_script_expansion.in b/tests/grub_script_expansion.in new file mode 100644 index 0000000..9d0dcdd --- /dev/null +++ b/tests/grub_script_expansion.in @@ -0,0 +1,43 @@ +#! @BUILD_SHEBANG@ +set -e + +# Run GRUB script in a Qemu instance +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +disks=`echo ls | @builddir@/grub-shell| grep -av '^Network protocols:$'| grep -av '^tftp http $'` +other=`echo insmod regexp\; echo \* | @builddir@/grub-shell` +for d in $disks; do + if echo "$d" |grep ',' >/dev/null; then + if echo "$other" | grep -F -- "$d" >/dev/null; then + echo "$d should not occur in * expansion" >&2 + exit 1 + fi + else + if ! echo "$other" | grep -F -- "$d" >/dev/null; then + echo "$d missing from * expansion" >&2 + exit 1 + fi + fi +done + +other=`echo insmod regexp\; echo '(*)' | @builddir@/grub-shell` +for d in $disks; do + if ! echo "$other" | grep -F -- "$d" >/dev/null; then + echo "$d missing from (*) expansion" >&2 + exit 1 + fi +done + diff --git a/tests/grub_script_final_semicolon.in b/tests/grub_script_final_semicolon.in new file mode 100644 index 0000000..f17a9bf --- /dev/null +++ b/tests/grub_script_final_semicolon.in @@ -0,0 +1,11 @@ +#! @BUILD_SHEBANG@ +set -e + +@builddir@/grub-script-check <<EOF +echo one; +echo one; echo two +echo one; echo two; +echo one ; echo two ; +echo one ; echo two ; echo three +echo one; echo two ; echo three; +EOF diff --git a/tests/grub_script_for1.in b/tests/grub_script_for1.in new file mode 100644 index 0000000..e39a766 --- /dev/null +++ b/tests/grub_script_for1.in @@ -0,0 +1,27 @@ +#! @builddir@/grub-shell-tester + +for x in one two 'three 3' "four 4" five six-6; do echo $x; done + +for x in one two 'three 3' "four 4" five six-6 +do + echo $x +done + +foo="1 2" +for x in ab${foo}cd; do echo $x; done +for x in "ab${foo}cd"; do echo $x; done + +a="one two three" +y=foo +echo $y +for y in $a; do + echo $y +done +echo $y + + +b="one two three" +for z in $b; do + echo $z +done +echo $z diff --git a/tests/grub_script_functions.in b/tests/grub_script_functions.in new file mode 100644 index 0000000..3e69014 --- /dev/null +++ b/tests/grub_script_functions.in @@ -0,0 +1,147 @@ +#! @builddir@/grub-shell-tester + +# Run GRUB script in a Qemu instance +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +echo parameter count +function fcount { + echo fcount "$#" +} + +fcount +fcount a +fcount a b + +echo parameter count, with nesting +function ffcount { + echo ffcount "$#" + fcount + fcount a + fcount a b +} + +ffcount +ffcount 1 +ffcount 1 2 + +echo parameters +function fparam { + echo fparam 1 $1 + echo fparam 2 $2 + echo fparam 3 $3 +} + +fparam +fparam a +fparam a b + +echo parameters, with nesting +function ffparam { + echo ffparam 1 $1 + echo ffparam 2 $2 + echo ffparam 3 $3 + fparam + fparam a + fparam a b +} + +ffparam +ffparam 1 +ffparam 1 2 + +echo parameter expansion with specials +function fstar { + for f in $* + do + echo fstar $f + done + + for f in aaa$*bbb + do + echo fstar $f + done +} + +fstar +fstar a +fstar a "1 2" +fstar a "1 2" b + +function fdqstar { + for f in "$*" + do + echo fdqstar $f + done + + for f in aaa"$*"bbb + do + echo fdqstar $f + done + + for f in "aaa$*bbb" + do + echo fdqstar $f + done +} + +fdqstar +fdqstar a +fdqstar a "1 2" +fdqstar a "1 2" b + +function fat { + for f in $@ + do + echo fat $f + done + + for f in aaa$@bbb + do + echo fat $f + done +} + +fat +fat a +fat a "1 2" +fat a "1 2" b +fat a "1 2" b "c d" +fat a "1 2" b "c d" e + +function fdqat { + for f in "$@" + do + echo fdqat $f + done + + for f in aaa"$@"bbb + do + echo fdqat $f + done + + for f in "aaa$@bbb" + do + echo fdqat $f + done +} + +# fdqat # this case needs special handling, lets ignore till we really need it. +fdqat a +fdqat a "1 2" +fdqat a "1 2" b +fdqat a "1 2" b "c d" +fdqat a "1 2" b "c d" e + diff --git a/tests/grub_script_gettext.in b/tests/grub_script_gettext.in new file mode 100644 index 0000000..cc42c67 --- /dev/null +++ b/tests/grub_script_gettext.in @@ -0,0 +1,69 @@ +#! @builddir@/grub-shell-tester +# +# Copyright (C) 2010,2012 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +echo $"foo" +echo $"foo bar" + +echo -n $"foo" + +echo -e $"foo\nbar" + +echo -n -e $"foo\nbar" + +x=5 +echo $"$x" +echo $"\x\\y\$x$x\\$xx${x}x\"$x\"" + +echo $"$" +echo $"$,x" + +echo $"one +" +echo $"one +\"" +echo $"one +two" + +echo one$"two +"three +echo one$"two +\""three +echo one$"two +\"three\" +four" + +echo $"one\ +" +echo $"one\ +\"" +echo $"one\ +two" + +echo one$"two\ +"three +echo one$"two\ +\""three +echo one$"two\ +\"three\"\ +four" + +if test -n "$grubshell"; then insmod regexp; fi + +echo $"*" + +foo="*" +echo $"$foo" diff --git a/tests/grub_script_if.in b/tests/grub_script_if.in new file mode 100644 index 0000000..fb17eaf --- /dev/null +++ b/tests/grub_script_if.in @@ -0,0 +1,31 @@ +#! @builddir@/grub-shell-tester + +#basic if, execute +if true; then echo yes; fi + +#basic if, no execution +if false; then echo no; fi + +#if else, execute if path +if true; then echo yes; else echo no; fi + +#if else, execute else path +if false; then echo no; else echo yes; fi + +#if elif, execute elif +if false; then echo no; elif true; then echo yes; fi + +#if elif else, execute else +if false; then echo no; elif false; then echo no; else echo yes; fi + +#if elif(1) elif(2), execute elif(2) +if false; then echo no; elif false; then echo no; elif true; then echo yes; fi + +#if elif(1) elif(2) else, execute else +if false; then echo no; elif false; then echo no; elif false; then echo no; else echo yes; fi + +#if {if elif else}, execute elif +if true; then if false; then echo no; elif true; then echo yes; else echo no; fi; fi + +#if {if elif} else, execute elif. ofcourse no dangling-else problem due to "fi" +if true; then if false; then echo no; elif true; then echo yes; fi; else echo no; fi diff --git a/tests/grub_script_leading_whitespace.in b/tests/grub_script_leading_whitespace.in new file mode 100644 index 0000000..d5946ba --- /dev/null +++ b/tests/grub_script_leading_whitespace.in @@ -0,0 +1,4 @@ +#! @builddir@/grub-shell-tester + +list=" 1 2 3" +echo $list diff --git a/tests/grub_script_no_commands.in b/tests/grub_script_no_commands.in new file mode 100644 index 0000000..996bb18 --- /dev/null +++ b/tests/grub_script_no_commands.in @@ -0,0 +1,21 @@ +#! @BUILD_SHEBANG@ +set -e + +# grub-script-check refuses to pass a file with no commands; this usually +# indicates a bug in the code generating that file. + +@builddir@/grub-script-check <<EOF && exit 1 + +EOF + +@builddir@/grub-script-check <<EOF && exit 1 +# comment +EOF + +@builddir@/grub-script-check <<EOF && exit 1 +# comment 1 +# comment 2 + +EOF + +exit 0 diff --git a/tests/grub_script_not.in b/tests/grub_script_not.in new file mode 100644 index 0000000..ff71039 --- /dev/null +++ b/tests/grub_script_not.in @@ -0,0 +1,62 @@ +#! @builddir@/grub-shell-tester +# +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +true +echo $? + +! true +echo $? + +false +echo $? + +! false +echo $? + +# +# Negated forms (copied from grub_script_if.in) +# + +#basic if, execute +if ! true; then echo yes; fi + +#basic if, no execution +if ! false; then echo no; fi + +#if else, execute if path +if ! true; then echo yes; else echo no; fi + +#if else, execute else path +if ! false; then echo no; else echo yes; fi + +#if elif, execute elif +if ! false; then echo no; elif ! true; then echo yes; fi + +#if elif else, execute else +if ! false; then echo no; elif ! false; then echo no; else echo yes; fi + +#if elif(1) elif(2), execute elif(2) +if false; then echo no; elif ! false; then echo no; elif ! true; then echo yes; fi + +#if elif(1) elif(2) else, execute else +if false; then echo no; elif false; then echo no; elif ! false; then echo no; else echo yes; fi + +#if {if elif else}, execute elif +if true; then if false; then echo no; elif ! true; then echo yes; else echo no; fi; fi + +#if {if elif} else, execute elif. ofcourse no dangling-else problem due to "fi" +if true; then if ! false; then echo no; elif true; then echo yes; fi; else echo no; fi diff --git a/tests/grub_script_return.in b/tests/grub_script_return.in new file mode 100644 index 0000000..712d1df --- /dev/null +++ b/tests/grub_script_return.in @@ -0,0 +1,134 @@ +#! @builddir@/grub-shell-tester + +# Run GRUB script in a Qemu instance +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +function f1 { + return + echo one +} +f1 + +function f2 { + true + return + echo one +} +if f2; then echo true; else echo false; fi + +function f3 { + false + return + echo one +} +if f3; then echo true; else echo false; fi + +function f4 { + true + return 1; + echo one +} +if f4; then echo true; else echo false; fi + +function f5 { + false + return 0; + echo one +} +if f5; then echo true; else echo false; fi + +function f6 { + echo one + if true; then + echo two + return 0 + else + echo three + return 1 + fi + echo four +} +if f6; then echo true; else echo false; fi + +function f7 { + if return 1; then + echo one + else + echo no + fi +} +if f7; then echo true; else echo false; fi + +function f8 { + echo one + for v in 1 2 3 4 5; do + echo $v + if test $v = 3; then return 1; fi + done + echo two +} +if f8; then echo true; else echo false; fi + +function f9 { + x=1 + echo one + until test x = 11111111; do + echo $x + x="1$x" + if test $x = 1111; then return 0; fi + done + echo two +} +if f9; then echo true; else echo false; fi + +function f10 { + echo one + while return 0; do + echo two + done + echo three +} +if f10; then echo true; else echo false; fi + +function f11 { + f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 +} +if f11; then echo true; else echo false; fi + +function f12 { + echo one + f11 + return 1 + echo two +} +if f12; then echo true; else echo false; fi + +function f13 { + echo one + f12 + echo two + return 0 +} +if f13; then echo true; else echo false; fi diff --git a/tests/grub_script_setparams.in b/tests/grub_script_setparams.in new file mode 100644 index 0000000..82d3168 --- /dev/null +++ b/tests/grub_script_setparams.in @@ -0,0 +1,59 @@ +#! @builddir@/grub-shell-tester + +# Run GRUB script in a Qemu instance +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +if test x$grubshell = xyes; then cmd=setparams; else cmd=set; fi + +function f1 { + echo $# + echo "$#" + + echo $@ + echo "$@" + + echo $* + echo "$*" + + echo $1 $2 + for v in "$@"; do echo $v; done + shift + echo $1 $2 + for v in "$@"; do echo $v; done + + $cmd 1 2 3 4 + + echo $# + echo "$#" + + echo $@ + echo "$@" + + echo $* + echo "$*" + + echo $1 $2 + for v in "$@"; do echo $v; done + shift + echo $1 $2 + for v in "$@"; do echo $v; done +} +# f1 +# f1 a +f1 a b +f1 a b c +f1 a b c d +f1 a b c d e diff --git a/tests/grub_script_shift.in b/tests/grub_script_shift.in new file mode 100644 index 0000000..785b9c3 --- /dev/null +++ b/tests/grub_script_shift.in @@ -0,0 +1,85 @@ +#! @builddir@/grub-shell-tester + +# Run GRUB script in a Qemu instance +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +function f1 { + echo f1 '$@' $@ + echo f1 '$*' $* + echo f1 $# $1 $2 $3 + shift + echo f1 '$@' $@ + echo f1 '$*' $* + echo f1 $# $1 $2 $3 +} + +f1 +f1 a +f1 a b +f1 a b c +f1 a b c d +f1 a b c d e + +function f2 { + echo f1 '$@' $@ + echo f1 '$*' $* + echo f2 $# $1 $2 $3 + shift 1 + echo f1 '$@' $@ + echo f1 '$*' $* + echo f2 $# $1 $2 $3 +} + +f2 +f2 a +f2 a b +f2 a b c +f2 a b c d +f2 a b c d e + +function f3 { + echo f1 '$@' $@ + echo f1 '$*' $* + echo f3 $# $1 $2 $3 + shift 3 + echo f1 '$@' $@ + echo f1 '$*' $* + echo f3 $# $1 $2 $3 +} + +f3 +f3 a +f3 a b +f3 a b c +f3 a b c d +f3 a b c d e + +function f4 { + echo f1 '$@' $@ + echo f1 '$*' $* + echo f4 $# $1 $2 $3 + shift 100 + echo f1 '$@' $@ + echo f1 '$*' $* + echo f4 $# $1 $2 $3 +} + +f4 +f4 a +f4 a b +f4 a b c +f4 a b c d +f4 a b c d e diff --git a/tests/grub_script_strcmp.in b/tests/grub_script_strcmp.in new file mode 100644 index 0000000..721549c --- /dev/null +++ b/tests/grub_script_strcmp.in @@ -0,0 +1,22 @@ +#! @builddir@/grub-shell-tester +# +# Copyright (C) 2012 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +LC_ALL=C +export LC_ALL + +if [ "z" "<" "รข" ]; then echo unsigned; else echo signed; fi +if [ "z" ">" "รข" ]; then echo signed; else echo unsigned; fi diff --git a/tests/grub_script_test.in b/tests/grub_script_test.in new file mode 100644 index 0000000..34a5f14 --- /dev/null +++ b/tests/grub_script_test.in @@ -0,0 +1,15 @@ +#! @builddir@/grub-shell-tester + +for device in 'hd0' 'fd0'; do + # But search them if their search has been inforced + set fd0search="no" + if [ "$device" != "fd0" -a "$device" != "cd" \ + -o \ + "$device" = "fd0" -a "$fd0search" = "yes" ]\ + ; then + echo "Yes" + else + echo "No" + fi + +done
\ No newline at end of file diff --git a/tests/grub_script_vars1.in b/tests/grub_script_vars1.in new file mode 100644 index 0000000..77b3cf2 --- /dev/null +++ b/tests/grub_script_vars1.in @@ -0,0 +1,34 @@ +#! @builddir@/grub-shell-tester + +# Run GRUB script in a Qemu instance +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +var=foo +echo $var +echo "$var" +echo ${var} +echo "${var}" + +echo $1 $2 $? + +foo=foo +echo "" $foo + +echo $bar $foo + +bar="" +echo $bar $foo + diff --git a/tests/grub_script_while1.in b/tests/grub_script_while1.in new file mode 100644 index 0000000..554247f --- /dev/null +++ b/tests/grub_script_while1.in @@ -0,0 +1,32 @@ +#! @builddir@/grub-shell-tester + +echo one +foo="" +while test "$foo" != "1111"; do foo="${foo}1"; echo "$foo"; done + +echo two +foo="" +while test "$foo" != "aaaa" +do + foo="${foo}a" + echo $foo +done + +foo="" +until test "$foo" = "1111"; do foo="${foo}1"; echo $foo; done +foo="" +until test "$foo" = "aaaa" +do + foo="${foo}a" + echo $foo +done + +# check "$?" in condition gets its value from while body commands +foo="" +false +while test "$?" != "0" +do + echo $foo + foo="${foo}1" + test "$foo" = "111111" +done diff --git a/tests/gzcompress_test.in b/tests/gzcompress_test.in new file mode 100644 index 0000000..42c8fe7 --- /dev/null +++ b/tests/gzcompress_test.in @@ -0,0 +1,29 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +if ! which gzip >/dev/null 2>&1; then + echo "gzip not installed; cannot test gzip compression." + exit 77 +fi + +if [ "$(echo hello | "${grubshell}" --mkrescue-arg=--compress=gz)" != "Hello World" ]; then + exit 1 +fi diff --git a/tests/hddboot_test.in b/tests/hddboot_test.in new file mode 100644 index 0000000..6d70847 --- /dev/null +++ b/tests/hddboot_test.in @@ -0,0 +1,37 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # PLATFORM: emu is different + *-emu) + exit 0;; + # PLATFORM: Flash targets + i386-qemu | i386-coreboot | mips-qemu_mips | mipsel-qemu_mips) + exit 0;; + # FIXME: currently grub-shell uses only -kernel for loongson + mipsel-loongson) + exit 0;; +esac + +if [ "$(echo hello | "${grubshell}" --boot=hd)" != "Hello World" ]; then + exit 1 +fi + diff --git a/tests/help_test.in b/tests/help_test.in new file mode 100644 index 0000000..b08cf20 --- /dev/null +++ b/tests/help_test.in @@ -0,0 +1,16 @@ +#! @BUILD_SHEBANG@ +set -e + +. "@builddir@/grub-core/modinfo.sh" + +template="Usage: help [PATTERN ...] +Show a help message. + +-h, --help Display this help and exit. +-u, --usage Display the usage of this command and exit. +Hello World" +outpu="$(echo 'help help; hello' | @builddir@/grub-shell)" + +if [ "$template" != "$outpu" ]; then + exit 1 +fi diff --git a/tests/hfs_test.in b/tests/hfs_test.in new file mode 100644 index 0000000..d7ec56b --- /dev/null +++ b/tests/hfs_test.in @@ -0,0 +1,23 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.hfs >/dev/null 2>&1; then + echo "mkfs.hfs not installed; cannot test HFS." + exit 77 +fi + +if ! modprobe mac-roman; then + echo "no mac-roman support; cannot test HFS." + exit 77 +fi + +"@builddir@/grub-fs-tester" hfs diff --git a/tests/hfsplus_test.in b/tests/hfsplus_test.in new file mode 100644 index 0000000..85f1c37 --- /dev/null +++ b/tests/hfsplus_test.in @@ -0,0 +1,20 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.hfsplus >/dev/null 2>&1; then + echo "mkfs.hfsplus not installed; cannot test hfsplus." + exit 77 +fi + +"@builddir@/grub-fs-tester" hfsplus +"@builddir@/grub-fs-tester" hfsplus_casesens +"@builddir@/grub-fs-tester" hfsplus_wrap diff --git a/tests/iso9660_test.in b/tests/iso9660_test.in new file mode 100644 index 0000000..571b938 --- /dev/null +++ b/tests/iso9660_test.in @@ -0,0 +1,15 @@ +#!@BUILD_SHEBANG@ + +set -e + +if ! which xorriso >/dev/null 2>&1; then + echo "xorriso not installed; cannot test iso9660." + exit 77 +fi + +"@builddir@/grub-fs-tester" joliet +"@builddir@/grub-fs-tester" rockridge +"@builddir@/grub-fs-tester" rockridge_joliet +"@builddir@/grub-fs-tester" joliet_1999 +"@builddir@/grub-fs-tester" rockridge_1999 +"@builddir@/grub-fs-tester" rockridge_joliet_1999
\ No newline at end of file diff --git a/tests/jfs_test.in b/tests/jfs_test.in new file mode 100644 index 0000000..6cf7576 --- /dev/null +++ b/tests/jfs_test.in @@ -0,0 +1,18 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.jfs >/dev/null 2>&1; then + echo "mkfs.jfs not installed; cannot test JFS." + exit 77 +fi + +"@builddir@/grub-fs-tester" jfs diff --git a/tests/lib/unit_test.c b/tests/lib/unit_test.c new file mode 100644 index 0000000..6adfd99 --- /dev/null +++ b/tests/lib/unit_test.c @@ -0,0 +1,42 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> + +#include <grub/list.h> +#include <grub/test.h> + +int +main (int argc __attribute__ ((unused)), + char *argv[] __attribute__ ((unused))) +{ + int status = 0; + + grub_test_t test; + + grub_unit_test_init (); + FOR_LIST_ELEMENTS (test, grub_test_list) + status = grub_test_run (test) ? : status; + + grub_unit_test_fini (); + + exit (status); +} diff --git a/tests/lzocompress_test.in b/tests/lzocompress_test.in new file mode 100644 index 0000000..4e5f7e0 --- /dev/null +++ b/tests/lzocompress_test.in @@ -0,0 +1,29 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +if ! which lzop >/dev/null 2>&1; then + echo "lzop not installed; cannot test lzo compression." + exit 77 +fi + +if [ "$(echo hello | "${grubshell}" --mkrescue-arg=--compress=lzo)" != "Hello World" ]; then + exit 1 +fi diff --git a/tests/minixfs_test.in b/tests/minixfs_test.in new file mode 100644 index 0000000..3b16a4d --- /dev/null +++ b/tests/minixfs_test.in @@ -0,0 +1,35 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.minix >/dev/null 2>&1; then + echo "mkfs.minix not installed; cannot test minixfs." + exit 77 +fi + +if ! mkfs.minix -h | grep -- -v > /dev/null; then + echo "mkfs.minix doesn't support minix2fs; cannot test minix*fs." + exit 77 +fi + +if ! mkfs.minix -h | grep -- -3 > /dev/null; then + echo "mkfs.minix doesn't support minix3fs; cannot test minix*fs." + exit 77 +fi + +if ! mkfs.minix -h | grep -- -B > /dev/null; then + echo "mkfs.minix doesn't support variable block size; cannot test minix*fs." + exit 77 +fi + +"@builddir@/grub-fs-tester" minix +"@builddir@/grub-fs-tester" minix2 +"@builddir@/grub-fs-tester" minix3 diff --git a/tests/netboot_test.in b/tests/netboot_test.in new file mode 100644 index 0000000..9f71e3d --- /dev/null +++ b/tests/netboot_test.in @@ -0,0 +1,45 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # PLATFORM: emu is different + *-emu) + exit 0;; + # PLATFORM: Flash targets + i386-qemu | i386-coreboot | mips-qemu_mips | mipsel-qemu_mips) + exit 0;; + # FIXME: currently grub-shell uses only -kernel for loongson + mipsel-loongson) + exit 0;; + # FIXME: no rtl8139 support + i386-multiboot) + exit 0;; + # FIXME: We don't fully support netboot on ARC + *-arc) + exit 0;; + # FIXME: Many QEMU firmware have no netboot capability + *-efi | i386-ieee1275 | powerpc-ieee1275 | sparc64-ieee1275) + exit 0;; +esac + +if [ "$(echo hello | "${grubshell}" --boot=net)" != "Hello World" ]; then + exit 1 +fi diff --git a/tests/nilfs2_test.in b/tests/nilfs2_test.in new file mode 100644 index 0000000..ad44d5b --- /dev/null +++ b/tests/nilfs2_test.in @@ -0,0 +1,18 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.nilfs2 >/dev/null 2>&1; then + echo "mkfs.nilfs2 not installed; cannot test nilfs2." + exit 77 +fi + +"@builddir@/grub-fs-tester" nilfs2 diff --git a/tests/ntfs_test.in b/tests/ntfs_test.in new file mode 100644 index 0000000..9eb7b01 --- /dev/null +++ b/tests/ntfs_test.in @@ -0,0 +1,24 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.ntfs >/dev/null 2>&1; then + echo "mkfs.ntfs not installed; cannot test ntfs." + exit 77 +fi + +if ! which setfattr >/dev/null 2>&1; then + echo "setfattr not installed; cannot test ntfs." + exit 77 +fi + +"@builddir@/grub-fs-tester" ntfs +"@builddir@/grub-fs-tester" ntfscomp diff --git a/tests/ohci_test.in b/tests/ohci_test.in new file mode 100644 index 0000000..8693f8c --- /dev/null +++ b/tests/ohci_test.in @@ -0,0 +1,51 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # PLATFORM: Don't mess with real devices when OS is active + *-emu) + exit 0;; + # FIXME: qemu gets bonito DMA wrong + mipsel-loongson) + exit 0;; + # PLATFORM: no USB on ARC and qemu-mips platforms + mips*-arc | mips*-qemu_mips) + exit 0;; + # FIXME: No native drivers are available for those + powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi) + exit 0;; +esac + +imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 + +echo "hello" > "$outfile" + +tar cf "$imgfile" "$outfile" + +if [ "$(echo "nativedisk; source '(usb0)/$outfile';" | "${grubshell}" --qemu-opts="-device pci-ohci -drive id=my_usb_disk,file=$imgfile,if=none -device usb-storage,drive=my_usb_disk" | tail -n 1)" != "Hello World" ]; then + rm "$imgfile" + rm "$outfile" + exit 1 +fi + +rm "$imgfile" +rm "$outfile" diff --git a/tests/partmap_test.in b/tests/partmap_test.in new file mode 100644 index 0000000..6ef518b --- /dev/null +++ b/tests/partmap_test.in @@ -0,0 +1,489 @@ +#! @BUILD_SHEBANG@ +set -e + +# Copyright (C) 2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +parted=parted +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +create_disk_image () { + name="$1" + size=$2 + rm -f "${name}" + dd if=/dev/zero of="${name}" bs=512 count=1 seek=$((size * 2048 - 1)) status=noxfer > /dev/null +} + +create_dfly_image () { + name="$1" + rm -f ${name} + + gunzip < "@srcdir@/tests/dfly-mbr-mbexample.mbr.img.gz" | dd of=${name} bs=1 seek=440 count=72 conv=notrunc > /dev/null + gunzip < "@srcdir@/tests/dfly-mbr-mbexample.dfly.img.gz" | dd of=${name} bs=512 seek=33 count=1 conv=notrunc > /dev/null +} + +check_output () { + outfile=$1 + shift + + for dsk in $@; do + if ! grep "($dsk)" "${outfile}" >/dev/null + then + echo "($dsk): disk/partiton not found" + exit 1 + fi + done +} + +list_parts () { + mod=$1; + shift; + imgfile="$1" + shift + outfile="$1" + shift + + echo ls | "${grubshell}" --disk="${imgfile}" \ + --modules=$mod | tr -d "\n\r" > "${outfile}" + cat "${outfile}" + echo +} + +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 + ;; + powerpc-ieee1275) + disk=ieee1275//pci@80000000/mac-io@4/ata-3@20000/disk@0 + # 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 + # FIXME: QEMU firmware has bugs which prevent it from accessing hard disk w/o recognised label. + exit 0 + ;; + i386-ieee1275) + disk=ieee1275/d + # FIXME: QEMU firmware has bugs which prevent it from accessing hard disk w/o recognised label. + exit 0 + ;; + mips-arc) + # FIXME: ARC firmware has bugs which prevent it from accessing hard disk w/o dvh disklabel. + exit 0 ;; + mipsel-arc) + disk=arc/scsi0/disk0/rdisk0 + ;; + arm*-efi) + disk=hd3 + ;; + *) + disk=hd0 + ;; +esac + +if ! which parted >/dev/null 2>&1; then + echo "parted not installed; cannot test partmap" + exit 77 +fi + +imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 + +# +# MSDOS partition types +# + +echo "Checking MSDOS partition types..." + +# 0 primary +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel msdos +list_parts part_msdos "${imgfile}" "${outfile}" +check_output "${outfile}" $disk + +# 1 primary +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M +list_parts part_msdos "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,msdos1 + +# 2 primary +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M +list_parts part_msdos "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 + +# 3 primary +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M +list_parts part_msdos "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 $disk,msdos3 + +# 4 primary +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M +list_parts part_msdos "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 $disk,msdos3 $disk,msdos4 + +# 1 primary, 1 extended +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% +list_parts part_msdos "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,msdos1 + +# 1 primary, 1 extended, 1 logical +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M +list_parts part_msdos "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 + +# 1 primary, 1 extended, 2 logical +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M mkpart logical 30M 40M +list_parts part_msdos "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 + +# 1 primary, 1 extended, 3 logical +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M mkpart logical 30M 40M mkpart logical 40M 50M +list_parts part_msdos "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 $disk,msdos7 + +# 1 primary, 1 extended, 4 logical +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M mkpart logical 30M 40M mkpart logical 40M 50M mkpart logical 50M 60M +list_parts part_msdos "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 $disk,msdos7 $disk,msdos8 + + +# +# GPT partition types +# + +echo "Checking GPT partition types..." + +# 0 parts +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel gpt +list_parts part_gpt "${imgfile}" "${outfile}" +check_output "${outfile}" $disk + +# 1 parts +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M +list_parts part_gpt "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,gpt1 + +# 2 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M +list_parts part_gpt "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 + +# 3 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M +list_parts part_gpt "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 + +# 4 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 4 20M 30M mkpart 5 30M 40M +list_parts part_gpt "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4 + +# 5 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M mkpart 4 30M 40M mkpart 5 40M 50M +list_parts part_gpt "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4 $disk,gpt5 + +# 6 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M mkpart 4 30M 40M mkpart 5 40M 50M mkpart 6 50M 60M +list_parts part_gpt "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4 $disk,gpt5 $disk,gpt6 + + +# +# SUN partition types +# +# It seems partition #3 is reserved for whole disk by parted. +# + +echo "Checking SUN partition types..." + +# 0 parts +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel sun +list_parts part_sun "${imgfile}" "${outfile}" +check_output "${outfile}" $disk + +# 1 parts +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M +list_parts part_sun "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,sun1 + +# 2 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M +list_parts part_sun "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,sun1 $disk,sun2 + +# 3 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M +list_parts part_sun "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 + +# 4 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M +list_parts part_sun "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 + +# 5 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M mkpart 40M 50M +list_parts part_sun "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 $disk,sun6 + +# 6 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M mkpart 40M 50M mkpart 50M 60M +list_parts part_sun "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 $disk,sun6 $disk,sun7 + +# 7 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M mkpart 40M 50M mkpart 50M 60M mkpart 60M 70M +list_parts part_sun "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 $disk,sun6 $disk,sun7 $disk,sun8 + + +# +# Apple partition types +# +# Partition table itself is part of some partition, so there is always +# a partition by default. Furthermore free space is also a partition, +# so there is always at least 2 partitions +# + +echo "Checking APPLE partition types..." + +# 0 parts +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel mac +list_parts part_apple "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,apple1 $disk,apple2 + +# 1 parts +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M +list_parts part_apple "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple3 + +# 2 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M +list_parts part_apple "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple3 $disk,apple4 + +# 3 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M +list_parts part_apple "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 + +# 4 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M +list_parts part_apple "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 + +# 5 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M mkpart e 40M 50M +list_parts part_apple "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7 + +# 6 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M mkpart e 40M 50M mkpart f 50M 60M +list_parts part_apple "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7 $disk,apple8 + +# +# DVH partition types +# +# Partition #11 is reserved for whole disk by parted. +# Parted also aliases #9 as whole disk +# + +echo "Checking DVH partition types..." + +# 0 parts +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel dvh +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk + +# 1 parts +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 + +# 2 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 + +# 3 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 + +# 4 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 $disk,dvh4 + +# 5 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M mkpart primary 40M 50M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 $disk,dvh4 $disk,dvh5 + +# 6 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M mkpart primary 40M 50M mkpart primary 50M 60M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 $disk,dvh4 $disk,dvh5 $disk,dvh6 + +# 7 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M mkpart primary 40M 50M mkpart primary 50M 60M mkpart primary 60M 70M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 $disk,dvh4 $disk,dvh5 $disk,dvh6 $disk,dvh7 + +# 8 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M mkpart primary 40M 50M mkpart primary 50M 60M mkpart primary 60M 70M mkpart primary 70M 80M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 $disk,dvh4 $disk,dvh5 $disk,dvh6 $disk,dvh7 $disk,dvh8 + +# 9 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M mkpart primary 40M 50M mkpart primary 50M 60M mkpart primary 60M 70M mkpart primary 70M 80M mkpart primary 80M 90M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 $disk,dvh4 $disk,dvh5 $disk,dvh6 $disk,dvh7 $disk,dvh8 $disk,dvh10 + +# 10 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M mkpart primary 40M 50M mkpart primary 50M 60M mkpart primary 60M 70M mkpart primary 70M 80M mkpart primary 80M 90M mkpart primary 90M 100M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 $disk,dvh4 $disk,dvh5 $disk,dvh6 $disk,dvh7 $disk,dvh8 $disk,dvh10 $disk,dvh12 + +# 11 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M mkpart primary 40M 50M mkpart primary 50M 60M mkpart primary 60M 70M mkpart primary 70M 80M mkpart primary 80M 90M mkpart primary 90M 100M mkpart primary 100M 110M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 $disk,dvh4 $disk,dvh5 $disk,dvh6 $disk,dvh7 $disk,dvh8 $disk,dvh10 $disk,dvh12 $disk,dvh13 + +# 12 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M mkpart primary 40M 50M mkpart primary 50M 60M mkpart primary 60M 70M mkpart primary 70M 80M mkpart primary 80M 90M mkpart primary 90M 100M mkpart primary 100M 110M mkpart primary 110M 120M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 $disk,dvh4 $disk,dvh5 $disk,dvh6 $disk,dvh7 $disk,dvh8 $disk,dvh10 $disk,dvh12 $disk,dvh13 $disk,dvh14 + +# 13 parts +create_disk_image "${imgfile}" 135 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M mkpart primary 40M 50M mkpart primary 50M 60M mkpart primary 60M 70M mkpart primary 70M 80M mkpart primary 80M 90M mkpart primary 90M 100M mkpart primary 100M 110M mkpart primary 110M 120M mkpart primary 120M 130M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 $disk,dvh4 $disk,dvh5 $disk,dvh6 $disk,dvh7 $disk,dvh8 $disk,dvh10 $disk,dvh12 $disk,dvh13 $disk,dvh14 $disk,dvh15 + +# 14 parts +create_disk_image "${imgfile}" 145 +${parted} -a none -s "${imgfile}" mklabel dvh mkpart primary 3M 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M mkpart primary 40M 50M mkpart primary 50M 60M mkpart primary 60M 70M mkpart primary 70M 80M mkpart primary 80M 90M mkpart primary 90M 100M mkpart primary 100M 110M mkpart primary 110M 120M mkpart primary 120M 130M mkpart primary 130M 140M +list_parts part_dvh "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,dvh1 $disk,dvh2 $disk,dvh3 $disk,dvh4 $disk,dvh5 $disk,dvh6 $disk,dvh7 $disk,dvh8 $disk,dvh10 $disk,dvh12 $disk,dvh13 $disk,dvh14 $disk,dvh15 $disk,dvh16 + +echo "Checking AMIGA partition types..." + +# 0 parts +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel amiga +list_parts part_amiga "${imgfile}" "${outfile}" +check_output "${outfile}" $disk + +# 1 parts +create_disk_image "${imgfile}" 64 +${parted} -a none -s "${imgfile}" mklabel amiga mkpart x 0 10M +list_parts part_amiga "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,amiga1 + +# 2 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel amiga mkpart x 0 10M mkpart x 10M 20M +list_parts part_amiga "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,amiga1 $disk,amiga2 + +# 3 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel amiga mkpart x 0 10M mkpart x 10M 20M mkpart x 20M 30M +list_parts part_amiga "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,amiga1 $disk,amiga2 $disk,amiga3 + +# 4 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel amiga mkpart x 0 10M mkpart x 10M 20M mkpart x 20M 30M mkpart x 30M 40M +list_parts part_amiga "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,amiga1 $disk,amiga2 $disk,amiga3 $disk,amiga4 + +# 5 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel amiga mkpart x 0 10M mkpart x 10M 20M mkpart x 20M 30M mkpart x 30M 40M mkpart x 40M 50M +list_parts part_amiga "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,amiga1 $disk,amiga2 $disk,amiga3 $disk,amiga4 $disk,amiga5 + +# 6 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel amiga mkpart x 0 10M mkpart x 10M 20M mkpart x 20M 30M mkpart x 30M 40M mkpart x 40M 50M mkpart x 50M 60M +list_parts part_amiga "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,amiga1 $disk,amiga2 $disk,amiga3 $disk,amiga4 $disk,amiga5 $disk,amiga6 + +# 7 parts +create_disk_image "${imgfile}" 128 +${parted} -a none -s "${imgfile}" mklabel amiga mkpart x 0 10M mkpart x 10M 20M mkpart x 20M 30M mkpart x 30M 40M mkpart x 40M 50M mkpart x 50M 60M mkpart x 60M 70M +list_parts part_amiga "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,amiga1 $disk,amiga2 $disk,amiga3 $disk,amiga4 $disk,amiga5 $disk,amiga6 $disk,amiga7 + +# +# DragonFly BSD disklabel64 +# + +echo "Checking DragonFly BSD disklabel64..." + +create_dfly_image "${imgfile}" +list_parts part_dfly "${imgfile}" "${outfile}" +check_output "${outfile}" $disk $disk,msdos1 $disk,msdos1,dfly1 $disk,msdos1,dfly2 $disk,msdos1,dfly3 diff --git a/tests/pata_test.in b/tests/pata_test.in new file mode 100644 index 0000000..4b18fde --- /dev/null +++ b/tests/pata_test.in @@ -0,0 +1,55 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +disk=hda +indisk=ata0 + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # PLATFORM: Don't mess with real devices when OS is active + *-emu) + exit 0;; + # PLATFORM: no ATA on ARC platforms (they use SCSI) + *-arc) + exit 0;; + # FIXME: No native drivers are available for those + powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi) + exit 0;; + i386-ieee1275) + disk=hdb + indisk=ata1 + ;; +esac + +imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 + +echo "hello" > "$outfile" + +tar cf "$imgfile" "$outfile" + +if [ "$(echo "nativedisk; source '($indisk)/$outfile';" | "${grubshell}" --qemu-opts="-$disk $imgfile")" != "Hello World" ]; then + rm "$imgfile" + rm "$outfile" + exit 1 +fi + +rm "$imgfile" +rm "$outfile" diff --git a/tests/printf_unit_test.c b/tests/printf_unit_test.c new file mode 100644 index 0000000..098c29f --- /dev/null +++ b/tests/printf_unit_test.c @@ -0,0 +1,78 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <string.h> +#include <grub/test.h> +#include <grub/misc.h> + +#define MSG "printf test failed: %s, %s", real, expected + +#if defined(__GNUC__) && __GNUC__ >= 7 +#pragma GCC diagnostic ignored "-Wformat-truncation=" +#endif + +static void +printf_test (void) +{ + char real[512]; + char expected[512]; + char *null = NULL; + + grub_snprintf (real, sizeof (real), "%s", null); + snprintf (expected, sizeof (expected), "%s", null); + grub_test_assert (strcmp (real, expected) == 0, MSG); + + grub_snprintf (real, sizeof (real), "%10s", null); + snprintf (expected, sizeof (expected), "%10s", null); + grub_test_assert (strcmp (real, expected) == 0, MSG); + + grub_snprintf (real, sizeof (real), "%-10s", null); + snprintf (expected, sizeof (expected), "%-10s", null); + grub_test_assert (strcmp (real, expected) == 0, MSG); + + grub_snprintf (real, sizeof (real), "%d%%", 10); + snprintf (expected, sizeof (expected), "%d%%", 10); + grub_test_assert (strcmp (real, expected) == 0, MSG); + + grub_snprintf (real, sizeof (real), "%d %%", 10); + snprintf (expected, sizeof (expected), "%d %%", 10); + grub_test_assert (strcmp (real, expected) == 0, MSG); + + grub_snprintf (real, sizeof (real), "%%"); + snprintf (expected, sizeof (expected), "%%"); + grub_test_assert (strcmp (real, expected) == 0, MSG); + + grub_snprintf (real, sizeof (real), "%d %d %d", 1, 2, 3); + snprintf (expected, sizeof (expected), "%d %d %d", 1, 2, 3); + grub_test_assert (strcmp (real, expected) == 0, MSG); + grub_snprintf (real, sizeof (real), "%3$d %2$d %1$d", 1, 2, 3); + snprintf (expected, sizeof (expected), "%3$d %2$d %1$d", 1, 2, 3); + grub_test_assert (strcmp (real, expected) == 0, MSG); + grub_snprintf (real, sizeof (real), "%d %lld %d", 1, 2LL, 3); + snprintf (expected, sizeof (expected), "%d %lld %d", 1, 2LL, 3); + grub_test_assert (strcmp (real, expected) == 0, MSG); + grub_snprintf (real, sizeof (real), "%3$d %2$lld %1$d", 1, 2LL, 3); + snprintf (expected, sizeof (expected), "%3$d %2$lld %1$d", 1, 2LL, 3); + grub_test_assert (strcmp (real, expected) == 0, MSG); + grub_snprintf (real, sizeof (real), "%%0%dd ", 1); + snprintf (expected, sizeof (expected), "%%0%dd ", 1); + grub_test_assert (strcmp (real, expected) == 0, MSG); +} + +GRUB_UNIT_TEST ("printf_unit_test", printf_test); diff --git a/tests/priority_queue_unit_test.cc b/tests/priority_queue_unit_test.cc new file mode 100644 index 0000000..bb0060e --- /dev/null +++ b/tests/priority_queue_unit_test.cc @@ -0,0 +1,105 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2013 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <string.h> +#include <grub/test.h> +#include <grub/misc.h> +#include <grub/priority_queue.h> + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include <queue> + +using namespace std; + +static int +compar (const void *a_, const void *b_) +{ + int a = *(int *) a_; + int b = *(int *) b_; + if (a < b) + return -1; + if (a > b) + return +1; + return 0; +} + +static void +priority_queue_test (void) +{ + priority_queue <int> pq; + grub_priority_queue_t pq2; + int counter; + int s = 0; + pq2 = grub_priority_queue_new (sizeof (int), compar); + if (!pq2) + { + grub_test_assert (0, + "priority queue: queue creating failed\n"); + return; + } + srand (1); + + for (counter = 0; counter < 1000000; counter++) + { + int op = rand () % 10; + if (s && *(int *) grub_priority_queue_top (pq2) != pq.top ()) + { + printf ("Error at %d\n", counter); + grub_test_assert (0, + "priority queue: error at %d\n", counter); + return; + } + if (op < 3 && s) + { + grub_priority_queue_pop (pq2); + pq.pop (); + s--; + } + else + { + int v = rand (); + pq.push (v); + if (grub_priority_queue_push (pq2, &v) != 0) + { + grub_test_assert (0, + "priority queue: push failed"); + return; + } + s++; + } + } + while (s) + { + if (*(int *) grub_priority_queue_top (pq2) != pq.top ()) + { + grub_test_assert (0, + "priority queue: Error at the end. %d elements remaining.\n", s); + return; + } + grub_priority_queue_pop (pq2); + pq.pop (); + s--; + } + printf ("priority_queue: passed successfully\n"); +} + +GRUB_UNIT_TEST ("priority_queue_unit_test", priority_queue_test); diff --git a/tests/pseries_test.in b/tests/pseries_test.in new file mode 100644 index 0000000..655eb4f --- /dev/null +++ b/tests/pseries_test.in @@ -0,0 +1,37 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" != powerpc-ieee1275 ]; then + exit 0 +fi + +if [ "$(echo hello | "${grubshell}" --pseries --timeout=180 --boot=cd)" != "Hello World" ]; then + exit 1 +fi + +if [ "$(echo hello | "${grubshell}" --pseries --timeout=180 --boot=hd)" != "Hello World" ]; then + exit 1 +fi + +# FIXME: workaround SLOF bugs +#if [ "$(echo hello | "${grubshell}" --pseries --timeout=180 --boot=net)" != "Hello World" ]; then +# exit 1 +#fi diff --git a/tests/reiserfs_test.in b/tests/reiserfs_test.in new file mode 100644 index 0000000..b5fed76 --- /dev/null +++ b/tests/reiserfs_test.in @@ -0,0 +1,20 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.reiserfs >/dev/null 2>&1; then + echo "mkfs.reiserfs not installed; cannot test reiserfs." + exit 77 +fi + +"@builddir@/grub-fs-tester" reiserfs +"@builddir@/grub-fs-tester" reiserfs_old + diff --git a/tests/romfs_test.in b/tests/romfs_test.in new file mode 100644 index 0000000..98bb50c --- /dev/null +++ b/tests/romfs_test.in @@ -0,0 +1,10 @@ +#!@BUILD_SHEBANG@ + +set -e + +if ! which genromfs >/dev/null 2>&1; then + echo "genromfs not installed; cannot test romfs." + exit 77 +fi + +"@builddir@/grub-fs-tester" romfs diff --git a/tests/squashfs_test.in b/tests/squashfs_test.in new file mode 100644 index 0000000..2f044f9 --- /dev/null +++ b/tests/squashfs_test.in @@ -0,0 +1,12 @@ +#!@BUILD_SHEBANG@ + +set -e + +if ! which mksquashfs >/dev/null 2>&1; then + echo "mksquashfs not installed; cannot test squashfs." + exit 77 +fi + +"@builddir@/grub-fs-tester" squash4_gzip +"@builddir@/grub-fs-tester" squash4_xz +"@builddir@/grub-fs-tester" squash4_lzo diff --git a/tests/syslinux/ubuntu10.04/isolinux/adtxt.cfg b/tests/syslinux/ubuntu10.04/isolinux/adtxt.cfg new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/syslinux/ubuntu10.04/isolinux/adtxt.cfg diff --git a/tests/syslinux/ubuntu10.04/isolinux/dtmenu.cfg b/tests/syslinux/ubuntu10.04/isolinux/dtmenu.cfg new file mode 100644 index 0000000..2e107fa --- /dev/null +++ b/tests/syslinux/ubuntu10.04/isolinux/dtmenu.cfg @@ -0,0 +1,52 @@ +menu hshift 9 +menu width 58 + +menu begin desktop + include stdmenu.cfg + menu hshift 13 + menu width 49 + menu label Alternative desktop environments + menu title Desktop environment menu + label mainmenu-kde + menu label ^Back.. + text help + Higher level options install the GNOME desktop environment + endtext + menu exit + menu begin kde-desktop + include stdmenu.cfg + menu label ^KDE + menu title KDE desktop boot menu + text help + Select the 'K Desktop Environment' for the Desktop task + endtext + label mainmenu-kde + menu label ^Back.. + menu exit + include kde/menu.cfg + menu end + menu begin lxde-desktop + include stdmenu.cfg + menu label ^LXDE + menu title LXDE desktop boot menu + text help + Select the 'Lightweight X11 Desktop Environment' for the Desktop task + endtext + label mainmenu-lxde + menu label ^Back.. + menu exit + include lxde/menu.cfg + menu end + menu begin xfce-desktop + include stdmenu.cfg + menu label ^Xfce + menu title Xfce desktop boot menu + text help + Select the 'Xfce lightweight desktop environment' for the Desktop task + endtext + label mainmenu-xfce + menu label ^Back.. + menu exit + include xfce/menu.cfg + menu end +menu end diff --git a/tests/syslinux/ubuntu10.04/isolinux/exithelp.cfg b/tests/syslinux/ubuntu10.04/isolinux/exithelp.cfg new file mode 100644 index 0000000..3119e65 --- /dev/null +++ b/tests/syslinux/ubuntu10.04/isolinux/exithelp.cfg @@ -0,0 +1,3 @@ +label menu + kernel vesamenu.c32 + config isolinux.cfg diff --git a/tests/syslinux/ubuntu10.04/isolinux/gfxboot.cfg b/tests/syslinux/ubuntu10.04/isolinux/gfxboot.cfg new file mode 100644 index 0000000..b799cb5 --- /dev/null +++ b/tests/syslinux/ubuntu10.04/isolinux/gfxboot.cfg @@ -0,0 +1,12 @@ +foreground=0xFFFFFF +background=0x958490 +screen-colour=0x270A1E +hidden-timeout=2 +label normal=Normal +append normal= +label driverupdates=Use driver update disc +append driverupdates=debian-installer/driver-update=true +applies driverupdates=live live-install +label oem=OEM install (for manufacturers) +append oem=oem-config/enable=true +applies oem=live live-install install diff --git a/tests/syslinux/ubuntu10.04/isolinux/isolinux.cfg b/tests/syslinux/ubuntu10.04/isolinux/isolinux.cfg new file mode 100644 index 0000000..fd9c333 --- /dev/null +++ b/tests/syslinux/ubuntu10.04/isolinux/isolinux.cfg @@ -0,0 +1,6 @@ +# D-I config version 2.0 +include menu.cfg +default vesamenu.c32 +prompt 0 +timeout 50 +ui gfxboot bootlogo diff --git a/tests/syslinux/ubuntu10.04/isolinux/menu.cfg b/tests/syslinux/ubuntu10.04/isolinux/menu.cfg new file mode 100644 index 0000000..9f5607d --- /dev/null +++ b/tests/syslinux/ubuntu10.04/isolinux/menu.cfg @@ -0,0 +1,23 @@ +menu hshift 13 +menu width 49 +menu margin 8 + +menu title Installer boot menu +include stdmenu.cfg +include txt.cfg +include gtk.cfg +menu begin advanced + menu title Advanced options + include stdmenu.cfg + label mainmenu + menu label ^Back.. + menu exit + include adtxt.cfg + include adgtk.cfg +menu end +label help + menu label ^Help + text help + Display help screens; type 'menu' at boot prompt to return to this menu + endtext + config prompt.cfg diff --git a/tests/syslinux/ubuntu10.04/isolinux/po4a.cfg b/tests/syslinux/ubuntu10.04/isolinux/po4a.cfg new file mode 100644 index 0000000..75f6788 --- /dev/null +++ b/tests/syslinux/ubuntu10.04/isolinux/po4a.cfg @@ -0,0 +1,3 @@ +[po4a_langs] ar bn ca cs da de es eu fi fr gl hu id it ja ka ko ku lv nb nl pl pt pt_BR ru sk sv ta tr vi zh_CN zh_TW +[po4a_paths] po/help.pot $lang:po/$lang.po +[type:docbook] help.xml diff --git a/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg b/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg new file mode 100644 index 0000000..f9984ae --- /dev/null +++ b/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg @@ -0,0 +1,16 @@ +prompt 1 +display f1.txt +timeout 50 +include menu.cfg +include exithelp.cfg + +f1 f1.txt +f2 f2.txt +f3 f3.txt +f4 f4.txt +f5 f5.txt +f6 f6.txt +f7 f7.txt +f8 f8.txt +f9 f9.txt +f0 f10.txt diff --git a/tests/syslinux/ubuntu10.04/isolinux/rqtxt.cfg b/tests/syslinux/ubuntu10.04/isolinux/rqtxt.cfg new file mode 100644 index 0000000..bdf6231 --- /dev/null +++ b/tests/syslinux/ubuntu10.04/isolinux/rqtxt.cfg @@ -0,0 +1,4 @@ +label rescue + menu label ^Rescue mode + kernel /install/vmlinuz + append vga=788 initrd=/install/initrd.gz rescue/enable=true -- quiet diff --git a/tests/syslinux/ubuntu10.04/isolinux/stdmenu.cfg b/tests/syslinux/ubuntu10.04/isolinux/stdmenu.cfg new file mode 100644 index 0000000..671b16f --- /dev/null +++ b/tests/syslinux/ubuntu10.04/isolinux/stdmenu.cfg @@ -0,0 +1,15 @@ +menu background splash.png +menu color title * #FFFFFFFF * +menu color border * #00000000 #00000000 none +menu color sel * #ffffffff #76a1d0ff * +menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff * +menu color tabmsg * #ffffffff #00000000 * +menu color help 37;40 #ffdddd00 #00000000 none +menu vshift 12 +menu rows 10 +menu helpmsgrow 15 +# The command line must be at least one line from the bottom. +menu cmdlinerow 16 +menu timeoutrow 16 +menu tabmsgrow 18 +menu tabmsg Press ENTER to boot or TAB to edit a menu entry diff --git a/tests/syslinux/ubuntu10.04/isolinux/txt.cfg b/tests/syslinux/ubuntu10.04/isolinux/txt.cfg new file mode 100644 index 0000000..860daad --- /dev/null +++ b/tests/syslinux/ubuntu10.04/isolinux/txt.cfg @@ -0,0 +1,19 @@ +default live +label live + menu label ^Try Ubuntu without installing + kernel /casper/vmlinuz + append file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash -- +label live-install + menu label ^Install Ubuntu + kernel /casper/vmlinuz + append file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash -- +label check + menu label ^Check disc for defects + kernel /casper/vmlinuz + append boot=casper integrity-check initrd=/casper/initrd.lz quiet splash -- +label memtest + menu label Test ^memory + kernel /install/mt86plus +label hd + menu label ^Boot from first hard disk + localboot 0x80 diff --git a/tests/syslinux/ubuntu10.04_grub.cfg.in b/tests/syslinux/ubuntu10.04_grub.cfg.in new file mode 100644 index 0000000..441dec0 --- /dev/null +++ b/tests/syslinux/ubuntu10.04_grub.cfg.in @@ -0,0 +1,236 @@ + background_image '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux'/'splash.png' +# D-I config version 2.0 + # UNSUPPORTED command 'menu hshift 13' + # UNSUPPORTED command 'menu width 49' + # UNSUPPORTED command 'menu margin 8' + + # UNSUPPORTED command 'menu title Installer boot menu' + # UNSUPPORTED command 'menu color title * #FFFFFFFF *' + # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' + # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' + # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' + # UNSUPPORTED command 'menu vshift 12' + # UNSUPPORTED command 'menu rows 10' + # UNSUPPORTED command 'menu helpmsgrow 15' +# The command line must be at least one line from the bottom. + # UNSUPPORTED command 'menu cmdlinerow 16' + # UNSUPPORTED command 'menu timeoutrow 16' + # UNSUPPORTED command 'menu tabmsgrow 18' + # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' +set timeout=5 + default='vesamenu.c32' +menuentry 'Try Ubuntu without installing' --hotkey 't' --id 'live' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash -- + initrd$linux_suffix '/'/'/casper/initrd.lz' +} +menuentry 'Install Ubuntu' --hotkey 'i' --id 'live-install' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash -- + initrd$linux_suffix '/'/'/casper/initrd.lz' +} +menuentry 'Check disc for defects' --hotkey 'c' --id 'check' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/casper/vmlinuz' boot=casper integrity-check initrd=/casper/initrd.lz quiet splash -- + initrd$linux_suffix '/'/'/casper/initrd.lz' +} +menuentry 'Test memory' --hotkey 'm' --id 'memtest' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/install/mt86plus' +} +menuentry 'Boot from first hard disk' --hotkey 'b' --id 'hd' { +# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/gtk.cfg not found + # UNSUPPORTED command 'menu begin advanced' + # UNSUPPORTED command 'menu title Advanced options' + # UNSUPPORTED command 'menu color title * #FFFFFFFF *' + # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' + # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' + # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' + # UNSUPPORTED command 'menu vshift 12' + # UNSUPPORTED command 'menu rows 10' + # UNSUPPORTED command 'menu helpmsgrow 15' +# The command line must be at least one line from the bottom. + # UNSUPPORTED command 'menu cmdlinerow 16' + # UNSUPPORTED command 'menu timeoutrow 16' + # UNSUPPORTED command 'menu tabmsgrow 18' + # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' + root=hd0; + chainloader +1; +} +menuentry 'Back..' --hotkey 'b' --id 'mainmenu' { + # UNSUPPORTED command 'menu exit' +# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/adgtk.cfg not found + # UNSUPPORTED command 'menu end' + # UNSUPPORTED entry type 0 +true; +} +menuentry 'Help' --hotkey 'h' --id 'help' { + # UNSUPPORTED command 'ui gfxboot bootlogo' +#'@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux'/'prompt.cfg' (host)@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg: + background_image '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/'/'splash.png' + # UNSUPPORTED command 'display f1.txt' + # UNSUPPORTED command 'menu hshift 13' + # UNSUPPORTED command 'menu width 49' + # UNSUPPORTED command 'menu margin 8' + + # UNSUPPORTED command 'menu title Installer boot menu' + # UNSUPPORTED command 'menu color title * #FFFFFFFF *' + # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' + # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' + # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' + # UNSUPPORTED command 'menu vshift 12' + # UNSUPPORTED command 'menu rows 10' + # UNSUPPORTED command 'menu helpmsgrow 15' +# The command line must be at least one line from the bottom. + # UNSUPPORTED command 'menu cmdlinerow 16' + # UNSUPPORTED command 'menu timeoutrow 16' + # UNSUPPORTED command 'menu tabmsgrow 18' + # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' +set timeout=5 + default='live' +menuentry 'Try Ubuntu without installing' --hotkey 't' --id 'live' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash -- + initrd$linux_suffix '/'/'/casper/initrd.lz' +} +menuentry 'Install Ubuntu' --hotkey 'i' --id 'live-install' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash -- + initrd$linux_suffix '/'/'/casper/initrd.lz' +} +menuentry 'Check disc for defects' --hotkey 'c' --id 'check' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/casper/vmlinuz' boot=casper integrity-check initrd=/casper/initrd.lz quiet splash -- + initrd$linux_suffix '/'/'/casper/initrd.lz' +} +menuentry 'Test memory' --hotkey 'm' --id 'memtest' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/install/mt86plus' +} +menuentry 'Boot from first hard disk' --hotkey 'b' --id 'hd' { +# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//gtk.cfg not found + # UNSUPPORTED command 'menu begin advanced' + # UNSUPPORTED command 'menu title Advanced options' + # UNSUPPORTED command 'menu color title * #FFFFFFFF *' + # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' + # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' + # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' + # UNSUPPORTED command 'menu vshift 12' + # UNSUPPORTED command 'menu rows 10' + # UNSUPPORTED command 'menu helpmsgrow 15' +# The command line must be at least one line from the bottom. + # UNSUPPORTED command 'menu cmdlinerow 16' + # UNSUPPORTED command 'menu timeoutrow 16' + # UNSUPPORTED command 'menu tabmsgrow 18' + # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' + root=hd0; + chainloader +1; +} +menuentry 'Back..' --hotkey 'b' --id 'mainmenu' { + # UNSUPPORTED command 'menu exit' +# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//adgtk.cfg not found + # UNSUPPORTED command 'menu end' + # UNSUPPORTED entry type 0 +true; +} +menuentry 'Help' --hotkey 'h' --id 'help' { +#'@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/'/'prompt.cfg' (host)@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg: + syslinux_configfile -r '/'/'/' -c '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/'/'' '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/'/'prompt.cfg' +} +menuentry 'menu' --id 'menu' { + # UNSUPPORTED command 'f1 f1.txt' + # UNSUPPORTED command 'f2 f2.txt' + # UNSUPPORTED command 'f3 f3.txt' + # UNSUPPORTED command 'f4 f4.txt' + # UNSUPPORTED command 'f5 f5.txt' + # UNSUPPORTED command 'f6 f6.txt' + # UNSUPPORTED command 'f7 f7.txt' + # UNSUPPORTED command 'f8 f8.txt' + # UNSUPPORTED command 'f9 f9.txt' + # UNSUPPORTED command 'f0 f10.txt' +#'@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/'/'isolinux.cfg' (host)@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/isolinux.cfg: + background_image '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//'/'splash.png' +# D-I config version 2.0 + # UNSUPPORTED command 'menu hshift 13' + # UNSUPPORTED command 'menu width 49' + # UNSUPPORTED command 'menu margin 8' + + # UNSUPPORTED command 'menu title Installer boot menu' + # UNSUPPORTED command 'menu color title * #FFFFFFFF *' + # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' + # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' + # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' + # UNSUPPORTED command 'menu vshift 12' + # UNSUPPORTED command 'menu rows 10' + # UNSUPPORTED command 'menu helpmsgrow 15' +# The command line must be at least one line from the bottom. + # UNSUPPORTED command 'menu cmdlinerow 16' + # UNSUPPORTED command 'menu timeoutrow 16' + # UNSUPPORTED command 'menu tabmsgrow 18' + # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' +set timeout=5 + default='vesamenu.c32' +menuentry 'Try Ubuntu without installing' --hotkey 't' --id 'live' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash -- + initrd$linux_suffix '/'/'/casper/initrd.lz' +} +menuentry 'Install Ubuntu' --hotkey 'i' --id 'live-install' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash -- + initrd$linux_suffix '/'/'/casper/initrd.lz' +} +menuentry 'Check disc for defects' --hotkey 'c' --id 'check' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/casper/vmlinuz' boot=casper integrity-check initrd=/casper/initrd.lz quiet splash -- + initrd$linux_suffix '/'/'/casper/initrd.lz' +} +menuentry 'Test memory' --hotkey 'm' --id 'memtest' { + if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi + linux$linux_suffix '/'/'/install/mt86plus' +} +menuentry 'Boot from first hard disk' --hotkey 'b' --id 'hd' { +# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux///gtk.cfg not found + # UNSUPPORTED command 'menu begin advanced' + # UNSUPPORTED command 'menu title Advanced options' + # UNSUPPORTED command 'menu color title * #FFFFFFFF *' + # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' + # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' + # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' + # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' + # UNSUPPORTED command 'menu vshift 12' + # UNSUPPORTED command 'menu rows 10' + # UNSUPPORTED command 'menu helpmsgrow 15' +# The command line must be at least one line from the bottom. + # UNSUPPORTED command 'menu cmdlinerow 16' + # UNSUPPORTED command 'menu timeoutrow 16' + # UNSUPPORTED command 'menu tabmsgrow 18' + # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' + root=hd0; + chainloader +1; +} +menuentry 'Back..' --hotkey 'b' --id 'mainmenu' { + # UNSUPPORTED command 'menu exit' +# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux///adgtk.cfg not found + # UNSUPPORTED command 'menu end' + # UNSUPPORTED entry type 0 +true; +} +menuentry 'Help' --hotkey 'h' --id 'help' { + # UNSUPPORTED command 'ui gfxboot bootlogo' +#'@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//'/'prompt.cfg' (host)@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg: + syslinux_configfile -r '/'/'/' -c '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//'/'' '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//'/'prompt.cfg' +} +} +} diff --git a/tests/syslinux_test.in b/tests/syslinux_test.in new file mode 100644 index 0000000..4ea8639 --- /dev/null +++ b/tests/syslinux_test.in @@ -0,0 +1,16 @@ +#!@BUILD_SHEBANG@ + +set -e + +outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 + +"@builddir@/grub-syslinux2cfg" -r "@abs_top_srcdir@/tests/syslinux/ubuntu10.04" "@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/isolinux.cfg" -o "$outfile" + +echo "$outfile" + +if ! diff -u "$outfile" "@builddir@/tests/syslinux/ubuntu10.04_grub.cfg"; then + echo "Mismatch in ubuntu10.04" + exit 1; +fi + +exit 0 diff --git a/tests/tar_test.in b/tests/tar_test.in new file mode 100644 index 0000000..6e2f2de --- /dev/null +++ b/tests/tar_test.in @@ -0,0 +1,10 @@ +#!@BUILD_SHEBANG@ + +set -e + +if ! which tar >/dev/null 2>&1; then + echo "tar not installed; cannot test tar." + exit 77 +fi + +"@builddir@/grub-fs-tester" tarfs diff --git a/tests/test_sha512sum.in b/tests/test_sha512sum.in new file mode 100644 index 0000000..027092a --- /dev/null +++ b/tests/test_sha512sum.in @@ -0,0 +1,36 @@ +#! @BUILD_SHEBANG@ + +# create a randome file +file="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +cat >$file <<EOF +hello world! +EOF + +. "@builddir@/grub-core/modinfo.sh" + +if [ x"${grub_modinfo_platform}" = xemu ]; then + grub_file="(host)$file" +else + grub_file="/boot/grub/file" +fi + + +outfile1="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +@builddir@/grub-shell --files=/boot/grub/file=$file >$outfile1 <<EOF +sha512sum $grub_file +EOF + +outfile2="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +sha512sum $file >$outfile2 + +SHA1=`cat $outfile1 | tr -d '\n' | cut -f1 -d\ ` +SHA2=`cat $outfile2 | cut -f1 -d\ ` + +if test "$SHA1" = "$SHA2"; then + rm -f ${outfile1} ${outfile2} + exit 0 +else + echo "GRUB sha512sum output did not match sha512sum output." + echo "See diff -u ${outfile1} ${outfile2}" + exit 1 +fi diff --git a/tests/test_unset.in b/tests/test_unset.in new file mode 100644 index 0000000..30f1a25 --- /dev/null +++ b/tests/test_unset.in @@ -0,0 +1,10 @@ +#! @builddir@/grub-shell-tester + +foo=one +echo $foo + +unset foo +echo $foo +echo ${foo} + + diff --git a/tests/udf_test.in b/tests/udf_test.in new file mode 100644 index 0000000..fb92f01 --- /dev/null +++ b/tests/udf_test.in @@ -0,0 +1,19 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkudffs >/dev/null 2>&1; then + echo "mkudffs not installed; cannot test UDF." + exit 77 +fi + +"@builddir@/grub-fs-tester" udf + diff --git a/tests/uhci_test.in b/tests/uhci_test.in new file mode 100644 index 0000000..f0eec50 --- /dev/null +++ b/tests/uhci_test.in @@ -0,0 +1,51 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in + # PLATFORM: Don't mess with real devices when OS is active + *-emu) + exit 0;; + # FIXME: qemu gets bonito DMA wrong + mipsel-loongson) + exit 0;; + # PLATFORM: no USB on ARC and qemu-mips platforms + mips*-arc | mips*-qemu_mips) + exit 0;; + # FIXME: No native drivers are available for those + powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi) + exit 0;; +esac + +imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 + +echo "hello" > "$outfile" + +tar cf "$imgfile" "$outfile" + +if [ "$(echo "nativedisk; source '(usb0)/$outfile';" | "${grubshell}" --qemu-opts="-device ich9-usb-uhci1 -drive id=my_usb_disk,file=$imgfile,if=none -device usb-storage,drive=my_usb_disk" | tail -n 1)" != "Hello World" ]; then + rm "$imgfile" + rm "$outfile" + exit 1 +fi + +rm "$imgfile" +rm "$outfile" diff --git a/tests/util/grub-fs-tester.in b/tests/util/grub-fs-tester.in new file mode 100644 index 0000000..bfc425e --- /dev/null +++ b/tests/util/grub-fs-tester.in @@ -0,0 +1,1572 @@ +#!@BUILD_SHEBANG@ + +set -e + +fs="$1" + +GRUBFSTEST="@builddir@/grub-fstest" + +tempdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + +# This wrapper is to ease insertion of valgrind or time statistics +run_it () { + LC_ALL=C "$GRUBFSTEST" "$@" +} + +range() { + range_counter="$1" + while test "$range_counter" -le "$2"; do + echo "$range_counter" + range_counter="$((range_counter + $3))" + done +} + +powrange() { + range_counter="$1" + while test "$range_counter" -le "$2"; do + echo "$range_counter" + range_counter="$((range_counter * 2))" + done +} + +run_grubfstest () { + need_images= + for i in $(range 0 $((NEED_IMAGES_N-1)) 1); do + need_images="$need_images $FSIMAGEP${i}.img"; + done + + run_it -c $NEED_IMAGES_N $need_images "$@" +} + +# OS LIMITATION: GNU/Linux has no AFS support, so we use a premade image and a reference tar file. I.a. no multiblocksize test + +MINLOGSECSIZE=9 +MAXLOGSECSIZE=9 +case x"$fs" in + xntfs*) + MINLOGSECSIZE=8 + MAXLOGSECSIZE=12;; + xvfat*|xmsdos*) + MINLOGSECSIZE=9 + # OS LIMITATION: It could go up to 32768 but Linux rejects sector sizes > 4096 + MAXLOGSECSIZE=12;; + xext*) + MINLOGSECSIZE=8 + MAXLOGSECSIZE=12;; + xbtrfs*) + MINLOGSECSIZE=8 + # OS LIMITATION: It could go up to 32768 but Linux rejects sector sizes > 4096 + MAXLOGSECSIZE=12;; + xxfs) + MINLOGSECSIZE=9 + # OS LIMITATION: GNU/Linux doesn't accept > 4096 + MAXLOGSECSIZE=12;; + xxfs_crc) + MINLOGSECSIZE=9 + # OS LIMITATION: GNU/Linux doesn't accept > 1024 + MAXLOGSECSIZE=10;; + xzfs*) + # OS LIMITATION: zfs-fuse hangs when creating zpool with sectors <=256B. + MINLOGSECSIZE=9 + # OS LIMITATION: zfs-fuse fails with >= 32K sectors. + # OS limitation: zfs-fuse always uses ashift=9 with loop devices + MAXLOGSECSIZE=9;; +esac +for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do + SECSIZE="$((1 << LOGSECSIZE))" + MINBLKSIZE=512 + MAXBLKSIZE=512 + BLKSTEP=0 + case x"$fs" in + xntfs*) + MINBLKSIZE=$SECSIZE + MAXBLKSIZE=65536 + if [ x"$SECSIZE" = x256 ]; then + MINBLKSIZE=512 + MAXBLKSIZE=32768 + fi + ;; + xvfat* | xmsdos*) + MINBLKSIZE=$SECSIZE + MAXBLKSIZE=$((128*SECSIZE)) + ;; + xexfat*) + MINBLKSIZE=$SECSIZE + # It could go further but it requires more and more space + MAXBLKSIZE=8286208 + ;; + xhfs) + MINBLKSIZE=512 + # OS LIMITATION: should be 1048576 but linux hangs on unmnount with + # >= 524288 + MAXBLKSIZE=262144 + ;; + xhfsplus | xhfsplus_casesens | xhfsplus_wrap) + MINBLKSIZE=512 + MAXBLKSIZE=1048576 + ;; + xnilfs2) + # nilfs2 supports blocksizes from 1024 to 4096 + # but non-4096 results in kernel oops in some cases, + # avoid it. + MINBLKSIZE=4096 + MAXBLKSIZE=4096 + ;; + xsfs*) + MINBLKSIZE=512 + MAXBLKSIZE=4096 + ;; + xaffs | xaffs_intl) + MINBLKSIZE=512 + MAXBLKSIZE=4096 + ;; + xreiserfs*) + MINBLKSIZE=512 + # OS LIMITATION: 8192 isn't supported. + MAXBLKSIZE=4096 + ;; + x"mdraid"*) + MINBLKSIZE=4096 + # OS LIMITATION: Linux oopses with >=32768K + MAXBLKSIZE=$((16384*1024)) + ;; + x"lvm_raid1"* | x"lvm_raid4" | x"lvm_raid5" | x"lvm_raid6") + # OS LIMITATION: Linux crashes with less than 16384 + MINBLKSIZE=16384 + # Could go further but what's the point? + MAXBLKSIZE=$((65536*1024)) + ;; + x"lvm_mirrorall") + MINBLKSIZE=2048 + # Could go further but what's the point? + MAXBLKSIZE=$((65536*1024)) + ;; + x"lvm_mirror1") + MINBLKSIZE=4096 + # Could go further but what's the point? + MAXBLKSIZE=$((65536*1024)) + ;; + x"lvm_stripe") + MINBLKSIZE=4096 + # Could go further but what's the point? + MAXBLKSIZE=$((65536*1024)) + ;; + x"lvm"*) + MINBLKSIZE=1024 + # Could go further but what's the point? + MAXBLKSIZE=$((65536*1024)) + ;; + xext4_encrypt) + # OS LIMITATION: Linux currently only allows the 'encrypt' feature + # in combination with block_size = PAGE_SIZE (4096 bytes on x86). + MINBLKSIZE=$(getconf PAGE_SIZE) + MAXBLKSIZE=$MINBLKSIZE + ;; + xext*) + MINBLKSIZE=1024 + if [ $MINBLKSIZE -lt $SECSIZE ]; then + MINBLKSIZE=$SECSIZE + fi + MAXBLKSIZE=4096 + ;; + xsquash*) + MINBLKSIZE=4096 + MAXBLKSIZE=1048576;; + xxfs|xf2fs) + MINBLKSIZE=$SECSIZE + # OS Limitation: GNU/Linux doesn't accept > 4096 + MAXBLKSIZE=4096;; + xxfs_crc) + # OS Limitation: GNU/Linux doesn't accept != 1024 + MINBLKSIZE=1024 + MAXBLKSIZE=1024;; + xudf) + MINBLKSIZE=1024 + MAXBLKSIZE=4096;; + xbfs) + MINBLKSIZE=1024 + MAXBLKSIZE=8192;; + xufs*) + MINBLKSIZE=4096 + # OS Limitation: Linux rejects 65536 blocks. + MAXBLKSIZE=32768;; + xminix3) + # OS LIMITATION: Linux rejects non-power-of-two blocks. + # OS LIMITATION: Linux rejects > 4096. + MINBLKSIZE=1024 + MAXBLKSIZE=4096;; + esac + if test "$BLKSTEP" -eq 0; then + blksizes="$(powrange "$MINBLKSIZE" "$MAXBLKSIZE")" + else + blksizes="$(range "$MINBLKSIZE" "$MAXBLKSIZE" "$BLKSTEP")" + fi + for BLKSIZE in $blksizes; do + MAXDEVICES=1 + MINDEVICES=1 + export fs + case x"$fs" in + x"zfs_raidz" | x"zfs_stripe" | x"zfs_mirror" | xbtrfs_raid0 \ + | xbtrfs_raid1 | x"mdraid"*"_raid4" | x"mdraid"*"_raid5" \ + | x"mdraid"*"_linear" \ + | x"mdraid"*"_raid10" | xlvm_raid1* | xlvm_mirror1 | xlvm_mirrorall) + MINDEVICES=2 + MAXDEVICES=7 + ;; + xbtrfs_raid10) + MINDEVICES=4 + MAXDEVICES=7 + ;; + x"zfs_raidz2"| xlvm_raid5 | xlvm_raid4) + MINDEVICES=3 + MAXDEVICES=7;; + x"zfs_raidz3" | x"mdraid"*"_raid6") + MINDEVICES=4 + MAXDEVICES=7;; + xlvm_raid6) + MINDEVICES=5 + MAXDEVICES=7;; + x"mdraid"*"_raid0" | x"mdraid"*"_raid1" | x"lvm" | xlvm_stripe) + MINDEVICES=1 + MAXDEVICES=7;; + esac + + for NDEVICES in $(range "$MINDEVICES" "$MAXDEVICES" 1); do + export NDEVICES + unset FSIMAGEP + FSIMAGEP="${tempdir}/${fs}_${SECSIZE}_${BLKSIZE}_${NDEVICES}_" + export FSIMAGEP + unset NEED_IMAGES; + + case x$fs in + # RAID 1 has to work with even one device of the set. + xzfs_mirror | x"mdraid"*"_raid1" | xlvm_mirrorall | xlvm_raid1all) + NEED_IMAGES_N=1;; + # Degrade raidz by removing 3 devices + xzfs_raidz3) + NEED_IMAGES_N=$((NDEVICES-3));; + # Degrade raidz by removing 2 devices + xzfs_raidz2 | x"mdraid"*"_raid6" | x"lvm_raid6") + NEED_IMAGES_N=$((NDEVICES-2));; + # Degrade raidz and btrfs RAID1 by removing one device + xbtrfs_raid1 | xbtrfs_raid10 | xzfs_raidz | x"mdraid"*"_raid4" \ + | x"mdraid"*"_raid5" | x"mdraid"*"_raid10" | xlvm_mirror1 \ + | x"lvm_raid1" | x"lvm_raid4" | x"lvm_raid5") + NEED_IMAGES_N=$((NDEVICES-1));; + *) + NEED_IMAGES_N=$NDEVICES;; + esac + export NEED_IMAGES_N + + MNTPOINTRO="${tempdir}/${fs}_ro" + MNTPOINTRW="${tempdir}/${fs}_rw" + MOUNTOPTS="" + MOUNTFS="$fs" + MASTER="${tempdir}/master" + FSLABEL="grub_;/testรฉ๐ฏฆ๐ฏฆ๐ฏฆ๐ะบะธัะธัi urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewrewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfew" + CFILESRC= + for cand in /usr/share/dict/american-english /usr/share/dict/linux.words /data/data/com.termux/files/usr/share/hunspell/en_US.dic; do + if test -f "$cand" ; then + CFILESRC="$cand" + break + fi + done + if test "$CFILESRC" = "" ; then + echo "Couldn't find compressible file" >&2 + exit 1 + fi + case x"$fs" in + # FS LIMITATION: 8.3 names + xmsdos*) + CFILE="american.eng";; + xiso9660) + CFILE="american_english";; + *) + CFILE="american-english";; + esac + # OS LIMITATION: Limited by NAME_MAX (usually 255) in GNU/Linux + LONGNAME="qwertzuiopasdfghjklyxcvbnm1234567890qwertzuiopasdfghjklyxcvbnm1234567890oiewqfiewioqoiqoiurqruewqoiuwoieoiiuewqroreqiufieiuwrnureweriuvceoiroiewqoiricdsalkcndsakfirefoiwqeoircorejwoijfreoijojoiewjfwnfcoirenfoirefnreoifenoiwfnoi" + rm -rf "$MASTER" + + case x"$fs" in + # FS LIMITATION: HFS+ label is at most 255 UTF-16 chars + # OS LIMITATION: Linux HFS+ tools check UTF-8 length and don't + # handle out-of-BMP characters + x"hfsplus" | x"hfsplus_casesens" | x"hfsplus_wrap") + FSLABEL="grub_;/testรฉไไไะบะธัะธัi urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoiq" + ;; + # FS LIMITATION: btrfs label is at most 255 UTF-8 chars + x"btrfs"*) + FSLABEL="grub_;/testรฉ๐ฏฆ๐ฏฆ๐ะบะธัะธัi urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoi";; + + # FS LIMITATION: f2fs label is at most 512 UTF-16 chars + x"f2fs") + FSLABEL="grub_;/testรฉไไไะบะธัะธัiurewfceniuewruewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoirvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoircreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoiq";; + + # FS LIMITATION: exfat is at most 15 UTF-16 chars + x"exfat") + FSLABEL="gรฉั ;/๐ฏฆ๐ฏฆ๐ะบะธั";; + # FS LIMITATION: ntfs label is at most ?? UTF-16 chars + x"ntfs"*) + FSLABEL="grub_;/testรฉัi u๐ฏฆ๐๐ฏฆะบะธัะธrewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvniwnivrewiuvcrewvnuewvrrrewniureifiuewifjiww";; + # FS LIMITATION: nilfs2 label is at most 80 UTF-8 characters + x"nilfs2") + FSLABEL="grub_;/testรฉัi u๐๐ฏฆ๐ฏฆะบะธัะธrewfceniuewruevrewnuuireurevueurnievrewfne";; + # FS LIMITATION: afs and iso9660 label is at most 32 UTF-8 characters + x"afs" | xiso9660 | xrockridge | xrockridge_joliet\ + | xiso9660_1999 | xrockridge_1999 | xrockridge_joliet_1999) + FSLABEL="gr_;/รฉ๐ฏฆ๐ฏฆ๐ะบะธัะธั u";; + # FS LIMITATION: bfs label is at most 32 UTF-8 characters + # OS LIMITATION: bfs label can't contain ; or / + x"bfs") + FSLABEL="grub_รฉ๐ฏฆ๐ฏฆ๐ะบะธัะธั u";; + # FS LIMITATION: Joliet label is at most 16 UTF-16 characters + # OS LIMITATION: xorriso doesn't handle out-of-BMP characters + xjoliet | xjoliet_1999) + FSLABEL="g;/_รฉไไไไไพไดะบะธั u" + #FSLABEL="g;/_รฉ๐ฏฆ๐ฏฆ๐ะบะธั u" + ;; + # FS LIMITATION: reiserfs, extN and jfs label is at most 16 UTF-8 characters + x"reiserfs_old" | x"reiserfs" | x"ext"* | x"lvm"* | x"mdraid"* | x"jfs" | x"jfs_caseins") + FSLABEL="g;/รฉั ๐ฏฆ๐";; + # FS LIMITATION: No underscore, space, semicolon, slash or international characters in UFS* in label. Limited to 32 UTF-8 characters + x"ufs1" | x"ufs1_sun" | x"ufs2") + FSLABEL="grubtest""ieurrucnenreeiurueurewf";; + # FS LIMITATION: XFS label is at most 12 UTF-8 characters + x"xfs"|x"xfs_crc") + FSLABEL="gรฉั ๐ะบ";; + # FS LIMITATION: FAT labels limited to 11 characters, no international characters or lowercase + x"vfat"* | xmsdos*) + FSLABEL="GRUBTEST ;_";; + # FS LIMITATION: AFFS is latin1. At most 29 characters + x"affs" | xaffs_intl) + FSLABEL="grub_tt? #*w;/eยฃ@ยกยคยฝยพ{[]}<>.,";; + # FS LIMITATION: SFS is latin1. At most 30 characters + x"sfs"*) + FSLABEL="GRUB tt รถรครผรฉ;/ร รจรง รฅรธยฟยชยฉรพรฐรยซยปยตยฌ";; + # FS LIMITATION: HFS is Mac-Roman. At most 27 characters + x"hfs") + FSLABEL="grub_t;/estรฉร รจรจรฉie fiucnree";; + # FS LIMITATION: UDF label is either up to 127 latin1 characters or 63 UTF-16 ones + # OS LIMITATION: Linux UDF tools force ASCII label ... + x"udf") + FSLABEL="grub_;/testurewfceniuewruevrewnuuireurevueurnievr";; + # FS LIMITATION: ZFS doesn't accept non-ASCII in label + # FIXME: since this is used as a path component for mount it's very limited in length + xzfs_* | xzfs) + FSLABEL="grub_testieufiue r";; + esac + case x"$fs" in + xmdraid*) + DISKSIZE=314572800;; + xlvm*) + LVMBLKMUL=$(((5800 * 1048576) / (8 * BLKSIZE * NDEVICES))) + DISKSIZE=$((8*BLKSIZE*LVMBLKMUL));; + # FS LIMITATION: some fs have disk size limit + x"vfat12" | xmsdos12) + DISKSIZE=$((4000*BLKSIZE));; + x"vfat12a" | xmsdos12a) + if [ $BLKSIZE -ge 2048 ]; then + DISKSIZE=$((2500*BLKSIZE)) + else + DISKSIZE=$((3000*BLKSIZE)) + fi + if [ $DISKSIZE -gt $((60000*SECSIZE)) ]; then + DISKSIZE=$((60000*SECSIZE)) + fi;; + x"vfat16" | xmsdos16) + DISKSIZE=$((65000*BLKSIZE));; + x"vfat16a" | xmsdos16a) + DISKSIZE=$((60000*SECSIZE)) + ;; + *) + DISKSIZE=10737418240;; + esac + + if [ $DISKSIZE -ge $(((5800/NDEVICES)*1048576)) ]; then + DISKSIZE=$(((5800/NDEVICES)*1048576)) + fi + + case x"$fs" in + xvfat* | xmsdos* | xexfat* | xhfs | xhfsplus | xhfsplus_wrap | xaffs \ + | xaffs_intl | xjfs_caseins | xsfs_caseins \ + | xzfs_caseins | xiso9660) + CASESENS=n;; + *) + CASESENS=y;; + esac + + BIGBLOCKCNT=$((5000 * 1048576)) + case x"$fs" in + # FS LIMITATION: small filesystems + x"vfat12" | xmsdos12) + if [ $BLKSIZE -le 4096 ]; then + BIGBLOCKCNT=0 + elif [ $BLKSIZE = 8192 ]; then + BIGBLOCKCNT=1500000 + else + BIGBLOCKCNT=$((2000*BLKSIZE)) + fi + ;; + x"vfat12a" | xmsdos12a) + if [ $BLKSIZE -le 4096 ] || [ $((128*SECSIZE)) = $BLKSIZE ]; then + BIGBLOCKCNT=0 + else + BIGBLOCKCNT=700000 + fi;; + x"vfat16a" | xmsdos16a) + if [ $((128*SECSIZE)) = $BLKSIZE ]; then + BIGBLOCKCNT=0 + else + BIGBLOCKCNT=$((2500*SECSIZE)) + fi + ;; + x"vfat16" | xmsdos16) + BIGBLOCKCNT=$((25000 * BLKSIZE)) + if [ $BIGBLOCKCNT -gt 4294967295 ]; then + BIGBLOCKCNT=4294967295 + fi + ;; + x"minix") + BIGBLOCKCNT=30000000;; + + xexfat) + # Big blocks waste really a lot of space. + # Not much is left. + if [ $BLKSIZE = 2097152 ]; then + BIGBLOCKCNT=4500000000 + fi + if [ $BLKSIZE = 4194304 ]; then + BIGBLOCKCNT=3500000000 + fi + ;; + # FS LIMITATION: romfs image is limited to 4G. + x"romfs") + BIGBLOCKCNT=$((4000 * 1048576));; + # FS LIMITATION: These FS have uint32 as file size field + x"vfat"* | xmsdos* | x"cpio_crc" | x"cpio_newc" | x"cpio_bin" | x"cpio_hpbin" | xsfs*) + BIGBLOCKCNT=4294967295;; + # FS LIMITATION: These FS have int32 as file size field + # FIXME: not so sure about AFFS + # OS LIMITATION: minix2/minix3 could be formatted in a way to permit more. + x"minix3" | x"minix2" | x"hfs"| x"affs" | xaffs_intl | xreiserfs_old | xext2_old) + BIGBLOCKCNT=$((16#7fffffff));; + + # FS LIMITATION: redundant storage + # We have only limited space. Mirroring multiplies it very effectively. + xmdraid* | xlvm* | xzfs_mirror | xbtrfs_raid1) + BIGBLOCKCNT=$((100 * 1048576));; + # We already test the FS for big files separately. Save some time here. + x"zfs_raid"* | x"zfs_stripe"* | x"zfs_mirror"* | x"btrfs_raid"*) + BIGBLOCKCNT=$((100 * 1048576));; + + # OS LIMITATION: bfs_fuse bugs beyond that + xbfs) + BIGBLOCKCNT=$((800 * 1048576));; + esac + + NOSYMLINK=n + case x"$fs" in + # FS LIMITATION: no symlinks on FAT, exFAT, HFS, plain ISO9660 and Joliet + # OS LIMITATION: ntfs-3g creates interix symlinks which aren't real symlinks + x"vfat"* | xmsdos* | x"hfs" | x"exfat" | x"ntfs"* \ + | xiso9660 | xjoliet| xiso9660_1999 | xjoliet_1999) + NOSYMLINK=y;; + esac + NOHARDLINK=n + case x"$fs" in + # FS LIMITATION: no hardlinks on BFS, exfat, fat, hfs and SFS + xbfs | xexfat | x"vfat"* | xmsdos* | xhfs | xsfs | xsfs_caseins) + NOHARDLINK=y;; + # GRUB LIMITATION: no hardlink support on newc and hfs+ + xcpio_crc | xcpio_newc | xhfsplus*) + NOHARDLINK=y;; + esac + + # FS LIMITATION: some filesystems limit file name size + case x"$fs" in + x"cpio_ustar") + LONGNAME="`echo $LONGNAME |head -c 99`";; + x"hfs") + LONGNAME="`echo $LONGNAME |head -c 31`";; + x"minix" | x"minix2" | x"affs" | xaffs_intl | xiso9660) + LONGNAME="`echo $LONGNAME |head -c 30`";; + x"sfs"*) + LONGNAME="`echo $LONGNAME |head -c 105`";; + x"minix3") + LONGNAME="`echo $LONGNAME |head -c 60`";; + x"udf") + LONGNAME="`echo $LONGNAME |head -c 192`";; + # GRUB LIMITATION: GRUB prefers Joliet over ISO9660:1999 + xjoliet | xjoliet_1999) + LONGNAME="`echo $LONGNAME |head -c 103`";; + xiso9660_1999) + LONGNAME="`echo $LONGNAME |head -c 207`";; + # FS LIMITATION: 8.3 + xmsdos*) + LONGNAME="qwertzui.opa";; + esac + NOFILETIME=n + NOFSTIME=n + case x"$fs" in + # FIXME: Not sure about BtrFS, NTFS, JFS, AFS, UDF and SFS. Check it. + # FS LIMITATION: as far as I know those FS don't store their last modification date. + x"jfs_caseins" | x"jfs" | x"xfs" | x"xfs_crc" | x"btrfs"* | x"reiserfs_old" | x"reiserfs" \ + | x"bfs" | x"afs" | x"f2fs" \ + | x"tarfs" | x"cpio_"* | x"minix" | x"minix2" \ + | x"minix3" | x"ntfs"* | x"udf" | x"sfs"*) + NOFSTIME=y;; + # OS LIMITATION: Linux doesn't update fstime. + # OS LIMITATION: Linux apparently uses localtime instead of UTC + xhfs) + NOFILETIME=y; NOFSTIME=y;; + # GRUB LIMITATION: FAT and exFAT use localtime. Unusable for GRUB + x"vfat"* | x"msdos"* | x"exfat") + NOFILETIME=y; NOFSTIME=y;; + # FS LIMITATION: romfs has no timestamps. + x"romfs") + NOFILETIME=y; NOFSTIME=y;; + esac + + NOFSLABEL=n + case x"$fs" in + # FS LIMITATION: these filesystems have no label. + x"cpio_"* | x"tarfs" | x"squash4_"* | x"minix" | x"minix2" \ + | x"minix3" | xreiserfs_old) + NOFSLABEL=y;; + esac + + PDIRCOMPNUM=210 + PDIR2COMPNUM=210 + + case x$fs in + # OS LIMITATION: bfs_fuse bugs beyond that + xbfs) + PDIRCOMPNUM=10 + PDIR2COMPNUM=10;; + # OS LIMITATION: Linux supports only inline symlinks + xudf) + if [ $BLKSIZE = 1024 ]; then + PDIR2COMPNUM=113 + fi ;; + # FS LIMITATION: at most 255 on path length + # FS LIMITATION: at most 100 on symlink length + xcpio_ustar) + PDIRCOMPNUM=84 + PDIR2COMPNUM=30;; + # OS LIMITATION: Linux supports only symlink at most one block long on reiserfs + xreiserfs | xreiserfs_old) + if [ $BLKSIZE = 512 ]; then + PDIR2COMPNUM=114 + fi ;; + # FS LIMITATION: SFS assumes that symlink + # with header fit in one block. + # FIXME: not sure about it. + xsfs | xsfs_caseins) + if [ $BLKSIZE = 512 ]; then + PDIR2COMPNUM=147 + fi ;; + # FS LIMITATION: AFFS assumes that symlink + # with rather larger header fit in one block. + # FIXME: not sure about it. + xaffs | xaffs_intl) + if [ $BLKSIZE = 512 ]; then + PDIR2COMPNUM=97 + fi ;; + esac + + + PDIR="" + # OS LIMITATION: Limited by PATH_MAX (usually 1024) + for i in $(range 0 $((PDIRCOMPNUM-1)) 1); do + PDIR="$PDIR/$i"; + if test $((i%3)) = 0; then + PDIR="$PDIR/" + fi + done + + PDIR2="" + # OS LIMITATION: Limited by PATH_MAX (usually 1024) + for i in $(range 0 $((PDIR2COMPNUM-1)) 1); do + PDIR2="${PDIR2}/$i"; + if test $((i%3)) = 0; then + PDIR2="${PDIR2}/" + fi + done + + PFIL="p.img" + + unset LODEVICES + GENERATED=n + LODEVICES= + MOUNTDEVICE= + + case x"$fs" in + x"tarfs" | x"cpio_"*| x"ziso9660" | x"romfs" | x"squash4_"*\ + | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet \ + | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 \ + | xrockridge_joliet_1999) + MNTPOINTRW="$MASTER" + MNTPOINTRO="$MASTER" + GENERATED=y + mkdir -p "$MASTER";; + # No mkfs for GNU/Linux. Just unpack preformatted empty image + *) + mkdir -p "$MNTPOINTRW" + mkdir -p "$MNTPOINTRO" + for i in $(range 0 $((NDEVICES-1)) 1); do + dd if=/dev/zero of="$FSIMAGEP${i}.img" count=1 bs=1 seek=$((DISKSIZE-1)) &> /dev/null + LODEVICE=$(losetup --find --show "$FSIMAGEP${i}.img") + LODEVICES="$LODEVICES $LODEVICE" + if test "$i" = 0; then + MOUNTDEVICE="$LODEVICE" + fi + done ;; + esac + + case x"$fs" in + x"afs") + ;; + x"btrfs") + "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${MOUNTDEVICE}" ;; + x"btrfs_zlib" | x"btrfs_lzo" | x"btrfs_zstd") + "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${MOUNTDEVICE}" + MOUNTOPTS="compress=${fs/btrfs_/}," + MOUNTFS="btrfs" + ;; + x"btrfs_raid0") + "mkfs.btrfs" -s $SECSIZE -d raid0 -m raid0 -L "$FSLABEL" $LODEVICES + MOUNTFS="btrfs" + ;; + x"btrfs_raid1") + "mkfs.btrfs" -s $SECSIZE -d raid1 -m raid1 -L "$FSLABEL" $LODEVICES + MOUNTFS="btrfs" + ;; + x"btrfs_raid10") + "mkfs.btrfs" -s $SECSIZE -d raid10 -m raid10 -L "$FSLABEL" $LODEVICES + MOUNTFS="btrfs" + ;; + x"btrfs_single") + "mkfs.btrfs" -s $SECSIZE -d single -L "$FSLABEL" $LODEVICES + MOUNTFS="btrfs" + ;; + x"exfat") + "mkfs.$fs" -s $((BLKSIZE/512)) -n "$FSLABEL" "${MOUNTDEVICE}" + MOUNTOPTS="iocharset=utf8," + MOUNTFS="exfat-fuse";; + x"minix") + "mkfs.minix" "${MOUNTDEVICE}" + ;; + # mkfs.hfs and mkfs.hfsplus don't fill UUID. + x"hfsplus") + "mkfs.hfsplus" -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}" + dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8 ;; + x"hfsplus_wrap") + "mkfs.hfsplus" -w -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}" + dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8 + MOUNTFS="hfsplus";; + x"hfsplus_casesens") + "mkfs.hfsplus" -s -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}" + dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8 + MOUNTFS="hfsplus";; + x"hfs") + "mkfs.hfs" -b $BLKSIZE -v "`echo $FSLABEL |recode utf8..macroman`" -h "${MOUNTDEVICE}" + dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#474)) conv=notrunc count=8 + MOUNTOPTS="iocharset=utf8,codepage=macroman," + ;; + x"vfat"*|xmsdos*) + BITS="${fs/vfat/}" + BITS="${BITS/msdos/}" + if [ "x${BITS:2:1}" = xa ]; then + A=-A + else + A= + fi + "mkfs.vfat" -a $A -S $SECSIZE -s $((BLKSIZE/SECSIZE)) -F "${BITS:0:2}" -n "$FSLABEL" "${MOUNTDEVICE}" + MOUNTOPTS="iocharset=utf8,codepage=437," + MOUNTFS="$(echo "$fs"|sed 's,[0-9]*a\?$,,')";; + x"minix2") + "mkfs.minix" -v "${MOUNTDEVICE}" + MOUNTFS="minix";; + x"minix3") + "mkfs.minix" -B $BLKSIZE -3 "${MOUNTDEVICE}" + MOUNTFS="minix";; + x"ntfs"*) + "mkfs.ntfs" -s "$SECSIZE" -c "$BLKSIZE" -L "$FSLABEL" -Q -q "${MOUNTDEVICE}" + MOUNTOPTS="iocharset=utf8,compression," + MOUNTFS="ntfs-3g";; + x"udf") + "mkudffs" --utf8 -b $BLKSIZE --lvid="$FSLABEL" "${MOUNTDEVICE}" + MOUNTOPTS="iocharset=utf8,bs=$BLKSIZE,";; + x"ufs2") + "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 2 "${MOUNTDEVICE}" + MOUNTOPTS="ufstype=ufs2," + MOUNTFS="ufs";; + x"ufs1") + "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${MOUNTDEVICE}" + MOUNTOPTS="ufstype=44bsd," + MOUNTFS="ufs";; + x"ufs1_sun") + "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${MOUNTDEVICE}" + MOUNTOPTS="ufstype=sun," + MOUNTFS="ufs";; + x"zfs") + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}" + sleep 1 + "zfs" create "$FSLABEL"/"grub fs" + sleep 1;; + x"zfs_caseins") + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}" + sleep 1 + "zfs" create -o casesensitivity=insensitive "$FSLABEL"/"grub fs" + sleep 1;; + x"zfs_lzjb" | xzfs_gzip | xzfs_zle) + "zpool" create -O compression=${fs/zfs_/} -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}" + sleep 1 + "zfs" create -o compression=${fs/zfs_/} "$FSLABEL"/"grub fs" + sleep 1;; + x"zfs_raidz") + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz1 $LODEVICES + sleep 1 + "zfs" create "$FSLABEL"/"grub fs" + sleep 1;; + x"zfs_raidz2") + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz2 $LODEVICES + sleep 1 + "zfs" create "$FSLABEL"/"grub fs" + sleep 1;; + x"zfs_raidz3") + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz3 $LODEVICES + sleep 1 + "zfs" create "$FSLABEL"/"grub fs" + sleep 1;; + x"zfs_mirror") + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" mirror $LODEVICES + sleep 1 + "zfs" create "$FSLABEL"/"grub fs" + sleep 1;; + x"zfs_stripe") + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" $LODEVICES + sleep 1 + "zfs" create "$FSLABEL"/"grub fs" + sleep 1;; + x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"*) + INSTDEVICE=/dev/null;; + x"reiserfs") + "mkfs.reiserfs" --format=3.6 -b $BLKSIZE -l "$FSLABEL" -q "${MOUNTDEVICE}" ;; + x"reiserfs_old") + "mkfs.reiserfs" --format=3.5 -b $BLKSIZE -l "$FSLABEL" -q "${MOUNTDEVICE}" + MOUNTFS=reiserfs;; + x"jfs") + "mkfs.jfs" -L "$FSLABEL" -q "${MOUNTDEVICE}" + MOUNTOPTS="iocharset=utf8,";; + x"jfs_caseins") + "mkfs.jfs" -O -L "$FSLABEL" -q "${MOUNTDEVICE}" + MOUNTFS=jfs + MOUNTOPTS="iocharset=utf8,";; + x"mdraid"*) + mdadm -C --chunk=$((BLKSIZE/1024)) --force -e "${fs:6:1}.${fs:7:1}" "/dev/md/${fs}_${NDEVICES}" --level="${fs:13}" --raid-devices="$NDEVICES" $LODEVICES + MOUNTDEVICE="/dev/md/${fs}_${NDEVICES}" + MOUNTFS=ext2 + "mkfs.ext2" -L "$FSLABEL" -q "${MOUNTDEVICE}" ;; + x"lvm"*) + for lodev in $LODEVICES; do + pvcreate "$lodev" + done + vgcreate -s $((BLKSIZE/1024))K grub_test $LODEVICES + if [ x$fs = xlvm ] ; then + lvcreate -l "$((NDEVICES*7*LVMBLKMUL))" -n testvol grub_test + elif [ x$fs = xlvm_stripe ] ; then + lvcreate -l "$((NDEVICES*7*LVMBLKMUL))" -i "$NDEVICES" -n testvol grub_test + elif [ x$fs = xlvm_mirror1 ] || [ x$fs = xlvm_raid1 ] ; then + lvcreate -m 1 -l "$((NDEVICES*2*LVMBLKMUL))" --type "${fs/lvm_/}" -n testvol grub_test + elif [ x$fs = xlvm_mirrorall ] ; then + lvcreate -m "$((NDEVICES-1))" -l "$((6*LVMBLKMUL))" --type mirror -n testvol grub_test + elif [ x$fs = xlvm_raid1all ] ; then + # Until version 2.02.103 LVM counts metadata segments + # twice when checking available space. Reduce segment + # count to work around it. + lvcreate -m "$((NDEVICES-1))" -l "$((6*LVMBLKMUL - 1))" --type raid1 -n testvol grub_test + elif [ x$fs = xlvm_raid4 ] || [ x$fs = xlvm_raid5 ]; then + lvcreate -l "$(((NDEVICES-1) * 5*LVMBLKMUL))" -i "$((NDEVICES-1))" --type "${fs/lvm_/}" -n testvol grub_test + elif [ x$fs = xlvm_raid6 ]; then + lvcreate -l "$(((NDEVICES-2) * 5*LVMBLKMUL))" -i "$((NDEVICES-2))" --type "${fs/lvm_/}" -n testvol grub_test + fi + MOUNTDEVICE="/dev/mapper/grub_test-testvol" + MOUNTFS=ext2 + "mkfs.ext2" -L "$FSLABEL" -q "${MOUNTDEVICE}" ;; + xf2fs) + "mkfs.f2fs" -l "$FSLABEL" -q "${MOUNTDEVICE}" ;; + xnilfs2) + "mkfs.nilfs2" -L "$FSLABEL" -b $BLKSIZE -q "${MOUNTDEVICE}" ;; + xext2_old) + MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext2" -r 0 -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" + MOUNTFS=ext2 + ;; + xext4_metabg) + MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext4" -O meta_bg,^resize_inode -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" + MOUNTFS=ext4 + ;; + xext4_encrypt) + MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext4" -O encrypt -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" + MOUNTFS=ext4 + ;; + xext*) + MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.$fs" -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;; + xxfs) + "mkfs.xfs" -m crc=0 -b size=$BLKSIZE -s size=$SECSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;; + xxfs_crc) + MOUNTFS="xfs" + "mkfs.xfs" -m crc=1 -b size=$BLKSIZE -s size=$SECSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;; + *) + echo "Add appropriate mkfs command here" + exit 1 + ;; + esac + BASEFILE="1.img" + NASTYFILE=".?*\\!\"#%@\$%&'()+ ,-.:;<=>^{_}[]\`|~." + case x"$fs" in + + # FS LIMITATION: AFFS and SFS don't accept : + xsfs*) + NASTYFILE=".?*\\!\"#%@\$%&'()+ ,-.;<=>^{_}[]\`|~.";; + # FS LIMITATION: AFFS is limited in file name length (30) + x"affs" | xaffs_intl) + NASTYFILE=".?*\\!\"#@\$'()+ ,-;<=>^{_}[]\`|~.";; + # FS LIMITATION: hfs, minix and minix2 are limited in file name length (30 or 31) + x"hfs" | x"minix" | x"minix2") + NASTYFILE=".?*\\!\"#@\$&'()+ ,-:;<=>{}[]\`|~.";; + # FS LIMITATION: FAT doesn't accept ?, *, \, ", :, <, >, | + # FS LIMITATION: FAT discards dots at the end. + x"vfat"* | x"exfat") + NASTYFILE=".!#%@\$%&'()+ ,-.;=^{_}[]\`~";; + # FS LIMITATION: 8.3 limitations apply + x"msdos"*) + NASTYFILE="!#%@\$%&.;=^";; + # FS LIMITATION: No ' ', '*', '/', ':', ';', '?', '\\' in joliet + # GRUB LIMITATION: GRUB prefers Joliet over ISO9660:1999 + xjoliet | xjoliet_1999) + NASTYFILE=".!\"#%@\$%&'()+,-.<=>^{_}[]\`|~.";; + # FS LIMITATION: iso9660 accepts only [0-9A-Z_]*, 32 characters at most + xiso9660) + NASTYFILE="0123456789_acefghijknopqrvwxyz";; + esac + + case x"$fs" in + # FS LIMITATION: HFS, AFFS and SFS use legacy codepage (mac-roman or latin1) + x"sfs"* | x"hfs" | x"affs" | xaffs_intl) + IFILE="รฉร รจรผรถรครซรฑ" + ISYM="รซรฑรฉรผรถรคร รจ" + ;; + # FS LIMITATION: filename length limitation. + x"minix" | x"minix2") + IFILE="รฉร รจรผรถ๐รฑะบะธฮฮปฮบฮฌ" + ISYM="ฮฮปฮบฮฌะบะธรฉร ๐รถรครซรฑ" + ;; + xminix3) + IFILE="รฉร รจรผรถรครซรฑะบะธัะธัะฐ๐ฏฆ๐ฏฆฮฮปฮปฮนฮบฮฌ๐๐๐" + ISYM="ฮฮปฮปฮนฮบฮฌ๐๐๐๐ฏฆ๐ฏฆะบะธัะธัะฐรฉร รจรผรถรครซรฑ";; + # GRUB LIMITATION: HFS+ uses NFD. GRUB doesn't handle NF conversion. + # OS LIMITATION: Linux doesn't handle out-of-BMP characters for UTF-16 + x"hfsplus" | x"hfsplus_casesens" | x"hfsplus_wrap") + IFILE="eฬaฬeฬuฬoฬaฬeฬnฬะบะธัะธะปะธัะฐไไไฮฮปฮปฮทฮฝฮนฮบฮฑฬไไไ" + ISYM="ฮฮปฮปฮทฮฝฮนฮบฮฑฬะบะธัะธะปะธัะฐไไไeฬaฬeฬuฬoฬaฬeฬnฬไไไ" + ;; + # GRUB LIMITATION: On case-insensitive ZFS isn't supported with non-uppercase characters + xzfs_caseins) + IFILE="รรรรรรรระะะ ะะะะฆะ๐ฏฆ๐ฏฆ๐ฏฆฮฮฮฮฮฮฮฮ๐๐๐" + ISYM="ฮฮฮฮฮฮฮฮะะะ ะะะะฆะ๐๐๐รรรรรรรร๐ฏฆ๐ฏฆ๐ฏฆ";; + # FS LIMITATION: 8.3 CP437 + x"msdos"*) + IFILE="รฉร รจรผรถรครซรฑ.รฉร รจ" + ;; + # FS LIMITATION: iso9660 is ASCII-only. + x"iso9660") + IFILE="abcdefghijkmmnop" + ;; + # OS LIMITATION: Linux doesn't handle out-of-BMP characters for UTF-16 + # OS LIMITATION: xorriso doesn't handle out-of-BMP characters + xjoliet | xjoliet_1999 | x"vfat"* | x"jfs"* | x"udf"*) + IFILE="รฉร รจรผรถรครซรฑะบะธัะธะปะธัะฐไไไฮฮปฮปฮทฮฝฮนฮบฮฌไไไ" + ISYM="ฮฮปฮปฮทฮฝฮนฮบฮฌะบะธัะธะปะธัะฐไไไรฉร รจรผรถรครซรฑไไไ";; + *) + IFILE="รฉร รจรผรถรครซรฑะบะธัะธะปะธัะฐ๐ฏฆ๐ฏฆ๐ฏฆฮฮปฮปฮทฮฝฮนฮบฮฌ๐๐๐" + ISYM="ฮฮปฮปฮทฮฝฮนฮบฮฌะบะธัะธะปะธัะฐ๐๐๐รฉร รจรผรถรครซรฑ๐ฏฆ๐ฏฆ๐ฏฆ";; + esac + BIGFILE="big.img" + BASESYM="sym" + BASEHARD="hard" + SSYM="///sdir////ssym" + USYM="///sdir////usym" + LONGSYM="longsym" + PSYM="psym" + OSDIR="" + GRUBDEVICE=loop0 + case x"$fs" in + xmdraid*) + GRUBDEVICE="mduuid/`mdadm --detail --export $MOUNTDEVICE | grep MD_UUID=|sed 's,MD_UUID=,,g;s,:,,g'`";; + xlvm*) + GRUBDEVICE="lvm/grub_test-testvol";; + esac + GRUBDIR="($GRUBDEVICE)" + case x"$fs" in + x"zfs"*) + OSDIR="grub fs/" + GRUBDIR="($GRUBDEVICE)/grub fs@";; + x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"* | xafs) + ;; + *) + if ! mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRW" -o ${MOUNTOPTS}${SELINUXOPTS}rw ; then + echo "MOUNT FAILED." + for lodev in $LODEVICES; do + while ! losetup -d "$lodev"; do + sleep 1 + done + done + for i in $(range 0 $((NDEVICES-1)) 1); do + rm "$FSIMAGEP${i}.img" + done + exit 1; + fi + ;; + esac + case x"$fs" in + # FS LIMITATION: redundant storage + xmdraid* | xlvm*) + BLOCKCNT=1048576;; + x"zfs_raid"* | x"zfs_stripe"* | x"zfs_mirror"* | x"btrfs_raid"*) + BLOCKCNT=1048576;; + + # FS LIMITATION: small filesystems + x"vfat16a" | x"msdos16a") + BLOCKCNT=65536;; + x"vfat12a" | xmsdos12a) + BLOCKCNT=32768;; + xminix) + BLOCKCNT=2621440;; + xvfat16 | xmsdos16) + if [ $BLKSIZE = 512 ] || [ $BLKSIZE = 1024 ]; then + BLOCKCNT=1048576 + else + BLOCKCNT=5242880 + fi + ;; + xvfat12 | xmsdos12) + BLOCKCNT=$((100*BLKSIZE)) + if [ $BLOCKCNT -gt 5242880 ]; then + BLOCKCNT=5242880; + fi + ;; + *) + BLOCKCNT=5242880;; + esac + # Make sure file is not exact multiple of block size. This helps to force + # tail packing in case of squash4. + BLOCKCNT="$((BLOCKCNT-1))" + case x"$fs" in + x"ntfscomp") + setfattr -h -v 0x00000800 -n system.ntfs_attrib_be "$MNTPOINTRW/$OSDIR";; + esac + # OS LIMITATION: No AFS support under GNU/Linux + mkdir "$MNTPOINTRW/$OSDIR/sdir" + mkdir -p "$MNTPOINTRW/$OSDIR/$PDIR" + "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/sdir/2.img" + "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$BASEFILE" + "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$NASTYFILE" + "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$IFILE" + "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$LONGNAME" + "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$PDIR/$PFIL" + if [ $PDIR != $PDIR2 ]; then + "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/${PDIR2}/$PFIL" + fi + "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/CaSe" + if [ x$CASESENS = xy ]; then + "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/cAsE" + fi + if (test x$fs = xvfat12a || test x$fs = xmsdos12a) && test x$BLKSIZE = x131072; then + # With this config there isn't enough space for full copy. + # Copy as much as we can + cp "${CFILESRC}" "$MNTPOINTRW/$OSDIR/${CFILE}" &> /dev/null; + else + + cp "${CFILESRC}" "$MNTPOINTRW/$OSDIR/${CFILE}"; + + fi + + if [ x$NOSYMLINK != xy ]; then + ln -s "$BASEFILE" "$MNTPOINTRW/$OSDIR/$BASESYM" + ln -s "2.img" "$MNTPOINTRW/$OSDIR/$SSYM" + ln -s "../1.img" "$MNTPOINTRW/$OSDIR/$USYM" + ln -s "$LONGNAME" "$MNTPOINTRW/$OSDIR/$LONGSYM" + ln -s "${PDIR2}/$PFIL" "$MNTPOINTRW/$OSDIR/$PSYM" + ln -s "$IFILE" "$MNTPOINTRW/$OSDIR/$ISYM" + fi + if [ x$NOHARDLINK != xy ]; then + ln "$MNTPOINTRW/$OSDIR/$BASEFILE" "$MNTPOINTRW/$OSDIR/$BASEHARD" + fi + + case x"$fs" in + x"afs") + ;; + x"zfs"*) + while ! zpool export "$FSLABEL" ; do + sleep 1; + done + sleep 2 + ;; + x"tarfs") + (cd "$MASTER"; tar cf "${FSIMAGEP}0.img" .) ;; + x"cpio_"*) + (cd "$MASTER"; find . | cpio -o -H "$(echo ${fs} | sed 's@^cpio_@@')" > "${FSIMAGEP}0.img" ) ;; + x"ziso9660") + FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); + xorriso -compliance rec_mtime -set_filter_r --zisofs -- -zisofs default -as mkisofs -iso-level 3 -graft-points -R -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" -- -set_filter_r --zisofs -- -zisofs default -add /="$MASTER" ;; + x"iso9660") + FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); + xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + x"joliet") + FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); + xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + x"rockridge") + FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); + xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + x"rockridge_joliet") + FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); + xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + x"iso9660_1999") + FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); + xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + x"joliet_1999") + FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); + xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + x"rockridge_1999") + FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); + xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + x"rockridge_joliet_1999") + FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); + xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + x"romfs") + genromfs -V "$FSLABEL" -f "${FSIMAGEP}0.img" -d "$MASTER" ;; + xsquash4_*) + echo mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE + mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE ;; + x"bfs") + sleep 1 + fusermount -u "$MNTPOINTRW" + ;; + xlvm*) + sleep 1 + for try in $(range 0 20 1); do + if umount "$MNTPOINTRW" ; then + break; + fi + sleep 1; + done + UMOUNT_TIME=$(date -u "+%Y-%m-%d %H:%M:%S") + sleep 1 + vgchange -a n grub_test + ;; + xmdraid*) + sleep 1 + for try in $(range 0 20 1); do + if umount "$MNTPOINTRW" ; then + break; + fi + sleep 1; + done + UMOUNT_TIME=$(date -u "+%Y-%m-%d %H:%M:%S") + sleep 1 + mdadm --stop /dev/md/"${fs}_$NDEVICES" + ;; + *) + sleep 1 + for try in $(range 0 20 1); do + if umount "$MNTPOINTRW" ; then + break; + fi + sleep 1; + done + ;; + esac + sleep 1 + + case x"$fs" in + x"zfs"*) + "zpool" import -d /dev -R "$MNTPOINTRO" "$FSLABEL" + ;; + x"tarfs") + ;; + x"cpio_"*) + ;; + x"ziso9660") + ;; + xiso9660 | xrockridge | xjoliet | xrockridge_joliet) + ;; + xiso9660_1999 | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) + ;; + x"romfs") + ;; + xsquash4_*) + ;; + xlvm*) + vgchange -a y grub_test + sleep 1 + mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;; + xmdraid*) + mdadm --assemble /dev/md/"${fs}_$NDEVICES" $LODEVICES + sleep 1 + mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;; + *) + mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;; + esac + + run_grubfstest ls -- -la + case x"$fs" in + x"zfs"*) + LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/grub fs@/");; + *) + LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/");; + esac + if echo "$LSROUT" | grep -F " $BASEFILE" | grep "$BLOCKCNT" > /dev/null; then + : + else + echo LIST FAIL + echo "$LSROUT" + TZ=UTC ls -l "$MNTPOINTRO" + exit 1 + fi + + if echo "$LSROUT" | grep -F " $NASTYFILE" | grep "$BLOCKCNT"> /dev/null; then + : + else + echo NLIST FAIL + echo "$LSROUT" + TZ=UTC ls -lA "$MNTPOINTRO" + exit 1 + fi + + if echo "$LSROUT" | grep -F " $IFILE" | grep "$BLOCKCNT"> /dev/null; then + : + else + echo ILIST FAIL + echo "$LSROUT" + TZ=UTC ls -l "$MNTPOINTRO" + exit 1 + fi + + if echo "$LSROUT" | grep -F " $LONGNAME" | grep "$BLOCKCNT"> /dev/null; then + : + else + echo LONG LIST FAIL + echo "$LSROUT" + TZ=UTC ls -l "$MNTPOINTRO" + exit 1 + fi + + if [ x$NOFILETIME != xy ]; then + filtime=$(TZ=UTC ls --time-style=+%Y%m%d%H%M%S -l -d "$MNTPOINTRO/$OSDIR/$BASEFILE"|awk '{print $6; }') + if echo "$LSROUT" | grep -F "$filtime $BASEFILE" > /dev/null; then + : + else + echo TIME FAIL + echo "$LSROUT" + TZ=UTC ls -l "$MNTPOINTRO" + exit 1 + fi + + filtime=$(TZ=UTC ls --time-style=+%Y%m%d%H%M%S -l -d "$MNTPOINTRO/$OSDIR/$LONGNAME"|awk '{print $6; }') + if echo "$LSROUT" | grep -F "$filtime $LONGNAME" > /dev/null; then + : + else + echo LONG TIME FAIL + echo "$LSROUT" + TZ=UTC ls -l "$MNTPOINTRO" + exit 1 + fi + fi + + case x"$fs" in + x"zfs"*) + LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/grub fs@/.");; + *) + LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/.");; + esac + if echo "$LSROUT" | grep -F " $BASEFILE" | grep "$BLOCKCNT" > /dev/null; then + : + else + echo DOT IN ROOTDIR FAIL + echo "$LSROUT" + TZ=UTC ls -l "$MNTPOINTRO" + exit 1 + fi + + case x"$fs" in + x"zfs"*) + ;; + *) + LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/.."); + if echo "$LSROUT" | grep -F " $BASEFILE" | grep "$BLOCKCNT" > /dev/null; then + : + else + echo DOTDOT IN ROOTDIR FAIL + echo "$LSROUT" + TZ=UTC ls -l "$MNTPOINTRO" + exit 1 + fi + ;; + esac + + case x"$fs" in + x"zfs"*) + LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/////sdir");; + *) + LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/////sdir");; + esac + if echo "$LSROUT" | grep -F " 2.img" | grep $BLOCKCNT > /dev/null; then + : + else + echo SLIST FAIL + echo "$LSROUT" + TZ=UTC ls -l "$MNTPOINTRO/sdir" + exit 1 + fi + + case x"$fs" in + x"zfs"*) + LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/$PDIR");; + *) + LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/$PDIR");; + esac + if echo "$LSROUT" | grep -F " p.img" | grep $BLOCKCNT > /dev/null; then + : + else + echo PLIST FAIL + echo "$LSROUT" + TZ=UTC ls -l "$MNTPOINTRO/$PDIR" + exit 1 + fi + + case x"$fs" in + x"zfs"*) + LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/sdir/.");; + *) + LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/sdir/.");; + esac + if echo "$LSROUT" | grep -F " 2.img" | grep $BLOCKCNT > /dev/null; then + : + else + echo DOT IN SUBDIR FAIL + echo "$LSROUT" + TZ=UTC ls -l "$MNTPOINTRO/$OSDIR/sdir" + exit 1 + fi + + case x"$fs" in + x"zfs"*) + LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/sdir/../sdir");; + *) + LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/sdir/../sdir");; + esac + if echo "$LSROUT" | grep -F " 2.img" | grep $BLOCKCNT > /dev/null; then + : + else + echo DOTDOT IN SUBDIR FAIL + echo "$LSROUT" + TZ=UTC ls -l "$MNTPOINTRO/$OSDIR/ssdir" + exit 1 + fi + + LSOUT=`run_grubfstest ls -- -l "($GRUBDEVICE)"` + if [ x"$NOFSLABEL" = xy ]; then + : + elif echo "$LSOUT" | grep -F "Label \`$FSLABEL'" > /dev/null; then + : + else + echo LABEL FAIL + echo "$LSOUT" + blkid "${MOUNTDEVICE}" + exit 1 + fi + + # Inconsistencies between GRUB and blkid. + case x"$fs" in + x"iso9660" | x"ziso9660" | xrockridge | xjoliet | xrockridge_joliet | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;; + x"zfs"*) + for lodev in $LODEVICES; do + FSUUID=$(printf "%016x\n" $(blkid -o export "$lodev" |grep -F UUID=|sed s,UUID=,,g)) + if [ "$FSUUID" != 0000000000000000 ]; then + break; + fi + done;; + *) + FSUUID=`blkid -o export "${MOUNTDEVICE}" |grep -F UUID=|sed s,UUID=,,g` + ;; + esac + case x"$fs" in + x"hfs"*) + GRUBUUID="`run_grubfstest xnu_uuid "$GRUBDEVICE"`" + if [ x"$GRUBUUID" = x"$FSUUID" ]; then + : + else + echo UUID FAIL + echo "$LSOUT" + echo "$GRUBUUID" + for lodev in $LODEVICES; do + blkid "$lodev" + done + exit 1 + fi + ;; + # FS LIMITATION: romfs, cpio, tar, squash4, minix, AFS, old reiserfs and minix2 + # have no UUID. + # GRUB LIMITATION: use creation date for squash4, AFFS and SFS? + # GRUB LIMITATION: use tags serials on UDF? + # GRUB LIMITATION: use root ctime on cpio, tar, minix*, UDF, reiserfs_old? + # GRUB LIMITATION: Support Atari UUIDs + x"romfs" | x"cpio_"* | x"tarfs" | x"squash4_"* | x"minix" \ + | x"minix2" | x"minix3" | x"affs" | xaffs_intl \ + | x"udf" | xvfat12a | xvfat16a | xmsdos12a | xmsdos16a | xafs | xsfs* \ + | xreiserfs_old) + ;; + *) + if [ x"$FSUUID" = x ]; then + echo "Warning: blkid couldn't retrieve UUID" + elif echo "$LSOUT" | grep -F 'UUID '"$FSUUID"' ' > /dev/null; then + : + else + echo UUID FAIL + echo "$FSUUID" + echo "$LSOUT" + blkid "${MOUNTDEVICE}" + exit 1 + fi + ;; + esac + + if [ x$NOFSTIME != xy ]; then + case x$fs in + xiso9660 | xziso9660 | xrockridge | xjoliet | xrockridge_joliet | xiso9660_1999 | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) + FSTIME="$(date -d "$(echo ${FSUUID} | awk -F - '{ print $1"-"$2"-"$3" "$4":"$5":"$6 ;}')" '+%Y-%m-%d %H:%M:%S')";; + xlvm*|xmdraid*) + # With some abstractions like mdraid flushing to disk + # may be delayed for a long time. + FSTIME="$UMOUNT_TIME";; + *) + FSTIME="$(TZ=UTC ls --time-style="+%Y-%m-%d_%H:%M:%S" -l -d "${FSIMAGEP}0.img"|awk '{print $6; }'|sed 's,_, ,g')";; + esac + # With some abstractions like mdraid computing of UMOUNT_TIME + # is not precise. Account for small difference here. + FSTIMEM1="$(date -d "$FSTIME UTC -1 second" -u "+%Y-%m-%d %H:%M:%S")" + FSTIMEM2="$(date -d "$FSTIME UTC -2 second" -u "+%Y-%m-%d %H:%M:%S")" + FSTIMEM3="$(date -d "$FSTIME UTC -3 second" -u "+%Y-%m-%d %H:%M:%S")" + + if echo "$LSOUT" | grep -F 'Last modification time '"$FSTIME" > /dev/null || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM1" > /dev/null || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM2" || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM3" > /dev/null; then + : + else + echo FSTIME FAIL + echo "$FSTIME" + echo "$LSOUT" + exit 1 + fi + fi + + if [ x$NOHARDLINK != xy ]; then + if run_grubfstest cmp "$GRUBDIR/$BASEHARD" "$MNTPOINTRO/$OSDIR/$BASEFILE" ; then + : + else + echo HARDLINK FAIL + exit 1 + fi + fi + + if [ x$NOSYMLINK != xy ]; then + if run_grubfstest cmp "$GRUBDIR/$BASESYM" "$MNTPOINTRO/$OSDIR/$BASEFILE" ; then + : + else + echo SYMLINK FAIL + exit 1 + fi + if run_grubfstest cmp "$GRUBDIR/$LONGSYM" "$MNTPOINTRO/$OSDIR/$LONGNAME" ; then + : + else + echo LONG SYMLINK FAIL + exit 1 + fi + if run_grubfstest cmp "$GRUBDIR/$ISYM" "$MNTPOINTRO/$OSDIR/$IFILE" ; then + : + else + echo INTL SYMLINK FAIL + exit 1 + fi + if run_grubfstest cmp "$GRUBDIR/$SSYM" "$MNTPOINTRO/$OSDIR/////sdir/////2.img" ; then + : + else + echo SDIR SYMLINK FAIL + exit 1 + fi + if run_grubfstest cmp "$GRUBDIR/$USYM" "$MNTPOINTRO/$OSDIR/1.img" ; then + : + else + echo SDIR SYMLINK FAIL + exit 1 + fi + if run_grubfstest cmp "$GRUBDIR/$PSYM" "$MNTPOINTRO/$OSDIR/${PDIR2}/$PFIL" ; then + : + else + echo PATH LONG SYMLINK FAIL + exit 1 + fi + fi + + if run_grubfstest cmp "$GRUBDIR/$BASEFILE" "$MNTPOINTRO/$OSDIR/$BASEFILE" ; then + : + else + echo READ FAIL + exit 1 + fi + if run_grubfstest cmp "$GRUBDIR/$NASTYFILE" "$MNTPOINTRO/$OSDIR/$NASTYFILE" ; then + : + else + echo NREAD FAIL + exit 1 + fi + # Reference archive contains original name + if run_grubfstest cmp "$GRUBDIR/$LONGNAME" "$MNTPOINTRO/$OSDIR/$LONGNAME" ; then + : + else + echo LONG NAME READ FAIL + exit 1 + fi + if run_grubfstest cmp "$GRUBDIR/////sdir/////2.img" "$MNTPOINTRO/$OSDIR/sdir/2.img" ; then + : + else + echo LONG NAME READ FAIL + exit 1 + fi + if run_grubfstest cmp "$GRUBDIR/$IFILE" "$MNTPOINTRO/$OSDIR/$IFILE" ; then + : + else + echo IREAD FAIL + exit 1 + fi + if run_grubfstest cmp "$GRUBDIR/$PDIR/$PFIL" "$MNTPOINTRO/$OSDIR/$PDIR/$PFIL" ; then + : + else + echo PREAD FAIL + echo cmp "$GRUBDIR/$PDIR/$PFIL" "$MNTPOINTRO/$OSDIR/$PDIR/$PFIL" + exit 1 + fi + ok=true + if ! run_grubfstest cmp "$GRUBDIR/${CFILE}" "$MNTPOINTRO/$OSDIR/${CFILE}" ; then + ok=false; + fi + if test x$ok = xtrue; then + : + else + echo CREAD FAIL + exit 1 + fi + + if [ x$CASESENS = xy ]; then + if run_grubfstest cmp "$GRUBDIR/CaSe" "$MNTPOINTRO/$OSDIR/CaSe" ; then + : + else + echo CASE1 READ FAIL + exit 1 + fi + if run_grubfstest cmp "$GRUBDIR/cAsE" "$MNTPOINTRO/$OSDIR/cAsE" ; then + : + else + exit 1 + fi + if cmp "$MNTPOINTRO/$OSDIR/cAsE" "$MNTPOINTRO/$OSDIR/CaSe" > /dev/null ; then + exit 1 + fi + if test x$ok = xtrue; then + : + else + echo CASE READ FAIL + exit 1 + fi + else + # OS LIMITATION: Linux make FAT (partially) case-sensitive... + # ISO9660 is generated and master doesn't change + case x$fs in + xiso9660 | xvfat*) + CASEX=CaSe;; + *) + CASEX=cAsE;; + esac + if run_grubfstest cmp "$GRUBDIR/CaSe" "$MNTPOINTRO/$OSDIR/${CASEX}" ; then + : + else + echo CASE1 READ FAIL + exit 1 + fi + if run_grubfstest cmp "$GRUBDIR/cAsE" "$MNTPOINTRO/$OSDIR/CaSe" ; then + : + else + echo CASE2 READ FAIL + exit 1 + fi + if ! cmp "$MNTPOINTRO/$OSDIR/CaSe" "$MNTPOINTRO/$OSDIR/${CASEX}" > /dev/null ; then + echo CASE CMP READ FAIL + exit 1 + fi + if test x$ok = xtrue; then + : + else + echo CASE READ FAIL + exit 1 + fi + fi + + case x"$fs" in + x"zfs"*) + while ! zpool export "$FSLABEL" ; do + sleep 1; + done + sleep 5;; + x"tarfs" | x"cpio_"* | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | xiso9660 | xiso9660_1999 | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) + rm -rf "$MNTPOINTRW";; + x"afs") + rm -rf "$MNTPOINTRO" + ;; + *) + sleep 1 + umount "$MNTPOINTRO" || true + umount "$MNTPOINTRW" || true + esac + sleep 1 + case x"$fs" in + xmdraid*) + mdadm --stop /dev/md/"${fs}_$NDEVICES" + sleep 1 + ;; + xlvm*) + vgchange -a n grub_test + sleep 1 + ;; + esac + case x"$fs" in + x"tarfs" | x"cpio_"* | x"iso9660" | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;; + *) + for lodev in $LODEVICES; do + while ! losetup -d "$lodev"; do + sleep 1 + done + done;; + esac + for i in $(range 0 $((NDEVICES-1)) 1); do + rm "$FSIMAGEP${i}.img" + done + if [ x"$fs" = x"zfs" ]; then + rmdir "$MNTPOINTRW"/"grub fs" || true + rmdir "$MNTPOINTRO"/"grub fs" || true + fi + rm -rf "$MNTPOINTRW" || true + rm -rf "$MNTPOINTRO" || true + done + done +done +rmdir "${tempdir}" diff --git a/tests/util/grub-shell-tester.in b/tests/util/grub-shell-tester.in new file mode 100644 index 0000000..8a87109 --- /dev/null +++ b/tests/util/grub-shell-tester.in @@ -0,0 +1,106 @@ +#! @BUILD_SHEBANG@ +set -e + +# Compares GRUB script output with BASH output. +# Copyright (C) 2009,2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +# Initialize some variables. +prefix="@prefix@" +exec_prefix="@exec_prefix@" +datarootdir="@datarootdir@" +builddir="@builddir@" +PACKAGE_NAME=@PACKAGE_NAME@ +PACKAGE_TARNAME=@PACKAGE_TARNAME@ +PACKAGE_VERSION=@PACKAGE_VERSION@ + +# Force build directory components +PATH="${builddir}:$PATH" +export PATH + +# Usage: usage +# Print the usage. +usage () { + cat <<EOF +Usage: $0 [OPTION] [SOURCE] +Compares GRUB script output with BASH shell output. + + -h, --help print this message and exit + -v, --version print the version information and exit + --modules=MODULES pre-load specified modules MODULES + --qemu-opts=OPTIONS extra options to pass to Qemu instance + +$0 compares GRUB script output with BASH shell output and prints their +differences. + +Report bugs to <bug-grub@gnu.org>. +EOF +} + +# Check the arguments. +for option in "$@"; do + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "$0 (GNU GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --modules=*) + ms=`echo "$option" | sed -e 's/--modules=//'` + modules="$modules,$ms" ;; + --qemu-opts=*) + qs=`echo "$option" | sed -e 's/--qemu-opts=//'` + qemuopts="$qemuopts $qs" ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 + ;; + *) + if [ "x${source}" != x ] ; then + echo "too many parameters at the end" 1>&2 + usage + exit 1 + fi + source="${option}" ;; + esac +done + +if [ "x${source}" = x ] ; then + tmpfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + while read REPLY; do + echo $REPLY >> "${tmpfile}" + done + source="${tmpfile}" +fi + +outfile1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 +"@builddir@/grub-shell" --qemu-opts="${qemuopts}" --modules=${modules} "${source}" >"${outfile1}" + +outfile2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 +bash "${source}" >"${outfile2}" + +if ! diff -q "${outfile1}" "${outfile2}" >/dev/null +then + echo "${source}: GRUB and BASH outputs did not match (see diff -u ${outfile1} ${outfile2})" + status=1 +else + rm -f "${outfile1}" "${outfile2}" +fi + +exit $status + + diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in new file mode 100644 index 0000000..93e9f51 --- /dev/null +++ b/tests/util/grub-shell.in @@ -0,0 +1,517 @@ +#! @BUILD_SHEBANG@ +set -e + +# Run GRUB script in a Qemu instance +# Copyright (C) 2009,2010 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +# Initialize some variables. +prefix="@prefix@" +exec_prefix="@exec_prefix@" +datarootdir="@datarootdir@" +builddir="@builddir@" +srcdir="@srcdir@" +PACKAGE_NAME=@PACKAGE_NAME@ +PACKAGE_TARNAME=@PACKAGE_TARNAME@ +PACKAGE_VERSION=@PACKAGE_VERSION@ + +# Force build directory components +PATH="${builddir}:$PATH" +export PATH + +trim=0 + +# Usage: usage +# Print the usage. +usage () { + cat <<EOF +Usage: $0 [OPTION] [SOURCE] +Run GRUB script in a Qemu instance. + + -h, --help print this message and exit + -v, --version print the version information and exit + --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 + --timeout=SECONDS set timeout + --trim trim firmware output + +$0 runs input GRUB script or SOURCE file in a Qemu instance and prints +its output. + +Report bugs to <bug-grub@gnu.org>. +EOF +} + +. "${builddir}/grub-core/modinfo.sh" +qemuopts="${GRUB_QEMU_OPTS}" +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 + serial_port= + ;; + powerpc-ieee1275) + boot=hd + qemu=qemu-system-ppc + console=console + serial_port=escc-ch-b + serial_null="-serial null" + netbootext=elf + trim=1 + ;; + + sparc64-ieee1275) + boot=cd + qemu=qemu-system-sparc64 + console= + serial_port=ieee1275/ttya + trim=1 + qemuopts="$qemuopts -no-reboot" + halt_cmd=reboot + ;; + + mips-qemu_mips) + boot=mips_qemu + qemu=qemu-system-mips + qemuopts="-M mips $qemuopts" + console=vga_text + ;; + mips-arc) + boot=cd + qemu=qemu-system-mips64 + qemuopts="-M indy $qemuopts" + serial_port=arc/serial0/line0 + console= + trim=1 + ;; + mipsel-arc) + boot=cd + qemu=qemu-system-mips64el + qemuopts="-M magnum $qemuopts -no-reboot" + serial_port=arc/multi0/serial0 + console=console + halt_cmd=reboot + trim=1 + ;; + mipsel-qemu_mips) + boot=mipsel_qemu + qemu=qemu-system-mipsel + qemuopts="-M mips $qemuopts" + console=vga_text + ;; + mipsel-loongson) + boot=mipsel_fulong2e + qemu=qemu-system-mips64el + qemuopts="-M fulong2e $qemuopts" + console= + trim=1 + ;; + i386-coreboot) + boot=coreboot + qemu=qemu-system-i386 + console=vga_text + ;; + i386-multiboot) + boot=cd + qemu=qemu-system-i386 + console=vga_text;; + + i386-ieee1275) + boot=hd + qemu=qemu-system-i386 + console=console + trim=1 + disk="hdb " + ;; + i386-qemu) + boot=qemu + qemu=qemu-system-i386 + console=vga_text;; + + i386-pc) + boot=cd + qemu=qemu-system-i386 + console=console + netbootext=0 + ;; + + i386-efi) + qemu=qemu-system-i386 + boot=cd + console=console + trim=1 + qemuopts="-bios OVMF-ia32.fd $qemuopts" + ;; + x86_64-efi) + qemu=qemu-system-x86_64 + boot=cd + console=console + trim=1 + qemuopts="-bios OVMF.fd $qemuopts" + ;; + arm64-efi) + qemu=qemu-system-aarch64 + boot=hd + console=console + trim=1 + qemuopts="-machine virt -cpu cortex-a57 -bios /usr/share/qemu-efi/QEMU_EFI.fd $qemuopts" + disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file=" + serial_port= + ;; + arm-efi) + qemu=qemu-system-arm + boot=hd + console=console + trim=1 + qemuopts="-machine virt -bios /usr/share/ovmf-arm/QEMU_EFI.fd $qemuopts" + disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file=" + serial_port=efi0 + ;; + *) + boot=hd + qemu=qemu-system-i386 + console=console;; +esac + +timeout=60 +mkimage_extra_arg= + +# Check the arguments. +for option in "$@"; do + case "$option" in + -h | --help) + usage + exit 0 ;; + -v | --version) + echo "$0 (GNU GRUB ${PACKAGE_VERSION})" + exit 0 ;; + --trim) + trim=1 + ;; + --debug) + debug=1 ;; + --modules=*) + ms=`echo "$option" | sed -e 's/--modules=//' -e 's/,/ /g'` + modules="$modules $ms" ;; + --files=*) + fls=`echo "$option" | sed -e 's/--files=//' -e 's/,/ /g'` + files="$files $fls" ;; + --mkrescue-arg=*) + mkr=`echo "$option" | sed -e 's/--mkrescue-arg=//' -e 's/,/ /g'` + mkrescue_args="$mkrescue_args $mkr" ;; + --qemu=*) + qemu=`echo "$option" | sed -e 's/--qemu=//' -e 's/,/ /g'`;; + --pseries) + qemu=qemu-system-ppc64 + serial_port=ieee1275/hvterm + serial_null= + qemuopts="$qemuopts -M pseries -no-reboot" + trim=1 + pseries=y + ;; + --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=//'` + ;; + + # Intentionally undocumented + --grub-mkimage-extra) + mkimage_extra_arg="$mkimage_extra_arg `argument $option "$@"`"; shift ;; + --grub-mkimage-extra=*) + mkimage_extra_arg="$mkimage_extra_arg `echo "$option" | sed 's/--grub-mkimage-extra=//'`" ;; + + --boot=*) + dev=`echo "$option" | sed -e 's/--boot=//'` + if [ "$dev" = "fd" ] ; then boot=fd; + elif [ "$dev" = "hd" ] ; then boot=hd; + elif [ "$dev" = "cd" ] ; then boot=cd; + elif [ "$dev" = "net" ] ; then boot=net; + elif [ "$dev" = "qemu" ] ; then boot=qemu; + elif [ "$dev" = "coreboot" ] ; then boot=coreboot; + elif [ "$dev" = "mips_qemu" ] ; then boot=mips_qemu; + elif [ "$dev" = "mipsel_qemu" ] ; then boot=mipsel_qemu; + elif [ "$dev" = "mipsel_fulong2e" ] ; then boot=mipsel_fulong2e; + else + echo "Unrecognized boot method \`$dev'" 1>&2 + usage + exit 1 + fi ;; + -*) + echo "Unrecognized option \`$option'" 1>&2 + usage + exit 1 ;; + *) + if [ "x${source}" != x ] ; then + echo "too many parameters at the end" 1>&2 + usage + exit 1 + fi + source="${option}" ;; + esac +done + +if [ "x${source}" = x ] ; then + tmpfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + while read REPLY; do + echo "$REPLY" >> ${tmpfile} + done + source=${tmpfile} +fi + +cfgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 +cat <<EOF >${cfgfile} +grubshell=yes +enable_progress_indicator=0 +export enable_progress_indicator +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 [ "${serial_port}" != "" ]; then + echo "serial ${serial_port}" >>${cfgfile} + term="serial_${serial_port}" +else + term=console +fi + +cat <<EOF >>${cfgfile} +terminfo -g 1024x1024 ${term} dumb +terminal_input ${term} +terminal_output ${term} +EOF + +trim_head=664cbea8-132f-4770-8aa4-1696d59ac35c + +if [ $trim = 1 ]; then + echo "echo $trim_head" >>${cfgfile} +fi + +rom_directory=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + +for mod in ${modules} +do + echo "insmod ${mod}" >> ${cfgfile} +done + +cat <<EOF >>${cfgfile} +source "\$prefix/testcase.cfg" +# Stop serial output to suppress "ACPI shutdown failed" error. +EOF +# Attempt to switch to console on i386-ieee1275 causes "screen not found" message +if [ x$console != x ] && [ x"${grub_modinfo_target_cpu}-${grub_modinfo_platform}" != xi386-ieee1275 ]; then + echo "terminal_output $console" >>${cfgfile} +fi +echo "${halt_cmd}" >>${cfgfile} + +test -z "$debug" || echo "GRUB script: ${cfgfile}" >&2 +test -z "$debug" || echo "GRUB testcase script: ${tmpfile}" >&2 +test -z "$debug" || echo "Boot device: ${boot}" >&2 + +isofile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 +test -z "$debug" || echo "GRUB ISO file: ${isofile}" >&2 +test -z "$debug" || echo "GRUB ROM directory: ${rom_directory}" >&2 + +if test -z "$debug"; then + qemuopts="${qemuopts} -nographic -monitor file:/dev/null" + # SeaBIOS 1.11.0 added support for VGA emulation over a serial port. If + # this is configured in SeaBIOS, then -nographic causes some extra junk to + # end up on the serial console, which interferes with our tests. This + # workaround unfortunately causes qemu to issue a warning 'externally + # provided fw_cfg item names should be prefixed with "opt/"', but there + # doesn't seem to be a better option. + qemuopts="${qemuopts} -fw_cfg name=etc/sercon-port,string=0" +fi + +if [ x$boot != xnet ] && [ x$boot != xemu ]; then + pkgdatadir="@builddir@" "@builddir@/grub-mkrescue" "--output=${isofile}" "--override-directory=${builddir}/grub-core" \ + --rom-directory="${rom_directory}" \ + --locale-directory="@srcdir@/po" \ + --themes-directory="@srcdir@/themes" \ + $mkimage_extra_arg ${mkrescue_args} \ + "/boot/grub/grub.cfg=${cfgfile}" "/boot/grub/testcase.cfg=${source}" \ + ${files} >/dev/null 2>&1 +fi +if [ x$boot = xhd ]; then + if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm64-efi ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm-efi ]; then + device="device virtio-blk-device,drive=hd0 -drive if=none,id=hd0,file=" + elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = mips-arc ]; then + device="hdb " + else + device="hda " + fi + bootdev="-boot c" +fi +if [ x$boot = xcd ]; then + if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm64-efi ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm-efi ]; then + device="device virtio-blk-device,drive=cd0 -drive if=none,id=cd0,media=cdrom,file=" + elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = powerpc-ieee1275 ] && [ x$pseries != xy ] ; then + device="-drive if=ide,media=cdrom,file=" + else + device="cdrom " + fi + bootdev="-boot d" +fi +if [ x$boot = xfd ]; then + device="fda " + bootdev="-boot a" +fi + +if [ x$boot = xqemu ]; then + bootdev="-bios ${rom_directory}/qemu.img" + device="cdrom " +fi + +if [ x$boot = xmipsel_qemu ]; then + bootdev="-kernel ${rom_directory}/mipsel-qemu_mips.elf" + device="cdrom " +fi + +if [ x$boot = xmipsel_fulong2e ]; then + bootdev="-kernel ${rom_directory}/mipsel-loongson.elf -append machtype=lemote-fuloong-2e" + device="cdrom " +fi + +if [ x$boot = xmips_qemu ]; then + bootdev="-kernel ${rom_directory}/mips-qemu_mips.elf" + device="cdrom " +fi + +if [ x$boot = xcoreboot ]; then + imgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + cp "${GRUB_COREBOOT_ROM}" "${imgfile}" + "${GRUB_CBFSTOOL}" "${imgfile}" add-payload -f "${rom_directory}/coreboot.elf" -n fallback/payload + bootdev="-bios ${imgfile}" + device="cdrom " + test -z "$debug" || echo "Coreboot image: ${imgfile}" >&2 +fi + +if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = mipsel-arc ]; then + case "$boot" in + hd) + bootdev="-global ds1225y.filename=$GRUB_QEMU_MAGNUM_NVRAM_DIR/disk" ;; + *) + bootdev="-global ds1225y.filename=$GRUB_QEMU_MAGNUM_NVRAM_DIR/cdrom";; + esac +fi + +do_trim () +{ + if [ $trim = 1 ]; then + awk '{ if (have_head == 1) print $0; } /664cbea8-132f-4770-8aa4-1696d59ac35c/ { have_head=1; }' + else + cat + fi +} + +copy_extra_files() { + _destdir="$1" + shift + + # FIXME support '=' in file names + for _file in "$@"; do + _target="${_file%=*}" + _source="${_file#*=}" + [ -n "$_source" ] || _source="$_target" + _target="$_destdir/$_target" + _targetdir="$(dirname "$_target")" + [ -d "$_targetdir" ] || mkdir -p "$_targetdir" + cp "$_source" "$_target" + done +} + +if [ x$boot = xnet ]; then + netdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + pkgdatadir="@builddir@" "@builddir@/grub-mknetdir" "--grub-mkimage=${builddir}/grub-mkimage" "--directory=${builddir}/grub-core" "--net-directory=$netdir" ${mkrescue_args} > /dev/null + cp "${cfgfile}" "$netdir/boot/grub/grub.cfg" + cp "${source}" "$netdir/boot/grub/testcase.cfg" + [ -z "$files" ] || copy_extra_files "$netdir" $files + timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -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 + rootdir="$(mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")" + grubdir="$rootdir/boot/grub" + mkdir -p "$grubdir/fonts" + mkdir -p "$grubdir/themes" + mkdir -p "$grubdir/locale" + test -f "@builddir@/"unicode.pf2 && cp "@builddir@/"unicode.pf2 "$grubdir/fonts/unicode.pf2" + cp -R "@srcdir@/themes/starfield" "$grubdir/themes/starfield" + for file in "@srcdir@/po/"*.gmo; do + if [ -f "$file" ]; then + cp "$file" "$grubdir/locale/" + fi + done + cp "${cfgfile}" "$grubdir/grub.cfg" + cp "${source}" "$grubdir/testcase.cfg" + [ -z "$files" ] || copy_extra_files "$rootdir" $files + roottar="$(mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")" + (cd "$rootdir"; tar cf "$roottar" .) + @builddir@/grub-core/grub-emu -m "$device_map" --memdisk "$roottar" -r memdisk -d "/boot/grub" | tr -d "\r" | do_trim + test -n "$debug" || rm -rf "$rootdir" + test -n "$debug" || rm -f "$roottar" +else + timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} | cat | tr -d "\r" | do_trim +fi +if [ x$boot = xcoreboot ]; then + test -n "$debug" || rm -f "${imgfile}" +fi +test -n "$debug" || rm -f "${isofile}" +test -n "$debug" || rm -rf "${rom_directory}" +test -n "$debug" || rm -f "${tmpfile}" "${cfgfile}" +exit 0 + + diff --git a/tests/xfs_test.in b/tests/xfs_test.in new file mode 100644 index 0000000..03a3513 --- /dev/null +++ b/tests/xfs_test.in @@ -0,0 +1,20 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which mkfs.xfs >/dev/null 2>&1; then + echo "mkfs.xfs not installed; cannot test xfs." + exit 77 +fi + + +"@builddir@/grub-fs-tester" xfs_crc +"@builddir@/grub-fs-tester" xfs diff --git a/tests/xzcompress_test.in b/tests/xzcompress_test.in new file mode 100644 index 0000000..03bfb5e --- /dev/null +++ b/tests/xzcompress_test.in @@ -0,0 +1,29 @@ +#! @BUILD_SHEBANG@ +# Copyright (C) 2013 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +set -e +grubshell=@builddir@/grub-shell + +. "@builddir@/grub-core/modinfo.sh" + +if ! which xz >/dev/null 2>&1; then + echo "xz not installed; cannot test xz compression." + exit 77 +fi + +if [ "$(echo hello | "${grubshell}" --mkrescue-arg=--compress=xz)" != "Hello World" ]; then + exit 1 +fi diff --git a/tests/zfs_test.in b/tests/zfs_test.in new file mode 100644 index 0000000..eee62c1 --- /dev/null +++ b/tests/zfs_test.in @@ -0,0 +1,27 @@ +#!@BUILD_SHEBANG@ + +set -e + +if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +fi + +if [ "$EUID" != 0 ] ; then + exit 77 +fi + +if ! which zpool >/dev/null 2>&1; then + echo "zpool not installed; cannot test zfs." + exit 77 +fi + +"@builddir@/grub-fs-tester" zfs +"@builddir@/grub-fs-tester" zfs_lzjb +"@builddir@/grub-fs-tester" zfs_gzip +"@builddir@/grub-fs-tester" zfs_zle +"@builddir@/grub-fs-tester" zfs_raidz3 +"@builddir@/grub-fs-tester" zfs_raidz2 +"@builddir@/grub-fs-tester" zfs_raidz +"@builddir@/grub-fs-tester" zfs_mirror +"@builddir@/grub-fs-tester" zfs_stripe +"@builddir@/grub-fs-tester" zfs_caseins |