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