]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Birdtest: Add Event Processing Tests
authorPavel Tvrdík <pawel.tvrdik@gmail.cz>
Fri, 3 Apr 2015 10:52:44 +0000 (12:52 +0200)
committerPavel Tvrdík <pawel.tvrdik@gmail.cz>
Fri, 3 Apr 2015 10:52:44 +0000 (12:52 +0200)
Add test/birdtest_support.h for provisional hack a build system

lib/event_test.c [new file with mode: 0644]
test/birdtest_support.h [new file with mode: 0644]

diff --git a/lib/event_test.c b/lib/event_test.c
new file mode 100644 (file)
index 0000000..6d69953
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ *     BIRD Library -- Event Processing Tests
+ *
+ *     (c) 2015 CZ.NIC z.s.p.o.
+ *
+ *     Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+
+#include "test/birdtest.h"
+#include "test/birdtest_support.h"     /* REMOVE ME */
+
+#include "lib/event.h"
+
+#define MAX_NUM 4
+
+int event_check_points[MAX_NUM];
+
+#define event_hook_body(num)                   \
+  do {                                                 \
+    bt_debug("Event Hook " #num "\n");         \
+    event_check_points[num] = 1;               \
+    bt_assert_msg(event_check_points[num-1], "Did not keep the right order!");         \
+  } while (0)
+
+static void event_hook_1(void *data) { event_hook_body(1); }
+static void event_hook_2(void *data) { event_hook_body(2); }
+static void event_hook_3(void *data) { event_hook_body(3); }
+
+#define schedule_event(num)                    \
+    do {                                       \
+      struct event *event_##num = ev_new(pool); \
+      event_##num->hook = event_hook_##num;    \
+      ev_schedule(event_##num);                        \
+    } while (0)
+
+static void
+init_event_check_points(void)
+{
+  int i;
+  event_check_points[0] = 1;
+  for (i = 1; i < MAX_NUM; i++)
+    event_check_points[i] = 0;
+}
+
+static int
+t_ev_run_list(void)
+{
+  int i;
+
+  resource_init();
+  init_list(&global_event_list);
+  struct pool *pool = rp_new(&root_pool, "Test pool");
+  init_event_check_points();
+
+  schedule_event(1);
+  schedule_event(2);
+  schedule_event(3);
+
+  ev_run_list(&global_event_list);
+
+  for (i = 1; i < MAX_NUM; i++)
+    bt_assert(event_check_points[i]);
+
+  return BT_SUCCESS;
+}
+
+int
+main(int argc, char *argv[])
+{
+  bt_init(argc, argv);
+
+  bt_test_case(t_ev_run_list, "Schedule and run 3 events in right order.");
+
+  return 0;
+}
+
diff --git a/test/birdtest_support.h b/test/birdtest_support.h
new file mode 100644 (file)
index 0000000..4554cf0
--- /dev/null
@@ -0,0 +1,25 @@
+#include "lib/event.c"                 /* REMOVE ME */
+#include "lib/ip.c"            /* REMOVE ME */
+#include "lib/resource.c"      /* REMOVE ME */
+#include "lib/printf.c"                /* REMOVE ME */
+#include "lib/xmalloc.c"       /* REMOVE ME */
+#include "lib/bitops.c"                /* REMOVE ME */
+
+void
+debug(const char *msg, ...)
+{
+  va_list argptr;
+  va_start(argptr, msg);
+  vfprintf(stderr, msg, argptr);
+  va_end(argptr);
+};
+
+void
+die(const char *msg, ...)
+{
+  va_list argptr;
+  va_start(argptr, msg);
+  vfprintf(stderr, msg, argptr);
+  va_end(argptr);
+  exit(3);
+};