2016-11-09 23:36:34 +08: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 20:38:12 +08:00
|
|
|
#include "filter/data.h"
|
2019-02-08 04:25:38 +08:00
|
|
|
#include "filter/f-inst.h"
|
2016-11-09 23:36:34 +08:00
|
|
|
#include "conf/conf.h"
|
|
|
|
|
|
|
|
#define BT_CONFIG_FILE "filter/test.conf"
|
|
|
|
|
|
|
|
|
2019-01-30 21:03:47 +08:00
|
|
|
struct parse_config_file_arg {
|
|
|
|
struct config **cp;
|
|
|
|
const char *filename;
|
|
|
|
};
|
2016-11-09 23:36:34 +08:00
|
|
|
|
2019-01-30 21:03:47 +08:00
|
|
|
static int
|
|
|
|
parse_config_file(const void *argv)
|
|
|
|
{
|
|
|
|
const struct parse_config_file_arg *arg = argv;
|
|
|
|
size_t fn_size = strlen(arg->filename) + 1;
|
2016-11-09 23:36:34 +08:00
|
|
|
char *filename = alloca(fn_size);
|
2019-02-08 18:19:04 +08:00
|
|
|
memcpy(filename, arg->filename, fn_size);
|
2019-01-30 21:03:47 +08:00
|
|
|
|
|
|
|
*(arg->cp) = bt_config_file_parse(filename);
|
|
|
|
return !!*(arg->cp);
|
2016-11-09 23:36:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-02-13 19:25:30 +08:00
|
|
|
run_function(const void *arg)
|
2016-11-09 23:36:34 +08:00
|
|
|
{
|
2019-02-13 19:25:30 +08:00
|
|
|
const struct f_bt_test_suite *t = arg;
|
|
|
|
|
|
|
|
if (t->cmp)
|
|
|
|
return t->result == f_same(t->fn, t->cmp);
|
|
|
|
|
|
|
|
if (!f_same(t->fn, t->fn)) {
|
|
|
|
bt_result = bt_suite_result = 0;
|
|
|
|
bt_log_suite_case_result(0, "The function doesn't compare to itself as the same");
|
|
|
|
return 0;
|
|
|
|
}
|
2016-11-09 23:36:34 +08:00
|
|
|
|
2017-05-16 20:31:16 +08:00
|
|
|
linpool *tmp = lp_new_default(&root_pool);
|
2018-12-17 20:51:11 +08:00
|
|
|
struct f_val res;
|
2019-02-13 19:25:30 +08:00
|
|
|
enum filter_return fret = f_eval(t->fn, tmp, &res);
|
2016-11-09 23:36:34 +08:00
|
|
|
rfree(tmp);
|
|
|
|
|
2018-12-17 20:51:11 +08:00
|
|
|
return (fret < F_REJECT);
|
2016-11-09 23:36:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-12-27 21:26:11 +08:00
|
|
|
bt_assert_filter(int result, const struct f_line_item *assert)
|
2016-11-09 23:36:34 +08:00
|
|
|
{
|
2016-11-12 00:43:09 +08:00
|
|
|
int bt_suit_case_result = 1;
|
2016-11-09 23:36:34 +08:00
|
|
|
if (!result)
|
|
|
|
{
|
2016-11-12 00:43:09 +08:00
|
|
|
bt_result = 0;
|
|
|
|
bt_suite_result = 0;
|
|
|
|
bt_suit_case_result = 0;
|
2016-11-09 23:36:34 +08:00
|
|
|
}
|
|
|
|
|
2019-02-16 06:59:44 +08: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 23:36:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
bt_init(argc, argv);
|
2019-01-30 21:03:47 +08:00
|
|
|
bt_bird_init();
|
|
|
|
|
|
|
|
bt_assert_hook = bt_assert_filter;
|
2016-11-09 23:36:34 +08:00
|
|
|
|
2019-01-30 21:03:47 +08:00
|
|
|
struct config *c = NULL;
|
|
|
|
struct parse_config_file_arg pcfa = { .cp = &c, .filename = BT_CONFIG_FILE };
|
|
|
|
bt_test_suite_base(parse_config_file, "conf", (const void *) &pcfa, 0, 0, "parse config file");
|
2019-02-13 19:25:30 +08:00
|
|
|
bt_test_suite_base(parse_config_file, "reconf", (const void *) &pcfa, 0, 0, "reconfigure with the same file");
|
2019-01-30 21:03:47 +08:00
|
|
|
|
|
|
|
bt_bird_cleanup();
|
2016-11-09 23:36:34 +08:00
|
|
|
|
|
|
|
if (c)
|
|
|
|
{
|
|
|
|
struct f_bt_test_suite *t;
|
|
|
|
WALK_LIST(t, c->tests)
|
2019-02-13 19:25:30 +08:00
|
|
|
bt_test_suite_base(run_function, t->fn_name, t, BT_FORKING, BT_TIMEOUT, "%s", t->dsc);
|
2016-11-09 23:36:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return bt_exit_value();
|
|
|
|
}
|