summaryrefslogtreecommitdiffstats
path: root/test/parser
diff options
context:
space:
mode:
Diffstat (limited to 'test/parser')
-rw-r--r--test/parser/Makefile.am7
-rw-r--r--test/parser/parser-test.h21
-rw-r--r--test/parser/test-grub2-default-index.c2
-rw-r--r--test/parser/test-grub2-default-multiword.c2
-rw-r--r--test/parser/test-grub2-default.c2
-rw-r--r--test/parser/test-grub2-f18-ppc64.c4
-rw-r--r--test/parser/test-grub2-lexer-error.c3
-rw-r--r--test/parser/test-grub2-load-env.c3
-rw-r--r--test/parser/test-grub2-multiple-resolve.c3
-rw-r--r--test/parser/test-grub2-parser-error.c3
-rw-r--r--test/parser/test-grub2-save-env.c4
-rw-r--r--test/parser/test-grub2-single-line-if.c3
-rw-r--r--test/parser/test-grub2-single.c3
-rw-r--r--test/parser/test-grub2-ubuntu-13_04-x86.c3
-rw-r--r--test/parser/test-kboot-single.c3
-rw-r--r--test/parser/test-pxe-empty.c8
-rw-r--r--test/parser/test-pxe-initrd-in-append.c8
-rw-r--r--test/parser/test-pxe-single.c8
-rw-r--r--test/parser/test-yaboot-default.c3
-rw-r--r--test/parser/test-yaboot-device-override.c3
-rw-r--r--test/parser/test-yaboot-external.c3
-rw-r--r--test/parser/test-yaboot-partition-override.c3
-rw-r--r--test/parser/test-yaboot-partition.c4
-rw-r--r--test/parser/test-yaboot-rh8-ppc64.c3
-rw-r--r--test/parser/test-yaboot-root-global.c3
-rw-r--r--test/parser/test-yaboot-root-override.c3
-rw-r--r--test/parser/test-yaboot-single.c3
-rw-r--r--test/parser/utils.c64
28 files changed, 125 insertions, 57 deletions
diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am
index 65dd7fc..32f204d 100644
--- a/test/parser/Makefile.am
+++ b/test/parser/Makefile.am
@@ -51,8 +51,7 @@ TESTS = \
test-yaboot-rh8-ppc64 \
test-pxe-empty \
test-pxe-single \
- test-pxe-initrd-in-append \
- test-pxe-default
+ test-pxe-initrd-in-append
$(TESTS): %: %.embedded-config.o
$(TESTS): LDADD += $@.embedded-config.o
@@ -70,7 +69,9 @@ parser_objs = \
$(top_srcdir)/discover/resource.c \
$(top_srcdir)/discover/paths.c \
$(top_srcdir)/discover/device-handler.c \
- $(top_srcdir)/discover/parser-conf.c
+ $(top_srcdir)/discover/parser-conf.c \
+ $(top_srcdir)/discover/user-event.c \
+ $(top_srcdir)/discover/event.c
libtest_ro_SOURCES = \
main.c \
diff --git a/test/parser/parser-test.h b/test/parser/parser-test.h
index ab3424c..7e4ffa2 100644
--- a/test/parser/parser-test.h
+++ b/test/parser/parser-test.h
@@ -11,10 +11,6 @@ struct parser_test {
struct discover_context *ctx;
struct list files;
struct config *config;
- struct {
- void *buf;
- size_t size;
- } conf;
};
/* interface required for parsers */
@@ -24,13 +20,13 @@ void __register_parser(struct parser *parser);
struct discover_device *test_create_device(struct parser_test *test,
const char *name);
-#define test_read_conf_data(t, d) \
- __test_read_conf_data(t, d, sizeof(d))
+#define test_read_conf_data(t, f, d) \
+ __test_read_conf_data(t, f, d, sizeof(d))
-void __test_read_conf_data(struct parser_test *test,
+void __test_read_conf_data(struct parser_test *test, const char *conf_file,
const char *buf, size_t len);
-void test_read_conf_file(struct parser_test *test, const char *filename);
-void test_set_conf_source(struct parser_test *test, const char *url);
+void test_read_conf_file(struct parser_test *test, const char *filename,
+ const char *conf_file);
int test_run_parser(struct parser_test *test, const char *parser_name);
@@ -38,6 +34,9 @@ void test_hotplug_device(struct parser_test *test, struct discover_device *dev);
void test_add_file_data(struct parser_test *test, struct discover_device *dev,
const char *filename, const void *data, int size);
+void test_set_event_source(struct parser_test *test);
+void test_set_event_param(struct event *event, const char *name,
+ const char *value);
#define test_add_file_string(test, dev, filename, str) \
test_add_file_data(test, dev, filename, str, sizeof(str) - 1)
@@ -48,8 +47,8 @@ struct discover_boot_option *get_boot_option(struct discover_context *ctx,
/* embedded config */
extern const char __embedded_config[];
extern const size_t __embedded_config_size;
-#define test_read_conf_embedded(t) \
- __test_read_conf_data(t, __embedded_config, __embedded_config_size)
+#define test_read_conf_embedded(t, f) \
+ __test_read_conf_data(t, f, __embedded_config, __embedded_config_size)
/**
* Checks for parser results.
diff --git a/test/parser/test-grub2-default-index.c b/test/parser/test-grub2-default-index.c
index 78835cd..cef8ef5 100644
--- a/test/parser/test-grub2-default-index.c
+++ b/test/parser/test-grub2-default-index.c
@@ -19,7 +19,7 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/boot/grub2/grub.cfg");
test_run_parser(test, "grub2");
ctx = test->ctx;
diff --git a/test/parser/test-grub2-default-multiword.c b/test/parser/test-grub2-default-multiword.c
index f7993fe..25d1cf1 100644
--- a/test/parser/test-grub2-default-multiword.c
+++ b/test/parser/test-grub2-default-multiword.c
@@ -16,7 +16,7 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/grub2/grub.cfg");
test_run_parser(test, "grub2");
ctx = test->ctx;
diff --git a/test/parser/test-grub2-default.c b/test/parser/test-grub2-default.c
index b3359d0..b083510 100644
--- a/test/parser/test-grub2-default.c
+++ b/test/parser/test-grub2-default.c
@@ -13,7 +13,7 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/grub2/grub.cfg");
test_run_parser(test, "grub2");
ctx = test->ctx;
diff --git a/test/parser/test-grub2-f18-ppc64.c b/test/parser/test-grub2-f18-ppc64.c
index 0baac05..bf59540 100644
--- a/test/parser/test-grub2-f18-ppc64.c
+++ b/test/parser/test-grub2-f18-ppc64.c
@@ -8,7 +8,9 @@ void run_test(struct parser_test *test)
struct discover_device *dev;
int i;
- test_read_conf_file(test, "grub2-f18-ppc64.conf");
+ test_read_conf_file(test, "grub2-f18-ppc64.conf",
+ "/boot/grub2/grub.cfg");
+
test_run_parser(test, "grub2");
ctx = test->ctx;
diff --git a/test/parser/test-grub2-lexer-error.c b/test/parser/test-grub2-lexer-error.c
index 503ec99..b08760e 100644
--- a/test/parser/test-grub2-lexer-error.c
+++ b/test/parser/test-grub2-lexer-error.c
@@ -7,7 +7,8 @@
void run_test(struct parser_test *test)
{
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/grub.cfg");
+
test_run_parser(test, "grub2");
check_boot_option_count(test->ctx, 0);
}
diff --git a/test/parser/test-grub2-load-env.c b/test/parser/test-grub2-load-env.c
index 2f4e96e..36fb3c5 100644
--- a/test/parser/test-grub2-load-env.c
+++ b/test/parser/test-grub2-load-env.c
@@ -18,7 +18,8 @@ void run_test(struct parser_test *test)
"# GRUB Environment Block\n"
"kernel=vmlinux-from-env\n");
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/boot/grub2/grub.cfg");
+
test_run_parser(test, "grub2");
ctx = test->ctx;
diff --git a/test/parser/test-grub2-multiple-resolve.c b/test/parser/test-grub2-multiple-resolve.c
index 4c4a7e9..f24c07f 100644
--- a/test/parser/test-grub2-multiple-resolve.c
+++ b/test/parser/test-grub2-multiple-resolve.c
@@ -19,7 +19,8 @@ void run_test(struct parser_test *test)
struct discover_context *ctx;
struct discover_device *dev;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/grub.cfg");
+
test_run_parser(test, "grub2");
ctx = test->ctx;
diff --git a/test/parser/test-grub2-parser-error.c b/test/parser/test-grub2-parser-error.c
index a7a00a4..92fa75c 100644
--- a/test/parser/test-grub2-parser-error.c
+++ b/test/parser/test-grub2-parser-error.c
@@ -7,7 +7,8 @@
void run_test(struct parser_test *test)
{
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/grub/grub.cfg");
+
test_run_parser(test, "grub2");
check_boot_option_count(test->ctx, 0);
}
diff --git a/test/parser/test-grub2-save-env.c b/test/parser/test-grub2-save-env.c
index 7a2938f..826963e 100644
--- a/test/parser/test-grub2-save-env.c
+++ b/test/parser/test-grub2-save-env.c
@@ -86,7 +86,9 @@ 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, envtest->script, strlen(envtest->script));
+ __test_read_conf_data(test, "/boot/grub2/grub.cfg", envtest->script,
+ strlen(envtest->script));
+
test_run_parser(test, "grub2");
check_file_contents(test, test->ctx->device, "/boot/grub/grubenv",
diff --git a/test/parser/test-grub2-single-line-if.c b/test/parser/test-grub2-single-line-if.c
index 487d2f3..3a750ba 100644
--- a/test/parser/test-grub2-single-line-if.c
+++ b/test/parser/test-grub2-single-line-if.c
@@ -16,7 +16,8 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/grub.cfg");
+
test_run_parser(test, "grub2");
ctx = test->ctx;
diff --git a/test/parser/test-grub2-single.c b/test/parser/test-grub2-single.c
index 7db8eb9..f12fe53 100644
--- a/test/parser/test-grub2-single.c
+++ b/test/parser/test-grub2-single.c
@@ -13,7 +13,8 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/grub2/grub.cfg");
+
test_run_parser(test, "grub2");
ctx = test->ctx;
diff --git a/test/parser/test-grub2-ubuntu-13_04-x86.c b/test/parser/test-grub2-ubuntu-13_04-x86.c
index 8f97858..2f9aefd 100644
--- a/test/parser/test-grub2-ubuntu-13_04-x86.c
+++ b/test/parser/test-grub2-ubuntu-13_04-x86.c
@@ -7,7 +7,8 @@ void run_test(struct parser_test *test)
struct discover_context *ctx;
struct discover_device *dev;
- test_read_conf_file(test, "grub2-ubuntu-13_04-x86.conf");
+ test_read_conf_file(test, "grub2-ubuntu-13_04-x86.conf", "/grub.cfg");
+
test_run_parser(test, "grub2");
ctx = test->ctx;
diff --git a/test/parser/test-kboot-single.c b/test/parser/test-kboot-single.c
index af7bdab..228b06d 100644
--- a/test/parser/test-kboot-single.c
+++ b/test/parser/test-kboot-single.c
@@ -9,7 +9,8 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_data(test, config);
+ test_read_conf_data(test, "/kboot.conf", config);
+
test_run_parser(test, "kboot");
ctx = test->ctx;
diff --git a/test/parser/test-pxe-empty.c b/test/parser/test-pxe-empty.c
index eb3b758..fbc1d8a 100644
--- a/test/parser/test-pxe-empty.c
+++ b/test/parser/test-pxe-empty.c
@@ -9,8 +9,12 @@ void run_test(struct parser_test *test)
{
struct discover_context *ctx;
- test_read_conf_embedded(test);
- test_set_conf_source(test, "tftp://host/dir/conf.txt");
+ test_read_conf_embedded(test, "conf.txt");
+
+ test_set_event_source(test);
+ test_set_event_param(test->ctx->event, "conffile",
+ "tftp://host/dir/conf.txt");
+
test_run_parser(test, "pxe");
ctx = test->ctx;
diff --git a/test/parser/test-pxe-initrd-in-append.c b/test/parser/test-pxe-initrd-in-append.c
index 3c1c217..6cd2ef4 100644
--- a/test/parser/test-pxe-initrd-in-append.c
+++ b/test/parser/test-pxe-initrd-in-append.c
@@ -14,8 +14,12 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test);
- test_set_conf_source(test, "tftp://host/dir/conf.txt");
+ test_read_conf_embedded(test, "conf.txt");
+
+ test_set_event_source(test);
+ test_set_event_param(test->ctx->event, "conffile",
+ "tftp://host/dir/conf.txt");
+
test_run_parser(test, "pxe");
ctx = test->ctx;
diff --git a/test/parser/test-pxe-single.c b/test/parser/test-pxe-single.c
index 65e3051..ccb4d5c 100644
--- a/test/parser/test-pxe-single.c
+++ b/test/parser/test-pxe-single.c
@@ -15,8 +15,12 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test);
- test_set_conf_source(test, "tftp://host/dir/conf.txt");
+ test_read_conf_embedded(test, "conf.txt");
+
+ test_set_event_source(test);
+ test_set_event_param(test->ctx->event, "conffile",
+ "tftp://host/dir/conf.txt");
+
test_run_parser(test, "pxe");
ctx = test->ctx;
diff --git a/test/parser/test-yaboot-default.c b/test/parser/test-yaboot-default.c
index 66ba3a2..4143def 100644
--- a/test/parser/test-yaboot-default.c
+++ b/test/parser/test-yaboot-default.c
@@ -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);
+ test_read_conf_embedded(test, "/etc/yaboot.conf");
+
test_run_parser(test, "yaboot");
ctx = test->ctx;
diff --git a/test/parser/test-yaboot-device-override.c b/test/parser/test-yaboot-device-override.c
index ddbe4f4..be9332f 100644
--- a/test/parser/test-yaboot-device-override.c
+++ b/test/parser/test-yaboot-device-override.c
@@ -34,7 +34,8 @@ void run_test(struct parser_test *test)
char *devname;
int i;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/etc/yaboot.conf");
+
test_run_parser(test, "yaboot");
ctx = test->ctx;
diff --git a/test/parser/test-yaboot-external.c b/test/parser/test-yaboot-external.c
index bd09b44..713145f 100644
--- a/test/parser/test-yaboot-external.c
+++ b/test/parser/test-yaboot-external.c
@@ -15,7 +15,8 @@ void run_test(struct parser_test *test)
struct discover_context *ctx;
struct discover_device *dev;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/yaboot.conf");
+
test_run_parser(test, "yaboot");
ctx = test->ctx;
diff --git a/test/parser/test-yaboot-partition-override.c b/test/parser/test-yaboot-partition-override.c
index fc23ba0..0231e1a 100644
--- a/test/parser/test-yaboot-partition-override.c
+++ b/test/parser/test-yaboot-partition-override.c
@@ -14,7 +14,8 @@ void run_test(struct parser_test *test)
struct discover_context *ctx;
struct discover_device *dev;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/yaboot.conf");
+
test_run_parser(test, "yaboot");
ctx = test->ctx;
diff --git a/test/parser/test-yaboot-partition.c b/test/parser/test-yaboot-partition.c
index 25aa98f..462aee9 100644
--- a/test/parser/test-yaboot-partition.c
+++ b/test/parser/test-yaboot-partition.c
@@ -1,4 +1,5 @@
#include "parser-test.h"
+#include <stdio.h>
#if 0 /* PARSER_EMBEDDED_CONFIG */
device=sda
@@ -14,7 +15,8 @@ void run_test(struct parser_test *test)
struct discover_context *ctx;
struct discover_device *dev;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/yaboot.conf");
+
test_run_parser(test, "yaboot");
ctx = test->ctx;
diff --git a/test/parser/test-yaboot-rh8-ppc64.c b/test/parser/test-yaboot-rh8-ppc64.c
index 8966cfd..3f6571e 100644
--- a/test/parser/test-yaboot-rh8-ppc64.c
+++ b/test/parser/test-yaboot-rh8-ppc64.c
@@ -6,7 +6,8 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_file(test, "yaboot-rh8-ppc64.conf");
+ test_read_conf_file(test, "yaboot-rh8-ppc64.conf", "/yaboot.conf");
+
test_run_parser(test, "yaboot");
ctx = test->ctx;
diff --git a/test/parser/test-yaboot-root-global.c b/test/parser/test-yaboot-root-global.c
index 6d8da85..c5e7698 100644
--- a/test/parser/test-yaboot-root-global.c
+++ b/test/parser/test-yaboot-root-global.c
@@ -16,7 +16,8 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/etc/yaboot.conf");
+
test_run_parser(test, "yaboot");
ctx = test->ctx;
diff --git a/test/parser/test-yaboot-root-override.c b/test/parser/test-yaboot-root-override.c
index 0eea3d4..74518cf 100644
--- a/test/parser/test-yaboot-root-override.c
+++ b/test/parser/test-yaboot-root-override.c
@@ -18,7 +18,8 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/etc/yaboot.conf");
+
test_run_parser(test, "yaboot");
ctx = test->ctx;
diff --git a/test/parser/test-yaboot-single.c b/test/parser/test-yaboot-single.c
index 17866e8..f5e1393 100644
--- a/test/parser/test-yaboot-single.c
+++ b/test/parser/test-yaboot-single.c
@@ -14,7 +14,8 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test);
+ test_read_conf_embedded(test, "/etc/yaboot.conf");
+
test_run_parser(test, "yaboot");
ctx = test->ctx;
diff --git a/test/parser/utils.c b/test/parser/utils.c
index 083d916..b80e0e1 100644
--- a/test/parser/utils.c
+++ b/test/parser/utils.c
@@ -15,6 +15,7 @@
#include "device-handler.h"
#include "parser.h"
#include "resource.h"
+#include "event.h"
#include "parser-test.h"
@@ -111,18 +112,20 @@ void test_fini(struct parser_test *test)
talloc_free(test);
}
-void __test_read_conf_data(struct parser_test *test,
+void __test_read_conf_data(struct parser_test *test, const char *conf_file,
const char *buf, size_t len)
{
- test->conf.size = len;
- test->conf.buf = talloc_memdup(test, buf, len);
+ test_add_file_data(test, test->ctx->device, conf_file, buf, len);
}
-void test_read_conf_file(struct parser_test *test, const char *filename)
+void test_read_conf_file(struct parser_test *test, const char *filename,
+ const char *conf_file)
{
struct stat stat;
+ size_t size;
char *path;
int fd, rc;
+ char *buf;
path = talloc_asprintf(test, "%s/%s", TEST_CONF_BASE, filename);
@@ -134,22 +137,18 @@ void test_read_conf_file(struct parser_test *test, const char *filename)
assert(!rc);
(void)rc;
- test->conf.size = stat.st_size;
- test->conf.buf = talloc_array(test, char, test->conf.size + 1);
+ size = stat.st_size;
+ buf = talloc_array(test, char, size + 1);
- rc = read(fd, test->conf.buf, test->conf.size);
- assert(rc == (ssize_t)test->conf.size);
+ rc = read(fd, buf, size);
+ assert(rc == (ssize_t)size);
- *(char *)(test->conf.buf + test->conf.size) = '\0';
+ *(buf + size) = '\0';
close(fd);
talloc_free(path);
-}
-void test_set_conf_source(struct parser_test *test, const char *url)
-{
- test->ctx->conf_url = pb_url_parse(test, url);
- assert(test->ctx->conf_url);
+ test_add_file_data(test, test->ctx->device, conf_file, buf, size);
}
void test_add_file_data(struct parser_test *test, struct discover_device *dev,
@@ -165,6 +164,16 @@ void test_add_file_data(struct parser_test *test, struct discover_device *dev,
list_add(&test->files, &file->list);
}
+void test_set_event_source(struct parser_test *test)
+{
+ test->ctx->event = talloc_zero(test->ctx, struct event);
+}
+
+void test_set_event_param(struct event *event, const char *name,
+ const char *value)
+{
+ event_set_param(event, name, value);
+}
int parser_request_file(struct discover_context *ctx,
struct discover_device *dev, const char *filename,
@@ -221,6 +230,31 @@ int parser_replace_file(struct discover_context *ctx,
file->size = len;
return 0;
}
+
+int parser_request_url(struct discover_context *ctx, struct pb_url *url,
+ char **buf, int *len)
+{
+ struct parser_test *test = ctx->test_data;
+ struct test_file *file;
+ char *tmp;
+
+ list_for_each_entry(&test->files, file, list) {
+ if (strcmp(file->name, url->file))
+ continue;
+
+ /* the read_file() interface always adds a trailing null
+ * for string-safety; do the same here */
+ tmp = talloc_array(test, char, file->size + 1);
+ memcpy(tmp, file->data, file->size);
+ tmp[file->size] = '\0';
+ *buf = tmp;
+ *len = file->size;
+ return 0;
+ }
+
+ return -1;
+}
+
int test_run_parser(struct parser_test *test, const char *parser_name)
{
struct p_item* i;
@@ -229,7 +263,7 @@ int test_run_parser(struct parser_test *test, const char *parser_name)
if (strcmp(i->parser->name, parser_name))
continue;
test->ctx->parser = i->parser;
- return i->parser->parse(test->ctx, test->conf.buf, test->conf.size);
+ return i->parser->parse(test->ctx);
}
errx(EXIT_FAILURE, "%s: parser '%s' not found", __func__, parser_name);
OpenPOWER on IntegriCloud