]> git.ozlabs.org Git - petitboot/commitdiff
test/parser: Add test device hotplug functions
authorJeremy Kerr <jk@ozlabs.org>
Wed, 15 May 2013 08:41:56 +0000 (16:41 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 16 May 2013 03:53:34 +0000 (11:53 +0800)
Add a function, test_hotplug_device(), to simulate the addition of
devices during tests. This should make it possible to observe boot
options' resources changing from unresolved state to resolved.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
test/parser/parser-test.h
test/parser/utils.c

index 3a4382ad2226e65de8fcd7df6e2f1afe2516138f..5ecfefc9b6ee46f7b469515651464e7d0d649564 100644 (file)
@@ -31,6 +31,8 @@ void test_read_conf_file(struct parser_test *test, const char *filename);
 
 int test_run_parser(struct parser_test *test, const char *parser_name);
 
+void test_hotplug_device(struct parser_test *test, struct discover_device *dev);
+
 struct discover_boot_option *get_boot_option(struct discover_context *ctx,
                int idx);
 
index fb558cf2c3ec457be3d0ef63a8f399bb06b3f343..43479b1a88aea8cbd3c25a91e578d47ca18eb524 100644 (file)
@@ -141,6 +141,41 @@ int test_run_parser(struct parser_test *test, const char *parser_name)
        return rc;
 }
 
+bool resource_resolve(struct device_handler *handler, struct parser *parser,
+               struct resource *resource)
+{
+       if (!resource)
+               return true;
+       if (resource->resolved)
+               return true;
+
+       assert(parser);
+       assert(parser->resolve_resource);
+
+       return parser->resolve_resource(handler, resource);
+}
+
+void boot_option_resolve(struct device_handler *handler,
+               struct discover_boot_option *opt)
+{
+       resource_resolve(handler, opt->source, opt->boot_image);
+       resource_resolve(handler, opt->source, opt->initrd);
+       resource_resolve(handler, opt->source, opt->icon);
+}
+
+extern void device_handler_add_device(struct device_handler *handler,
+               struct discover_device *dev);
+
+void test_hotplug_device(struct parser_test *test, struct discover_device *dev)
+{
+       struct discover_boot_option *opt;
+
+       device_handler_add_device(test->handler, dev);
+
+       list_for_each_entry(&test->ctx->boot_options, opt, list)
+               boot_option_resolve(test->handler, opt);
+}
+
 struct discover_boot_option *get_boot_option(struct discover_context *ctx,
                int idx)
 {