From 7b3cfeca9d3406a8ac028a2bad29b37d139be6de Mon Sep 17 00:00:00 2001
From: Dave Wells <wells@tokutek.com>
Date: Tue, 16 Apr 2013 23:58:03 -0400
Subject: [PATCH] changed checkpoint_stress.c to work correctly with -l option.
  This allows testing with recovery turned on.  Incomplete, but partially
 addresses #1977

git-svn-id: file:///svn/toku/tokudb@14720 c7de825b-a66e-492c-adef-691d508d4ae1
---
 src/tests/Makefile            | 12 ++++++++++++
 src/tests/checkpoint_1.c      |  4 ++--
 src/tests/checkpoint_stress.c | 17 ++++++++++++++---
 src/tests/checkpoint_test.h   |  6 ++----
 4 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/src/tests/Makefile b/src/tests/Makefile
index dca26d08474..1a276bf7e43 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -507,6 +507,18 @@ checkpoint_stress.tdbrun: checkpoint_stress.tdb$(BINSUF) $(PTHREAD_LOCAL)
 	test `grep -l 'HAPPY CRASH' dir.checkpoint_stress.c.tdb/error.* |wc -l` = $$(($(STRESS_RUNS)-1)) \
 	) $(MAYBEINVERTER) $(SUMMARIZE_CMD)
 
+recover_stress.tdbrun: SHELL=/bin/bash
+recover_stress.tdbrun: checkpoint_stress.tdb$(BINSUF) $(PTHREAD_LOCAL)
+	$(VGRIND) ./$< -C -n $(STRESS_SIZE) -l $(VERBVERBOSE) && \
+	($(VGRIND) ./$< -C -i 0 -n $(STRESS_SIZE) -l $(VERBVERBOSE) && \
+	 for (( i = 1; i < $(STRESS_RUNS); i++ )); do \
+		date; \
+		./$< -c -i $$i -n $(STRESS_SIZE) -l $(VERBVERBOSE) 2> dir.checkpoint_stress.c.tdb/error.$$i ; \
+		if ! grep -q 'HAPPY CRASH' dir.checkpoint_stress.c.tdb/error.$$i; then break; fi; \
+	done && \
+	test `grep -l 'HAPPY CRASH' dir.checkpoint_stress.c.tdb/error.* |wc -l` = $$(($(STRESS_RUNS)-1)) \
+	) $(MAYBEINVERTER) $(SUMMARIZE_CMD)
+
 # helgrind1 is supposed to fail.
 helgrind1.tdbrun: TDBVGRIND=$(HGRIND) --log-file=helgrind1.tdb.deleteme
 helgrind1.tdbrun: MAYBEINVERTER=$(INVERTER)
diff --git a/src/tests/checkpoint_1.c b/src/tests/checkpoint_1.c
index 7131e911713..50ec2ec0246 100644
--- a/src/tests/checkpoint_1.c
+++ b/src/tests/checkpoint_1.c
@@ -23,7 +23,7 @@ checkpoint_test_1(u_int32_t flags, u_int32_t n, int snap_all) {
         fflush(stdout); 
     }
     dir_create();
-    env_startup(0, FALSE);
+    env_startup(0, 0);
     int run;
     int r;
     DICTIONARY_S db_control;
@@ -61,7 +61,7 @@ checkpoint_test_2(u_int32_t flags, u_int32_t n) {
         fflush(stdout); 
     }
     dir_create();
-    env_startup(0, FALSE);
+    env_startup(0, 0);
     int run;
     int r;
     DICTIONARY_S db_control;
diff --git a/src/tests/checkpoint_stress.c b/src/tests/checkpoint_stress.c
index f0bb1e8e81b..a4c3096a0de 100644
--- a/src/tests/checkpoint_stress.c
+++ b/src/tests/checkpoint_stress.c
@@ -107,7 +107,8 @@ thin_out(DB* db, int iter) {
 	}
     }
     
-    r = txn->commit(txn, 0);
+    if ( !do_log_recover )
+        r = txn->commit(txn, 0);
     CKERR(r);
 
 }
@@ -156,7 +157,11 @@ verify_and_insert (DB* db, int iter) {
     firstkey = iter * oper_per_iter;
     numkeys = oper_per_iter;
 
+    int r;
+    DB_TXN *txn;
+    r = env->txn_begin(env, NULL, &txn, 0);               CKERR(r);
     insert_n_fixed(db, NULL, NULL, firstkey, numkeys);
+    r = txn->commit(txn, 0);                              CKERR(r);
 }
 
 
@@ -219,8 +224,14 @@ run_test (int iter, int die) {
 
     if (verbose)
 	printf("checkpoint_stress: iter = %d, cachesize (bytes) = 0x%08"PRIx64"\n", iter, cachebytes);
-    
-    env_startup(cachebytes, do_log_recover);
+
+    int recovery_flags = 0;
+    if ( do_log_recover ) {
+        flags += DB_INIT_LOG;
+        if ( iter != 0 )
+            flags += DB_RECOVER;
+    }
+    env_startup(cachebytes, recovery_flags);
 
     // create array of dictionaries
     // for each dictionary verify previous iterations and perform new inserts
diff --git a/src/tests/checkpoint_test.h b/src/tests/checkpoint_test.h
index ea148cfacd9..e26b1305b05 100644
--- a/src/tests/checkpoint_test.h
+++ b/src/tests/checkpoint_test.h
@@ -96,7 +96,7 @@ dir_create(void) {
 
 // pass in zeroes for default cachesize
 static void  UU()
-    env_startup(int64_t bytes, BOOL do_log_recover) {
+    env_startup(int64_t bytes, int recovery_flags) {
     int r;
     r = db_env_create(&env, 0);
         CKERR(r);
@@ -108,9 +108,7 @@ static void  UU()
 	r = env->set_cachesize(env, bytes >> 30, bytes % (1<<30), 1);
         CKERR(r);
     }
-    int envflags = DB_INIT_LOCK | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE;
-    if (do_log_recover)
-        envflags += DB_INIT_LOG | DB_RECOVER;
+    int envflags = DB_INIT_LOCK | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE | recovery_flags;
     r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO);
         CKERR(r);
     env->set_errfile(env, stderr);
-- 
2.30.9