]>
Commit | Line | Data |
---|---|---|
9b0a0ba9 OZ |
1 | /* |
2 | * Filters: Tests | |
3 | * | |
4 | * (c) 2015 CZ.NIC z.s.p.o. | |
5 | * | |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
9 | #ifndef _GNU_SOURCE | |
10 | #define _GNU_SOURCE | |
11 | #endif | |
12 | ||
13 | #include <string.h> | |
14 | #include <stdlib.h> | |
15 | ||
16 | #include "test/birdtest.h" | |
17 | #include "test/bt-utils.h" | |
18 | ||
19 | #include "filter/filter.h" | |
20 | #include "conf/conf.h" | |
21 | ||
22 | #define BT_CONFIG_FILE "filter/test.conf" | |
23 | ||
24 | ||
25 | static struct config * | |
26 | parse_config_file(const void *filename_void) | |
27 | { | |
28 | bt_bird_init(); | |
29 | ||
30 | size_t fn_size = strlen((const char *) filename_void) + 1; | |
31 | char *filename = alloca(fn_size); | |
32 | strncpy(filename, filename_void, fn_size); | |
33 | ||
34 | struct config *c = bt_config_file_parse(filename); | |
35 | bt_bird_cleanup(); | |
36 | ||
37 | return c; | |
38 | } | |
39 | ||
40 | static int | |
41 | run_function(const void *parsed_fn_def) | |
42 | { | |
43 | /* XXX: const -> non-const */ | |
44 | struct f_inst *f = (struct f_inst *) parsed_fn_def; | |
45 | ||
46 | linpool *tmp = lp_new(&root_pool, 4096); | |
47 | struct f_val res = f_eval(f, tmp); | |
48 | rfree(tmp); | |
49 | ||
50 | if (res.type == T_RETURN && res.val.i >= F_REJECT) | |
51 | return BT_FAILURE; | |
52 | ||
53 | return BT_SUCCESS; | |
54 | } | |
55 | ||
56 | static void | |
57 | bt_assert_filter(int result, struct f_inst *assert) | |
58 | { | |
59 | int bt_suit_case_result = BT_SUCCESS; | |
60 | if (!result) | |
61 | { | |
62 | bt_result = BT_FAILURE; | |
63 | bt_suite_result = BT_FAILURE; | |
64 | bt_suit_case_result = BT_FAILURE; | |
65 | } | |
66 | ||
67 | bt_log_suite_case_result(bt_suit_case_result, "Assertion at line %d (%s)", assert->lineno, (char *) assert->a2.p); | |
68 | } | |
69 | ||
70 | int | |
71 | main(int argc, char *argv[]) | |
72 | { | |
73 | bt_init(argc, argv); | |
74 | ||
75 | struct config *c = parse_config_file(BT_CONFIG_FILE); | |
76 | ||
77 | if (c) | |
78 | { | |
79 | bt_assert_hook = bt_assert_filter; | |
80 | ||
81 | struct f_bt_test_suite *t; | |
82 | WALK_LIST(t, c->tests) | |
83 | bt_test_suite_base(run_function, t->fn_name, t->fn, BT_FORKING, BT_TIMEOUT, "%s", t->dsc); | |
84 | } | |
85 | ||
86 | return bt_exit_value(); | |
87 | } |