GRUB-1.98 changes
[grub2/jjazz.git] / tests / util / grub-shell-tester.in
blob6ed4ebcac8e9485084daa860f66dff9760da459f
1 #! /bin/bash -e
3 # Compares GRUB script output with BASH output.
4 # Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
6 # GRUB is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # GRUB is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 # Initialize some variables.
20 transform="@program_transform_name@"
22 prefix=@prefix@
23 exec_prefix=@exec_prefix@
24 bindir=@bindir@
25 libdir=@libdir@
26 builddir=@builddir@
27 PACKAGE_NAME=@PACKAGE_NAME@
28 PACKAGE_TARNAME=@PACKAGE_TARNAME@
29 PACKAGE_VERSION=@PACKAGE_VERSION@
30 target_cpu=@target_cpu@
32 # Force build directory components
33 PATH=${builddir}:$PATH
34 export PATH
36 # Usage: usage
37 # Print the usage.
38 usage () {
39 cat <<EOF
40 Usage: $0 [OPTION] [SOURCE]
41 Compares GRUB script output with BASH shell output.
43 -h, --help print this message and exit
44 -v, --version print the version information and exit
45 --modules=MODULES pre-load specified modules MODULES
46 --qemu-opts=OPTIONS extra options to pass to Qemu instance
48 $0 compares GRUB script output with BASH shell output and prints their
49 differences.
51 Report bugs to <bug-grub@gnu.org>.
52 EOF
55 # Check the arguments.
56 for option in "$@"; do
57 case "$option" in
58 -h | --help)
59 usage
60 exit 0 ;;
61 -v | --version)
62 echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
63 exit 0 ;;
64 --modules=*)
65 ms=`echo "$option" | sed -e 's/--modules=//'`
66 modules="$modules,$ms" ;;
67 --qemu-opts=*)
68 qs=`echo "$option" | sed -e 's/--qemu-opts=//'`
69 qemuopts="$qemuopts $qs" ;;
70 -*)
71 echo "Unrecognized option \`$option'" 1>&2
72 usage
73 exit 1
76 if [ "x${source}" != x ] ; then
77 echo "too many parameters at the end" 1>&2
78 usage
79 exit 1
81 source="${option}" ;;
82 esac
83 done
85 if [ "x${source}" = x ] ; then
86 tmpfile=`mktemp`
87 while read; do
88 echo $REPLY >> ${tmpfile}
89 done
90 source=${tmpfile}
93 outfile1=`mktemp`
94 @builddir@/grub-shell --qemu-opts="${qemuopts}" --modules=${modules} ${source} >${outfile1}
96 outfile2=`mktemp`
97 bash ${source} >${outfile2}
99 if ! diff -q ${outfile1} ${outfile2} >/dev/null
100 then
101 echo "${source}: GRUB and BASH outputs did not match (see diff -u ${outfile1} ${outfile2})"
102 status=1
103 else
104 rm -f ${outfile1} ${outfile2}
107 exit $status