1 #include "failtest_helper.h"
4 #include "tap-interface.h"
6 bool failtest_suppress = false;
8 bool failmatch(const struct failtest_call *call,
9 const char *file, int line, enum failtest_call_type type)
11 return call->type == type
13 && ((strcmp(call->file, file) == 0)
14 || (strends(call->file, file)
15 && (call->file[strlen(call->file) - strlen(file) - 1]
19 static bool is_nonblocking_lock(const struct failtest_call *call)
21 return call->type == FAILTEST_FCNTL && call->u.fcntl.cmd == F_SETLK;
24 static bool is_unlock(const struct failtest_call *call)
26 return call->type == FAILTEST_FCNTL
27 && call->u.fcntl.arg.fl.l_type == F_UNLCK;
30 bool exit_check_log(struct tlist_calls *history)
32 const struct failtest_call *i;
33 unsigned int malloc_count = 0;
35 tlist_for_each(history, i, list) {
38 /* Failing the /dev/urandom open doesn't count: we fall back. */
39 if (failmatch(i, URANDOM_OPEN))
42 /* Similarly with read fail. */
43 if (failmatch(i, URANDOM_READ))
46 /* Initial allocation of ntdb doesn't log. */
47 if (i->type == FAILTEST_MALLOC) {
48 if (malloc_count++ == 0) {
53 /* We don't block "failures" on non-blocking locks. */
54 if (is_nonblocking_lock(i))
57 if (!tap_log_messages)
58 diag("We didn't log for %s:%u", i->file, i->line);
59 return tap_log_messages != 0;
64 /* Some places we soldier on despite errors: only fail them once. */
66 block_repeat_failures(struct tlist_calls *history)
68 const struct failtest_call *last;
70 last = tlist_tail(history, list);
72 if (failtest_suppress)
73 return FAIL_DONT_FAIL;
75 if (failmatch(last, URANDOM_OPEN)
76 || failmatch(last, URANDOM_READ)) {
80 /* We handle mmap failing, by falling back to read/write, so
81 * don't try all possible paths. */
82 if (last->type == FAILTEST_MMAP)
85 /* Unlock or non-blocking lock is fail-once. */
86 if (is_unlock(last) || is_nonblocking_lock(last))