From: Rusty Russell Date: Sun, 12 Sep 2010 11:51:25 +0000 (+0930) Subject: tdb: missing files from checkin. X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=cbe5094e85d08d19393c1b66abd59aecce7c8408 tdb: missing files from checkin. --- diff --git a/ccan/tdb/test/logging.c b/ccan/tdb/test/logging.c new file mode 100644 index 00000000..fa413f63 --- /dev/null +++ b/ccan/tdb/test/logging.c @@ -0,0 +1,33 @@ +#include "logging.h" +#include +#include +#include +#include +#include + +bool suppress_logging = false; +const char *log_prefix = ""; + +/* Turn log messages into tap diag messages. */ +static void taplog(struct tdb_context *tdb, + enum tdb_debug_level level, + const char *fmt, ...) +{ + va_list ap; + char line[200]; + + if (suppress_logging) + return; + + va_start(ap, fmt); + vsprintf(line, fmt, ap); + va_end(ap); + + /* Strip trailing \n: diag adds it. */ + if (line[0] && line[strlen(line)-1] == '\n') + diag("%s%.*s", log_prefix, strlen(line)-1, line); + else + diag("%s%s", log_prefix, line); +} + +struct tdb_logging_context taplogctx = { taplog, NULL }; diff --git a/ccan/tdb/test/logging.h b/ccan/tdb/test/logging.h new file mode 100644 index 00000000..6745a327 --- /dev/null +++ b/ccan/tdb/test/logging.h @@ -0,0 +1,10 @@ +#ifndef TDB_TEST_LOGGING_H +#define TDB_TEST_LOGGING_H +#include +#include + +extern bool suppress_logging; +extern const char *log_prefix; +extern struct tdb_logging_context taplogctx; + +#endif /* TDB_TEST_LOGGING_H */ diff --git a/ccan/tdb/test/run-check.c b/ccan/tdb/test/run-check.c index b76d91bb..fe0842d3 100644 --- a/ccan/tdb/test/run-check.c +++ b/ccan/tdb/test/run-check.c @@ -35,12 +35,14 @@ int main(int argc, char *argv[]) ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); - tdb = tdb_open("run-check.tdb", 1024, 0, O_RDWR, 0); + tdb = tdb_open_ex("run-check.tdb", 1024, 0, O_RDWR, 0, + &taplogctx, NULL); ok1(tdb); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); - tdb = tdb_open("test/tdb.corrupt", 1024, 0, O_RDWR, 0); + tdb = tdb_open_ex("test/tdb.corrupt", 1024, 0, O_RDWR, 0, + &taplogctx, NULL); ok1(tdb); ok1(tdb_check(tdb, NULL, NULL) == -1); ok1(tdb_error(tdb) == TDB_ERR_CORRUPT);