]> git.ozlabs.org Git - petitboot/commitdiff
test/parser: Check for full URLs in parser tests
authorJeremy Kerr <jk@ozlabs.org>
Fri, 17 Jan 2014 08:36:41 +0000 (16:36 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Fri, 17 Jan 2014 08:58:14 +0000 (16:58 +0800)
At present, we only match the 'file' portion of a URL in the parser
tests, so we "serve" a file if just the filename (but not the scheme,
hostname or path) matches the file we set with test_read_conf_embedded.

This change introduces test_read_conf_embedded_url, which we can use to
specify a full URL. In this case, the fake parser_request_file matches
the entire URL before returning the file data.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
test/parser/parser-test.h
test/parser/test-grub2-save-env.c
test/parser/test-pxe-initrd-in-append.c
test/parser/test-pxe-ip-without-conf.c
test/parser/test-pxe-mac-without-conf.c
test/parser/test-pxe-non-url-conf.c
test/parser/test-pxe-single.c
test/parser/utils.c

index c23a7b051d3d001110b3e81d52cc26497dfbdb1f..7c406504e3d6fde9f0ffaab29643911ac64d39ca 100644 (file)
@@ -21,9 +21,10 @@ struct discover_device *test_create_device(struct parser_test *test,
                const char *name);
 
 #define test_read_conf_data(t, f, d) \
-       __test_read_conf_data(t, f, d, sizeof(d))
+       __test_read_conf_data(t, t->ctx->device, f, d, sizeof(d))
 
-void __test_read_conf_data(struct parser_test *test, const char *conf_file,
+void __test_read_conf_data(struct parser_test *test,
+               struct discover_device *dev, const char *conf_file,
                const char *buf, size_t len);
 void test_read_conf_file(struct parser_test *test, const char *filename,
                const char *conf_file);
@@ -49,7 +50,12 @@ struct discover_boot_option *get_boot_option(struct discover_context *ctx,
 extern const char __embedded_config[];
 extern const size_t __embedded_config_size;
 #define test_read_conf_embedded(t, f) \
-       __test_read_conf_data(t, f, __embedded_config, __embedded_config_size)
+       __test_read_conf_data(t, t->ctx->device, f, \
+                               __embedded_config, __embedded_config_size)
+
+#define test_read_conf_embedded_url(t, u) \
+       __test_read_conf_data(t, NULL, u, \
+                               __embedded_config, __embedded_config_size)
 
 /**
  * Checks for parser results.
index ce9a76a1d85760a0bbc7f72b28c33a9619deb54c..68e91bdbb73d796c2dc79e934f5eeebab7745578 100644 (file)
@@ -86,7 +86,8 @@ static void run_env_test(struct parser_test *test, struct env_test *envtest)
        test_add_file_data(test, test->ctx->device, "/boot/grub/grubenv",
                        env_before, strlen(env_before));
 
-       __test_read_conf_data(test, "/boot/grub/grub.cfg", envtest->script,
+       __test_read_conf_data(test, test->ctx->device,
+                       "/boot/grub/grub.cfg", envtest->script,
                        strlen(envtest->script));
 
        test_run_parser(test, "grub2");
index 2939e98eb50923dde3e824096a44f1bffe4d6c88..6ea6beff271ef0da704f91712781f669270e73d5 100644 (file)
@@ -14,7 +14,7 @@ void run_test(struct parser_test *test)
        struct discover_boot_option *opt;
        struct discover_context *ctx;
 
-       test_read_conf_embedded(test, "conf.txt");
+       test_read_conf_embedded_url(test, "tftp://host/dir/conf.txt");
 
        test_set_event_source(test);
        test_set_event_param(test->ctx->event, "pxeconffile",
index dd4ceddfd8f7711dac0d46234c35230bb3aae1d8..ff3bf9e2ade591b599dc6cf1ad64daa5191fd6e6 100644 (file)
@@ -15,7 +15,7 @@ void run_test(struct parser_test *test)
        struct discover_boot_option *opt;
        struct discover_context *ctx;
 
-       test_read_conf_embedded(test, "C0A8");
+       test_read_conf_embedded_url(test, "tftp://host/dir/C0A8");
 
        test_set_event_source(test);
        test_set_event_param(test->ctx->event, "bootfile", "dir/pxe");
index 72ef94bc6c0392f418ed4218dc80e4999aec72ab..8c0b561fb00a09a482b97661567a4db9347a6cb6 100644 (file)
@@ -15,7 +15,8 @@ void run_test(struct parser_test *test)
        struct discover_boot_option *opt;
        struct discover_context *ctx;
 
-       test_read_conf_embedded(test, "01-12-34-56-78-9A-BC");
+       test_read_conf_embedded_url(test,
+                       "tftp://host/dir/01-12-34-56-78-9A-BC");
 
        test_set_event_source(test);
        test_set_event_param(test->ctx->event, "bootfile", "dir/pxe");
index 08f246a9fd88b976c2aa1bce4526d21694c3cac6..491a40bd839e82b575a51647320eef4e60bb49ce 100644 (file)
@@ -15,7 +15,7 @@ void run_test(struct parser_test *test)
        struct discover_boot_option *opt;
        struct discover_context *ctx;
 
-       test_read_conf_embedded(test, "conf.txt");
+       test_read_conf_embedded_url(test, "tftp://host/conf.txt");
 
        test_set_event_source(test);
        test_set_event_param(test->ctx->event, "siaddr", "host");
index 0bc6a590347bf92ede7430bb40ec0c04549a0797..56c404cd98203fb8cb6afb816a26598e838e8969 100644 (file)
@@ -15,7 +15,7 @@ void run_test(struct parser_test *test)
        struct discover_boot_option *opt;
        struct discover_context *ctx;
 
-       test_read_conf_embedded(test, "conf.txt");
+       test_read_conf_embedded_url(test, "tftp://host/dir/conf.txt");
 
        test_set_event_source(test);
        test_set_event_param(test->ctx->event, "pxeconffile",
index 80117937e56f2f598e8bf211a2d3235d8072d26d..67401abc9e0d8fa5d95cfb2ed9f1b27ba2fce35e 100644 (file)
@@ -112,10 +112,11 @@ void test_fini(struct parser_test *test)
        talloc_free(test);
 }
 
-void __test_read_conf_data(struct parser_test *test, const char *conf_file,
+void __test_read_conf_data(struct parser_test *test,
+               struct discover_device *dev, const char *conf_file,
                const char *buf, size_t len)
 {
-       test_add_file_data(test, test->ctx->device, conf_file, buf, len);
+       test_add_file_data(test, dev, conf_file, buf, len);
 }
 
 void test_read_conf_file(struct parser_test *test, const char *filename,
@@ -239,7 +240,10 @@ int parser_request_url(struct discover_context *ctx, struct pb_url *url,
        char *tmp;
 
        list_for_each_entry(&test->files, file, list) {
-               if (strcmp(file->name, url->file))
+               if (file->dev)
+                       continue;
+
+               if (strcmp(file->name, url->full))
                        continue;
 
                /* the read_file() interface always adds a trailing null