Statistics
| Branch: | Revision:

iof-bird / bird-2.0.1 / filter / filter_test.c @ 6b3f1a54

History | View | Annotate | Download (1.64 KB)

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 "conf/conf.h"
21

    
22
#define BT_CONFIG_FILE "filter/test.conf"
23

    
24

    
25
static struct config *
26
parse_config_file(const void *filename_void)
27
{
28
  bt_bird_init();
29

    
30
  size_t fn_size = strlen((const char *) filename_void) + 1;
31
  char *filename = alloca(fn_size);
32
  strncpy(filename, filename_void, fn_size);
33

    
34
  struct config *c = bt_config_file_parse(filename);
35
  bt_bird_cleanup();
36

    
37
  return c;
38
}
39

    
40
static int
41
run_function(const void *parsed_fn_def)
42
{
43
  /* XXX: const -> non-const */
44
  struct f_inst *f = (struct f_inst *) parsed_fn_def;
45

    
46
  linpool *tmp = lp_new_default(&root_pool);
47
  struct f_val res = f_eval(f, tmp);
48
  rfree(tmp);
49

    
50
  if (res.type == T_RETURN && res.val.i >= F_REJECT)
51
    return 0;
52

    
53
  return 1;
54
}
55

    
56
static void
57
bt_assert_filter(int result, struct f_inst *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)", assert->lineno, (char *) assert->a2.p);
68
}
69

    
70
int
71
main(int argc, char *argv[])
72
{
73
  bt_init(argc, argv);
74

    
75
  struct config *c = parse_config_file(BT_CONFIG_FILE);
76

    
77
  if (c)
78
  {
79
    bt_assert_hook = bt_assert_filter;
80

    
81
    struct f_bt_test_suite *t;
82
    WALK_LIST(t, c->tests)
83
      bt_test_suite_base(run_function, t->fn_name, t->fn, BT_FORKING, BT_TIMEOUT, "%s", t->dsc);
84
  }
85

    
86
  return bt_exit_value();
87
}