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