summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-01-24 14:39:37 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-01-30 21:59:10 +0800
commit4896183708855fbfd0aa892537fbcc17ed7eb971 (patch)
tree5bbd851636871982cc26ca59ff1aa0970f6d8116 /test
parenteea9a9fa697654ef26d7e2c1cee3b4ac610db643 (diff)
downloadtalos-petitboot-4896183708855fbfd0aa892537fbcc17ed7eb971.zip
talos-petitboot-4896183708855fbfd0aa892537fbcc17ed7eb971.tar.gz
discover: Add support for checking directories in parser API
This change adds a function to the parser API: int parser_check_dir(struct discover_context *ctx, struct discover_device *dev, const char *dirname) - which allows parsers to check for the presence of a directory (path of 'dirname') on the device ('dev'). We use this in the GRUB2 parser to implement the `test -d` check. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'test')
-rw-r--r--test/parser/parser-test.h2
-rw-r--r--test/parser/utils.c38
2 files changed, 40 insertions, 0 deletions
diff --git a/test/parser/parser-test.h b/test/parser/parser-test.h
index 7c40650..631f1e5 100644
--- a/test/parser/parser-test.h
+++ b/test/parser/parser-test.h
@@ -36,6 +36,8 @@ void test_remove_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_add_dir(struct parser_test *test, struct discover_device *dev,
+ const char *dirname);
void test_set_event_source(struct parser_test *test);
void test_set_event_param(struct event *event, const char *name,
const char *value);
diff --git a/test/parser/utils.c b/test/parser/utils.c
index 67401ab..838250b 100644
--- a/test/parser/utils.c
+++ b/test/parser/utils.c
@@ -26,6 +26,10 @@ struct p_item {
struct test_file {
struct discover_device *dev;
+ enum {
+ TEST_FILE,
+ TEST_DIR,
+ } type;
const char *name;
void *data;
int size;
@@ -158,6 +162,7 @@ void test_add_file_data(struct parser_test *test, struct discover_device *dev,
struct test_file *file;
file = talloc_zero(test, struct test_file);
+ file->type = TEST_FILE;
file->dev = dev;
file->name = filename;
file->data = talloc_memdup(test, data, size);
@@ -165,6 +170,18 @@ void test_add_file_data(struct parser_test *test, struct discover_device *dev,
list_add(&test->files, &file->list);
}
+void test_add_dir(struct parser_test *test, struct discover_device *dev,
+ const char *dirname)
+{
+ struct test_file *file;
+
+ file = talloc_zero(test, struct test_file);
+ file->type = TEST_DIR;
+ file->dev = dev;
+ file->name = dirname;
+ list_add(&test->files, &file->list);
+}
+
void test_set_event_source(struct parser_test *test)
{
test->ctx->event = talloc_zero(test->ctx, struct event);
@@ -189,6 +206,8 @@ int parser_request_file(struct discover_context *ctx,
continue;
if (strcmp(file->name, filename))
continue;
+ if (file->type != TEST_FILE)
+ continue;
/* the read_file() interface always adds a trailing null
* for string-safety; do the same here */
@@ -203,6 +222,25 @@ int parser_request_file(struct discover_context *ctx,
return -1;
}
+int parser_check_dir(struct discover_context *ctx,
+ struct discover_device *dev, const char *dirname)
+{
+ struct parser_test *test = ctx->test_data;
+ struct test_file *file;
+
+ printf("%s: %s\n", __func__, dirname);
+
+ list_for_each_entry(&test->files, file, list) {
+ if (file->dev != dev)
+ continue;
+ if (strcmp(file->name, dirname))
+ continue;
+ return file->type == TEST_DIR ? 0 : -1;
+ }
+
+ return -1;
+}
+
int parser_replace_file(struct discover_context *ctx,
struct discover_device *dev, const char *filename,
char *buf, int len)
OpenPOWER on IntegriCloud