Commit 0577b98a authored by Yoni Fogel's avatar Yoni Fogel

Addresses #307

Additional tests.
Code coverage of non-write stuff is complete except for asserts and error cases.
We have not yet checked branch coverage.

git-svn-id: file:///svn/tokudb@1973 c7de825b-a66e-492c-adef-691d508d4ae1
parent 4bdbce1c
...@@ -36,6 +36,10 @@ int dbcmp (DB *db __attribute__((__unused__)), const DBT *a, const DBT*b) { ...@@ -36,6 +36,10 @@ int dbcmp (DB *db __attribute__((__unused__)), const DBT *a, const DBT*b) {
return toku_keycompare(a->data, a->size, b->data, b->size); return toku_keycompare(a->data, a->size, b->data, b->size);
} }
void dbpanic(DB* db) {
if (verbose) printf("AHH!!!! Run away %p!!!\n", db);
}
#define CKERR(r) ({ if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, strerror(r)); assert(r==0); }) #define CKERR(r) ({ if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, strerror(r)); assert(r==0); })
#define CKERR2(r,r2) ({ if (r!=r2) fprintf(stderr, "%s:%d error %d %s, expected %d\n", __FILE__, __LINE__, r, strerror(r), r2); assert(r==r2); }) #define CKERR2(r,r2) ({ if (r!=r2) fprintf(stderr, "%s:%d error %d %s, expected %d\n", __FILE__, __LINE__, r, strerror(r), r2); assert(r==r2); })
......
...@@ -8,7 +8,7 @@ int main() { ...@@ -8,7 +8,7 @@ int main() {
BOOL duplicates; BOOL duplicates;
for (duplicates = 0; duplicates < 2; duplicates++) { for (duplicates = 0; duplicates < 2; duplicates++) {
r = toku_lt_create(&lt, db, duplicates, mem, dbcmp, dbcmp, r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
......
...@@ -39,7 +39,7 @@ static void do_range_test(int (*acquire)(toku_lock_tree*, DB_TXN*, ...@@ -39,7 +39,7 @@ static void do_range_test(int (*acquire)(toku_lock_tree*, DB_TXN*,
reverse_data_l = &_data_l; reverse_data_l = &_data_l;
reverse_data_r = &_data_r; reverse_data_r = &_data_r;
} }
r = toku_lt_create(&lt, db, duplicates, mem, dbcmp, dbcmp, r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
...@@ -141,7 +141,7 @@ static void do_point_test(int (*acquire)(toku_lock_tree*, DB_TXN*, ...@@ -141,7 +141,7 @@ static void do_point_test(int (*acquire)(toku_lock_tree*, DB_TXN*,
reverse_data = &_data; reverse_data = &_data;
data = NULL; data = NULL;
} }
r = toku_lt_create(&lt, db, duplicates, mem, dbcmp, dbcmp, r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
...@@ -186,33 +186,36 @@ int main(int argc, const char *argv[]) { ...@@ -186,33 +186,36 @@ int main(int argc, const char *argv[]) {
/* create tests. */ /* create tests. */
for (duplicates = 0; duplicates < 2; duplicates++) { for (duplicates = 0; duplicates < 2; duplicates++) {
r = toku_lt_create(NULL, db, duplicates, mem, dbcmp, dbcmp, r = toku_lt_create(NULL, db, duplicates, dbpanic, mem, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_create(&lt, NULL, duplicates, mem, dbcmp, dbcmp, r = toku_lt_create(&lt, NULL, duplicates, dbpanic, mem, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, db, duplicates, NULL, mem, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
size_t old_mem = mem; size_t old_mem = mem;
mem = 0; mem = 0;
r = toku_lt_create(&lt, db, duplicates, mem, dbcmp, dbcmp, r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
mem = old_mem; mem = old_mem;
r = toku_lt_create(&lt, db, duplicates, mem, NULL, dbcmp, r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, NULL, dbcmp,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_create(&lt, db, duplicates, mem, dbcmp, NULL, r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, dbcmp, NULL,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_create(&lt, db, duplicates, mem, dbcmp, dbcmp, r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, dbcmp, dbcmp,
NULL, toku_free, toku_realloc); NULL, toku_free, toku_realloc);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_create(&lt, db, duplicates, mem, dbcmp, dbcmp, r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, dbcmp, dbcmp,
toku_malloc, NULL, toku_realloc); toku_malloc, NULL, toku_realloc);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_create(&lt, db, duplicates, mem, dbcmp, dbcmp, r = toku_lt_create(&lt, db, duplicates, dbpanic, mem, dbcmp, dbcmp,
toku_malloc, toku_free, NULL); toku_malloc, toku_free, NULL);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
} }
......
...@@ -29,7 +29,7 @@ unsigned buflen; ...@@ -29,7 +29,7 @@ unsigned buflen;
unsigned numfound; unsigned numfound;
void setup_tree(BOOL dups) { void setup_tree(BOOL dups) {
r = toku_lt_create(&lt, db, dups, mem, dbcmp, dbcmp, r = toku_lt_create(&lt, db, dups, dbpanic, mem, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
...@@ -42,17 +42,18 @@ void close_tree(void) { ...@@ -42,17 +42,18 @@ void close_tree(void) {
lt = NULL; lt = NULL;
} }
typedef enum { infinite = -2, neg_infinite = -3 } lt_infty; typedef enum { null = -1, infinite = -2, neg_infinite = -3 } lt_infty;
DBT *set_to_infty(DBT *dbt, lt_infty value) { DBT* set_to_infty(DBT *dbt, lt_infty value) {
if (value == infinite) return (DBT*)toku_lt_infinity; if (value == infinite) return (DBT*)toku_lt_infinity;
if (value == neg_infinite) return (DBT*)toku_lt_neg_infinity; if (value == neg_infinite) return (DBT*)toku_lt_neg_infinity;
if (value == null) return dbt_init(dbt, NULL, 0);
assert(value >= 0); assert(value >= 0);
return dbt_init(dbt, &nums[value], sizeof(nums[0])); return dbt_init(dbt, &nums[value], sizeof(nums[0]));
} }
void lt_insert(BOOL dups, int key_l, int key_r, int data_l, int data_r) { void lt_insert(BOOL dups, int key_l, int data_l, int key_r, int data_r) {
DBT _key_left; DBT _key_left;
DBT _key_right; DBT _key_right;
DBT _data_left; DBT _data_left;
...@@ -66,9 +67,9 @@ void lt_insert(BOOL dups, int key_l, int key_r, int data_l, int data_r) { ...@@ -66,9 +67,9 @@ void lt_insert(BOOL dups, int key_l, int key_r, int data_l, int data_r) {
key_right = set_to_infty(key_right, key_r); key_right = set_to_infty(key_right, key_r);
if (dups) { if (dups) {
if (key_left != &_key_left) data_left = key_left; if (key_left != &_key_left) data_left = key_left;
else data_left = set_to_infty(key_left, key_l); else data_left = set_to_infty(data_left, data_l);
if (key_right != &_key_right) data_right = key_right; if (key_right != &_key_right) data_right = key_right;
else data_right = set_to_infty(key_right, key_r); else data_right = set_to_infty(data_right, data_r);
assert(key_left && data_left); assert(key_left && data_left);
assert(key_right && data_right); assert(key_right && data_right);
} else { } else {
...@@ -85,14 +86,22 @@ void lt_insert(BOOL dups, int key_l, int key_r, int data_l, int data_r) { ...@@ -85,14 +86,22 @@ void lt_insert(BOOL dups, int key_l, int key_r, int data_l, int data_r) {
void setup_payload_len(void** payload, u_int32_t* len, int val) { void setup_payload_len(void** payload, u_int32_t* len, int val) {
assert(payload && len); assert(payload && len);
*payload = set_to_infty(*payload, val); DBT temp;
if (val < 0) *len = 0;
*payload = set_to_infty(&temp, val);
if (val < 0) {
*len = 0;
}
else {
*len = sizeof(nums[0]); *len = sizeof(nums[0]);
*payload = temp.data;
}
} }
void lt_find(BOOL dups, toku_range_tree* rt, void lt_find(BOOL dups, toku_range_tree* rt,
unsigned k, int key_l, int key_r, unsigned k, int key_l, int data_l,
int data_l, int data_r, int key_r, int data_r,
DB_TXN* find_txn) { DB_TXN* find_txn) {
r = toku_rt_find(rt, &query, 0, &buf, &buflen, &numfound); r = toku_rt_find(rt, &query, 0, &buf, &buflen, &numfound);
...@@ -103,22 +112,22 @@ void lt_find(BOOL dups, toku_range_tree* rt, ...@@ -103,22 +112,22 @@ void lt_find(BOOL dups, toku_range_tree* rt,
memset(&left,0,sizeof(left)); memset(&left,0,sizeof(left));
setup_payload_len(&left.key_payload, &left.key_len, key_l); setup_payload_len(&left.key_payload, &left.key_len, key_l);
if (dups) { if (dups) {
if (key_l < 0) left.data_payload = left.key_payload; if (key_l < null) left.data_payload = left.key_payload;
else setup_payload_len(&left.data_payload, &left.data_len, data_l); else setup_payload_len(&left.data_payload, &left.data_len, data_l);
} }
memset(&right,0,sizeof(right)); memset(&right,0,sizeof(right));
setup_payload_len(&right.key_payload, &right.key_len, key_r); setup_payload_len(&right.key_payload, &right.key_len, key_r);
if (dups) { if (dups) {
if (key_r < 0) right.data_payload = right.key_payload; if (key_r < null) right.data_payload = right.key_payload;
else setup_payload_len(&right.data_payload, &right.data_len, data_r); else setup_payload_len(&right.data_payload, &right.data_len, data_r);
} }
unsigned i; unsigned i;
for (i = 0; i < numfound; i++) { for (i = 0; i < numfound; i++) {
if (toku_lt_point_cmp(buf[0].left, &left ) == 0 && if (toku_lt_point_cmp(buf[i].left, &left ) == 0 &&
toku_lt_point_cmp(buf[0].right, &right) == 0 && toku_lt_point_cmp(buf[i].right, &right) == 0 &&
buf[0].data == find_txn) return; buf[i].data == find_txn) return;
} }
assert(FALSE); assert(FALSE); //Crash since we didn't find it.
} }
...@@ -230,52 +239,127 @@ void runtest(BOOL dups) { ...@@ -230,52 +239,127 @@ void runtest(BOOL dups) {
choices[b], choices[b]); choices[b], choices[b]);
} }
int key_l[2];
int key_r[2];
int data_l[2];
int data_r[2];
const void* kl[2];
const void* dl[2];
const void* kr[2];
const void* dr[2];
toku_range_tree *rt; toku_range_tree *rt;
/* ************************************** */
setup_tree(dups);
key_l[0] = 3; /////BUG HERE MAYBE NOT CONSOLIDATING.
data_l[0] = 3; /*nodups:
key_r[0] = dups ? 3 : 7; [(3, 3), (7,7)] and [(4,4), (5,5)]
data_r[0] = 7; dups:
kl[0] = kr[0] = dl[0] = dr[0] = NULL; [(3, 3), (3,7)] and [(3,4), (3,5)]
*/
key_l[1] = dups ? 3 : 4;
data_l[1] = 4;
key_r[1] = dups ? 3 : 5;
data_r[1] = 5;
kl[1] = kr[1] = dl[1] = dr[1] = NULL;
insert_2_noclose(dups, key_l, key_r, data_l, data_r, kl, dl, kr, dr); lt_insert(dups,
3, 3,
dups ? 3 : 7, 7);
lt_insert(dups,
dups ? 3 : 4, 4,
dups ? 3 : 5, 5);
rt = __toku_lt_ifexist_selfread(lt, txn); rt = __toku_lt_ifexist_selfread(lt, txn);
assert(rt); assert(rt);
r = toku_rt_find(rt, &query, 0, &buf, &buflen, &numfound); lt_find(dups, rt, 1,
CKERR(r); 3, 3,
assert(numfound==1); dups ? 3 : 7, 7,
txn);
toku_point left, right; rt = lt->mainread;
memset(&left,0,sizeof(left)); assert(rt);
left.key_payload = &nums[key_l[0]];
left.key_len = sizeof(nums[0]); lt_find(dups, rt, 1,
left.data_payload = &nums[data_l[0]]; 3, 3,
left.data_len = sizeof(nums[0]); dups ? 3 : 7, 7,
memset(&right,0,sizeof(right)); txn);
right.key_payload = &nums[key_r[0]];
right.key_len = sizeof(nums[0]);
right.data_payload = &nums[data_r[0]];
right.data_len = sizeof(nums[0]);
assert(toku_lt_point_cmp(buf[0].left , &left ) == 0); close_tree();
assert(toku_lt_point_cmp(buf[0].right, &right) == 0); /* ************************************** */
setup_tree(dups);
/*nodups:
[(3, 3), (7,7)] and [(4,4), (5,5)]
dups:
[(3, 3), (3,7)] and [(3,4), (3,5)]
*/
lt_insert(dups,
dups ? 3 : 4, 4,
dups ? 3 : 5, 5);
lt_insert(dups,
3, 3,
dups ? 3 : 7, 7);
rt = __toku_lt_ifexist_selfread(lt, txn); assert(rt);
lt_find(dups, rt, 1,
3, 3,
dups ? 3 : 7, 7,
txn);
rt = lt->mainread; assert(rt);
lt_find(dups, rt, 1,
3, 3,
dups ? 3 : 7, 7,
txn);
rt = NULL;
close_tree();
/* ************************************** */
setup_tree(dups);
lt_insert(dups, 3, 3, 3, 3);
lt_insert(dups, 4, 4, 4, 4);
lt_insert(dups, 3, 3, 3, 3);
rt = __toku_lt_ifexist_selfread(lt, txn); assert(rt);
lt_find(dups, rt, 2, 3, 3, 3, 3, txn);
lt_find(dups, rt, 2, 4, 4, 4, 4, txn);
rt = lt->mainread; assert(rt);
lt_find(dups, rt, 2, 3, 3, 3, 3, txn);
lt_find(dups, rt, 2, 4, 4, 4, 4, txn);
rt = NULL;
close_tree();
/* ************************************** */
setup_tree(dups);
for (i = 0; i < 20; i += 2) {
lt_insert(dups, i, 5, i + 1, 10);
}
rt = __toku_lt_ifexist_selfread(lt, txn);
assert(rt);
for (i = 0; i < 20; i += 2) {
lt_find(dups, rt, 10, i, 5, i + 1, 10, txn);
}
rt = lt->mainread; assert(rt);
for (i = 0; i < 20; i += 2) {
lt_find(dups, rt, 10, i, 5, i + 1, 10, txn);
}
lt_insert(dups, 0, neg_infinite, 20, infinite);
rt = __toku_lt_ifexist_selfread(lt, txn); assert(rt);
lt_find( dups, rt, 1, 0, neg_infinite, 20, infinite, txn);
rt = lt->mainread; assert(rt);
lt_find( dups, rt, 1, 0, neg_infinite, 20, infinite, txn);
rt = NULL;
close_tree();
/* ************************************** */
setup_tree(dups);
lt_insert(dups, 0, neg_infinite, 1, infinite);
lt_insert(dups, 1, neg_infinite, 2, infinite);
lt_insert(dups, 4, neg_infinite, 5, infinite);
lt_insert(dups, 3, neg_infinite, 4, infinite);
rt = __toku_lt_ifexist_selfread(lt, txn); assert(rt);
lt_find(dups, rt, 2, 0, neg_infinite, 2, infinite, txn);
lt_find(dups, rt, 2, 3, neg_infinite, 5, infinite, txn);
rt = lt->mainread; assert(rt);
lt_find(dups, rt, 2, 0, neg_infinite, 2, infinite, txn);
lt_find(dups, rt, 2, 3, neg_infinite, 5, infinite, txn);
lt_insert(dups, 2, neg_infinite, 3, infinite);
rt = __toku_lt_ifexist_selfread(lt, txn); assert(rt);
lt_find(dups, rt, 1, 0, neg_infinite, 5, infinite, txn);
rt = lt->mainread; assert(rt);
lt_find(dups, rt, 1, 0, neg_infinite, 5, infinite, txn);
rt = NULL;
close_tree(); close_tree();
} }
......
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