]> git.ozlabs.org Git - petitboot/commitdiff
discover/yaboot: implement default options
authorJeremy Kerr <jk@ozlabs.org>
Wed, 7 Aug 2013 06:39:40 +0000 (14:39 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 7 Aug 2013 06:39:40 +0000 (14:39 +0800)
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/yaboot-parser.c
test/parser/Makefile.am
test/parser/parser-test.h
test/parser/test-yaboot-default.c [new file with mode: 0644]
test/parser/utils.c

index 81ab83d548b9e8e93979500a6bbce9bc792954f2..c0750fe1f227e08f4e17ccac674c7b4b2e8a89d9 100644 (file)
@@ -87,6 +87,7 @@ static struct resource *create_yaboot_devpath_resource(
 static void yaboot_finish(struct conf_context *conf)
 {
        struct yaboot_state *state = conf->parser_info;
+       const char *default_label;
        struct boot_option *opt;
 
        assert(state->opt);
@@ -143,6 +144,11 @@ static void yaboot_finish(struct conf_context *conf)
        conf_strip_str(opt->boot_args);
        conf_strip_str(opt->description);
 
+       default_label = conf_get_global_option(conf, "default");
+       if (default_label &&
+                       !strcasecmp(state->opt->option->name, default_label))
+               state->opt->option->is_default = true;
+
        discover_context_add_boot_option(conf->dc, state->opt);
 }
 
@@ -302,6 +308,7 @@ static struct conf_global_option yaboot_global_options[] = {
        { .name = "video" },
        { .name = "literal" },
        { .name = "ramdisk" },
+       { .name = "default" },
        { .name = NULL },
 };
 
index 3c6d73beac746eafd09d452ac2d5e344e94f69dc..9bb7c16a5722b503b36715804ddd4be01c1ff113 100644 (file)
@@ -37,6 +37,7 @@ TESTS = \
        test-yaboot-root-global \
        test-yaboot-root-override \
        test-yaboot-device-override \
+       test-yaboot-default \
        test-yaboot-rh8-ppc64 \
        test-pxe-single \
        test-pxe-initrd-in-append
index 53296180e3291b7a74c01b9c39d06194056bd4d8..df9670fed8c0188657a9e8577a5cbe07c4e4ffa9 100644 (file)
@@ -74,6 +74,14 @@ void __check_name(struct discover_boot_option *opt, const char *name,
 #define check_name(opt, name) \
        __check_name(opt, name, __FILE__, __LINE__)
 
+/**
+ * Check that a boot option @opt is marked as default
+ */
+void __check_is_default(struct discover_boot_option *opt,
+               const char *file, int line);
+#define check_is_default(opt) \
+       __check_is_default(opt, __FILE__, __LINE__)
+
 /**
  * Check that a resource (@res) is present, resolved, and has a local path
  * (within @dev's mount point) of @path.
diff --git a/test/parser/test-yaboot-default.c b/test/parser/test-yaboot-default.c
new file mode 100644 (file)
index 0000000..66ba3a2
--- /dev/null
@@ -0,0 +1,28 @@
+#include "parser-test.h"
+
+#if 0 /* PARSER_EMBEDDED_CONFIG */
+default=linux.2
+
+image=/vmlinux
+       label=linux.1
+
+image=/vmlinux
+       label=linux.2
+#endif
+
+void run_test(struct parser_test *test)
+{
+       struct discover_boot_option *opt;
+       struct discover_context *ctx;
+
+       test_read_conf_embedded(test);
+       test_run_parser(test, "yaboot");
+
+       ctx = test->ctx;
+
+       check_boot_option_count(ctx, 2);
+
+       opt = get_boot_option(ctx, 1);
+       check_name(opt, "linux.2");
+       check_is_default(opt);
+}
index 3e218e4af07d35292ab2acfde23cb9da2f7dd475..407ac80ba40e1184658f289e2f11df5801605118 100644 (file)
@@ -262,6 +262,16 @@ void __check_name(struct discover_boot_option *opt, const char *name,
        }
 }
 
+void __check_is_default(struct discover_boot_option *opt,
+               const char *file, int line)
+{
+       if (opt->option->is_default)
+               return;
+
+       fprintf(stderr, "%s:%d: default check failed\n", file, line);
+       exit(EXIT_FAILURE);
+}
+
 void __check_resolved_local_resource(struct resource *res,
                struct discover_device *dev, const char *local_path,
                const char *file, int line)