Commit 94100f82 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #307

Added more parameter based tests

git-svn-id: file:///svn/tokudb@1875 c7de825b-a66e-492c-adef-691d508d4ae1
parent 80a723c9
...@@ -7,85 +7,109 @@ static DBT _data; ...@@ -7,85 +7,109 @@ static DBT _data;
DBT* key; DBT* key;
DBT* data; DBT* data;
int main(int argc, const char *argv[]) { static void do_range_test(int (*acquire)(toku_lock_tree*, DB_TXN*,
const DBT*, const DBT*,
const DBT*, const DBT*)) {
int r; int r;
toku_lock_tree* lt = NULL; toku_lock_tree* lt = NULL;
DB* db = (DB*)1; DB* db = (DB*)1;
DB_TXN* txn = (DB_TXN*)1; // Fake. DB_TXN* txn = (DB_TXN*)1; // Fake.
BOOL duplicates = FALSE; BOOL duplicates = FALSE;
DBT _key_l = _key;
/* create tests. */ DBT _key_r = _key;
for (duplicates = 0; duplicates < 2; duplicates++) { DBT _data_l = _data;
r = toku_lt_create(NULL, db, duplicates, dbcmp, dbcmp, DBT _data_r = _data;
toku_malloc, toku_free, toku_realloc); DBT* key_l = &_key_l;
CKERR2(r, EINVAL); DBT* key_r = &_key_r;
r = toku_lt_create(&lt, NULL, duplicates, dbcmp, dbcmp, DBT* data_l;
toku_malloc, toku_free, toku_realloc); DBT* data_r;
CKERR2(r, EINVAL); DBT* reverse_data_l;
r = toku_lt_create(&lt, db, duplicates, NULL, dbcmp, DBT* reverse_data_r;
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, db, duplicates, dbcmp, NULL,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp,
NULL, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp,
toku_malloc, NULL, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp,
toku_malloc, toku_free, NULL);
CKERR2(r, EINVAL);
}
/* Close tests. */
r = toku_lt_close(NULL);
CKERR2(r, EINVAL);
lt = NULL;
DBT* reverse_data;
/* Point read tests. */
key = &_key;
for (duplicates = 0; duplicates < 2; duplicates++) { for (duplicates = 0; duplicates < 2; duplicates++) {
if (duplicates) { if (duplicates) {
data = &_data; data_l = &_data_l;
reverse_data = NULL; data_r = &_data_r;
reverse_data_l = NULL;
reverse_data_r = NULL;
} }
else { else {
reverse_data = &_data; data_l = NULL;
data = NULL; data_r = NULL;
reverse_data_l = &_data_l;
reverse_data_r = &_data_r;
} }
r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp, r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR(r); CKERR(r);
assert(lt); assert(lt);
r = toku_lt_acquire_read_lock(NULL, txn, key, data); if (acquire == toku_lt_acquire_range_write_lock) {
CKERR2(r, EINVAL); r = acquire(lt, txn, key_l, data_l,
key_r, data_r);
CKERR2(r, ENOSYS);
}
r = toku_lt_acquire_read_lock(lt, NULL, key, data);
CKERR2(r, EINVAL);
r = toku_lt_acquire_read_lock(lt, txn, NULL, data); r = acquire(NULL, txn, key_l, data_l,
key_r, data_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = acquire(lt, NULL, key_l, data_l,
r = toku_lt_acquire_read_lock(lt, txn, key, reverse_data); key_r, data_r);
CKERR2(r, EINVAL);
r = acquire(lt, txn, NULL, data_l,
key_r, data_r);
CKERR2(r, EINVAL);
r = acquire(lt, txn, key_l, reverse_data_l,
key_r, data_r);
CKERR2(r, EINVAL);
r = acquire(lt, txn, key_l, data_l,
NULL, data_r);
CKERR2(r, EINVAL);
r = acquire(lt, txn, key_l, data_l,
key_r, reverse_data_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
/* Infinite tests. */ /* Infinite tests. */
if (duplicates) { if (duplicates) {
r = toku_lt_acquire_read_lock(lt, txn, toku_lt_infinity, data); r = acquire(lt, txn, toku_lt_infinity, data_l,
key_r, data_r);
CKERR2(r, EINVAL);
r = acquire(lt, txn, toku_lt_neg_infinity, data_l,
key_r, data_r);
CKERR2(r, EINVAL);
r = acquire(lt, txn, key_l, data_l,
toku_lt_infinity, data_r);
CKERR2(r, EINVAL);
r = acquire(lt, txn, key_l, data_l,
toku_lt_neg_infinity, data_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_read_lock(lt, txn, toku_lt_neg_infinity, data); r = acquire(lt, txn, toku_lt_infinity, toku_lt_neg_infinity,
key_r, data_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_read_lock(lt, txn, toku_lt_infinity, r = acquire(lt, txn, toku_lt_neg_infinity, toku_lt_infinity,
toku_lt_neg_infinity); key_r, data_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_read_lock(lt, txn, toku_lt_neg_infinity, r = acquire(lt, txn, key_l, data_l,
toku_lt_infinity); toku_lt_infinity, toku_lt_neg_infinity);
CKERR2(r, EINVAL);
r = acquire(lt, txn, key_l, data_l,
toku_lt_neg_infinity, toku_lt_infinity);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
} }
/* left > right tests. */
const DBT* d_inf = duplicates ? toku_lt_infinity : NULL;
const DBT* inf = toku_lt_infinity;
const DBT* d_ninf = duplicates ? toku_lt_neg_infinity : NULL;
const DBT* ninf = toku_lt_neg_infinity;
r = acquire(lt, txn, inf, d_inf,
key_r, data_r);
CKERR2(r, EDOM);
r = acquire(lt, txn, key_l, data_l,
ninf, d_ninf);
CKERR2(r, EDOM);
r = acquire(lt, txn, inf, d_inf,
ninf, d_ninf);
CKERR2(r, EDOM);
/* Cleanup. */ /* Cleanup. */
r = toku_lt_close(lt); r = toku_lt_close(lt);
...@@ -93,8 +117,19 @@ int main(int argc, const char *argv[]) { ...@@ -93,8 +117,19 @@ int main(int argc, const char *argv[]) {
lt = NULL; lt = NULL;
} }
}
static void do_point_test(int (*acquire)(toku_lock_tree*, DB_TXN*,
const DBT*, const DBT*)) {
int r;
toku_lock_tree* lt = NULL;
DB* db = (DB*)1;
DB_TXN* txn = (DB_TXN*)1; // Fake.
BOOL duplicates = FALSE;
/* Point write tests. */ lt = NULL;
DBT* reverse_data;
/* Point read tests. */
key = &_key; key = &_key;
for (duplicates = 0; duplicates < 2; duplicates++) { for (duplicates = 0; duplicates < 2; duplicates++) {
if (duplicates) { if (duplicates) {
...@@ -110,29 +145,27 @@ int main(int argc, const char *argv[]) { ...@@ -110,29 +145,27 @@ int main(int argc, const char *argv[]) {
CKERR(r); CKERR(r);
assert(lt); assert(lt);
r = toku_lt_acquire_write_lock(NULL, txn, key, data); r = acquire(NULL, txn, key, data);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_write_lock(lt, NULL, key, data); r = acquire(lt, NULL, key, data);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_write_lock(lt, txn, NULL, data); r = acquire(lt, txn, NULL, data);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_write_lock(lt, txn, key, reverse_data); r = acquire(lt, txn, key, reverse_data);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
/* Infinite tests. */ /* Infinite tests. */
if (duplicates) { if (duplicates) {
r = toku_lt_acquire_write_lock(lt, txn, toku_lt_infinity, data); r = acquire(lt, txn, toku_lt_infinity, data);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_write_lock(lt, txn, toku_lt_neg_infinity, data); r = acquire(lt, txn, toku_lt_neg_infinity, data);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_write_lock(lt, txn, toku_lt_infinity, r = acquire(lt, txn, toku_lt_infinity, toku_lt_neg_infinity);
toku_lt_neg_infinity);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_write_lock(lt, txn, toku_lt_neg_infinity, r = acquire(lt, txn, toku_lt_neg_infinity, toku_lt_infinity);
toku_lt_infinity);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
} }
...@@ -142,118 +175,48 @@ int main(int argc, const char *argv[]) { ...@@ -142,118 +175,48 @@ int main(int argc, const char *argv[]) {
lt = NULL; lt = NULL;
} }
}
/* Range read tests. */ int main(int argc, const char *argv[]) {
DBT _key_l = _key; int r;
DBT _key_r = _key; toku_lock_tree* lt = NULL;
DBT _data_l = _data; DB* db = (DB*)1;
DBT _data_r = _data; BOOL duplicates = FALSE;
DBT* key_l = &_key_l;
DBT* key_r = &_key_r; /* create tests. */
DBT* data_l;
DBT* data_r;
DBT* reverse_data_l;
DBT* reverse_data_r;
for (duplicates = 0; duplicates < 2; duplicates++) { for (duplicates = 0; duplicates < 2; duplicates++) {
if (duplicates) { r = toku_lt_create(NULL, db, duplicates, dbcmp, dbcmp,
data_l = &_data_l; toku_malloc, toku_free, toku_realloc);
data_r = &_data_r; CKERR2(r, EINVAL);
reverse_data_l = NULL; r = toku_lt_create(&lt, NULL, duplicates, dbcmp, dbcmp,
reverse_data_r = NULL;
}
else {
data_l = NULL;
data_r = NULL;
reverse_data_l = &_data_l;
reverse_data_r = &_data_r;
}
r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc); toku_malloc, toku_free, toku_realloc);
CKERR(r);
assert(lt);
r = toku_lt_acquire_range_read_lock(NULL, txn,
key_l, data_l,
key_r, data_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, NULL, r = toku_lt_create(&lt, db, duplicates, NULL, dbcmp,
key_l, data_l, toku_malloc, toku_free, toku_realloc);
key_r, data_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn, r = toku_lt_create(&lt, db, duplicates, dbcmp, NULL,
NULL, data_l, toku_malloc, toku_free, toku_realloc);
key_r, data_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn, r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp,
key_l, reverse_data_l, NULL, toku_free, toku_realloc);
key_r, data_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn, r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp,
key_l, data_l, toku_malloc, NULL, toku_realloc);
NULL, data_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn, r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp,
key_l, data_l, toku_malloc, toku_free, NULL);
key_r, reverse_data_r);
CKERR2(r, EINVAL); CKERR2(r, EINVAL);
}
/* Infinite tests. */ /* Close tests. */
if (duplicates) { r = toku_lt_close(NULL);
r = toku_lt_acquire_range_read_lock(lt, txn, CKERR2(r, EINVAL);
toku_lt_infinity, data_l,
key_r, data_r); do_point_test(toku_lt_acquire_read_lock);
CKERR2(r, EINVAL); do_point_test(toku_lt_acquire_write_lock);
r = toku_lt_acquire_range_read_lock(lt, txn,
toku_lt_neg_infinity, data_l, do_range_test(toku_lt_acquire_range_read_lock);
key_r, data_r); do_range_test(toku_lt_acquire_range_write_lock);
CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn,
key_l, data_l,
toku_lt_infinity, data_r);
CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn,
key_l, data_l,
toku_lt_neg_infinity, data_r);
CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn,
toku_lt_infinity, toku_lt_neg_infinity,
key_r, data_r);
CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn,
toku_lt_neg_infinity, toku_lt_infinity,
key_r, data_r);
CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn,
key_l, data_l,
toku_lt_infinity, toku_lt_neg_infinity);
CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn,
key_l, data_l,
toku_lt_neg_infinity, toku_lt_infinity);
CKERR2(r, EINVAL);
}
/* left > right tests. */
const DBT* d_inf = duplicates ? toku_lt_infinity : NULL;
const DBT* inf = toku_lt_infinity;
const DBT* d_ninf = duplicates ? toku_lt_neg_infinity : NULL;
const DBT* ninf = toku_lt_neg_infinity;
r = toku_lt_acquire_range_read_lock(lt, txn,
inf, d_inf,
key_r, data_r);
CKERR2(r, EDOM);
r = toku_lt_acquire_range_read_lock(lt, txn,
key_l, data_l,
ninf, d_ninf);
CKERR2(r, EDOM);
r = toku_lt_acquire_range_read_lock(lt, txn,
inf, d_inf,
ninf, d_ninf);
CKERR2(r, EDOM);
/* Cleanup. */
r = toku_lt_close(lt);
CKERR(r);
lt = NULL;
}
return 0; return 0;
} }
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