2016-11-09 15:36:34 +00:00
|
|
|
/*
|
|
|
|
* Filters: Tests
|
|
|
|
*
|
|
|
|
* (c) 2015 CZ.NIC z.s.p.o.
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "test/birdtest.h"
|
|
|
|
#include "test/bt-utils.h"
|
|
|
|
|
|
|
|
#include "filter/filter.h"
|
2019-02-08 12:38:12 +00:00
|
|
|
#include "filter/data.h"
|
2019-02-07 20:25:38 +00:00
|
|
|
#include "filter/f-inst.h"
|
2016-11-09 15:36:34 +00:00
|
|
|
#include "conf/conf.h"
|
|
|
|
|
|
|
|
#define BT_CONFIG_FILE "filter/test.conf"
|
|
|
|
|
|
|
|
|
2019-01-30 13:03:47 +00:00
|
|
|
static int
|
2023-06-23 07:05:48 +00:00
|
|
|
t_reconfig(const void *arg)
|
2019-01-30 13:03:47 +00:00
|
|
|
{
|
2023-06-23 07:05:48 +00:00
|
|
|
if (!bt_config_file_parse(arg))
|
2019-12-16 23:01:53 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
struct symbol *s;
|
|
|
|
WALK_LIST(s, config->symbols)
|
|
|
|
if ((s->class == SYM_FUNCTION) || (s->class == SYM_FILTER))
|
|
|
|
bt_assert_msg((s->flags & SYM_FLAG_SAME), "Symbol %s same check", s->name);
|
|
|
|
|
|
|
|
return 1;
|
2016-11-09 15:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-02-13 11:25:30 +00:00
|
|
|
run_function(const void *arg)
|
2016-11-09 15:36:34 +00:00
|
|
|
{
|
2019-02-13 11:25:30 +00:00
|
|
|
const struct f_bt_test_suite *t = arg;
|
|
|
|
|
|
|
|
if (t->cmp)
|
|
|
|
return t->result == f_same(t->fn, t->cmp);
|
|
|
|
|
2022-03-02 09:59:52 +00:00
|
|
|
enum filter_return fret = f_eval(t->fn, tmp_linpool, NULL);
|
2016-11-09 15:36:34 +00:00
|
|
|
|
2018-12-17 12:51:11 +00:00
|
|
|
return (fret < F_REJECT);
|
2016-11-09 15:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-12-27 13:26:11 +00:00
|
|
|
bt_assert_filter(int result, const struct f_line_item *assert)
|
2016-11-09 15:36:34 +00:00
|
|
|
{
|
2016-11-11 16:43:09 +00:00
|
|
|
int bt_suit_case_result = 1;
|
2016-11-09 15:36:34 +00:00
|
|
|
if (!result)
|
|
|
|
{
|
2016-11-11 16:43:09 +00:00
|
|
|
bt_result = 0;
|
|
|
|
bt_suite_result = 0;
|
|
|
|
bt_suit_case_result = 0;
|
2016-11-09 15:36:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-15 22:59:44 +00:00
|
|
|
bt_log_suite_case_result(bt_suit_case_result, "Assertion at line %d (%s)",
|
|
|
|
assert->lineno, assert->i_FI_ASSERT.s);
|
2016-11-09 15:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
bt_init(argc, argv);
|
2019-01-30 13:03:47 +00:00
|
|
|
bt_bird_init();
|
2019-12-12 14:42:29 +00:00
|
|
|
|
2019-12-16 23:01:53 +00:00
|
|
|
bt_assert_hook = bt_assert_filter;
|
2019-12-12 14:42:29 +00:00
|
|
|
|
2019-12-16 23:01:53 +00:00
|
|
|
/* Initial test.conf parsing, must be done here */
|
|
|
|
if (!bt_config_file_parse(BT_CONFIG_FILE))
|
|
|
|
abort();
|
2019-01-30 13:03:47 +00:00
|
|
|
|
2023-06-23 07:05:48 +00:00
|
|
|
bt_test_suite_arg(t_reconfig, BT_CONFIG_FILE ".overlay", "Testing reconfiguration to overlay");
|
|
|
|
bt_test_suite_arg(t_reconfig, BT_CONFIG_FILE, "Testing reconfiguration back");
|
|
|
|
bt_test_suite_arg(t_reconfig, BT_CONFIG_FILE, "Testing reconfiguration to the same file");
|
2016-11-09 15:36:34 +00:00
|
|
|
|
2019-12-12 14:42:29 +00:00
|
|
|
struct f_bt_test_suite *t;
|
2019-12-16 23:01:53 +00:00
|
|
|
WALK_LIST(t, config->tests)
|
2019-12-12 14:42:29 +00:00
|
|
|
bt_test_suite_base(run_function, t->fn_name, t, BT_FORKING, BT_TIMEOUT, "%s", t->dsc);
|
2016-11-09 15:36:34 +00:00
|
|
|
|
2019-12-12 14:42:29 +00:00
|
|
|
bt_bird_cleanup();
|
2016-11-09 15:36:34 +00:00
|
|
|
return bt_exit_value();
|
|
|
|
}
|