]>
git.ipfire.org Git - thirdparty/bird.git/blob - filter/filter_test.c
4 * (c) 2015 CZ.NIC z.s.p.o.
6 * Can be freely distributed and used under the terms of the GNU GPL.
16 #include "test/birdtest.h"
17 #include "test/bt-utils.h"
19 #include "filter/filter.h"
20 #include "conf/conf.h"
22 #define BT_CONFIG_FILE "filter/test.conf"
25 static struct config
*
26 parse_config_file(const void *filename_void
)
30 size_t fn_size
= strlen((const char *) filename_void
) + 1;
31 char *filename
= alloca(fn_size
);
32 strncpy(filename
, filename_void
, fn_size
);
34 struct config
*c
= bt_config_file_parse(filename
);
41 run_function(const void *parsed_fn_def
)
43 /* XXX: const -> non-const */
44 struct f_inst
*f
= (struct f_inst
*) parsed_fn_def
;
46 linpool
*tmp
= lp_new_default(&root_pool
);
48 enum filter_return fret
= f_eval(f
, tmp
, &res
);
51 return (fret
< F_REJECT
);
55 bt_assert_filter(int result
, struct f_inst
*assert)
57 int bt_suit_case_result
= 1;
62 bt_suit_case_result
= 0;
65 bt_log_suite_case_result(bt_suit_case_result
, "Assertion at line %d (%s)", assert->lineno
, (char *) assert->a
[1].p
);
69 main(int argc
, char *argv
[])
73 struct config
*c
= parse_config_file(BT_CONFIG_FILE
);
77 bt_assert_hook
= bt_assert_filter
;
79 struct f_bt_test_suite
*t
;
80 WALK_LIST(t
, c
->tests
)
81 bt_test_suite_base(run_function
, t
->fn_name
, t
->fn
, BT_FORKING
, BT_TIMEOUT
, "%s", t
->dsc
);
84 return bt_exit_value();