From: Jeremy Kerr Date: Wed, 15 May 2013 08:41:56 +0000 (+0800) Subject: test/parser: Add test device hotplug functions X-Git-Tag: v1.0.0~623 X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=commitdiff_plain;h=22b9ca8f4b9d28b4405576b39a87d3d0c945dd07 test/parser: Add test device hotplug functions 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 --- diff --git a/test/parser/parser-test.h b/test/parser/parser-test.h index 3a4382a..5ecfefc 100644 --- a/test/parser/parser-test.h +++ b/test/parser/parser-test.h @@ -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); diff --git a/test/parser/utils.c b/test/parser/utils.c index fb558cf..43479b1 100644 --- a/test/parser/utils.c +++ b/test/parser/utils.c @@ -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) {