diff options
Diffstat (limited to 'test/parser')
-rw-r--r-- | test/parser/Makefile.am | 15 | ||||
-rw-r--r-- | test/parser/data/grub2-rhcos-ootpa.conf | 194 | ||||
-rw-r--r-- | test/parser/data/grub2-rhel8.conf | 190 | ||||
-rw-r--r-- | test/parser/test-grub2-default-id-space.c | 34 | ||||
-rw-r--r-- | test/parser/test-grub2-default-id.c | 34 | ||||
-rw-r--r-- | test/parser/test-grub2-default-multiword.c | 4 | ||||
-rw-r--r-- | test/parser/test-grub2-devpath-scripting.c | 56 | ||||
-rw-r--r-- | test/parser/test-grub2-devpath.c | 88 | ||||
-rw-r--r-- | test/parser/test-grub2-rhcos-ootpa.c | 38 | ||||
-rw-r--r-- | test/parser/test-grub2-rhel8.c | 21 | ||||
-rw-r--r-- | test/parser/test-grub2-search-args.c | 35 | ||||
-rw-r--r-- | test/parser/test-grub2-search-label.c | 47 | ||||
-rw-r--r-- | test/parser/test-grub2-search-uuid.c | 55 | ||||
-rw-r--r-- | test/parser/test-grub2-source-functions.c | 46 | ||||
-rw-r--r-- | test/parser/test-grub2-source-recursion-infinite.c | 43 | ||||
-rw-r--r-- | test/parser/test-grub2-source-recursion.c | 58 | ||||
-rw-r--r-- | test/parser/test-grub2-source.c | 54 |
17 files changed, 1010 insertions, 2 deletions
diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index f9083bd..866e9d4 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -19,6 +19,8 @@ parser_TESTS = \ test/parser/test-grub2-noeol \ test/parser/test-grub2-menuentry-formats \ test/parser/test-grub2-if-formats \ + test/parser/test-grub2-default-id \ + test/parser/test-grub2-default-id-space \ test/parser/test-grub2-default-index \ test/parser/test-grub2-default-multiword \ test/parser/test-grub2-implicit-default-unset \ @@ -27,6 +29,11 @@ parser_TESTS = \ test/parser/test-grub2-multiple-id \ test/parser/test-grub2-single-line-if \ test/parser/test-grub2-pos-param \ + test/parser/test-grub2-search-args \ + test/parser/test-grub2-search-uuid \ + test/parser/test-grub2-search-label \ + test/parser/test-grub2-devpath \ + test/parser/test-grub2-devpath-scripting \ test/parser/test-grub2-load-env \ test/parser/test-grub2-save-env \ test/parser/test-grub2-save-env-dash-f \ @@ -36,9 +43,15 @@ parser_TESTS = \ test/parser/test-grub2-f20-ppc64 \ test/parser/test-grub2-ubuntu-13_04-x86 \ test/parser/test-grub2-sles-btrfs-snapshot \ + test/parser/test-grub2-rhel8 \ + test/parser/test-grub2-rhcos-ootpa \ test/parser/test-grub2-lexer-error \ test/parser/test-grub2-parser-error \ test/parser/test-grub2-test-file-ops \ + test/parser/test-grub2-source \ + test/parser/test-grub2-source-functions \ + test/parser/test-grub2-source-recursion \ + test/parser/test-grub2-source-recursion-infinite \ test/parser/test-grub2-single-yocto \ test/parser/test-grub2-blscfg-default-filename \ test/parser/test-grub2-blscfg-default-index \ @@ -102,6 +115,8 @@ check_DATA += \ test/parser/data/grub2-f18-ppc64.conf \ test/parser/data/grub2-f20-ppc.conf \ test/parser/data/grub2-ubuntu-13_04-x86.conf \ + test/parser/data/grub2-rhel8.conf \ + test/parser/data/grub2-rhcos-ootpa.conf \ test/parser/data/yaboot-rh8-ppc64.conf \ test/parser/data/syslinux-include-root.cfg \ test/parser/data/syslinux-include-nest-1.cfg \ diff --git a/test/parser/data/grub2-rhcos-ootpa.conf b/test/parser/data/grub2-rhcos-ootpa.conf new file mode 100644 index 0000000..329980e --- /dev/null +++ b/test/parser/data/grub2-rhcos-ootpa.conf @@ -0,0 +1,194 @@ +# +# 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 ### +set pager=1 + +if [ -f ${config_directory}/grubenv ]; then + load_env -f ${config_directory}/grubenv +elif [ -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 +} + +terminal_output ofconsole +if [ x$feature_timeout_style = xy ] ; then + set timeout_style=menu + set timeout=1 +# Fallback normal timeout code in case the timeout_style feature is +# unavailable. +else + set timeout=1 +fi +### END /etc/grub.d/00_header ### + +### BEGIN /etc/grub.d/01_menu_auto_hide ### +if [ "${boot_success}" = "1" -o "${boot_indeterminate}" = "1" ]; then + set last_boot_ok=1 +else + set last_boot_ok=0 +fi + +# Reset boot_indeterminate after a successful boot +if [ "${boot_success}" = "1" ] ; then + set boot_indeterminate=0 +# Avoid boot_indeterminate causing the menu to be hidden more then once +elif [ "${boot_indeterminate}" = "1" ]; then + set boot_indeterminate=2 +fi +set boot_success=0 +save_env boot_success boot_indeterminate + +if [ x$feature_timeout_style = xy ] ; then + if [ "${menu_show_once}" ]; then + unset menu_show_once + save_env menu_show_once + set timeout_style=menu + set timeout=60 + elif [ "${menu_auto_hide}" -a "${last_boot_ok}" = "1" ]; then + set orig_timeout_style=${timeout_style} + set orig_timeout=${timeout} + if [ "${fastboot}" = "1" ]; then + # timeout_style=menu + timeout=0 avoids the countdown code keypress check + set timeout_style=menu + set timeout=0 + else + set timeout_style=hidden + set timeout=1 + fi + fi +fi +### END /etc/grub.d/01_menu_auto_hide ### + +### BEGIN /etc/grub.d/01_users ### +if [ -f ${prefix}/user.cfg ]; then + source ${prefix}/user.cfg + if [ -n "${GRUB2_PASSWORD}" ]; then + set superusers="root" + export superusers + password_pbkdf2 root ${GRUB2_PASSWORD} + fi +fi +### END /etc/grub.d/01_users ### + +### BEGIN /etc/grub.d/02_ignition_firstboot ### +# We store the file on the /boot/ partition so find the +# boot partition. On UEFI this may different than the grub +# $root so we search for it here. +# https://github.com/coreos/ignition-dracut/issues/51 +search --set=bootpart --label boot +# Determine if this is a first boot and set the variable +# to be used later on the kernel command line. +set ignition_firstboot="" +if [ -f "(${bootpart})/ignition.firstboot" ]; then + # default to dhcp networking parameters to be used with ignition + set ignition_network_kcmdline='rd.neednet=1 ip=dhcp' + + # source in the `ignition.firstboot` file which could override the + # above $ignition_network_kcmdline with static networking config. + # This override feature is primarily used by coreos-installer to + # persist static networking config provided during install to the + # first boot of the machine. + source "(${bootpart})/ignition.firstboot" + + # we support setting variables in the + set ignition_firstboot="ignition.firstboot $ignition_network_kcmdline $ignition_extra_kcmdline" +fi +### END /etc/grub.d/02_ignition_firstboot ### + +### BEGIN /etc/grub.d/10_linux_bls ### + +### END /etc/grub.d/10_linux_bls ### + +### BEGIN /etc/grub.d/15_ostree ### +menuentry 'Red Hat Enterprise Linux CoreOS 42.80.20191030.0 (Ootpa) (ostree)' --class gnu-linux --class gnu --class os --unrestricted 'ostree-0-645e1535-a6f3-4fa6-a82c-b8c032619a7b' { +load_video +set gfxpayload=keep +insmod gzio +insmod part_gpt +insmod ext2 +set root='hd0,gpt2' +if [ x$feature_platform_search_hint = xy ]; then + search --no-floppy --fs-uuid --set=root --hint='hd0,gpt2' 645e1535-a6f3-4fa6-a82c-b8c032619a7b +else + search --no-floppy --fs-uuid --set=root 645e1535-a6f3-4fa6-a82c-b8c032619a7b +fi +linux /ostree/rhcos-6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/vmlinuz-4.18.0-80.11.2.el8_0.ppc64le console=tty0 console=hvc0,115200n8 rootflags=defaults,prjquota rw $ignition_firstboot root=UUID=8d8a5c3b-97e6-4d7b-bb87-206af5a9d851 ostree=/ostree/boot.0/rhcos/6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/0 ignition.platform.id=openstack +initrd /ostree/rhcos-6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/initramfs-4.18.0-80.11.2.el8_0.ppc64le.img +} +### END /etc/grub.d/15_ostree ### + +### BEGIN /etc/grub.d/20_linux_xen ### +### END /etc/grub.d/20_linux_xen ### + +### BEGIN /etc/grub.d/20_ppc_terminfo ### + terminfo -g 80x24 ofconsole +### 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/30_uefi-firmware ### +### END /etc/grub.d/30_uefi-firmware ### + +### 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/parser/data/grub2-rhel8.conf b/test/parser/data/grub2-rhel8.conf new file mode 100644 index 0000000..563b3e5 --- /dev/null +++ b/test/parser/data/grub2-rhel8.conf @@ -0,0 +1,190 @@ +# +# 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 ### +set pager=1 + +if [ -f ${config_directory}/grubenv ]; then + load_env -f ${config_directory}/grubenv +elif [ -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 +} + +terminal_output ofconsole +if [ x$feature_timeout_style = xy ] ; then + set timeout_style=menu + set timeout=5 +# Fallback normal timeout code in case the timeout_style feature is +# unavailable. +else + set timeout=5 +fi +### END /etc/grub.d/00_header ### + +### BEGIN /etc/grub.d/00_tuned ### +set tuned_params="" +set tuned_initrd="" +### END /etc/grub.d/00_tuned ### + +### BEGIN /etc/grub.d/01_menu_auto_hide ### +if [ "${boot_success}" = "1" -o "${boot_indeterminate}" = "1" ]; then + set last_boot_ok=1 +else + set last_boot_ok=0 +fi + +# Reset boot_indeterminate after a successful boot +if [ "${boot_success}" = "1" ] ; then + set boot_indeterminate=0 +# Avoid boot_indeterminate causing the menu to be hidden more then once +elif [ "${boot_indeterminate}" = "1" ]; then + set boot_indeterminate=2 +fi +set boot_success=0 +save_env boot_success boot_indeterminate + +if [ x$feature_timeout_style = xy ] ; then + if [ "${menu_show_once}" ]; then + unset menu_show_once + save_env menu_show_once + set timeout_style=menu + set timeout=60 + elif [ "${menu_auto_hide}" -a "${last_boot_ok}" = "1" ]; then + set orig_timeout_style=${timeout_style} + set orig_timeout=${timeout} + if [ "${fastboot}" = "1" ]; then + # timeout_style=menu + timeout=0 avoids the countdown code keypress check + set timeout_style=menu + set timeout=0 + else + set timeout_style=hidden + set timeout=1 + fi + fi +fi +### END /etc/grub.d/01_menu_auto_hide ### + +### BEGIN /etc/grub.d/01_users ### +if [ -f ${prefix}/user.cfg ]; then + source ${prefix}/user.cfg + if [ -n "${GRUB2_PASSWORD}" ]; then + set superusers="root" + export superusers + password_pbkdf2 root ${GRUB2_PASSWORD} + fi +fi +### END /etc/grub.d/01_users ### + +### BEGIN /etc/grub.d/10_linux_bls ### +insmod part_msdos +insmod xfs +set root='hd0,msdos2' +if [ x$feature_platform_search_hint = xy ]; then + search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//pciex@600c3c0100000/pci@0/pci@0/pci@9/raid@0/disk@8,msdos2' --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2 --hint='hd0,msdos2' 9a8ea027-4829-45b9-829b-18ed6cc1f33b +else + search --no-floppy --fs-uuid --set=root 9a8ea027-4829-45b9-829b-18ed6cc1f33b +fi +insmod part_msdos +insmod xfs +set boot='hd0,msdos2' +if [ x$feature_platform_search_hint = xy ]; then + search --no-floppy --fs-uuid --set=boot --hint-ieee1275='ieee1275//pciex@600c3c0100000/pci@0/pci@0/pci@9/raid@0/disk@8,msdos2' --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2 --hint='hd0,msdos2' 9a8ea027-4829-45b9-829b-18ed6cc1f33b +else + search --no-floppy --fs-uuid --set=boot 9a8ea027-4829-45b9-829b-18ed6cc1f33b +fi + +# This section was generated by a script. Do not modify the generated file - all changes +# will be lost the next time file is regenerated. Instead edit the BootLoaderSpec files. + +menuentry 'Red Hat Enterprise Linux (4.18.0-80.11.2.el8_0.ppc64le) 8.0 (Ootpa)' --class kernel --unrestricted --users $grub_users --id 8e15296c9cc14deb9e3f8548d49fd6fc-4.18.0-80.11.2.el8_0.ppc64le { + linux /vmlinuz-4.18.0-80.11.2.el8_0.ppc64le $kernelopts $tuned_params + initrd /initramfs-4.18.0-80.11.2.el8_0.ppc64le.img $tuned_initrd +} + +menuentry 'Red Hat Enterprise Linux (4.18.0-80.el8.ppc64le) 8.0 (Ootpa)' --class kernel --unrestricted --users $grub_users --id 8e15296c9cc14deb9e3f8548d49fd6fc-4.18.0-80.el8.ppc64le { + linux /vmlinuz-4.18.0-80.el8.ppc64le $kernelopts $tuned_params + initrd /initramfs-4.18.0-80.el8.ppc64le.img $tuned_initrd +} + +menuentry 'Red Hat Enterprise Linux (0-rescue-8e15296c9cc14deb9e3f8548d49fd6fc) 8.0 (Ootpa)' --class kernel --unrestricted --users $grub_users --id 8e15296c9cc14deb9e3f8548d49fd6fc-0-rescue { + linux /vmlinuz-0-rescue-8e15296c9cc14deb9e3f8548d49fd6fc $kernelopts + initrd /initramfs-0-rescue-8e15296c9cc14deb9e3f8548d49fd6fc.img +} + +### END /etc/grub.d/10_linux_bls ### + +### BEGIN /etc/grub.d/20_linux_xen ### +### END /etc/grub.d/20_linux_xen ### + +### BEGIN /etc/grub.d/20_ppc_terminfo ### + terminfo -g 80x24 ofconsole +### 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/30_uefi-firmware ### +### END /etc/grub.d/30_uefi-firmware ### + +### 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/parser/test-grub2-default-id-space.c b/test/parser/test-grub2-default-id-space.c new file mode 100644 index 0000000..df0eb2a --- /dev/null +++ b/test/parser/test-grub2-default-id-space.c @@ -0,0 +1,34 @@ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ +set default=option1 +menuentry 'test-option-0' --id option0 { + linux /vmlinux.0 +} +menuentry 'test-option-1' --id option1 { + linux /vmlinux.1 +} +menuentry 'test-option-2' --id option2 { + linux /vmlinux.2 +} +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + + test_read_conf_embedded(test, "/boot/grub2/grub.cfg"); + test_run_parser(test, "grub2"); + + ctx = test->ctx; + + check_boot_option_count(ctx, 3); + opt = get_boot_option(ctx, 1); + + check_name(opt, "test-option-1"); + check_resolved_local_resource(opt->boot_image, ctx->device, + "/vmlinux.1"); + check_is_default(opt); +} diff --git a/test/parser/test-grub2-default-id.c b/test/parser/test-grub2-default-id.c new file mode 100644 index 0000000..a41a4f9 --- /dev/null +++ b/test/parser/test-grub2-default-id.c @@ -0,0 +1,34 @@ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ +set default=option1 +menuentry 'test-option-0' --id=option0 { + linux /vmlinux.0 +} +menuentry 'test-option-1' --id=option1 { + linux /vmlinux.1 +} +menuentry 'test-option-2' --id=option2 { + linux /vmlinux.2 +} +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + + test_read_conf_embedded(test, "/boot/grub2/grub.cfg"); + test_run_parser(test, "grub2"); + + ctx = test->ctx; + + check_boot_option_count(ctx, 3); + opt = get_boot_option(ctx, 1); + + check_name(opt, "test-option-1"); + check_resolved_local_resource(opt->boot_image, ctx->device, + "/vmlinux.1"); + check_is_default(opt); +} diff --git a/test/parser/test-grub2-default-multiword.c b/test/parser/test-grub2-default-multiword.c index 25d1cf1..d455d62 100644 --- a/test/parser/test-grub2-default-multiword.c +++ b/test/parser/test-grub2-default-multiword.c @@ -3,10 +3,10 @@ #if 0 /* PARSER_EMBEDDED_CONFIG */ set default="Multiple word option" -menuentry 'Non-defalt option' { +menuentry 'Non-defalt option' --id=option0 { linux /vmlinux.non-default } -menuentry 'Multiple word option' { +menuentry 'Multiple word option' --id=option1 { linux /vmlinux } #endif diff --git a/test/parser/test-grub2-devpath-scripting.c b/test/parser/test-grub2-devpath-scripting.c new file mode 100644 index 0000000..9046ab6 --- /dev/null +++ b/test/parser/test-grub2-devpath-scripting.c @@ -0,0 +1,56 @@ +/* check grub2 device+path string parsing, as used in scripts */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +v= + +# local device, file present +if [ -f "/1-present" ]; then v=${v}a; fi + +# local device, file absent +if [ -f "/1-absent" ]; then v=${v}b; fi; + +# local device by UUID, file present +if [ -f "(00000000-0000-0000-0000-000000000001)/1-present" ]; then v=${v}c; fi; + +# remote device by UUID, file present +if [ -f "(00000000-0000-0000-0000-000000000002)/2-present" ]; then v=${v}d; fi; + +# non-existent device +if [ -f "(00000000-0000-0000-0000-000000000003)/present" ]; then v=${v}e; fi; + +menuentry $v { + linux /vmlinux +} + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_device *dev1, *dev2; + struct discover_boot_option *opt; + struct discover_context *ctx; + + ctx = test->ctx; + + /* set local uuid */ + dev1 = test->ctx->device; + dev1->uuid = "00000000-0000-0000-0000-000000000001"; + + dev2 = test_create_device(test, "extdev"); + dev2->uuid = "00000000-0000-0000-0000-000000000002"; + device_handler_add_device(ctx->handler, dev2); + + test_add_file_data(test, dev1, "/1-present", "x", 1); + test_add_file_data(test, dev2, "/2-present", "x", 1); + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 1); + opt = get_boot_option(ctx, 0); + check_name(opt, "acd"); +} diff --git a/test/parser/test-grub2-devpath.c b/test/parser/test-grub2-devpath.c new file mode 100644 index 0000000..d1d00f1 --- /dev/null +++ b/test/parser/test-grub2-devpath.c @@ -0,0 +1,88 @@ +/* check grub2 device+path string parsing */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +# local +menuentry a { + linux /vmlinux +} + +# local, specified by root env var +root=00000000-0000-0000-0000-000000000001 +menuentry b { + linux /vmlinux +} + +# remote, specified by root env var +root=00000000-0000-0000-0000-000000000002 +menuentry c { + linux /vmlinux +} + +# local, full dev+path spec +menuentry d { + linux (00000000-0000-0000-0000-000000000001)/vmlinux +} + +# remote, full dev+path spec +menuentry e { + linux (00000000-0000-0000-0000-000000000002)/vmlinux +} + +# invalid: incomplete dev+path spec +menuentry f { + linux (00000000-0000-0000-0000-000000000001 +} + +# invalid: no path +menuentry g { + linux (00000000-0000-0000-0000-000000000001) +} + + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_device *dev1, *dev2; + struct discover_boot_option *opt; + struct discover_context *ctx; + + ctx = test->ctx; + + /* set local uuid */ + dev1 = test->ctx->device; + dev1->uuid = "00000000-0000-0000-0000-000000000001"; + + dev2 = test_create_device(test, "extdev"); + dev2->uuid = "00000000-0000-0000-0000-000000000002"; + device_handler_add_device(ctx->handler, dev2); + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 5); + + opt = get_boot_option(ctx, 0); + check_name(opt, "a"); + check_resolved_local_resource(opt->boot_image, dev1, "/vmlinux"); + + opt = get_boot_option(ctx, 1); + check_name(opt, "b"); + check_resolved_local_resource(opt->boot_image, dev1, "/vmlinux"); + + opt = get_boot_option(ctx, 2); + check_name(opt, "c"); + check_resolved_local_resource(opt->boot_image, dev2, "/vmlinux"); + + opt = get_boot_option(ctx, 3); + check_name(opt, "d"); + check_resolved_local_resource(opt->boot_image, dev1, "/vmlinux"); + + opt = get_boot_option(ctx, 4); + check_name(opt, "e"); + check_resolved_local_resource(opt->boot_image, dev2, "/vmlinux"); +} diff --git a/test/parser/test-grub2-rhcos-ootpa.c b/test/parser/test-grub2-rhcos-ootpa.c new file mode 100644 index 0000000..19299be --- /dev/null +++ b/test/parser/test-grub2-rhcos-ootpa.c @@ -0,0 +1,38 @@ + +#include "parser-test.h" + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + + dev = test_create_device(test, "bootdev"); + dev->label = "boot"; + device_handler_add_device(test->handler, dev); + + test_read_conf_file(test, "grub2-rhcos-ootpa.conf", + "/grub/grub.cfg"); + + /* add the ignition.firstboot file on the boot-labelled partition, + * to check that we can source this correctly */ + test_add_file_string(test, dev, + "/ignition.firstboot", + "ignition_extra_kcmdline=meep\n"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 1); + + opt = get_boot_option(ctx, 0); + check_name(opt, + "Red Hat Enterprise Linux CoreOS 42.80.20191030.0 (Ootpa) (ostree)"); + check_args(opt, "console=tty0 console=hvc0,115200n8 " + "rootflags=defaults,prjquota rw " + "ignition.firstboot rd.neednet=1 ip=dhcp meep " + "root=UUID=8d8a5c3b-97e6-4d7b-bb87-206af5a9d851 " + "ostree=/ostree/boot.0/rhcos/6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/0 " + "ignition.platform.id=openstack"); +} diff --git a/test/parser/test-grub2-rhel8.c b/test/parser/test-grub2-rhel8.c new file mode 100644 index 0000000..3e208bc --- /dev/null +++ b/test/parser/test-grub2-rhel8.c @@ -0,0 +1,21 @@ + +#include "parser-test.h" + +void run_test(struct parser_test *test) +{ + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + + dev = test_create_device(test, "boot"); + dev->uuid = "9a8ea027-4829-45b9-829b-18ed6cc1f33b"; + device_handler_add_device(test->handler, dev); + + test_read_conf_file(test, "grub2-rhel8.conf", + "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 3); +} diff --git a/test/parser/test-grub2-search-args.c b/test/parser/test-grub2-search-args.c new file mode 100644 index 0000000..0eb5762 --- /dev/null +++ b/test/parser/test-grub2-search-args.c @@ -0,0 +1,35 @@ + +/* check for multiple styles of option parsing for the 'search' command */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +# no --set arugment will set the 'root' var +search a +search --set=v1 b +search --set v2 c +search --set=v3 --no-floppy d +search --no-floppy --set=v4 e + +menuentry $root$v1$v2$v3$v4 { + linux /vmlinux +} + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + + ctx = test->ctx; + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 1); + opt = get_boot_option(ctx, 0); + check_name(opt, "abcde"); +} diff --git a/test/parser/test-grub2-search-label.c b/test/parser/test-grub2-search-label.c new file mode 100644 index 0000000..b9ee034 --- /dev/null +++ b/test/parser/test-grub2-search-label.c @@ -0,0 +1,47 @@ +/* check for grub2 search command, searching by partition label */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +# valid label +search --set=v1 --label testlabel + +v2=prev +# invalid label: does not alter v2 +search --set=v2 --label invalidlabel + +menuentry $v1 { + linux /vmlinux +} + +menuentry $v2 { + linux /vmlinux +} + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + + dev = test_create_device(test, "testdev"); + dev->label = "testlabel"; + device_handler_add_device(test->handler, dev); + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 2); + + opt = get_boot_option(ctx, 0); + check_name(opt, "testdev"); + + opt = get_boot_option(ctx, 1); + check_name(opt, "prev"); +} diff --git a/test/parser/test-grub2-search-uuid.c b/test/parser/test-grub2-search-uuid.c new file mode 100644 index 0000000..7eacd1d --- /dev/null +++ b/test/parser/test-grub2-search-uuid.c @@ -0,0 +1,55 @@ +/* check for grub2 search command, searching by FS UUID */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +# valid UUID +search --set=v1 --fs-uuid ee0cc6fa-1dba-48f2-8f5b-19e4b8de8c37 + +# invalid UUID: will fall back to passing the UUID through +search --set=v2 --fs-uuid 92b0da57-6e04-4e54-960b-85e6bb060433 + +# no 'type' argument defaults to UUID search +search --set=v3 ee0cc6fa-1dba-48f2-8f5b-19e4b8de8c37 + +menuentry $v1 { + linux /vmlinux +} + +menuentry $v2 { + linux /vmlinux +} + +menuentry $v3 { + linux /vmlinux +} +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + + dev = test_create_device(test, "testdev"); + dev->uuid = "ee0cc6fa-1dba-48f2-8f5b-19e4b8de8c37"; + device_handler_add_device(test->handler, dev); + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 3); + + opt = get_boot_option(ctx, 0); + check_name(opt, dev->device->id); + + opt = get_boot_option(ctx, 1); + check_name(opt, "92b0da57-6e04-4e54-960b-85e6bb060433"); + + opt = get_boot_option(ctx, 2); + check_name(opt, dev->device->id); +} diff --git a/test/parser/test-grub2-source-functions.c b/test/parser/test-grub2-source-functions.c new file mode 100644 index 0000000..a9da934 --- /dev/null +++ b/test/parser/test-grub2-source-functions.c @@ -0,0 +1,46 @@ + +/* check that we can source other scripts, and functions can be defined + * and called across sourced scripts */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +function f1 { + menuentry "f1$1" { linux $2 } +} + +source /grub/2.cfg + +f2 a /vmlinux + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + dev = ctx->device; + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_add_file_string(test, dev, + "/grub/2.cfg", + "function f2 { menuentry \"f2$1\" { linux $2 } }\n" + "f1 a /vmlinux\n"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 2); + + opt = get_boot_option(ctx, 0); + check_name(opt, "f1a"); + check_resolved_local_resource(opt->boot_image, dev, "/vmlinux"); + + opt = get_boot_option(ctx, 1); + check_name(opt, "f2a"); + check_resolved_local_resource(opt->boot_image, dev, "/vmlinux"); +} diff --git a/test/parser/test-grub2-source-recursion-infinite.c b/test/parser/test-grub2-source-recursion-infinite.c new file mode 100644 index 0000000..fbcc5a3 --- /dev/null +++ b/test/parser/test-grub2-source-recursion-infinite.c @@ -0,0 +1,43 @@ + +/* check that have a maximum source recursion limit */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +name=a$name + +menuentry $name { + linux /a +} + +source /grub/grub.cfg + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + dev = ctx->device; + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + /* we error out after 10 levels, but we should still have + * parse results up to that point + */ + check_boot_option_count(ctx, 11); + + opt = get_boot_option(ctx, 0); + check_name(opt, "a"); + check_resolved_local_resource(opt->boot_image, dev, "/a"); + + opt = get_boot_option(ctx,10); + check_name(opt, "aaaaaaaaaaa"); + check_resolved_local_resource(opt->boot_image, dev, "/a"); +} diff --git a/test/parser/test-grub2-source-recursion.c b/test/parser/test-grub2-source-recursion.c new file mode 100644 index 0000000..21b6bd2 --- /dev/null +++ b/test/parser/test-grub2-source-recursion.c @@ -0,0 +1,58 @@ +/* check that we can source other files recursively */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +menuentry a { + linux /a +} + +source /grub/2.cfg + +menuentry c { + linux /c +} + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + dev = ctx->device; + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + /* four levels of config files, the last defining a boot option */ + test_add_file_string(test, dev, + "/grub/2.cfg", + "source /grub/3.cfg\n"); + + test_add_file_string(test, dev, + "/grub/3.cfg", + "source /grub/4.cfg\n"); + + test_add_file_string(test, dev, + "/grub/4.cfg", + "menuentry b { linux /b }\n"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 3); + + opt = get_boot_option(ctx, 0); + check_name(opt, "a"); + check_resolved_local_resource(opt->boot_image, dev, "/a"); + + opt = get_boot_option(ctx, 1); + check_name(opt, "b"); + check_resolved_local_resource(opt->boot_image, dev, "/b"); + + opt = get_boot_option(ctx, 2); + check_name(opt, "c"); + check_resolved_local_resource(opt->boot_image, dev, "/c"); +} diff --git a/test/parser/test-grub2-source.c b/test/parser/test-grub2-source.c new file mode 100644 index 0000000..a14bef7 --- /dev/null +++ b/test/parser/test-grub2-source.c @@ -0,0 +1,54 @@ + +/* check that we can source other scripts, and variables get passed + * in to and out of sourced scripts */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +menuentry a { + linux /a +} + +# var: outer -> inner -> outer +v=b + +source /grub/2.cfg + +menuentry $v { + linux /c +} + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + dev = ctx->device; + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_add_file_string(test, dev, + "/grub/2.cfg", + "menuentry $v { linux /b }\nv=c\n"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 3); + + opt = get_boot_option(ctx, 0); + check_name(opt, "a"); + check_resolved_local_resource(opt->boot_image, dev, "/a"); + + opt = get_boot_option(ctx, 1); + check_name(opt, "b"); + check_resolved_local_resource(opt->boot_image, dev, "/b"); + + opt = get_boot_option(ctx, 2); + check_name(opt, "c"); + check_resolved_local_resource(opt->boot_image, dev, "/c"); +} |