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);
}
{
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);
bt_test_case(t_masklen, "u32_masklen()");
bt_test_case(t_log2, "u32_log2()");
-
return 0;
}
#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 \
+ { \
+ unsigned int bt_i; \
+ for (bt_i = 0; bt_i < (sizeof(in_out)/sizeof(in_out[0])); bt_i++) \
{ \
- 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_]) \
- { \
- 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_]); \
- } \
- else \
- bt_debug(" OK \n"); \
+ 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_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)