X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftest%2Frun-01-new_database.c;h=4cfd04d91ce73c558a28d4bbc350474a6e31301f;hp=ee6cd55d68e3e6e85e03838dd202ce567efbc52a;hb=a97da100b00206544c7a68593b64a49f2b854f7e;hpb=3835bb95d716cb6448913792b0d8d539877d93e9 diff --git a/ccan/tdb2/test/run-01-new_database.c b/ccan/tdb2/test/run-01-new_database.c index ee6cd55d..4cfd04d9 100644 --- a/ccan/tdb2/test/run-01-new_database.c +++ b/ccan/tdb2/test/run-01-new_database.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -9,112 +10,7 @@ #include #include #include "logging.h" - -/* FIXME: Check these! */ -#define INITIAL_TDB_MALLOC "tdb.c", 182, FAILTEST_MALLOC -#define LOGGING_MALLOC "tdb.c", 792, FAILTEST_MALLOC -#define URANDOM_OPEN "tdb.c", 49, FAILTEST_OPEN -#define URANDOM_READ "tdb.c", 29, FAILTEST_READ - -static bool failmatch(const struct failtest_call *call, - const char *file, int line, enum failtest_call_type type) -{ - return call->type == type - && call->line == line - && ((strcmp(call->file, file) == 0) - || (strends(call->file, file) - && (call->file[strlen(call->file) - strlen(file) - 1] - == '/'))); -} - -static const struct failtest_call * -find_repeat(const struct failtest_call *start, const struct failtest_call *end, - const struct failtest_call *call) -{ - const struct failtest_call *i; - - for (i = start; i < end; i++) { - if (failmatch(i, call->file, call->line, call->type)) - return i; - } - return NULL; -} - -static bool is_nonblocking_lock(const struct failtest_call *call) -{ - return call->type == FAILTEST_FCNTL && call->u.fcntl.cmd == F_SETLK; -} - -/* Some places we soldier on despite errors: only fail them once. */ -static enum failtest_result -block_repeat_failures(struct failtest_call *history, unsigned num) -{ - const struct failtest_call *i, *last = &history[num-1]; - - if (failmatch(last, INITIAL_TDB_MALLOC) - || failmatch(last, LOGGING_MALLOC) - || failmatch(last, URANDOM_OPEN) - || failmatch(last, URANDOM_READ)) { - if (find_repeat(history, last, last)) - return FAIL_DONT_FAIL; - return FAIL_PROBE; - } - - /* Unlock or non-blocking lock is fail-once. */ - if (last->type == FAILTEST_FCNTL - && last->u.fcntl.arg.fl.l_type == F_UNLCK) { - /* Find a previous unlock at this point? */ - for (i = find_repeat(history, last, last); - i; - i = find_repeat(history, i, last)) { - if (i->u.fcntl.arg.fl.l_type == F_UNLCK) - return FAIL_DONT_FAIL; - } - return FAIL_PROBE; - } else if (is_nonblocking_lock(last)) { - /* Find a previous non-blocking lock at this point? */ - for (i = find_repeat(history, last, last); - i; - i = find_repeat(history, i, last)) { - if (is_nonblocking_lock(i)) - return FAIL_DONT_FAIL; - } - return FAIL_PROBE; - } - - return FAIL_OK; -} - -static bool exit_check(struct failtest_call *history, unsigned num) -{ - unsigned int i; - - for (i = 0; i < num; i++) { - if (!history[i].fail) - continue; - /* Failing the /dev/urandom open doesn't count: we fall back. */ - if (failmatch(&history[i], URANDOM_OPEN)) - continue; - - /* Similarly with read fail. */ - if (failmatch(&history[i], URANDOM_READ)) - continue; - - /* Initial allocation of tdb doesn't log. */ - if (failmatch(&history[i], INITIAL_TDB_MALLOC)) - continue; - - /* We don't block "failures" on non-blocking locks. */ - if (is_nonblocking_lock(&history[i])) - continue; - - if (!tap_log_messages) - diag("We didn't log for %u (%s:%u)", - i, history[i].file, history[i].line); - return tap_log_messages != 0; - } - return true; -} +#include "failtest_helper.h" int main(int argc, char *argv[]) { @@ -126,7 +22,7 @@ int main(int argc, char *argv[]) failtest_init(argc, argv); failtest_hook = block_repeat_failures; - failtest_exit_check = exit_check; + failtest_exit_check = exit_check_log; plan_tests(sizeof(flags) / sizeof(flags[0]) * 3); for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { tdb = tdb_open("run-new_database.tdb", flags[i],