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
$(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 \
struct discover_context *ctx;
struct list files;
struct config *config;
- struct {
- void *buf;
- size_t size;
- } conf;
};
/* interface required for parsers */
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);
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)
/* 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.
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;
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;
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;
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;
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);
}
"# 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;
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;
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);
}
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",
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;
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;
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;
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;
{
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;
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;
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;
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;
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;
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;
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;
#include "parser-test.h"
+#include <stdio.h>
#if 0 /* PARSER_EMBEDDED_CONFIG */
device=sda
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;
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;
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;
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;
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;
#include "device-handler.h"
#include "parser.h"
#include "resource.h"
+#include "event.h"
#include "parser-test.h"
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);
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,
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,
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;
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);