mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-23 02:01:55 +00:00
Birdtest: improve bt_check macro
Now dat for testing can be defined somelike this: struct in_out_data_ { char *in; u32 out; } in_out_data[] = { { .in = "192.168.1.128", .out = build_ip4(192, 168, 1, 128), }, { .in = "255.255.255.255", .out = build_ip4(255, 255, 255, 255), }, ... }; bt_check(ip4_pton_, in_out_data, "%s", "0x%08X");
This commit is contained in:
parent
1bdf2a54ed
commit
e7bb2daf1f
@ -101,7 +101,7 @@ check_log2(u32 n)
|
||||
u32 low = pow2(log);
|
||||
u32 high = pow2(log+1);
|
||||
|
||||
bt_debug("Test u32_log2(%u) = %u, %u should be in <%u, %u) \n", n, log, n, low, high);
|
||||
bt_debug("Test u32_log2(%u) = %u, %u should be in the range <%u, %u) \n", n, log, n, low, high);
|
||||
bt_assert(n >= low && n < high);
|
||||
}
|
||||
|
||||
@ -110,14 +110,17 @@ t_log2(void)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
u32 in[31];
|
||||
u32 expected[31];
|
||||
struct in_out_data_ {
|
||||
u32 in;
|
||||
u32 out;
|
||||
} in_out_data[31];
|
||||
|
||||
for (i = 0; i < 31; i++)
|
||||
{
|
||||
in[i] = pow2(i+1);
|
||||
expected[i] = i+1;
|
||||
in_out_data[i].in = pow2(i+1);
|
||||
in_out_data[i].out = i+1;
|
||||
}
|
||||
bt_check(u32_log2, in, expected, 31);
|
||||
bt_check(u32_log2, in_out_data, "%u", "%u");
|
||||
|
||||
u32_log2(0);
|
||||
|
||||
@ -139,6 +142,5 @@ main(int argc, char *argv[])
|
||||
bt_test_case(t_masklen, "u32_masklen()");
|
||||
bt_test_case(t_log2, "u32_log2()");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -59,19 +59,16 @@ int bt_rand_num(void);
|
||||
#define bt_syscall(test,format, ...) \
|
||||
do { if (test) { bt_log(format ": %s", ##__VA_ARGS__, strerror(errno)); exit(3); } } while (0)
|
||||
|
||||
#define bt_check(fn, in_arr, expected_arr, len) \
|
||||
do { \
|
||||
unsigned int bt_i_; \
|
||||
for (bt_i_ = 0; bt_i_ < len; bt_i_++) \
|
||||
#define bt_check(fn, in_out, in_fmt, out_fmt) \
|
||||
do \
|
||||
{ \
|
||||
bt_debug("%s(%u) = %u", #fn, in_arr[bt_i_], fn(in_arr[bt_i_])); \
|
||||
if(fn(in_arr[bt_i_]) != expected_arr[bt_i_]) \
|
||||
unsigned int bt_i; \
|
||||
for (bt_i = 0; bt_i < (sizeof(in_out)/sizeof(in_out[0])); bt_i++) \
|
||||
{ \
|
||||
bt_debug(", expected %u FAIL! \n", expected_arr[bt_i_]); \
|
||||
bt_abort_msg("%s(%u) = %u, but expected %u", #fn, in_arr[bt_i_], fn(in_arr[bt_i_]), expected_arr[bt_i_]); \
|
||||
} \
|
||||
if (fn(in_out[bt_i].in) == in_out[bt_i].out) \
|
||||
bt_debug ("[ OK ] %s(" in_fmt ") got " out_fmt " \n", #fn, in_out[bt_i].in, fn(in_out[bt_i].in)); \
|
||||
else \
|
||||
bt_debug(" OK \n"); \
|
||||
bt_abort_msg("[FAIL] %s(" in_fmt ") got " out_fmt ", but was expected " out_fmt " \n", #fn, in_out[bt_i].in, fn(in_out[bt_i].in), in_out[bt_i].out); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user