From 0e5c50b8dff5208b915391e3b592790bdf174cf4 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 8 Jul 2014 14:37:21 -0400 Subject: [PATCH 02/10] Add bls test harness bits. This expects that there are bls config files and that grubby knows how to deal with them, which isn't at all true, and so the test case currently fails because test/grub2.15 doesn't provide any kernel stanzas whatsoever. Maybe I should add a dummy there, but... I'd rather leave this failing here. Signed-off-by: Peter Jones --- test.sh | 105 +++++++++++++++++++ ...724b7a981ebb5b8495b9ea-3.8.0-2.fc19.x86_64.conf | 8 ++ ...724b7a981ebb5b8495b9ea-3.8.1-2.fc19.x86_64.conf | 8 ++ ...981ebb5b8495b9ea-tboot-3.8.0-2.fc19.x86_64.conf | 10 ++ ...981ebb5b8495b9ea-tboot-3.8.1-2.fc19.x86_64.conf | 10 ++ test/grub2.15 | 112 +++++++++++++++++++++ test/results/grub2.15 | 112 +++++++++++++++++++++ 7 files changed, 365 insertions(+) create mode 100644 test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-3.8.0-2.fc19.x86_64.conf create mode 100644 test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-3.8.1-2.fc19.x86_64.conf create mode 100644 test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-tboot-3.8.0-2.fc19.x86_64.conf create mode 100644 test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-tboot-3.8.1-2.fc19.x86_64.conf create mode 100644 test/grub2.15 create mode 100644 test/results/grub2.15 diff --git a/test.sh b/test.sh index 864a8ce..e7be15f 100755 --- a/test.sh +++ b/test.sh @@ -163,6 +163,102 @@ for b in $(./grubby --help | \ eval "${b}DisplayTest() { [[ \"$b\" == \$opt_bootloader ]] && oneDisplayTest --$b \"\$@\"; }" done +grub2BlsTest() { + declare blsdir=$(mktemp -d) cmpdir=$(mktemp -d) + + declare blspairs="" + while [ -n "$1" ]; do + if [ "$1" == "--blspair" ]; then + blsin=$(echo $2 | sed 's/\(.*\),.*/\1/') + blsout=$(echo $2 | sed 's/[^,]*,\(.*\)/\1/') + [ -n "$blsin" ] && cp "test/grub2-support_files/$blsin" ${blsdir}/ + [ -n "$blsout" ] && cp "test/grub2-support_files/$blsout" ${cmpdir}/ + blspairs="${blspairs} $2" + shift 2 + else + break + fi + done + + typeset mode=$1 cfg=test/$2 correct=test/results/$3 + shift 3 + + local ENV_FILE="" + if [ "$mode" == "--grub2" ]; then + ENV_FILE="test/grub2-support_files/env_temp" + if [ "$1" == "--env" ]; then + cp "test/grub2-support_files/$2" "$ENV_FILE" + shift 2 + else + cp "test/grub2-support_files/grubenv.0" "$ENV_FILE" + fi + ENV_FILE="--env=$ENV_FILE" + fi + + declare outfile=$(mktemp) + echo "$testing ... $mode bls $cfg $correct" + runme=( ./grubby "$mode" --bad-image-okay $ENV_FILE -c "$cfg" -o - --blsdir="${blsdir}" "$@" ) + declare -i old_fail=$fail + if "${runme[@]}" 2>&1 | cmp "$correct" > /dev/null; then + (( pass++ )) + if $opt_verbose; then + echo ------------------------------------------------------------- + echo -n "PASS: " + printf "%q " "${runme[@]}"; echo + "${runme[@]}" 2>&1 | diff -U30 "$cfg" - + echo + fi + else + (( fail++ )) + echo ------------------------------------------------------------- + echo -n "FAIL: " + printf "%q " "${runme[@]}"; echo + "${runme[@]}" 2>&1 | diff -U30 "$correct" - + echo + fi + + for pair in ${blspairs} ; do + blsin=$(echo $pair | sed 's/\(.*\),.*/\1/') + blsout=$(echo $pair | sed 's/[^,]*,\(.*\)/\1/') + + if [ -z "${blsout}" -a -f ${blsdir}/${blsin} ]; then + (( fail++ )) + echo ------------------------------------------------------------- + echo -n "FAIL: " + printf "%q " "${runme[@]}"; echo + diff -U30 /dev/null ${blsdir}/${blsin} + elif [ -n "${blsout}" ] && ! cmp ${blsdir}/${blsout} ${cmpdir}/${blsout} >/dev/null ; then + (( fail++ )) + echo ------------------------------------------------------------- + echo -n "FAIL: " + printf "%q " "${runme[@]}"; echo + diff -U30 "${cmpdir}/${blsout}" "${blsdir}/${blsout}" + else + (( pass++ )) + if $opt_verbose; then + echo ------------------------------------------------------------- + echo -n "PASS: " + printf "%q " "${runme[@]}"; echo + diff -U30 "${cmpdir}/${blsout}" "${blsdir}/${blsout}" + fi + fi + done + + if [ $old_fail -eq $fail ]; then + (( pass++ )) + if $opt_verbose; then + echo ------------------------------------------------------------- + echo -n "PASS: " + printf "%q " "${runme[@]}"; echo + "${runme[@]}" 2>&1 | diff -U30 "$cfg" - + echo + fi + fi + + rm -rvf ${blsdir}/ ${cmpdir}/ +} + + #---------------------------------------------------------------------- # Main #---------------------------------------------------------------------- @@ -533,6 +629,15 @@ if [ "$testgrub2" == "y" ]; then grub2Test grub2.2 add/g2-1.4 --update-kernel=/boot/new-kernel.img \ --initrd=/boot/new-initrd --boot-filesystem=/boot/ + testing="GRUB2 add bls kernel+initrd" + grub2BlsTest \ + --blspair 6a9857a393724b7a981ebb5b8495b9ea-3.8.0-2.fc19.x86_64.conf,6a9857a393724b7a981ebb5b8495b9ea-3.8.0-2.fc19.x86_64.conf \ + --blspair ,6a9857a393724b7a981ebb5b8495b9ea-3.8.1-2.fc19.x86_64.conf \ + --grub2 grub2.15 grub2.15 \ + --add-kernel=/boot/new-kernel.img \ + --title=title --initrd=/boot/new-initrd --boot-filesystem=/boot/ \ + --copy-default + testing="GRUB2 display default index" grub2DisplayTest grub2.1 defaultindex/0 --default-index grub2DisplayTest grub2.2 defaultindex/0 --default-index diff --git a/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-3.8.0-2.fc19.x86_64.conf b/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-3.8.0-2.fc19.x86_64.conf new file mode 100644 index 0000000..84b2bdf --- /dev/null +++ b/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-3.8.0-2.fc19.x86_64.conf @@ -0,0 +1,8 @@ +# /boot/org/freedesktop/bls/entries/6a9857a393724b7a981ebb5b8495b9ea-3.8.0-2.fc19.x86_64.conf +title Fedora 19 (Rawhide) +version 3.8.0-2.fc19.x86_64 +machine-id 6a9857a393724b7a981ebb5b8495b9ea +filesystem 6d3376e4-fc93-4509-95ec-a21d68011da2 +linux /boot/vmlinux-3.8.0-2.fc19.x86_64 +options root=UUID=6d3376e4-fc93-4509-95ec-a21d68011da2 +initrd /boot/initrd-3.8.0-2.fc19.x86_64 diff --git a/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-3.8.1-2.fc19.x86_64.conf b/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-3.8.1-2.fc19.x86_64.conf new file mode 100644 index 0000000..e1c61a8 --- /dev/null +++ b/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-3.8.1-2.fc19.x86_64.conf @@ -0,0 +1,8 @@ +# /boot/org/freedesktop/bls/entries/6a9857a393724b7a981ebb5b8495b9ea-3.8.1-2.fc19.x86_64.conf +title Fedora 19 (Rawhide) +version 3.8.1-2.fc19.x86_64 +machine-id 6a9857a393724b7a981ebb5b8495b9ea +filesystem 6d3376e4-fc93-4509-95ec-a21d68011da2 +linux /boot/vmlinux-3.8.1-2.fc19.x86_64 +options root=UUID=6d3376e4-fc93-4509-95ec-a21d68011da2 +initrd /boot/initrd-3.8.1-2.fc19.x86_64 diff --git a/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-tboot-3.8.0-2.fc19.x86_64.conf b/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-tboot-3.8.0-2.fc19.x86_64.conf new file mode 100644 index 0000000..4a60fbc --- /dev/null +++ b/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-tboot-3.8.0-2.fc19.x86_64.conf @@ -0,0 +1,10 @@ +# /boot/org/freedesktop/bls/entries/6a9857a393724b7a981ebb5b8495b9ea-tboot-3.8.0-2.fc19.x86_64.conf +title Fedora 19 (tboot) (Rawhide) +version 3.8.0-2.fc19.x86_64 +machine-id 6a9857a393724b7a981ebb5b8495b9ea +filesystem 6d3376e4-fc93-4509-95ec-a21d68011da2 +multiboot /boot/tboot.gz + options logging=serial,vga,memory +linux /boot/vmlinux-3.8.0-2.fc19.x86_64 +options root=UUID=6d3376e4-fc93-4509-95ec-a21d68011da2 +initrd /boot/initrd-3.8.0-2.fc19.x86_64 diff --git a/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-tboot-3.8.1-2.fc19.x86_64.conf b/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-tboot-3.8.1-2.fc19.x86_64.conf new file mode 100644 index 0000000..34c0e09 --- /dev/null +++ b/test/grub2-support_files/6a9857a393724b7a981ebb5b8495b9ea-tboot-3.8.1-2.fc19.x86_64.conf @@ -0,0 +1,10 @@ +# /boot/org/freedesktop/bls/entries/6a9857a393724b7a981ebb5b8495b9ea-tboot-3.8.1-2.fc19.x86_64.conf +title Fedora 19 (tboot) (Rawhide) +version 3.8.1-2.fc19.x86_64 +machine-id 6a9857a393724b7a981ebb5b8495b9ea +filesystem 6d3376e4-fc93-4509-95ec-a21d68011da2 +multiboot /boot/tboot.gz + options logging=serial,vga,memory +linux /boot/vmlinux-3.8.1-2.fc19.x86_64 +options root=UUID=6d3376e4-fc93-4509-95ec-a21d68011da2 +initrd /boot/initrd-3.8.1-2.fc19.x86_64 diff --git a/test/grub2.15 b/test/grub2.15 new file mode 100644 index 0000000..0be2d74 --- /dev/null +++ b/test/grub2.15 @@ -0,0 +1,112 @@ +# +# DO NOT EDIT THIS FILE +# +# It is automatically generated by grub2-mkconfig using templates +# from /etc/grub.d and settings from /etc/default/grub +# + +### BEGIN /etc/grub.d/00_header ### +if [ -s $prefix/grubenv ]; then + load_env +fi +if [ "${next_entry}" ] ; then + set default="${next_entry}" + set next_entry= + save_env next_entry + set boot_once=true +else + set default="${saved_entry}" +fi + +if [ x"${feature_menuentry_id}" = xy ]; then + menuentry_id_option="--id" +else + menuentry_id_option="" +fi + +export menuentry_id_option + +if [ "${prev_saved_entry}" ]; then + set saved_entry="${prev_saved_entry}" + save_env saved_entry + set prev_saved_entry= + save_env prev_saved_entry + set boot_once=true +fi + +function savedefault { + if [ -z "${boot_once}" ]; then + saved_entry="${chosen}" + save_env saved_entry + fi +} + +function load_video { + if [ x$feature_all_video_module = xy ]; then + insmod all_video + else + insmod efi_gop + insmod efi_uga + insmod ieee1275_fb + insmod vbe + insmod vga + insmod video_bochs + insmod video_cirrus + fi +} + +if [ x$feature_default_font_path = xy ] ; then + font=unicode +else +insmod part_gpt +insmod btrfs +set root='hd0,gpt4' +if [ x$feature_platform_search_hint = xy ]; then + search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt4 --hint-efi=hd0,gpt4 --hint-baremetal=ahci0,gpt4 5a2ca487-30f7-4fa5-96bd-abe38b68ceb3 +else + search --no-floppy --fs-uuid --set=root 5a2ca487-30f7-4fa5-96bd-abe38b68ceb3 +fi + font="/root/usr/share/grub/unicode.pf2" +fi + +if loadfont $font ; then + set gfxmode=auto + load_video + insmod gfxterm + set locale_dir=$prefix/locale + set lang=en_US + insmod gettext +fi +terminal_output gfxterm +set timeout=5 +### END /etc/grub.d/00_header ### + +### BEGIN /etc/grub.d/10_blscfg ### + +bls_import + +### END /etc/grub.d/10_blscfg ### + +### BEGIN /etc/grub.d/20_linux_xen ### + +### END /etc/grub.d/20_linux_xen ### + +### BEGIN /etc/grub.d/20_ppc_terminfo ### +### END /etc/grub.d/20_ppc_terminfo ### + +### BEGIN /etc/grub.d/30_os-prober ### +### END /etc/grub.d/30_os-prober ### + +### BEGIN /etc/grub.d/40_custom ### +# This file provides an easy way to add custom menu entries. Simply type the +# menu entries you want to add after this comment. Be careful not to change +# the 'exec tail' line above. +### END /etc/grub.d/40_custom ### + +### BEGIN /etc/grub.d/41_custom ### +if [ -f ${config_directory}/custom.cfg ]; then + source ${config_directory}/custom.cfg +elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then + source $prefix/custom.cfg; +fi +### END /etc/grub.d/41_custom ### diff --git a/test/results/grub2.15 b/test/results/grub2.15 new file mode 100644 index 0000000..0be2d74 --- /dev/null +++ b/test/results/grub2.15 @@ -0,0 +1,112 @@ +# +# DO NOT EDIT THIS FILE +# +# It is automatically generated by grub2-mkconfig using templates +# from /etc/grub.d and settings from /etc/default/grub +# + +### BEGIN /etc/grub.d/00_header ### +if [ -s $prefix/grubenv ]; then + load_env +fi +if [ "${next_entry}" ] ; then + set default="${next_entry}" + set next_entry= + save_env next_entry + set boot_once=true +else + set default="${saved_entry}" +fi + +if [ x"${feature_menuentry_id}" = xy ]; then + menuentry_id_option="--id" +else + menuentry_id_option="" +fi + +export menuentry_id_option + +if [ "${prev_saved_entry}" ]; then + set saved_entry="${prev_saved_entry}" + save_env saved_entry + set prev_saved_entry= + save_env prev_saved_entry + set boot_once=true +fi + +function savedefault { + if [ -z "${boot_once}" ]; then + saved_entry="${chosen}" + save_env saved_entry + fi +} + +function load_video { + if [ x$feature_all_video_module = xy ]; then + insmod all_video + else + insmod efi_gop + insmod efi_uga + insmod ieee1275_fb + insmod vbe + insmod vga + insmod video_bochs + insmod video_cirrus + fi +} + +if [ x$feature_default_font_path = xy ] ; then + font=unicode +else +insmod part_gpt +insmod btrfs +set root='hd0,gpt4' +if [ x$feature_platform_search_hint = xy ]; then + search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt4 --hint-efi=hd0,gpt4 --hint-baremetal=ahci0,gpt4 5a2ca487-30f7-4fa5-96bd-abe38b68ceb3 +else + search --no-floppy --fs-uuid --set=root 5a2ca487-30f7-4fa5-96bd-abe38b68ceb3 +fi + font="/root/usr/share/grub/unicode.pf2" +fi + +if loadfont $font ; then + set gfxmode=auto + load_video + insmod gfxterm + set locale_dir=$prefix/locale + set lang=en_US + insmod gettext +fi +terminal_output gfxterm +set timeout=5 +### END /etc/grub.d/00_header ### + +### BEGIN /etc/grub.d/10_blscfg ### + +bls_import + +### END /etc/grub.d/10_blscfg ### + +### BEGIN /etc/grub.d/20_linux_xen ### + +### END /etc/grub.d/20_linux_xen ### + +### BEGIN /etc/grub.d/20_ppc_terminfo ### +### END /etc/grub.d/20_ppc_terminfo ### + +### BEGIN /etc/grub.d/30_os-prober ### +### END /etc/grub.d/30_os-prober ### + +### BEGIN /etc/grub.d/40_custom ### +# This file provides an easy way to add custom menu entries. Simply type the +# menu entries you want to add after this comment. Be careful not to change +# the 'exec tail' line above. +### END /etc/grub.d/40_custom ### + +### BEGIN /etc/grub.d/41_custom ### +if [ -f ${config_directory}/custom.cfg ]; then + source ${config_directory}/custom.cfg +elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then + source $prefix/custom.cfg; +fi +### END /etc/grub.d/41_custom ### -- 1.9.3