diff options
Diffstat (limited to 'common/tests')
| -rw-r--r-- | common/tests/Atffile | 5 | ||||
| -rw-r--r-- | common/tests/Makefile.am | 30 | ||||
| -rw-r--r-- | common/tests/Makefile.in | 694 | ||||
| -rw-r--r-- | common/tests/ns_name_test.c | 160 | ||||
| -rw-r--r-- | common/tests/test_alloc.c | 501 |
5 files changed, 1390 insertions, 0 deletions
diff --git a/common/tests/Atffile b/common/tests/Atffile new file mode 100644 index 0000000..10402ce --- /dev/null +++ b/common/tests/Atffile @@ -0,0 +1,5 @@ +Content-Type: application/X-atf-atffile; version="1" + +prop: test-suite = dhcp4 + +tp-glob: *_unittest diff --git a/common/tests/Makefile.am b/common/tests/Makefile.am new file mode 100644 index 0000000..cfe3d83 --- /dev/null +++ b/common/tests/Makefile.am @@ -0,0 +1,30 @@ +SUBDIRS = . + +AM_CPPFLAGS = $(ATF_CFLAGS) -I$(top_srcdir)/includes + +EXTRA_DIST = Atffile + +ATF_TESTS = + +if HAVE_ATF + +ATF_TESTS += alloc_unittest ns_name_unittest + +alloc_unittest_SOURCES = test_alloc.c $(top_srcdir)/tests/t_api_dhcp.c +alloc_unittest_LDADD = $(ATF_LDFLAGS) +alloc_unittest_LDADD += ../libdhcp.a \ + ../../omapip/libomapi.a ../../bind/lib/libdns.a \ + ../../bind/lib/libisc.a + +ns_name_unittest_SOURCES = ns_name_test.c $(top_srcdir)/tests/t_api_dhcp.c +ns_name_unittest_LDADD = $(ATF_LDFLAGS) +ns_name_unittest_LDADD += ../libdhcp.a \ + ../../omapip/libomapi.a ../../bind/lib/libdns.a \ + ../../bind/lib/libisc.a + +check: $(ATF_TESTS) + sh ${top_srcdir}/tests/unittest.sh + +endif + +check_PROGRAMS = $(ATF_TESTS) diff --git a/common/tests/Makefile.in b/common/tests/Makefile.in new file mode 100644 index 0000000..67d5865 --- /dev/null +++ b/common/tests/Makefile.in @@ -0,0 +1,694 @@ +# Makefile.in generated by automake 1.14 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2013 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@ +am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +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@ +@HAVE_ATF_TRUE@am__append_1 = alloc_unittest ns_name_unittest +check_PROGRAMS = $(am__EXEEXT_2) +subdir = common/tests +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ + $(top_srcdir)/depcomp +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_HEADER = $(top_builddir)/includes/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +@HAVE_ATF_TRUE@am__EXEEXT_1 = alloc_unittest$(EXEEXT) \ +@HAVE_ATF_TRUE@ ns_name_unittest$(EXEEXT) +am__EXEEXT_2 = $(am__EXEEXT_1) +am__alloc_unittest_SOURCES_DIST = test_alloc.c \ + $(top_srcdir)/tests/t_api_dhcp.c +@HAVE_ATF_TRUE@am_alloc_unittest_OBJECTS = test_alloc.$(OBJEXT) \ +@HAVE_ATF_TRUE@ t_api_dhcp.$(OBJEXT) +alloc_unittest_OBJECTS = $(am_alloc_unittest_OBJECTS) +am__DEPENDENCIES_1 = +@HAVE_ATF_TRUE@alloc_unittest_DEPENDENCIES = $(am__DEPENDENCIES_1) \ +@HAVE_ATF_TRUE@ ../libdhcp.a ../../omapip/libomapi.a \ +@HAVE_ATF_TRUE@ ../../bind/lib/libdns.a ../../bind/lib/libisc.a +am__ns_name_unittest_SOURCES_DIST = ns_name_test.c \ + $(top_srcdir)/tests/t_api_dhcp.c +@HAVE_ATF_TRUE@am_ns_name_unittest_OBJECTS = ns_name_test.$(OBJEXT) \ +@HAVE_ATF_TRUE@ t_api_dhcp.$(OBJEXT) +ns_name_unittest_OBJECTS = $(am_ns_name_unittest_OBJECTS) +@HAVE_ATF_TRUE@ns_name_unittest_DEPENDENCIES = $(am__DEPENDENCIES_1) \ +@HAVE_ATF_TRUE@ ../libdhcp.a ../../omapip/libomapi.a \ +@HAVE_ATF_TRUE@ ../../bind/lib/libdns.a ../../bind/lib/libisc.a +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/includes +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(alloc_unittest_SOURCES) $(ns_name_unittest_SOURCES) +DIST_SOURCES = $(am__alloc_unittest_SOURCES_DIST) \ + $(am__ns_name_unittest_SOURCES_DIST) +RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ + ctags-recursive dvi-recursive html-recursive info-recursive \ + install-data-recursive install-dvi-recursive \ + install-exec-recursive install-html-recursive \ + install-info-recursive install-pdf-recursive \ + install-ps-recursive install-recursive installcheck-recursive \ + installdirs-recursive pdf-recursive ps-recursive \ + tags-recursive uninstall-recursive +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +am__recursive_targets = \ + $(RECURSIVE_TARGETS) \ + $(RECURSIVE_CLEAN_TARGETS) \ + $(am__extra_recursive_targets) +AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ + distdir +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +ATF_BIN = @ATF_BIN@ +ATF_CFLAGS = @ATF_CFLAGS@ +ATF_LDFLAGS = @ATF_LDFLAGS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDAP_CFLAGS = @LDAP_CFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +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@ +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_prefix_program = @ac_prefix_program@ +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@ +byte_order = @byte_order@ +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@ +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@ +SUBDIRS = . +AM_CPPFLAGS = $(ATF_CFLAGS) -I$(top_srcdir)/includes +EXTRA_DIST = Atffile +ATF_TESTS = $(am__append_1) +@HAVE_ATF_TRUE@alloc_unittest_SOURCES = test_alloc.c $(top_srcdir)/tests/t_api_dhcp.c +@HAVE_ATF_TRUE@alloc_unittest_LDADD = $(ATF_LDFLAGS) ../libdhcp.a \ +@HAVE_ATF_TRUE@ ../../omapip/libomapi.a ../../bind/lib/libdns.a \ +@HAVE_ATF_TRUE@ ../../bind/lib/libisc.a +@HAVE_ATF_TRUE@ns_name_unittest_SOURCES = ns_name_test.c $(top_srcdir)/tests/t_api_dhcp.c +@HAVE_ATF_TRUE@ns_name_unittest_LDADD = $(ATF_LDFLAGS) ../libdhcp.a \ +@HAVE_ATF_TRUE@ ../../omapip/libomapi.a ../../bind/lib/libdns.a \ +@HAVE_ATF_TRUE@ ../../bind/lib/libisc.a +all: all-recursive + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(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 common/tests/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign common/tests/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: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-checkPROGRAMS: + -test -z "$(check_PROGRAMS)" || rm -f $(check_PROGRAMS) + +alloc_unittest$(EXEEXT): $(alloc_unittest_OBJECTS) $(alloc_unittest_DEPENDENCIES) $(EXTRA_alloc_unittest_DEPENDENCIES) + @rm -f alloc_unittest$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(alloc_unittest_OBJECTS) $(alloc_unittest_LDADD) $(LIBS) + +ns_name_unittest$(EXEEXT): $(ns_name_unittest_OBJECTS) $(ns_name_unittest_DEPENDENCIES) $(EXTRA_ns_name_unittest_DEPENDENCIES) + @rm -f ns_name_unittest$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(ns_name_unittest_OBJECTS) $(ns_name_unittest_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ns_name_test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_api_dhcp.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_alloc.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +t_api_dhcp.o: $(top_srcdir)/tests/t_api_dhcp.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT t_api_dhcp.o -MD -MP -MF $(DEPDIR)/t_api_dhcp.Tpo -c -o t_api_dhcp.o `test -f '$(top_srcdir)/tests/t_api_dhcp.c' || echo '$(srcdir)/'`$(top_srcdir)/tests/t_api_dhcp.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/t_api_dhcp.Tpo $(DEPDIR)/t_api_dhcp.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$(top_srcdir)/tests/t_api_dhcp.c' object='t_api_dhcp.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o t_api_dhcp.o `test -f '$(top_srcdir)/tests/t_api_dhcp.c' || echo '$(srcdir)/'`$(top_srcdir)/tests/t_api_dhcp.c + +t_api_dhcp.obj: $(top_srcdir)/tests/t_api_dhcp.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT t_api_dhcp.obj -MD -MP -MF $(DEPDIR)/t_api_dhcp.Tpo -c -o t_api_dhcp.obj `if test -f '$(top_srcdir)/tests/t_api_dhcp.c'; then $(CYGPATH_W) '$(top_srcdir)/tests/t_api_dhcp.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/tests/t_api_dhcp.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/t_api_dhcp.Tpo $(DEPDIR)/t_api_dhcp.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$(top_srcdir)/tests/t_api_dhcp.c' object='t_api_dhcp.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o t_api_dhcp.obj `if test -f '$(top_srcdir)/tests/t_api_dhcp.c'; then $(CYGPATH_W) '$(top_srcdir)/tests/t_api_dhcp.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/tests/t_api_dhcp.c'; fi` + +# This directory's subdirectories are mostly independent; you can cd +# into them and run 'make' without going through this Makefile. +# To change the values of 'make' variables: instead of editing Makefiles, +# (1) if the variable is set in 'config.status', edit 'config.status' +# (which will cause the Makefiles to be regenerated when you run 'make'); +# (2) otherwise, pass the desired values on the 'make' command line. +$(am__recursive_targets): + @fail=; \ + if $(am__make_keepgoing); then \ + failcom='fail=yes'; \ + else \ + failcom='exit 1'; \ + fi; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-recursive +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + $(am__define_uniq_tagged_files); \ + 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-recursive + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + 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" +cscopelist: cscopelist-recursive + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +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 + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) +check: check-recursive +all-am: Makefile +installdirs: installdirs-recursive +installdirs-am: +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +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-recursive + +clean-am: clean-checkPROGRAMS clean-generic mostlyclean-am + +distclean: distclean-recursive + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: + +.MAKE: $(am__recursive_targets) check-am install-am install-strip + +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ + check-am clean clean-checkPROGRAMS clean-generic cscopelist-am \ + ctags ctags-am distclean distclean-compile distclean-generic \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am 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 \ + installdirs-am maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \ + ps ps-am tags tags-am uninstall uninstall-am + + +@HAVE_ATF_TRUE@check: $(ATF_TESTS) +@HAVE_ATF_TRUE@ sh ${top_srcdir}/tests/unittest.sh + +# 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/common/tests/ns_name_test.c b/common/tests/ns_name_test.c new file mode 100644 index 0000000..93ffa76 --- /dev/null +++ b/common/tests/ns_name_test.c @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2014 by Internet Systems Consortium, Inc. ("ISC") + * + * Tests the newly added functions: MRns_name_compress_list and + * MRns_name_uncompress_list. These two functions rely on most of + * the other functions in ns_name.c. If these tests pass, then the + * majority of those functions work. + * + * This is not exhaustive test of these functions, much more could be + * done. + */ +#include "config.h" +#include <atf-c.h> +#include "dhcpd.h" + +ATF_TC(MRns_name_list_funcs); + +ATF_TC_HEAD(MRns_name_list_funcs, tc) { + atf_tc_set_md_var(tc, "descr", "MRns_name list funcs test, " + "compress from text, decompress to text"); +} + +void concat_lists (const char* label, struct data_string* list1, + struct data_string* list2, const char *refbuf, size_t reflen); + +ATF_TC_BODY(MRns_name_list_funcs, tc) { + + const char text_list[] = "one.two.com,three.two.com,four.two.com"; + unsigned char comp_list[] = { + 0x03,0x6f,0x6e,0x65,0x03,0x74,0x77,0x6f,0x03,0x63,0x6f, + 0x6d,0x00,0x05,0x74,0x68,0x72,0x65,0x65,0xc0,0x04,0x04, + 0x66,0x6f,0x75,0x72,0xc0,0x04}; + unsigned char compbuf[sizeof(comp_list)]; + char textbuf[sizeof(text_list)]; + int ret; + + memset(compbuf, 0x00, sizeof(compbuf)); + + /* Compress the reference text list */ + ret = MRns_name_compress_list(text_list, sizeof(text_list), + compbuf, sizeof(compbuf)); + + /* Verify compressed length is correct */ + ATF_REQUIRE_MSG((ret == sizeof(compbuf)), "compressed len %d wrong", ret); + + /* Verify compressed content is correct */ + ATF_REQUIRE_MSG((memcmp(comp_list, compbuf, sizeof(compbuf)) == 0), + "compressed buffer content wrong"); + + /* Decompress the new compressed list */ + ret = MRns_name_uncompress_list(compbuf, ret, textbuf, sizeof(textbuf)); + + /* Verify decompressed length is correct */ + ATF_REQUIRE_MSG((ret == strlen(text_list)), + "uncompressed len %d wrong", ret); + + /* Verify decompressed content is correct */ + ATF_REQUIRE_MSG((memcmp(textbuf, text_list, sizeof(textbuf)) == 0), + "uncompressed buffer content wrong"); +} + +ATF_TC(concat_dclists); + +ATF_TC_HEAD(concat_dclists, tc) { + atf_tc_set_md_var(tc, "descr", "concat_dclists function test, " + "permutate concating empty and non-empty lists"); +} + +ATF_TC_BODY(concat_dclists, tc) { + /* Compressed list version of "booya.com" */ + const char data[] = + {0x05, 0x62, 0x6f, 0x6f, 0x79, 0x61, 0x03, 0x63, 0x6f, 0x6d, 0x00 }; + + /* Concatenation of data with itself */ + const char data2[] = + {0x05, 0x62, 0x6f, 0x6f, 0x79, 0x61, 0x03, 0x63, 0x6f, 0x6d, 0x00, + 0xc0, 0x00 }; + + struct data_string nonempty; + struct data_string empty; + + /* Make a non-empty compressed list from data[] */ + nonempty.len = sizeof(data); + buffer_allocate(&(nonempty.buffer), nonempty.len, MDL); + memcpy(nonempty.buffer->data, data, nonempty.len); + nonempty.data = nonempty.buffer->data; + + /* Permutate NULL with non-empty list */ + concat_lists("null + null", NULL, NULL, "", 1); + concat_lists("null + nonempty", NULL, &nonempty, data, sizeof(data)); + concat_lists("nonempty + null", &nonempty, NULL, data, sizeof(data)); + + /* Permutate zeroed-out list with non-empty list */ + memset (&empty, 0x00, sizeof(struct data_string)); + concat_lists("zero-list + zero-list", &empty, &empty, "", 1); + concat_lists("zero-list + nonempty", &empty, &nonempty, data, sizeof(data)); + concat_lists("nonempty + zero-list", &nonempty, &empty, data, sizeof(data)); + + /* Create an empty list which is a buffer with 1 null in it */ + /* Make sure those work the same as zeroed out data_strings */ + buffer_allocate (&empty.buffer, 1, MDL); + empty.len = 1; + empty.data = empty.buffer->data; + + /* Permutate with empty list */ + concat_lists("empty + empty", &empty, &empty, "", 1); + concat_lists("empty + nonempty", &empty, &nonempty, data, sizeof(data)); + concat_lists("nonempty + empty", &nonempty, &empty, data, sizeof(data)); + + /* Permutate with list len of 0 */ + empty.len = 0; + concat_lists("zero-len + zero-len", &empty, &empty, "", 1); + concat_lists("zero-len + nonempty", &empty, &nonempty, data, sizeof(data)); + concat_lists("nonempty + zero-len", &nonempty, &empty, data, sizeof(data)); + + /* Lastly, make sure two non-empty lists concat correctly */ + concat_lists("nonempty + nonempty", &nonempty, &nonempty, + data2, sizeof(data2)); + + data_string_forget(&empty, MDL); + data_string_forget(&nonempty, MDL); +} + +/* Helper function which tests concatenating two compressed lists +* +* \param label text to print in error message +* \param list1 data_string containing first list +* \param list2 data_string containing second list +* \param refbuf buffer containing the expected concatentated data +* \param reflen length of the expected data +*/ +void concat_lists (const char* label, struct data_string* list1, + struct data_string* list2, const char *refbuf, size_t reflen) +{ + struct data_string result; + int rc; + + memset (&result, 0x00, sizeof(struct data_string)); + rc = concat_dclists (&result, list1, list2); + ATF_REQUIRE_MSG((rc >= 0), "%s concat_dclists call failed %d", + label, rc); + + ATF_REQUIRE_MSG(result.len == reflen, "%s result len: %d incorrect", + label, result.len); + + if (refbuf != NULL) { + ATF_REQUIRE_MSG((memcmp(result.data, refbuf, reflen) == 0), + "%s content is incorrect", label); + } + + data_string_forget(&result, MDL); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, MRns_name_list_funcs); + ATF_TP_ADD_TC(tp, concat_dclists); + + return (atf_no_error()); +} diff --git a/common/tests/test_alloc.c b/common/tests/test_alloc.c new file mode 100644 index 0000000..9e08213 --- /dev/null +++ b/common/tests/test_alloc.c @@ -0,0 +1,501 @@ +/* + * Copyright (c) 2007,2009-2014 by Internet Systems Consortium, Inc. ("ISC") + * + * We test the functions provided in alloc.c here. These are very + * basic functions, and it is very important that they work correctly. + * + * You can see two different styles of testing: + * + * - In the first, we have a single test for each function that tests + * all of the possible ways it can operate. (This is the case for + * the buffer tests.) + * + * - In the second, we have a separate test for each of the ways a + * function can operate. (This is the case for the data_string + * tests.) + * + * The advantage of a single test per function is that you have fewer + * tests, and less duplicated and extra code. The advantage of having + * a separate test is that each test is simpler. Plus if you need to + * allow certain tests to fail for some reason (known bugs that are + * hard to fix for example), then + */ + +/** @TODO: dmalloc() test */ + +#include "config.h" +#include <atf-c.h> +#include "dhcpd.h" + +static const char* checkString (struct data_string* ds, const char *src); + +ATF_TC(buffer_allocate); + +ATF_TC_HEAD(buffer_allocate, tc) { + atf_tc_set_md_var(tc, "descr", "buffer_allocate basic test"); +} + +ATF_TC_BODY(buffer_allocate, tc) { + struct buffer *buf = 0; + + /* + * Check a 0-length buffer. + */ + buf = NULL; + if (!buffer_allocate(&buf, 0, MDL)) { + atf_tc_fail("failed on 0-len buffer"); + } + if (!buffer_dereference(&buf, MDL)) { + atf_tc_fail("buffer_dereference() failed"); + } + if (buf != NULL) { + atf_tc_fail("buffer_dereference() did not NULL-out buffer"); + } + + /* + * Check an actual buffer. + */ + buf = NULL; + if (!buffer_allocate(&buf, 100, MDL)) { + atf_tc_fail("failed on allocate 100 bytes\n"); + } + if (!buffer_dereference(&buf, MDL)) { + atf_tc_fail("buffer_dereference() failed"); + } + if (buf != NULL) { + atf_tc_fail("buffer_dereference() did not NULL-out buffer"); + } + + /* + * Okay, we're happy. + */ + atf_tc_pass(); +} + +ATF_TC(buffer_reference); + +ATF_TC_HEAD(buffer_reference, tc) { + atf_tc_set_md_var(tc, "descr", "buffer_reference basic test"); +} + +ATF_TC_BODY(buffer_reference, tc) { + + struct buffer *a, *b; + + /* + * Create a buffer. + */ + a = NULL; + if (!buffer_allocate(&a, 100, MDL)) { + atf_tc_fail("failed on allocate 100 bytes"); + } + + /** + * Confirm buffer_reference() doesn't work if we pass in NULL. + * + * @TODO: we should confirm we get an error message here. + */ + if (buffer_reference(NULL, a, MDL)) { + atf_tc_fail("succeeded on an error input"); + } + + /** + * @TODO: we should confirm we get an error message if we pass + * a non-NULL target. + */ + + /* + * Confirm we work under normal circumstances. + */ + b = NULL; + if (!buffer_reference(&b, a, MDL)) { + atf_tc_fail("buffer_reference() failed"); + } + + if (b != a) { + atf_tc_fail("incorrect pointer returned"); + } + + if (b->refcnt != 2) { + atf_tc_fail("incorrect refcnt"); + } + + /* + * Clean up. + */ + if (!buffer_dereference(&b, MDL)) { + atf_tc_fail("buffer_dereference() failed"); + } + if (!buffer_dereference(&a, MDL)) { + atf_tc_fail("buffer_dereference() failed"); + } + +} + + +ATF_TC(buffer_dereference); + +ATF_TC_HEAD(buffer_dereference, tc) { + atf_tc_set_md_var(tc, "descr", "buffer_dereference basic test"); +} + +ATF_TC_BODY(buffer_dereference, tc) { + struct buffer *a, *b; + + /** + * Confirm buffer_dereference() doesn't work if we pass in NULL. + * + * TODO: we should confirm we get an error message here. + */ + if (buffer_dereference(NULL, MDL)) { + atf_tc_fail("succeeded on an error input"); + } + + /** + * Confirm buffer_dereference() doesn't work if we pass in + * a pointer to NULL. + * + * @TODO: we should confirm we get an error message here. + */ + a = NULL; + if (buffer_dereference(&a, MDL)) { + atf_tc_fail("succeeded on an error input"); + } + + /* + * Confirm we work under normal circumstances. + */ + a = NULL; + if (!buffer_allocate(&a, 100, MDL)) { + atf_tc_fail("failed on allocate"); + } + if (!buffer_dereference(&a, MDL)) { + atf_tc_fail("buffer_dereference() failed"); + } + if (a != NULL) { + atf_tc_fail("non-null buffer after buffer_dereference()"); + } + + /** + * Confirm we get an error from negative refcnt. + * + * @TODO: we should confirm we get an error message here. + */ + a = NULL; + if (!buffer_allocate(&a, 100, MDL)) { + atf_tc_fail("failed on allocate"); + } + b = NULL; + if (!buffer_reference(&b, a, MDL)) { + atf_tc_fail("buffer_reference() failed"); + } + a->refcnt = 0; /* purposely set to invalid value */ + if (buffer_dereference(&a, MDL)) { + atf_tc_fail("buffer_dereference() succeeded on error input"); + } + a->refcnt = 2; + if (!buffer_dereference(&b, MDL)) { + atf_tc_fail("buffer_dereference() failed"); + } + if (!buffer_dereference(&a, MDL)) { + atf_tc_fail("buffer_dereference() failed"); + } +} + +ATF_TC(data_string_forget); + +ATF_TC_HEAD(data_string_forget, tc) { + atf_tc_set_md_var(tc, "descr", "data_string_forget basic test"); +} + +ATF_TC_BODY(data_string_forget, tc) { + struct buffer *buf; + struct data_string a; + const char *str = "Lorem ipsum dolor sit amet turpis duis."; + + /* + * Create the string we want to forget. + */ + memset(&a, 0, sizeof(a)); + a.len = strlen(str); + buf = NULL; + if (!buffer_allocate(&buf, a.len, MDL)) { + atf_tc_fail("out of memory"); + } + if (!buffer_reference(&a.buffer, buf, MDL)) { + atf_tc_fail("buffer_reference() failed"); + } + a.data = a.buffer->data; + memcpy(a.buffer->data, str, a.len); + + /* + * Forget and confirm we've forgotten. + */ + data_string_forget(&a, MDL); + + if (a.len != 0) { + atf_tc_fail("incorrect length"); + } + + if (a.data != NULL) { + atf_tc_fail("incorrect data"); + } + if (a.terminated) { + atf_tc_fail("incorrect terminated"); + } + if (a.buffer != NULL) { + atf_tc_fail("incorrect buffer"); + } + if (buf->refcnt != 1) { + atf_tc_fail("too many references to buf"); + } + + /* + * Clean up buffer. + */ + if (!buffer_dereference(&buf, MDL)) { + atf_tc_fail("buffer_reference() failed"); + } +} + +ATF_TC(data_string_forget_nobuf); + +ATF_TC_HEAD(data_string_forget_nobuf, tc) { + atf_tc_set_md_var(tc, "descr", "data_string_forget test, " + "data_string without buffer"); +} + +ATF_TC_BODY(data_string_forget_nobuf, tc) { + struct data_string a; + const char *str = "Lorem ipsum dolor sit amet massa nunc."; + + /* + * Create the string we want to forget. + */ + memset(&a, 0, sizeof(a)); + a.len = strlen(str); + a.data = (const unsigned char *)str; + a.terminated = 1; + + /* + * Forget and confirm we've forgotten. + */ + data_string_forget(&a, MDL); + + if (a.len != 0) { + atf_tc_fail("incorrect length"); + } + if (a.data != NULL) { + atf_tc_fail("incorrect data"); + } + if (a.terminated) { + atf_tc_fail("incorrect terminated"); + } + if (a.buffer != NULL) { + atf_tc_fail("incorrect buffer"); + } +} + +ATF_TC(data_string_copy); + +ATF_TC_HEAD(data_string_copy, tc) { + atf_tc_set_md_var(tc, "descr", "data_string_copy basic test"); +} + +ATF_TC_BODY(data_string_copy, tc) { + struct data_string a, b; + const char *str = "Lorem ipsum dolor sit amet orci aliquam."; + + /* + * Create the string we want to copy. + */ + memset(&a, 0, sizeof(a)); + a.len = strlen(str); + if (!buffer_allocate(&a.buffer, a.len, MDL)) { + atf_tc_fail("out of memory"); + } + a.data = a.buffer->data; + memcpy(a.buffer->data, str, a.len); + + /* + * Copy the string, and confirm it works. + */ + memset(&b, 0, sizeof(b)); + data_string_copy(&b, &a, MDL); + + if (b.len != a.len) { + atf_tc_fail("incorrect length"); + } + if (b.data != a.data) { + atf_tc_fail("incorrect data"); + } + if (b.terminated != a.terminated) { + atf_tc_fail("incorrect terminated"); + } + if (b.buffer != a.buffer) { + atf_tc_fail("incorrect buffer"); + } + + /* + * Clean up. + */ + data_string_forget(&b, MDL); + data_string_forget(&a, MDL); +} + +ATF_TC(data_string_copy_nobuf); + +ATF_TC_HEAD(data_string_copy_nobuf, tc) { + atf_tc_set_md_var(tc, "descr", "data_string_copy test, " + "data_string without buffer"); +} + +ATF_TC_BODY(data_string_copy_nobuf, tc) { + struct data_string a, b; + const char *str = "Lorem ipsum dolor sit amet cras amet."; + + /* + * Create the string we want to copy. + */ + memset(&a, 0, sizeof(a)); + a.len = strlen(str); + a.data = (const unsigned char *)str; + a.terminated = 1; + + /* + * Copy the string, and confirm it works. + */ + memset(&b, 0, sizeof(b)); + data_string_copy(&b, &a, MDL); + + if (b.len != a.len) { + atf_tc_fail("incorrect length"); + } + if (b.data != a.data) { + atf_tc_fail("incorrect data"); + } + if (b.terminated != a.terminated) { + atf_tc_fail("incorrect terminated"); + } + if (b.buffer != a.buffer) { + atf_tc_fail("incorrect buffer"); + } + + /* + * Clean up. + */ + data_string_forget(&b, MDL); + data_string_forget(&a, MDL); + +} + + +ATF_TC(data_string_new); + +ATF_TC_HEAD(data_string_new, tc) { + atf_tc_set_md_var(tc, "descr", "data_string_new test, " + "exercises data_string_new function"); +} + +ATF_TC_BODY(data_string_new, tc) { + struct data_string new_string; + const char *src = "Really? Latin? ... geeks"; + int len_arg = 0; + const char *error; + + /* Case 1: Call with an invalid data_string pointer, should fail */ + if (data_string_new(NULL, src, len_arg, MDL)) { + atf_tc_fail("case 1: call should have failed"); + } + + /* Case 2: Passing in NULL src should fail */ + if (data_string_new(&new_string, NULL, 10, MDL)) { + atf_tc_fail("case 2: did not return success"); + } + + /* Case 3: Call with valid params, length includes NULL */ + len_arg = strlen(src) + 1; + if (data_string_new(&new_string, src, len_arg, MDL) == 0) { + atf_tc_fail("case 3: did not return success"); + } + + error = checkString(&new_string, src); + ATF_REQUIRE_MSG((error == NULL), "case 3: %s", error); + data_string_forget(&new_string, MDL); + + + /* Case 4: Call with valid params, length does not include NULL */ + len_arg = 7; + if (data_string_new(&new_string, src, len_arg, MDL) == 0) { + atf_tc_fail("case 4: did not return success"); + } + + error = checkString(&new_string, "Really?"); + ATF_REQUIRE_MSG((error == NULL), "case 4: %s", error); + data_string_forget(&new_string, MDL); + + + /* Case 5: Call with valid params, source string is "" */ + len_arg = 0; + if (data_string_new(&new_string, "", len_arg, MDL) == 0) { + atf_tc_fail("case 5: did not return success"); + } + + error = checkString(&new_string, ""); + ATF_REQUIRE_MSG((error == NULL), "case 4: %s", error); + data_string_forget(&new_string, MDL); + + +} + +/* Helper function which tests validity of a data_string +* +* Verifies that the given data_string contains a null-terminated string +* equal to a given string. +* +* \param string data_string to test +* \param src text content string should contain +* \return returns NULL if data_string is validate or an error message +* describing why it is invalid +*/ +const char* checkString (struct data_string* string, + const char* src) { + int src_len = strlen(src); + + if (string->buffer == NULL) { + return ("buffer is NULL"); + } + + if (string->data != string->buffer->data) { + return ("data not set to buffer->data"); + } + + if (string->len != src_len) { + return ("len is wrong "); + } + + if (string->terminated != 1) { + return ("terminated flag not set"); + } + + if (memcmp(string->data, src, src_len + 1)) { + return ("data content wrong"); + } + + return (NULL); +} + + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, buffer_allocate); + ATF_TP_ADD_TC(tp, buffer_reference); + ATF_TP_ADD_TC(tp, buffer_dereference); + ATF_TP_ADD_TC(tp, data_string_forget); + ATF_TP_ADD_TC(tp, data_string_forget_nobuf); + ATF_TP_ADD_TC(tp, data_string_copy); + ATF_TP_ADD_TC(tp, data_string_copy_nobuf); + ATF_TP_ADD_TC(tp, data_string_new); + + return (atf_no_error()); +} |
