Birdtest: Replace BT_SUCCESS and BT_FAILURE with 1 and 0

This commit is contained in:
Pavel Tvrdik 2016-11-11 17:43:09 +01:00
parent fa71b268a8
commit 5e3cd0e5b5
20 changed files with 100 additions and 104 deletions

View file

@ -48,20 +48,20 @@ run_function(const void *parsed_fn_def)
rfree(tmp);
if (res.type == T_RETURN && res.val.i >= F_REJECT)
return BT_FAILURE;
return 0;
return BT_SUCCESS;
return 1;
}
static void
bt_assert_filter(int result, struct f_inst *assert)
{
int bt_suit_case_result = BT_SUCCESS;
int bt_suit_case_result = 1;
if (!result)
{
bt_result = BT_FAILURE;
bt_suite_result = BT_FAILURE;
bt_suit_case_result = BT_FAILURE;
bt_result = 0;
bt_suite_result = 0;
bt_suit_case_result = 0;
}
bt_log_suite_case_result(bt_suit_case_result, "Assertion at line %d (%s)", assert->lineno, (char *) assert->a2.p);

View file

@ -174,7 +174,7 @@ t_balancing(void)
bt_assert(same_tree(balanced_tree_from_simple, expected_balanced_tree));
}
return BT_SUCCESS;
return 1;
}
@ -205,7 +205,7 @@ t_balancing_random(void)
}
}
return BT_SUCCESS;
return 1;
}
static int
@ -231,7 +231,7 @@ t_find(void)
}
}
return BT_SUCCESS;
return 1;
}
static uint
@ -287,7 +287,7 @@ t_find_ranges(void)
}
}
return BT_SUCCESS;
return 1;
}
int

View file

@ -130,7 +130,7 @@ t_match_net(void)
}
bt_bird_cleanup();
return BT_SUCCESS;
return 1;
}
static int
@ -170,7 +170,7 @@ t_trie_same(void)
}
}
return BT_SUCCESS;
return 1;
}
int

View file

@ -28,7 +28,7 @@ t_mkmask(void)
bt_assert_msg(compute == expect, "u32_mkmask(%d) = 0x%08X, expected 0x%08X", i, compute, expect);
}
return BT_SUCCESS;
return 1;
}
static int
@ -78,7 +78,7 @@ t_masklen(void)
for (i = 0; i <= MAX_NUM; i++)
check_mask(bt_random());
return BT_SUCCESS;
return 1;
}
static void
@ -107,7 +107,7 @@ t_log2(void)
for (i = 1; i < MAX_NUM; i++)
check_log2(((u32) bt_random()) % 0x0fffffff);
return BT_SUCCESS;
return 1;
}
int

View file

@ -69,7 +69,7 @@ t_buffer_push(void)
BUFFER_PUSH(buf) = expected[i];
is_buffer_as_expected(&buf);
return BT_SUCCESS;
return 1;
}
static int
@ -97,7 +97,7 @@ t_buffer_pop(void)
BUFFER_PUSH(buf) = expected[i];
is_buffer_as_expected(&buf);
return BT_SUCCESS;
return 1;
}
static int
@ -114,7 +114,7 @@ t_buffer_resize(void)
is_buffer_as_expected(&buf);
bt_assert(buf.size >= MAX_NUM);
return BT_SUCCESS;
return 1;
}
static int
@ -130,7 +130,7 @@ t_buffer_flush(void)
BUFFER_FLUSH(buf);
bt_assert(buf.used == 0);
return BT_SUCCESS;
return 1;
}
int

View file

@ -60,7 +60,7 @@ t_calculate(void)
bt_assert(sum_calculated == sum_expected);
return BT_SUCCESS;
return 1;
}
static int
@ -78,7 +78,7 @@ t_verify(void)
bt_assert(ipsum_verify(a, sizeof(a), NULL));
return BT_SUCCESS;
return 1;
}

View file

@ -73,7 +73,7 @@ t_ev_run_list(void)
for (i = 1; i < MAX_NUM; i++)
bt_assert(event_check_points[i]);
return BT_SUCCESS;
return 1;
}
int

View file

@ -55,7 +55,7 @@ test_fletcher16(void *out_, const void *in_, const void *expected_out_)
fletcher16_update(&ctxt, in, strlen(in));
put_u16(out, fletcher16_compute(&ctxt));
return (*out == *expected_out) ? BT_SUCCESS : BT_FAILURE;
return *out == *expected_out;
}
static int
@ -72,7 +72,7 @@ test_fletcher16_checksum(void *out_, const void *in_, const void *expected_out_)
fletcher16_update(&ctxt, in, len);
put_u16(out, fletcher16_final(&ctxt, len, len));
return (*out == *expected_out) ? BT_SUCCESS : BT_FAILURE;
return *out == *expected_out;
}
static int

View file

@ -129,7 +129,7 @@ t_insert_find(void)
fill_hash();
validate_filled_hash();
return BT_SUCCESS;
return 1;
}
static int
@ -148,7 +148,7 @@ t_insert_find_random(void)
validate_filled_hash();
return BT_SUCCESS;
return 1;
}
static int
@ -168,7 +168,7 @@ t_insert2_find(void)
validate_filled_hash();
return BT_SUCCESS;
return 1;
}
static int
@ -191,7 +191,7 @@ t_walk(void)
for (i = 0; i < MAX_NUM; i++)
bt_assert(check[i] == 1);
return BT_SUCCESS;
return 1;
}
static int
@ -208,7 +208,7 @@ t_walk_delsafe_delete(void)
validate_empty_hash();
return BT_SUCCESS;
return 1;
}
static int
@ -225,7 +225,7 @@ t_walk_delsafe_remove(void)
validate_empty_hash();
return BT_SUCCESS;
return 1;
}
static int
@ -242,7 +242,7 @@ t_walk_delsafe_delete2(void)
validate_empty_hash();
return BT_SUCCESS;
return 1;
}
static int
@ -259,7 +259,7 @@ t_walk_delsafe_remove2(void)
validate_empty_hash();
return BT_SUCCESS;
return 1;
}
static int
@ -283,7 +283,7 @@ t_walk_filter(void)
for (i = 0; i < MAX_NUM; i++)
bt_assert(check[i] == 1);
return BT_SUCCESS;
return 1;
}
int

View file

@ -82,7 +82,7 @@ t_heap_insert(void)
bt_assert(is_heap_valid(heap, num));
}
return BT_SUCCESS;
return 1;
}
static int
@ -110,7 +110,7 @@ t_heap_increase_decrease(void)
bt_assert(is_heap_valid(heap, num));
}
return BT_SUCCESS;
return 1;
}
static int
@ -128,7 +128,7 @@ t_heap_delete(void)
bt_assert(is_heap_valid(heap, num));
}
return BT_SUCCESS;
return 1;
}
static int
@ -139,7 +139,7 @@ t_heap_0(void)
t_heap_increase_decrease();
t_heap_delete();
return (heap[0] == SPECIAL_KEY) ? BT_SUCCESS : BT_FAILURE;
return heap[0] == SPECIAL_KEY;
}
static int
@ -168,7 +168,7 @@ t_heap_insert_random(void)
bt_abort_msg("Did not find a number %d in heap.", expected[i]);
}
return BT_SUCCESS;
return 1;
}
int

View file

@ -31,7 +31,7 @@ test_ipa_pton(void *out_, const void *in_, const void *expected_out_)
/* ip_addr == ip6_addr */
}
return ipa_equal(*out, *expected_out) ? BT_SUCCESS : BT_FAILURE;
return ipa_equal(*out, *expected_out);
}
static int
@ -105,7 +105,7 @@ test_ipa_ntop(void *out_, const void *in_, const void *expected_out_)
ip6_ntop(ipa_to_ip6(*in), out);
int result = strncmp(out, expected_out, ipa_is_ip4(*in) ? IP4_MAX_TEXT_LENGTH : IP6_MAX_TEXT_LENGTH) == 0;
return result ? BT_SUCCESS : BT_FAILURE;
return result;
}
static int

View file

@ -111,7 +111,7 @@ t_add_tail(void)
show_list();
bt_assert(is_filled_list_well_linked());
return BT_SUCCESS;
return 1;
}
static int
@ -135,7 +135,7 @@ t_add_head(void)
show_list();
bt_assert(is_filled_list_well_linked());
return BT_SUCCESS;
return 1;
}
static void
@ -166,7 +166,7 @@ t_insert_node(void)
bt_debug("\n");
bt_assert(is_filled_list_well_linked());
return BT_SUCCESS;
return 1;
}
static void
@ -218,7 +218,7 @@ t_remove_node(void)
rem_node(&nodes[i]);
bt_assert(is_empty_list_well_unlinked());
return BT_SUCCESS;
return 1;
}
static int
@ -247,7 +247,7 @@ t_replace_node(void)
bt_assert(tail.next == NODE &l.null);
bt_assert(nodes[MAX_NUM-2].next == &tail);
return BT_SUCCESS;
return 1;
}
static int
@ -268,7 +268,7 @@ t_add_tail_list(void)
bt_assert(nodes2[0].prev == &nodes[MAX_NUM-1]);
bt_assert(l.tail == &nodes2[MAX_NUM-1]);
return BT_SUCCESS;
return 1;
}
int

View file

@ -28,7 +28,7 @@ test_##name(void *out_, const void *in_, const void *expected_out_) \
uint len = mac_type_length(id); \
bt_bytes_to_hex(out, out_bin, len); \
\
return strncmp(out, expected_out, 2*len+1) == 0 ? BT_SUCCESS : BT_FAILURE; \
return strncmp(out, expected_out, 2*len+1) == 0; \
}
define_test_hash_fn(md5, ALG_MD5)
@ -284,7 +284,7 @@ test_##name##_hmac(void *out_, const void *in_, const void *expected_out_) \
uint len = mac_type_length(id); \
bt_bytes_to_hex(out, out_bin, len); \
\
return strncmp(out, expected_out, 2*len+1) == 0 ? BT_SUCCESS : BT_FAILURE; \
return strncmp(out, expected_out, 2*len+1) == 0; \
}
define_test_hmac_fn(md5, ALG_HMAC_MD5)
@ -1092,7 +1092,7 @@ t_sha256_concating(void)
int are_hash_a_b_equal = (strncmp(hash_a, hash_b, sizeof(hash_a)) == 0);
bt_assert_msg(are_hash_a_b_equal, "Hashes A: %s, B: %s should be same", hash_a, hash_b);
return BT_SUCCESS;
return 1;
}
@ -1130,7 +1130,7 @@ t_sha512_concating(void)
int are_hash_a_b_equal = (strncmp(hash_a, hash_b, sizeof(hash_a)) == 0);
bt_assert_msg(are_hash_a_b_equal, "Hashes A: %s, B: %s should be same", hash_a, hash_b);
return BT_SUCCESS;
return 1;
}
int

View file

@ -28,7 +28,7 @@ test_matching(void *out_, const void *in_, const void *expected_out_)
*out = patmatch(in->pattern, in->data);
return (*out == *expected_out) ? BT_SUCCESS : BT_FAILURE;
return *out == *expected_out;
}
static void

View file

@ -56,7 +56,7 @@ t_simple(void)
BSPRINTF(2, "-1", buf, "%d", -1);
BSPRINTF(11, "-2147483648", buf, "%d", -2147483648);
return BT_SUCCESS;
return 1;
}
int

View file

@ -103,7 +103,7 @@ t_add_tail(void)
bt_assert(is_filled_list_well_linked());
return BT_SUCCESS;
return 1;
}
static int
@ -127,7 +127,7 @@ t_add_head(void)
bt_assert(is_filled_list_well_linked());
return BT_SUCCESS;
return 1;
}
static void
@ -158,7 +158,7 @@ t_insert_node(void)
bt_debug("\n");
bt_assert(is_filled_list_well_linked());
return BT_SUCCESS;
return 1;
}
static void
@ -211,7 +211,7 @@ t_remove_node(void)
s_rem_node(&nodes[i]);
bt_assert(is_empty_list_well_unlinked());
return BT_SUCCESS;
return 1;
}
static int
@ -232,7 +232,7 @@ t_add_tail_list(void)
bt_assert(nodes2[0].prev == &nodes[MAX_NUM-1]);
bt_assert(lst.tail == &nodes2[MAX_NUM-1]);
return BT_SUCCESS;
return 1;
}
void
@ -290,7 +290,7 @@ t_iterator_walk(void)
i++;
}
return BT_SUCCESS;
return 1;
}
static int
@ -344,7 +344,7 @@ t_original(void)
s_add_tail_list(&b, &a);
dump("8 (after merge)", &b);
return BT_SUCCESS;
return 1;
}
static int
@ -363,7 +363,7 @@ t_safe_del_walk(void)
}
bt_assert(is_empty_list_well_unlinked());
return BT_SUCCESS;
return 1;
}
int

View file

@ -66,7 +66,7 @@ t_as_path_match(void)
rfree(lp);
}
return BT_SUCCESS;
return 1;
}
static int
@ -97,7 +97,7 @@ t_path_format(void)
rfree(lp);
return BT_SUCCESS;
return 1;
}
static int
@ -152,7 +152,7 @@ t_path_include(void)
rfree(lp);
return BT_SUCCESS;
return 1;
}
static int
@ -197,7 +197,7 @@ t_as_path_converting(void)
"\032\0310\030\039\030\038\030\037\030\036\030\035\030\034\030\033\030\032\030\031\030\030",
22));
return BT_SUCCESS;
return 1;
}
int

View file

@ -86,7 +86,7 @@ t_set_int_contains(void)
bt_assert_msg(data[i] == i, "(data[i] = %d) == i = %d)", data[i], i);
rfree(lp);
return BT_SUCCESS;
return 1;
}
static int
@ -105,7 +105,7 @@ t_set_int_union(void)
bt_assert(int_set_format(set_union, 0, 2, buf, BUFFER_SIZE) == 0);
rfree(lp);
return BT_SUCCESS;
return 1;
}
static int
@ -127,7 +127,7 @@ t_set_int_format(void)
bt_assert(strcmp(buf, "(0,0) (0,1) (0,2) (0,3) (0,4) (0,5) (0,6) (0,7) (0,8) (0,9)") == 0);
rfree(lp);
return BT_SUCCESS;
return 1;
}
static int
@ -149,7 +149,7 @@ t_set_int_delete(void)
bt_assert(int_set_get_size(set_sequence) == SET_SIZE);
return BT_SUCCESS;
return 1;
}
/*
@ -176,7 +176,7 @@ t_set_ec_contains(void)
// bt_assert_msg(data[i] == (SET_SIZE-1-i), "(data[i] = %d) == ((SET_SIZE-1-i) = %d)", data[i], SET_SIZE-1-i);
rfree(lp);
return BT_SUCCESS;
return 1;
}
static int
@ -195,7 +195,7 @@ t_set_ec_union(void)
bt_assert(ec_set_format(set_union, 0, buf, BUFFER_SIZE) == 0);
rfree(lp);
return BT_SUCCESS;
return 1;
}
static int
@ -217,7 +217,7 @@ t_set_ec_format(void)
"ec_set_format() returns '%s'", buf);
rfree(lp);
return BT_SUCCESS;
return 1;
}
static int
@ -238,7 +238,7 @@ t_set_ec_delete(void)
bt_assert(ec_set_get_size(set_sequence) == SET_SIZE);
return BT_SUCCESS;
return 1;
}
int

View file

@ -63,7 +63,7 @@ bt_init(int argc, char *argv[])
bt_verbose = 0;
bt_filename = argv[0];
bt_result = BT_SUCCESS;
bt_result = 1;
bt_test_id = NULL;
is_terminal = isatty(fileno(stdout));
@ -160,8 +160,8 @@ int bt_run_test_fn(int (*fn)(const void *), const void *fn_arg, int timeout)
else
result = ((int (*)(void))fn)();
if (bt_suite_result != BT_SUCCESS)
result = BT_FAILURE;
if (!bt_suite_result)
result = 0;
return result;
}
@ -177,7 +177,7 @@ get_num_terminal_cols(void)
/**
* bt_log_result - pretty print of test result
* @result: BT_SUCCESS or BT_FAILURE
* @result: 1 or 0
* @fmt: a description message (could be long, over more lines)
* @argptr: variable argument list
*
@ -222,7 +222,7 @@ bt_log_result(int result, const char *fmt, va_list argptr)
putchar(' ');
const char *result_str = is_terminal ? BT_PROMPT_OK : BT_PROMPT_OK_NO_COLOR;
if (result != BT_SUCCESS)
if (!result)
result_str = is_terminal ? BT_PROMPT_FAIL : BT_PROMPT_FAIL_NO_COLOR;
printf("%s\n", result_str);
@ -230,7 +230,7 @@ bt_log_result(int result, const char *fmt, va_list argptr)
/**
* bt_log_overall_result - pretty print of suite case result
* @result: BT_SUCCESS or BT_FAILURE
* @result: 1 or 0
* @fmt: a description message (could be long, over more lines)
* ...: variable argument list
*
@ -247,7 +247,7 @@ bt_log_overall_result(int result, const char *fmt, ...)
/**
* bt_log_suite_result - pretty print of suite case result
* @result: BT_SUCCESS or BT_FAILURE
* @result: 1 or 0
* @fmt: a description message (could be long, over more lines)
* ...: variable argument list
*
@ -256,7 +256,7 @@ bt_log_overall_result(int result, const char *fmt, ...)
void
bt_log_suite_result(int result, const char *fmt, ...)
{
if(bt_verbose >= BT_VERBOSE_SUITE || result == BT_FAILURE)
if(bt_verbose >= BT_VERBOSE_SUITE || !result)
{
va_list argptr;
va_start(argptr, fmt);
@ -267,7 +267,7 @@ bt_log_suite_result(int result, const char *fmt, ...)
/**
* bt_log_suite_case_result - pretty print of suite result
* @result: BT_SUCCESS or BT_FAILURE
* @result: 1 or 0
* @fmt: a description message (could be long, over more lines)
* ...: variable argument list
*
@ -296,7 +296,7 @@ bt_test_suite_base(int (*fn)(const void *), const char *id, const void *fn_arg,
vprintf(dsc, args);
va_end(args);
printf("\n");
return BT_SUCCESS;
return 1;
}
if (no_fork)
@ -306,9 +306,9 @@ bt_test_suite_base(int (*fn)(const void *), const char *id, const void *fn_arg,
timeout = 0;
if (request && strcmp(id, request))
return BT_SUCCESS;
return 1;
bt_suite_result = BT_SUCCESS;
bt_suite_result = 1;
bt_test_id = id;
if (bt_verbose >= BT_VERBOSE_ABSOLUTELY_ALL)
@ -341,7 +341,7 @@ bt_test_suite_base(int (*fn)(const void *), const char *id, const void *fn_arg,
else if (WIFSIGNALED(s))
{
/* Stopped by signal */
bt_suite_result = BT_FAILURE;
bt_suite_result = 0;
int sn = WTERMSIG(s);
if (sn == SIGALRM)
@ -361,8 +361,8 @@ bt_test_suite_base(int (*fn)(const void *), const char *id, const void *fn_arg,
bt_log("Core dumped");
}
if (bt_suite_result == BT_FAILURE)
bt_result = BT_FAILURE;
if (!bt_suite_result)
bt_result = 0;
bt_log_suite_result(bt_suite_result, NULL);
bt_test_id = NULL;
@ -373,9 +373,9 @@ bt_test_suite_base(int (*fn)(const void *), const char *id, const void *fn_arg,
int
bt_exit_value(void)
{
if (!list_tests || (list_tests && bt_result != BT_SUCCESS))
if (!list_tests || (list_tests && !bt_result))
bt_log_overall_result(bt_result, "");
return bt_result == BT_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
return bt_result ? EXIT_SUCCESS : EXIT_FAILURE;
}
/**
@ -383,7 +383,7 @@ bt_exit_value(void)
* @opts: includes all necessary data
*
* Should be called using macro bt_assert_batch().
* Returns BT_SUCCESS or BT_FAILURE.
* Returns 1 or 0.
*/
int
bt_assert_batch__(struct bt_batch *opts)
@ -393,8 +393,8 @@ bt_assert_batch__(struct bt_batch *opts)
{
int bt_suit_case_result = opts->test_fn(opts->out_buf, opts->data[i].in, opts->data[i].out);
if (bt_suit_case_result == BT_FAILURE)
bt_suite_result = BT_FAILURE;
if (bt_suit_case_result == 0)
bt_suite_result = 0;
char b[BT_BUFFER_SIZE];
snprintf(b, sizeof(b), "%s(", opts->test_fn_name);
@ -403,7 +403,7 @@ bt_assert_batch__(struct bt_batch *opts)
sprintf_concat(b, ") gives ");
opts->out_fmt(b+strlen(b), sizeof(b)-strlen(b), opts->out_buf);
if (bt_suit_case_result == BT_FAILURE)
if (bt_suit_case_result == 0)
{
sprintf_concat(b, ", but expecting is ");
opts->out_fmt(b+strlen(b), sizeof(b)-strlen(b), opts->data[i].out);

View file

@ -38,9 +38,6 @@ long int bt_random(void);
void bt_log_suite_result(int result, const char *fmt, ...);
void bt_log_suite_case_result(int result, const char *fmt, ...);
#define BT_SUCCESS 42 /* 1 is too usual, filter quitbird returns 1 too */
#define BT_FAILURE 0
#define BT_TIMEOUT 5 /* Default timeout in seconds */
#define BT_FORKING 1 /* Forking is enabled in default */
@ -101,12 +98,12 @@ void bt_log_suite_case_result(int result, const char *fmt, ...);
#define bt_assert_msg(test, format, ...) \
do \
{ \
int bt_suit_case_result = BT_SUCCESS; \
int bt_suit_case_result = 1; \
if ((test) == 0) \
{ \
bt_result = BT_FAILURE; \
bt_suite_result = BT_FAILURE; \
bt_suit_case_result = BT_FAILURE; \
bt_result = 0; \
bt_suite_result = 0; \
bt_suit_case_result = 0; \
} \
bt_log_suite_case_result(bt_suit_case_result, format, ##__VA_ARGS__); \
} while (0)
@ -149,14 +146,13 @@ struct bt_batch {
* @expected_out: expected data from tested function
*
* Input arguments should not be stringified using in_fmt() or out_fmt()
* function already. This function should return only BT_SUCCESS or
* BT_FAILURE */
* function already. This function should return only 0 or 1 */
int (*test_fn)(void *out, const void *in, const void *expected_out);
/* Name of testing function @test_fn */
const char *test_fn_name;
/* Number of items in data*/
/* Number of items in data */
int ndata;
/* Array of input and expected output pairs */