grub-shell-tester.in 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #! @BUILD_SHEBANG@
  2. set -e
  3. # Compares GRUB script output with BASH output.
  4. # Copyright (C) 2009,2010 Free Software Foundation, Inc.
  5. #
  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.
  10. #
  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.
  15. #
  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/>.
  18. # Initialize some variables.
  19. prefix="@prefix@"
  20. exec_prefix="@exec_prefix@"
  21. datarootdir="@datarootdir@"
  22. builddir="@builddir@"
  23. PACKAGE_NAME=@PACKAGE_NAME@
  24. PACKAGE_TARNAME=@PACKAGE_TARNAME@
  25. PACKAGE_VERSION=@PACKAGE_VERSION@
  26. # Force build directory components
  27. PATH="${builddir}:$PATH"
  28. export PATH
  29. # Usage: usage
  30. # Print the usage.
  31. usage () {
  32. cat <<EOF
  33. Usage: $0 [OPTION] [SOURCE]
  34. Compares GRUB script output with BASH shell output.
  35. -h, --help print this message and exit
  36. -v, --version print the version information and exit
  37. --modules=MODULES pre-load specified modules MODULES
  38. --qemu-opts=OPTIONS extra options to pass to Qemu instance
  39. $0 compares GRUB script output with BASH shell output and prints their
  40. differences.
  41. Report bugs to <bug-grub@gnu.org>.
  42. EOF
  43. }
  44. # Check the arguments.
  45. for option in "$@"; do
  46. case "$option" in
  47. -h | --help)
  48. usage
  49. exit 0 ;;
  50. -v | --version)
  51. echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
  52. exit 0 ;;
  53. --modules=*)
  54. ms=`echo "$option" | sed -e 's/--modules=//'`
  55. modules="$modules,$ms" ;;
  56. --qemu-opts=*)
  57. qs=`echo "$option" | sed -e 's/--qemu-opts=//'`
  58. qemuopts="$qemuopts $qs" ;;
  59. -*)
  60. echo "Unrecognized option \`$option'" 1>&2
  61. usage
  62. exit 1
  63. ;;
  64. *)
  65. if [ "x${source}" != x ] ; then
  66. echo "too many parameters at the end" 1>&2
  67. usage
  68. exit 1
  69. fi
  70. source="${option}" ;;
  71. esac
  72. done
  73. if [ "x${source}" = x ] ; then
  74. tmpfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
  75. while read REPLY; do
  76. echo $REPLY >> "${tmpfile}"
  77. done
  78. source="${tmpfile}"
  79. fi
  80. outfile1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
  81. "@builddir@/grub-shell" --qemu-opts="${qemuopts}" --modules=${modules} "${source}" >"${outfile1}"
  82. outfile2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
  83. bash "${source}" >"${outfile2}"
  84. if ! diff -q "${outfile1}" "${outfile2}" >/dev/null
  85. then
  86. echo "${source}: GRUB and BASH outputs did not match (see diff -u ${outfile1} ${outfile2})"
  87. status=1
  88. else
  89. rm -f "${outfile1}" "${outfile2}"
  90. fi
  91. exit $status