X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=test%2Fparser%2Futils.c;h=33efda80536f8354ebc4e10e6b64fe1299755831;hp=7ebb411c0c9f6eb664991da10e75b7fb684a64c3;hb=9fbd73a208c9465b4bf9e2c80c7290b72e62ead1;hpb=85d8a6966cbf5c97023c11620cabd8a63b883e07 diff --git a/test/parser/utils.c b/test/parser/utils.c index 7ebb411..33efda8 100644 --- a/test/parser/utils.c +++ b/test/parser/utils.c @@ -22,6 +22,14 @@ struct p_item { struct parser *parser; }; +struct test_file { + struct discover_device *dev; + const char *name; + void *data; + int size; + struct list_item list; +}; + STATIC_LIST(parsers); void __register_parser(struct parser *parser) @@ -61,6 +69,7 @@ struct discover_device *test_create_device(struct parser_test *test, dev->device->id = talloc_strdup(dev, name); dev->device_path = talloc_asprintf(dev, "/dev/%s", name); dev->mount_path = talloc_asprintf(dev, "/test/mount/%s", name); + dev->mounted = true; return dev; } @@ -74,6 +83,7 @@ static struct discover_context *test_create_context(struct parser_test *test) list_init(&ctx->boot_options); ctx->device = test_create_device_simple(test); + ctx->test_data = test; device_handler_add_device(test->handler, ctx->device); return ctx; @@ -89,6 +99,7 @@ struct parser_test *test_init(void) test->config = test_config_init(test); test->handler = device_handler_init(NULL, NULL, 0); test->ctx = test_create_context(test); + list_init(&test->files); return test; } @@ -140,6 +151,71 @@ void test_set_conf_source(struct parser_test *test, const char *url) assert(test->ctx->conf_url); } +void test_add_file_data(struct parser_test *test, struct discover_device *dev, + const char *filename, void *data, int size) +{ + struct test_file *file; + + file = talloc_zero(test, struct test_file); + file->dev = dev; + file->name = filename; + file->data = data; + file->size = size; + list_add(&test->files, &file->list); +} + + +int parser_request_file(struct discover_context *ctx, + struct discover_device *dev, const char *filename, + char **buf, int *len) +{ + struct parser_test *test = ctx->test_data; + struct test_file *file; + + list_for_each_entry(&test->files, file, list) { + if (file->dev != dev) + continue; + if (strcmp(file->name, filename)) + continue; + + *buf = talloc_memdup(test, file->data, file->size); + *len = file->size; + return 0; + } + + return -1; +} + +int parser_replace_file(struct discover_context *ctx, + struct discover_device *dev, const char *filename, + char *buf, int len) +{ + struct parser_test *test = ctx->test_data; + struct test_file *f, *file; + + list_for_each_entry(&test->files, f, list) { + if (f->dev != dev) + continue; + if (strcmp(f->name, filename)) + continue; + + file = f; + break; + } + + if (!file) { + file = talloc_zero(test, struct test_file); + file->dev = dev; + file->name = filename; + list_add(&test->files, &file->list); + } else { + talloc_free(file->data); + } + + file->data = talloc_memdup(test, buf, len); + file->size = len; + return 0; +} int test_run_parser(struct parser_test *test, const char *parser_name) { struct p_item* i; @@ -239,6 +315,9 @@ void __check_args(struct discover_boot_option *opt, const char *args, { int rc; + if (!opt->option->boot_args && !args) + return; + if (!opt->option->boot_args) { fprintf(stderr, "%s:%d: arg check failed\n", file, line); fprintf(stderr, " no arguments parsed\n");