Commit cbe5094e authored by Rusty Russell's avatar Rusty Russell

tdb: missing files from checkin.

parent 655ef777
#include "logging.h"
#include <ccan/tap/tap.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
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 };
#ifndef TDB_TEST_LOGGING_H
#define TDB_TEST_LOGGING_H
#include <ccan/tdb/tdb.h>
#include <stdbool.h>
extern bool suppress_logging;
extern const char *log_prefix;
extern struct tdb_logging_context taplogctx;
#endif /* TDB_TEST_LOGGING_H */
...@@ -35,12 +35,14 @@ int main(int argc, char *argv[]) ...@@ -35,12 +35,14 @@ int main(int argc, char *argv[])
ok1(tdb_check(tdb, NULL, NULL) == 0); ok1(tdb_check(tdb, NULL, NULL) == 0);
tdb_close(tdb); 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);
ok1(tdb_check(tdb, NULL, NULL) == 0); ok1(tdb_check(tdb, NULL, NULL) == 0);
tdb_close(tdb); 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);
ok1(tdb_check(tdb, NULL, NULL) == -1); ok1(tdb_check(tdb, NULL, NULL) == -1);
ok1(tdb_error(tdb) == TDB_ERR_CORRUPT); ok1(tdb_error(tdb) == TDB_ERR_CORRUPT);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment