]> git.ozlabs.org Git - petitboot/blob - test/parser/parser-test.h
discover: Change parsers to explicitly request configuration files
[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         struct config *config;
14         struct {
15                 void    *buf;
16                 size_t  size;
17         } conf;
18 };
19
20 /* interface required for parsers */
21 void __register_parser(struct parser *parser);
22
23 /* test functions */
24 struct discover_device *test_create_device(struct parser_test *test,
25                 const char *name);
26
27 #define test_read_conf_data(t, d) \
28         __test_read_conf_data(t, d, sizeof(d))
29
30 void __test_read_conf_data(struct parser_test *test,
31                 const char *buf, size_t len);
32 void test_read_conf_file(struct parser_test *test, const char *filename);
33 void test_set_conf_source(struct parser_test *test, const char *url);
34
35 int test_run_parser(struct parser_test *test, const char *parser_name);
36
37 void test_hotplug_device(struct parser_test *test, struct discover_device *dev);
38
39 void test_add_file_data(struct parser_test *test, struct discover_device *dev,
40                 const char *filename, const void *data, int size);
41
42 #define test_add_file_string(test, dev, filename, str) \
43         test_add_file_data(test, dev, filename, str, sizeof(str) - 1)
44
45 struct discover_boot_option *get_boot_option(struct discover_context *ctx,
46                 int idx);
47
48 /* embedded config */
49 extern const char __embedded_config[];
50 extern const size_t __embedded_config_size;
51 #define test_read_conf_embedded(t) \
52         __test_read_conf_data(t, __embedded_config, __embedded_config_size)
53
54 /**
55  * Checks for parser results.
56  *
57  * These return void, but will respond to check failures by printing a reason
58  * for the failure, and exit the test with a non-zero exit status.
59  */
60
61 /**
62  * Check that we have an expected number of boot options parsed. If not,
63  * print out what we did find, then exit.
64  */
65 #define check_boot_option_count(ctx, count) \
66         __check_boot_option_count(ctx, count, __FILE__, __LINE__)
67 void __check_boot_option_count(struct discover_context *ctx, int count,
68                 const char *file, int line);
69 /*
70  * Check that a boot option @opt has args @args
71  */
72 void __check_args(struct discover_boot_option *opt, const char *args,
73                 const char *file, int line);
74 #define check_args(opt, args) \
75         __check_args(opt, args, __FILE__, __LINE__)
76
77 /**
78  * Check that a boot option @opt has name @name
79  */
80 void __check_name(struct discover_boot_option *opt, const char *name,
81                 const char *file, int line);
82 #define check_name(opt, name) \
83         __check_name(opt, name, __FILE__, __LINE__)
84
85 /**
86  * Check that a boot option @opt is marked as default
87  */
88 void __check_is_default(struct discover_boot_option *opt,
89                 const char *file, int line);
90 #define check_is_default(opt) \
91         __check_is_default(opt, __FILE__, __LINE__)
92
93 /**
94  * Check that a resource (@res) is present, resolved, and has a local path
95  * (within @dev's mount point) of @path.
96  */
97 #define check_resolved_local_resource(res, dev, path) \
98         __check_resolved_local_resource(res, dev, path, __FILE__, __LINE__)
99
100 void __check_resolved_local_resource(struct resource *res,
101                 struct discover_device *dev, const char *local_path,
102                 const char *file, int line);
103
104 /**
105  * Check that a resource (@res) is present, resolved, and has a URL of
106  * @url.
107  */
108 #define check_resolved_url_resource(res, url) \
109         __check_resolved_url_resource(res, url, __FILE__, __LINE__)
110 void __check_resolved_url_resource(struct resource *res,
111                 const char *url, const char *file, int line);
112 /**
113  * Check that a resource (@res) is present but not resolved
114  */
115 void __check_unresolved_resource(struct resource *res,
116                 const char *file, int line);
117 #define check_unresolved_resource(res) \
118         __check_unresolved_resource(res, __FILE__, __LINE__)
119
120 /**
121  * Check that a resource (@res) is not present
122  */
123 void __check_not_present_resource(struct resource *res,
124                 const char *file, int line);
125 #define check_not_present_resource(res) \
126         __check_not_present_resource(res, __FILE__, __LINE__)
127
128 /**
129  * Check the contents of a file - file @filename must be present on @dev,
130  * and match the @len bytes of @buf.
131  */
132 void __check_file_contents(struct parser_test *test,
133                 struct discover_device *dev, const char *filename,
134                 const char *buf, int len,
135                 const char *srcfile, int srcline);
136 #define check_file_contents(test, dev, filename, buf, len) \
137         __check_file_contents(test, dev, filename, buf, len, __FILE__, __LINE__)
138
139 #endif /* PARSER_TEST_H */