]> git.ozlabs.org Git - petitboot/blob - test/parser/parser-test.h
ui/ncurses: Implement non-boot-cancelling keys
[petitboot] / test / parser / parser-test.h
1 #ifndef PARSER_TEST_H
2 #define PARSER_TEST_H
3
4 #include <stdlib.h>
5
6 #include "device-handler.h"
7 #include "resource.h"
8
9 struct parser_test {
10         struct device_handler *handler;
11         struct discover_context *ctx;
12         struct list files;
13 };
14
15 /* interface required for parsers */
16 void __register_parser(struct parser *parser);
17
18 /* test functions */
19 struct discover_device *test_create_device(struct parser_test *test,
20                 const char *name);
21
22 #define test_read_conf_data(t, f, d) \
23         __test_read_conf_data(t, t->ctx->device, f, d, sizeof(d))
24
25 void __test_read_conf_data(struct parser_test *test,
26                 struct discover_device *dev, const char *conf_file,
27                 const char *buf, size_t len);
28 void test_read_conf_file(struct parser_test *test, const char *filename,
29                 const char *conf_file);
30
31 int test_run_parser(struct parser_test *test, const char *parser_name);
32
33 void test_hotplug_device(struct parser_test *test, struct discover_device *dev);
34 void test_remove_device(struct parser_test *test, struct discover_device *dev);
35
36 /* Note that the testing filesystem will only reflect files and
37  * directories that you explicitly add, so it is possible for a test
38  * to inconsistently believe that a file exists but that its parent
39  * directory does not. */
40 void test_add_file_data(struct parser_test *test, struct discover_device *dev,
41                 const char *filename, const void *data, int size);
42 void test_add_dir(struct parser_test *test, struct discover_device *dev,
43                 const char *dirname);
44
45 void test_set_event_source(struct parser_test *test);
46 void test_set_event_param(struct event *event, const char *name,
47                 const char *value);
48 void test_set_event_device(struct event *event, const char *dev);
49
50 #define test_add_file_string(test, dev, filename, str) \
51         test_add_file_data(test, dev, filename, str, sizeof(str) - 1)
52
53 struct discover_boot_option *get_boot_option(struct discover_context *ctx,
54                 int idx);
55
56 /* embedded config */
57 extern const char __embedded_config[];
58 extern const size_t __embedded_config_size;
59 #define test_read_conf_embedded(t, f) \
60         __test_read_conf_data(t, t->ctx->device, f, \
61                                 __embedded_config, __embedded_config_size)
62
63 #define test_read_conf_embedded_url(t, u) \
64         __test_read_conf_data(t, NULL, u, \
65                                 __embedded_config, __embedded_config_size)
66
67 /**
68  * Checks for parser results.
69  *
70  * These return void, but will respond to check failures by printing a reason
71  * for the failure, and exit the test with a non-zero exit status.
72  */
73
74 /**
75  * Check that we have an expected number of boot options parsed. If not,
76  * print out what we did find, then exit.
77  */
78 #define check_boot_option_count(ctx, count) \
79         __check_boot_option_count(ctx, count, __FILE__, __LINE__)
80 void __check_boot_option_count(struct discover_context *ctx, int count,
81                 const char *file, int line);
82 /*
83  * Check that a boot option @opt has args @args
84  */
85 void __check_args(struct discover_boot_option *opt, const char *args,
86                 const char *file, int line);
87 #define check_args(opt, args) \
88         __check_args(opt, args, __FILE__, __LINE__)
89
90 /**
91  * Check that a boot option @opt has name @name
92  */
93 void __check_name(struct discover_boot_option *opt, const char *name,
94                 const char *file, int line);
95 #define check_name(opt, name) \
96         __check_name(opt, name, __FILE__, __LINE__)
97
98 /**
99  * Check that a boot option @opt is marked as default
100  */
101 void __check_is_default(struct discover_boot_option *opt,
102                 const char *file, int line);
103 #define check_is_default(opt) \
104         __check_is_default(opt, __FILE__, __LINE__)
105
106 /**
107  * Check that a resource (@res) is present, resolved, and has a local path
108  * (within @dev's mount point) of @path.
109  */
110 #define check_resolved_local_resource(res, dev, path) \
111         __check_resolved_local_resource(res, dev, path, __FILE__, __LINE__)
112
113 void __check_resolved_local_resource(struct resource *res,
114                 struct discover_device *dev, const char *local_path,
115                 const char *file, int line);
116
117 /**
118  * Check that a resource (@res) is present, resolved, and has a URL of
119  * @url.
120  */
121 #define check_resolved_url_resource(res, url) \
122         __check_resolved_url_resource(res, url, __FILE__, __LINE__)
123 void __check_resolved_url_resource(struct resource *res,
124                 const char *url, const char *file, int line);
125 /**
126  * Check that a resource (@res) is present but not resolved
127  */
128 void __check_unresolved_resource(struct resource *res,
129                 const char *file, int line);
130 #define check_unresolved_resource(res) \
131         __check_unresolved_resource(res, __FILE__, __LINE__)
132
133 /**
134  * Check that a resource (@res) is not present
135  */
136 void __check_not_present_resource(struct resource *res,
137                 const char *file, int line);
138 #define check_not_present_resource(res) \
139         __check_not_present_resource(res, __FILE__, __LINE__)
140
141 /**
142  * Check the contents of a file - file @filename must be present on @dev,
143  * and match the @len bytes of @buf.
144  */
145 void __check_file_contents(struct parser_test *test,
146                 struct discover_device *dev, const char *filename,
147                 const char *buf, int len,
148                 const char *srcfile, int srcline);
149 #define check_file_contents(test, dev, filename, buf, len) \
150         __check_file_contents(test, dev, filename, buf, len, __FILE__, __LINE__)
151
152 #endif /* PARSER_TEST_H */