--- trunk/mkinitrd-magellan/grubby/test.sh 2007/09/01 22:45:15 532 +++ trunk/mkinitrd-magellan/grubby/test.sh 2011/05/27 17:35:32 1308 @@ -1,132 +1,167 @@ #!/bin/bash +# +# test.sh -- grubby regression tests +# +# Copyright 2007-2008 Red Hat, Inc. All rights reserved. +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program. If not, see . +# + +if [ -n "$TOPDIR" ]; then + LD_LIBRARY_PATH="$TOPDIR/nash:$TOPDIR/bdevid:/usr/lib:/lib" + export LD_LIBRARY_PATH +fi -ARCH=$(uname -m) - -elilotest="" -lilotest="" -grubtest="" -zipltest="" -yaboottest="" - -case "$ARCH" in - i?86) - lilotest="yes" - grubtest="yes" - ;; - x86_64) - lilotest="yes" - grubtest="yes" - ;; - ppc*) - yaboottest="yes" - ;; - s390*) - zipltest="yes" - ;; - *) - echo "Not running any tests for $ARCH" - exit 0 -esac - -export MALLOC_CHECK_=2 - -RESULT=0 - -oneTest () { - mode=$1 - cfg=test/$2 - correct=test/results/$3 - shift; shift; shift - ./grubby $mode --bad-image-okay -c $cfg -o - "$@" | cmp $correct > /dev/null - - if [ $? != 0 ]; then +#---------------------------------------------------------------------- +# Global vars +#---------------------------------------------------------------------- + +cmd=${0##*/} +opt_bootloader=* +opt_verbose=false +read -d '' usage < /dev/null; then + (( pass++ )) + if $opt_verbose; then + echo ------------------------------------------------------------- + echo -n "PASS: " + printf "%q " "${runme[@]}"; echo + "${runme[@]}" | diff -U30 "$cfg" - + echo + fi + else + (( fail++ )) echo ------------------------------------------------------------- - echo FAILURE: $cfg $correct "$@" - echo -n ./grubby $mode --bad-image-okay -c $cfg -o - - for arg in "$@"; do - echo -n " \"$arg\"" - done - echo "" - ./grubby $mode --bad-image-okay -c $cfg -o - "$@" | diff -u $correct -; - RESULT=1 + echo -n "FAIL: " + printf "%q " "${runme[@]}"; echo + "${runme[@]}" | diff -U30 "$correct" - + echo fi } -liloTest() { - if [ -z "$lilotest" ]; then echo "skipping LILO test" ; return; fi - oneTest --lilo "$@" -} - -eliloTest() { - if [ -z "$elilotest" ]; then echo "skipping ELILO test" ; return; fi - oneTest --elilo "$@" -} - -grubTest() { - if [ -z "$grubtest" ]; then echo "skipping GRUB test" ; return; fi - oneTest --grub "$@" -} +# generate convenience functions +for b in $(./grubby --help | \ + sed -n 's/^.*--\([^ ]*\) *configure \1 bootloader$/\1/p'); do + eval "${b}Test() { [[ \"$b\" == \$opt_bootloader ]] && oneTest --$b \"\$@\"; }" +done -yabootTest() { - if [ -z "$yaboottest" ]; then echo "skipping YABOOT test" ; return; fi - oneTest --yaboot "$@" -} +#---------------------------------------------------------------------- +# Main +#---------------------------------------------------------------------- + +# Use /usr/bin/getopt which supports GNU-style long options +args=$(getopt -o b:hv --long bootloader,help,verbose -n "$cmd" -- "$@") || exit +eval set -- "$args" +while true; do + case $1 in + -b|--bootloader) opt_bootloader=$2; shift 2 ;; + -h|--help) echo "$usage"; exit 0 ;; + -v|--verbose) opt_verbose=true; shift ;; + --) shift; break ;; + *) echo "failed to process cmdline args" >&2; exit 1 ;; + esac +done -ziplTest() { - if [ -z "$zipltest" ]; then echo "skipping Z/IPL test" ; return; fi - oneTest --zipl "$@" -} +export MALLOC_CHECK_=2 -echo "Parse/write comparison..." -for n in $(cd test; echo grub.[0-9]*); do - grubTest $n ../$n --remove-kernel 1234 +testing="Parse/write comparison" +for n in test/*.[0-9]*; do + n=${n#*/} # remove test/ + b=${n%.*} # remove suffix + [[ $b == $opt_bootloader ]] || continue + ${b}Test $n ../$n --remove-kernel 1234 done -for n in $(cd test; echo lilo.[0-9]*); do - liloTest $n ../$n --remove-kernel 1234 +testing="Permission preservation" +unset b +for n in test/*.[0-9]*; do + n=${n#*/} # remove test/ + [[ ${n%.*} == "$b" ]] && continue + b=${n%.*} # remove suffix + [[ $b == $opt_bootloader ]] || continue + + echo "$testing ... --$b" + + cp test/$n ${b}-test + chmod 0614 ${b}-test + touch -t 200301010101.00 ${b}-test + time=$(ls -l ${b}-test | awk '{ print $6 " " $7 " "$8}') + perm=$(ls -l ${b}-test | awk '{print $1}') + ./grubby --${b} --add-kernel bar --title title -c ${b}-test + if [[ $? != 0 ]]; then + echo " FAIL (grubby returned non-zero)" + (( fail++ )) + elif newtime=$(ls -l ${b}-test | awk '{ print $6 " " $7 " "$8}') && \ + newperm=$(ls -l ${b}-test | awk '{print $1}') && \ + [[ $time == "$newtime" || $perm != "$newperm" ]] + then + echo " FAIL ($perm $newperm)"; + (( fail++ )) + else + (( pass++ )) + fi + rm -f ${b}-test done -echo "Permission preservation..." -cp test/grub.1 grub-test -chmod 0614 grub-test -touch -t 200301010101.00 grub-test -time=$(ls -l grub-test | awk '{ print $6 " " $7 " "$8}') -perm=$(ls -l grub-test | awk '{print $1}') -./grubby --grub --add-kernel bar --title title -c grub-test -newtime=$(ls -l grub-test | awk '{ print $6 " " $7 " "$8}') -newperm=$(ls -l grub-test | awk '{print $1}') -if [ "$time" == "$newtime" -o "$perm" != "$newperm" ]; then - echo " failed ($perm $newperm)"; -fi -rm -f grub-test - -cp test/lilo.1 lilo-test -chmod 0614 lilo-test -touch -t 200301010101.00 lilo-test -time=$(ls -l lilo-test | awk '{ print $6 " " $7 " "$8}') -perm=$(ls -l lilo-test | awk '{print $1}') -./grubby --lilo --add-kernel bar --title title -c lilo-test -newtime=$(ls -l lilo-test | awk '{ print $6 " " $7 " "$8}') -newperm=$(ls -l lilo-test | awk '{print $1}') -if [ "$time" == "$newtime" -o "$perm" != "$newperm" ]; then - echo " failed ($perm $newperm)"; -fi -rm -f lilo-test - -echo "Following symlinks..." -cp test/grub.1 grub-test -ln -s grub-test mytest -./grubby --grub --add-kernel bar --title title -c mytest -if [ ! -L mytest ]; then - echo " failed (not a symlink)" -fi -target=$(ls -l mytest | awk '{ print $11 }') -if [ "$target" != grub-test ]; then - echo " failed (wrong target)" -fi -rm -f grub-test mytest +testing="Following symlinks" +unset b +for n in test/*.[0-9]*; do + n=${n#*/} # remove test/ + [[ ${n%.*} == "$b" ]] && continue + b=${n%.*} # remove suffix + [[ $b == $opt_bootloader ]] || continue + + echo "$testing ... --$b" + + cp test/${b}.1 ${b}-test + ln -s ./${b}-test mytest + ./grubby --${b} --add-kernel bar --title title -c mytest + if [[ $? != 0 ]]; then + echo " failed (grubby returned non-zero)" + (( fail++ )) + elif [[ ! -L mytest ]]; then + echo " failed (not a symlink)" + (( fail++ )) + elif target=$(readlink mytest) && [[ $target != "./${b}-test" ]]; then + echo " failed (wrong target)" + (( fail++ )) + else + (( pass++ )) + fi + rm -f ${b}-test mytest +done -echo "GRUB default directive..." +testing="GRUB default directive" grubTest grub.1 default/g1.1 --boot-filesystem=/boot --add-kernel /boot/new-kernel --title Some_Title grubTest grub.1 default/g1.2 --boot-filesystem=/boot --add-kernel /boot/new-kernel --title Some_Title --make-default grubTest grub.3 default/g3.1 --boot-filesystem=/boot --set-default=/boot/vmlinuz-2.4.7-2 @@ -135,7 +170,7 @@ grubTest grub.4 default/g4.2 --boot-filesystem=/ --set-default=/boot/vmlinuz-2.4.7-ac3 --remove-kernel /boot/vmlinuz-2.4.7-2.5 --add-kernel=/boot/new-kernel --copy-default --title New_Title grubTest grub.6 default/g6.1 --remove-kernel=/boot/vmlinuz-2.4.7-2.9 --boot-filesystem=/ -echo "LILO default directive..." +testing="LILO default directive" liloTest lilo.1 default/l1.1 --set-default=/boot/vmlinuz-2.4.18-4 liloTest lilo.1 default/l1.2 --remove-kernel=/boot/vmlinuz-2.4.18-4smp liloTest lilo.1 default/l1.3 --add-kernel /boot/kernel --title label \ @@ -143,11 +178,11 @@ liloTest lilo.1 default/l1.4 --add-kernel /boot/kernel --title label \ --copy-default --make-default -echo "Z/IPL default directive..." +testing="Z/IPL default directive" ziplTest zipl.1 default/z1.1 --add-kernel /boot/new-kernel --title test ziplTest zipl.1 default/z1.2 --add-kernel /boot/new-kernel --title test --make-default -echo "GRUB fallback directive..." +testing="GRUB fallback directive" grubTest grub.5 fallback/g5.1 --remove-kernel=/boot/vmlinuz-2.4.7-ac3 \ --boot-filesystem=/ grubTest grub.5 fallback/g5.2 --remove-kernel=/boot/vmlinuz-2.4.7-2.5 \ @@ -156,13 +191,13 @@ --boot-filesystem=/ --copy-default --add-kernel=/boot/new-kernel \ --title="Some_Title" -echo "GRUB new kernel argument handling..." +testing="GRUB new kernel argument handling" grubTest grub.1 args/g1.1 --boot-filesystem=/boot \ --add-kernel=/boot/foo --title=some_title --args="1234" --copy-default grubTest grub.1 args/g1.2 --boot-filesystem=/boot \ --add-kernel=/boot/foo --title=some_title --args="1234" -echo "GRUB remove kernel..." +testing="GRUB remove kernel" grubTest grub.7 remove/g7.1 --boot-filesystem=/ \ --remove-kernel=/boot/vmlinuz-2.4.7-2.5 grubTest grub.3 remove/g3.1 --boot-filesystem=/ \ @@ -170,16 +205,16 @@ grubTest grub.9 remove/g9.1 --boot-filesystem=/boot \ --remove-kernel=/boot/vmlinuz-2.4.7-2 -echo "YABOOT remove kernel..." +testing="YABOOT remove kernel" yabootTest yaboot.1 remove/y1.1 --boot-filesystem=/ --remove-kernel=DEFAULT yabootTest yaboot.1 remove/y1.2 --boot-filesystem=/ --remove-kernel=/boot/vmlinuz-2.5.50-eepro yabootTest yaboot.2 remove/y2.1 --boot-filesystem=/ --remove-kernel=/boot/vmlinux-2.5.50 -echo "Z/IPL remove kernel..." +testing="Z/IPL remove kernel" ziplTest zipl.1 remove/z1.1 --remove-kernel=/boot/vmlinuz-2.4.9-38 ziplTest zipl.1 remove/z1.2 --remove-kernel=DEFAULT -echo "GRUB update kernel argument handling..." +testing="GRUB update kernel argument handling" grubTest grub.1 updargs/g1.1 --update-kernel=DEFAULT --args="root=/dev/hda1" grubTest grub.1 updargs/g1.2 --update-kernel=DEFAULT \ --args="root=/dev/hda1 hda=ide-scsi root=/dev/hda2" @@ -202,6 +237,8 @@ grubTest grub.7 updargs/g7.4 --boot-filesystem=/ \ --update-kernel=/vmlinuz-2.4.7-2 \ --args "ro root=LABEL=/ console=tty0 console=ttyS1,9600n81 single" +grubTest grub.7 updargs/g7.5 --boot-filesystem=/ \ + --update-kernel=ALL --args "root=/dev/hda2" grubTest grub.11 updargs/g11.1 --boot-filesystem=/ \ --update-kernel=/vmlinuz-2.4.7-2smp \ --args "ro root=LABEL=/ console=tty0 console=ttyS1,9600n81 single" @@ -209,7 +246,7 @@ --update-kernel=/vmlinuz-2.4.7-2smp \ --args "ro root=LABEL=/ single" -echo "LILO update kernel argument handling..." +testing="LILO update kernel argument handling" liloTest lilo.1 updargs/l1.1 --update-kernel=/boot/vmlinuz-2.4.18-4 \ --args="root=/dev/md1" liloTest lilo.1 updargs/l1.2 --update-kernel=/boot/vmlinuz-2.4.18-4smp \ @@ -223,7 +260,7 @@ liloTest lilo.3 updargs/l3.2 --update-kernel=ALL \ --remove-args="single" --args "root=/dev/hda2" -echo "LILO add kernel..." +testing="LILO add kernel" liloTest lilo.4 add/l4.1 --add-kernel=/boot/new-kernel.img --title="title" \ --copy-default --boot-filesystem=/boot liloTest lilo.4 add/l4.2 --add-kernel=/boot/new-kernel.img --title="linux" \ @@ -238,7 +275,7 @@ --initrd=/boot/new-initrd --copy-default --boot-filesystem=/boot --remove-kernel "TITLE=linux" -echo "GRUB add kernel..." +testing="GRUB add kernel" grubTest grub.1 add/g1.1 --add-kernel=/boot/new-kernel.img --title='title' \ --initrd=/boot/new-initrd --boot-filesystem=/ grubTest grub.1 add/g1.2 --add-kernel=/boot/new-kernel.img --title='title' \ @@ -247,6 +284,10 @@ --initrd=/boot/new-initrd --boot-filesystem=/ --copy-default grubTest grub.1 add/g1.4 --add-kernel=/boot/new-kernel.img --title='title' \ --initrd=/boot/new-initrd --boot-filesystem=/boot --copy-default +grubTest grub.1 add/g1.5 --add-kernel=/boot/new-kernel.img --title='title' \ + --initrd=/boot/new-initrd --extra-initrd=/boot/extra-initrd --boot-filesystem=/ +grubTest grub.1 add/g1.6 --add-kernel=/boot/new-kernel.img --title='title' \ + --initrd=/boot/new-initrd --extra-initrd=/boot/extra-initrd --boot-filesystem=/boot grubTest grub.2 add/g2.1 --add-kernel=/boot/vmlinuz-2.4.7-2 \ --initrd=/boot/initrd-2.4.7-new.img --boot-filesystem=/boot --copy-default \ --title="Red Hat Linux (2.4.7-2)" \ @@ -260,19 +301,19 @@ --initrd=/boot/new-initrd --boot-filesystem=/boot --copy-default \ --args='console=tty0 console=ttyS1,9600n81 single' -echo "YABOOT add kernel..." +testing="YABOOT add kernel" yabootTest yaboot.1 add/y1.1 --copy-default --boot-filesystem=/ --add-kernel=/boot/new-kernel \ --title=newtitle yabootTest yaboot.1 add/y1.2 --add-kernel=/boot/new-kernel --boot-filesystem=/ --title=newtitle -echo "YABOOT empty label..." +testing="YABOOT empty label" yabootTest yaboot.3 add/y3.1 --add-kernel=/boot/new-kernel --boot-filesystem=/ --title=newtitle -echo "Z/IPL add kernel..." +testing="Z/IPL add kernel" ziplTest zipl.1 add/z1.1 --add-kernel=/boot/new-kernel.img --title test ziplTest zipl.1 add/z1.2 --add-kernel=/boot/new-kernel.img --title test --copy-default -echo "LILO long titles..." +testing="LILO long titles" liloTest lilo.1 longtitle/l1.1 --add-kernel=/boot/new-kernel.img \ --title="linux-longtitle" --copy-default --boot-filesystem=/boot liloTest lilo.1 longtitle/l1.2 --add-kernel=/boot/new-kernel.img \ @@ -280,11 +321,11 @@ liloTest lilo.7 longtitle/l7.1 --add-kernel=/boot/new-kernel.img \ --title="linux-longtitle-fix" --copy-default --boot-filesystem=/boot -echo "ELILO long titles..." +testing="ELILO long titles" eliloTest lilo.7 longtitle/e7.1 --add-kernel=/boot/new-kernel.img \ --title="linux-longtitle-fix" --copy-default --boot-filesystem=/boot -echo "GRUB add multiboot..." +testing="GRUB add multiboot" grubTest grub.1 multiboot/g1.1 --add-multiboot=/boot/xen.gz \ --add-kernel=/boot/vmlinuz-2.6.10-1.1088_FC4 --boot-filesystem=/boot \ --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \ @@ -308,7 +349,7 @@ --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \ --boot-filesystem=/boot -echo "GRUB remove multiboot..." +testing="GRUB remove multiboot" grubTest grub.10 multiboot/g10.5 --boot-filesystem=/boot \ --remove-kernel=/boot/vmlinuz-2.6.10-1.1076_FC4 grubTest grub.10 multiboot/g10.6 --boot-filesystem=/boot \ @@ -316,4 +357,26 @@ grubTest grub.10 multiboot/g10.7 --boot-filesystem=/boot \ --remove-multiboot=/boot/xen.gz -exit $RESULT +testing="ELILO add multiboot" +eliloTest elilo.1 multiboot/e1.1 --add-multiboot=/boot/xen.gz \ + --add-kernel=/boot/vmlinuz-2.6.10-1.1088_FC4 --boot-filesystem=/boot \ + --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \ + --mbargs="dom0_mem=130000" +eliloTest elilo.1 multiboot/e1.2 --add-multiboot=/boot/xen.gz \ + --add-kernel=/boot/vmlinuz-2.6.10-1.1088_FC4 --boot-filesystem=/boot \ + --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \ + --mbargs="dom0_mem=130000" --copy-default + +testing="ELILO remove multiboot" +eliloTest elilo.2 multiboot/e2.1 --boot-filesystem=/boot \ + --remove-kernel=/boot/vmlinuz-2.6.10-1.1076_FC4 +eliloTest elilo.2 multiboot/e2.2 --boot-filesystem=/boot \ + --remove-kernel=/boot/vmlinuz-2.6.10-1.1082_FC4 +eliloTest elilo.2 multiboot/e2.3 --boot-filesystem=/boot \ + --remove-multiboot=/boot/xen.gz + +printf "\n%d (%d%%) tests passed, %d (%d%%) tests failed\n" \ + $pass $(((100*pass)/(pass+fail))) \ + $fail $(((100*fail)/(pass+fail))) + +exit $(( !!fail ))