birdtest: in unit tests, function bt_assert_bug() checks if given code calls bug() with given message
obj := $(src-o-files)
$(all-daemon)
-tests_src := bitmap_test.c heap_test.c buffer_test.c event_test.c flowspec_test.c bitops_test.c patmatch_test.c fletcher16_test.c slist_test.c checksum_test.c lists_test.c mac_test.c ip_test.c hash_test.c printf_test.c slab_test.c
+tests_src := bitmap_test.c heap_test.c buffer_test.c event_test.c flowspec_test.c bitops_test.c patmatch_test.c fletcher16_test.c slist_test.c checksum_test.c lists_test.c mac_test.c ip_test.c hash_test.c printf_test.c slab_test.c fail_test.c
tests_targets := $(tests_targets) $(tests-target-files)
tests_objs := $(tests_objs) $(src-o-files)
#ifndef _BIRD_BIRDLIB_H_
#define _BIRD_BIRDLIB_H_
+#include <setjmp.h>
+
#include "lib/alloca.h"
/* Ugly structure offset handling macros */
#define CALL(fn, args...) ({ if (fn) fn(args); })
#define ADVANCE(w, r, l) ({ r -= (l); w += (l); })
+extern const enum build_target {
+ BT_BIRD,
+ BT_TEST,
+} build_target;
+
+jmp_buf *get_test_bug_jump(char *msg);
+
static inline int uint_cmp(uint i1, uint i2)
{ return (int)(i1 > i2) - (int)(i1 < i2); }
/* If the protocol in not UP, it has no routes */
if (p->proto_state != PS_UP)
+ {
+ cli_msg(-8, "%s: not reloading - protocol is not UP", p->name);
return;
+ }
/* All channels must support reload */
if (dir != CMD_RELOAD_OUT)
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
+#include <setjmp.h>
#include "nest/bird.h"
#include "nest/cli.h"
void
bug(const char *msg, ...)
{
+ if (build_target == BT_TEST)
+ longjmp(*get_test_bug_jump(msg), 1);
va_list args;
va_start(args, msg);
#include "unix.h"
#include "krt.h"
+const enum build_target build_target = BT_BIRD;
+
/*
* Debugging
*/
#include <signal.h>
#include <time.h>
#include <unistd.h>
+#include <setjmp.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
#define sprintf_concat(s, format, ...) \
snprintf(s + strlen(s), sizeof(s) - strlen(s), format, ##__VA_ARGS__)
+const enum build_target build_target = BT_TEST;
+
static const char *request;
static int list_tests;
static int do_core;
int bt_result; /* Overall program run result */
int bt_suite_result; /* One suit result */
char bt_out_fmt_buf[1024]; /* Temporary memory buffer for output of testing function */
+jmp_buf bug_jump_buf;
+int bug_expected = 0;
+char *expected_bug_message;
struct timespec bt_begin, bt_suite_begin, bt_suite_case_begin;
return bt_result ? EXIT_SUCCESS : EXIT_FAILURE;
}
+/**
+ * It tests that given function calls bug with given error massage. Sets jump, and bug() function jumps back.
+*/
+int
+bt_assert_bug(void (*functionPtr)(void), char *expected_message)
+{
+ bug_expected = 1;
+ expected_bug_message = expected_message;
+ if (setjmp(bug_jump_buf))
+ {
+ bug_expected = 0;
+ expected_bug_message = "";
+ return 1;
+ }
+ else
+ (*functionPtr)();
+ bug_expected = 0;
+ expected_bug_message = "";
+ return 0;
+}
+
+jmp_buf *
+get_test_bug_jump(char *msg)
+{
+ if (!bug_expected || strcmp(msg, expected_bug_message) != 0)
+ abort();
+ return &bug_jump_buf;
+}
+
/**
* bt_assert_batch__ - test a batch of inputs/outputs tests
* @opts: includes all necessary data
#include <string.h>
#include <errno.h>
#include <sys/types.h>
+#include <setjmp.h>
#include "nest/bird.h"
extern const char *bt_test_id;
void bt_init(int argc, char *argv[]);
-int bt_exit_value(void);
+int bt_exit_value(void);
+int bt_assert_bug(void (*functionPtr)(void), char *msg);
void bt_reset_suite_case_timer(void);
int bt_test_suite_base(int (*test_fn)(const void *), const char *test_id, const void *test_fn_argument, int forked, int timeout, const char *dsc, ...);
static inline u64 bt_random(void)