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