summaryrefslogtreecommitdiff
path: root/lib/tdb2/test
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-12-05 17:03:30 +1030
committerRusty Russell <rusty@rustcorp.com.au>2011-12-05 17:03:30 +1030
commit6d248534936ce5169d651b7d5e47ae8c74efb610 (patch)
treee98e09b60b3eaa0c378ad94e80bbd71e5477e5e8 /lib/tdb2/test
parent7f95ad045a36f1d40f66c815c9461bd5720c5808 (diff)
downloadsamba-6d248534936ce5169d651b7d5e47ae8c74efb610.tar.gz
samba-6d248534936ce5169d651b7d5e47ae8c74efb610.tar.bz2
samba-6d248534936ce5169d651b7d5e47ae8c74efb610.zip
tdb2: failtest: use a linked list for history, not an array.
This avoids a silly realloc, but more importantly it gets us closer to being runtime extensible, as each history element can be a different size. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit 9571a41e8494f3135557e3ec50c2de856392173e)
Diffstat (limited to 'lib/tdb2/test')
-rw-r--r--lib/tdb2/test/failtest_helper.c51
-rw-r--r--lib/tdb2/test/failtest_helper.h5
2 files changed, 26 insertions, 30 deletions
diff --git a/lib/tdb2/test/failtest_helper.c b/lib/tdb2/test/failtest_helper.c
index d24ac4c42b..f3ef09a6c3 100644
--- a/lib/tdb2/test/failtest_helper.c
+++ b/lib/tdb2/test/failtest_helper.c
@@ -26,12 +26,14 @@ bool failmatch(const struct failtest_call *call,
}
static const struct failtest_call *
-find_repeat(const struct failtest_call *start, const struct failtest_call *end,
+find_repeat(const struct tlist_calls *history,
const struct failtest_call *call)
{
const struct failtest_call *i;
- for (i = start; i < end; i++) {
+ tlist_for_each(history, i, list) {
+ if (i != call)
+ continue;
if (failmatch(i, call->file, call->line, call->type))
return i;
}
@@ -49,32 +51,31 @@ static bool is_unlock(const struct failtest_call *call)
&& call->u.fcntl.arg.fl.l_type == F_UNLCK;
}
-bool exit_check_log(struct failtest_call *history, unsigned num)
+bool exit_check_log(struct tlist_calls *history)
{
- unsigned int i;
+ const struct failtest_call *i;
- for (i = 0; i < num; i++) {
- if (!history[i].fail)
+ tlist_for_each(history, i, list) {
+ if (!i->fail)
continue;
/* Failing the /dev/urandom open doesn't count: we fall back. */
- if (failmatch(&history[i], URANDOM_OPEN))
+ if (failmatch(i, URANDOM_OPEN))
continue;
/* Similarly with read fail. */
- if (failmatch(&history[i], URANDOM_READ))
+ if (failmatch(i, URANDOM_READ))
continue;
/* Initial allocation of tdb doesn't log. */
- if (failmatch(&history[i], INITIAL_TDB_MALLOC))
+ if (failmatch(i, INITIAL_TDB_MALLOC))
continue;
/* We don't block "failures" on non-blocking locks. */
- if (is_nonblocking_lock(&history[i]))
+ if (is_nonblocking_lock(i))
continue;
if (!tap_log_messages)
- diag("We didn't log for %u (%s:%u)",
- i, history[i].file, history[i].line);
+ diag("We didn't log for %s:%u", i->file, i->line);
return tap_log_messages != 0;
}
return true;
@@ -82,9 +83,11 @@ bool exit_check_log(struct failtest_call *history, unsigned num)
/* Some places we soldier on despite errors: only fail them once. */
enum failtest_result
-block_repeat_failures(struct failtest_call *history, unsigned num)
+block_repeat_failures(struct tlist_calls *history)
{
- const struct failtest_call *i, *last = &history[num-1];
+ const struct failtest_call *i, *last;
+
+ last = tlist_tail(history, struct failtest_call, list);
if (failtest_suppress)
return FAIL_DONT_FAIL;
@@ -92,7 +95,7 @@ block_repeat_failures(struct failtest_call *history, unsigned num)
if (failmatch(last, INITIAL_TDB_MALLOC)
|| failmatch(last, URANDOM_OPEN)
|| failmatch(last, URANDOM_READ)) {
- if (find_repeat(history, last, last))
+ if (find_repeat(history, last))
return FAIL_DONT_FAIL;
return FAIL_PROBE;
}
@@ -100,21 +103,15 @@ block_repeat_failures(struct failtest_call *history, unsigned num)
/* Unlock or non-blocking lock is fail-once. */
if (is_unlock(last)) {
/* Find a previous unlock at this point? */
- for (i = find_repeat(history, last, last);
- i;
- i = find_repeat(history, i, last)) {
- if (is_unlock(i))
- return FAIL_DONT_FAIL;
- }
+ i = find_repeat(history, last);
+ if (i && is_unlock(i))
+ 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;
- }
+ i = find_repeat(history, last);
+ if (i && is_nonblocking_lock(i))
+ return FAIL_DONT_FAIL;
return FAIL_PROBE;
}
diff --git a/lib/tdb2/test/failtest_helper.h b/lib/tdb2/test/failtest_helper.h
index 7f912bb5e9..a3c680885d 100644
--- a/lib/tdb2/test/failtest_helper.h
+++ b/lib/tdb2/test/failtest_helper.h
@@ -8,11 +8,10 @@
#define URANDOM_OPEN "open.c", 62, FAILTEST_OPEN
#define URANDOM_READ "open.c", 42, FAILTEST_READ
-bool exit_check_log(struct failtest_call *history, unsigned num);
+bool exit_check_log(struct tlist_calls *history);
bool failmatch(const struct failtest_call *call,
const char *file, int line, enum failtest_call_type type);
-enum failtest_result
-block_repeat_failures(struct failtest_call *history, unsigned num);
+enum failtest_result block_repeat_failures(struct tlist_calls *history);
/* Set this to suppress failure. */
extern bool failtest_suppress;