diff --git a/src/lock_tree/tests/Makefile b/src/lock_tree/tests/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..c8bbbf4fd269540cc21a8fe8183d6ac056c11386 --- /dev/null +++ b/src/lock_tree/tests/Makefile @@ -0,0 +1,97 @@ +# On OSX do: +# make OSX=OSX + +# For verbose output do +# make VERBOSE=1 +# For very verbose output do +# make VERBOSE=2 + +ifeq ($(OSX),OSX) +#Note: OSX 10.4 needs DYLD_LIBRARY_PATH. OSX 10.5 claims to support -rpath. + LIBEXT=dylib + VGRIND= + CPPFLAGS = + SETENV=export DYLD_LIBRARY_PATH=..:../../range_tree ; +else + SETTOKUENV= + UNSETTOKUENV= + LIBEXT=so + CPPFLAGS = -Wl,-rpath,..,-rpath,../../range_tree + VGRIND=valgrind --quiet --error-exitcode=1 --leak-check=yes +endif + +LIBNAME=librt.$(LIBEXT) +# GCOV_FLAGS = -fprofile-arcs -ftest-coverage +CFLAGS = -Wall -Werror $(OPTFLAGS) -g3 -ggdb3 $(GCOV_FLAGS) +CPPFLAGS += -L../ -L../../range_tree +CPPFLAGS += -I. -I../ -I../../range_tree -I../../../newbrt -lpthread + + +SRCS = $(wildcard *.c) + +LOG_TESTS = $(patsubst %.c,%.log,$(SRCS)) +LIN_TESTS = $(patsubst %.c,%.lin,$(SRCS)) + +ALL_TESTS = $(LOG_TESTS) $(LIN_TESTS) + +RUN_LOG_TESTS = $(patsubst %.log,%.logrun,$(LOG_TESTS)) +RUN_LIN_TESTS = $(patsubst %.lin,%.linrun,$(LIN_TESTS)) +RUN_ALL_TESTS = $(RUN_LOG_TESTS) $(RUN_LIN_TESTS) + + +all: make_libs $(ALL_TESTS) + +.PHONY: check check.lin check.log tests.lin tests.log +check: check.lin check.log + @ echo ok +tests.lin: make_libs $(LIN_TESTS) +check.lin: make_libs $(RUN_LIN_TESTS) +tests.log: make_libs $(LOG_TESTS) +check.log: make_libs $(RUN_LOG_TESTS) + +# Need these rule so that Make knows about all the file names +.PHONY: %.linrun %.logrun %.run +$(RUN_ALL_TESTS): +$(ALL_TESTS): + +%.run: %.linrun %.logrun + @ echo ok + +ifeq ($(VERBOSE),2) +VERBVERBOSE=-v +MAYBEATSIGN= +VERBQUIET= +else + ifeq ($(VERBOSE),1) + VERBVERBOSE= + MAYBEATSIGN= + VERBQUIET= + else + VERBVERBOSE= + MAYBEATSIGN=@ + VERBQUIET=--quiet + endif +endif + +# The @ sign makes the make quiet. If there is an error there is enough info to tell what test failed. +%.linrun: %.lin + $(MAYBEATSIGN) $(SETENV) $(VGRIND) ./$< $(VERBVERBOSE) +%.logrun: %.log + $(MAYBEATSIGN) $(SETENV) $(VGRIND) ./$< $(VERBVERBOSE) + +libs: + cd ..;make + +%.lin: %.c ../locktree.h test.h + $(SETENV) cc -DDIR=\"dir.$<.lin\" -DTOKU_LINEAR_RANGE_TREE $(CPPFLAGS) $(CFLAGS) $< -lrangetreelinear -llocktree -o $@ +%.log: %.c ../locktree.h test.h + $(SETENV) cc -DDIR=\"dir.$<.log\" -DTOKU_LOG_RANGE_TREE $(CPPFLAGS) $(CFLAGS) $< -lrangetree -llocktre -o $@ + +.PHONY: make_libs + +make_libs: + cd ..;make + +clean: + rm -f $(ALL_TESTS) *.o *.gcno *.gcda *.gcov + rm -rf dir.*.log dir.*.LIN diff --git a/src/lock_tree/tests/test.h b/src/lock_tree/tests/test.h new file mode 100644 index 0000000000000000000000000000000000000000..c0b72fe39c7fa130b89ddd5b1f122aaefb0591c3 --- /dev/null +++ b/src/lock_tree/tests/test.h @@ -0,0 +1,83 @@ +#include <string.h> +#include <locktree.h> +#include <db.h> +#include <brttypes.h> +#include <stdlib.h> +#include <stdint.h> +#include <stdio.h> +#include <assert.h> +#include <errno.h> +int verbose=0; + +int toku_keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len) { + int comparelen = key1len<key2len ? key1len : key2len; + const unsigned char *k1; + const unsigned char *k2; + for (k1=key1, k2=key2; + comparelen>4; + k1+=4, k2+=4, comparelen-=4) { + { int v1=k1[0], v2=k2[0]; if (v1!=v2) return v1-v2; } + { int v1=k1[1], v2=k2[1]; if (v1!=v2) return v1-v2; } + { int v1=k1[2], v2=k2[2]; if (v1!=v2) return v1-v2; } + { int v1=k1[3], v2=k2[3]; if (v1!=v2) return v1-v2; } + } + for (; + comparelen>0; + k1++, k2++, comparelen--) { + if (*k1 != *k2) { + return (int)*k1-(int)*k2; + } + } + return key1len-key2len; +} + + +int dbcmp (DB *db __attribute__((__unused__)), const DBT *a, const DBT*b) { + return toku_keycompare(a->data, a->size, b->data, b->size); +} + + +#define CKERR(r) ({ if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, strerror(r)); assert(r==0); }) +#define CKERR2(r,r2) ({ if (r!=r2) fprintf(stderr, "%s:%d error %d %s, expected %d\n", __FILE__, __LINE__, r, strerror(r), r2); assert(r==r2); }) + +void parse_args (int argc, const char *argv[]) { + const char *argv0=argv[0]; + while (argc>1) { + int resultcode=0; + if (strcmp(argv[1], "-v")==0) { + verbose++; + } else if (strcmp(argv[1], "-h")==0) { + do_usage: + fprintf(stderr, "Usage:\n%s [-v|-h]\n", argv0); + exit(resultcode); + } else { + resultcode=1; + goto do_usage; + } + argc--; + argv++; + } +} + +// Simle LCG random number generator. Not high quality, but good enough. +static uint32_t rstate=1; +static inline void mysrandom (int s) { + rstate=s; +} +static inline uint32_t myrandom (void) { + rstate = (279470275ull*(uint64_t)rstate)%4294967291ull; + return rstate; +} + + +void* toku_malloc(size_t size) { + return malloc(size); +} + +void toku_free(void* p) { + free(p); +} + +void* toku_realloc(void *ptr, size_t size) { + return realloc(ptr, size); +} diff --git a/src/lock_tree/tests/test_00010_createclose.c b/src/lock_tree/tests/test_00010_createclose.c new file mode 100644 index 0000000000000000000000000000000000000000..2ba571c92699edcefb214a08d4be20f00b3e6a07 --- /dev/null +++ b/src/lock_tree/tests/test_00010_createclose.c @@ -0,0 +1,19 @@ +#include <test.h> + +int main() { + int r; + toku_lock_tree* lt = NULL; + DB* db; + BOOL duplicates = FALSE; + + r = toku_lt_create(<, db, duplicates, dbcmp, dbcmp, toku_malloc, toku_free, + toku_realloc); + CKERR(r); + assert(lt); + + r = toku_lt_close(lt); + CKERR(r); + + return 0; +} +