diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2010-06-21 14:57:11 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2010-06-21 14:57:11 +0930 |
commit | b0a8fd19ffcb8129ca45d1dfa9e7cd3d317601ad (patch) | |
tree | 382682414367235e57aecc25318208d27c648565 /ctdb/libctdb/test | |
parent | fee11bf13be72de71d83912dfc12e61c5e4ecbbf (diff) | |
download | samba-b0a8fd19ffcb8129ca45d1dfa9e7cd3d317601ad.tar.gz samba-b0a8fd19ffcb8129ca45d1dfa9e7cd3d317601ad.tar.xz samba-b0a8fd19ffcb8129ca45d1dfa9e7cd3d317601ad.zip |
libctdb: test: improve logging of failure paths
We include the file and line which called the functions, so the printed
failure path now looks like:
[malloc(ctdb.c:144)]:1:S[socket(ctdb.c:168)]:1:S...
The form is:
[ <function> ( <caller> ) ] : <input line> : <result>
<function> is the function which is called (eg. malloc).
<caller> is the file and line number which called <function>.
<input line> is the 1-based line number in the input which we were up to.
<result> is 'S' (success) or 'F' (failure).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(This used to be ctdb commit 5fb6da30b5b5a8b761c8ab9a8124b87b759ef055)
Diffstat (limited to 'ctdb/libctdb/test')
-rw-r--r-- | ctdb/libctdb/test/ctdb-test.c | 16 | ||||
-rw-r--r-- | ctdb/libctdb/test/failtest.c | 25 | ||||
-rw-r--r-- | ctdb/libctdb/test/failtest.h | 4 |
3 files changed, 29 insertions, 16 deletions
diff --git a/ctdb/libctdb/test/ctdb-test.c b/ctdb/libctdb/test/ctdb-test.c index b4c12ff9ab..1587a4f8c3 100644 --- a/ctdb/libctdb/test/ctdb-test.c +++ b/ctdb/libctdb/test/ctdb-test.c @@ -251,7 +251,7 @@ static char *get_cmdline_optstr(void) static int ctdb_test_poll(struct pollfd *fds, nfds_t nfds, int timeout, const char *location) { - if (should_i_fail("poll")) { + if (should_i_fail("poll", location)) { errno = EINVAL; return -1; } @@ -260,7 +260,7 @@ static int ctdb_test_poll(struct pollfd *fds, nfds_t nfds, int timeout, static void *ctdb_test_malloc(size_t size, const char *location) { - if (should_i_fail("malloc")) { + if (should_i_fail("malloc", location)) { errno = ENOMEM; return NULL; } @@ -274,7 +274,7 @@ static void ctdb_test_free(void *ptr, const char *location) static void *ctdb_test_realloc(void *ptr, size_t size, const char *location) { - if (should_i_fail("realloc")) { + if (should_i_fail("realloc", location)) { errno = ENOMEM; return NULL; } @@ -288,7 +288,7 @@ static void *ctdb_test_realloc(void *ptr, size_t size, const char *location) static ssize_t ctdb_test_read(int fd, void *buf, size_t count, const char *location) { - if (should_i_fail("read")) { + if (should_i_fail("read", location)) { errno = EBADF; return -1; } @@ -305,7 +305,7 @@ static ssize_t ctdb_test_read(int fd, void *buf, size_t count, static ssize_t ctdb_test_write(int fd, const void *buf, size_t count, const char *location) { - if (should_i_fail("write")) { + if (should_i_fail("write", location)) { errno = EBADF; return -1; } @@ -323,7 +323,7 @@ static ssize_t ctdb_test_write(int fd, const void *buf, size_t count, static int ctdb_test_socket(int domain, int type, int protocol, const char *location) { - if (should_i_fail("socket")) { + if (should_i_fail("socket", location)) { errno = EINVAL; return -1; } @@ -333,7 +333,7 @@ static int ctdb_test_socket(int domain, int type, int protocol, static int ctdb_test_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen, const char *location) { - if (should_i_fail("connect")) { + if (should_i_fail("connect", location)) { errno = EINVAL; return -1; } @@ -347,7 +347,7 @@ static struct tdb_context *ctdb_test_tdb_open_ex(const char *name, tdb_hash_func hash_fn, const char *location) { - if (should_i_fail("tdb_open_ex")) { + if (should_i_fail("tdb_open_ex", location)) { errno = ENOENT; return NULL; } diff --git a/ctdb/libctdb/test/failtest.c b/ctdb/libctdb/test/failtest.c index d42ab05709..c12d4fcaed 100644 --- a/ctdb/libctdb/test/failtest.c +++ b/ctdb/libctdb/test/failtest.c @@ -199,11 +199,23 @@ bool am_parent(void) return true; } +static char *make_location(const char *func, const char *caller) +{ + const char *afterslash; + + afterslash = strrchr(caller, '/'); + if (afterslash) + afterslash++; + else + afterslash = caller; + return talloc_asprintf(working, "%s(%s)", func, afterslash); +} + /* Should I fail at this point? Once only: it would be too expensive * to fail at every possible call. */ -bool should_i_fail_once(const char *location) +bool should_i_fail_once(const char *func, const char *caller) { - char *p; + char *p, *location = make_location(func, caller); struct fail_decision *i; if (failpath) { @@ -219,7 +231,7 @@ bool should_i_fail_once(const char *location) if (streq(location, i->location)) return false; - if (should_i_fail(location)) { + if (should_i_fail(func, caller)) { excessive_fails++; return true; } @@ -227,16 +239,17 @@ bool should_i_fail_once(const char *location) } /* Should I fail at this point? */ -bool should_i_fail(const char *func) +bool should_i_fail(const char *func, const char *caller) { pid_t child; int status, pfd[2]; struct fail_decision *dec; size_t log_size; char *log; + char *location = make_location(func, caller); if (failpath) - return do_failpath(func); + return do_failpath(location); failpoints++; if (!failtest) @@ -251,7 +264,7 @@ bool should_i_fail(const char *func) } dec = talloc(NULL, struct fail_decision); - dec->location = talloc_strdup(dec, func); + dec->location = talloc_steal(dec, location); dec->tui_line = tui_linenum; DLIST_ADD_END(decisions, dec, struct fail_decision); diff --git a/ctdb/libctdb/test/failtest.h b/ctdb/libctdb/test/failtest.h index c361f84c9b..4d0c579f20 100644 --- a/ctdb/libctdb/test/failtest.h +++ b/ctdb/libctdb/test/failtest.h @@ -2,8 +2,8 @@ #define FAILTEST_H #include <stdbool.h> -bool should_i_fail_once(const char *location); -bool should_i_fail(const char *func); +bool should_i_fail_once(const char *func, const char *caller); +bool should_i_fail(const char *func, const char *caller); bool failtest; |