diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2019-11-11 19:30:41 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2019-11-29 13:54:10 +0800 |
commit | b22445748f44ed6965f31f45b39abb690d24ec47 (patch) | |
tree | cb9f942dac9ff19cc1786ea23f9f5a3509deec48 /test/parser | |
parent | 9fc2ac627df17ddc8e7c2735053aeb9e1252ff6e (diff) | |
download | talos-petitboot-b22445748f44ed6965f31f45b39abb690d24ec47.tar.gz talos-petitboot-b22445748f44ed6965f31f45b39abb690d24ec47.zip |
discover/grub2: Allow (device)/path references in general script usage
Currently, we have support for grub2 (device)/path syntax for boot
resources. This change allows this syntax for general paths in grub2
scripts (for example, -f tests).
This involves exposing grub2_lookup_device, to allow the script
execution code to resolve pathnames.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'test/parser')
-rw-r--r-- | test/parser/Makefile.am | 1 | ||||
-rw-r--r-- | test/parser/test-grub2-devpath-scripting.c | 56 |
2 files changed, 57 insertions, 0 deletions
diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index 0378317..c8e059b 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -33,6 +33,7 @@ parser_TESTS = \ 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 \ 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"); +} |