]> git.ozlabs.org Git - petitboot/blob - test/parser/parser-test.h
autotools: Fix make maintainer-clean
[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
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
36 struct discover_boot_option *get_boot_option(struct discover_context *ctx,
37                 int idx);
38
39 /* embedded config */
40 extern const char __embedded_config[];
41 extern const size_t __embedded_config_size;
42 #define test_read_conf_embedded(t) \
43         __test_read_conf_data(t, __embedded_config, __embedded_config_size)
44
45 /**
46  * Checks for parser results.
47  *
48  * These return void, but will respond to check failures by printing a reason
49  * for the failure, and exit the test with a non-zero exit status.
50  */
51
52 /**
53  * Check that we have an expected number of boot options parsed. If not,
54  * print out what we did find, then exit.
55  */
56 #define check_boot_option_count(ctx, count) \
57         __check_boot_option_count(ctx, count, __FILE__, __LINE__)
58 void __check_boot_option_count(struct discover_context *ctx, int count,
59                 const char *file, int line);
60 /*
61  * Check that a boot option @opt has args @args
62  */
63 void __check_args(struct discover_boot_option *opt, const char *args,
64                 const char *file, int line);
65 #define check_args(opt, args) \
66         __check_args(opt, args, __FILE__, __LINE__)
67
68 /**
69  * Check that a boot option @opt has name @name
70  */
71 void __check_name(struct discover_boot_option *opt, const char *name,
72                 const char *file, int line);
73 #define check_name(opt, name) \
74         __check_name(opt, name, __FILE__, __LINE__)
75
76 /**
77  * Check that a resource (@res) is present, resolved, and has a local path
78  * (within @dev's mount point) of @path.
79  */
80 #define check_resolved_local_resource(res, dev, path) \
81         __check_resolved_local_resource(res, dev, path, __FILE__, __LINE__)
82
83 void __check_resolved_local_resource(struct resource *res,
84                 struct discover_device *dev, const char *local_path,
85                 const char *file, int line);
86
87 /**
88  * Check that a resource (@res) is present but not resolved
89  */
90 void __check_unresolved_resource(struct resource *res,
91                 const char *file, int line);
92 #define check_unresolved_resource(res) \
93         __check_unresolved_resource(res, __FILE__, __LINE__)
94
95 /**
96  * Check that a resource (@res) is not present
97  */
98 void __check_not_present_resource(struct resource *res,
99                 const char *file, int line);
100 #define check_not_present_resource(res) \
101         __check_not_present_resource(res, __FILE__, __LINE__)
102
103 #endif /* PARSER_TEST_H */