summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/birdtest.c18
-rw-r--r--test/birdtest.h4
2 files changed, 15 insertions, 7 deletions
diff --git a/test/birdtest.c b/test/birdtest.c
index a4312e9b..b5ee48c7 100644
--- a/test/birdtest.c
+++ b/test/birdtest.c
@@ -31,6 +31,7 @@
static const char *request;
static int list_tests;
static int do_core;
+static int do_die;
static int no_fork;
static int no_timeout;
static int is_terminal; /* Whether stdout is a live terminal or pipe redirect */
@@ -67,7 +68,7 @@ bt_init(int argc, char *argv[])
bt_test_id = NULL;
is_terminal = isatty(fileno(stdout));
- while ((c = getopt(argc, argv, "lcftv")) >= 0)
+ while ((c = getopt(argc, argv, "lcdftv")) >= 0)
switch (c)
{
case 'l':
@@ -78,6 +79,10 @@ bt_init(int argc, char *argv[])
do_core = 1;
break;
+ case 'd':
+ do_die = 1;
+ break;
+
case 'f':
no_fork = 1;
break;
@@ -111,10 +116,11 @@ bt_init(int argc, char *argv[])
return;
usage:
- printf("Usage: %s [-l] [-c] [-f] [-t] [-vvv] [<test_suit_name>]\n", argv[0]);
+ printf("Usage: %s [-l] [-c] [-d] [-f] [-t] [-vvv] [<test_suit_name>]\n", argv[0]);
printf("Options: \n");
printf(" -l List all test suite names and descriptions \n");
printf(" -c Force unlimit core dumps (needs root privileges) \n");
+ printf(" -d Die on first failed test case \n");
printf(" -f No forking \n");
printf(" -t No timeout limit \n");
printf(" -v More verbosity, maximum is 3 -vvv \n");
@@ -155,10 +161,7 @@ int bt_run_test_fn(int (*fn)(const void *), const void *fn_arg, int timeout)
int result;
alarm(timeout);
- if (fn_arg)
- result = fn(fn_arg);
- else
- result = ((int (*)(void))fn)();
+ result = fn(fn_arg);
if (!bt_suite_result)
result = 0;
@@ -226,6 +229,9 @@ bt_log_result(int result, const char *fmt, va_list argptr)
result_str = is_terminal ? BT_PROMPT_FAIL : BT_PROMPT_FAIL_NO_COLOR;
printf("%s\n", result_str);
+
+ if (do_die && !result)
+ abort();
}
/**
diff --git a/test/birdtest.h b/test/birdtest.h
index 4443bfc1..18228711 100644
--- a/test/birdtest.h
+++ b/test/birdtest.h
@@ -54,11 +54,13 @@ void bt_log_suite_case_result(int result, const char *fmt, ...);
#define BT_PROMPT_FAIL_NO_COLOR " [" "FAIL" "] "
#define BT_PROMPT_OK_FAIL_STRLEN 8 /* strlen ' [FAIL] ' */
+static inline int bt_test_fn_noarg(const void *cp) { return ((int (*)(void)) cp)(); }
+
#define bt_test_suite(fn, dsc, ...) \
bt_test_suite_extra(fn, BT_FORKING, BT_TIMEOUT, dsc, ##__VA_ARGS__)
#define bt_test_suite_extra(fn, f, t, dsc, ...) \
- bt_test_suite_base((int (*)(const void *))fn, #fn, NULL, f, t, dsc, ##__VA_ARGS__)
+ bt_test_suite_base(bt_test_fn_noarg, #fn, fn, f, t, dsc, ##__VA_ARGS__)
#define bt_test_suite_arg(fn, arg, dsc, ...) \
bt_test_suite_arg_extra(fn, arg, BT_FORKING, BT_TIMEOUT, dsc, ##__VA_ARGS__)