diff options
author | Alan Dunn <amdunn@google.com> | 2016-01-12 15:43:02 -0800 |
---|---|---|
committer | Sam Mendoza-Jonas <sam@mendozajonas.com> | 2016-02-08 15:27:41 +1100 |
commit | 01e104dfb79a09bc28f8c5fb65bfe44596c25161 (patch) | |
tree | 74d27b78669f4546537d105080bb20302dde6a2c /test | |
parent | b3d51f6ec5d077e6a2068fde0631074a7302b1da (diff) | |
download | petitboot-01e104dfb79a09bc28f8c5fb65bfe44596c25161.zip petitboot-01e104dfb79a09bc28f8c5fb65bfe44596c25161.tar.gz |
discover/grub2: Fix behavior of save_env -f
Currently, "save_env -f" in the GRUB2 parser only works with three
arguments, which means only commands of the form "save_env -f <path>"
that save *no* environment variables are allowed.
Allow "save_env -f <path> [<var>]*", making "save_env -f" useful.
Tested:
Unit test test-grub2-save-env-dash-f tests this change, and the
remaining unit tests still pass.
Signed-off-by: Alan Dunn <amdunn@google.com>
Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parser/Makefile.am | 1 | ||||
-rw-r--r-- | test/parser/test-grub2-save-env-dash-f.c | 37 |
2 files changed, 38 insertions, 0 deletions
diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index d69ca7f..dddb472 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -28,6 +28,7 @@ parser_TESTS = \ test/parser/test-grub2-single-line-if \ test/parser/test-grub2-load-env \ test/parser/test-grub2-save-env \ + test/parser/test-grub2-save-env-dash-f \ test/parser/test-grub2-saved-default \ test/parser/test-grub2-nondefault-prefix \ test/parser/test-grub2-f18-ppc64 \ diff --git a/test/parser/test-grub2-save-env-dash-f.c b/test/parser/test-grub2-save-env-dash-f.c new file mode 100644 index 0000000..7d48f67 --- /dev/null +++ b/test/parser/test-grub2-save-env-dash-f.c @@ -0,0 +1,37 @@ + +#include <string.h> + +#include <talloc/talloc.h> + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ +hello=world +save_env -f env_file hello +#endif + +static const char *envsig = "# GRUB Environment Block\n"; + +void run_test(struct parser_test *test) +{ + const char *env_before, *env_after; + + /* The environment file must be preallocated */ + + /* The padding at the end of the environment block is the length of + * "hello=world\n" */ + env_before = talloc_asprintf(test, "%s%s", envsig, + "############"); + test_add_file_data(test, test->ctx->device, "/boot/grub/env_file", + env_before, strlen(env_before)); + + env_after = talloc_asprintf(test, "%s%s", envsig, + "hello=world\n"); + + test_read_conf_embedded(test, "/boot/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_file_contents(test, test->ctx->device, "/boot/grub/env_file", + env_after, strlen(env_after)); +} |