Commit 9e701335 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Make the tests run under BDB as well as TDB

git-svn-id: file:///svn/tokudb@611 c7de825b-a66e-492c-adef-691d508d4ae1
parent dfd26d86
......@@ -4,51 +4,63 @@
ifeq ($(OSX),OSX)
LIBEXT=dylib
TEST=
LOADLIBES = -L../ -ldb
VGRIND=
TDB_LOADLIBES = -L../ -ldb
else
LIBEXT=so
LOADLIBES = -L../ -ldb -Wl,-rpath,..
TEST=valgrind --quiet --error-exitcode=1 --leak-check=yes
TDB_LOADLIBES = -L../ -ldb -Wl,-rpath,..
VGRIND=valgrind --quiet --error-exitcode=1 --leak-check=yes
endif
LIBNAME=libdb.$(LIBEXT)
CFLAGS = -Wall -Werror -O0 -g
CPPFLAGS = -I../../include
TDB_CPPFLAGS = -I../../include
SRCS = $(wildcard *.c)
TESTS = $(patsubst %.c,%,$(SRCS))
all: make_libs $(TESTS)
TDB_TESTS = $(patsubst %.c,%.tdb,$(SRCS))
BDB_TESTS = $(patsubst %.c,%.bdb,$(SRCS))
test_log1.bdb: test_log1
ALL_TESTS = $(TDB_TESTS) $(BDB_TESTS)
check_log0: ./test_log0
$(TEST) ./test_log0
test -f dir.test_log0/log000000000000.tokulog
check_log1: ./test_log1
$(TEST) ./test_log1
check_db_close_no_open: ./test_db_close_no_open
$(TEST) ./test_db_close_no_open
check_db_version: ./test_db_version
$(TEST) ./test_db_version
check_db_open_notexist_reopen : ./test_db_open_notexist_reopen
$(TEST) ./test_db_open_notexist_reopen
RUN_TDB_TESTS = $(patsubst %.tdb,%.tdbrun,$(TDB_TESTS))
RUN_BDB_TESTS = $(patsubst %.bdb,%.bdbrun,$(BDB_TESTS))
RUN_ALL_TESTS = $(RUN_TDB_TESTS) $(RUN_BDB_TESTS)
.PHONY: check_log0 make_libs
make_libs:
cd ..;make
check: $(TESTS) check_log0
for testcase in $(TESTS) ; do echo $(TEST) ./$$testcase ; if ! $(TEST) ./$$testcase; then echo "Test Failed!" ; exit 1; fi; done
all: make_libs $(ALL_TESTS)
foo:
echo RUN_TDB_TESTS: $(RUN_TDB_TESTS)
echo ALL_TESTS: $(ALL_TESTS)
.PHONY: check check.bdb check.tdb
check: check.bdb check.tdb
check.bdb: $(RUN_BDB_TESTS)
check.tdb: $(RUN_TDB_TESTS)
test_log1.bdb: test_log1.c
cc -Wall -Werror -O2 -g test_log1.c -o $@ -ldb -DDBVERSION=\"bdb\"
# Need these rule so that Make knows about all the file names
.PHONY: %.bdbrun %.tdbrun
$(RUN_ALL_TESTS):
$(ALL_TESTS):
test_log1.bdb_link: test_log1.c
cc -Wall -Werror -O2 -g test_log1.c -o $@ -ldb $(CPPFLAGS)
%.foo:
echo $@
test_log1.tokudb_link: test_log1.c
cc -Wall -Werror -O2 -g test_log1.c -o $@ $(LOADLIBES)
%.bdbrun: %.bdb
./$<
%.tdbrun: %.tdb
$(VGRIND) ./$<
%.bdb: %.c
cc -DDIR=\"dir.$<.bdb\" $(CFLAGS) $< -ldb -o $@
%.tdb: %.c
cc -DDIR=\"dir.$<.tdb\" $(CFLAGS) $(TDB_CPPFLAGS) $(TDB_LOADLIBES) $< -o $@
make_libs:
cd ..;make
clean:
rm -f $(TESTS)
rm -f $(ALL_TESTS) *.o
rm -rf dir.*.tdb dir.*.bdb
......@@ -5,7 +5,9 @@
#include <unistd.h>
#include <db.h>
#define DIR "dir.test_db_already_exists"
// DIR is defined in the Makefile
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
int main() {
DB_ENV * const null_env = 0;
......@@ -34,7 +36,7 @@ int main() {
assert(r == 0);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666);
assert(r != 0);
assert(r == 0);
r = db->close(db, 0);
assert(r == 0);
......
......@@ -5,7 +5,9 @@
#include <sys/types.h>
#include <db.h>
#define DIR "dir.test_db_close_no_open"
// DIR is defined in the Makefile
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
DB_ENV *env;
DB *db;
......
......@@ -5,59 +5,59 @@
#include <unistd.h>
#include <db.h>
#define DIR "dir.test_db_dup"
// DIR is defined in the Makefile
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
int main() {
DB_ENV * const null_env = 0;
DB *db;
DB_TXN * const null_txn = 0;
const char * const fname = "test.dup.brt";
const char * const fname = DIR "/test.dup.db";
int r;
system("rm -rf " DIR);
r=mkdir(DIR, 0777); assert(r==0);
r=chdir(DIR); assert(r==0);
/* create the dup database file */
r = db_create(&db, null_env, 0);
assert(r == 0);
CKERR(r);
r = db->set_flags(db, DB_DUP);
assert(r == 0);
CKERR(r);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666);
assert(r == 0);
CKERR(r);
r = db->close(db, 0);
assert(r == 0);
CKERR(r);
/* verify dup flags match */
r = db_create(&db, null_env, 0);
assert(r == 0);
CKERR(r);
r = db->open(db, null_txn, fname, "main", DB_BTREE, 0, 0666);
assert(r != 0);
CKERR(r);
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, DB_DUP);
assert(r == 0);
CKERR(r);
r = db->open(db, null_txn, fname, "main", DB_BTREE, 0, 0666);
assert(r == 0);
CKERR(r);
r = db->close(db, 0);
assert(r == 0);
CKERR(r);
/* verify nodesize match */
r = db_create(&db, null_env, 0);
assert(r == 0);
CKERR(r);
r = db->set_flags(db, DB_DUP);
assert(r == 0);
CKERR(r);
r = db->set_pagesize(db, 4096);
assert(r == 0);
CKERR(r);
r = db->open(db, null_txn, fname, "main", DB_BTREE, 0, 0666);
assert(r == 0);
CKERR(r);
r = db->close(db, 0);
assert(r == 0);
r=chdir(".."); assert(r==0);
CKERR(r);
return 0;
}
#include <stdio.h>
#include <assert.h>
#include <db.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
// DIR is defined in the Makefile
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
int main() {
DB_ENV *dbenv;
int r;
system("rm -rf " DIR);
r=mkdir(DIR, 0777); assert(r==0);
r = db_env_create(&dbenv, 0);
assert(r == 0);
r = dbenv->open(dbenv, ".", DB_PRIVATE, 0);
r = dbenv->open(dbenv, DIR, DB_CREATE|DB_INIT_MPOOL|DB_PRIVATE, 0666);
assert(r == 0);
r = dbenv->open(dbenv, ".", DB_PRIVATE, 0);
r = dbenv->open(dbenv, DIR, DB_INIT_MPOOL|DB_PRIVATE, 0666);
assert(r != 0);
r = dbenv->close(dbenv, 0);
......
......@@ -5,7 +5,8 @@
#include <errno.h>
#include <db.h>
#define DIR "dir.test_db_open_notexist_reopen"
// DIR is defined in the Makefile
DB_ENV *env;
DB *db;
......
......@@ -5,7 +5,8 @@
#include <errno.h>
#include <db.h>
#define DIR "dir.test_db_open_notexist_reopen"
// DIR is defined in the Makefile
DB_ENV *env;
DB *db;
......
......@@ -6,7 +6,8 @@
#include <db.h>
#include <string.h>
#define DIR "dir.test_db_remove_memleak"
// DIR is defined in the Makefile
DB_ENV *env;
DB *db;
DBT key;
......@@ -22,7 +23,7 @@ int main (int argc, char *argv[]) {
key.data = "name";
r=db_env_create(&env, 0); assert(r==0);
r=env->open(env, DIR, DB_PRIVATE|DB_CREATE, 0777); assert(r==0);
r=env->open(env, DIR, DB_INIT_MPOOL|DB_PRIVATE|DB_CREATE, 0777); assert(r==0);
r=db_create(&db, env, 0); assert(r==0);
r=db->open(db, NULL, "master.db", NULL, DB_BTREE, DB_CREATE, 0666); assert(r==0);
......
......@@ -6,7 +6,9 @@
#include <db.h>
#include <string.h>
#define DIR "dir.test_db_remove_subdb"
// DIR is defined in the Makefile
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
DB_ENV *env;
DB *db;
DBT key;
......@@ -22,10 +24,11 @@ int main (int argc, char *argv[]) {
key.data = "name";
r=db_env_create(&env, 0); assert(r==0);
r=env->open(env, DIR, DB_PRIVATE|DB_CREATE, 0777); assert(r==0);
// Note: without DB_INIT_MPOOL the BDB library will fail on db->open().
r=env->open(env, DIR, DB_INIT_MPOOL|DB_PRIVATE|DB_CREATE, 0777); assert(r==0);
r=db_create(&db, env, 0); assert(r==0);
r=db->open(db, NULL, "master.db", "first", DB_BTREE, DB_CREATE, 0666); assert(r==0);
r=db->open(db, NULL, "master.db", "first", DB_BTREE, DB_CREATE, 0666); CKERR(r);
data.size = sizeof("first.db");
data.data = "first.db";
db->put(db, NULL, &key, &data, 0);
......
#include <stdlib.h>
#include <sys/stat.h>
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <db.h>
// DIR is defined in the Makefile
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
int main() {
DB_ENV * env = 0;
DB *db;
DB_TXN * const null_txn = 0;
const char * const fname = "test.db";
int r;
system("rm -rf " DIR);
r=mkdir(DIR, 0777); assert(r==0);
r=db_env_create(&env, 0); assert(r==0);
// Note: without DB_INIT_MPOOL the BDB library will fail on db->open().
r=env->open(env, DIR, DB_INIT_MPOOL|DB_PRIVATE|DB_CREATE|DB_INIT_LOG, 0777); assert(r==0);
r = db_create(&db, env, 0);
assert(r == 0);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666);
assert(r == 0);
r = db->close(db, 0);
assert(r == 0);
return 0;
}
#include <assert.h>
#include <db.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
// DIR is defined in the Makefile
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
DB_ENV *env;
int r;
system("rm -rf " DIR);
r=mkdir(DIR, 0777); assert(r==0);
r=db_env_create(&env, 0); assert(r==0);
r=env->close (env, 0); assert(r==0);
system("rm -rf " DIR);
r=mkdir(DIR, 0777); assert(r==0);
r=db_env_create(&env, 0); assert(r==0);
r=env->close (env, 1); assert(r==EINVAL);
system("rm -rf " DIR);
r=mkdir(DIR, 0777); assert(r==0);
r=db_env_create(&env, 0); assert(r==0);
r=env->open(env, DIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_PRIVATE|DB_CREATE, 0777); CKERR(r);
r=env->close (env, 0); assert(r==0);
system("rm -rf " DIR);
r=mkdir(DIR, 0777); assert(r==0);
r=db_env_create(&env, 0); assert(r==0);
r=env->open(env, DIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_PRIVATE|DB_CREATE, 0777); CKERR(r);
r=env->close (env, 1); assert(r==EINVAL);
return 0;
}
......@@ -5,7 +5,7 @@
#include <sys/types.h>
#include <db.h>
#define DIR "dir.test_log0"
// DIR is defined in the Makefile
DB_ENV *env;
......
......@@ -7,10 +7,7 @@
#include <string.h>
#include <stdio.h>
#ifndef DBVERSION
#define DBVERSION "toku"
#endif
#define DIR "dir.test_log1." DBVERSION
// DIR is defined in the Makefile
DB_ENV *env;
DB *db;
......
/* Test to see if we can do logging and recovery. */
/* This is very specific to TokuDB. It won't work with Berkeley DB. */
#include <assert.h>
#include <db.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
// DIR is defined in the Makefile
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
static void make_db (void) {
DB_ENV *env;
DB *db;
DB_TXN *tid;
int r;
system("rm -rf " DIR);
r=mkdir(DIR, 0777); assert(r==0);
r=db_env_create(&env, 0); assert(r==0);
r=env->open(env, DIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_PRIVATE|DB_CREATE, 0777); CKERR(r);
r=db_create(&db, env, 0); CKERR(r);
r=env->txn_begin(env, 0, &tid, 0); assert(r==0);
r=db->open(db, tid, "foo.db", 0, DB_BTREE, DB_CREATE, 0777); CKERR(r);
r=tid->commit(tid, 0); assert(r==0);
r=db->close(db, 0); assert(r==0);
r=env->close(env, 0); assert(r==0);
}
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
make_db();
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