Commit c3ef7302 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1691 Modified root fifo tests to test additional cases.

git-svn-id: file:///svn/toku/tokudb@11532 c7de825b-a66e-492c-adef-691d508d4ae1
parent 40f04fbc
...@@ -7,6 +7,7 @@ DB_ENV *null_env = NULL; ...@@ -7,6 +7,7 @@ DB_ENV *null_env = NULL;
DB *null_db = NULL; DB *null_db = NULL;
DB_TXN *null_txn = NULL; DB_TXN *null_txn = NULL;
DBC *null_cursor = NULL; DBC *null_cursor = NULL;
int constant = 0;
static void root_fifo_verify(DB_ENV *env, int n) { static void root_fifo_verify(DB_ENV *env, int n) {
if (verbose) printf("%s:%d %d\n", __FUNCTION__, __LINE__, n); if (verbose) printf("%s:%d %d\n", __FUNCTION__, __LINE__, n);
...@@ -33,7 +34,10 @@ static void root_fifo_verify(DB_ENV *env, int n) { ...@@ -33,7 +34,10 @@ static void root_fifo_verify(DB_ENV *env, int n) {
memcpy(&k, key.data, key.size); memcpy(&k, key.data, key.size);
assert((int)toku_ntohl(k) == i); assert((int)toku_ntohl(k) == i);
} }
assert(i == n); if (constant)
assert(i==1);
else
assert(i == n);
r = cursor->c_close(cursor); assert(r == 0); cursor = null_cursor; r = cursor->c_close(cursor); assert(r == 0); cursor = null_cursor;
...@@ -42,7 +46,7 @@ static void root_fifo_verify(DB_ENV *env, int n) { ...@@ -42,7 +46,7 @@ static void root_fifo_verify(DB_ENV *env, int n) {
r = db->close(db, 0); assert(r == 0); db = null_db; r = db->close(db, 0); assert(r == 0); db = null_db;
} }
static void root_fifo_1(int n) { static void root_fifo_1(int n, int create_outside) {
if (verbose) printf("%s:%d %d\n", __FUNCTION__, __LINE__, n); if (verbose) printf("%s:%d %d\n", __FUNCTION__, __LINE__, n);
int r; int r;
...@@ -60,11 +64,24 @@ static void root_fifo_1(int n) { ...@@ -60,11 +64,24 @@ static void root_fifo_1(int n) {
S_IRWXU+S_IRWXG+S_IRWXO); S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == 0); assert(r == 0);
if (create_outside) {
DB_TXN *txn_open = null_txn;
r = env->txn_begin(env, null_txn, &txn_open, 0); assert(r == 0); assert(txn_open != NULL);
DB *db_open = null_db;
r = db_create(&db_open, env, 0); assert(r == 0); assert(db_open != NULL);
r = db_open->open(db_open, txn_open, "test.db", 0, DB_BTREE, DB_CREATE|DB_EXCL, S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == 0);
r = db_open->close(db_open, 0); assert(r == 0); db_open = null_db;
r = txn_open->commit(txn_open, 0); assert(r == 0); txn_open = null_txn;
}
DB_TXN *txn = null_txn; DB_TXN *txn = null_txn;
r = env->txn_begin(env, null_txn, &txn, 0); assert(r == 0); assert(txn != NULL); r = env->txn_begin(env, null_txn, &txn, 0); assert(r == 0); assert(txn != NULL);
int i; int i;
for (i=0; i<n; i++) { for (i=0; i<n; i++) {
if (verbose>1) {
printf("%s-%s:%d %d\n", __FILE__, __FUNCTION__, __LINE__, i);
}
DB *db = null_db; DB *db = null_db;
r = db_create(&db, env, 0); assert(r == 0); assert(db != NULL); r = db_create(&db, env, 0); assert(r == 0); assert(db != NULL);
...@@ -73,7 +90,11 @@ static void root_fifo_1(int n) { ...@@ -73,7 +90,11 @@ static void root_fifo_1(int n) {
DBT key, val; DBT key, val;
int k = toku_htonl(i); int k = toku_htonl(i);
r = db->put(db, txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &i, sizeof i), 0); int v = i;
if (constant) {
k = v = 0;
}
r = db->put(db, txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), 0);
assert(r == 0); assert(r == 0);
r = db->close(db, 0); assert(r == 0); db = null_db; r = db->close(db, 0); assert(r == 0); db = null_db;
...@@ -95,7 +116,7 @@ int test_main(int argc, char *argv[]) { ...@@ -95,7 +116,7 @@ int test_main(int argc, char *argv[]) {
// parse_args(argc, argv); // parse_args(argc, argv);
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-v") == 0) { if (strcmp(argv[i], "-v") == 0) {
verbose = 1; verbose++;
continue; continue;
} }
if (strcmp(argv[i], "-n") == 0) { if (strcmp(argv[i], "-n") == 0) {
...@@ -103,13 +124,26 @@ int test_main(int argc, char *argv[]) { ...@@ -103,13 +124,26 @@ int test_main(int argc, char *argv[]) {
n = atoi(argv[++i]); n = atoi(argv[++i]);
continue; continue;
} }
if (strcmp(argv[i], "-q") == 0) {
verbose--;
if (verbose<0) verbose = 0;
continue;
}
if (strcmp(argv[i], "-c") == 0) {
constant = 1;
continue;
}
} }
if (n >= 0) if (n >= 0) {
root_fifo_1(n); root_fifo_1(n, 0);
root_fifo_1(n, 1);
}
else else
for (i=0; i<100; i++) for (i=0; i<100; i++) {
root_fifo_1(i); root_fifo_1(i, 0);
root_fifo_1(i, 1);
}
return 0; return 0;
} }
...@@ -42,7 +42,7 @@ static void root_fifo_verify(DB_ENV *env, int n) { ...@@ -42,7 +42,7 @@ static void root_fifo_verify(DB_ENV *env, int n) {
r = db->close(db, 0); assert(r == 0); db = null_db; r = db->close(db, 0); assert(r == 0); db = null_db;
} }
static void root_fifo_2(int n) { static void root_fifo_2(int n, int create_outside) {
if (verbose) printf("%s:%d %d\n", __FUNCTION__, __LINE__, n); if (verbose) printf("%s:%d %d\n", __FUNCTION__, __LINE__, n);
int r; int r;
...@@ -60,6 +60,16 @@ static void root_fifo_2(int n) { ...@@ -60,6 +60,16 @@ static void root_fifo_2(int n) {
S_IRWXU+S_IRWXG+S_IRWXO); S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == 0); assert(r == 0);
if (create_outside) {
DB_TXN *txn_open = null_txn;
r = env->txn_begin(env, null_txn, &txn_open, 0); assert(r == 0); assert(txn_open != NULL);
DB *db_open = null_db;
r = db_create(&db_open, env, 0); assert(r == 0); assert(db_open != NULL);
r = db_open->open(db_open, txn_open, "test.db", 0, DB_BTREE, DB_CREATE|DB_EXCL, S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == 0);
r = db_open->close(db_open, 0); assert(r == 0); db_open = null_db;
r = txn_open->commit(txn_open, 0); assert(r == 0); txn_open = null_txn;
}
DB_TXN *txn = null_txn; DB_TXN *txn = null_txn;
r = env->txn_begin(env, null_txn, &txn, 0); assert(r == 0); assert(txn != NULL); r = env->txn_begin(env, null_txn, &txn, 0); assert(r == 0); assert(txn != NULL);
...@@ -110,11 +120,15 @@ int test_main(int argc, char *argv[]) { ...@@ -110,11 +120,15 @@ int test_main(int argc, char *argv[]) {
} }
} }
if (n >= 0) if (n >= 0) {
root_fifo_2(n); root_fifo_2(n, 0);
root_fifo_2(n, 1);
}
else else
for (i=0; i<100; i++) for (i=0; i<100; i++) {
root_fifo_2(i); root_fifo_2(i, 0);
root_fifo_2(i, 1);
}
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