]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Test: Improve filter_test
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Mon, 16 Dec 2019 23:01:53 +0000 (00:01 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Mon, 16 Dec 2019 23:01:53 +0000 (00:01 +0100)
Initial parsing of test.conf must be done directly in filter_test main,
while reconfiguration is handled as a regular test. Also fix several
minor issues in test code.

filter/filter_test.c
filter/test.conf
test/birdtest.c
test/birdtest.h
test/bt-utils.c

index 7adc480fad46cfa8f313cc22fbe0127b21c28b47..7e4af092bc6d59ebbc0a6c5c6112d30e75fa7e6d 100644 (file)
 #define BT_CONFIG_FILE "filter/test.conf"
 
 
-struct parse_config_file_arg {
-  struct config **cp;
-  const char *filename;
-};
-
 static int
-parse_config_file(const void *argv)
+t_reconfig(void)
 {
-  const struct parse_config_file_arg *arg = argv;
-  size_t fn_size = strlen(arg->filename) + 1;
-  char *filename = alloca(fn_size);
-  memcpy(filename, arg->filename, fn_size);
-  
-  *(arg->cp) = bt_config_file_parse(filename);
-  return !!*(arg->cp);
+  if (!bt_config_file_parse(BT_CONFIG_FILE))
+    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;
 }
 
 static int
@@ -75,27 +72,18 @@ int
 main(int argc, char *argv[])
 {
   bt_init(argc, argv);
-
   bt_bird_init();
-  
-  bt_assert_hook = bt_assert_filter;
-
-  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");
-  bt_assert(c);
+  bt_assert_hook = bt_assert_filter;
 
-  bt_test_suite_base(parse_config_file, "reconf", (const void *) &pcfa, 0, 0, "reconfigure with the same file");
-  bt_assert(c);
+  /* Initial test.conf parsing, must be done here */
+  if (!bt_config_file_parse(BT_CONFIG_FILE))
+    abort();
 
-  struct symbol *s;
-  WALK_LIST(s, c->symbols)
-    if ((s->class == SYM_FUNCTION) || (s->class == SYM_FILTER))
-      bt_assert_msg((s->flags & SYM_FLAG_SAME), "Symbol %s same check", s->name);
+  bt_test_suite(t_reconfig, "Testing reconfiguration");
 
   struct f_bt_test_suite *t;
-  WALK_LIST(t, c->tests)
+  WALK_LIST(t, config->tests)
     bt_test_suite_base(run_function, t->fn_name, t, BT_FORKING, BT_TIMEOUT, "%s", t->dsc);
 
   bt_bird_cleanup();
index 7152ee72f5ccb9b12677742be3408e6cda6bb39e..d0941e11117646a4ef288162d36c28557b190d9a 100644 (file)
@@ -1271,10 +1271,9 @@ protocol static
   route 2001:0db8:85a3:8a2e::/64 max 96 as 1000;
 }
 
-function test_roa_check()
+function t_roa_check()
 prefix pfx;
 {
-       # cannot be tested in __startup(), sorry
        bt_assert(roa_check(r4, 10.10.0.0/16, 1000) = ROA_UNKNOWN);
        bt_assert(roa_check(r4, 10.0.0.0/8, 1000) = ROA_UNKNOWN);
        bt_assert(roa_check(r4, 10.110.0.0/16, 1000) = ROA_VALID);
@@ -1329,7 +1328,10 @@ prefix pfx;
        bt_assert(pfx.asn = 1234);
 }
 
-bt_test_suite(test_roa_check, "Testing ROA");
+bt_test_suite(t_roa_check, "Testing ROA");
+
+
+
 
 /*
  *      Testing Mixed Net Types
index 9e258c80ad89788c740e03de4e0421a85efce647..a092446a6a9b65ada63ad44c71bbfeb534d3bd57 100644 (file)
@@ -117,6 +117,7 @@ bt_init(int argc, char *argv[])
   }
 
   clock_gettime(CLOCK_MONOTONIC, &bt_begin);
+  bt_suite_case_begin = bt_suite_begin = bt_begin;
 
   return;
 
@@ -198,14 +199,13 @@ bt_log_result(int result, u64 time, const char *fmt, va_list argptr)
   static char msg_buf[BT_BUFFER_SIZE];
   char *pos;
 
-  snprintf(msg_buf, sizeof(msg_buf), "%s%s%s%s %" PRIu64 ".%09" PRIu64 "s",
+  snprintf(msg_buf, sizeof(msg_buf), "%s%s%s %" PRIu64 ".%09" PRIu64 "s%s",
           bt_filename,
           bt_test_id ? ": " : "",
           bt_test_id ? bt_test_id : "",
-          (fmt && strlen(fmt) > 0) ? ": " : "",
           time / 1000000000,
-          time % 1000000000
-          );
+          time % 1000000000,
+          (fmt && strlen(fmt) > 0) ? ": " : "");
   pos = msg_buf + strlen(msg_buf);
 
   if (fmt)
@@ -339,6 +339,7 @@ bt_test_suite_base(int (*fn)(const void *), const char *id, const void *fn_arg,
     bt_log("Starting");
 
   clock_gettime(CLOCK_MONOTONIC, &bt_suite_begin);
+  bt_suite_case_begin = bt_suite_begin;
 
   if (!forked)
   {
index dacfb0952508b7037ba14f87347ca477b1de1de9..caec529b5bc90437ea1bde17a1cba9019d58e8c4 100644 (file)
@@ -101,12 +101,12 @@ static inline int bt_test_fn_noarg(const void *cp) { return ((int (*)(void)) cp)
 #define bt_assert_msg(test, format, ...)                               \
   do                                                                   \
   {                                                                    \
-    int bt_suit_case_result = 1;                               \
+    int bt_suit_case_result = 1;                                       \
     if ((test) == 0)                                                   \
     {                                                                  \
-      bt_result = 0;                                           \
-      bt_suite_result = 0;                                     \
-      bt_suit_case_result = 0;                                 \
+      bt_result = 0;                                                   \
+      bt_suite_result = 0;                                             \
+      bt_suit_case_result = 0;                                         \
     }                                                                  \
     bt_log_suite_case_result(bt_suit_case_result, format, ##__VA_ARGS__); \
   } while (0)
index 7653abf64f0ae35abf433f6d79767ffabc45f1a3..cbca3a6b1a2a1735a0e175819024cdc3494db4f5 100644 (file)
@@ -154,7 +154,7 @@ bt_config_parse__(struct config *cfg)
 
   if (cfg->err_msg)
   {
-    bt_debug("Parse error %s, line %d: %s\n", cfg->err_file_name, cfg->err_lino, cfg->err_msg);
+    bt_log("Parse error %s, line %d: %s", cfg->err_file_name, cfg->err_lino, cfg->err_msg);
     bt_show_cfg_error(cfg);
     return NULL;
   }