diff options
author | Andrew Tridgell <tridge@samba.org> | 2001-09-24 04:56:56 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2001-09-24 04:56:56 +0000 |
commit | 7ef445e22683f8a6221ffce76fff219e112348a7 (patch) | |
tree | 3bd1905a54f5e039b7d917f5efa7a78a055e9bd8 /source3/tdb | |
parent | 1fcc9e1f6d2a6ee3f170055692cbfbe7432cf7ee (diff) | |
download | samba-7ef445e22683f8a6221ffce76fff219e112348a7.tar.gz samba-7ef445e22683f8a6221ffce76fff219e112348a7.tar.bz2 samba-7ef445e22683f8a6221ffce76fff219e112348a7.zip |
tdbtorture updates from when I was trying to track down the hp tdb bug
(This used to be commit b8d9d1fca3eec5150fb9784f1d0157a82e60cebd)
Diffstat (limited to 'source3/tdb')
-rw-r--r-- | source3/tdb/tdbtorture.c | 62 |
1 files changed, 50 insertions, 12 deletions
diff --git a/source3/tdb/tdbtorture.c b/source3/tdb/tdbtorture.c index 13f5aec518..4ee36fa857 100644 --- a/source3/tdb/tdbtorture.c +++ b/source3/tdb/tdbtorture.c @@ -17,12 +17,15 @@ -#define DELETE_PROB 10 -#define STORE_PROB 3 -#define TRAVERSE_PROB 8 -#define CULL_PROB 60 +#define REOPEN_PROB 30 +#define DELETE_PROB 8 +#define STORE_PROB 4 +#define LOCKSTORE_PROB 0 +#define TRAVERSE_PROB 20 +#define CULL_PROB 100 #define KEYLEN 3 #define DATALEN 100 +#define LOCKLEN 20 static TDB_CONTEXT *db; @@ -74,15 +77,17 @@ static int cull_traverse(TDB_CONTEXT *db, TDB_DATA key, TDB_DATA dbuf, static void addrec_db(void) { - int klen, dlen; - char *k, *d; - TDB_DATA key, data; + int klen, dlen, slen; + char *k, *d, *s; + TDB_DATA key, data, lockkey; klen = 1 + (rand() % KEYLEN); dlen = 1 + (rand() % DATALEN); + slen = 1 + (rand() % LOCKLEN); k = randbuf(klen); d = randbuf(dlen); + s = randbuf(slen); key.dptr = k; key.dsize = klen+1; @@ -90,21 +95,54 @@ static void addrec_db(void) data.dptr = d; data.dsize = dlen+1; + lockkey.dptr = s; + lockkey.dsize = slen+1; + +#if REOPEN_PROB + if (random() % REOPEN_PROB == 0) { + tdb_reopen_all(); + goto next; + } +#endif + +#if DELETE_PROB if (random() % DELETE_PROB == 0) { tdb_delete(db, key); - } else if (random() % STORE_PROB == 0) { + } +#endif + +#if STORE_PROB + if (random() % STORE_PROB == 0) { if (tdb_store(db, key, data, TDB_REPLACE) != 0) { fatal("tdb_store failed"); } - } else if (random() % TRAVERSE_PROB == 0) { - tdb_traverse(db, cull_traverse, NULL); - } else { + } +#endif + +#if LOCKSTORE_PROB + if (random() % LOCKSTORE_PROB == 0) { + tdb_chainlock(db, lockkey); data = tdb_fetch(db, key); + if (tdb_store(db, key, data, TDB_REPLACE) != 0) { + fatal("tdb_store failed"); + } if (data.dptr) free(data.dptr); + tdb_chainunlock(db, lockkey); + } +#endif + +#if TRAVERSE_PROB + if (random() % TRAVERSE_PROB == 0) { + tdb_traverse(db, cull_traverse, NULL); } +#endif + + data = tdb_fetch(db, key); + if (data.dptr) free(data.dptr); free(k); free(d); + free(s); } static int traverse_fn(TDB_CONTEXT *db, TDB_DATA key, TDB_DATA dbuf, @@ -134,7 +172,7 @@ int main(int argc, char *argv[]) if ((pids[i+1]=fork()) == 0) break; } - db = tdb_open("torture.tdb", 0, TDB_CLEAR_IF_FIRST, + db = tdb_open("torture.tdb", 2, TDB_CLEAR_IF_FIRST, O_RDWR | O_CREAT, 0600); if (!db) { fatal("db open failed"); |