1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

tdbtorture updates from when I was trying to track down the hp tdb bug

This commit is contained in:
Andrew Tridgell 0001-01-01 00:00:00 +00:00
parent cd6478ad98
commit b8d9d1fca3

View File

@ -17,12 +17,15 @@
#define DELETE_PROB 10 #define REOPEN_PROB 30
#define STORE_PROB 3 #define DELETE_PROB 8
#define TRAVERSE_PROB 8 #define STORE_PROB 4
#define CULL_PROB 60 #define LOCKSTORE_PROB 0
#define TRAVERSE_PROB 20
#define CULL_PROB 100
#define KEYLEN 3 #define KEYLEN 3
#define DATALEN 100 #define DATALEN 100
#define LOCKLEN 20
static TDB_CONTEXT *db; 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) static void addrec_db(void)
{ {
int klen, dlen; int klen, dlen, slen;
char *k, *d; char *k, *d, *s;
TDB_DATA key, data; TDB_DATA key, data, lockkey;
klen = 1 + (rand() % KEYLEN); klen = 1 + (rand() % KEYLEN);
dlen = 1 + (rand() % DATALEN); dlen = 1 + (rand() % DATALEN);
slen = 1 + (rand() % LOCKLEN);
k = randbuf(klen); k = randbuf(klen);
d = randbuf(dlen); d = randbuf(dlen);
s = randbuf(slen);
key.dptr = k; key.dptr = k;
key.dsize = klen+1; key.dsize = klen+1;
@ -90,21 +95,54 @@ static void addrec_db(void)
data.dptr = d; data.dptr = d;
data.dsize = dlen+1; 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) { if (random() % DELETE_PROB == 0) {
tdb_delete(db, key); 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) { if (tdb_store(db, key, data, TDB_REPLACE) != 0) {
fatal("tdb_store failed"); fatal("tdb_store failed");
} }
} else if (random() % TRAVERSE_PROB == 0) {
tdb_traverse(db, cull_traverse, NULL);
} else {
data = tdb_fetch(db, key);
if (data.dptr) free(data.dptr);
} }
#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(k);
free(d); free(d);
free(s);
} }
static int traverse_fn(TDB_CONTEXT *db, TDB_DATA key, TDB_DATA dbuf, 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; 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); O_RDWR | O_CREAT, 0600);
if (!db) { if (!db) {
fatal("db open failed"); fatal("db open failed");