summaryrefslogtreecommitdiffstats
path: root/test/parser
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-09-19 17:16:53 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-09-19 21:36:33 +0800
commitf611bde3f182e9a4befb48a0160d1831708aca67 (patch)
treecacf467246c85c491bf91b3fe46c448c5fdbab94 /test/parser
parent4926cde5c97d09794ec33cca1321bb05a8d43304 (diff)
downloadpetitboot-f611bde3f182e9a4befb48a0160d1831708aca67.zip
petitboot-f611bde3f182e9a4befb48a0160d1831708aca67.tar.gz
discover: Remove unnecessary event passing
Currently, we pass "events" between the udev, user-event and device-handler layers. These events all get sent through device_handler_event, then de-multiplexed to an appropriate handler, depending on their source. Instead, just export relevant device_handler functions, and have the (old) event sources call these functions directly. This also means we can include a lot more of the device hander code in the parser tests. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'test/parser')
-rw-r--r--test/parser/handler.c32
-rw-r--r--test/parser/parser-test.h3
-rw-r--r--test/parser/test-grub2-f18-ppc64.c2
-rw-r--r--test/parser/test-grub2-multiple-resolve.c2
-rw-r--r--test/parser/test-grub2-ubuntu-13_04-x86.c2
-rw-r--r--test/parser/test-yaboot-device-override.c2
-rw-r--r--test/parser/test-yaboot-external.c2
-rw-r--r--test/parser/test-yaboot-partition-override.c2
-rw-r--r--test/parser/test-yaboot-partition.c2
-rw-r--r--test/parser/utils.c20
10 files changed, 50 insertions, 19 deletions
diff --git a/test/parser/handler.c b/test/parser/handler.c
index f585c31..437f765 100644
--- a/test/parser/handler.c
+++ b/test/parser/handler.c
@@ -1,9 +1,12 @@
+#include <assert.h>
+
#include <talloc/talloc.h>
#include <types/types.h>
#include "device-handler.h"
+typedef void (*boot_status_fn)(void *arg, struct boot_status *);
void discover_server_notify_device_add(struct discover_server *server,
struct device *device)
@@ -26,3 +29,32 @@ void discover_server_notify_device_remove(struct discover_server *server,
(void)device;
}
+void discover_server_notify_boot_status(struct discover_server *server,
+ struct boot_status *status)
+{
+ (void)server;
+ (void)status;
+}
+
+void parser_init(void)
+{
+}
+
+void iterate_parsers(struct discover_context *ctx, enum conf_method method)
+{
+ (void)ctx;
+ (void)method;
+ assert(false);
+}
+
+int boot(void *ctx, struct discover_boot_option *opt, struct boot_command *cmd,
+ int dry_run, boot_status_fn status_fn, void *status_arg)
+{
+ (void)ctx;
+ (void)opt;
+ (void)cmd;
+ (void)dry_run;
+ (void)status_fn;
+ (void)status_arg;
+ assert(false);
+}
diff --git a/test/parser/parser-test.h b/test/parser/parser-test.h
index df9670f..7e43a68 100644
--- a/test/parser/parser-test.h
+++ b/test/parser/parser-test.h
@@ -9,6 +9,7 @@
struct parser_test {
struct device_handler *handler;
struct discover_context *ctx;
+ struct config *config;
struct {
void *buf;
size_t size;
@@ -19,7 +20,7 @@ struct parser_test {
void __register_parser(struct parser *parser);
/* test functions */
-struct discover_device *test_create_device(struct discover_context *ctx,
+struct discover_device *test_create_device(struct parser_test *test,
const char *name);
#define test_read_conf_data(t, d) \
diff --git a/test/parser/test-grub2-f18-ppc64.c b/test/parser/test-grub2-f18-ppc64.c
index 94eb6a4..ba3515d 100644
--- a/test/parser/test-grub2-f18-ppc64.c
+++ b/test/parser/test-grub2-f18-ppc64.c
@@ -38,7 +38,7 @@ void run_test(struct parser_test *test)
/* hotplug a device with a maching UUID, and check that our
* resources become resolved */
- dev = test_create_device(ctx, "external");
+ dev = test_create_device(test, "external");
dev->uuid = "773653a7-660e-490e-9a74-d9fdfc9bbbf6";
test_hotplug_device(test, dev);
diff --git a/test/parser/test-grub2-multiple-resolve.c b/test/parser/test-grub2-multiple-resolve.c
index dd78695..4c4a7e9 100644
--- a/test/parser/test-grub2-multiple-resolve.c
+++ b/test/parser/test-grub2-multiple-resolve.c
@@ -34,7 +34,7 @@ void run_test(struct parser_test *test)
check_unresolved_resource(opt[1]->boot_image);
check_not_present_resource(opt[1]->initrd);
- dev = test_create_device(ctx, "external");
+ dev = test_create_device(test, "external");
dev->uuid = "48c1b787-20ad-47ce-b9eb-b108dddc3535";
test_hotplug_device(test, dev);
diff --git a/test/parser/test-grub2-ubuntu-13_04-x86.c b/test/parser/test-grub2-ubuntu-13_04-x86.c
index 45da55f..145e4c0 100644
--- a/test/parser/test-grub2-ubuntu-13_04-x86.c
+++ b/test/parser/test-grub2-ubuntu-13_04-x86.c
@@ -44,7 +44,7 @@ void run_test(struct parser_test *test)
/* hotplug a device with a maching UUID, and check that our
* resources become resolved */
- dev = test_create_device(ctx, "external");
+ dev = test_create_device(test, "external");
dev->uuid = "29beca39-9181-4780-bbb2-ab5d4be59aaf";
test_hotplug_device(test, dev);
diff --git a/test/parser/test-yaboot-device-override.c b/test/parser/test-yaboot-device-override.c
index 5db5788..ddbe4f4 100644
--- a/test/parser/test-yaboot-device-override.c
+++ b/test/parser/test-yaboot-device-override.c
@@ -63,7 +63,7 @@ void run_test(struct parser_test *test)
/* hotplug all dependent devices */
for (i = 0; i < 4; i++) {
devname = talloc_asprintf(test, "sda%d", i + 1);
- dev[i] = test_create_device(ctx, devname);
+ dev[i] = test_create_device(test, devname);
test_hotplug_device(test, dev[i]);
}
diff --git a/test/parser/test-yaboot-external.c b/test/parser/test-yaboot-external.c
index 6d48b27..bd09b44 100644
--- a/test/parser/test-yaboot-external.c
+++ b/test/parser/test-yaboot-external.c
@@ -28,7 +28,7 @@ void run_test(struct parser_test *test)
check_unresolved_resource(opt->boot_image);
check_unresolved_resource(opt->initrd);
- dev = test_create_device(ctx, "external");
+ dev = test_create_device(test, "external");
test_hotplug_device(test, dev);
check_resolved_local_resource(opt->boot_image, dev, "/vmlinux");
diff --git a/test/parser/test-yaboot-partition-override.c b/test/parser/test-yaboot-partition-override.c
index a29c852..fc23ba0 100644
--- a/test/parser/test-yaboot-partition-override.c
+++ b/test/parser/test-yaboot-partition-override.c
@@ -26,7 +26,7 @@ void run_test(struct parser_test *test)
check_name(opt, "linux");
check_unresolved_resource(opt->boot_image);
- dev = test_create_device(ctx, "sda2");
+ dev = test_create_device(test, "sda2");
test_hotplug_device(test, dev);
check_resolved_local_resource(opt->boot_image, dev, "/vmlinux");
diff --git a/test/parser/test-yaboot-partition.c b/test/parser/test-yaboot-partition.c
index 0606982..25aa98f 100644
--- a/test/parser/test-yaboot-partition.c
+++ b/test/parser/test-yaboot-partition.c
@@ -26,7 +26,7 @@ void run_test(struct parser_test *test)
check_name(opt, "linux");
check_unresolved_resource(opt->boot_image);
- dev = test_create_device(ctx, "sda2");
+ dev = test_create_device(test, "sda2");
test_hotplug_device(test, dev);
check_resolved_local_resource(opt->boot_image, dev, "/vmlinux");
diff --git a/test/parser/utils.c b/test/parser/utils.c
index 407ac80..de1dc13 100644
--- a/test/parser/utils.c
+++ b/test/parser/utils.c
@@ -41,25 +41,22 @@ static void __attribute__((destructor)) __cleanup_parsers(void)
}
static struct discover_device *test_create_device_simple(
- struct discover_context *ctx)
+ struct parser_test *test)
{
static int dev_idx;
char name[10];
sprintf(name, "__test%d", dev_idx++);
- return test_create_device(ctx, name);
+ return test_create_device(test, name);
}
-struct discover_device *test_create_device(struct discover_context *ctx,
+struct discover_device *test_create_device(struct parser_test *test,
const char *name)
{
struct discover_device *dev;
- dev = talloc_zero(ctx, struct discover_device);
- dev->device = talloc_zero(dev, struct device);
-
- list_init(&dev->boot_options);
+ dev = discover_device_create(test->handler, name);
dev->device->id = talloc_strdup(dev, name);
dev->device_path = talloc_asprintf(dev, "/dev/%s", name);
@@ -76,16 +73,20 @@ static struct discover_context *test_create_context(struct parser_test *test)
assert(ctx);
list_init(&ctx->boot_options);
- ctx->device = test_create_device_simple(ctx);
+ ctx->device = test_create_device_simple(test);
+ device_handler_add_device(test->handler, ctx->device);
return ctx;
}
+extern struct config *test_config_init(struct parser_test *test);
+
struct parser_test *test_init(void)
{
struct parser_test *test;
test = talloc_zero(NULL, struct parser_test);
+ test->config = test_config_init(test);
test->handler = device_handler_init(NULL, NULL, 0);
test->ctx = test_create_context(test);
@@ -175,9 +176,6 @@ void boot_option_resolve(struct device_handler *handler,
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;
OpenPOWER on IntegriCloud