Commit 4b8fc285 authored by Leif Walsh's avatar Leif Walsh Committed by Yoni Fogel

closes #5450 fix use-after-free, remove whitespace


git-svn-id: file:///svn/toku/tokudb@47596 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0fbccaae
...@@ -14,15 +14,15 @@ ...@@ -14,15 +14,15 @@
struct checkpointer_test { struct checkpointer_test {
checkpointer m_cp; checkpointer m_cp;
pair_list m_pl; pair_list m_pl;
// Tests // Tests
void test_begin_checkpoint(); void test_begin_checkpoint();
void test_pending_bits(); void test_pending_bits();
void test_end_checkpoint(); void test_end_checkpoint();
// Test Helper // Test Helper
void add_pairs(struct cachefile *cf, void add_pairs(struct cachefile *cf,
ctpair pairs[], ctpair pairs[],
uint32_t count, uint32_t count,
uint32_t k); uint32_t k);
}; };
...@@ -34,15 +34,15 @@ static int dummy_log_fassociate(CACHEFILE UU(cf), void* UU(p)) ...@@ -34,15 +34,15 @@ static int dummy_log_fassociate(CACHEFILE UU(cf), void* UU(p))
{ return 0; } { return 0; }
static int dummy_log_rollback(CACHEFILE UU(cf), void* UU(p)) static int dummy_log_rollback(CACHEFILE UU(cf), void* UU(p))
{ return 0; } { return 0; }
static int dummy_close_usr(CACHEFILE UU(cf), int UU(i), void* UU(p), char** UU(c), bool UU(b), LSN UU(lsn)) static int dummy_close_usr(CACHEFILE UU(cf), int UU(i), void* UU(p), char** UU(c), bool UU(b), LSN UU(lsn))
{ return 0; } { return 0; }
static int dummy_chckpnt_usr(CACHEFILE UU(cf), int UU(i), void* UU(p)) static int dummy_chckpnt_usr(CACHEFILE UU(cf), int UU(i), void* UU(p))
{ return 0; } { return 0; }
static int dummy_begin(LSN UU(lsn), void* UU(p)) static int dummy_begin(LSN UU(lsn), void* UU(p))
{ return 0; } { return 0; }
static int dummy_end(CACHEFILE UU(cf), int UU(i), void* UU(p)) static int dummy_end(CACHEFILE UU(cf), int UU(i), void* UU(p))
{ return 0; } { return 0; }
static int dummy_note_pin(CACHEFILE UU(cf), void* UU(p)) static int dummy_note_pin(CACHEFILE UU(cf), void* UU(p))
{ return 0; } { return 0; }
static int dummy_note_unpin(CACHEFILE UU(cf), void* UU(p)) static int dummy_note_unpin(CACHEFILE UU(cf), void* UU(p))
{ return 0; } { return 0; }
...@@ -75,19 +75,19 @@ create_dummy_functions(CACHEFILE cf) ...@@ -75,19 +75,19 @@ create_dummy_functions(CACHEFILE cf)
// //
void checkpointer_test::test_begin_checkpoint() { void checkpointer_test::test_begin_checkpoint() {
int r = 0; int r = 0;
cachefile_list cfl; cachefile_list cfl;
cfl.init(); cfl.init();
cachetable ctbl; cachetable ctbl;
ctbl.list.init(); ctbl.list.init();
m_cp.init(&ctbl.list, NULL, &ctbl.ev, &cfl); m_cp.init(&ctbl.list, NULL, &ctbl.ev, &cfl);
// 1. Call checkpoint with NO cachefiles. // 1. Call checkpoint with NO cachefiles.
r = m_cp.begin_checkpoint(); r = m_cp.begin_checkpoint();
if (r) { assert(!"CHECKPOINTER: Checkpoint with no cachefiles failed!\n"); } if (r) { assert(!"CHECKPOINTER: Checkpoint with no cachefiles failed!\n"); }
// 2. Call checkpoint with ONE cachefile. // 2. Call checkpoint with ONE cachefile.
//cachefile cf; //cachefile cf;
struct cachefile cf; struct cachefile cf;
...@@ -95,7 +95,7 @@ void checkpointer_test::test_begin_checkpoint() { ...@@ -95,7 +95,7 @@ void checkpointer_test::test_begin_checkpoint() {
cf.for_checkpoint = false; cf.for_checkpoint = false;
m_cp.m_cf_list->m_head = &cf; m_cp.m_cf_list->m_head = &cf;
create_dummy_functions(&cf); create_dummy_functions(&cf);
r = m_cp.begin_checkpoint(); r = m_cp.begin_checkpoint();
if (r) { assert(!"CHECKPOINTER: Checkpoint with one cachefile failed!\n"); } if (r) { assert(!"CHECKPOINTER: Checkpoint with one cachefile failed!\n"); }
assert(m_cp.m_checkpoint_num_files == 1); assert(m_cp.m_checkpoint_num_files == 1);
...@@ -114,7 +114,7 @@ void checkpointer_test::test_begin_checkpoint() { ...@@ -114,7 +114,7 @@ void checkpointer_test::test_begin_checkpoint() {
cfs[i].next = &cfs[i + 1]; cfs[i].next = &cfs[i + 1];
} }
} }
r = m_cp.begin_checkpoint(); r = m_cp.begin_checkpoint();
if (r) { assert(!"CHECKPOINTER: Multiple checkpoint failed!\n"); } if (r) { assert(!"CHECKPOINTER: Multiple checkpoint failed!\n"); }
assert(m_cp.m_checkpoint_num_files == count); assert(m_cp.m_checkpoint_num_files == count);
...@@ -133,15 +133,17 @@ void checkpointer_test::test_begin_checkpoint() { ...@@ -133,15 +133,17 @@ void checkpointer_test::test_begin_checkpoint() {
void checkpointer_test::test_pending_bits() { void checkpointer_test::test_pending_bits() {
cachefile_list cfl; cachefile_list cfl;
cfl.init(); cfl.init();
cachetable ctbl; cachetable ctbl;
ctbl.list.init(); ctbl.list.init();
m_cp.init(&ctbl.list, NULL, &ctbl.ev, &cfl);
// //
// 1. Empty hash chain. // 1. Empty hash chain.
// //
m_cp.turn_on_pending_bits(); m_cp.turn_on_pending_bits();
// //
// 2. One entry in pair chain // 2. One entry in pair chain
// //
...@@ -151,14 +153,14 @@ void checkpointer_test::test_pending_bits() { ...@@ -151,14 +153,14 @@ void checkpointer_test::test_pending_bits() {
cf.for_checkpoint = true; cf.for_checkpoint = true;
m_cp.m_cf_list->m_head = &cf; m_cp.m_cf_list->m_head = &cf;
create_dummy_functions(&cf); create_dummy_functions(&cf);
CACHEKEY k; CACHEKEY k;
k.b = 0; k.b = 0;
uint32_t hash = toku_cachetable_hash(&cf, k); uint32_t hash = toku_cachetable_hash(&cf, k);
ctpair p; ctpair p;
CACHETABLE_WRITE_CALLBACK cb; CACHETABLE_WRITE_CALLBACK cb;
pair_attr_s attr; pair_attr_s attr;
attr.size = 0; attr.size = 0;
attr.nonleaf_size = 0; attr.nonleaf_size = 0;
...@@ -166,33 +168,33 @@ void checkpointer_test::test_pending_bits() { ...@@ -166,33 +168,33 @@ void checkpointer_test::test_pending_bits() {
attr.rollback_size = 0; attr.rollback_size = 0;
attr.cache_pressure_size = 0; attr.cache_pressure_size = 0;
attr.is_valid = true; attr.is_valid = true;
pair_init(&p, pair_init(&p,
&cf, &cf,
k, k,
NULL, NULL,
attr, attr,
CACHETABLE_CLEAN, CACHETABLE_CLEAN,
hash, hash,
cb, cb,
NULL, NULL,
&ctbl.list); &ctbl.list);
m_cp.m_list->put(&p); m_cp.m_list->put(&p);
m_cp.turn_on_pending_bits(); m_cp.turn_on_pending_bits();
assert(p.checkpoint_pending); assert(p.checkpoint_pending);
m_cp.m_list->evict(&p); m_cp.m_list->evict(&p);
// //
// 3. Many hash chain entries. // 3. Many hash chain entries.
// //
const uint32_t count = 3; const uint32_t count = 3;
ctpair pairs[count]; ctpair pairs[count];
add_pairs(&cf, pairs, count, 0); add_pairs(&cf, pairs, count, 0);
m_cp.turn_on_pending_bits(); m_cp.turn_on_pending_bits();
for (uint32_t i = 0; i < count; ++i) { for (uint32_t i = 0; i < count; ++i) {
assert(pairs[i].checkpoint_pending); assert(pairs[i].checkpoint_pending);
} }
...@@ -204,9 +206,10 @@ void checkpointer_test::test_pending_bits() { ...@@ -204,9 +206,10 @@ void checkpointer_test::test_pending_bits() {
assert(pp); assert(pp);
m_cp.m_list->evict(pp); m_cp.m_list->evict(pp);
} }
int r = ctbl.list.destroy(); int r = ctbl.list.destroy();
assert_zero(r); assert_zero(r);
m_cp.destroy();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -227,7 +230,7 @@ void checkpointer_test::add_pairs(struct cachefile *cf, ...@@ -227,7 +230,7 @@ void checkpointer_test::add_pairs(struct cachefile *cf,
attr.cache_pressure_size = 0; attr.cache_pressure_size = 0;
attr.is_valid = true; attr.is_valid = true;
CACHETABLE_WRITE_CALLBACK cb; CACHETABLE_WRITE_CALLBACK cb;
for (uint32_t i = k; i < count + k; ++i) { for (uint32_t i = k; i < count + k; ++i) {
CACHEKEY key; CACHEKEY key;
key.b = i; key.b = i;
...@@ -248,11 +251,11 @@ void checkpointer_test::add_pairs(struct cachefile *cf, ...@@ -248,11 +251,11 @@ void checkpointer_test::add_pairs(struct cachefile *cf,
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// get_number_pending_pairs() - // get_number_pending_pairs() -
// //
// Description: Helper function that iterates over pending list, and returns // Description: Helper function that iterates over pending list, and returns
// the number of pairs discovered. // the number of pairs discovered.
// //
static uint32_t get_number_pending_pairs(pair_list *list) static uint32_t get_number_pending_pairs(pair_list *list)
{ {
PAIR p; PAIR p;
...@@ -263,7 +266,7 @@ static uint32_t get_number_pending_pairs(pair_list *list) ...@@ -263,7 +266,7 @@ static uint32_t get_number_pending_pairs(pair_list *list)
list->m_pending_head = list->m_pending_head->pending_next; list->m_pending_head = list->m_pending_head->pending_next;
count++; count++;
} }
list->m_pending_head = head; list->m_pending_head = head;
return count; return count;
} }
...@@ -280,13 +283,13 @@ void checkpointer_test::test_end_checkpoint() { ...@@ -280,13 +283,13 @@ void checkpointer_test::test_end_checkpoint() {
cachefile_list cfl; cachefile_list cfl;
cfl.init(); cfl.init();
struct cachefile cf; struct cachefile cf;
memset(&cf, 0, sizeof(cf)); memset(&cf, 0, sizeof(cf));
cf.next = NULL; cf.next = NULL;
cf.for_checkpoint = true; cf.for_checkpoint = true;
create_dummy_functions(&cf); create_dummy_functions(&cf);
m_cp.init(&ctbl.list, NULL, &ctbl.ev, &cfl); m_cp.init(&ctbl.list, NULL, &ctbl.ev, &cfl);
m_cp.m_cf_list->m_head = &cf; m_cp.m_cf_list->m_head = &cf;
...@@ -295,7 +298,7 @@ void checkpointer_test::test_end_checkpoint() { ...@@ -295,7 +298,7 @@ void checkpointer_test::test_end_checkpoint() {
ctpair pairs[count]; ctpair pairs[count];
add_pairs(&cf, pairs, count / 2, 0); add_pairs(&cf, pairs, count / 2, 0);
assert(m_cp.m_list->m_n_in_table == count / 2); assert(m_cp.m_list->m_n_in_table == count / 2);
// 3. Call begin checkpoint. // 3. Call begin checkpoint.
m_cp.begin_checkpoint(); m_cp.begin_checkpoint();
assert(m_cp.m_checkpoint_num_files == 1); assert(m_cp.m_checkpoint_num_files == 1);
...@@ -303,7 +306,7 @@ void checkpointer_test::test_end_checkpoint() { ...@@ -303,7 +306,7 @@ void checkpointer_test::test_end_checkpoint() {
{ {
assert(pairs[i].checkpoint_pending); assert(pairs[i].checkpoint_pending);
} }
// 4. Add new data between starting and stopping checkpoint. // 4. Add new data between starting and stopping checkpoint.
add_pairs(&cf, pairs, count / 2, count / 2); add_pairs(&cf, pairs, count / 2, count / 2);
assert(m_cp.m_list->m_n_in_table == count); assert(m_cp.m_list->m_n_in_table == count);
...@@ -311,11 +314,11 @@ void checkpointer_test::test_end_checkpoint() { ...@@ -311,11 +314,11 @@ void checkpointer_test::test_end_checkpoint() {
{ {
assert(!pairs[i].checkpoint_pending); assert(!pairs[i].checkpoint_pending);
} }
uint32_t pending_pairs = 0; uint32_t pending_pairs = 0;
pending_pairs = get_number_pending_pairs(m_cp.m_list); pending_pairs = get_number_pending_pairs(m_cp.m_list);
assert(pending_pairs == count / 2); assert(pending_pairs == count / 2);
// 5. Call end checkpoint // 5. Call end checkpoint
m_cp.end_checkpoint(NULL, NULL); m_cp.end_checkpoint(NULL, NULL);
...@@ -327,7 +330,7 @@ void checkpointer_test::test_end_checkpoint() { ...@@ -327,7 +330,7 @@ void checkpointer_test::test_end_checkpoint() {
{ {
assert(!pairs[i].checkpoint_pending); assert(!pairs[i].checkpoint_pending);
} }
// 6. Cleanup // 6. Cleanup
for (uint32_t i = 0; i < count; ++i) { for (uint32_t i = 0; i < count; ++i) {
CACHEKEY key; CACHEKEY key;
...@@ -353,13 +356,11 @@ test_main(int argc, const char *argv[]) { ...@@ -353,13 +356,11 @@ test_main(int argc, const char *argv[]) {
int r = 0; int r = 0;
default_parse_args(argc, argv); default_parse_args(argc, argv);
checkpointer_test cp_test; checkpointer_test cp_test;
// Run the tests. // Run the tests.
cp_test.test_begin_checkpoint(); cp_test.test_begin_checkpoint();
cp_test.test_pending_bits(); cp_test.test_pending_bits();
cp_test.test_end_checkpoint(); cp_test.test_end_checkpoint();
return r; return r;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment