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;
DBT* key;
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;
toku_lock_tree* lt = NULL;
DB* db = (DB*)1;
DB_TXN* txn = (DB_TXN*)1; // Fake.
BOOL duplicates = FALSE;
/* create tests. */
for (duplicates = 0; duplicates < 2; duplicates++) {
r = toku_lt_create(NULL, db, duplicates, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, NULL, duplicates, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, db, duplicates, NULL, dbcmp,
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;
DBT _key_l = _key;
DBT _key_r = _key;
DBT _data_l = _data;
DBT _data_r = _data;
DBT* key_l = &_key_l;
DBT* key_r = &_key_r;
DBT* data_l;
DBT* data_r;
DBT* reverse_data_l;
DBT* reverse_data_r;
for (duplicates = 0; duplicates < 2; duplicates++) {
if (duplicates) {
data = &_data;
reverse_data = NULL;
data_l = &_data_l;
data_r = &_data_r;
reverse_data_l = NULL;
reverse_data_r = NULL;
}
else {
reverse_data = &_data;
data = NULL;
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);
CKERR(r);
assert(lt);
r = toku_lt_acquire_read_lock(NULL, txn, key, data);
CKERR2(r, EINVAL);
if (acquire == toku_lt_acquire_range_write_lock) {
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);
r = toku_lt_acquire_read_lock(lt, txn, key, reverse_data);
r = acquire(lt, NULL, key_l, data_l,
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);
/* Infinite tests. */
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);
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);
r = toku_lt_acquire_read_lock(lt, txn, toku_lt_infinity,
toku_lt_neg_infinity);
r = acquire(lt, txn, toku_lt_neg_infinity, toku_lt_infinity,
key_r, data_r);
CKERR2(r, EINVAL);
r = toku_lt_acquire_read_lock(lt, txn, toku_lt_neg_infinity,
toku_lt_infinity);
r = acquire(lt, txn, key_l, data_l,
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);
}
/* 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. */
r = toku_lt_close(lt);
......@@ -93,8 +117,19 @@ int main(int argc, const char *argv[]) {
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;
for (duplicates = 0; duplicates < 2; duplicates++) {
if (duplicates) {
......@@ -110,29 +145,27 @@ int main(int argc, const char *argv[]) {
CKERR(r);
assert(lt);
r = toku_lt_acquire_write_lock(NULL, txn, key, data);
r = acquire(NULL, txn, key, data);
CKERR2(r, EINVAL);
r = toku_lt_acquire_write_lock(lt, NULL, key, data);
r = acquire(lt, NULL, key, data);
CKERR2(r, EINVAL);
r = toku_lt_acquire_write_lock(lt, txn, NULL, data);
r = acquire(lt, txn, NULL, data);
CKERR2(r, EINVAL);
r = toku_lt_acquire_write_lock(lt, txn, key, reverse_data);
r = acquire(lt, txn, key, reverse_data);
CKERR2(r, EINVAL);
/* Infinite tests. */
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);
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);
r = toku_lt_acquire_write_lock(lt, txn, toku_lt_infinity,
toku_lt_neg_infinity);
r = acquire(lt, txn, toku_lt_infinity, toku_lt_neg_infinity);
CKERR2(r, EINVAL);
r = toku_lt_acquire_write_lock(lt, txn, toku_lt_neg_infinity,
toku_lt_infinity);
r = acquire(lt, txn, toku_lt_neg_infinity, toku_lt_infinity);
CKERR2(r, EINVAL);
}
......@@ -142,118 +175,48 @@ int main(int argc, const char *argv[]) {
lt = NULL;
}
}
/* Range read tests. */
DBT _key_l = _key;
DBT _key_r = _key;
DBT _data_l = _data;
DBT _data_r = _data;
DBT* key_l = &_key_l;
DBT* key_r = &_key_r;
DBT* data_l;
DBT* data_r;
DBT* reverse_data_l;
DBT* reverse_data_r;
int main(int argc, const char *argv[]) {
int r;
toku_lock_tree* lt = NULL;
DB* db = (DB*)1;
BOOL duplicates = FALSE;
/* create tests. */
for (duplicates = 0; duplicates < 2; duplicates++) {
if (duplicates) {
data_l = &_data_l;
data_r = &_data_r;
reverse_data_l = NULL;
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,
r = toku_lt_create(NULL, db, duplicates, dbcmp, dbcmp,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_create(&lt, NULL, duplicates, dbcmp, dbcmp,
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);
r = toku_lt_acquire_range_read_lock(lt, NULL,
key_l, data_l,
key_r, data_r);
r = toku_lt_create(&lt, db, duplicates, NULL, dbcmp,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn,
NULL, data_l,
key_r, data_r);
r = toku_lt_create(&lt, db, duplicates, dbcmp, NULL,
toku_malloc, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn,
key_l, reverse_data_l,
key_r, data_r);
r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp,
NULL, toku_free, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn,
key_l, data_l,
NULL, data_r);
r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp,
toku_malloc, NULL, toku_realloc);
CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn,
key_l, data_l,
key_r, reverse_data_r);
r = toku_lt_create(&lt, db, duplicates, dbcmp, dbcmp,
toku_malloc, toku_free, NULL);
CKERR2(r, EINVAL);
}
/* Infinite tests. */
if (duplicates) {
r = toku_lt_acquire_range_read_lock(lt, txn,
toku_lt_infinity, data_l,
key_r, data_r);
CKERR2(r, EINVAL);
r = toku_lt_acquire_range_read_lock(lt, txn,
toku_lt_neg_infinity, data_l,
key_r, data_r);
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);
/* Close tests. */
r = toku_lt_close(NULL);
CKERR2(r, EINVAL);
do_point_test(toku_lt_acquire_read_lock);
do_point_test(toku_lt_acquire_write_lock);
do_range_test(toku_lt_acquire_range_read_lock);
do_range_test(toku_lt_acquire_range_write_lock);
/* Cleanup. */
r = toku_lt_close(lt);
CKERR(r);
lt = NULL;
}
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