From de6a462f71aead0c8aef3c09517a6465d118861b Mon Sep 17 00:00:00 2001 From: "Bradley C. Kuszmaul" Date: Sat, 17 Nov 2007 22:36:59 +0000 Subject: [PATCH] Make test_reverse_compare_fun.bdbrun work git-svn-id: file:///svn/tokudb@619 c7de825b-a66e-492c-adef-691d508d4ae1 --- src/tests/Makefile | 15 +++++--- src/tests/test_reverse_compare_fun.c | 52 ++++++++++++++++------------ 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/tests/Makefile b/src/tests/Makefile index 215cacaf125..6db4f6db6c3 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -53,11 +53,16 @@ $(ALL_TESTS): $(VGRIND) ./$< # For a few of the tests bdb is making valgrind unhappy. -test_db_already_exists.bdbrun: VGRIND= -test_db_dup.bdbrun: VGRIND= -test_reverse_compare_fun.bdbrun: VGRIND= -test_db_subdb.bdbrun: VGRIND= -test_db_env_open_open_close.bdbrun: VGRIND= +NO_VGRIND = \ + db_already_exists \ + db_dup \ + db_env_open_open_close \ + db_remove_subdb \ + db_subdb \ + reverse_compare_fun \ + # Comment to terminate list so the previous line can end with a slash + +$(patsubst %,test_%.bdbrun,$(NO_VGRIND)): VGRIND= %.bdb: %.c cc -DDIR=\"dir.$<.bdb\" -DUSE_BDB $(CFLAGS) $< -ldb -o $@ diff --git a/src/tests/test_reverse_compare_fun.c b/src/tests/test_reverse_compare_fun.c index 5542a4da05b..875c42c2c47 100644 --- a/src/tests/test_reverse_compare_fun.c +++ b/src/tests/test_reverse_compare_fun.c @@ -1,13 +1,17 @@ /* try a reverse compare function to verify that the database always uses the application's compare function */ +#include +#include +#include #include #include -#include -#include #include -#include -#include +#include +#include +#include + +#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0); DBT *dbt_init(DBT *dbt, void *data, u_int32_t size) { memset(dbt, 0, sizeof *dbt); @@ -41,7 +45,7 @@ int reverse_compare(DB *db __attribute__((__unused__)), const DBT *a, const DBT* void expect(DBC *cursor, int k, int v) { DBT key, val; int r = cursor->c_get(cursor, dbt_init_malloc(&key), dbt_init_malloc(&val), DB_NEXT); - assert(r == 0); + CKERR(r); assert(key.size == sizeof k); int kk; memcpy(&kk, key.data, key.size); @@ -62,23 +66,25 @@ void test_reverse_compare(int n) { DB_ENV * const null_env = 0; DB *db; DB_TXN * const null_txn = 0; - const char * const fname = "test.reverse.compare.brt"; + const char * const fname = DIR "/reverse.compare.db"; + int r; int i; - unlink(fname); + system("rm -rf " DIR); + mkdir(DIR, 0777); /* create the dup database file */ r = db_create(&db, null_env, 0); - assert(r == 0); + CKERR(r); r = db->set_flags(db, 0); - assert(r == 0); + CKERR(r); r = db->set_pagesize(db, 4096); - assert(r == 0); + CKERR(r); r = db->set_bt_compare(db, reverse_compare); - assert(r == 0); + CKERR(r); r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666); - assert(r == 0); + CKERR(r); /* insert n unique keys {0, 1, n-1} */ for (i=0; iput(db, null_txn, &key, &val, 0); - assert(r == 0); + CKERR(r); } /* reopen the database to force nonleaf buffering */ r = db->close(db, 0); - assert(r == 0); + CKERR(r); r = db_create(&db, null_env, 0); - assert(r == 0); + CKERR(r); r = db->set_flags(db, 0); - assert(r == 0); + CKERR(r); r = db->set_pagesize(db, 4096); - assert(r == 0); + CKERR(r); r = db->set_bt_compare(db, reverse_compare); - assert(r == 0); + CKERR(r); r = db->open(db, null_txn, fname, "main", DB_BTREE, 0, 0666); - assert(r == 0); + CKERR(r); /* insert n unique keys {n, n+1, 2*n-1} */ for (i=n; i<2*n; i++) { @@ -115,23 +121,23 @@ void test_reverse_compare(int n) { v = i; dbt_init(&val, &v, sizeof v); r = db->put(db, null_txn, &key, &val, 0); - assert(r == 0); + CKERR(r); } /* verify the sort order with a cursor */ DBC *cursor; r = db->cursor(db, null_txn, &cursor, 0); - assert(r == 0); + CKERR(r); //for (i=0; i<2*n; i++) for (i=2*n-1; i>=0; i--) expect(cursor, htonl(i), i); r = cursor->c_close(cursor); - assert(r == 0); + CKERR(r); r = db->close(db, 0); - assert(r == 0); + CKERR(r); } int main() {