2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-22 09:57:20 +00:00

Unit test framework now added.

See RT ticket #17223 for more.
This commit is contained in:
Shane Kerr 2007-11-16 11:04:12 +00:00
parent b9ced02868
commit 6e999c3c8a
27 changed files with 6246 additions and 3404 deletions

View File

@ -15,35 +15,9 @@ EXTRA_DIST = RELNOTES \
doc/References.txt doc/References.xml doc/api+protocol \ doc/References.txt doc/References.xml doc/api+protocol \
doc/ja_JP.eucJP/dhclient-script.8 doc/ja_JP.eucJP/dhclient.8 \ doc/ja_JP.eucJP/dhclient-script.8 doc/ja_JP.eucJP/dhclient.8 \
doc/ja_JP.eucJP/dhclient.conf.5 doc/ja_JP.eucJP/dhclient.leases.5 \ doc/ja_JP.eucJP/dhclient.conf.5 doc/ja_JP.eucJP/dhclient.leases.5 \
doc/ja_JP.eucJP/dhcp-eval.5 doc/ja_JP.eucJP/dhcp-options.5 \ doc/ja_JP.eucJP/dhcp-eval.5 doc/ja_JP.eucJP/dhcp-options.5
tests/failover/dhcp-1.cf tests/failover/dhcp-2.cf \
tests/failover/new-failover \
tests/DHCPv6/000-badmsgtype.pl \
tests/DHCPv6/010-solicit-noclientid.pl \
tests/DHCPv6/011-solicit-serverid.pl \
tests/DHCPv6/020-advertise-mcast.pl \
tests/DHCPv6/030-request-noclientid.pl \
tests/DHCPv6/031-request-noserverid.pl \
tests/DHCPv6/032-request-badduid.pl \
tests/DHCPv6/110-information-request-ia_na.pl \
tests/DHCPv6/111-information-request-ia_ta.pl \
tests/DHCPv6/112-badduid.pl \
tests/DHCPv6/210-solicit-nohost.pl \
tests/DHCPv6/211-solicit-opt-in-na.pl \
tests/DHCPv6/212-solicit-opt-in-na-norapidcommit.pl \
tests/DHCPv6/280-release-nohost.pl \
tests/DHCPv6/281-release-bad-address.pl \
tests/DHCPv6/282-release-no-address.pl \
tests/DHCPv6/283-release.pl \
tests/DHCPv6/290-decline-nohost.pl \
tests/DHCPv6/291-decline-bad-address.pl \
tests/DHCPv6/292-decline-no-address.pl \
tests/DHCPv6/293-decline.pl \
tests/DHCPv6/README tests/DHCPv6/dhcp_client.pm \
tests/DHCPv6/stubcli-opt-in-na.pl tests/DHCPv6/stubcli.pl \
tests/DHCPv6/test-a.conf tests/DHCPv6/test-b.conf
SUBDIRS = includes common minires dst omapip client dhcpctl relay server SUBDIRS = includes tests common minires dst omapip client dhcpctl relay server
nobase_include_HEADERS = dhcpctl/dhcpctl.h nobase_include_HEADERS = dhcpctl/dhcpctl.h

View File

@ -37,7 +37,7 @@ POST_UNINSTALL = :
subdir = . subdir = .
DIST_COMMON = README $(am__configure_deps) $(nobase_include_HEADERS) \ DIST_COMMON = README $(am__configure_deps) $(nobase_include_HEADERS) \
$(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(top_srcdir)/configure depcomp install-sh missing $(top_srcdir)/configure TODO depcomp install-sh missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__aclocal_m4_deps = $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
@ -99,6 +99,7 @@ ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@ ECHO_T = @ECHO_T@
EGREP = @EGREP@ EGREP = @EGREP@
EXEEXT = @EXEEXT@ EXEEXT = @EXEEXT@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -122,8 +123,6 @@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
VERSION = @VERSION@ VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@ ac_ct_CC = @ac_ct_CC@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@ am__include = @am__include@
@ -135,19 +134,26 @@ bindir = @bindir@
build_alias = @build_alias@ build_alias = @build_alias@
byte_order = @byte_order@ byte_order = @byte_order@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
host_alias = @host_alias@ host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@ includedir = @includedir@
infodir = @infodir@ infodir = @infodir@
install_sh = @install_sh@ install_sh = @install_sh@
libdir = @libdir@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
mkdir_p = @mkdir_p@ mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@ oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@
@ -165,35 +171,9 @@ EXTRA_DIST = RELNOTES \
doc/References.txt doc/References.xml doc/api+protocol \ doc/References.txt doc/References.xml doc/api+protocol \
doc/ja_JP.eucJP/dhclient-script.8 doc/ja_JP.eucJP/dhclient.8 \ doc/ja_JP.eucJP/dhclient-script.8 doc/ja_JP.eucJP/dhclient.8 \
doc/ja_JP.eucJP/dhclient.conf.5 doc/ja_JP.eucJP/dhclient.leases.5 \ doc/ja_JP.eucJP/dhclient.conf.5 doc/ja_JP.eucJP/dhclient.leases.5 \
doc/ja_JP.eucJP/dhcp-eval.5 doc/ja_JP.eucJP/dhcp-options.5 \ doc/ja_JP.eucJP/dhcp-eval.5 doc/ja_JP.eucJP/dhcp-options.5
tests/failover/dhcp-1.cf tests/failover/dhcp-2.cf \
tests/failover/new-failover \
tests/DHCPv6/000-badmsgtype.pl \
tests/DHCPv6/010-solicit-noclientid.pl \
tests/DHCPv6/011-solicit-serverid.pl \
tests/DHCPv6/020-advertise-mcast.pl \
tests/DHCPv6/030-request-noclientid.pl \
tests/DHCPv6/031-request-noserverid.pl \
tests/DHCPv6/032-request-badduid.pl \
tests/DHCPv6/110-information-request-ia_na.pl \
tests/DHCPv6/111-information-request-ia_ta.pl \
tests/DHCPv6/112-badduid.pl \
tests/DHCPv6/210-solicit-nohost.pl \
tests/DHCPv6/211-solicit-opt-in-na.pl \
tests/DHCPv6/212-solicit-opt-in-na-norapidcommit.pl \
tests/DHCPv6/280-release-nohost.pl \
tests/DHCPv6/281-release-bad-address.pl \
tests/DHCPv6/282-release-no-address.pl \
tests/DHCPv6/283-release.pl \
tests/DHCPv6/290-decline-nohost.pl \
tests/DHCPv6/291-decline-bad-address.pl \
tests/DHCPv6/292-decline-no-address.pl \
tests/DHCPv6/293-decline.pl \
tests/DHCPv6/README tests/DHCPv6/dhcp_client.pm \
tests/DHCPv6/stubcli-opt-in-na.pl tests/DHCPv6/stubcli.pl \
tests/DHCPv6/test-a.conf tests/DHCPv6/test-b.conf
SUBDIRS = includes common minires dst omapip client dhcpctl relay server SUBDIRS = includes tests common minires dst omapip client dhcpctl relay server
nobase_include_HEADERS = dhcpctl/dhcpctl.h nobase_include_HEADERS = dhcpctl/dhcpctl.h
all: all-recursive all: all-recursive
@ -378,7 +358,7 @@ distclean-tags:
distdir: $(DISTFILES) distdir: $(DISTFILES)
$(am__remove_distdir) $(am__remove_distdir)
mkdir $(distdir) mkdir $(distdir)
$(mkdir_p) $(distdir)/contrib $(distdir)/contrib/ms2isc $(distdir)/dhcpctl $(distdir)/doc $(distdir)/doc/ja_JP.eucJP $(distdir)/tests/DHCPv6 $(distdir)/tests/failover $(mkdir_p) $(distdir)/contrib $(distdir)/contrib/ms2isc $(distdir)/dhcpctl $(distdir)/doc $(distdir)/doc/ja_JP.eucJP
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \ list='$(DISTFILES)'; for file in $$list; do \

View File

@ -100,6 +100,7 @@ ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@ ECHO_T = @ECHO_T@
EGREP = @EGREP@ EGREP = @EGREP@
EXEEXT = @EXEEXT@ EXEEXT = @EXEEXT@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -123,8 +124,6 @@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
VERSION = @VERSION@ VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@ ac_ct_CC = @ac_ct_CC@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@ am__include = @am__include@
@ -136,19 +135,26 @@ bindir = @bindir@
build_alias = @build_alias@ build_alias = @build_alias@
byte_order = @byte_order@ byte_order = @byte_order@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
host_alias = @host_alias@ host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@ includedir = @includedir@
infodir = @infodir@ infodir = @infodir@
install_sh = @install_sh@ install_sh = @install_sh@
libdir = @libdir@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
mkdir_p = @mkdir_p@ mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@ oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@

View File

@ -9,3 +9,4 @@ libdhcp_a_SOURCES = alloc.c bpf.c comapi.c conflex.c ctrace.c discover.c \
man_MANS = dhcp-eval.5 dhcp-options.5 man_MANS = dhcp-eval.5 dhcp-options.5
EXTRA_DIST = $(man_MANS) EXTRA_DIST = $(man_MANS)
SUBDIRS = tests

View File

@ -67,12 +67,19 @@ CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(libdhcp_a_SOURCES) SOURCES = $(libdhcp_a_SOURCES)
DIST_SOURCES = $(libdhcp_a_SOURCES) DIST_SOURCES = $(libdhcp_a_SOURCES)
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
html-recursive info-recursive install-data-recursive \
install-exec-recursive install-info-recursive \
install-recursive installcheck-recursive installdirs-recursive \
pdf-recursive ps-recursive uninstall-info-recursive \
uninstall-recursive
man5dir = $(mandir)/man5 man5dir = $(mandir)/man5
am__installdirs = "$(DESTDIR)$(man5dir)" am__installdirs = "$(DESTDIR)$(man5dir)"
NROFF = nroff NROFF = nroff
MANS = $(man_MANS) MANS = $(man_MANS)
ETAGS = etags ETAGS = etags
CTAGS = ctags CTAGS = ctags
DIST_SUBDIRS = $(SUBDIRS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@ ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@ AMDEP_FALSE = @AMDEP_FALSE@
@ -95,6 +102,7 @@ ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@ ECHO_T = @ECHO_T@
EGREP = @EGREP@ EGREP = @EGREP@
EXEEXT = @EXEEXT@ EXEEXT = @EXEEXT@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -118,8 +126,6 @@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
VERSION = @VERSION@ VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@ ac_ct_CC = @ac_ct_CC@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@ am__include = @am__include@
@ -131,19 +137,26 @@ bindir = @bindir@
build_alias = @build_alias@ build_alias = @build_alias@
byte_order = @byte_order@ byte_order = @byte_order@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
host_alias = @host_alias@ host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@ includedir = @includedir@
infodir = @infodir@ infodir = @infodir@
install_sh = @install_sh@ install_sh = @install_sh@
libdir = @libdir@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
mkdir_p = @mkdir_p@ mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@ oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@
@ -158,7 +171,8 @@ libdhcp_a_SOURCES = alloc.c bpf.c comapi.c conflex.c ctrace.c discover.c \
man_MANS = dhcp-eval.5 dhcp-options.5 man_MANS = dhcp-eval.5 dhcp-options.5
EXTRA_DIST = $(man_MANS) EXTRA_DIST = $(man_MANS)
all: all-am SUBDIRS = tests
all: all-recursive
.SUFFIXES: .SUFFIXES:
.SUFFIXES: .c .o .obj .SUFFIXES: .c .o .obj
@ -295,6 +309,77 @@ uninstall-man5:
rm -f "$(DESTDIR)$(man5dir)/$$inst"; \ rm -f "$(DESTDIR)$(man5dir)/$$inst"; \
done done
# 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.
$(RECURSIVE_TARGETS):
@failcom='exit 1'; \
for f in x $$MAKEFLAGS; do \
case $$f in \
*=* | --[!k]*);; \
*k*) failcom='fail=yes';; \
esac; \
done; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; 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; \
(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"
mostlyclean-recursive clean-recursive distclean-recursive \
maintainer-clean-recursive:
@failcom='exit 1'; \
for f in x $$MAKEFLAGS; do \
case $$f in \
*=* | --[!k]*);; \
*k*) failcom='fail=yes';; \
esac; \
done; \
dot_seen=no; \
case "$@" in \
distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
*) list='$(SUBDIRS)' ;; \
esac; \
rev=''; for subdir in $$list; do \
if test "$$subdir" = "."; then :; else \
rev="$$subdir $$rev"; \
fi; \
done; \
rev="$$rev ."; \
target=`echo $@ | sed s/-recursive//`; \
for subdir in $$rev; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| eval $$failcom; \
done && test -z "$$fail"
tags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
done
ctags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \ unique=`for i in $$list; do \
@ -305,10 +390,23 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
mkid -fID $$unique mkid -fID $$unique
tags: TAGS tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP) $(TAGS_FILES) $(LISP)
tags=; \ tags=; \
here=`pwd`; \ 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 || \
tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
fi; \
done; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \ unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
@ -321,7 +419,7 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$$tags $$unique; \ $$tags $$unique; \
fi fi
ctags: CTAGS ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP) $(TAGS_FILES) $(LISP)
tags=; \ tags=; \
here=`pwd`; \ here=`pwd`; \
@ -370,22 +468,38 @@ distdir: $(DISTFILES)
|| exit 1; \ || exit 1; \
fi; \ fi; \
done done
list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test -d "$(distdir)/$$subdir" \
|| $(mkdir_p) "$(distdir)/$$subdir" \
|| exit 1; \
distdir=`$(am__cd) $(distdir) && pwd`; \
top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
(cd $$subdir && \
$(MAKE) $(AM_MAKEFLAGS) \
top_distdir="$$top_distdir" \
distdir="$$distdir/$$subdir" \
distdir) \
|| exit 1; \
fi; \
done
check-am: all-am check-am: all-am
check: check-am check: check-recursive
all-am: Makefile $(LIBRARIES) $(MANS) all-am: Makefile $(LIBRARIES) $(MANS)
installdirs: installdirs: installdirs-recursive
installdirs-am:
for dir in "$(DESTDIR)$(man5dir)"; do \ for dir in "$(DESTDIR)$(man5dir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \ test -z "$$dir" || $(mkdir_p) "$$dir"; \
done done
install: install-am install: install-recursive
install-exec: install-exec-am install-exec: install-exec-recursive
install-data: install-data-am install-data: install-data-recursive
uninstall: uninstall-am uninstall: uninstall-recursive
install-am: all-am install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am installcheck: installcheck-recursive
install-strip: install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
@ -401,23 +515,23 @@ distclean-generic:
maintainer-clean-generic: maintainer-clean-generic:
@echo "This command is intended for maintainers to use" @echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild." @echo "it deletes files that may require special tools to rebuild."
clean: clean-am clean: clean-recursive
clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am
distclean: distclean-am distclean: distclean-recursive
-rm -rf ./$(DEPDIR) -rm -rf ./$(DEPDIR)
-rm -f Makefile -rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \ distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags distclean-tags
dvi: dvi-am dvi: dvi-recursive
dvi-am: dvi-am:
html: html-am html: html-recursive
info: info-am info: info-recursive
info-am: info-am:
@ -425,43 +539,48 @@ install-data-am: install-man
install-exec-am: install-exec-am:
install-info: install-info-am install-info: install-info-recursive
install-man: install-man5 install-man: install-man5
installcheck-am: installcheck-am:
maintainer-clean: maintainer-clean-am maintainer-clean: maintainer-clean-recursive
-rm -rf ./$(DEPDIR) -rm -rf ./$(DEPDIR)
-rm -f Makefile -rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am mostlyclean: mostlyclean-recursive
mostlyclean-am: mostlyclean-compile mostlyclean-generic mostlyclean-am: mostlyclean-compile mostlyclean-generic
pdf: pdf-am pdf: pdf-recursive
pdf-am: pdf-am:
ps: ps-am ps: ps-recursive
ps-am: ps-am:
uninstall-am: uninstall-info-am uninstall-man uninstall-am: uninstall-info-am uninstall-man
uninstall-info: uninstall-info-recursive
uninstall-man: uninstall-man5 uninstall-man: uninstall-man5
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ .PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \
clean-noinstLIBRARIES ctags distclean distclean-compile \ clean clean-generic clean-noinstLIBRARIES clean-recursive \
distclean-generic distclean-tags distdir dvi dvi-am html \ ctags ctags-recursive distclean distclean-compile \
html-am info info-am install install-am install-data \ distclean-generic distclean-recursive distclean-tags distdir \
install-data-am install-exec install-exec-am install-info \ dvi dvi-am html html-am info info-am install install-am \
install-info-am install-man install-man5 install-strip \ install-data install-data-am install-exec install-exec-am \
installcheck installcheck-am installdirs maintainer-clean \ install-info install-info-am install-man install-man5 \
maintainer-clean-generic mostlyclean mostlyclean-compile \ install-strip installcheck installcheck-am installdirs \
mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ installdirs-am maintainer-clean maintainer-clean-generic \
uninstall-am uninstall-info-am uninstall-man uninstall-man5 maintainer-clean-recursive mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-recursive pdf pdf-am ps ps-am \
tags tags-recursive uninstall uninstall-am uninstall-info-am \
uninstall-man uninstall-man5
# Tell versions [3.59,3.63) of GNU make to not export all variables. # 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. # Otherwise a system limit (for SysV at least) may be exceeded.

6758
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -219,6 +219,7 @@ AC_OUTPUT([
Makefile Makefile
client/Makefile client/Makefile
common/Makefile common/Makefile
common/tests/Makefile
dhcpctl/Makefile dhcpctl/Makefile
dst/Makefile dst/Makefile
includes/Makefile includes/Makefile
@ -226,5 +227,6 @@ AC_OUTPUT([
omapip/Makefile omapip/Makefile
relay/Makefile relay/Makefile
server/Makefile server/Makefile
tests/Makefile
]) ])

View File

@ -111,6 +111,7 @@ ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@ ECHO_T = @ECHO_T@
EGREP = @EGREP@ EGREP = @EGREP@
EXEEXT = @EXEEXT@ EXEEXT = @EXEEXT@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -134,8 +135,6 @@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
VERSION = @VERSION@ VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@ ac_ct_CC = @ac_ct_CC@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@ am__include = @am__include@
@ -147,19 +146,26 @@ bindir = @bindir@
build_alias = @build_alias@ build_alias = @build_alias@
byte_order = @byte_order@ byte_order = @byte_order@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
host_alias = @host_alias@ host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@ includedir = @includedir@
infodir = @infodir@ infodir = @infodir@
install_sh = @install_sh@ install_sh = @install_sh@
libdir = @libdir@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
mkdir_p = @mkdir_p@ mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@ oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@

View File

@ -93,6 +93,7 @@ ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@ ECHO_T = @ECHO_T@
EGREP = @EGREP@ EGREP = @EGREP@
EXEEXT = @EXEEXT@ EXEEXT = @EXEEXT@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -116,8 +117,6 @@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
VERSION = @VERSION@ VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@ ac_ct_CC = @ac_ct_CC@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@ am__include = @am__include@
@ -129,19 +128,26 @@ bindir = @bindir@
build_alias = @build_alias@ build_alias = @build_alias@
byte_order = @byte_order@ byte_order = @byte_order@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
host_alias = @host_alias@ host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@ includedir = @includedir@
infodir = @infodir@ infodir = @infodir@
install_sh = @install_sh@ install_sh = @install_sh@
libdir = @libdir@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
mkdir_p = @mkdir_p@ mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@ oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@

View File

@ -79,6 +79,7 @@ ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@ ECHO_T = @ECHO_T@
EGREP = @EGREP@ EGREP = @EGREP@
EXEEXT = @EXEEXT@ EXEEXT = @EXEEXT@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -102,8 +103,6 @@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
VERSION = @VERSION@ VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@ ac_ct_CC = @ac_ct_CC@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@ am__include = @am__include@
@ -115,19 +114,26 @@ bindir = @bindir@
build_alias = @build_alias@ build_alias = @build_alias@
byte_order = @byte_order@ byte_order = @byte_order@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
host_alias = @host_alias@ host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@ includedir = @includedir@
infodir = @infodir@ infodir = @infodir@
install_sh = @install_sh@ install_sh = @install_sh@
libdir = @libdir@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
mkdir_p = @mkdir_p@ mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@ oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@

View File

@ -82,7 +82,7 @@
/* Define to the version of this package. */ /* Define to the version of this package. */
#undef PACKAGE_VERSION #undef PACKAGE_VERSION
/* The size of a `struct iaddr *', as computed by sizeof. */ /* The size of `struct iaddr *', as computed by sizeof. */
#undef SIZEOF_STRUCT_IADDR_P #undef SIZEOF_STRUCT_IADDR_P
/* Define to 1 if you have the ANSI C header files. */ /* Define to 1 if you have the ANSI C header files. */

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: commandline.h,v 1.2 2007/11/16 11:04:11 shane Exp $ */
#ifndef ISC_COMMANDLINE_H
#define ISC_COMMANDLINE_H 1
/*! \file isc/commandline.h */
#include <isc-dhcp/boolean.h>
#include <isc-dhcp/lang.h>
/*#include <isc-dhcp/platform.h>*/
/*% Index into parent argv vector. */
extern int isc_commandline_index;
/*% Character checked for validity. */
extern int isc_commandline_option;
/*% Argument associated with option. */
extern char *isc_commandline_argument;
/*% For printing error messages. */
extern char *isc_commandline_progname;
/*% Print error message. */
extern isc_boolean_t isc_commandline_errprint;
/*% Reset getopt. */
extern isc_boolean_t isc_commandline_reset;
ISC_LANG_BEGINDECLS
/*% parse command line */
int
isc_commandline_parse(int argc, char * const *argv, const char *options);
ISC_LANG_ENDDECLS
#endif /* ISC_COMMANDLINE_H */

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000, 2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: formatcheck.h,v 1.2 2007/11/16 11:04:11 shane Exp $ */
#ifndef ISC_FORMATCHECK_H
#define ISC_FORMATCHECK_H 1
/*! \file isc/formatcheck.h */
/*%
* ISC_FORMAT_PRINTF().
*
* \li fmt is the location of the format string parameter.
* \li args is the location of the first argument (or 0 for no argument checking).
*
* Note:
* \li The first parameter is 1, not 0.
*/
#ifdef __GNUC__
#define ISC_FORMAT_PRINTF(fmt, args) __attribute__((__format__(__printf__, fmt, args)))
#else
#define ISC_FORMAT_PRINTF(fmt, args)
#endif
#endif /* ISC_FORMATCHECK_H */

552
includes/isc-dhcp/mem.h Normal file
View File

@ -0,0 +1,552 @@
/*
* Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1997-2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: mem.h,v 1.2 2007/11/16 11:04:11 shane Exp $ */
#ifndef ISC_MEM_H
#define ISC_MEM_H 1
/*! \file isc/mem.h */
#include <stdio.h>
#include <isc-dhcp/lang.h>
/*#include <isc-dhcp/mutex.h>*/
/*#include <isc-dhcp/platform.h>*/
#include <isc-dhcp/types.h>
/*#include <isc-dhcp/xml.h>*/
#include <isc-dhcp/result.h>
ISC_LANG_BEGINDECLS
#define ISC_MEM_LOWATER 0
#define ISC_MEM_HIWATER 1
typedef void (*isc_mem_water_t)(void *, int);
typedef void * (*isc_memalloc_t)(void *, size_t);
typedef void (*isc_memfree_t)(void *, void *);
/*%
* Define ISC_MEM_DEBUG=1 to make all functions that free memory
* set the pointer being freed to NULL after being freed.
* This is the default; set ISC_MEM_DEBUG=0 to disable it.
*/
#ifndef ISC_MEM_DEBUG
#define ISC_MEM_DEBUG 1
#endif
/*%
* Define ISC_MEM_TRACKLINES=1 to turn on detailed tracing of memory
* allocation and freeing by file and line number.
*/
#ifndef ISC_MEM_TRACKLINES
#define ISC_MEM_TRACKLINES 1
#endif
/*%
* Define ISC_MEM_CHECKOVERRUN=1 to turn on checks for using memory outside
* the requested space. This will increase the size of each allocation.
*/
#ifndef ISC_MEM_CHECKOVERRUN
#define ISC_MEM_CHECKOVERRUN 1
#endif
/*%
* Define ISC_MEM_FILL=1 to fill each block of memory returned to the system
* with the byte string '0xbe'. This helps track down uninitialized pointers
* and the like. On freeing memory, the space is filled with '0xde' for
* the same reasons.
*/
#ifndef ISC_MEM_FILL
#define ISC_MEM_FILL 1
#endif
/*%
* Define ISC_MEMPOOL_NAMES=1 to make memory pools store a symbolic
* name so that the leaking pool can be more readily identified in
* case of a memory leak.
*/
#ifndef ISC_MEMPOOL_NAMES
#define ISC_MEMPOOL_NAMES 1
#endif
extern unsigned int isc_mem_debugging;
/*@{*/
#define ISC_MEM_DEBUGTRACE 0x00000001U
#define ISC_MEM_DEBUGRECORD 0x00000002U
#define ISC_MEM_DEBUGUSAGE 0x00000004U
#define ISC_MEM_DEBUGSIZE 0x00000008U
#define ISC_MEM_DEBUGCTX 0x00000010U
#define ISC_MEM_DEBUGALL 0x0000001FU
/*!<
* The variable isc_mem_debugging holds a set of flags for
* turning certain memory debugging options on or off at
* runtime. Its is intialized to the value ISC_MEM_DEGBUGGING,
* which is 0 by default but may be overridden at compile time.
* The following flags can be specified:
*
* \li #ISC_MEM_DEBUGTRACE
* Log each allocation and free to isc_lctx.
*
* \li #ISC_MEM_DEBUGRECORD
* Remember each allocation, and match them up on free.
* Crash if a free doesn't match an allocation.
*
* \li #ISC_MEM_DEBUGUSAGE
* If a hi_water mark is set, print the maximium inuse memory
* every time it is raised once it exceeds the hi_water mark.
*
* \li #ISC_MEM_DEBUGSIZE
* Check the size argument being passed to isc_mem_put() matches
* that passed to isc_mem_get().
*
* \li #ISC_MEM_DEBUGCTX
* Check the mctx argument being passed to isc_mem_put() matches
* that passed to isc_mem_get().
*/
/*@}*/
#if ISC_MEM_TRACKLINES
#define _ISC_MEM_FILELINE , __FILE__, __LINE__
#define _ISC_MEM_FLARG , const char *, int
#else
#define _ISC_MEM_FILELINE
#define _ISC_MEM_FLARG
#endif
/*!
* Define ISC_MEM_USE_INTERNAL_MALLOC=1 to use the internal malloc()
* implementation in preference to the system one. The internal malloc()
* is very space-efficient, and quite fast on uniprocessor systems. It
* performs poorly on multiprocessor machines.
* JT: we can overcome the performance issue on multiprocessor machines
* by carefully separating memory contexts.
*/
#ifndef ISC_MEM_USE_INTERNAL_MALLOC
#define ISC_MEM_USE_INTERNAL_MALLOC 1
#endif
/*
* Flags for isc_mem_create2()calls.
*/
#define ISC_MEMFLAG_NOLOCK 0x00000001 /* no lock is necessary */
#define ISC_MEMFLAG_INTERNAL 0x00000002 /* use internal malloc */
#if ISC_MEM_USE_INTERNAL_MALLOC
#define ISC_MEMFLAG_DEFAULT ISC_MEMFLAG_INTERNAL
#else
#define ISC_MEMFLAG_DEFAULT 0
#endif
#define isc_mem_get(c, s) isc__mem_get((c), (s) _ISC_MEM_FILELINE)
#define isc_mem_allocate(c, s) isc__mem_allocate((c), (s) _ISC_MEM_FILELINE)
#define isc_mem_strdup(c, p) isc__mem_strdup((c), (p) _ISC_MEM_FILELINE)
#define isc_mempool_get(c) isc__mempool_get((c) _ISC_MEM_FILELINE)
/*%
* isc_mem_putanddetach() is a convienence function for use where you
* have a structure with an attached memory context.
*
* Given:
*
* \code
* struct {
* ...
* isc_mem_t *mctx;
* ...
* } *ptr;
*
* isc_mem_t *mctx;
*
* isc_mem_putanddetach(&ptr->mctx, ptr, sizeof(*ptr));
* \endcode
*
* is the equivalent of:
*
* \code
* mctx = NULL;
* isc_mem_attach(ptr->mctx, &mctx);
* isc_mem_detach(&ptr->mctx);
* isc_mem_put(mctx, ptr, sizeof(*ptr));
* isc_mem_detach(&mctx);
* \endcode
*/
#if ISC_MEM_DEBUG
#define isc_mem_put(c, p, s) \
do { \
isc__mem_put((c), (p), (s) _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mem_putanddetach(c, p, s) \
do { \
isc__mem_putanddetach((c), (p), (s) _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mem_free(c, p) \
do { \
isc__mem_free((c), (p) _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mempool_put(c, p) \
do { \
isc__mempool_put((c), (p) _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#else
#define isc_mem_put(c, p, s) isc__mem_put((c), (p), (s) _ISC_MEM_FILELINE)
#define isc_mem_putanddetach(c, p, s) \
isc__mem_putanddetach((c), (p), (s) _ISC_MEM_FILELINE)
#define isc_mem_free(c, p) isc__mem_free((c), (p) _ISC_MEM_FILELINE)
#define isc_mempool_put(c, p) isc__mempool_put((c), (p) _ISC_MEM_FILELINE)
#endif
/*@{*/
isc_result_t
isc_mem_create(size_t max_size, size_t target_size,
isc_mem_t **mctxp);
isc_result_t
isc_mem_create2(size_t max_size, size_t target_size,
isc_mem_t **mctxp, unsigned int flags);
isc_result_t
isc_mem_createx(size_t max_size, size_t target_size,
isc_memalloc_t memalloc, isc_memfree_t memfree,
void *arg, isc_mem_t **mctxp);
isc_result_t
isc_mem_createx2(size_t max_size, size_t target_size,
isc_memalloc_t memalloc, isc_memfree_t memfree,
void *arg, isc_mem_t **mctxp, unsigned int flags);
/*!<
* \brief Create a memory context.
*
* 'max_size' and 'target_size' are tuning parameters. When
* ISC_MEMFLAG_INTERNAL is set, allocations smaller than 'max_size'
* will be satisfied by getting blocks of size 'target_size' from the
* system allocator and breaking them up into pieces; larger allocations
* will use the system allocator directly. If 'max_size' and/or
* 'target_size' are zero, default values will be * used. When
* ISC_MEMFLAG_INTERNAL is not set, 'target_size' is ignored.
*
* 'max_size' is also used to size the statistics arrays and the array
* used to record active memory when ISC_MEM_DEBUGRECORD is set. Settin
* 'max_size' too low can have detrimental effects on performance.
*
* A memory context created using isc_mem_createx() will obtain
* memory from the system by calling 'memalloc' and 'memfree',
* passing them the argument 'arg'. A memory context created
* using isc_mem_create() will use the standard library malloc()
* and free().
*
* If ISC_MEMFLAG_NOLOCK is set in 'flags', the corresponding memory context
* will be accessed without locking. The user who creates the context must
* ensure there be no race. Since this can be a source of bug, it is generally
* inadvisable to use this flag unless the user is very sure about the race
* condition and the access to the object is highly performance sensitive.
*
* Requires:
* mctxp != NULL && *mctxp == NULL */
/*@}*/
/*@{*/
void
isc_mem_attach(isc_mem_t *, isc_mem_t **);
void
isc_mem_detach(isc_mem_t **);
/*!<
* \brief Attach to / detach from a memory context.
*
* This is intended for applications that use multiple memory contexts
* in such a way that it is not obvious when the last allocations from
* a given context has been freed and destroying the context is safe.
*
* Most applications do not need to call these functions as they can
* simply create a single memory context at the beginning of main()
* and destroy it at the end of main(), thereby guaranteeing that it
* is not destroyed while there are outstanding allocations.
*/
/*@}*/
void
isc_mem_destroy(isc_mem_t **);
/*%<
* Destroy a memory context.
*/
isc_result_t
isc_mem_ondestroy(isc_mem_t *ctx,
isc_task_t *task,
isc_event_t **event);
/*%<
* Request to be notified with an event when a memory context has
* been successfully destroyed.
*/
void
isc_mem_stats(isc_mem_t *mctx, FILE *out);
/*%<
* Print memory usage statistics for 'mctx' on the stream 'out'.
*/
void
isc_mem_setdestroycheck(isc_mem_t *mctx,
isc_boolean_t on);
/*%<
* If 'on' is ISC_TRUE, 'mctx' will check for memory leaks when
* destroyed and abort the program if any are present.
*/
/*@{*/
void
isc_mem_setquota(isc_mem_t *, size_t);
size_t
isc_mem_getquota(isc_mem_t *);
/*%<
* Set/get the memory quota of 'mctx'. This is a hard limit
* on the amount of memory that may be allocated from mctx;
* if it is exceeded, allocations will fail.
*/
/*@}*/
size_t
isc_mem_inuse(isc_mem_t *mctx);
/*%<
* Get an estimate of the number of memory in use in 'mctx', in bytes.
* This includes quantization overhead, but does not include memory
* allocated from the system but not yet used.
*/
void
isc_mem_setwater(isc_mem_t *mctx, isc_mem_water_t water, void *water_arg,
size_t hiwater, size_t lowater);
/*%<
* Set high and low water marks for this memory context.
*
* When the memory
* usage of 'mctx' exceeds 'hiwater', '(water)(water_arg, #ISC_MEM_HIWATER)'
* will be called. When the usage drops below 'lowater', 'water' will
* again be called, this time with #ISC_MEM_LOWATER.
*
* If 'water' is NULL then 'water_arg', 'hi_water' and 'lo_water' are
* ignored and the state is reset.
*
* Requires:
*
* 'water' is not NULL.
* hi_water >= lo_water
*/
void
isc_mem_printactive(isc_mem_t *mctx, FILE *file);
/*%<
* Print to 'file' all active memory in 'mctx'.
*
* Requires ISC_MEM_DEBUGRECORD to have been set.
*/
void
isc_mem_printallactive(FILE *file);
/*%<
* Print to 'file' all active memory in all contexts.
*
* Requires ISC_MEM_DEBUGRECORD to have been set.
*/
void
isc_mem_checkdestroyed(FILE *file);
/*%<
* Check that all memory contexts have been destroyed.
* Prints out those that have not been.
* Fatally fails if there are still active contexts.
*/
/*
* Memory pools
*/
isc_result_t
isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp);
/*%<
* Create a memory pool.
*
* Requires:
*\li mctx is a valid memory context.
*\li size > 0
*\li mpctxp != NULL and *mpctxp == NULL
*
* Defaults:
*\li maxalloc = UINT_MAX
*\li freemax = 1
*\li fillcount = 1
*
* Returns:
*\li #ISC_R_NOMEMORY -- not enough memory to create pool
*\li #ISC_R_SUCCESS -- all is well.
*/
void
isc_mempool_destroy(isc_mempool_t **mpctxp);
/*%<
* Destroy a memory pool.
*
* Requires:
*\li mpctxp != NULL && *mpctxp is a valid pool.
*\li The pool has no un"put" allocations outstanding
*/
void
isc_mempool_setname(isc_mempool_t *mpctx, const char *name);
/*%<
* Associate a name with a memory pool. At most 15 characters may be used.
*
* Requires:
*\li mpctx is a valid pool.
*\li name != NULL;
*/
/*
void
isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock);
*/
/*%<
* Associate a lock with this memory pool.
*
* This lock is used when getting or putting items using this memory pool,
* and it is also used to set or get internal state via the isc_mempool_get*()
* and isc_mempool_set*() set of functions.
*
* Mutiple pools can each share a single lock. For instance, if "manager"
* type object contained pools for various sizes of events, and each of
* these pools used a common lock. Note that this lock must NEVER be used
* by other than mempool routines once it is given to a pool, since that can
* easily cause double locking.
*
* Requires:
*
*\li mpctpx is a valid pool.
*
*\li lock != NULL.
*
*\li No previous lock is assigned to this pool.
*
*\li The lock is initialized before calling this function via the normal
* means of doing that.
*/
/*
* The following functions get/set various parameters. Note that due to
* the unlocked nature of pools these are potentially random values unless
* the imposed externally provided locking protocols are followed.
*
* Also note that the quota limits will not always take immediate effect.
* For instance, setting "maxalloc" to a number smaller than the currently
* allocated count is permitted. New allocations will be refused until
* the count drops below this threshold.
*
* All functions require (in addition to other requirements):
* mpctx is a valid memory pool
*/
unsigned int
isc_mempool_getfreemax(isc_mempool_t *mpctx);
/*%<
* Returns the maximum allowed size of the free list.
*/
void
isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit);
/*%<
* Sets the maximum allowed size of the free list.
*/
unsigned int
isc_mempool_getfreecount(isc_mempool_t *mpctx);
/*%<
* Returns current size of the free list.
*/
unsigned int
isc_mempool_getmaxalloc(isc_mempool_t *mpctx);
/*!<
* Returns the maximum allowed number of allocations.
*/
void
isc_mempool_setmaxalloc(isc_mempool_t *mpctx, unsigned int limit);
/*%<
* Sets the maximum allowed number of allocations.
*
* Additional requirements:
*\li limit > 0
*/
unsigned int
isc_mempool_getallocated(isc_mempool_t *mpctx);
/*%<
* Returns the number of items allocated from this pool.
*/
unsigned int
isc_mempool_getfillcount(isc_mempool_t *mpctx);
/*%<
* Returns the number of items allocated as a block from the parent memory
* context when the free list is empty.
*/
void
isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit);
/*%<
* Sets the fillcount.
*
* Additional requirements:
*\li limit > 0
*/
/*
* Pseudo-private functions for use via macros. Do not call directly.
*/
void *
isc__mem_get(isc_mem_t *, size_t _ISC_MEM_FLARG);
void
isc__mem_putanddetach(isc_mem_t **, void *,
size_t _ISC_MEM_FLARG);
void
isc__mem_put(isc_mem_t *, void *, size_t _ISC_MEM_FLARG);
void *
isc__mem_allocate(isc_mem_t *, size_t _ISC_MEM_FLARG);
void
isc__mem_free(isc_mem_t *, void * _ISC_MEM_FLARG);
char *
isc__mem_strdup(isc_mem_t *, const char *_ISC_MEM_FLARG);
void *
isc__mempool_get(isc_mempool_t * _ISC_MEM_FLARG);
void
isc__mempool_put(isc_mempool_t *, void * _ISC_MEM_FLARG);
#ifdef HAVE_LIBXML2
void
isc_mem_renderxml(isc_mem_t *mgr, xmlTextWriterPtr writer);
#endif /* HAVE_LIBXML2 */
ISC_LANG_ENDDECLS
#endif /* ISC_MEM_H */

87
includes/isc-dhcp/print.h Normal file
View File

@ -0,0 +1,87 @@
/*
* Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2001, 2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: print.h,v 1.2 2007/11/16 11:04:11 shane Exp $ */
#ifndef ISC_PRINT_H
#define ISC_PRINT_H 1
/*! \file isc/print.h */
/***
*** Imports
***/
#include <isc-dhcp/formatcheck.h> /* Required for ISC_FORMAT_PRINTF() macro. */
#include <isc-dhcp/lang.h>
/*#include <isc-dhcp/platform.h>*/
/*!
* This block allows lib/isc/print.c to be cleanly compiled even if
* the platform does not need it. The standard Makefile will still
* not compile print.c or archive print.o, so this is just to make test
* compilation ("make print.o") easier.
*/
#if !defined(ISC_PLATFORM_NEEDVSNPRINTF) && defined(ISC__PRINT_SOURCE)
#define ISC_PLATFORM_NEEDVSNPRINTF
#endif
#if !defined(ISC_PLATFORM_NEEDSPRINTF) && defined(ISC__PRINT_SOURCE)
#define ISC_PLATFORM_NEEDSPRINTF
#endif
/***
*** Macros
***/
#define ISC_PRINT_QUADFORMAT ISC_PLATFORM_QUADFORMAT
/***
*** Functions
***/
#ifdef ISC_PLATFORM_NEEDVSNPRINTF
#include <stdarg.h>
#include <stddef.h>
#endif
#ifdef ISC_PLATFORM_NEEDSPRINTF
#include <stdio.h>
#endif
ISC_LANG_BEGINDECLS
#ifdef ISC_PLATFORM_NEEDVSNPRINTF
int
isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap)
ISC_FORMAT_PRINTF(3, 0);
#define vsnprintf isc_print_vsnprintf
int
isc_print_snprintf(char *str, size_t size, const char *format, ...)
ISC_FORMAT_PRINTF(3, 4);
#define snprintf isc_print_snprintf
#endif /* ISC_PLATFORM_NEEDVSNPRINTF */
#ifdef ISC_PLATFORM_NEEDSPRINTF
int
isc_print_sprintf(char *str, const char *format, ...) ISC_FORMAT_PRINTF(2, 3);
#define sprintf isc_print_sprintf
#endif
ISC_LANG_ENDDECLS
#endif /* ISC_PRINT_H */

234
includes/isc-dhcp/string.h Normal file
View File

@ -0,0 +1,234 @@
/*
* Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: string.h,v 1.2 2007/11/16 11:04:11 shane Exp $ */
#ifndef ISC_STRING_H
#define ISC_STRING_H 1
/*! \file isc/string.h */
#include <isc-dhcp/formatcheck.h>
#include <isc-dhcp/int.h>
#include <isc-dhcp/lang.h>
/*#include <isc-dhcp/platform.h>*/
#include <isc-dhcp/types.h>
#include <isc-dhcp/result.h>
#include <string.h>
#ifdef ISC_PLATFORM_HAVESTRINGSH
#include <strings.h>
#endif
#define ISC_STRING_MAGIC 0x5e
ISC_LANG_BEGINDECLS
isc_uint64_t
isc_string_touint64(char *source, char **endp, int base);
/*%<
* Convert the string pointed to by 'source' to isc_uint64_t.
*
* On successful conversion 'endp' points to the first character
* after conversion is complete.
*
* 'base': 0 or 2..36
*
* If base is 0 the base is computed from the string type.
*
* On error 'endp' points to 'source'.
*/
isc_result_t
isc_string_copy(char *target, size_t size, const char *source);
/*
* Copy the string pointed to by 'source' to 'target' which is a
* pointer to a string of at least 'size' bytes.
*
* Requires:
* 'target' is a pointer to a char[] of at least 'size' bytes.
* 'size' an integer > 0.
* 'source' == NULL or points to a NUL terminated string.
*
* Ensures:
* If result == ISC_R_SUCCESS
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*
* If result == ISC_R_NOSPACE
* 'target' is undefined.
*
* Returns:
* ISC_R_SUCCESS -- 'source' was successfully copied to 'target'.
* ISC_R_NOSPACE -- 'source' could not be copied since 'target'
* is too small.
*/
void
isc_string_copy_truncate(char *target, size_t size, const char *source);
/*
* Copy the string pointed to by 'source' to 'target' which is a
* pointer to a string of at least 'size' bytes.
*
* Requires:
* 'target' is a pointer to a char[] of at least 'size' bytes.
* 'size' an integer > 0.
* 'source' == NULL or points to a NUL terminated string.
*
* Ensures:
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*/
isc_result_t
isc_string_append(char *target, size_t size, const char *source);
/*
* Append the string pointed to by 'source' to 'target' which is a
* pointer to a NUL terminated string of at least 'size' bytes.
*
* Requires:
* 'target' is a pointer to a NUL terminated char[] of at
* least 'size' bytes.
* 'size' an integer > 0.
* 'source' == NULL or points to a NUL terminated string.
*
* Ensures:
* If result == ISC_R_SUCCESS
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*
* If result == ISC_R_NOSPACE
* 'target' is undefined.
*
* Returns:
* ISC_R_SUCCESS -- 'source' was successfully appended to 'target'.
* ISC_R_NOSPACE -- 'source' could not be appended since 'target'
* is too small.
*/
void
isc_string_append_truncate(char *target, size_t size, const char *source);
/*
* Append the string pointed to by 'source' to 'target' which is a
* pointer to a NUL terminated string of at least 'size' bytes.
*
* Requires:
* 'target' is a pointer to a NUL terminated char[] of at
* least 'size' bytes.
* 'size' an integer > 0.
* 'source' == NULL or points to a NUL terminated string.
*
* Ensures:
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*/
isc_result_t
isc_string_printf(char *target, size_t size, const char *format, ...)
ISC_FORMAT_PRINTF(3, 4);
/*
* Print 'format' to 'target' which is a pointer to a string of at least
* 'size' bytes.
*
* Requires:
* 'target' is a pointer to a char[] of at least 'size' bytes.
* 'size' an integer > 0.
* 'format' == NULL or points to a NUL terminated string.
*
* Ensures:
* If result == ISC_R_SUCCESS
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*
* If result == ISC_R_NOSPACE
* 'target' is undefined.
*
* Returns:
* ISC_R_SUCCESS -- 'format' was successfully printed to 'target'.
* ISC_R_NOSPACE -- 'format' could not be printed to 'target' since it
* is too small.
*/
void
isc_string_printf_truncate(char *target, size_t size, const char *format, ...)
ISC_FORMAT_PRINTF(3, 4);
/*
* Print 'format' to 'target' which is a pointer to a string of at least
* 'size' bytes.
*
* Requires:
* 'target' is a pointer to a char[] of at least 'size' bytes.
* 'size' an integer > 0.
* 'format' == NULL or points to a NUL terminated string.
*
* Ensures:
* 'target' will be a NUL terminated string of no more
* than 'size' bytes (including NUL).
*/
/*
char *
isc_string_regiondup(isc_mem_t *mctx, const isc_region_t *source);
*/
/*
* Copy the region pointed to by r to a NUL terminated string
* allocated from the memory context pointed to by mctx.
*
* The result should be deallocated using isc_mem_free()
*
* Requires:
* 'mctx' is a point to a valid memory context.
* 'source' is a pointer to a valid region.
*
* Returns:
* a pointer to a NUL terminated string or
* NULL if memory for the copy could not be allocated
*
*/
char *
isc_string_separate(char **stringp, const char *delim);
#ifdef ISC_PLATFORM_NEEDSTRSEP
#define strsep isc_string_separate
#endif
#ifdef ISC_PLATFORM_NEEDMEMMOVE
#define memmove(a,b,c) bcopy(b,a,c)
#endif
size_t
isc_string_strlcpy(char *dst, const char *src, size_t size);
#ifdef ISC_PLATFORM_NEEDSTRLCPY
#define strlcpy isc_string_strlcpy
#endif
size_t
isc_string_strlcat(char *dst, const char *src, size_t size);
#ifdef ISC_PLATFORM_NEEDSTRLCAT
#define strlcat isc_string_strlcat
#endif
ISC_LANG_ENDDECLS
#endif /* ISC_STRING_H */

103
includes/t_api.h Normal file
View File

@ -0,0 +1,103 @@
/*
* Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: t_api.h,v 1.2 2007/11/16 11:04:11 shane Exp $ */
#ifndef TESTS_T_API_H
#define TESTS_T_API_H 1
/*! \file tests/t_api.h */
#include <stdio.h>
#include <isc-dhcp/lang.h>
#include <isc-dhcp/result.h>
#include <isc-dhcp/formatcheck.h>
/*
*
* Result codes.
*
*/
#define T_PASS 0x1
#define T_FAIL 0x2
#define T_UNRESOLVED 0x3
#define T_UNSUPPORTED 0x4
#define T_UNTESTED 0x5
#define T_THREADONLY 0x6
/*
*
* Assertion class codes.
*
*/
#define T_OPTIONAL 0x0
#define T_REQUIRED 0x1
/*
* Misc
*/
#define T_MAXTOKS 16
#define T_ARG(n) (*(av + (n)))
typedef void (*PFV)(void);
typedef struct {
PFV pfv;
const char *func_name;
} testspec_t;
extern int T_debug;
extern testspec_t T_testlist[];
ISC_LANG_BEGINDECLS
void
t_assert(const char *component, int anum, int class, const char *what, ...)
ISC_FORMAT_PRINTF(4, 5);
void
t_info(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
void
t_result(int result);
char *
t_getenv(const char *name);
char *
t_fgetbs(FILE *fp);
isc_result_t
t_dns_result_fromtext(char *result);
unsigned int
t_dc_method_fromtext(char *dc_method);
int
t_bustline(char *line, char **toks);
int
t_eval(const char *filename, int (*func)(char **), int nargs);
ISC_LANG_ENDDECLS
#endif /* TESTS_T_API_H */

View File

@ -88,6 +88,7 @@ ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@ ECHO_T = @ECHO_T@
EGREP = @EGREP@ EGREP = @EGREP@
EXEEXT = @EXEEXT@ EXEEXT = @EXEEXT@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -111,8 +112,6 @@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
VERSION = @VERSION@ VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@ ac_ct_CC = @ac_ct_CC@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@ am__include = @am__include@
@ -124,19 +123,26 @@ bindir = @bindir@
build_alias = @build_alias@ build_alias = @build_alias@
byte_order = @byte_order@ byte_order = @byte_order@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
host_alias = @host_alias@ host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@ includedir = @includedir@
infodir = @infodir@ infodir = @infodir@
install_sh = @install_sh@ install_sh = @install_sh@
libdir = @libdir@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
mkdir_p = @mkdir_p@ mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@ oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@

View File

@ -107,6 +107,7 @@ ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@ ECHO_T = @ECHO_T@
EGREP = @EGREP@ EGREP = @EGREP@
EXEEXT = @EXEEXT@ EXEEXT = @EXEEXT@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -130,8 +131,6 @@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
VERSION = @VERSION@ VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@ ac_ct_CC = @ac_ct_CC@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@ am__include = @am__include@
@ -143,19 +142,26 @@ bindir = @bindir@
build_alias = @build_alias@ build_alias = @build_alias@
byte_order = @byte_order@ byte_order = @byte_order@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
host_alias = @host_alias@ host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@ includedir = @includedir@
infodir = @infodir@ infodir = @infodir@
install_sh = @install_sh@ install_sh = @install_sh@
libdir = @libdir@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
mkdir_p = @mkdir_p@ mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@ oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@

View File

@ -87,6 +87,7 @@ ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@ ECHO_T = @ECHO_T@
EGREP = @EGREP@ EGREP = @EGREP@
EXEEXT = @EXEEXT@ EXEEXT = @EXEEXT@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -110,8 +111,6 @@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
VERSION = @VERSION@ VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@ ac_ct_CC = @ac_ct_CC@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@ am__include = @am__include@
@ -123,19 +122,26 @@ bindir = @bindir@
build_alias = @build_alias@ build_alias = @build_alias@
byte_order = @byte_order@ byte_order = @byte_order@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
host_alias = @host_alias@ host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@ includedir = @includedir@
infodir = @infodir@ infodir = @infodir@
install_sh = @install_sh@ install_sh = @install_sh@
libdir = @libdir@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
mkdir_p = @mkdir_p@ mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@ oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@

View File

@ -104,6 +104,7 @@ ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@ ECHO_T = @ECHO_T@
EGREP = @EGREP@ EGREP = @EGREP@
EXEEXT = @EXEEXT@ EXEEXT = @EXEEXT@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -127,8 +128,6 @@ SHELL = @SHELL@
STRIP = @STRIP@ STRIP = @STRIP@
VERSION = @VERSION@ VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@ ac_ct_CC = @ac_ct_CC@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@ am__include = @am__include@
@ -140,19 +139,26 @@ bindir = @bindir@
build_alias = @build_alias@ build_alias = @build_alias@
byte_order = @byte_order@ byte_order = @byte_order@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
host_alias = @host_alias@ host_alias = @host_alias@
htmldir = @htmldir@
includedir = @includedir@ includedir = @includedir@
infodir = @infodir@ infodir = @infodir@
install_sh = @install_sh@ install_sh = @install_sh@
libdir = @libdir@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
mkdir_p = @mkdir_p@ mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@ oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@

153
tests/HOWTO-unit-test Normal file
View File

@ -0,0 +1,153 @@
Introduction
------------
In DHCP, a unit test exercises a particular piece of code in
isolation. There is a separate unit test per module or API. Each unit
test lives in a directory beneath the code it is designed to exercise.
So, we have:
client/tests/
common/tests/
dhcpctl/tests/
And so on.
Ideally each function would be invoked with every possible type of
input, and each branch of every function would be checked. In practice
we try to be a bit more pragmatic, and target the most basic
operations, as well tricky code, and areas we have seen bugs in the
past.
Running Unit Tests
------------------
In order to run the unit tests for DHCP, use:
$ make check
This will run all of the unit tests.
You can run a single test by going to the appropriate test directory
and invoking the test directly:
$ cd common/tests
$ make test_alloc
$ ./test_alloc
There are also a number of options that you can use when running a
test. To see these, use the "-u" flag on the program.
Adding a New Unit Test
----------------------
To add an additional test to an existing test program, you must create
a function for the new test in the C source file:
static void
mynewtest(void) {
static const char *test_desc = "describe the test";
t_assert("mynewtest", 1, T_REQUIRED, test_desc);
/* ... test code ... */
t_result(T_PASS);
}
Then add this function to the T_testlist[] array in the file:
testspec_t T_testlist[] = {
...
{ mynewtest, "some new test" },
{ NULL, NULL }
};
Then you should be able to compile and run your new test.
Adding a New Unit Test Program
------------------------------
To add a new program, such as when a new module is added, you can copy
the "unit_test_sample.c" file (in this directory) to a new name, add
the new file as a target in Makefile.am, and begin adding tests. Do
not forget to add it to CVS via "cvs add".
If there is no "tests" directory for a given subdirectory, then one
must be created. This can be done by:
1. Creating the directory:
$ mkdir $subdir/tests
$ cvs add tests
2. Adding the subdirectory to the build system:
Add to $subdir/Makefile.am:
SUBDIRS = tests
Add to the AC_OUTPUT macro in configure.ac:
$subdir/tests/Makefile
3. Create a Makefile.am in the new directory, something like this:
AM_CPPFLAGS = -I../..
check_PROGRAMS = test_foo
TESTS = test_foo
test_foo_SOURCES = test_foo.c
test_foo_LDADD = ../../tests/libt_api.a # plus others...
See existing Makefile.am for examples, and the Automake documentation:
http://www.gnu.org/software/automake/manual/html_node/Tests.html
Support Functions
-----------------
Here are a few of the most useful functions defined in t_api that you
can use in testing:
void
t_assert(const char *component, int anum, int class,
const char *what, ...);
The name of this function is slightly misleading. It
actually just prints out an error message in the test
output.
void
t_info(const char *format, ...);
Prints out a message in the test output. You should
include "\n" at the end.
void
t_result(int result);
Prints out the result in the test output. You should
use one of the constants for this:
T_PASS
T_FAIL
T_UNRESOLVED
T_UNSUPPORTED
T_UNTESTED
T_THREADONLY
Additional Testing
------------------
Other static or runtime testing is always an option. For instance, you
can use valgrind to check for memory leaks.
$Id: HOWTO-unit-test,v 1.2 2007/11/16 11:04:12 shane Exp $

33
tests/Makefile.am Normal file
View File

@ -0,0 +1,33 @@
EXTRA_DIST = failover/dhcp-1.cf failover/dhcp-2.cf failover/new-failover \
DHCPv6/000-badmsgtype.pl \
DHCPv6/010-solicit-noclientid.pl \
DHCPv6/011-solicit-serverid.pl \
DHCPv6/020-advertise-mcast.pl \
DHCPv6/030-request-noclientid.pl \
DHCPv6/031-request-noserverid.pl \
DHCPv6/032-request-badduid.pl \
DHCPv6/110-information-request-ia_na.pl \
DHCPv6/111-information-request-ia_ta.pl \
DHCPv6/112-badduid.pl \
DHCPv6/210-solicit-nohost.pl \
DHCPv6/211-solicit-opt-in-na.pl \
DHCPv6/212-solicit-opt-in-na-norapidcommit.pl \
DHCPv6/280-release-nohost.pl \
DHCPv6/281-release-bad-address.pl \
DHCPv6/282-release-no-address.pl \
DHCPv6/283-release.pl \
DHCPv6/290-decline-nohost.pl \
DHCPv6/291-decline-bad-address.pl \
DHCPv6/292-decline-no-address.pl \
DHCPv6/293-decline.pl \
DHCPv6/README DHCPv6/dhcp_client.pm \
DHCPv6/stubcli-opt-in-na.pl DHCPv6/stubcli.pl \
DHCPv6/test-a.conf DHCPv6/test-b.conf \
HOWTO-unit-test \
unit_test_sample.c
AM_CPPFLAGS = -I..
check_LIBRARIES = libt_api.a
libt_api_a_SOURCES = t_api.c t_api_dhcp.c

406
tests/Makefile.in Normal file
View File

@ -0,0 +1,406 @@
# Makefile.in generated by automake 1.9.6 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005 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@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
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 = :
subdir = tests
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_HEADER = $(top_builddir)/includes/config.h
CONFIG_CLEAN_FILES =
AR = ar
ARFLAGS = cru
libt_api_a_AR = $(AR) $(ARFLAGS)
libt_api_a_LIBADD =
am_libt_api_a_OBJECTS = t_api.$(OBJEXT) t_api_dhcp.$(OBJEXT)
libt_api_a_OBJECTS = $(am_libt_api_a_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/includes
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(libt_api_a_SOURCES)
DIST_SOURCES = $(libt_api_a_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
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_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
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_alias = @build_alias@
byte_order = @byte_order@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host_alias = @host_alias@
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@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
EXTRA_DIST = failover/dhcp-1.cf failover/dhcp-2.cf failover/new-failover \
DHCPv6/000-badmsgtype.pl \
DHCPv6/010-solicit-noclientid.pl \
DHCPv6/011-solicit-serverid.pl \
DHCPv6/020-advertise-mcast.pl \
DHCPv6/030-request-noclientid.pl \
DHCPv6/031-request-noserverid.pl \
DHCPv6/032-request-badduid.pl \
DHCPv6/110-information-request-ia_na.pl \
DHCPv6/111-information-request-ia_ta.pl \
DHCPv6/112-badduid.pl \
DHCPv6/210-solicit-nohost.pl \
DHCPv6/211-solicit-opt-in-na.pl \
DHCPv6/212-solicit-opt-in-na-norapidcommit.pl \
DHCPv6/280-release-nohost.pl \
DHCPv6/281-release-bad-address.pl \
DHCPv6/282-release-no-address.pl \
DHCPv6/283-release.pl \
DHCPv6/290-decline-nohost.pl \
DHCPv6/291-decline-bad-address.pl \
DHCPv6/292-decline-no-address.pl \
DHCPv6/293-decline.pl \
DHCPv6/README DHCPv6/dhcp_client.pm \
DHCPv6/stubcli-opt-in-na.pl DHCPv6/stubcli.pl \
DHCPv6/test-a.conf DHCPv6/test-b.conf \
HOWTO-unit-test \
unit_test_sample.c
AM_CPPFLAGS = -I..
check_LIBRARIES = libt_api.a
libt_api_a_SOURCES = t_api.c t_api_dhcp.c
all: all-am
.SUFFIXES:
.SUFFIXES: .c .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 \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign tests/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign 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: $(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
clean-checkLIBRARIES:
-test -z "$(check_LIBRARIES)" || rm -f $(check_LIBRARIES)
libt_api.a: $(libt_api_a_OBJECTS) $(libt_api_a_DEPENDENCIES)
-rm -f libt_api.a
$(libt_api_a_AR) libt_api.a $(libt_api_a_OBJECTS) $(libt_api_a_LIBADD)
$(RANLIB) libt_api.a
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_api.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_api_dhcp.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@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@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@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) '$<'`
uninstall-info-am:
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; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
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; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
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; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
$(mkdir_p) $(distdir)/DHCPv6 $(distdir)/failover
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$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
$(MAKE) $(AM_MAKEFLAGS) $(check_LIBRARIES)
check: check-am
all-am: Makefile
installdirs:
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)
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-checkLIBRARIES clean-generic 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
info: info-am
info-am:
install-data-am:
install-exec-am:
install-info: install-info-am
install-man:
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
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-info-am
.PHONY: CTAGS GTAGS all all-am check check-am clean \
clean-checkLIBRARIES clean-generic ctags 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-exec install-exec-am \
install-info install-info-am install-man install-strip \
installcheck installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \
uninstall-am uninstall-info-am
# 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:

823
tests/t_api.c Normal file
View File

@ -0,0 +1,823 @@
/*
* Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: t_api.c,v 1.2 2007/11/16 11:04:12 shane Exp $ */
/*! \file */
/*
* This test API framework is taken from the BIND 9 code. It has been
* modified to remove the DNS-specific parts, and the BIND-specific
* parts.
*
* The DNS-specific parts are now wrapped with the DNS_SUPPORT macro,
* and the BIND-specific parts are now wrapped with the BIND_SUPPORT
* macro.
*/
#include <config.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <sys/wait.h>
#include <isc-dhcp/boolean.h>
#include <isc-dhcp/commandline.h>
#include <isc-dhcp/print.h>
#include <isc-dhcp/string.h>
#include <isc-dhcp/mem.h>
#ifdef DNS_SUPPORT
#include <dns/compress.h>
#include <dns/result.h>
#endif /* DNS_SUPPORT */
#ifndef BIND_SUPPORT
#define isc_commandline_parse getopt
#define isc_commandline_argument optarg
#define isc_commandline_option optopt
#endif /* BIND_SUPPORT */
#include "t_api.h"
static const char *Usage =
"\t-a : run all tests\n"
"\t-b <dir> : chdir to dir before running tests"
"\t-c <config_file> : use specified config file\n"
"\t-d <debug_level> : set debug level to debug_level\n"
"\t-h : print test info\n"
"\t-u : print usage info\n"
"\t-n <test_name> : run specified test name\n"
"\t-t <test_number> : run specified test number\n"
"\t-x : don't execute tests in a subproc\n"
"\t-q <timeout> : use 'timeout' as the timeout value\n";
/*!<
* -a --> run all tests
* -b dir --> chdir to dir before running tests
* -c config --> use config file 'config'
* -d --> turn on api debugging
* -h --> print out available test names
* -u --> print usage info
* -n name --> run test named name
* -tn --> run test n
* -x --> don't execute testcases in a subproc
* -q timeout --> use 'timeout' as the timeout value
*/
#define T_MAXTESTS 256 /*% must be 0 mod 8 */
#define T_MAXENV 256
#define T_DEFAULT_CONFIG "t_config"
#define T_BUFSIZ 256
#define T_BIGBUF 4096
#define T_TCTOUT 60
int T_debug;
int T_timeout;
pid_t T_pid;
static const char * T_config;
static char T_tvec[T_MAXTESTS / 8];
static char * T_env[T_MAXENV + 1];
static char T_buf[T_BIGBUF];
static char * T_dir;
static int
t_initconf(const char *path);
static int
t_dumpconf(const char *path);
static int
t_putinfo(const char *key, const char *info);
static char *
t_getdate(char *buf, size_t buflen);
static void
printhelp(void);
static void
printusage(void);
static int T_int;
static void
t_sighandler(int sig) {
T_int = sig;
}
int
main(int argc, char **argv) {
int c;
int tnum;
int subprocs;
pid_t deadpid;
int status;
int len;
isc_boolean_t first;
testspec_t *pts;
struct sigaction sa;
#ifdef BIND_SUPPORT
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
#endif /* BIND_SUPPORT */
first = ISC_TRUE;
subprocs = 1;
T_timeout = T_TCTOUT;
/*
* -a option is now default.
*/
memset(T_tvec, 0xffff, sizeof(T_tvec));
/*
* Parse args.
*/
while ((c = isc_commandline_parse(argc, argv, ":at:c:d:n:huxq:b:"))
!= -1) {
if (c == 'a') {
/*
* Flag all tests to be run.
*/
memset(T_tvec, 0xffff, sizeof(T_tvec));
}
else if (c == 'b') {
T_dir = isc_commandline_argument;
}
else if (c == 't') {
tnum = atoi(isc_commandline_argument);
if ((tnum > 0) && (tnum < T_MAXTESTS)) {
if (first) {
/*
* Turn off effect of -a default
* and allow multiple -t and -n
* options.
*/
memset(T_tvec, 0, sizeof(T_tvec));
first = ISC_FALSE;
}
/*
* Flag test tnum to be run.
*/
tnum -= 1;
T_tvec[tnum / 8] |= (0x01 << (tnum % 8));
}
}
else if (c == 'c') {
T_config = isc_commandline_argument;
}
else if (c == 'd') {
T_debug = atoi(isc_commandline_argument);
}
else if (c == 'n') {
pts = &T_testlist[0];
tnum = 0;
while (pts->pfv != NULL) {
if (! strcmp(pts->func_name,
isc_commandline_argument)) {
if (first) {
memset(T_tvec, 0,
sizeof(T_tvec));
first = ISC_FALSE;
}
T_tvec[tnum/8] |= (0x01 << (tnum%8));
break;
}
++pts;
++tnum;
}
if (pts->pfv == NULL) {
fprintf(stderr, "no such test %s\n",
isc_commandline_argument);
exit(1);
}
}
else if (c == 'h') {
printhelp();
exit(0);
}
else if (c == 'u') {
printusage();
exit(0);
}
else if (c == 'x') {
subprocs = 0;
}
else if (c == 'q') {
T_timeout = atoi(isc_commandline_argument);
}
else if (c == ':') {
fprintf(stderr, "Option -%c requires an argument\n",
isc_commandline_option);
exit(1);
}
else if (c == '?') {
fprintf(stderr, "Unrecognized option -%c\n",
isc_commandline_option);
exit(1);
}
}
/*
* Set cwd.
*/
if (T_dir != NULL)
(void) chdir(T_dir);
/*
* We don't want buffered output.
*/
(void)setbuf(stdout, NULL);
(void)setbuf(stderr, NULL);
/*
* Setup signals.
*/
sa.sa_flags = 0;
sigfillset(&sa.sa_mask);
#ifdef SIGCHLD
/*
* This is mostly here for NetBSD's pthread implementation, until
* people catch up to the latest unproven-pthread package.
*/
sa.sa_handler = SIG_DFL;
(void)sigaction(SIGCHLD, &sa, NULL);
#endif
sa.sa_handler = t_sighandler;
(void)sigaction(SIGINT, &sa, NULL);
(void)sigaction(SIGALRM, &sa, NULL);
/*
* Output start stanza to journal.
*/
snprintf(T_buf, sizeof(T_buf), "%s:", argv[0]);
len = strlen(T_buf);
(void) t_getdate(T_buf + len, T_BIGBUF - len);
t_putinfo("S", T_buf);
/*
* Setup the test environment using the config file.
*/
if (T_config == NULL)
T_config = T_DEFAULT_CONFIG;
t_initconf(T_config);
if (T_debug)
t_dumpconf(T_config);
/*
* Now invoke all the test cases.
*/
tnum = 0;
pts = &T_testlist[0];
while (*pts->pfv != NULL) {
if (T_tvec[tnum / 8] & (0x01 << (tnum % 8))) {
if (subprocs) {
T_pid = fork();
if (T_pid == 0) {
(*pts->pfv)();
exit(0);
} else if (T_pid > 0) {
T_int = 0;
sa.sa_handler = t_sighandler;
(void)sigaction(SIGALRM, &sa, NULL);
alarm(T_timeout);
deadpid = (pid_t) -1;
while (deadpid != T_pid) {
deadpid =
waitpid(T_pid, &status, 0);
if (deadpid == T_pid) {
if (WIFSIGNALED(status)) {
if (WTERMSIG(status) ==
SIGTERM)
t_info(
"the test case timed out\n");
else
t_info(
"the test case caused exception %d\n",
WTERMSIG(status));
t_result(T_UNRESOLVED);
}
} else if ((deadpid == -1) &&
(errno == EINTR) &&
T_int) {
kill(T_pid, SIGTERM);
T_int = 0;
}
else if ((deadpid == -1) &&
((errno == ECHILD) ||
(errno == ESRCH)))
break;
}
alarm(0);
sa.sa_handler = SIG_IGN;
(void)sigaction(SIGALRM, &sa, NULL);
} else {
t_info("fork failed, errno == %d\n",
errno);
t_result(T_UNRESOLVED);
}
}
else {
(*pts->pfv)();
}
}
++pts;
++tnum;
}
snprintf(T_buf, sizeof(T_buf), "%s:", argv[0]);
len = strlen(T_buf);
(void) t_getdate(T_buf + len, T_BIGBUF - len);
t_putinfo("E", T_buf);
return(0);
}
void
t_assert(const char *component, int anum, int class, const char *what, ...) {
va_list args;
(void)printf("T:%s:%d:%s\n", component, anum, class == T_REQUIRED ?
"A" : "C");
/*
* Format text to a buffer.
*/
va_start(args, what);
(void)vsnprintf(T_buf, sizeof(T_buf), what, args);
va_end(args);
(void)t_putinfo("A", T_buf);
(void)printf("\n");
}
void
t_info(const char *format, ...) {
va_list args;
va_start(args, format);
(void) vsnprintf(T_buf, sizeof(T_buf), format, args);
va_end(args);
(void) t_putinfo("I", T_buf);
}
void
t_result(int result) {
const char *p;
switch (result) {
case T_PASS:
p = "PASS";
break;
case T_FAIL:
p = "FAIL";
break;
case T_UNRESOLVED:
p = "UNRESOLVED";
break;
case T_UNSUPPORTED:
p = "UNSUPPORTED";
break;
case T_UNTESTED:
p = "UNTESTED";
break;
case T_THREADONLY:
p = "THREADONLY";
break;
default:
p = "UNKNOWN";
break;
}
printf("R:%s\n", p);
}
char *
t_getenv(const char *name) {
char *n;
char **p;
size_t len;
n = NULL;
if (name && *name) {
p = &T_env[0];
len = strlen(name);
while (*p != NULL) {
if (strncmp(*p, name, len) == 0) {
if ( *(*p + len) == '=') {
n = *p + len + 1;
break;
}
}
++p;
}
}
return(n);
}
/*
*
* Read in the config file at path, initializing T_env.
*
* note: no format checking for now ...
*
*/
static int
t_initconf(const char *path) {
int n;
int rval;
char **p;
FILE *fp;
rval = -1;
fp = fopen(path, "r");
if (fp != NULL) {
n = 0;
p = &T_env[0];
while (n < T_MAXENV) {
*p = t_fgetbs(fp);
if (*p == NULL)
break;
if ((**p == '#') || (strchr(*p, '=') == NULL)) {
/*
* Skip comments and other junk.
*/
(void)free(*p);
continue;
}
++p; ++n;
}
(void)fclose(fp);
rval = 0;
}
return (rval);
}
/*
*
* Dump T_env to stdout.
*
*/
static int
t_dumpconf(const char *path) {
int rval;
char **p;
FILE *fp;
rval = -1;
fp = fopen(path, "r");
if (fp != NULL) {
p = &T_env[0];
while (*p != NULL) {
printf("C:%s\n", *p);
++p;
}
(void) fclose(fp);
rval = 0;
}
return(rval);
}
/*
*
* Read a newline or EOF terminated string from fp.
* On success:
* return a malloc'd buf containing the string with
* the newline converted to a '\0'.
* On error:
* return NULL.
*
* Caller is responsible for freeing buf.
*
*/
char *
t_fgetbs(FILE *fp) {
int c;
size_t n;
size_t size;
char *buf;
char *p;
n = 0;
size = T_BUFSIZ;
buf = (char *) malloc(T_BUFSIZ * sizeof(char));
if (buf != NULL) {
p = buf;
while ((c = fgetc(fp)) != EOF) {
if (c == '\n')
break;
*p++ = c;
++n;
if ( n >= size ) {
size += T_BUFSIZ;
buf = (char *)realloc(buf,
size * sizeof(char));
if (buf == NULL)
break;
p = buf + n;
}
}
*p = '\0';
if (c == EOF && n == 0U) {
free(buf);
return (NULL);
}
return (buf);
} else {
fprintf(stderr, "malloc failed %d", errno);
return(NULL);
}
}
/*
*
* Put info to log, using key.
* For now, just dump it out.
* Later format into pretty lines.
*
*/
static int
t_putinfo(const char *key, const char *info) {
int rval;
/*
* For now.
*/
rval = printf("%s:%s", key, info);
return(rval);
}
static char *
t_getdate(char *buf, size_t buflen) {
size_t n;
time_t t;
struct tm *p;
t = time(NULL);
p = localtime(&t);
n = strftime(buf, buflen - 1, "%A %d %B %H:%M:%S %Y\n", p);
return(n != 0U ? buf : NULL);
}
/*
* Some generally used utilities.
*/
#ifdef DNS_SUPPORT
struct dns_errormap {
isc_result_t result;
const char *text;
} dns_errormap[] = {
{ ISC_R_SUCCESS, "ISC_R_SUCCESS" },
{ ISC_R_EXISTS, "ISC_R_EXISTS" },
{ ISC_R_NOTFOUND, "ISC_R_NOTFOUND" },
{ ISC_R_NOSPACE, "ISC_R_NOSPACE" },
{ ISC_R_UNEXPECTED, "ISC_R_UNEXPECTED" },
{ ISC_R_UNEXPECTEDEND, "ISC_R_UNEXPECTEDEND" },
{ ISC_R_RANGE, "ISC_R_RANGE" },
{ DNS_R_LABELTOOLONG, "DNS_R_LABELTOOLONG" },
{ DNS_R_BADESCAPE, "DNS_R_BADESCAPE" },
/* { DNS_R_BADBITSTRING, "DNS_R_BADBITSTRING" }, */
/* { DNS_R_BITSTRINGTOOLONG, "DNS_R_BITSTRINGTOOLONG"}, */
{ DNS_R_EMPTYLABEL, "DNS_R_EMPTYLABEL" },
{ DNS_R_BADDOTTEDQUAD, "DNS_R_BADDOTTEDQUAD" },
{ DNS_R_UNKNOWN, "DNS_R_UNKNOWN" },
{ DNS_R_BADLABELTYPE, "DNS_R_BADLABELTYPE" },
{ DNS_R_BADPOINTER, "DNS_R_BADPOINTER" },
{ DNS_R_TOOMANYHOPS, "DNS_R_TOOMANYHOPS" },
{ DNS_R_DISALLOWED, "DNS_R_DISALLOWED" },
{ DNS_R_EXTRATOKEN, "DNS_R_EXTRATOKEN" },
{ DNS_R_EXTRADATA, "DNS_R_EXTRADATA" },
{ DNS_R_TEXTTOOLONG, "DNS_R_TEXTTOOLONG" },
{ DNS_R_SYNTAX, "DNS_R_SYNTAX" },
{ DNS_R_BADCKSUM, "DNS_R_BADCKSUM" },
{ DNS_R_BADAAAA, "DNS_R_BADAAAA" },
{ DNS_R_NOOWNER, "DNS_R_NOOWNER" },
{ DNS_R_NOTTL, "DNS_R_NOTTL" },
{ DNS_R_BADCLASS, "DNS_R_BADCLASS" },
{ DNS_R_PARTIALMATCH, "DNS_R_PARTIALMATCH" },
{ DNS_R_NEWORIGIN, "DNS_R_NEWORIGIN" },
{ DNS_R_UNCHANGED, "DNS_R_UNCHANGED" },
{ DNS_R_BADTTL, "DNS_R_BADTTL" },
{ DNS_R_NOREDATA, "DNS_R_NOREDATA" },
{ DNS_R_CONTINUE, "DNS_R_CONTINUE" },
{ DNS_R_DELEGATION, "DNS_R_DELEGATION" },
{ DNS_R_GLUE, "DNS_R_GLUE" },
{ DNS_R_DNAME, "DNS_R_DNAME" },
{ DNS_R_CNAME, "DNS_R_CNAME" },
{ DNS_R_NXDOMAIN, "DNS_R_NXDOMAIN" },
{ DNS_R_NXRRSET, "DNS_R_NXRRSET" },
{ DNS_R_BADDB, "DNS_R_BADDB" },
{ DNS_R_ZONECUT, "DNS_R_ZONECUT" },
{ DNS_R_NOTZONETOP, "DNS_R_NOTZONETOP" },
{ DNS_R_SEENINCLUDE, "DNS_R_SEENINCLUDE" },
{ DNS_R_SINGLETON, "DNS_R_SINGLETON" },
{ (isc_result_t)0, NULL }
};
isc_result_t
t_dns_result_fromtext(char *name) {
isc_result_t result;
struct dns_errormap *pmap;
result = ISC_R_UNEXPECTED;
pmap = dns_errormap;
while (pmap->text != NULL) {
if (strcmp(name, pmap->text) == 0)
break;
++pmap;
}
if (pmap->text != NULL)
result = pmap->result;
return (result);
}
struct dc_method_map {
unsigned int dc_method;
const char *text;
} dc_method_map[] = {
{ DNS_COMPRESS_NONE, "DNS_COMPRESS_NONE" },
{ DNS_COMPRESS_GLOBAL14, "DNS_COMPRESS_GLOBAL14" },
{ DNS_COMPRESS_ALL, "DNS_COMPRESS_ALL" },
{ 0, NULL }
};
unsigned int
t_dc_method_fromtext(char *name) {
unsigned int dc_method;
struct dc_method_map *pmap;
dc_method = DNS_COMPRESS_NONE;
pmap = dc_method_map;
while (pmap->text != NULL) {
if (strcmp(name, pmap->text) == 0)
break;
++pmap;
}
if (pmap->text != NULL)
dc_method = pmap->dc_method;
return(dc_method);
}
#endif /* DNS_SUPPORT */
int
t_bustline(char *line, char **toks) {
int cnt;
char *p;
cnt = 0;
if (line && *line) {
while ((p = strtok(line, "\t")) && (cnt < T_MAXTOKS)) {
*toks++ = p;
line = NULL;
++cnt;
}
}
return(cnt);
}
static void
printhelp(void) {
int cnt;
testspec_t *pts;
cnt = 1;
pts = &T_testlist[0];
printf("Available tests:\n");
while (pts->func_name) {
printf("\t%d\t%s\n", cnt, pts->func_name);
++pts;
++cnt;
}
}
static void
printusage(void) {
printf("Usage:\n%s\n", Usage);
}
int
t_eval(const char *filename, int (*func)(char **), int nargs) {
FILE *fp;
char *p;
int line;
int cnt;
int result;
int nfails;
int nprobs;
int npass;
char *tokens[T_MAXTOKS + 1];
npass = 0;
nfails = 0;
nprobs = 0;
fp = fopen(filename, "r");
if (fp != NULL) {
line = 0;
while ((p = t_fgetbs(fp)) != NULL) {
++line;
/*
* Skip comment lines.
*/
if ((isspace((unsigned char)*p)) || (*p == '#')) {
(void)free(p);
continue;
}
cnt = t_bustline(p, tokens);
if (cnt == nargs) {
result = func(tokens);
switch (result) {
case T_PASS:
++npass;
break;
case T_FAIL:
++nfails;
break;
case T_UNTESTED:
break;
default:
++nprobs;
break;
}
} else {
t_info("bad format in %s at line %d\n",
filename, line);
++nprobs;
}
(void)free(p);
}
(void)fclose(fp);
} else {
t_info("Missing datafile %s\n", filename);
++nprobs;
}
result = T_UNRESOLVED;
if (nfails == 0 && nprobs == 0 && npass > 0)
result = T_PASS;
else if (nfails > 0)
result = T_FAIL;
else if (npass == 0)
result = T_UNTESTED;
return (result);
}

44
tests/t_api_dhcp.c Normal file
View File

@ -0,0 +1,44 @@
/*
* We have to have a number of symbols defined in order to build a
* DHCP program.
*/
#include <config.h>
#include "dhcpd.h"
void
bootp(struct packet *packet) {
}
void
dhcp(struct packet *packet) {
}
void
dhcpv6(struct packet *packet) {
}
isc_result_t
dhcp_set_control_state(control_object_state_t old, control_object_state_t new) {
return ISC_R_NOTIMPLEMENTED;
}
int
check_collection(struct packet *p, struct lease *l, struct collection *c) {
return 0;
}
void
classify (struct packet *p, struct class *c) {
}
isc_result_t
find_class(struct class **class, const char *c1, const char *c2, int i) {
return ISC_R_NOTFOUND;
}
int
parse_allow_deny(struct option_cache **oc, struct parse *p, int i) {
return 0;
}

25
tests/unit_test_sample.c Normal file
View File

@ -0,0 +1,25 @@
#include "config.h"
#include "t_api.h"
static void foo(void);
/*
* T_testlist is a list of tests that are invoked.
*/
testspec_t T_testlist[] = {
{ foo, "sample test" },
{ NULL, NULL }
};
static void
foo(void) {
static const char *test_desc =
"this is an example test, for no actual module";
t_assert("sample", 1, T_REQUIRED, test_desc);
/* ... */ /* Test code would go here. */
t_result(T_PASS);
}