From d5ab80054d3c1dde396c18ae506bb3713e84e7e6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 9 Nov 2007 23:43:24 +0100 Subject: dbwrap_rbt This is meant as a replacement for the internal tdb. To me it seems a bit silly that for in-memory structures we do our own memory management. With this rbt based approach we can make use of the system-supplied malloc. (This used to be commit 54e5d4404619443caed32e2acff8921cdbff9ed1) --- source3/torture/torture.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'source3/torture') diff --git a/source3/torture/torture.c b/source3/torture/torture.c index 48b7aa60c0..1e6865b754 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -4960,6 +4960,88 @@ static bool run_local_gencache(int dummy) return True; } +static bool rbt_testval(struct db_context *db, const char *key, + const char *value) +{ + struct db_record *rec; + TDB_DATA data = string_tdb_data(value); + bool ret = false; + NTSTATUS status; + + rec = db->fetch_locked(db, db, string_tdb_data(key)); + if (rec == NULL) { + d_fprintf(stderr, "fetch_locked failed\n"); + goto done; + } + status = rec->store(rec, data, 0); + if (!NT_STATUS_IS_OK(status)) { + d_fprintf(stderr, "store failed: %s\n", nt_errstr(status)); + goto done; + } + TALLOC_FREE(rec); + + rec = db->fetch_locked(db, db, string_tdb_data(key)); + if (rec == NULL) { + d_fprintf(stderr, "second fetch_locked failed\n"); + goto done; + } + if ((rec->value.dsize != data.dsize) + || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) { + d_fprintf(stderr, "Got wrong data back\n"); + goto done; + } + + ret = true; + done: + TALLOC_FREE(rec); + return ret; +} + +static bool run_local_rbtree(int dummy) +{ + struct db_context *db; + bool ret = false; + int i; + + db = db_open_rbt(NULL); + + if (db == NULL) { + d_fprintf(stderr, "db_open_rbt failed\n"); + return false; + } + + for (i=0; i<1000; i++) { + char *key, *value; + + asprintf(&key, "key%ld", random()); + asprintf(&value, "value%ld", random()); + + if (!rbt_testval(db, key, value)) { + SAFE_FREE(key); + SAFE_FREE(value); + goto done; + } + + SAFE_FREE(value); + asprintf(&value, "value%ld", random()); + + if (!rbt_testval(db, key, value)) { + SAFE_FREE(key); + SAFE_FREE(value); + goto done; + } + + SAFE_FREE(key); + SAFE_FREE(value); + } + + ret = true; + + done: + TALLOC_FREE(db); + return ret; +} + static double create_procs(bool (*fn)(int), bool *result) { int i, status; @@ -5113,6 +5195,7 @@ static struct { { "SESSSETUP_BENCH", run_sesssetup_bench, 0}, { "LOCAL-SUBSTITUTE", run_local_substitute, 0}, { "LOCAL-GENCACHE", run_local_gencache, 0}, + { "LOCAL-RBTREE", run_local_rbtree, 0}, {NULL, NULL, 0}}; -- cgit