aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJames <james.mckenzie@citrix.com>2012-11-16 10:41:01 +0000
committerJames <james.mckenzie@citrix.com>2012-11-16 10:41:01 +0000
commit041d1ea37802bf7178a31a53f96c26efa6b8fb7b (patch)
treec193e84ad1237f25a79d0f6a267722e44c73f56a /tests
downloadgrub-1.99-041d1ea37802bf7178a31a53f96c26efa6b8fb7b.tar.gz
grub-1.99-041d1ea37802bf7178a31a53f96c26efa6b8fb7b.tar.bz2
grub-1.99-041d1ea37802bf7178a31a53f96c26efa6b8fb7b.zip
fish
Diffstat (limited to 'tests')
-rw-r--r--tests/example_grub_script_test.in3
-rw-r--r--tests/example_scripted_test.in3
-rw-r--r--tests/example_unit_test.c38
-rw-r--r--tests/grub_cmd_echo.in41
-rw-r--r--tests/grub_cmd_regexp.in41
-rw-r--r--tests/grub_script_blanklines.in14
-rw-r--r--tests/grub_script_blockarg.in41
-rw-r--r--tests/grub_script_break.in86
-rw-r--r--tests/grub_script_comments.in28
-rw-r--r--tests/grub_script_continue.in86
-rw-r--r--tests/grub_script_dollar.in5
-rw-r--r--tests/grub_script_echo1.in101
-rw-r--r--tests/grub_script_echo_keywords.in3
-rw-r--r--tests/grub_script_expansion.in42
-rw-r--r--tests/grub_script_final_semicolon.in10
-rw-r--r--tests/grub_script_for1.in27
-rw-r--r--tests/grub_script_functions.in147
-rw-r--r--tests/grub_script_if.in31
-rw-r--r--tests/grub_script_not.in62
-rw-r--r--tests/grub_script_return.in134
-rw-r--r--tests/grub_script_setparams.in59
-rw-r--r--tests/grub_script_shift.in85
-rw-r--r--tests/grub_script_vars1.in34
-rw-r--r--tests/grub_script_while1.in32
-rw-r--r--tests/lib/unit_test.c45
-rw-r--r--tests/partmap_test.in274
-rw-r--r--tests/util/grub-shell-tester.in109
-rw-r--r--tests/util/grub-shell.in192
28 files changed, 1773 insertions, 0 deletions
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..9ac0424
--- /dev/null
+++ b/tests/example_scripted_test.in
@@ -0,0 +1,3 @@
+#!/bin/sh -e
+
+true
diff --git a/tests/example_unit_test.c b/tests/example_unit_test.c
new file mode 100644
index 0000000..d721a9d
--- /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);
+
+ /* 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/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..43b479f
--- /dev/null
+++ b/tests/grub_cmd_regexp.in
@@ -0,0 +1,41 @@
+#! /bin/bash -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_script_blanklines.in b/tests/grub_script_blanklines.in
new file mode 100644
index 0000000..71b869b
--- /dev/null
+++ b/tests/grub_script_blanklines.in
@@ -0,0 +1,14 @@
+#! /bin/sh -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..2765b61
--- /dev/null
+++ b/tests/grub_script_blockarg.in
@@ -0,0 +1,41 @@
+#! /bin/bash
+
+# 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..3819b8b
--- /dev/null
+++ b/tests/grub_script_dollar.in
@@ -0,0 +1,5 @@
+#! /bin/sh -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..9415a3f
--- /dev/null
+++ b/tests/grub_script_echo1.in
@@ -0,0 +1,101 @@
+#! @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'
+
+# 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\
+# two"
+# echo 'one\
+# two'
+# echo foo\
+# bar
+# \
+# echo foo
+# echo "one
+#
+# two"
+
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_expansion.in b/tests/grub_script_expansion.in
new file mode 100644
index 0000000..d1e8d55
--- /dev/null
+++ b/tests/grub_script_expansion.in
@@ -0,0 +1,42 @@
+#! /bin/bash -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`
+other=`echo insmod regexp\; echo \* | @builddir@/grub-shell`
+for d in $disks; do
+ if echo "$d" |grep ',' >/dev/null; then
+ if echo "$other" | grep "$d" >/dev/null; then
+ echo "$d should not occur in * expansion" >&2
+ exit 1
+ fi
+ else
+ if ! echo "$other" | grep "$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 "$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..99e55e5
--- /dev/null
+++ b/tests/grub_script_final_semicolon.in
@@ -0,0 +1,10 @@
+#! /bin/sh -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_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_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_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/lib/unit_test.c b/tests/lib/unit_test.c
new file mode 100644
index 0000000..a780d68
--- /dev/null
+++ b/tests/lib/unit_test.c
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+ extern void grub_unit_test_init (void);
+ extern void grub_unit_test_fini (void);
+
+ 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/partmap_test.in b/tests/partmap_test.in
new file mode 100644
index 0000000..7e9cef7
--- /dev/null
+++ b/tests/partmap_test.in
@@ -0,0 +1,274 @@
+#! /bin/sh -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
+
+create_disk_image () {
+ name=$1
+ size=$2
+ qemu-img create ${name} ${size} >/dev/null
+}
+
+check_output () {
+ outfile=$1
+ shift
+
+ for disk in $@; do
+ if ! grep "($disk)" ${outfile} >/dev/null
+ then
+ echo "($disk): disk/partiton not found"
+ exit 1
+ fi
+ done
+}
+
+list_parts () {
+ mod=$1;
+ shift;
+ imgfile=$1
+ shift
+ outfile=$1
+ shift
+
+ echo ls | ${grubshell} --boot=cd --qemu-opts="-hda ${imgfile}" \
+ --modules=$mod | tr -d "\n\r" > ${outfile}
+ cat ${outfile}
+ echo
+}
+
+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} 64M
+${parted} -a none -s ${imgfile} mklabel msdos
+list_parts part_msdos ${imgfile} ${outfile}
+check_output ${outfile} hd0
+
+# 1 primary
+create_disk_image ${imgfile} 64M
+${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M
+list_parts part_msdos ${imgfile} ${outfile}
+check_output ${outfile} hd0 hd0,msdos1
+
+# 2 primary
+create_disk_image ${imgfile} 128M
+${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M
+list_parts part_msdos ${imgfile} ${outfile}
+check_output ${outfile} hd0 hd0,msdos1 hd0,msdos2
+
+# 3 primary
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,msdos1 hd0,msdos2 hd0,msdos3
+
+# 4 primary
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,msdos1 hd0,msdos2 hd0,msdos3 hd0,msdos4
+
+# 1 primary, 1 extended
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,msdos1
+
+# 1 primary, 1 extended, 1 logical
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,msdos1 hd0,msdos5
+
+# 1 primary, 1 extended, 2 logical
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6
+
+# 1 primary, 1 extended, 3 logical
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6 hd0,msdos7
+
+# 1 primary, 1 extended, 4 logical
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6 hd0,msdos7 hd0,msdos8
+
+
+#
+# GPT partition types
+#
+
+echo "Checking GPT partition types..."
+
+# 0 parts
+create_disk_image ${imgfile} 64M
+${parted} -a none -s ${imgfile} mklabel gpt
+list_parts part_gpt ${imgfile} ${outfile}
+check_output ${outfile} hd0
+
+# 1 parts
+create_disk_image ${imgfile} 64M
+${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M
+list_parts part_gpt ${imgfile} ${outfile}
+check_output ${outfile} hd0 hd0,gpt1
+
+# 2 parts
+create_disk_image ${imgfile} 128M
+${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M
+list_parts part_gpt ${imgfile} ${outfile}
+check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2
+
+# 3 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3
+
+# 4 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4
+
+# 5 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4 hd0,gpt5
+
+# 6 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4 hd0,gpt5 hd0,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} 64M
+${parted} -a none -s ${imgfile} mklabel sun
+list_parts part_sun ${imgfile} ${outfile}
+check_output ${outfile} hd0
+
+# 1 parts
+create_disk_image ${imgfile} 64M
+${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M
+list_parts part_sun ${imgfile} ${outfile}
+check_output ${outfile} hd0 hd0,sun1
+
+# 2 parts
+create_disk_image ${imgfile} 128M
+${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M
+list_parts part_sun ${imgfile} ${outfile}
+check_output ${outfile} hd0 hd0,sun1 hd0,sun2
+
+# 3 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,sun1 hd0,sun2 hd0,sun4
+
+# 4 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5
+
+# 5 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5 hd0,sun6
+
+# 6 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5 hd0,sun6 hd0,sun7
+
+
+#
+# Apple partition types
+#
+# Partition table itself is part of some partition, so there is always
+# a partition by default. But I don't understand why GRUB displays
+# two partitions by default :-(
+#
+
+echo "Checking APPLE partition types..."
+
+# 0 parts
+create_disk_image ${imgfile} 64M
+${parted} -a none -s ${imgfile} mklabel mac
+list_parts part_apple ${imgfile} ${outfile}
+check_output ${outfile} hd0 hd0,apple1 hd0,apple2
+
+# 1 parts
+create_disk_image ${imgfile} 64M
+${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M
+list_parts part_apple ${imgfile} ${outfile}
+check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple3
+
+# 2 parts
+create_disk_image ${imgfile} 128M
+${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M mkpart b 10M 20M
+list_parts part_apple ${imgfile} ${outfile}
+check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple3 hd0,apple4
+
+# 3 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5
+
+# 4 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6
+
+# 5 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6 hd0,apple7
+
+# 6 parts
+create_disk_image ${imgfile} 128M
+${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} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6 hd0,apple7 hd0,apple8
diff --git a/tests/util/grub-shell-tester.in b/tests/util/grub-shell-tester.in
new file mode 100644
index 0000000..02e49d3
--- /dev/null
+++ b/tests/util/grub-shell-tester.in
@@ -0,0 +1,109 @@
+#! /bin/sh -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.
+transform="@program_transform_name@"
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+bindir=@bindir@
+libdir=@libdir@
+builddir=@builddir@
+PACKAGE_NAME=@PACKAGE_NAME@
+PACKAGE_TARNAME=@PACKAGE_TARNAME@
+PACKAGE_VERSION=@PACKAGE_VERSION@
+target_cpu=@target_cpu@
+
+# 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..0213376
--- /dev/null
+++ b/tests/util/grub-shell.in
@@ -0,0 +1,192 @@
+#! /bin/sh -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.
+transform="@program_transform_name@"
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+bindir=@bindir@
+libdir=@libdir@
+builddir=@builddir@
+PACKAGE_NAME=@PACKAGE_NAME@
+PACKAGE_TARNAME=@PACKAGE_TARNAME@
+PACKAGE_VERSION=@PACKAGE_VERSION@
+target_cpu=@target_cpu@
+platform=@platform@
+
+# Force build directory components
+PATH=${builddir}:$PATH
+export PATH
+
+# 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
+ --qemu-opts=OPTIONS extra options to pass to Qemu instance
+ --files=FILES add files to the image
+
+$0 runs input GRUB script or SOURCE file in a Qemu instance and prints
+its output.
+
+Report bugs to <bug-grub@gnu.org>.
+EOF
+}
+
+boot=hd
+qemu=qemu-system-i386
+
+# 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=//' -e 's/,/ /g'`
+ modules="$modules $ms" ;;
+ --files=*)
+ fls=`echo "$option" | sed -e 's/--files=//' -e 's/,/ /g'`
+ files="$files $fls" ;;
+ --qemu=*)
+ qemu=`echo "$option" | sed -e 's/--qemu=//' -e 's/,/ /g'`;;
+ --qemu-opts=*)
+ qs=`echo "$option" | sed -e 's/--qemu-opts=//'`
+ qemuopts="$qemuopts $qs" ;;
+ --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;
+ 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
+insmod serial
+serial
+terminfo serial dumb
+terminal_input serial
+terminal_output serial
+EOF
+
+rom_directory=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+
+for mod in ${modules}
+do
+ echo "insmod ${mod}" >> ${cfgfile}
+done
+
+cat <<EOF >>${cfgfile}
+source /boot/grub/testcase.cfg
+# Stop serial output to suppress "ACPI shutdown failed" error.
+terminal_output console
+halt
+EOF
+
+isofile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+if [ x$boot != xnet ]; then
+ sh @builddir@/grub-mkrescue --grub-mkimage=${builddir}/grub-mkimage --output=${isofile} --override-directory=${builddir}/grub-core \
+ --rom-directory="${rom_directory}" \
+ /boot/grub/grub.cfg=${cfgfile} /boot/grub/testcase.cfg=${source} \
+ ${files} >/dev/null 2>&1
+fi
+if [ x$boot = xhd ]; then
+ device=hda
+ bootdev="-boot c"
+fi
+if [ x$boot = xcd ]; then
+ device=cdrom
+ 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 = xcoreboot ]; then
+ imgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+ cp "${GRUB_COREBOOT_ROM}" "${imgfile}"
+ "${GRUB_CBFSTOOL}" "${imgfile}" add-payload "${rom_directory}/coreboot.elf" fallback/payload
+ bootdev="-bios ${imgfile}"
+ device=cdrom
+fi
+
+if [ x$boot = xnet ]; then
+ netdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+ sh @builddir@/grub-mknetdir --grub-mkimage=${builddir}/grub-mkimage --override-directory=${builddir}/grub-core --net-directory=$netdir
+ cp ${cfgfile} $netdir/boot/grub/grub.cfg
+ cp ${source} $netdir/boot/grub/testcase.cfg
+ ${qemu} ${qemuopts} -nographic -serial file:/dev/stdout -monitor file:/dev/null -boot n -net user,tftp=$netdir,bootfile=/boot/grub/$target_cpu-$platform/core.0 -net nic | cat | tr -d "\r"
+else
+ ${qemu} ${qemuopts} -nographic -serial file:/dev/stdout -monitor file:/dev/null -${device} ${isofile} ${bootdev} | cat | tr -d "\r"
+fi
+rm -f "${isofile}" "${imgfile}"
+rm -rf "${rom_directory}"
+if [ x$boot = xcoreboot ]; then
+ rm -f "${imgfile}"
+fi
+
+rm -f "${tmpfile}" "${cfgfile}"
+exit 0
+
+