summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am14
-rw-r--r--test/Makefile.in548
-rw-r--r--test/itzam_btree_test_insert.c210
-rw-r--r--test/itzam_btree_test_stress.c374
-rw-r--r--test/itzam_btree_test_strvar.c277
-rw-r--r--test/itzam_btree_test_threads.c285
-rw-r--r--test/itzam_errors.h124
7 files changed, 1832 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..bfb4edb
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,14 @@
+CFLAGS = @CFLAGS@ -std=gnu99
+
+h_sources = itzam_errors.h
+
+bin_PROGRAMS = itzam_btree_test_insert itzam_btree_test_stress itzam_btree_test_threads itzam_btree_test_strvar
+
+itzam_btree_test_insert_SOURCES = itzam_btree_test_insert.c
+itzam_btree_test_stress_SOURCES = itzam_btree_test_stress.c
+itzam_btree_test_threads_SOURCES = itzam_btree_test_threads.c
+itzam_btree_test_strvar_SOURCES = itzam_btree_test_strvar.c
+
+LIBS = -L../src -litzam -lpthread
+
+EXTRA_DIST = itzam_errors.h
diff --git a/test/Makefile.in b/test/Makefile.in
new file mode 100644
index 0000000..46cfed8
--- /dev/null
+++ b/test/Makefile.in
@@ -0,0 +1,548 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+bin_PROGRAMS = itzam_btree_test_insert$(EXEEXT) \
+ itzam_btree_test_stress$(EXEEXT) \
+ itzam_btree_test_threads$(EXEEXT) \
+ itzam_btree_test_strvar$(EXEEXT)
+subdir = test
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__installdirs = "$(DESTDIR)$(bindir)"
+PROGRAMS = $(bin_PROGRAMS)
+am_itzam_btree_test_insert_OBJECTS = \
+ itzam_btree_test_insert.$(OBJEXT)
+itzam_btree_test_insert_OBJECTS = \
+ $(am_itzam_btree_test_insert_OBJECTS)
+itzam_btree_test_insert_LDADD = $(LDADD)
+am_itzam_btree_test_stress_OBJECTS = \
+ itzam_btree_test_stress.$(OBJEXT)
+itzam_btree_test_stress_OBJECTS = \
+ $(am_itzam_btree_test_stress_OBJECTS)
+itzam_btree_test_stress_LDADD = $(LDADD)
+am_itzam_btree_test_strvar_OBJECTS = \
+ itzam_btree_test_strvar.$(OBJEXT)
+itzam_btree_test_strvar_OBJECTS = \
+ $(am_itzam_btree_test_strvar_OBJECTS)
+itzam_btree_test_strvar_LDADD = $(LDADD)
+am_itzam_btree_test_threads_OBJECTS = \
+ itzam_btree_test_threads.$(OBJEXT)
+itzam_btree_test_threads_OBJECTS = \
+ $(am_itzam_btree_test_threads_OBJECTS)
+itzam_btree_test_threads_LDADD = $(LDADD)
+DEFAULT_INCLUDES = -I.@am__isrc@
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
+SOURCES = $(itzam_btree_test_insert_SOURCES) \
+ $(itzam_btree_test_stress_SOURCES) \
+ $(itzam_btree_test_strvar_SOURCES) \
+ $(itzam_btree_test_threads_SOURCES)
+DIST_SOURCES = $(itzam_btree_test_insert_SOURCES) \
+ $(itzam_btree_test_stress_SOURCES) \
+ $(itzam_btree_test_strvar_SOURCES) \
+ $(itzam_btree_test_threads_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@ -std=gnu99
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GENERIC_LIBRARY_NAME = @GENERIC_LIBRARY_NAME@
+GENERIC_LIBRARY_VERSION = @GENERIC_LIBRARY_VERSION@
+GENERIC_RELEASE = @GENERIC_RELEASE@
+GENERIC_VERSION = @GENERIC_VERSION@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = -L../src -litzam -lpthread
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+h_sources = itzam_errors.h
+itzam_btree_test_insert_SOURCES = itzam_btree_test_insert.c
+itzam_btree_test_stress_SOURCES = itzam_btree_test_stress.c
+itzam_btree_test_threads_SOURCES = itzam_btree_test_threads.c
+itzam_btree_test_strvar_SOURCES = itzam_btree_test_strvar.c
+EXTRA_DIST = itzam_errors.h
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign test/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign test/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-binPROGRAMS: $(bin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
+ @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed 's/$(EXEEXT)$$//' | \
+ while read p p1; do if test -f $$p || test -f $$p1; \
+ then echo "$$p"; echo "$$p"; else :; fi; \
+ done | \
+ sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \
+ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+ sed 'N;N;N;s,\n, ,g' | \
+ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+ if ($$2 == $$4) files[d] = files[d] " " $$1; \
+ else { print "f", $$3 "/" $$4, $$1; } } \
+ END { for (d in files) print "f", d, files[d] }' | \
+ while read type dir files; do \
+ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+ test -z "$$files" || { \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+ } \
+ ; done
+
+uninstall-binPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ files=`for p in $$list; do echo "$$p"; done | \
+ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+ -e 's/$$/$(EXEEXT)/' `; \
+ test -n "$$list" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(bindir)" && rm -f $$files
+
+clean-binPROGRAMS:
+ @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+itzam_btree_test_insert$(EXEEXT): $(itzam_btree_test_insert_OBJECTS) $(itzam_btree_test_insert_DEPENDENCIES)
+ @rm -f itzam_btree_test_insert$(EXEEXT)
+ $(LINK) $(itzam_btree_test_insert_OBJECTS) $(itzam_btree_test_insert_LDADD) $(LIBS)
+itzam_btree_test_stress$(EXEEXT): $(itzam_btree_test_stress_OBJECTS) $(itzam_btree_test_stress_DEPENDENCIES)
+ @rm -f itzam_btree_test_stress$(EXEEXT)
+ $(LINK) $(itzam_btree_test_stress_OBJECTS) $(itzam_btree_test_stress_LDADD) $(LIBS)
+itzam_btree_test_strvar$(EXEEXT): $(itzam_btree_test_strvar_OBJECTS) $(itzam_btree_test_strvar_DEPENDENCIES)
+ @rm -f itzam_btree_test_strvar$(EXEEXT)
+ $(LINK) $(itzam_btree_test_strvar_OBJECTS) $(itzam_btree_test_strvar_LDADD) $(LIBS)
+itzam_btree_test_threads$(EXEEXT): $(itzam_btree_test_threads_OBJECTS) $(itzam_btree_test_threads_DEPENDENCIES)
+ @rm -f itzam_btree_test_threads$(EXEEXT)
+ $(LINK) $(itzam_btree_test_threads_OBJECTS) $(itzam_btree_test_threads_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/itzam_btree_test_insert.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/itzam_btree_test_stress.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/itzam_btree_test_strvar.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/itzam_btree_test_threads.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ set x; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+ for dir in "$(DESTDIR)$(bindir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-binPROGRAMS
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-binPROGRAMS
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
+ clean-generic clean-libtool ctags distclean distclean-compile \
+ distclean-generic distclean-libtool distclean-tags distdir dvi \
+ dvi-am html html-am info info-am install install-am \
+ install-binPROGRAMS install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-ps install-ps-am \
+ install-strip installcheck installcheck-am installdirs \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+ pdf pdf-am ps ps-am tags uninstall uninstall-am \
+ uninstall-binPROGRAMS
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/test/itzam_btree_test_insert.c b/test/itzam_btree_test_insert.c
new file mode 100644
index 0000000..784b35e
--- /dev/null
+++ b/test/itzam_btree_test_insert.c
@@ -0,0 +1,210 @@
+/*
+ Itzam/C (version 6.0) is an embedded database engine written in Standard C.
+
+ Copyright 2011 Scott Robert Ladd. All rights reserved.
+
+ Older versions of Itzam/C are:
+ Copyright 2002, 2004, 2006, 2008 Scott Robert Ladd. All rights reserved.
+
+ Ancestral code, from Java and C++ books by the author, is:
+ Copyright 1992, 1994, 1996, 2001 Scott Robert Ladd. All rights reserved.
+
+ Itzam/C is user-supported open source software. It's continued development is dependent on
+ financial support from the community. You can provide funding by visiting the Itzam/C
+ website at:
+
+ http://www.coyotegulch.com
+
+ You may license Itzam/C in one of two fashions:
+
+ 1) Simplified BSD License (FreeBSD License)
+
+ Redistribution and use in source and binary forms, with or without modification, are
+ permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this list of
+ conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ of conditions and the following disclaimer in the documentation and/or other materials
+ provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY SCOTT ROBERT LADD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SCOTT ROBERT LADD OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ The views and conclusions contained in the software and documentation are those of the
+ authors and should not be interpreted as representing official policies, either expressed
+ or implied, of Scott Robert Ladd.
+
+ 2) Closed-Source Proprietary License
+
+ If your project is a closed-source or proprietary project, the Simplified BSD License may
+ not be appropriate or desirable. In such cases, contact the Itzam copyright holder to
+ arrange your purchase of an appropriate license.
+
+ The author can be contacted at:
+
+ scott.ladd@coyotegulch.com
+ scott.ladd@gmail.com
+ http:www.coyotegulch.com
+*/
+
+#include "../src/itzam.h"
+#include "itzam_errors.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/*----------------------------------------------------------
+ * Report an itzam error
+ */
+void not_okay(itzam_state state)
+{
+ fprintf(stderr, "\nItzam problem: %s\n", STATE_MESSAGES[state]);
+ exit(EXIT_FAILURE);
+}
+
+void error_handler(const char * function_name, itzam_error error)
+{
+ fprintf(stderr, "Itzam error in %s: %s\n", function_name, ERROR_STRINGS[error]);
+ exit(EXIT_FAILURE);
+}
+
+/*----------------------------------------------------------
+ * tests
+ */
+
+#define REC_SIZE 2560 /// x 4 bytes = 10240 bytes per record
+
+typedef struct record_t
+{
+ uint32_t m_key;
+ uint32_t m_data[REC_SIZE];
+}
+record;
+
+int compare_recs(const void * key1, const void * key2)
+{
+ int result = 0;
+
+ record * k1 = (record *)key1;
+ record * k2 = (record *)key2;
+
+ if (k1->m_key < k2->m_key)
+ result = -1;
+ else if (k1->m_key > k2->m_key)
+ result = 1;
+
+ return result;
+}
+
+itzam_bool test_btree_insert()
+{
+ itzam_btree btree;
+ itzam_state state;
+ record rec;
+ int n;
+ char * filename = "insert.itz";
+ itzam_int test_size = 1000000;
+ int order = 25;
+
+ time_t start = time(NULL);
+
+ memset(&rec.m_data,0,REC_SIZE * sizeof(uint32_t));
+ rec.m_key = 0;
+
+ // banner for this test
+ printf("\nItzam/C B-Tree Test\nStraight Insertion Performance\n");
+ printf("Please wait while I insert %d records of %d bytes...\n", (int)test_size, (int)(REC_SIZE * sizeof(uint32_t)));
+
+ state = itzam_btree_create(&btree, filename, order, sizeof(record), compare_recs, error_handler);
+
+ if (state != ITZAM_OKAY)
+ {
+ not_okay(state);
+ return itzam_false;
+ }
+
+ for (n = 1; n <= test_size; ++ n)
+ {
+ rec.m_key = n;
+ rec.m_data[0] = n;
+ rec.m_data[REC_SIZE - 1] = n;
+
+ state = itzam_btree_insert(&btree,(const void *)&rec);
+
+ if (state != ITZAM_OKAY)
+ {
+ not_okay(state);
+ return itzam_false;
+ }
+ }
+
+ time_t elapsed = time(NULL) - start;
+
+ printf(" database count: %d\n", (int)btree.m_header->m_count);
+ printf(" database ticker: %d\n", (int)btree.m_header->m_ticker);
+ printf(" total run time: %d seconds\n", (int)elapsed);
+ printf("insertions per second: %f\n", ((double)test_size / (double)elapsed));
+
+ // verify database after benchmark
+ itzam_btree_cursor cursor;
+ state = itzam_btree_cursor_create(&cursor, &btree);
+
+ if (state == ITZAM_OKAY)
+ {
+ do
+ {
+ // get the key pointed to by the cursor
+ state = itzam_btree_cursor_read(&cursor,(void *)&rec);
+
+ if (state == ITZAM_OKAY)
+ {
+ if ((rec.m_key != rec.m_data[0]) || (rec.m_key != rec.m_data[REC_SIZE - 1]))
+ {
+ printf("ERROR: record retrieved for %u does not match %u or %u\n",rec.m_key,rec.m_data[0],rec.m_data[REC_SIZE - 1]);
+ break;
+ }
+ }
+ else
+ not_okay(state);
+ }
+ while (itzam_btree_cursor_next(&cursor));
+
+ state = itzam_btree_cursor_free(&cursor);
+
+ if (state != ITZAM_OKAY)
+ return itzam_false;
+ }
+
+ state = itzam_btree_close(&btree);
+
+ if (state != ITZAM_OKAY)
+ {
+ not_okay(state);
+ return itzam_false;
+ }
+
+ return itzam_true;
+}
+
+int main(int argc, char* argv[])
+{
+ int result = EXIT_FAILURE;
+
+ itzam_set_default_error_handler(error_handler);
+
+ if (test_btree_insert())
+ result = EXIT_SUCCESS;
+
+ return result;
+}
diff --git a/test/itzam_btree_test_stress.c b/test/itzam_btree_test_stress.c
new file mode 100644
index 0000000..f9d1e77
--- /dev/null
+++ b/test/itzam_btree_test_stress.c
@@ -0,0 +1,374 @@
+/*
+ Itzam/C (version 6.0) is an embedded database engine written in Standard C.
+
+ Copyright 2011 Scott Robert Ladd. All rights reserved.
+
+ Older versions of Itzam/C are:
+ Copyright 2002, 2004, 2006, 2008 Scott Robert Ladd. All rights reserved.
+
+ Ancestral code, from Java and C++ books by the author, is:
+ Copyright 1992, 1994, 1996, 2001 Scott Robert Ladd. All rights reserved.
+
+ Itzam/C is user-supported open source software. It's continued development is dependent on
+ financial support from the community. You can provide funding by visiting the Itzam/C
+ website at:
+
+ http://www.coyotegulch.com
+
+ You may license Itzam/C in one of two fashions:
+
+ 1) Simplified BSD License (FreeBSD License)
+
+ Redistribution and use in source and binary forms, with or without modification, are
+ permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this list of
+ conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ of conditions and the following disclaimer in the documentation and/or other materials
+ provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY SCOTT ROBERT LADD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SCOTT ROBERT LADD OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ The views and conclusions contained in the software and documentation are those of the
+ authors and should not be interpreted as representing official policies, either expressed
+ or implied, of Scott Robert Ladd.
+
+ 2) Closed-Source Proprietary License
+
+ If your project is a closed-source or proprietary project, the Simplified BSD License may
+ not be appropriate or desirable. In such cases, contact the Itzam copyright holder to
+ arrange your purchase of an appropriate license.
+
+ The author can be contacted at:
+
+ scott.ladd@coyotegulch.com
+ scott.ladd@gmail.com
+ http:www.coyotegulch.com
+*/
+
+#include "../src/itzam.h"
+#include "itzam_errors.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/*----------------------------------------------------------
+ * embedded random number generator; ala Park and Miller
+ */
+static int32_t seed = 1325;
+
+void init_test_prng(int32_t s)
+{
+ seed = s;
+}
+
+int32_t random_int32(int32_t limit)
+{
+ static const int32_t IA = 16807;
+ static const int32_t IM = 2147483647;
+ static const int32_t IQ = 127773;
+ static const int32_t IR = 2836;
+ static const int32_t MASK = 123459876;
+
+ int32_t k;
+ int32_t result;
+
+ seed ^= MASK;
+ k = seed / IQ;
+ seed = IA * (seed - k * IQ) - IR * k;
+
+ if (seed < 0L)
+ seed += IM;
+
+ result = (seed % limit);
+ seed ^= MASK;
+
+ return result;
+}
+
+/*----------------------------------------------------------
+ * Reports an itzam error
+ */
+void not_okay(itzam_state state)
+{
+ fprintf(stderr, "\nItzam problem: %s\n", STATE_MESSAGES[state]);
+ exit(EXIT_FAILURE);
+}
+
+void error_handler(const char * function_name, itzam_error error)
+{
+ fprintf(stderr, "Itzam error in %s: %s\n", function_name, ERROR_STRINGS[error]);
+ exit(EXIT_FAILURE);
+}
+
+/*----------------------------------------------------------
+ * Verifies that the database contains the expected records
+ */
+static itzam_bool verify(itzam_btree * btree, itzam_bool * key_flags, int maxkey)
+{
+ itzam_bool result = itzam_true;
+ int32_t key, rec;
+
+ printf(" -- verifying... ");
+ fflush(stdout);
+
+ for (key = 0; key < maxkey; ++key)
+ {
+ if (itzam_btree_find(btree,(const void *)(&key),(void *)(&rec)))
+ {
+ if (key_flags[key])
+ {
+ if (rec != key)
+ {
+ printf("data does not match key %d\n", key);
+ result = itzam_false;
+ }
+ }
+ else
+ {
+ printf("key %d found, and should not have been\n", key);
+ result = itzam_false;
+ }
+ }
+ else
+ {
+ if (key_flags[key])
+ {
+ printf("expected key %d not found\n", key);
+ result = itzam_false;
+ }
+ }
+ }
+
+ if (result)
+ printf("okay\n");
+
+ return result;
+}
+
+/*----------------------------------------------------------
+ * tests
+ */
+itzam_bool test_btree_stress()
+{
+ itzam_btree btree;
+ itzam_state state;
+ int32_t key;
+ itzam_int n, i;
+ itzam_int add_count = 0;
+ itzam_int rem_count = 0;
+ itzam_int tran_count = 0;
+ itzam_int roll_count = 0;
+ itzam_int commit_count = 0;
+ itzam_bool in_transaction = itzam_false;
+ itzam_bool * save_flags = NULL;
+ itzam_int save_add_count = 0;
+ itzam_int save_rem_count = 0;
+ char * tran_message = NULL;
+ char * filename = "stress.itz";
+ itzam_int maxkey = 400000;
+ itzam_int test_size = 1000000;
+ int order = 25;
+ itzam_bool verified_run = itzam_false;
+ itzam_bool verbose = itzam_false;
+ itzam_bool use_transactions = itzam_true;
+ itzam_bool * key_flags = (itzam_bool *)malloc(maxkey * sizeof(itzam_bool));
+
+ time_t start = time(NULL);
+
+ for (n = 0; n < maxkey; ++n)
+ key_flags[n] = itzam_false;
+
+ // banner for this test
+ printf("\nItzam/C B-Tree Test\nRandomized Stress Test\n");
+
+ state = itzam_btree_create(&btree, filename, order, sizeof(int32_t), itzam_comparator_int32, error_handler);
+
+ if (state != ITZAM_OKAY)
+ {
+ not_okay(state);
+ return itzam_false;
+ }
+
+ save_flags = (itzam_bool *)malloc(sizeof(itzam_bool) * maxkey);
+
+ for (n = 1; n <= test_size; ++ n)
+ {
+ if (use_transactions && !in_transaction)
+ {
+ if (random_int32(100) < 20)
+ {
+ state = itzam_btree_transaction_start(&btree);
+ in_transaction = itzam_true;
+
+ if (verbose) printf("transaction START\n");
+
+ for (i = 0; i < maxkey; ++i)
+ save_flags[i] = key_flags[i];
+
+ save_add_count = add_count;
+ save_rem_count = rem_count;
+ ++tran_count;
+ }
+ }
+
+ key = (int32_t)random_int32((int32_t)maxkey);
+
+ if (verbose) printf("%8d: test key = %8u: ", (int)n, key);
+
+ state = itzam_btree_insert(&btree,(const void *)&key);
+
+ switch (state)
+ {
+ case ITZAM_OKAY:
+ if (key_flags[key])
+ {
+ if (verbose) printf("key was not found, and should have been\n");
+ return itzam_false;
+ }
+
+ key_flags[key] = itzam_true;
+ ++add_count;
+
+ if (verbose) printf("written successfully");
+
+ break;
+
+ case ITZAM_DUPLICATE:
+ if (!key_flags[key])
+ {
+ if (verbose) printf("key was found, and should not have been\n");
+ return itzam_false;
+ }
+
+ state = itzam_btree_remove(&btree,(const void *)(&key));
+ ++rem_count;
+
+ if (state == ITZAM_OKAY)
+ {
+ key_flags[key] = itzam_false;
+ if (verbose) printf("removed successfully");
+ }
+ else
+ {
+ if (verbose) printf("unable to remove data\n");
+ return itzam_false;
+ }
+
+ break;
+
+ default:
+ not_okay(state);
+ return itzam_false;
+ }
+
+ if (in_transaction)
+ {
+ int32_t choice = random_int32(100);
+
+ if (choice < 35)
+ {
+ state = itzam_btree_transaction_commit(&btree);
+ in_transaction = itzam_false;
+
+ tran_message = "transaction COMMIT\n";
+ ++commit_count;
+ }
+ else if (choice < 65)
+ {
+ state = itzam_btree_transaction_rollback(&btree);
+ in_transaction = itzam_false;
+
+ tran_message = "transaction ROLLBACK\n";
+
+ for (i = 0; i < maxkey; ++i)
+ key_flags[i] = save_flags[i];
+
+ add_count = save_add_count;
+ rem_count = save_rem_count;
+
+ ++roll_count;
+ }
+ }
+
+ if (verified_run)
+ {
+ itzam_bool okay = verify(&btree,key_flags,maxkey);
+
+ if (!okay)
+ return itzam_false;
+ }
+ else
+ {
+ if (verbose) printf(" - done\n");
+ }
+
+ if (tran_message != NULL)
+ {
+ if (verbose)
+ printf("%s\n",tran_message);
+
+ tran_message = NULL;
+ }
+ }
+
+ time_t elapsed = time(NULL) - start;
+
+ int tests = add_count + rem_count;
+
+ printf("\ntotal records added: %u\n", (unsigned int)add_count);
+ printf("total records removed: %u\n", (unsigned int)rem_count);
+
+ if (use_transactions)
+ {
+ printf(" transactions: %u\n", (unsigned int)tran_count);
+ printf(" commits: %u\n", (unsigned int)commit_count);
+ printf(" rollbacks: %u\n", (unsigned int)roll_count);
+ }
+
+ printf(" database count: %d\n", (int)btree.m_header->m_count);
+ printf(" database ticker: %d\n", (int)btree.m_header->m_ticker);
+ printf(" total run time: %u seconds\n", (unsigned int)elapsed);
+ printf("operations per second: %f\n", ((double)tests / (double)elapsed));
+
+ free(save_flags);
+
+ state = itzam_btree_close(&btree);
+
+ if (state != ITZAM_OKAY)
+ {
+ not_okay(state);
+ return itzam_false;
+ }
+
+ free(key_flags);
+
+ return itzam_true;
+}
+
+int main(int argc, char* argv[])
+{
+ int result = EXIT_FAILURE;
+
+ itzam_set_default_error_handler(error_handler);
+
+ init_test_prng((long)time(NULL));
+
+ if (test_btree_stress())
+ result = EXIT_SUCCESS;
+
+ return result;
+}
+
diff --git a/test/itzam_btree_test_strvar.c b/test/itzam_btree_test_strvar.c
new file mode 100644
index 0000000..a3928f5
--- /dev/null
+++ b/test/itzam_btree_test_strvar.c
@@ -0,0 +1,277 @@
+/*
+ Itzam/C (version 6.0) is an embedded database engine written in Standard C.
+
+ Copyright 2011 Scott Robert Ladd. All rights reserved.
+
+ Older versions of Itzam/C are:
+ Copyright 2002, 2004, 2006, 2008 Scott Robert Ladd. All rights reserved.
+
+ Ancestral code, from Java and C++ books by the author, is:
+ Copyright 1992, 1994, 1996, 2001 Scott Robert Ladd. All rights reserved.
+
+ Itzam/C is user-supported open source software. It's continued development is dependent on
+ financial support from the community. You can provide funding by visiting the Itzam/C
+ website at:
+
+ http://www.coyotegulch.com
+
+ You may license Itzam/C in one of two fashions:
+
+ 1) Simplified BSD License (FreeBSD License)
+
+ Redistribution and use in source and binary forms, with or without modification, are
+ permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this list of
+ conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ of conditions and the following disclaimer in the documentation and/or other materials
+ provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY SCOTT ROBERT LADD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SCOTT ROBERT LADD OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ The views and conclusions contained in the software and documentation are those of the
+ authors and should not be interpreted as representing official policies, either expressed
+ or implied, of Scott Robert Ladd.
+
+ 2) Closed-Source Proprietary License
+
+ If your project is a closed-source or proprietary project, the Simplified BSD License may
+ not be appropriate or desirable. In such cases, contact the Itzam copyright holder to
+ arrange your purchase of an appropriate license.
+
+ The author can be contacted at:
+
+ scott.ladd@coyotegulch.com
+ scott.ladd@gmail.com
+ http:www.coyotegulch.com
+*/
+
+#include "../src/itzam.h"
+#include "itzam_errors.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/*----------------------------------------------------------
+ * embedded random number generator; ala Park and Miller
+ */
+static int32_t seed = 1325;
+
+void init_test_prng(int32_t s)
+{
+ seed = s;
+}
+
+int32_t random_int32(int32_t limit)
+{
+ static const int32_t IA = 16807;
+ static const int32_t IM = 2147483647;
+ static const int32_t IQ = 127773;
+ static const int32_t IR = 2836;
+ static const int32_t MASK = 123459876;
+
+ int32_t k;
+ int32_t result;
+
+ seed ^= MASK;
+ k = seed / IQ;
+ seed = IA * (seed - k * IQ) - IR * k;
+
+ if (seed < 0L)
+ seed += IM;
+
+ result = (seed % limit);
+ seed ^= MASK;
+
+ return result;
+}
+
+/*----------------------------------------------------------
+ * Reports an itzam error
+ */
+void not_okay(itzam_state state)
+{
+ fprintf(stderr, "\nItzam problem: %s\n", STATE_MESSAGES[state]);
+ exit(EXIT_FAILURE);
+}
+
+void error_handler(const char * function_name, itzam_error error)
+{
+ fprintf(stderr, "Itzam error in %s: %s\n", function_name, ERROR_STRINGS[error]);
+ exit(EXIT_FAILURE);
+}
+
+/*----------------------------------------------------------
+ * Key record
+ */
+#define MAX_KEY_LEN 24
+#define REC_LEN_BASE 10
+#define REC_LEN_EXT 90
+
+typedef struct t_key_type
+{
+ char m_key[MAX_KEY_LEN];
+ itzam_int m_rec_len;
+ itzam_ref m_rec_ref;
+}
+key_type;
+
+// could be shorter, but want to be clear
+int compare_keys(const void * key1, const void * key2)
+{
+ const key_type * k1 = (const key_type *)key1;
+ const key_type * k2 = (const key_type *)key2;
+
+ return strcmp(k1->m_key,k2->m_key);
+}
+
+/*----------------------------------------------------------
+ * tests
+ */
+itzam_bool test_btree_strvar()
+{
+ itzam_btree btree;
+ itzam_btree_cursor cursor;
+ itzam_state state;
+ int n, i, klen;
+ char * filename = "strvar.itz";
+ itzam_int test_size = 100;
+ int order = 25;
+ key_type key;
+ char * record;
+ itzam_int len_read;
+
+ // banner for this test
+ printf("\nItzam/C B-Tree Test\nString Keys & Variable-Length Records\n");
+
+ state = itzam_btree_create(&btree, filename, order, sizeof(key_type), compare_keys, error_handler);
+
+ if (state != ITZAM_OKAY)
+ not_okay(state);
+
+ for (n = 1; n <= test_size; ++ n)
+ {
+ /* generate a random alphabetic key */
+ memset(key.m_key,0,MAX_KEY_LEN);
+
+ klen = random_int32((int32_t)(MAX_KEY_LEN - 9)) + 9;
+
+ for (i = 0; i < klen; ++i)
+ key.m_key[i] = 'A' + random_int32(26);
+
+ /* generate the record */
+ key.m_rec_len = REC_LEN_BASE + (itzam_int)random_int32((int32_t)REC_LEN_EXT);
+
+ record = (char *)malloc(key.m_rec_len);
+
+ memset(record, key.m_key[0], key.m_rec_len);
+
+ /* write record directly to the datafile */
+ key.m_rec_ref = itzam_datafile_write(btree.m_datafile, (void *)record, key.m_rec_len, ITZAM_NULL_REF);
+
+ /* if it worked, write the key */
+ if (key.m_rec_ref != ITZAM_NULL_REF)
+ {
+ state = itzam_btree_insert(&btree,(const void *)&key);
+
+ if (ITZAM_OKAY != state)
+ not_okay(state);
+ }
+ else
+ {
+ fprintf(stderr,"Unable to write database record\n");
+ exit(EXIT_FAILURE);
+ }
+
+ printf("wrote record at key %s\n",key.m_key);
+
+ free(record);
+ }
+
+ // now use a cursor to show the records stored, in key order
+ state = itzam_btree_cursor_create(&cursor, &btree);
+
+ if (state == ITZAM_OKAY)
+ {
+ do
+ {
+ // get the key pointed to by the cursor
+ state = itzam_btree_cursor_read(&cursor,(void *)&key);
+
+ if (state == ITZAM_OKAY)
+ {
+ // seek to record
+ state = itzam_datafile_seek(btree.m_datafile, key.m_rec_ref);
+
+ if (state == ITZAM_OKAY)
+ {
+ // read record
+ state = itzam_datafile_read_alloc(btree.m_datafile,(void **)&record,&len_read);
+
+ if (state == ITZAM_OKAY)
+ {
+ // verify that record matches key
+ for (i = 0; i < key.m_rec_len; ++i)
+ {
+ if (key.m_key[0] != record[i])
+ {
+ printf("ERROR: record retrieved for %s does not match\n",key.m_key);
+ break;
+ }
+ }
+
+ printf("record retrieved for %s matches\n",key.m_key);
+
+ free(record); // was allocated by the datafile read;
+ }
+ else
+ not_okay(state);
+ }
+ else
+ not_okay(state);
+ }
+ else
+ not_okay(state);
+ }
+ while (itzam_btree_cursor_next(&cursor));
+
+ state = itzam_btree_cursor_free(&cursor);
+
+ if (state != ITZAM_OKAY)
+ return itzam_false;
+ }
+
+ state = itzam_btree_close(&btree);
+
+ if (state != ITZAM_OKAY)
+ return itzam_false;
+
+ return itzam_true;
+}
+
+int main(int argc, char* argv[])
+{
+ int result = EXIT_FAILURE;
+
+ itzam_set_default_error_handler(error_handler);
+
+ init_test_prng((long)time(NULL));
+
+ if (test_btree_strvar())
+ result = EXIT_SUCCESS;
+
+ return result;
+}
+
diff --git a/test/itzam_btree_test_threads.c b/test/itzam_btree_test_threads.c
new file mode 100644
index 0000000..7b8c547
--- /dev/null
+++ b/test/itzam_btree_test_threads.c
@@ -0,0 +1,285 @@
+/*
+ Itzam/C (version 6.0) is an embedded database engine written in Standard C.
+
+ Copyright 2011 Scott Robert Ladd. All rights reserved.
+
+ Older versions of Itzam/C are:
+ Copyright 2002, 2004, 2006, 2008 Scott Robert Ladd. All rights reserved.
+
+ Ancestral code, from Java and C++ books by the author, is:
+ Copyright 1992, 1994, 1996, 2001 Scott Robert Ladd. All rights reserved.
+
+ Itzam/C is user-supported open source software. It's continued development is dependent on
+ financial support from the community. You can provide funding by visiting the Itzam/C
+ website at:
+
+ http://www.coyotegulch.com
+
+ You may license Itzam/C in one of two fashions:
+
+ 1) Simplified BSD License (FreeBSD License)
+
+ Redistribution and use in source and binary forms, with or without modification, are
+ permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this list of
+ conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ of conditions and the following disclaimer in the documentation and/or other materials
+ provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY SCOTT ROBERT LADD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SCOTT ROBERT LADD OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ The views and conclusions contained in the software and documentation are those of the
+ authors and should not be interpreted as representing official policies, either expressed
+ or implied, of Scott Robert Ladd.
+
+ 2) Closed-Source Proprietary License
+
+ If your project is a closed-source or proprietary project, the Simplified BSD License may
+ not be appropriate or desirable. In such cases, contact the Itzam copyright holder to
+ arrange your purchase of an appropriate license.
+
+ The author can be contacted at:
+
+ scott.ladd@coyotegulch.com
+ scott.ladd@gmail.com
+ http:www.coyotegulch.com
+*/
+
+#include "../src/itzam.h"
+#include "itzam_errors.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sched.h>
+
+/*----------------------------------------------------------
+ * embedded random number generator; ala Park and Miller
+ */
+static int32_t seed = 1325;
+
+void init_test_prng(int32_t s)
+{
+ seed = s;
+}
+
+int32_t random_int32(int32_t limit)
+{
+ static const int32_t IA = 16807;
+ static const int32_t IM = 2147483647;
+ static const int32_t IQ = 127773;
+ static const int32_t IR = 2836;
+ static const int32_t MASK = 123459876;
+
+ int32_t k;
+ int32_t result;
+
+ seed ^= MASK;
+ k = seed / IQ;
+ seed = IA * (seed - k * IQ) - IR * k;
+
+ if (seed < 0L)
+ seed += IM;
+
+ result = (seed % limit);
+ seed ^= MASK;
+
+ return result;
+}
+
+/*----------------------------------------------------------
+ * Reports an itzam error
+ */
+void not_okay(itzam_state state)
+{
+ fprintf(stderr, "\nItzam problem: %s\n", STATE_MESSAGES[state]);
+ exit(EXIT_FAILURE);
+}
+
+void error_handler(const char * function_name, itzam_error error)
+{
+ fprintf(stderr, "Itzam error in %s: %s\n", function_name, ERROR_STRINGS[error]);
+ exit(EXIT_FAILURE);
+}
+
+/*----------------------------------------------------------
+ * tests
+ */
+
+pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+itzam_bool test_btree_thread(itzam_btree * btree, int maxkey, int test_size, int * completed)
+{
+ itzam_state state = ITZAM_FAILED;
+ int32_t key;
+ int i;
+
+ if (btree != NULL)
+ {
+ for (i = 0; i < test_size; ++i)
+ {
+ key = (int32_t)random_int32((int32_t)maxkey);
+
+ if (ITZAM_OKAY != itzam_btree_insert(btree,(const void *)&key))
+ {
+ // ignore error here, as the record may have been removed by another thread
+ itzam_btree_remove(btree,(const void *)&key);
+ }
+ }
+
+ state = ITZAM_OKAY;
+
+ pthread_mutex_lock(&mutex);
+
+ if (completed != NULL)
+ (*completed)++;
+
+ pthread_mutex_unlock(&mutex);
+ }
+
+ if (state == ITZAM_OKAY)
+ return itzam_true;
+ else
+ return itzam_false;
+}
+
+struct threadArgs
+{
+ itzam_btree * btree;
+ int maxkey;
+ int test_size;
+ int * completed;
+};
+
+void * threadProc(void * a)
+{
+ struct threadArgs * args = (struct threadArgs *)a;
+ test_btree_thread(args->btree, args->maxkey, args->test_size, args->completed);
+ return NULL;
+}
+
+static void createdb(const char * filename, uint16_t order)
+{
+ itzam_btree btree;
+ itzam_state state;
+
+ /* create an empty database file
+ */
+ state = itzam_btree_create(&btree, filename, order, sizeof(int32_t), itzam_comparator_int32, error_handler);
+
+ if (state != ITZAM_OKAY)
+ {
+ printf("Unable to create B-tree index file %s\n", filename);
+ exit(1);
+ }
+
+ itzam_btree_close(&btree);
+}
+
+static itzam_bool test_threaded()
+{
+ const uint16_t order = 7;
+ char * sfilename = "threaded.single";
+ char * mfilename = "threaded.multi";
+ time_t start;
+ int maxkey = 5000;
+ int test_size = 1000000;
+ pthread_attr_t attr;
+ pthread_t * thread;
+ struct threadArgs * args;
+ int completed = 0;
+ int32_t key;
+ int n;
+
+ itzam_btree btree;
+ itzam_state state;
+
+ /* get number of processors available
+ */
+ int num_threads = (int)sysconf(_SC_NPROCESSORS_CONF) - 1;
+
+ if (num_threads < 2)
+ num_threads = 2;
+
+ thread = (pthread_t *)malloc(num_threads * sizeof(pthread_t));
+ args = (struct threadArgs *)malloc(num_threads * sizeof(struct threadArgs));
+
+ printf("\nItzam/C B-Tree Test\nMultiple threads, simultaneously using the same Itzam index\n\n");
+ printf("Parameters:\n%8d B-tree order\n%8d unique keys\n%8d threads\n%8d insert & remove operations\n",
+ order, maxkey, num_threads, test_size);
+
+ /* create threads and test simultaneous access to the database
+ */
+ createdb(mfilename, order);
+
+ test_size /= num_threads;
+
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ pthread_attr_setschedpolicy(&attr, SCHED_RR);
+
+ state = itzam_btree_open(&btree, mfilename, itzam_comparator_int32, error_handler, false, false);
+
+ if (state != ITZAM_OKAY)
+ {
+ printf("Unable to open B-tree index file %s\n",mfilename);
+ return itzam_false;
+ }
+
+ printf("\nPerforming multi-thread test... ");
+ fflush(stdout);
+
+ start = time(NULL);
+
+ for (n = 0; n < num_threads; ++n)
+ {
+ args[n].btree = &btree;
+ args[n].maxkey = maxkey;
+ args[n].test_size = test_size;
+ args[n].completed = &completed;
+ pthread_create(&thread[n], &attr, threadProc, &args[n]);
+ }
+
+ while (completed < num_threads)
+ usleep(100000);
+
+ itzam_btree_close(&btree);
+
+ free(thread);
+ free(args);
+
+ /* stats
+ */
+ time_t melapsed = time(NULL) - start;
+
+ printf("done\n\n%8d seconds run time\n\n", (int)melapsed);
+
+ return itzam_true;
+}
+
+int main(int argc, char* argv[])
+{
+ int result = EXIT_FAILURE;
+
+ itzam_set_default_error_handler(error_handler);
+
+ init_test_prng(314159);
+
+ if (test_threaded())
+ result = EXIT_SUCCESS;
+
+ return result;
+}
+
diff --git a/test/itzam_errors.h b/test/itzam_errors.h
new file mode 100644
index 0000000..c98905c
--- /dev/null
+++ b/test/itzam_errors.h
@@ -0,0 +1,124 @@
+/*
+ Itzam/C (version 6.0) is an embedded database engine written in Standard C.
+
+ Copyright 2011 Scott Robert Ladd. All rights reserved.
+
+ Older versions of Itzam/C are:
+ Copyright 2002, 2004, 2006, 2008 Scott Robert Ladd. All rights reserved.
+
+ Ancestral code, from Java and C++ books by the author, is:
+ Copyright 1992, 1994, 1996, 2001 Scott Robert Ladd. All rights reserved.
+
+ Itzam/C is user-supported open source software. It's continued development is dependent on
+ financial support from the community. You can provide funding by visiting the Itzam/C
+ website at:
+
+ http://www.coyotegulch.com
+
+ You may license Itzam/C in one of two fashions:
+
+ 1) Simplified BSD License (FreeBSD License)
+
+ Redistribution and use in source and binary forms, with or without modification, are
+ permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this list of
+ conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ of conditions and the following disclaimer in the documentation and/or other materials
+ provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY SCOTT ROBERT LADD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SCOTT ROBERT LADD OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ The views and conclusions contained in the software and documentation are those of the
+ authors and should not be interpreted as representing official policies, either expressed
+ or implied, of Scott Robert Ladd.
+
+ 2) Closed-Source Proprietary License
+
+ If your project is a closed-source or proprietary project, the Simplified BSD License may
+ not be appropriate or desirable. In such cases, contact the Itzam copyright holder to
+ arrange your purchase of an appropriate license.
+
+ The author can be contacted at:
+
+ scott.ladd@coyotegulch.com
+ scott.ladd@gmail.com
+ http:www.coyotegulch.com
+*/
+
+#if !defined(ITZAM_ERRORS_H)
+#define ITZAM_ERRORS_H
+
+static const char * ERROR_STRINGS [] =
+{
+ "invalid datafile signature",
+ "invalid version",
+ "can not open 64-bit datafile on 32-bit operating system",
+ "write failed",
+ "open failed",
+ "read failed",
+ "close failed",
+ "seek failed",
+ "tell failed",
+ "duplicate remove",
+ "flush failed",
+ "rewrite record too small",
+ "page not found",
+ "lost key",
+ "key not written",
+ "key seek failed",
+ "unable to remove key record",
+ "record seek failed",
+ "unable to remove data record",
+ "list of deleted records could not be read",
+ "list of deleted records could not be written",
+ "iterator record count differs from database internal count",
+ "rewrite over deleted record",
+ "invalid column index",
+ "invalid row index",
+ "invalid hash value",
+ "memory allocation failed",
+ "attempt reading deleted record",
+ "invalid record signature found",
+ "invalid file locking mode",
+ "unable to lock datafile",
+ "unable to unlock datafile",
+ "size mismatch when reading record",
+ "attempt to start new transaction while one is already active",
+ "no transaction active",
+ "attempt to free a B-tree cursor when cursors were active",
+ "invalid datafile object",
+ "size_t is incompatible with Itzam",
+ "could not create datafile",
+ "global shared memory requires Administrator or user with SeCreateGlobalPrivilege",
+ "cannot create global shared memory",
+ "another process or thread has already created shared objects for this datafile",
+ "invalid operation for read only file"
+};
+
+static const char * STATE_MESSAGES [] =
+{
+ "okay",
+ "operation failed",
+ "version mismatch in files",
+ "iterator at end",
+ "iterator at beginning",
+ "key not found",
+ "duplicate key",
+ "exceeded maximum file size on 32-bit system",
+ "unable to write data record for index",
+ "sizeof(size_t) smaller than required for file references; possibly 64-bit DB on 32-bit platform",
+ "invalid operation for read only file"
+};
+
+#endif \ No newline at end of file