]>
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" | |
4f082dfa | 20 | #include "filter/data.h" |
8bdb05ed | 21 | #include "filter/f-inst.h" |
9b0a0ba9 OZ |
22 | #include "conf/conf.h" |
23 | ||
24 | #define BT_CONFIG_FILE "filter/test.conf" | |
25 | ||
26 | ||
c0e958e0 | 27 | static int |
3dabf7b8 | 28 | t_reconfig(void) |
c0e958e0 | 29 | { |
3dabf7b8 OZ |
30 | if (!bt_config_file_parse(BT_CONFIG_FILE)) |
31 | return 0; | |
32 | ||
33 | struct symbol *s; | |
34 | WALK_LIST(s, config->symbols) | |
35 | if ((s->class == SYM_FUNCTION) || (s->class == SYM_FILTER)) | |
36 | bt_assert_msg((s->flags & SYM_FLAG_SAME), "Symbol %s same check", s->name); | |
37 | ||
38 | return 1; | |
9b0a0ba9 OZ |
39 | } |
40 | ||
41 | static int | |
132529ce | 42 | run_function(const void *arg) |
9b0a0ba9 | 43 | { |
132529ce MM |
44 | const struct f_bt_test_suite *t = arg; |
45 | ||
46 | if (t->cmp) | |
47 | return t->result == f_same(t->fn, t->cmp); | |
48 | ||
d814a8cb | 49 | enum filter_return fret = f_eval(t->fn, tmp_linpool, NULL); |
9b0a0ba9 | 50 | |
7afa1438 | 51 | return (fret < F_REJECT); |
9b0a0ba9 OZ |
52 | } |
53 | ||
54 | static void | |
4c553c5a | 55 | bt_assert_filter(int result, const struct f_line_item *assert) |
9b0a0ba9 | 56 | { |
5e3cd0e5 | 57 | int bt_suit_case_result = 1; |
9b0a0ba9 OZ |
58 | if (!result) |
59 | { | |
5e3cd0e5 PT |
60 | bt_result = 0; |
61 | bt_suite_result = 0; | |
62 | bt_suit_case_result = 0; | |
9b0a0ba9 OZ |
63 | } |
64 | ||
ea4f55e3 MM |
65 | bt_log_suite_case_result(bt_suit_case_result, "Assertion at line %d (%s)", |
66 | assert->lineno, assert->i_FI_ASSERT.s); | |
9b0a0ba9 OZ |
67 | } |
68 | ||
69 | int | |
70 | main(int argc, char *argv[]) | |
71 | { | |
72 | bt_init(argc, argv); | |
c0e958e0 | 73 | bt_bird_init(); |
d3aa4f2a | 74 | |
3dabf7b8 | 75 | bt_assert_hook = bt_assert_filter; |
d3aa4f2a | 76 | |
3dabf7b8 OZ |
77 | /* Initial test.conf parsing, must be done here */ |
78 | if (!bt_config_file_parse(BT_CONFIG_FILE)) | |
79 | abort(); | |
c0e958e0 | 80 | |
3dabf7b8 | 81 | bt_test_suite(t_reconfig, "Testing reconfiguration"); |
9b0a0ba9 | 82 | |
d3aa4f2a | 83 | struct f_bt_test_suite *t; |
3dabf7b8 | 84 | WALK_LIST(t, config->tests) |
d3aa4f2a | 85 | bt_test_suite_base(run_function, t->fn_name, t, BT_FORKING, BT_TIMEOUT, "%s", t->dsc); |
9b0a0ba9 | 86 | |
d3aa4f2a | 87 | bt_bird_cleanup(); |
9b0a0ba9 OZ |
88 | return bt_exit_value(); |
89 | } |