summaryrefslogtreecommitdiff
path: root/source3/torture
diff options
context:
space:
mode:
authorVolker Lendecke <vl@sernet.de>2007-11-09 23:43:24 +0100
committerVolker Lendecke <vl@samba.org>2007-12-10 16:06:32 +0100
commitd5ab80054d3c1dde396c18ae506bb3713e84e7e6 (patch)
treec6953bf605e9aca1ebfbc10ab1160019ae1665f4 /source3/torture
parent8a8b146ead07149de57069ed803051ce460fa94b (diff)
downloadsamba-d5ab80054d3c1dde396c18ae506bb3713e84e7e6.tar.gz
samba-d5ab80054d3c1dde396c18ae506bb3713e84e7e6.tar.bz2
samba-d5ab80054d3c1dde396c18ae506bb3713e84e7e6.zip
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)
Diffstat (limited to 'source3/torture')
-rw-r--r--source3/torture/torture.c83
1 files changed, 83 insertions, 0 deletions
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}};