s3: Add two tests a CLEAR_IF_FIRST crash
authorVolker Lendecke <vl@samba.org>
Mon, 8 Oct 2012 19:25:49 +0000 (12:25 -0700)
committerKarolin Seeger <kseeger@samba.org>
Tue, 9 Oct 2012 07:25:57 +0000 (09:25 +0200)
The last 3 patches address bug #9268 - Make tdb robust against improper
CLEAR_IF_FIRST restart.

source3/torture/torture.c

index 658224a9446ae81e3e2db84fa8cf2d91e261418c..d37d83c782446feb8a07041ec65a597a13a9b4cb 100644 (file)
@@ -8102,6 +8102,60 @@ fail:
        return result;
 }
 
+static bool run_local_tdb_opener(int dummy)
+{
+       TDB_CONTEXT *t;
+       unsigned v = 0;
+
+       while (1) {
+               t = tdb_open("test.tdb", 1000, TDB_CLEAR_IF_FIRST,
+                            O_RDWR|O_CREAT, 0755);
+               if (t == NULL) {
+                       perror("tdb_open failed");
+                       return false;
+               }
+               tdb_close(t);
+
+               v += 1;
+               printf("\r%u", v);
+       }
+       return true;
+}
+
+static bool run_local_tdb_writer(int dummy)
+{
+       TDB_CONTEXT *t;
+       unsigned v = 0;
+       TDB_DATA val;
+
+       t = tdb_open("test.tdb", 1000, 0, O_RDWR|O_CREAT, 0755);
+       if (t == 0) {
+               perror("tdb_open failed");
+               return 1;
+       }
+
+       val.dptr = (uint8_t *)&v;
+       val.dsize = sizeof(v);
+
+       while (1) {
+               TDB_DATA data;
+               int ret;
+
+               ret = tdb_store(t, val, val, 0);
+               if (ret != 0) {
+                       printf("%s\n", tdb_errorstr(t));
+               }
+               v += 1;
+               printf("\r%u", v);
+
+               data = tdb_fetch(t, val);
+               if (data.dptr != NULL) {
+                       SAFE_FREE(data.dptr);
+               }
+       }
+       return true;
+}
+
 static double create_procs(bool (*fn)(int), bool *result)
 {
        int i, status;
@@ -8290,6 +8344,8 @@ static struct {
        { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
        { "LOCAL-DBTRANS", run_local_dbtrans, 0},
        { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
+       { "LOCAL-TDB-OPENER", run_local_tdb_opener, 0 },
+       { "LOCAL-TDB-WRITER", run_local_tdb_writer, 0 },
        {NULL, NULL, 0}};