]> git.ipfire.org Git - thirdparty/bird.git/blob - filter/filter_test.c
Filter: Remove mixed address tests and fix formatting
[thirdparty/bird.git] / filter / filter_test.c
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 "filter/data.h"
21 #include "filter/f-inst.h"
22 #include "conf/conf.h"
23
24 #define BT_CONFIG_FILE "filter/test.conf"
25
26
27 static int
28 t_reconfig(void)
29 {
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;
39 }
40
41 static int
42 run_function(const void *arg)
43 {
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
49 linpool *tmp = lp_new_default(&root_pool);
50 enum filter_return fret = f_eval(t->fn, tmp, NULL);
51 rfree(tmp);
52
53 return (fret < F_REJECT);
54 }
55
56 static void
57 bt_assert_filter(int result, const struct f_line_item *assert)
58 {
59 int bt_suit_case_result = 1;
60 if (!result)
61 {
62 bt_result = 0;
63 bt_suite_result = 0;
64 bt_suit_case_result = 0;
65 }
66
67 bt_log_suite_case_result(bt_suit_case_result, "Assertion at line %d (%s)",
68 assert->lineno, assert->i_FI_ASSERT.s);
69 }
70
71 int
72 main(int argc, char *argv[])
73 {
74 bt_init(argc, argv);
75 bt_bird_init();
76
77 bt_assert_hook = bt_assert_filter;
78
79 /* Initial test.conf parsing, must be done here */
80 if (!bt_config_file_parse(BT_CONFIG_FILE))
81 abort();
82
83 bt_test_suite(t_reconfig, "Testing reconfiguration");
84
85 struct f_bt_test_suite *t;
86 WALK_LIST(t, config->tests)
87 bt_test_suite_base(run_function, t->fn_name, t, BT_FORKING, BT_TIMEOUT, "%s", t->dsc);
88
89 bt_bird_cleanup();
90 return bt_exit_value();
91 }