Annotation of embedaddon/bird2/filter/filter_test.c, revision 1.1.1.1
1.1 misho 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: struct parse_config_file_arg {
28: struct config **cp;
29: const char *filename;
30: };
31:
32: static int
33: parse_config_file(const void *argv)
34: {
35: const struct parse_config_file_arg *arg = argv;
36: size_t fn_size = strlen(arg->filename) + 1;
37: char *filename = alloca(fn_size);
38: memcpy(filename, arg->filename, fn_size);
39:
40: *(arg->cp) = bt_config_file_parse(filename);
41: return !!*(arg->cp);
42: }
43:
44: static int
45: run_function(const void *arg)
46: {
47: const struct f_bt_test_suite *t = arg;
48:
49: if (t->cmp)
50: return t->result == f_same(t->fn, t->cmp);
51:
52: if (!f_same(t->fn, t->fn)) {
53: bt_result = bt_suite_result = 0;
54: bt_log_suite_case_result(0, "The function doesn't compare to itself as the same");
55: return 0;
56: }
57:
58: linpool *tmp = lp_new_default(&root_pool);
59: enum filter_return fret = f_eval(t->fn, tmp, NULL);
60: rfree(tmp);
61:
62: return (fret < F_REJECT);
63: }
64:
65: static void
66: bt_assert_filter(int result, const struct f_line_item *assert)
67: {
68: int bt_suit_case_result = 1;
69: if (!result)
70: {
71: bt_result = 0;
72: bt_suite_result = 0;
73: bt_suit_case_result = 0;
74: }
75:
76: bt_log_suite_case_result(bt_suit_case_result, "Assertion at line %d (%s)",
77: assert->lineno, assert->i_FI_ASSERT.s);
78: }
79:
80: int
81: main(int argc, char *argv[])
82: {
83: bt_init(argc, argv);
84: bt_bird_init();
85:
86: bt_assert_hook = bt_assert_filter;
87:
88: struct config *c = NULL;
89: struct parse_config_file_arg pcfa = { .cp = &c, .filename = BT_CONFIG_FILE };
90: bt_test_suite_base(parse_config_file, "conf", (const void *) &pcfa, 0, 0, "parse config file");
91: bt_test_suite_base(parse_config_file, "reconf", (const void *) &pcfa, 0, 0, "reconfigure with the same file");
92:
93: bt_bird_cleanup();
94:
95: if (c)
96: {
97: struct f_bt_test_suite *t;
98: WALK_LIST(t, c->tests)
99: bt_test_suite_base(run_function, t->fn_name, t, BT_FORKING, BT_TIMEOUT, "%s", t->dsc);
100: }
101:
102: return bt_exit_value();
103: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>