From 9fc2ac627df17ddc8e7c2735053aeb9e1252ff6e Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Mon, 11 Nov 2019 17:10:30 +0800 Subject: discover/grub2: add support for grub2-style path specifiers in resources This change incorporates the grub2-style (device)/path specifiers in the grub2 parser's resource code. This allows the boot option paths to use device-specific references. Device names are looked-up using the UUID and kernel IDs, but with the lookup logic specific to a new function (grub2_lookup_device), so that can be extended in a future change. Signed-off-by: Jeremy Kerr --- test/parser/Makefile.am | 1 + test/parser/test-grub2-devpath.c | 88 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 test/parser/test-grub2-devpath.c (limited to 'test') diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index f5985d6..0378317 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -32,6 +32,7 @@ parser_TESTS = \ 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-load-env \ test/parser/test-grub2-save-env \ test/parser/test-grub2-save-env-dash-f \ 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"); +} -- cgit v1.2.1