mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-02-02 14:20:01 +00:00
nest/proto.c: if reload called on not-UP protocol, it logs that no reload will be done
birdtest: in unit tests, function bt_assert_bug() checks if given code calls bug() with given message
This commit is contained in:
parent
d0512ba74b
commit
0bcb1f9746
@ -2,6 +2,6 @@ src := bitmap.c bitops.c blake2s.c blake2b.c checksum.c event.c flowspec.c idm.c
|
||||
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)
|
||||
|
@ -9,6 +9,8 @@
|
||||
#ifndef _BIRD_BIRDLIB_H_
|
||||
#define _BIRD_BIRDLIB_H_
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "lib/alloca.h"
|
||||
|
||||
/* Ugly structure offset handling macros */
|
||||
@ -43,6 +45,13 @@ struct align_probe { char x; long int y; };
|
||||
#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); }
|
||||
|
||||
|
@ -2233,7 +2233,10 @@ proto_cmd_reload(struct proto *p, uintptr_t dir, int cnt UNUSED)
|
||||
|
||||
/* 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)
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "nest/cli.h"
|
||||
@ -336,6 +337,8 @@ log_rl(struct tbf *f, const char *msg, ...)
|
||||
void
|
||||
bug(const char *msg, ...)
|
||||
{
|
||||
if (build_target == BT_TEST)
|
||||
longjmp(*get_test_bug_jump(msg), 1);
|
||||
va_list args;
|
||||
|
||||
va_start(args, msg);
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include "unix.h"
|
||||
#include "krt.h"
|
||||
|
||||
const enum build_target build_target = BT_BIRD;
|
||||
|
||||
/*
|
||||
* Debugging
|
||||
*/
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/resource.h>
|
||||
@ -31,6 +32,8 @@
|
||||
#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;
|
||||
@ -51,6 +54,9 @@ const char *bt_test_id;
|
||||
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;
|
||||
|
||||
@ -417,6 +423,35 @@ bt_exit_value(void)
|
||||
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
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "nest/bird.h"
|
||||
|
||||
@ -31,7 +32,8 @@ extern const char *bt_filename;
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user