Skip to content

Commit

Permalink
lib-test: Introduce test_fatal_func_t as typedef and comment how it w…
Browse files Browse the repository at this point in the history
…orks.
  • Loading branch information
sirainen committed Dec 15, 2016
1 parent b127fb2 commit 333ccb2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/lib-test/test-common.c
Expand Up @@ -256,7 +256,7 @@ static void test_run_named_funcs(struct named_test tests[], const char *match)
}
}

static void run_one_fatal(enum fatal_test_state (*fatal_function)(int))
static void run_one_fatal(test_fatal_func_t *fatal_function)
{
static int index = 0;
for (;;) {
Expand Down Expand Up @@ -287,7 +287,7 @@ static void run_one_fatal(enum fatal_test_state (*fatal_function)(int))
}
}
}
static void test_run_fatals(enum fatal_test_state (*fatal_functions[])(int index))
static void test_run_fatals(test_fatal_func_t *fatal_functions[])
{
unsigned int i;

Expand Down Expand Up @@ -321,7 +321,7 @@ int test_run_named(struct named_test tests[], const char *match)
return test_deinit();
}
int test_run_with_fatals(void (*test_functions[])(void),
enum fatal_test_state (*fatal_functions[])(int))
test_fatal_func_t *fatal_functions[])
{
test_init();
test_run_funcs(test_functions);
Expand Down
10 changes: 8 additions & 2 deletions src/lib-test/test-common.h
Expand Up @@ -68,12 +68,18 @@ enum fatal_test_state {
FATAL_TEST_FAILURE, /* single stage has failed, continue */
FATAL_TEST_ABORT, /* something's gone horrifically wrong */
};
/* The fatal function is called first with stage=0. After each call the stage
is increased by 1. The idea is that each stage would be running an
individual test that is supposed to crash. The function is called until
FATAL_TEST_FINISHED or FATAL_TEST_ABORT is returned. */
typedef enum fatal_test_state test_fatal_func_t(int stage);

struct named_fatal {
const char *name;
enum fatal_test_state (*func)(int);
test_fatal_func_t *func;
};
int test_run_with_fatals(void (*test_functions[])(void),
enum fatal_test_state (*fatal_functions[])(int));
test_fatal_func_t *fatal_functions[]);
int test_run_named_with_fatals(const char *match, struct named_test tests[],
struct named_fatal fatals[]);

Expand Down

0 comments on commit 333ccb2

Please sign in to comment.