]> git.ozlabs.org Git - petitboot/blob - test/parser/parser-test.h
test/parser: Add check_name helper
[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 struct discover_boot_option *get_boot_option(struct discover_context *ctx,
35                 int idx);
36
37 /* embedded config */
38 extern const char __embedded_config[];
39 extern const size_t __embedded_config_size;
40 #define test_read_conf_embedded(t) \
41         __test_read_conf_data(t, __embedded_config, __embedded_config_size)
42
43 /**
44  * Checks for parser results.
45  *
46  * These return void, but will respond to check failures by printing a reason
47  * for the failure, and exit the test with a non-zero exit status.
48  */
49
50 /**
51  * Check that we have an expected number of boot options parsed. If not,
52  * print out what we did find, then exit.
53  */
54 #define check_boot_option_count(ctx, count) \
55         __check_boot_option_count(ctx, count, __FILE__, __LINE__)
56 void __check_boot_option_count(struct discover_context *ctx, int count,
57                 const char *file, int line);
58 /*
59  * Check that a boot option @opt has args @args
60  */
61 void __check_args(struct discover_boot_option *opt, const char *args,
62                 const char *file, int line);
63 #define check_args(opt, args) \
64         __check_args(opt, args, __FILE__, __LINE__)
65
66 /**
67  * Check that a boot option @opt has name @name
68  */
69 void __check_name(struct discover_boot_option *opt, const char *name,
70                 const char *file, int line);
71 #define check_name(opt, name) \
72         __check_name(opt, name, __FILE__, __LINE__)
73
74 #endif /* PARSER_TEST_H */