mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-12 23:40:01 -04:00
Merge branch '620-cmocka-conversions-v9_12-v9_11' into 'v9_11'
Resolve "CMOCKA conversions" See merge request isc-projects/bind9!1063
This commit is contained in:
commit
11cbb0619d
413 changed files with 7472 additions and 130153 deletions
|
|
@ -115,7 +115,7 @@ stages:
|
|||
- test -w "${CCACHE_DIR}" && export PATH="/usr/lib/ccache:${PATH}"
|
||||
- autoreconf -fi
|
||||
script:
|
||||
- ./configure --enable-developer --with-libtool --disable-static --with-atf=/usr --with-libidn2 --prefix=$HOME/.local --without-make-clean "${EXTRA_CONFIGURE}" || cat config.log
|
||||
- ./configure --enable-developer --with-libtool --disable-static --with-cmocka --with-libidn2 --prefix=$HOME/.local --without-make-clean "${EXTRA_CONFIGURE}" || cat config.log
|
||||
- make -j${PARALLEL_JOBS_BUILD:-1} -k all V=1
|
||||
artifacts:
|
||||
paths:
|
||||
|
|
@ -153,7 +153,6 @@ stages:
|
|||
- kyua report-html --force --results-file kyua.results --results-filter "" --output kyua_html
|
||||
artifacts:
|
||||
paths:
|
||||
- atf.out
|
||||
- kyua.log
|
||||
- kyua.results
|
||||
- kyua_html/
|
||||
|
|
|
|||
5
Atffile
5
Atffile
|
|
@ -1,5 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: lib
|
||||
5
CHANGES
5
CHANGES
|
|
@ -1,3 +1,8 @@
|
|||
5095. [test] Converted all unit tests from ATF to CMocka;
|
||||
removed the source code for the ATF libraries.
|
||||
Build with "configure --with-cmocka" to enable
|
||||
unit testing. [GL #620]
|
||||
|
||||
5094. [func] Add 'dig -r' to disable reading of .digrc. [GL !970]
|
||||
|
||||
5092. [bug] Address memory leak on SIGTERM in nsupdate when using
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ top_builddir = @top_builddir@
|
|||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
SUBDIRS = make unit lib bin doc
|
||||
SUBDIRS = make lib bin doc
|
||||
TARGETS =
|
||||
PREREQS = bind.keys.h
|
||||
|
||||
|
|
|
|||
126
configure
vendored
126
configure
vendored
|
|
@ -677,11 +677,8 @@ BIND9_ISCCFG_BUILDINCLUDE
|
|||
BIND9_ISCCC_BUILDINCLUDE
|
||||
BIND9_ISC_BUILDINCLUDE
|
||||
BIND9_TOP_BUILDDIR
|
||||
UNITTESTS
|
||||
ATFLIBS
|
||||
ATFBIN
|
||||
ATFBUILD
|
||||
LD_WRAP_TESTS
|
||||
UNITTESTS
|
||||
CMOCKA_LIBS
|
||||
CMOCKA_CFLAGS
|
||||
LIBIDN2_LIBS
|
||||
|
|
@ -974,6 +971,7 @@ infodir
|
|||
docdir
|
||||
oldincludedir
|
||||
includedir
|
||||
runstatedir
|
||||
localstatedir
|
||||
sharedstatedir
|
||||
sysconfdir
|
||||
|
|
@ -1074,7 +1072,6 @@ with_iconv
|
|||
with_idnlib
|
||||
with_libidn2
|
||||
with_cmocka
|
||||
with_atf
|
||||
with_tuning
|
||||
enable_querytrace
|
||||
with_dlopen
|
||||
|
|
@ -1141,6 +1138,7 @@ datadir='${datarootdir}'
|
|||
sysconfdir='${prefix}/etc'
|
||||
sharedstatedir='${prefix}/com'
|
||||
localstatedir='${prefix}/var'
|
||||
runstatedir='${localstatedir}/run'
|
||||
includedir='${prefix}/include'
|
||||
oldincludedir='/usr/include'
|
||||
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
|
||||
|
|
@ -1393,6 +1391,15 @@ do
|
|||
| -silent | --silent | --silen | --sile | --sil)
|
||||
silent=yes ;;
|
||||
|
||||
-runstatedir | --runstatedir | --runstatedi | --runstated \
|
||||
| --runstate | --runstat | --runsta | --runst | --runs \
|
||||
| --run | --ru | --r)
|
||||
ac_prev=runstatedir ;;
|
||||
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
|
||||
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
|
||||
| --run=* | --ru=* | --r=*)
|
||||
runstatedir=$ac_optarg ;;
|
||||
|
||||
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
|
||||
ac_prev=sbindir ;;
|
||||
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
|
||||
|
|
@ -1530,7 +1537,7 @@ fi
|
|||
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
|
||||
datadir sysconfdir sharedstatedir localstatedir includedir \
|
||||
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
|
||||
libdir localedir mandir
|
||||
libdir localedir mandir runstatedir
|
||||
do
|
||||
eval ac_val=\$$ac_var
|
||||
# Remove trailing slashes.
|
||||
|
|
@ -1683,6 +1690,7 @@ Fine tuning of the installation directories:
|
|||
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
|
||||
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
|
||||
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
|
||||
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
|
||||
--libdir=DIR object code libraries [EPREFIX/lib]
|
||||
--includedir=DIR C header files [PREFIX/include]
|
||||
--oldincludedir=DIR C header files for non-gcc [/usr/include]
|
||||
|
|
@ -1807,7 +1815,6 @@ Optional Packages:
|
|||
--with-idnlib=ARG specify libidnkit
|
||||
--with-libidn2=PATH enable IDN support using GNU libidn2 [yes|no|path]
|
||||
--with-cmocka=no enable cmocka based tests (default is no)
|
||||
--with-atf support Automated Test Framework
|
||||
--with-tuning=ARG Specify server tuning (large or default)
|
||||
--with-dlopen=ARG support dynamically loadable DLZ drivers
|
||||
--with-dlz-postgres=PATH
|
||||
|
|
@ -23221,6 +23228,7 @@ case $with_cmocka in #(
|
|||
: ;; #(
|
||||
yes) :
|
||||
|
||||
|
||||
pkg_failed=no
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for cmocka >= 1.0.0" >&5
|
||||
$as_echo_n "checking for cmocka >= 1.0.0... " >&6; }
|
||||
|
|
@ -23312,7 +23320,9 @@ $as_echo "yes" >&6; }
|
|||
|
||||
$as_echo "#define HAVE_CMOCKA 1" >>confdefs.h
|
||||
|
||||
fi ;; #(
|
||||
fi
|
||||
UNITTESTS=tests
|
||||
;; #(
|
||||
*) :
|
||||
|
||||
save_CFLAGS="$CFLAGS"
|
||||
|
|
@ -23393,6 +23403,7 @@ if test "$ac_res" != no; then :
|
|||
|
||||
CMOCKA_CFLAGS="-Iwith_cmocka/include"
|
||||
CMOCKA_LIBS="-L$with_cmocka/lib -lcmocka"
|
||||
UNITTESTS=tests
|
||||
|
||||
$as_echo "#define HAVE_CMOCKA 1" >>confdefs.h
|
||||
|
||||
|
|
@ -23408,6 +23419,7 @@ esac
|
|||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Check for -Wl,--wrap= support
|
||||
#
|
||||
|
|
@ -23449,86 +23461,6 @@ rm -f core conftest.err conftest.$ac_objext \
|
|||
|
||||
LDFLAGS=$save_LDFLAGS
|
||||
|
||||
#
|
||||
# Check whether to build Automated Test Framework unit tests
|
||||
#
|
||||
|
||||
# Check whether --with-atf was given.
|
||||
if test "${with_atf+set}" = set; then :
|
||||
withval=$with_atf; atf="$withval"
|
||||
else
|
||||
atf="no"
|
||||
fi
|
||||
|
||||
if test "yes" = "$atf"; then
|
||||
atf=`pwd`/unit/atf
|
||||
ATFBUILD=atf-src
|
||||
|
||||
ac_config_commands="$ac_config_commands atf-config"
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: building ATF from bind9/unit/atf-src" >&5
|
||||
$as_echo "building ATF from bind9/unit/atf-src" >&6; }
|
||||
fi
|
||||
|
||||
ATFLIBS=
|
||||
if test "no" != "$atf"; then
|
||||
|
||||
$as_echo "#define ATF_TEST 1" >>confdefs.h
|
||||
|
||||
STD_CINCLUDES="$STD_CINCLUDES -I$atf/include"
|
||||
ATFBIN="$atf/bin"
|
||||
ATFLIBS="-L$atf/lib -latf-c"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for exp in -lm" >&5
|
||||
$as_echo_n "checking for exp in -lm... " >&6; }
|
||||
if ${ac_cv_lib_m_exp+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
ac_check_lib_save_LIBS=$LIBS
|
||||
LIBS="-lm $LIBS"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
/* Override any GCC internal prototype to avoid an error.
|
||||
Use char because int might match the return type of a GCC
|
||||
builtin and then its argument prototype would still apply. */
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
char exp ();
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return exp ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
ac_cv_lib_m_exp=yes
|
||||
else
|
||||
ac_cv_lib_m_exp=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS=$ac_check_lib_save_LIBS
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_exp" >&5
|
||||
$as_echo "$ac_cv_lib_m_exp" >&6; }
|
||||
if test "x$ac_cv_lib_m_exp" = xyes; then :
|
||||
libm=yes
|
||||
else
|
||||
libm=no
|
||||
fi
|
||||
|
||||
if test "yes" = "$libm"; then
|
||||
ATFLIBS="$ATFLIBS -lm"
|
||||
fi
|
||||
UNITTESTS=tests
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
for ac_header in locale.h
|
||||
do :
|
||||
ac_fn_c_check_header_mongrel "$LINENO" "locale.h" "ac_cv_header_locale_h" "$ac_includes_default"
|
||||
|
|
@ -24961,7 +24893,7 @@ ac_config_commands="$ac_config_commands chmod"
|
|||
# elsewhere if there's a good reason for doing so.
|
||||
#
|
||||
|
||||
ac_config_files="$ac_config_files make/Makefile make/mkdep Makefile bin/Makefile bin/check/Makefile bin/confgen/Makefile bin/confgen/unix/Makefile bin/delv/Makefile bin/dig/Makefile bin/dnssec/Makefile bin/named/Makefile bin/named/unix/Makefile bin/nsupdate/Makefile bin/pkcs11/Makefile bin/python/Makefile bin/python/isc/Makefile bin/python/isc/utils.py bin/python/isc/tests/Makefile bin/python/dnssec-checkds.py bin/python/dnssec-coverage.py bin/python/dnssec-keymgr.py bin/python/isc/__init__.py bin/python/isc/checkds.py bin/python/isc/coverage.py bin/python/isc/dnskey.py bin/python/isc/eventlist.py bin/python/isc/keydict.py bin/python/isc/keyevent.py bin/python/isc/keymgr.py bin/python/isc/keyseries.py bin/python/isc/keyzone.py bin/python/isc/policy.py bin/python/isc/rndc.py bin/python/isc/tests/dnskey_test.py bin/python/isc/tests/policy_test.py bin/rndc/Makefile bin/tests/Makefile bin/tests/headerdep_test.sh bin/tests/optional/Makefile bin/tests/pkcs11/Makefile bin/tests/pkcs11/benchmarks/Makefile bin/tests/system/Makefile bin/tests/system/conf.sh bin/tests/system/dlz/prereq.sh bin/tests/system/dlzexternal/Makefile bin/tests/system/dlzexternal/ns1/dlzs.conf bin/tests/system/dyndb/Makefile bin/tests/system/dyndb/driver/Makefile bin/tests/system/inline/checkdsa.sh bin/tests/system/lwresd/Makefile bin/tests/system/pipelined/Makefile bin/tests/system/rndc/Makefile bin/tests/system/rsabigexponent/Makefile bin/tests/system/tkey/Makefile bin/tests/virtual-time/Makefile bin/tests/virtual-time/conf.sh bin/tools/Makefile contrib/scripts/check-secure-delegation.pl contrib/scripts/zone-edit.sh doc/Makefile doc/arm/Makefile doc/arm/noteversion.xml doc/arm/pkgversion.xml doc/arm/releaseinfo.xml doc/doxygen/Doxyfile doc/doxygen/Makefile doc/doxygen/doxygen-input-filter doc/misc/Makefile doc/tex/Makefile doc/tex/armstyle.sty doc/xsl/Makefile doc/xsl/isc-docbook-chunk.xsl doc/xsl/isc-docbook-html.xsl doc/xsl/isc-manpage.xsl doc/xsl/isc-notes-html.xsl isc-config.sh lib/Makefile lib/bind9/Makefile lib/bind9/include/Makefile lib/bind9/include/bind9/Makefile lib/dns/Makefile lib/dns/include/Makefile lib/dns/include/dns/Makefile lib/dns/include/dst/Makefile lib/dns/tests/Makefile lib/irs/Makefile lib/irs/include/Makefile lib/irs/include/irs/Makefile lib/irs/include/irs/netdb.h lib/irs/include/irs/platform.h lib/irs/tests/Makefile lib/isc/$arch/Makefile lib/isc/$arch/include/Makefile lib/isc/$arch/include/isc/Makefile lib/isc/$thread_dir/Makefile lib/isc/$thread_dir/include/Makefile lib/isc/$thread_dir/include/isc/Makefile lib/isc/Makefile lib/isc/include/Makefile lib/isc/include/isc/Makefile lib/isc/include/isc/platform.h lib/isc/include/pk11/Makefile lib/isc/include/pkcs11/Makefile lib/isc/tests/Makefile lib/isc/nls/Makefile lib/isc/unix/Makefile lib/isc/unix/include/Makefile lib/isc/unix/include/isc/Makefile lib/isc/unix/include/pkcs11/Makefile lib/isccc/Makefile lib/isccc/include/Makefile lib/isccc/include/isccc/Makefile lib/isccc/tests/Makefile lib/isccfg/Makefile lib/isccfg/include/Makefile lib/isccfg/include/isccfg/Makefile lib/isccfg/tests/Makefile lib/lwres/Makefile lib/lwres/include/Makefile lib/lwres/include/lwres/Makefile lib/lwres/include/lwres/netdb.h lib/lwres/include/lwres/platform.h lib/lwres/man/Makefile lib/lwres/tests/Makefile lib/lwres/unix/Makefile lib/lwres/unix/include/Makefile lib/lwres/unix/include/lwres/Makefile lib/samples/Makefile lib/samples/Makefile-postinstall unit/Makefile unit/unittest.sh"
|
||||
ac_config_files="$ac_config_files make/Makefile make/mkdep Makefile bin/Makefile bin/check/Makefile bin/confgen/Makefile bin/confgen/unix/Makefile bin/delv/Makefile bin/dig/Makefile bin/dnssec/Makefile bin/named/Makefile bin/named/unix/Makefile bin/nsupdate/Makefile bin/pkcs11/Makefile bin/python/Makefile bin/python/isc/Makefile bin/python/isc/utils.py bin/python/isc/tests/Makefile bin/python/dnssec-checkds.py bin/python/dnssec-coverage.py bin/python/dnssec-keymgr.py bin/python/isc/__init__.py bin/python/isc/checkds.py bin/python/isc/coverage.py bin/python/isc/dnskey.py bin/python/isc/eventlist.py bin/python/isc/keydict.py bin/python/isc/keyevent.py bin/python/isc/keymgr.py bin/python/isc/keyseries.py bin/python/isc/keyzone.py bin/python/isc/policy.py bin/python/isc/rndc.py bin/python/isc/tests/dnskey_test.py bin/python/isc/tests/policy_test.py bin/rndc/Makefile bin/tests/Makefile bin/tests/headerdep_test.sh bin/tests/optional/Makefile bin/tests/pkcs11/Makefile bin/tests/pkcs11/benchmarks/Makefile bin/tests/system/Makefile bin/tests/system/conf.sh bin/tests/system/dlz/prereq.sh bin/tests/system/dlzexternal/Makefile bin/tests/system/dlzexternal/ns1/dlzs.conf bin/tests/system/dyndb/Makefile bin/tests/system/dyndb/driver/Makefile bin/tests/system/inline/checkdsa.sh bin/tests/system/lwresd/Makefile bin/tests/system/pipelined/Makefile bin/tests/system/rndc/Makefile bin/tests/system/rsabigexponent/Makefile bin/tests/system/tkey/Makefile bin/tests/virtual-time/Makefile bin/tests/virtual-time/conf.sh bin/tools/Makefile contrib/scripts/check-secure-delegation.pl contrib/scripts/zone-edit.sh doc/Makefile doc/arm/Makefile doc/arm/noteversion.xml doc/arm/pkgversion.xml doc/arm/releaseinfo.xml doc/doxygen/Doxyfile doc/doxygen/Makefile doc/doxygen/doxygen-input-filter doc/misc/Makefile doc/tex/Makefile doc/tex/armstyle.sty doc/xsl/Makefile doc/xsl/isc-docbook-chunk.xsl doc/xsl/isc-docbook-html.xsl doc/xsl/isc-manpage.xsl doc/xsl/isc-notes-html.xsl isc-config.sh lib/Makefile lib/bind9/Makefile lib/bind9/include/Makefile lib/bind9/include/bind9/Makefile lib/dns/Makefile lib/dns/include/Makefile lib/dns/include/dns/Makefile lib/dns/include/dst/Makefile lib/dns/tests/Makefile lib/irs/Makefile lib/irs/include/Makefile lib/irs/include/irs/Makefile lib/irs/include/irs/netdb.h lib/irs/include/irs/platform.h lib/irs/tests/Makefile lib/isc/$arch/Makefile lib/isc/$arch/include/Makefile lib/isc/$arch/include/isc/Makefile lib/isc/$thread_dir/Makefile lib/isc/$thread_dir/include/Makefile lib/isc/$thread_dir/include/isc/Makefile lib/isc/Makefile lib/isc/include/Makefile lib/isc/include/isc/Makefile lib/isc/include/isc/platform.h lib/isc/include/pk11/Makefile lib/isc/include/pkcs11/Makefile lib/isc/tests/Makefile lib/isc/nls/Makefile lib/isc/unix/Makefile lib/isc/unix/include/Makefile lib/isc/unix/include/isc/Makefile lib/isc/unix/include/pkcs11/Makefile lib/isccc/Makefile lib/isccc/include/Makefile lib/isccc/include/isccc/Makefile lib/isccc/tests/Makefile lib/isccfg/Makefile lib/isccfg/include/Makefile lib/isccfg/include/isccfg/Makefile lib/isccfg/tests/Makefile lib/lwres/Makefile lib/lwres/include/Makefile lib/lwres/include/lwres/Makefile lib/lwres/include/lwres/netdb.h lib/lwres/include/lwres/platform.h lib/lwres/man/Makefile lib/lwres/tests/Makefile lib/lwres/unix/Makefile lib/lwres/unix/include/Makefile lib/lwres/unix/include/lwres/Makefile lib/samples/Makefile lib/samples/Makefile-postinstall unit/unittest.sh"
|
||||
|
||||
|
||||
#
|
||||
|
|
@ -25943,7 +25875,6 @@ fi
|
|||
|
||||
|
||||
|
||||
atfdir=`pwd`/unit/atf
|
||||
|
||||
_ACEOF
|
||||
|
||||
|
|
@ -25957,7 +25888,6 @@ do
|
|||
"libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
|
||||
"make/rules") CONFIG_FILES="$CONFIG_FILES make/rules" ;;
|
||||
"make/includes") CONFIG_FILES="$CONFIG_FILES make/includes" ;;
|
||||
"atf-config") CONFIG_COMMANDS="$CONFIG_COMMANDS atf-config" ;;
|
||||
"contrib/dlz/bin/dlzbdb/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/dlz/bin/dlzbdb/Makefile" ;;
|
||||
"$DLZ_DRIVER_RULES") CONFIG_FILES="$CONFIG_FILES $DLZ_DRIVER_RULES" ;;
|
||||
"contrib/dlz/modules/mysql/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/dlz/modules/mysql/Makefile" ;;
|
||||
|
|
@ -26092,7 +26022,6 @@ do
|
|||
"lib/lwres/unix/include/lwres/Makefile") CONFIG_FILES="$CONFIG_FILES lib/lwres/unix/include/lwres/Makefile" ;;
|
||||
"lib/samples/Makefile") CONFIG_FILES="$CONFIG_FILES lib/samples/Makefile" ;;
|
||||
"lib/samples/Makefile-postinstall") CONFIG_FILES="$CONFIG_FILES lib/samples/Makefile-postinstall" ;;
|
||||
"unit/Makefile") CONFIG_FILES="$CONFIG_FILES unit/Makefile" ;;
|
||||
"unit/unittest.sh") CONFIG_FILES="$CONFIG_FILES unit/unittest.sh" ;;
|
||||
|
||||
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
|
||||
|
|
@ -27231,15 +27160,6 @@ ltmain=$ac_aux_dir/ltmain.sh
|
|||
chmod +x "$ofile"
|
||||
|
||||
;;
|
||||
"atf-config":C) (
|
||||
mkdir -p unit/atf-src;
|
||||
cd unit/atf-src;
|
||||
case "$srcdir" in
|
||||
/*) ;;
|
||||
*) srcdir="../../$srcdir";;
|
||||
esac
|
||||
${SHELL} "${srcdir}${srcdir:+/unit/atf-src/}./configure" --enable-tools --disable-shared MISSING=: --prefix $atfdir;
|
||||
) || as_fn_error $? "Failed to configure ATF." "$LINENO" 5 ;;
|
||||
"chmod":C) chmod a+x isc-config.sh doc/doxygen/doxygen-input-filter ;;
|
||||
|
||||
esac
|
||||
|
|
@ -27375,7 +27295,7 @@ report() {
|
|||
test "no" = "$use_libtool" || echo " Use GNU libtool (--with-libtool)"
|
||||
test "yes" = "$want_querytrace" && \
|
||||
echo " Very verbose query trace logging (--enable-querytrace)"
|
||||
test "no" = "$atf" || echo " Automated Testing Framework (--with-atf)"
|
||||
test "no" = "$with_cmocka" || echo " CMocka Unit Testing Framework (--with-cmocka)"
|
||||
|
||||
echo " Dynamically loadable zone (DLZ) drivers:"
|
||||
test "no" = "$use_dlz_bdb" || \
|
||||
|
|
@ -27433,7 +27353,7 @@ report() {
|
|||
echo " Very verbose query trace logging (--enable-querytrace)"
|
||||
|
||||
test "yes" = "$use_libtool" || echo " Use GNU libtool (--with-libtool)"
|
||||
test "no" = "$atf" && echo " Automated Testing Framework (--with-atf)"
|
||||
test "no" = "$with_cmocka" && echo " CMocka Unit Testng Framework (--with-cmocka)"
|
||||
|
||||
test "X$PYTHON" = "X" && echo " Python tools (--with-python)"
|
||||
test "X$XMLSTATS" = "X" && echo " XML statistics (--with-libxml2)"
|
||||
|
|
|
|||
54
configure.ac
54
configure.ac
|
|
@ -4843,8 +4843,11 @@ AC_ARG_WITH([cmocka],
|
|||
|
||||
AS_CASE([$with_cmocka],
|
||||
[no],[:],
|
||||
[yes],[PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.0.0],
|
||||
[AC_DEFINE([HAVE_CMOCKA], [1], [Use cmocka])])],
|
||||
[yes],[
|
||||
PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.0.0],
|
||||
[AC_DEFINE([HAVE_CMOCKA], [1], [Use cmocka])])
|
||||
UNITTESTS=tests
|
||||
],
|
||||
[*],[
|
||||
save_CFLAGS="$CFLAGS"
|
||||
save_LIBS="$LIBS"
|
||||
|
|
@ -4862,12 +4865,14 @@ AS_CASE([$with_cmocka],
|
|||
[
|
||||
CMOCKA_CFLAGS="-Iwith_cmocka/include"
|
||||
CMOCKA_LIBS="-L$with_cmocka/lib -lcmocka"
|
||||
UNITTESTS=tests
|
||||
AC_DEFINE([HAVE_CMOCKA], [1], [Use cmocka])
|
||||
],
|
||||
[AC_MSG_ERROR([cmocka unit testing framework not found in $with_cmocka path])])
|
||||
])
|
||||
AC_SUBST([CMOCKA_CFLAGS])
|
||||
AC_SUBST([CMOCKA_LIBS])
|
||||
AC_SUBST(UNITTESTS)
|
||||
|
||||
#
|
||||
# Check for -Wl,--wrap= support
|
||||
|
|
@ -4891,46 +4896,6 @@ AC_SUBST([LD_WRAP_TESTS])
|
|||
|
||||
LDFLAGS=$save_LDFLAGS
|
||||
|
||||
#
|
||||
# Check whether to build Automated Test Framework unit tests
|
||||
#
|
||||
AC_ARG_WITH(atf,
|
||||
AS_HELP_STRING([--with-atf],[support Automated Test Framework]),
|
||||
atf="$withval", atf="no")
|
||||
if test "yes" = "$atf"; then
|
||||
atf=`pwd`/unit/atf
|
||||
ATFBUILD=atf-src
|
||||
AC_SUBST(ATFBUILD)
|
||||
AC_CONFIG_COMMANDS([atf-config],
|
||||
[(
|
||||
mkdir -p unit/atf-src;
|
||||
cd unit/atf-src;
|
||||
case "$srcdir" in
|
||||
/*) ;;
|
||||
*) srcdir="../../$srcdir";;
|
||||
esac
|
||||
${SHELL} "${srcdir}${srcdir:+/unit/atf-src/}./configure" --enable-tools --disable-shared MISSING=: --prefix $atfdir;
|
||||
) || AC_MSG_ERROR([Failed to configure ATF.]) ],
|
||||
[atfdir=`pwd`/unit/atf])
|
||||
AC_MSG_RESULT(building ATF from bind9/unit/atf-src)
|
||||
fi
|
||||
|
||||
ATFLIBS=
|
||||
if test "no" != "$atf"; then
|
||||
AC_DEFINE(ATF_TEST, 1, [define if ATF unit tests are to be built.])
|
||||
STD_CINCLUDES="$STD_CINCLUDES -I$atf/include"
|
||||
ATFBIN="$atf/bin"
|
||||
ATFLIBS="-L$atf/lib -latf-c"
|
||||
AC_CHECK_LIB(m, exp, libm=yes, libm=no)
|
||||
if test "yes" = "$libm"; then
|
||||
ATFLIBS="$ATFLIBS -lm"
|
||||
fi
|
||||
UNITTESTS=tests
|
||||
fi
|
||||
AC_SUBST(ATFBIN)
|
||||
AC_SUBST(ATFLIBS)
|
||||
AC_SUBST(UNITTESTS)
|
||||
|
||||
AC_CHECK_HEADERS(locale.h)
|
||||
AC_CHECK_FUNCS(setlocale)
|
||||
|
||||
|
|
@ -5522,7 +5487,6 @@ AC_CONFIG_FILES([
|
|||
lib/lwres/unix/include/lwres/Makefile
|
||||
lib/samples/Makefile
|
||||
lib/samples/Makefile-postinstall
|
||||
unit/Makefile
|
||||
unit/unittest.sh
|
||||
])
|
||||
|
||||
|
|
@ -5621,7 +5585,7 @@ report() {
|
|||
test "no" = "$use_libtool" || echo " Use GNU libtool (--with-libtool)"
|
||||
test "yes" = "$want_querytrace" && \
|
||||
echo " Very verbose query trace logging (--enable-querytrace)"
|
||||
test "no" = "$atf" || echo " Automated Testing Framework (--with-atf)"
|
||||
test "no" = "$with_cmocka" || echo " CMocka Unit Testing Framework (--with-cmocka)"
|
||||
|
||||
echo " Dynamically loadable zone (DLZ) drivers:"
|
||||
test "no" = "$use_dlz_bdb" || \
|
||||
|
|
@ -5679,7 +5643,7 @@ report() {
|
|||
echo " Very verbose query trace logging (--enable-querytrace)"
|
||||
|
||||
test "yes" = "$use_libtool" || echo " Use GNU libtool (--with-libtool)"
|
||||
test "no" = "$atf" && echo " Automated Testing Framework (--with-atf)"
|
||||
test "no" = "$with_cmocka" && echo " CMocka Unit Testng Framework (--with-cmocka)"
|
||||
|
||||
test "X$PYTHON" = "X" && echo " Python tools (--with-python)"
|
||||
test "X$XMLSTATS" = "X" && echo " XML statistics (--with-libxml2)"
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: dns
|
||||
tp: irs
|
||||
tp: isc
|
||||
tp: isccfg
|
||||
tp: lwres
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: tests
|
||||
|
|
@ -725,9 +725,16 @@ openssldh_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
|
|||
static void
|
||||
openssldh_cleanup(void) {
|
||||
BN_free(bn2);
|
||||
bn2 = NULL;
|
||||
|
||||
BN_free(bn768);
|
||||
bn768 = NULL;
|
||||
|
||||
BN_free(bn1024);
|
||||
bn1024 = NULL;
|
||||
|
||||
BN_free(bn1536);
|
||||
bn1536 = NULL;
|
||||
}
|
||||
|
||||
static dst_func_t openssldh_functions = {
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: acl_test
|
||||
tp: db_test
|
||||
tp: dbdiff_test
|
||||
tp: dbiterator_test
|
||||
tp: dbversion_test
|
||||
tp: dh_test
|
||||
tp: dispatch_test
|
||||
tp: dnstap_test
|
||||
tp: dst_test
|
||||
tp: geoip_test
|
||||
tp: gost_test
|
||||
tp: keytable_test
|
||||
tp: master_test
|
||||
tp: name_test
|
||||
tp: nsec3_test
|
||||
tp: peer_test
|
||||
tp: private_test
|
||||
tp: rbt_serialize_test
|
||||
tp: rbt_test
|
||||
tp: rdata_test
|
||||
tp: rdataset_test
|
||||
tp: rdatasetstats_test
|
||||
tp: resolver_test
|
||||
tp: rsa_test
|
||||
tp: sigs_test
|
||||
tp: time_test
|
||||
tp: tsig_test
|
||||
tp: update_test
|
||||
tp: zonemgr_test
|
||||
tp: zt_test
|
||||
|
|
@ -1,34 +1,34 @@
|
|||
syntax(2)
|
||||
test_suite('bind9')
|
||||
|
||||
atf_test_program{name='acl_test'}
|
||||
atf_test_program{name='db_test'}
|
||||
atf_test_program{name='dbdiff_test'}
|
||||
atf_test_program{name='dbiterator_test'}
|
||||
atf_test_program{name='dbversion_test'}
|
||||
atf_test_program{name='dh_test'}
|
||||
atf_test_program{name='dispatch_test'}
|
||||
atf_test_program{name='dnstap_test'}
|
||||
atf_test_program{name='dst_test'}
|
||||
atf_test_program{name='geoip_test'}
|
||||
atf_test_program{name='gost_test'}
|
||||
atf_test_program{name='keytable_test'}
|
||||
atf_test_program{name='master_test'}
|
||||
atf_test_program{name='name_test'}
|
||||
atf_test_program{name='nsec3_test'}
|
||||
atf_test_program{name='peer_test'}
|
||||
atf_test_program{name='private_test'}
|
||||
atf_test_program{name='rbt_serialize_test', is_exclusive=true}
|
||||
atf_test_program{name='rbt_test'}
|
||||
atf_test_program{name='rdata_test'}
|
||||
atf_test_program{name='rdataset_test'}
|
||||
atf_test_program{name='rdatasetstats_test'}
|
||||
atf_test_program{name='resolver_test'}
|
||||
tap_test_program{name='acl_test'}
|
||||
tap_test_program{name='db_test'}
|
||||
tap_test_program{name='dbdiff_test'}
|
||||
tap_test_program{name='dbiterator_test'}
|
||||
tap_test_program{name='dbversion_test'}
|
||||
tap_test_program{name='dh_test'}
|
||||
tap_test_program{name='dispatch_test'}
|
||||
tap_test_program{name='dnstap_test'}
|
||||
tap_test_program{name='dst_test'}
|
||||
tap_test_program{name='geoip_test'}
|
||||
tap_test_program{name='gost_test'}
|
||||
tap_test_program{name='keytable_test'}
|
||||
tap_test_program{name='master_test'}
|
||||
tap_test_program{name='name_test'}
|
||||
tap_test_program{name='nsec3_test'}
|
||||
tap_test_program{name='peer_test'}
|
||||
tap_test_program{name='private_test'}
|
||||
tap_test_program{name='rbt_serialize_test'}
|
||||
tap_test_program{name='rbt_test'}
|
||||
tap_test_program{name='rdata_test'}
|
||||
tap_test_program{name='rdataset_test'}
|
||||
tap_test_program{name='rdatasetstats_test'}
|
||||
tap_test_program{name='resolver_test'}
|
||||
tap_test_program{name='result_test'}
|
||||
atf_test_program{name='rsa_test'}
|
||||
atf_test_program{name='sigs_test'}
|
||||
atf_test_program{name='time_test'}
|
||||
atf_test_program{name='tsig_test'}
|
||||
atf_test_program{name='update_test'}
|
||||
atf_test_program{name='zonemgr_test'}
|
||||
atf_test_program{name='zt_test'}
|
||||
tap_test_program{name='rsa_test'}
|
||||
tap_test_program{name='sigs_test'}
|
||||
tap_test_program{name='time_test'}
|
||||
tap_test_program{name='tsig_test'}
|
||||
tap_test_program{name='update_test'}
|
||||
tap_test_program{name='zonemgr_test'}
|
||||
tap_test_program{name='zt_test'}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ srcdir = @srcdir@
|
|||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
# Attempt to disable parallel processing.
|
||||
.NOTPARALLEL:
|
||||
.NO_PARALLEL:
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
@BIND9_MAKE_INCLUDES@
|
||||
|
|
@ -28,10 +24,8 @@ ISCDEPLIBS = ../../isc/libisc.@A@
|
|||
DNSLIBS = ../libdns.@A@ @DNS_CRYPTO_LIBS@
|
||||
DNSDEPLIBS = ../libdns.@A@
|
||||
|
||||
LIBS = @LIBS@ @ATFLIBS@
|
||||
|
||||
CMOCKA_CFLAGS = @CMOCKA_CFLAGS@
|
||||
CMOCKA_LIBS = @CMOCKA_LIBS@
|
||||
LIBS = @LIBS@ @CMOCKA_LIBS@
|
||||
CFLAGS = @CFLAGS@ @CMOCKA_CFLAGS@
|
||||
|
||||
OBJS = dnstest.@O@
|
||||
SRCS = acl_test.c \
|
||||
|
|
@ -102,64 +96,64 @@ TARGETS = acl_test@EXEEXT@ \
|
|||
@BIND9_MAKE_RULES@
|
||||
|
||||
acl_test@EXEEXT@: acl_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
acl_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ acl_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
db_test@EXEEXT@: db_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
db_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
keytable_test@EXEEXT@: keytable_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
keytable_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
dbiterator_test@EXEEXT@: dbiterator_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
dbiterator_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
db_test@EXEEXT@: db_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ db_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
dbdiff_test@EXEEXT@: dbdiff_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
dbdiff_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ dbdiff_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
dbiterator_test@EXEEXT@: dbiterator_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ dbiterator_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
dbversion_test@EXEEXT@: dbversion_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
dbversion_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ dbversion_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
dh_test@EXEEXT@: dh_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
dh_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ dh_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
dispatch_test@EXEEXT@: dispatch_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
dispatch_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ dispatch_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
dnstap_test@EXEEXT@: dnstap_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
dnstap_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ dnstap_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
dst_test@EXEEXT@: dst_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
dst_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
dst_test@EXEEXT@: dst_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ dst_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
geoip_test@EXEEXT@: geoip_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
geoip_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
geoip_test@EXEEXT@: geoip_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ geoip_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
gost_test@EXEEXT@: gost_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
gost_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ gost_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
keytable_test@EXEEXT@: keytable_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ keytable_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
master_test@EXEEXT@: master_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
test -d testdata || mkdir testdata
|
||||
|
|
@ -170,101 +164,99 @@ master_test@EXEEXT@: master_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
|||
> testdata/master/master13.data
|
||||
${PERL} ${srcdir}/mkraw.pl < ${srcdir}/testdata/master/master14.data.in \
|
||||
> testdata/master/master14.data
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
master_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ master_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
name_test@EXEEXT@: name_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
name_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ name_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
nsec3_test@EXEEXT@: nsec3_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
nsec3_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ nsec3_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
peer_test@EXEEXT@: peer_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
peer_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ peer_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
private_test@EXEEXT@: private_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
private_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ private_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
rbt_serialize_test@EXEEXT@: rbt_serialize_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
rbt_serialize_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ rbt_serialize_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
rbt_test@EXEEXT@: rbt_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
rbt_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ rbt_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
rdata_test@EXEEXT@: rdata_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
rdata_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
rdata_test@EXEEXT@: rdata_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ rdata_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
rdataset_test@EXEEXT@: rdataset_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
rdataset_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ rdataset_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
rdatasetstats_test@EXEEXT@: rdatasetstats_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
rdatasetstats_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ rdatasetstats_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
resolver_test@EXEEXT@: resolver_test.@O@ dnstest.@O@ \
|
||||
${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
resolver_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
resolver_test@EXEEXT@: resolver_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ resolver_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
result_test@EXEEXT@: result_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ result_test.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
rsa_test@EXEEXT@: rsa_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
rsa_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ rsa_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
sigs_test@EXEEXT@: sigs_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
sigs_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ sigs_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
time_test@EXEEXT@: time_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
time_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ time_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
tsig_test@EXEEXT@: tsig_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
tsig_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ tsig_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
update_test@EXEEXT@: update_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
update_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ update_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
zonemgr_test@EXEEXT@: zonemgr_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
zonemgr_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ zonemgr_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
zt_test@EXEEXT@: zt_test.@O@ dnstest.@O@ \
|
||||
${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
zt_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
zt_test@EXEEXT@: zt_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ zt_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
unit::
|
||||
sh ${top_builddir}/unit/unittest.sh
|
||||
|
|
|
|||
|
|
@ -9,36 +9,59 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/acl.h>
|
||||
|
||||
#include "dnstest.h"
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#define BUFLEN 255
|
||||
#define BIGBUFLEN (70 * 1024)
|
||||
#define TEST_ORIGIN "test"
|
||||
|
||||
ATF_TC(dns_acl_isinsecure);
|
||||
ATF_TC_HEAD(dns_acl_isinsecure, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test that dns_acl_isinsecure works");
|
||||
}
|
||||
ATF_TC_BODY(dns_acl_isinsecure, tc) {
|
||||
/* test that dns_acl_isinsecure works */
|
||||
static void
|
||||
dns_acl_isinsecure_test(void **state) {
|
||||
isc_result_t result;
|
||||
unsigned int pass;
|
||||
struct {
|
||||
|
|
@ -60,7 +83,6 @@ ATF_TC_BODY(dns_acl_isinsecure, tc) {
|
|||
dns_acl_t *notgeoip = NULL;
|
||||
dns_aclelement_t *de;
|
||||
#endif
|
||||
|
||||
dns_acl_t *pos4pos6 = NULL;
|
||||
dns_acl_t *notpos4pos6 = NULL;
|
||||
dns_acl_t *neg4pos6 = NULL;
|
||||
|
|
@ -84,60 +106,57 @@ ATF_TC_BODY(dns_acl_isinsecure, tc) {
|
|||
struct in_addr inaddr;
|
||||
isc_netaddr_t addr;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_acl_any(mctx, &any);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_none(mctx, &none);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, ¬none);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, ¬any);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_merge(notnone, none, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_merge(notany, any, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
#ifdef HAVE_GEOIP
|
||||
result = dns_acl_create(mctx, 1, &geoip);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
de = geoip->elements;
|
||||
ATF_REQUIRE(de != NULL);
|
||||
assert_non_null(de);
|
||||
strlcpy(de->geoip_elem.as_string, "AU",
|
||||
sizeof(de->geoip_elem.as_string));
|
||||
de->geoip_elem.subtype = dns_geoip_country_code;
|
||||
de->type = dns_aclelementtype_geoip;
|
||||
de->negative = false;
|
||||
ATF_REQUIRE(geoip->length < geoip->alloc);
|
||||
assert_true(geoip->length < geoip->alloc);
|
||||
geoip->node_count++;
|
||||
de->node_num = geoip->node_count;
|
||||
geoip->length++;
|
||||
|
||||
result = dns_acl_create(mctx, 1, ¬geoip);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_merge(notgeoip, geoip, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
#endif
|
||||
|
||||
ATF_CHECK(dns_acl_isinsecure(any)); /* any; */
|
||||
ATF_CHECK(!dns_acl_isinsecure(none)); /* none; */
|
||||
ATF_CHECK(!dns_acl_isinsecure(notany)); /* !any; */
|
||||
ATF_CHECK(!dns_acl_isinsecure(notnone)); /* !none; */
|
||||
assert_true(dns_acl_isinsecure(any)); /* any; */
|
||||
assert_false(dns_acl_isinsecure(none)); /* none; */
|
||||
assert_false(dns_acl_isinsecure(notany)); /* !any; */
|
||||
assert_false(dns_acl_isinsecure(notnone)); /* !none; */
|
||||
|
||||
#ifdef HAVE_GEOIP
|
||||
ATF_CHECK(dns_acl_isinsecure(geoip)); /* geoip; */
|
||||
ATF_CHECK(!dns_acl_isinsecure(notgeoip)); /* !geoip; */
|
||||
assert_true(dns_acl_isinsecure(geoip)); /* geoip; */
|
||||
assert_false(dns_acl_isinsecure(notgeoip)); /* !geoip; */
|
||||
#endif
|
||||
|
||||
dns_acl_detach(&any);
|
||||
|
|
@ -151,93 +170,93 @@ ATF_TC_BODY(dns_acl_isinsecure, tc) {
|
|||
|
||||
for (pass = 0; pass < sizeof(ecs)/sizeof(ecs[0]); pass++) {
|
||||
result = dns_acl_create(mctx, 1, &pos4pos6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, ¬pos4pos6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, &neg4pos6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, ¬neg4pos6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, &pos4neg6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, ¬pos4neg6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, &neg4neg6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, ¬neg4neg6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
inaddr.s_addr = htonl(0x0a000000); /* 10.0.0.0 */
|
||||
isc_netaddr_fromin(&addr, &inaddr);
|
||||
result = dns_iptable_addprefix2(pos4pos6->iptable, &addr, 8,
|
||||
true, ecs[pass].first);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
addr.family = AF_INET6; /* 0a00:: */
|
||||
result = dns_iptable_addprefix2(pos4pos6->iptable, &addr, 8,
|
||||
true, ecs[pass].second);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_merge(notpos4pos6, pos4pos6, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
inaddr.s_addr = htonl(0x0a000000); /* !10.0.0.0/8 */
|
||||
isc_netaddr_fromin(&addr, &inaddr);
|
||||
result = dns_iptable_addprefix2(neg4pos6->iptable, &addr, 8,
|
||||
false, ecs[pass].first);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
addr.family = AF_INET6; /* 0a00::/8 */
|
||||
result = dns_iptable_addprefix2(neg4pos6->iptable, &addr, 8,
|
||||
true, ecs[pass].second);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_merge(notneg4pos6, neg4pos6, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
inaddr.s_addr = htonl(0x0a000000); /* 10.0.0.0/8 */
|
||||
isc_netaddr_fromin(&addr, &inaddr);
|
||||
result = dns_iptable_addprefix2(pos4neg6->iptable, &addr, 8,
|
||||
true, ecs[pass].first);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
addr.family = AF_INET6; /* !0a00::/8 */
|
||||
result = dns_iptable_addprefix2(pos4neg6->iptable, &addr, 8,
|
||||
false, ecs[pass].second);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_merge(notpos4neg6, pos4neg6, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
inaddr.s_addr = htonl(0x0a000000); /* !10.0.0.0/8 */
|
||||
isc_netaddr_fromin(&addr, &inaddr);
|
||||
result = dns_iptable_addprefix2(neg4neg6->iptable, &addr, 8,
|
||||
false, ecs[pass].first);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
addr.family = AF_INET6; /* !0a00::/8 */
|
||||
result = dns_iptable_addprefix2(neg4neg6->iptable, &addr, 8,
|
||||
false, ecs[pass].second);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_merge(notneg4neg6, neg4neg6, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK(dns_acl_isinsecure(pos4pos6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notpos4pos6));
|
||||
ATF_CHECK(dns_acl_isinsecure(neg4pos6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notneg4pos6));
|
||||
ATF_CHECK(dns_acl_isinsecure(pos4neg6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notpos4neg6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(neg4neg6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notneg4neg6));
|
||||
assert_true(dns_acl_isinsecure(pos4pos6));
|
||||
assert_false(dns_acl_isinsecure(notpos4pos6));
|
||||
assert_true(dns_acl_isinsecure(neg4pos6));
|
||||
assert_false(dns_acl_isinsecure(notneg4pos6));
|
||||
assert_true(dns_acl_isinsecure(pos4neg6));
|
||||
assert_false(dns_acl_isinsecure(notpos4neg6));
|
||||
assert_false(dns_acl_isinsecure(neg4neg6));
|
||||
assert_false(dns_acl_isinsecure(notneg4neg6));
|
||||
|
||||
dns_acl_detach(&pos4pos6);
|
||||
dns_acl_detach(¬pos4pos6);
|
||||
|
|
@ -249,44 +268,44 @@ ATF_TC_BODY(dns_acl_isinsecure, tc) {
|
|||
dns_acl_detach(¬neg4neg6);
|
||||
|
||||
result = dns_acl_create(mctx, 1, &loop4);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, ¬loop4);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, &loop6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, ¬loop6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
inaddr.s_addr = htonl(0x7f000001); /* 127.0.0.1 */
|
||||
isc_netaddr_fromin(&addr, &inaddr);
|
||||
result = dns_iptable_addprefix2(loop4->iptable, &addr, 32,
|
||||
true, ecs[pass].first);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_merge(notloop4, loop4, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_netaddr_fromin6(&addr, &in6addr_loopback); /* ::1 */
|
||||
result = dns_iptable_addprefix2(loop6->iptable, &addr, 128,
|
||||
true, ecs[pass].first);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_merge(notloop6, loop6, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
if (!ecs[pass].first) {
|
||||
ATF_CHECK(!dns_acl_isinsecure(loop4));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop4));
|
||||
ATF_CHECK(!dns_acl_isinsecure(loop6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop6));
|
||||
assert_false(dns_acl_isinsecure(loop4));
|
||||
assert_false(dns_acl_isinsecure(notloop4));
|
||||
assert_false(dns_acl_isinsecure(loop6));
|
||||
assert_false(dns_acl_isinsecure(notloop6));
|
||||
} else if (ecs[pass].first) {
|
||||
ATF_CHECK(dns_acl_isinsecure(loop4));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop4));
|
||||
ATF_CHECK(dns_acl_isinsecure(loop6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop6));
|
||||
assert_true(dns_acl_isinsecure(loop4));
|
||||
assert_false(dns_acl_isinsecure(notloop4));
|
||||
assert_true(dns_acl_isinsecure(loop6));
|
||||
assert_false(dns_acl_isinsecure(notloop6));
|
||||
}
|
||||
|
||||
dns_acl_detach(&loop4);
|
||||
|
|
@ -295,65 +314,65 @@ ATF_TC_BODY(dns_acl_isinsecure, tc) {
|
|||
dns_acl_detach(¬loop6);
|
||||
|
||||
result = dns_acl_create(mctx, 1, &loop4pos6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, ¬loop4pos6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, &loop4neg6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_create(mctx, 1, ¬loop4neg6);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
inaddr.s_addr = htonl(0x7f000001); /* 127.0.0.1 */
|
||||
isc_netaddr_fromin(&addr, &inaddr);
|
||||
result = dns_iptable_addprefix2(loop4pos6->iptable, &addr, 32,
|
||||
true, ecs[pass].first);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
addr.family = AF_INET6; /* f700:0001::/32 */
|
||||
result = dns_iptable_addprefix2(loop4pos6->iptable, &addr, 32,
|
||||
true, ecs[pass].second);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_merge(notloop4pos6, loop4pos6, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
inaddr.s_addr = htonl(0x7f000001); /* 127.0.0.1 */
|
||||
isc_netaddr_fromin(&addr, &inaddr);
|
||||
result = dns_iptable_addprefix2(loop4neg6->iptable, &addr, 32,
|
||||
true, ecs[pass].first);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
addr.family = AF_INET6; /* !f700:0001::/32 */
|
||||
result = dns_iptable_addprefix2(loop4neg6->iptable, &addr, 32,
|
||||
false, ecs[pass].second);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_acl_merge(notloop4neg6, loop4neg6, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
if (!ecs[pass].first && !ecs[pass].second) {
|
||||
ATF_CHECK(dns_acl_isinsecure(loop4pos6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop4pos6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(loop4neg6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop4neg6));
|
||||
assert_true(dns_acl_isinsecure(loop4pos6));
|
||||
assert_false(dns_acl_isinsecure(notloop4pos6));
|
||||
assert_false(dns_acl_isinsecure(loop4neg6));
|
||||
assert_false(dns_acl_isinsecure(notloop4neg6));
|
||||
} else if (ecs[pass].first && !ecs[pass].second) {
|
||||
ATF_CHECK(dns_acl_isinsecure(loop4pos6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop4pos6));
|
||||
ATF_CHECK(dns_acl_isinsecure(loop4neg6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop4neg6));
|
||||
assert_true(dns_acl_isinsecure(loop4pos6));
|
||||
assert_false(dns_acl_isinsecure(notloop4pos6));
|
||||
assert_true(dns_acl_isinsecure(loop4neg6));
|
||||
assert_false(dns_acl_isinsecure(notloop4neg6));
|
||||
} else if (!ecs[pass].first && ecs[pass].second) {
|
||||
ATF_CHECK(dns_acl_isinsecure(loop4pos6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop4pos6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(loop4neg6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop4neg6));
|
||||
assert_true(dns_acl_isinsecure(loop4pos6));
|
||||
assert_false(dns_acl_isinsecure(notloop4pos6));
|
||||
assert_false(dns_acl_isinsecure(loop4neg6));
|
||||
assert_false(dns_acl_isinsecure(notloop4neg6));
|
||||
} else {
|
||||
ATF_CHECK(dns_acl_isinsecure(loop4pos6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop4pos6));
|
||||
ATF_CHECK(dns_acl_isinsecure(loop4neg6));
|
||||
ATF_CHECK(!dns_acl_isinsecure(notloop4neg6));
|
||||
assert_true(dns_acl_isinsecure(loop4pos6));
|
||||
assert_false(dns_acl_isinsecure(notloop4pos6));
|
||||
assert_true(dns_acl_isinsecure(loop4neg6));
|
||||
assert_false(dns_acl_isinsecure(notloop4neg6));
|
||||
}
|
||||
|
||||
dns_acl_detach(&loop4pos6);
|
||||
|
|
@ -361,14 +380,26 @@ ATF_TC_BODY(dns_acl_isinsecure, tc) {
|
|||
dns_acl_detach(&loop4neg6);
|
||||
dns_acl_detach(¬loop4neg6);
|
||||
}
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, dns_acl_isinsecure);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(dns_acl_isinsecure_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,15 +9,22 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
|
||||
#include <dns/db.h>
|
||||
#include <dns/dbiterator.h>
|
||||
#include <dns/name.h>
|
||||
|
|
@ -25,9 +32,26 @@
|
|||
|
||||
#include "dnstest.h"
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#define BUFLEN 255
|
||||
#define BIGBUFLEN (64 * 1024)
|
||||
|
|
@ -37,101 +61,88 @@
|
|||
* Individual unit tests
|
||||
*/
|
||||
|
||||
ATF_TC(getoriginnode);
|
||||
ATF_TC_HEAD(getoriginnode, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"test multiple calls to dns_db_getoriginnode");
|
||||
}
|
||||
ATF_TC_BODY(getoriginnode, tc) {
|
||||
/* test multiple calls to dns_db_getoriginnode */
|
||||
static void
|
||||
getoriginnode_test(void **state) {
|
||||
dns_db_t *db = NULL;
|
||||
dns_dbnode_t *node = NULL;
|
||||
isc_mem_t *mymctx = NULL;
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_mem_create(0, 0, &mymctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_hash_create(mymctx, NULL, 256);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
result = isc_mem_create(0, 0, &mymctx);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_create(mymctx, "rbt", dns_rootname, dns_dbtype_zone,
|
||||
dns_rdataclass_in, 0, NULL, &db);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_getoriginnode(db, &node);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_db_detachnode(db, &node);
|
||||
|
||||
result = dns_db_getoriginnode(db, &node);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_db_detachnode(db, &node);
|
||||
|
||||
dns_db_detach(&db);
|
||||
isc_mem_detach(&mymctx);
|
||||
}
|
||||
|
||||
ATF_TC(class);
|
||||
ATF_TC_HEAD(class, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "database class");
|
||||
}
|
||||
ATF_TC_BODY(class, tc) {
|
||||
/* database class */
|
||||
static void
|
||||
class_test(void **state) {
|
||||
isc_result_t result;
|
||||
dns_db_t *db = NULL;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
|
||||
dns_rdataclass_in, 0, NULL, &db);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_load(db, "testdata/db/data.db");
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK_EQ(dns_db_class(db), dns_rdataclass_in);
|
||||
assert_int_equal(dns_db_class(db), dns_rdataclass_in);
|
||||
|
||||
dns_db_detach(&db);
|
||||
}
|
||||
|
||||
ATF_TC(dbtype);
|
||||
ATF_TC_HEAD(dbtype, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "database type");
|
||||
}
|
||||
ATF_TC_BODY(dbtype, tc) {
|
||||
/* database type */
|
||||
static void
|
||||
dbtype_test(void **state) {
|
||||
isc_result_t result;
|
||||
dns_db_t *db = NULL;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* DB has zone semantics */
|
||||
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
|
||||
dns_rdataclass_in, 0, NULL, &db);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_db_load(db, "testdata/db/data.db");
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(dns_db_iszone(db));
|
||||
ATF_CHECK(!dns_db_iscache(db));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(dns_db_iszone(db));
|
||||
assert_false(dns_db_iscache(db));
|
||||
dns_db_detach(&db);
|
||||
|
||||
/* DB has cache semantics */
|
||||
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_cache,
|
||||
dns_rdataclass_in, 0, NULL, &db);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_db_load(db, "testdata/db/data.db");
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(dns_db_iscache(db));
|
||||
ATF_CHECK(!dns_db_iszone(db));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(dns_db_iscache(db));
|
||||
assert_false(dns_db_iszone(db));
|
||||
dns_db_detach(&db);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(version);
|
||||
ATF_TC_HEAD(version, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "database versions");
|
||||
}
|
||||
ATF_TC_BODY(version, tc) {
|
||||
/* database versions */
|
||||
static void
|
||||
version_test(void **state) {
|
||||
isc_result_t result;
|
||||
dns_fixedname_t fname, ffound;
|
||||
dns_name_t *name, *foundname;
|
||||
|
|
@ -140,12 +151,11 @@ ATF_TC_BODY(version, tc) {
|
|||
dns_dbnode_t *node = NULL;
|
||||
dns_rdataset_t rdataset;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_loaddb(&db, dns_dbtype_zone, "test.test",
|
||||
"testdata/db/data.db");
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Open current version for reading */
|
||||
dns_db_currentversion(db, &ver);
|
||||
|
|
@ -155,7 +165,7 @@ ATF_TC_BODY(version, tc) {
|
|||
dns_rdataset_init(&rdataset);
|
||||
result = dns_db_find(db, name , ver, dns_rdatatype_a, 0, 0, &node,
|
||||
foundname, &rdataset, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_rdataset_disassociate(&rdataset);
|
||||
dns_db_detachnode(db, &node);
|
||||
dns_db_closeversion(db, &ver, false);
|
||||
|
|
@ -168,14 +178,14 @@ ATF_TC_BODY(version, tc) {
|
|||
dns_rdataset_init(&rdataset);
|
||||
result = dns_db_find(db, name , ver, dns_rdatatype_a, 0, 0, &node,
|
||||
foundname, &rdataset, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_newversion(db, &new);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Delete the rdataset from the new verison */
|
||||
result = dns_db_deleterdataset(db, node, new, dns_rdatatype_a, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_rdataset_disassociate(&rdataset);
|
||||
dns_db_detachnode(db, &node);
|
||||
|
|
@ -183,30 +193,44 @@ ATF_TC_BODY(version, tc) {
|
|||
/* This should fail now */
|
||||
result = dns_db_find(db, name, new, dns_rdatatype_a, 0, 0, &node,
|
||||
foundname, &rdataset, NULL);
|
||||
ATF_REQUIRE_EQ(result, DNS_R_NXDOMAIN);
|
||||
assert_int_equal(result, DNS_R_NXDOMAIN);
|
||||
|
||||
dns_db_closeversion(db, &new, true);
|
||||
|
||||
/* But this should still succeed */
|
||||
result = dns_db_find(db, name, ver, dns_rdatatype_a, 0, 0, &node,
|
||||
foundname, &rdataset, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_rdataset_disassociate(&rdataset);
|
||||
dns_db_detachnode(db, &node);
|
||||
dns_db_closeversion(db, &ver, false);
|
||||
|
||||
dns_db_detach(&db);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, getoriginnode);
|
||||
ATF_TP_ADD_TC(tp, class);
|
||||
ATF_TP_ADD_TC(tp, dbtype);
|
||||
ATF_TP_ADD_TC(tp, version);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(getoriginnode_test),
|
||||
cmocka_unit_test_setup_teardown(class_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(dbtype_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(version_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,15 +9,23 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/db.h>
|
||||
#include <dns/dbiterator.h>
|
||||
|
|
@ -26,141 +34,152 @@
|
|||
|
||||
#include "dnstest.h"
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
|
||||
#define BUFLEN 255
|
||||
#define BIGBUFLEN (64 * 1024)
|
||||
#define TEST_ORIGIN "test"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
test_create(const atf_tc_t *tc, dns_db_t **old, dns_db_t **newdb) {
|
||||
test_create(const char *oldfile, dns_db_t **old,
|
||||
const char *newfile, dns_db_t **newdb)
|
||||
{
|
||||
isc_result_t result;
|
||||
|
||||
result = dns_test_loaddb(old, dns_dbtype_zone, TEST_ORIGIN,
|
||||
atf_tc_get_md_var(tc, "X-old"));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
result = dns_test_loaddb(old, dns_dbtype_zone, TEST_ORIGIN, oldfile);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_loaddb(newdb, dns_dbtype_zone, TEST_ORIGIN,
|
||||
atf_tc_get_md_var(tc, "X-new"));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
result = dns_test_loaddb(newdb, dns_dbtype_zone, TEST_ORIGIN, newfile);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
ATF_TC(diffx_same);
|
||||
ATF_TC_HEAD(diffx_same, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_db_diffx of identical content");
|
||||
atf_tc_set_md_var(tc, "X-old", "testdata/diff/zone1.data");
|
||||
atf_tc_set_md_var(tc, "X-new", "testdata/diff/zone1.data"); }
|
||||
ATF_TC_BODY(diffx_same, tc) {
|
||||
/* dns_db_diffx of identical content */
|
||||
static void
|
||||
diffx_same(void **state) {
|
||||
dns_db_t *newdb = NULL, *olddb = NULL;
|
||||
isc_result_t result;
|
||||
dns_diff_t diff;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
test_create(tc, &olddb, &newdb);
|
||||
test_create("testdata/diff/zone1.data", &olddb,
|
||||
"testdata/diff/zone1.data", &newdb);
|
||||
|
||||
dns_diff_init(mctx, &diff);
|
||||
|
||||
result = dns_db_diffx(&diff, newdb, NULL, olddb, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_REQUIRE_EQ(ISC_LIST_EMPTY(diff.tuples), true);
|
||||
assert_true(ISC_LIST_EMPTY(diff.tuples));
|
||||
|
||||
dns_diff_clear(&diff);
|
||||
dns_db_detach(&newdb);
|
||||
dns_db_detach(&olddb);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(diffx_add);
|
||||
ATF_TC_HEAD(diffx_add, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"dns_db_diffx of zone with record added");
|
||||
atf_tc_set_md_var(tc, "X-old", "testdata/diff/zone1.data");
|
||||
atf_tc_set_md_var(tc, "X-new", "testdata/diff/zone2.data");
|
||||
}
|
||||
ATF_TC_BODY(diffx_add, tc) {
|
||||
/* dns_db_diffx of zone with record added */
|
||||
static void
|
||||
diffx_add(void **state) {
|
||||
dns_db_t *newdb = NULL, *olddb = NULL;
|
||||
dns_difftuple_t *tuple;
|
||||
isc_result_t result;
|
||||
dns_diff_t diff;
|
||||
int count = 0;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
test_create(tc, &olddb, &newdb);
|
||||
test_create("testdata/diff/zone1.data", &olddb,
|
||||
"testdata/diff/zone2.data", &newdb);
|
||||
|
||||
dns_diff_init(mctx, &diff);
|
||||
|
||||
result = dns_db_diffx(&diff, newdb, NULL, olddb, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_REQUIRE_EQ(ISC_LIST_EMPTY(diff.tuples), false);
|
||||
assert_false(ISC_LIST_EMPTY(diff.tuples));
|
||||
for (tuple = ISC_LIST_HEAD(diff.tuples); tuple != NULL;
|
||||
tuple = ISC_LIST_NEXT(tuple, link)) {
|
||||
ATF_REQUIRE_EQ(tuple->op, DNS_DIFFOP_ADD);
|
||||
assert_int_equal(tuple->op, DNS_DIFFOP_ADD);
|
||||
count++;
|
||||
}
|
||||
ATF_REQUIRE_EQ(count, 1);
|
||||
assert_int_equal(count, 1);
|
||||
|
||||
dns_diff_clear(&diff);
|
||||
dns_db_detach(&newdb);
|
||||
dns_db_detach(&olddb);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(diffx_remove);
|
||||
ATF_TC_HEAD(diffx_remove, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"dns_db_diffx of zone with record removed");
|
||||
atf_tc_set_md_var(tc, "X-old", "testdata/diff/zone1.data");
|
||||
atf_tc_set_md_var(tc, "X-new", "testdata/diff/zone3.data");
|
||||
}
|
||||
ATF_TC_BODY(diffx_remove, tc) {
|
||||
/* dns_db_diffx of zone with record removed */
|
||||
static void
|
||||
diffx_remove(void **state) {
|
||||
dns_db_t *newdb = NULL, *olddb = NULL;
|
||||
dns_difftuple_t *tuple;
|
||||
isc_result_t result;
|
||||
dns_diff_t diff;
|
||||
int count = 0;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
test_create(tc, &olddb, &newdb);
|
||||
test_create("testdata/diff/zone1.data", &olddb,
|
||||
"testdata/diff/zone3.data", &newdb);
|
||||
|
||||
dns_diff_init(mctx, &diff);
|
||||
|
||||
result = dns_db_diffx(&diff, newdb, NULL, olddb, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_REQUIRE_EQ(ISC_LIST_EMPTY(diff.tuples), false);
|
||||
assert_false(ISC_LIST_EMPTY(diff.tuples));
|
||||
for (tuple = ISC_LIST_HEAD(diff.tuples); tuple != NULL;
|
||||
tuple = ISC_LIST_NEXT(tuple, link)) {
|
||||
ATF_REQUIRE_EQ(tuple->op, DNS_DIFFOP_DEL);
|
||||
assert_int_equal(tuple->op, DNS_DIFFOP_DEL);
|
||||
count++;
|
||||
}
|
||||
ATF_REQUIRE_EQ(count, 1);
|
||||
assert_int_equal(count, 1);
|
||||
|
||||
dns_diff_clear(&diff);
|
||||
dns_db_detach(&newdb);
|
||||
dns_db_detach(&olddb);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, diffx_same);
|
||||
ATF_TP_ADD_TC(tp, diffx_add);
|
||||
ATF_TP_ADD_TC(tp, diffx_remove);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(diffx_same, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(diffx_add, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(diffx_remove,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,15 +9,23 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/db.h>
|
||||
#include <dns/dbiterator.h>
|
||||
|
|
@ -25,14 +33,31 @@
|
|||
|
||||
#include "dnstest.h"
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
|
||||
#define BUFLEN 255
|
||||
#define BIGBUFLEN (64 * 1024)
|
||||
#define TEST_ORIGIN "test"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
make_name(const char *src, dns_name_t *name) {
|
||||
isc_buffer_t b;
|
||||
|
|
@ -41,53 +66,40 @@ make_name(const char *src, dns_name_t *name) {
|
|||
return (dns_name_fromtext(name, &b, dns_rootname, 0, NULL));
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
/* create: make sure we can create a dbiterator */
|
||||
static void
|
||||
test_create(const atf_tc_t *tc) {
|
||||
test_create(const char *filename) {
|
||||
isc_result_t result;
|
||||
dns_db_t *db = NULL;
|
||||
dns_dbiterator_t *iter = NULL;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
|
||||
atf_tc_get_md_var(tc, "X-filename"));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN, filename);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_createiterator(db, 0, &iter);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_dbiterator_destroy(&iter);
|
||||
dns_db_detach(&db);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(create);
|
||||
ATF_TC_HEAD(create, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create a database iterator");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone1.data");
|
||||
}
|
||||
ATF_TC_BODY(create, tc) {
|
||||
test_create(tc);
|
||||
static void
|
||||
create(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
test_create("testdata/dbiterator/zone1.data");
|
||||
}
|
||||
|
||||
ATF_TC(create_nsec3);
|
||||
ATF_TC_HEAD(create_nsec3, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create a database iterator (NSEC3)");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone2.data");
|
||||
}
|
||||
ATF_TC_BODY(create_nsec3, tc) {
|
||||
test_create(tc);
|
||||
static void
|
||||
create_nsec3(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
test_create("testdata/dbiterator/zone2.data");
|
||||
}
|
||||
|
||||
/* walk: walk a database */
|
||||
static void
|
||||
test_walk(const atf_tc_t *tc) {
|
||||
test_walk(const char *filename, int nodes) {
|
||||
isc_result_t result;
|
||||
dns_db_t *db = NULL;
|
||||
dns_dbiterator_t *iter = NULL;
|
||||
|
|
@ -96,19 +108,13 @@ test_walk(const atf_tc_t *tc) {
|
|||
dns_fixedname_t f;
|
||||
int i = 0;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
name = dns_fixedname_initname(&f);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
|
||||
atf_tc_get_md_var(tc, "X-filename"));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN, filename);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_createiterator(db, 0, &iter);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
for (result = dns_dbiterator_first(iter);
|
||||
result == ISC_R_SUCCESS;
|
||||
|
|
@ -116,40 +122,34 @@ test_walk(const atf_tc_t *tc) {
|
|||
result = dns_dbiterator_current(iter, &node, name);
|
||||
if (result == DNS_R_NEWORIGIN)
|
||||
result = ISC_R_SUCCESS;
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_db_detachnode(db, &node);
|
||||
i++;
|
||||
}
|
||||
|
||||
ATF_CHECK_EQ(i, atoi(atf_tc_get_md_var(tc, "X-nodes")));
|
||||
assert_int_equal(i, nodes);
|
||||
|
||||
dns_dbiterator_destroy(&iter);
|
||||
dns_db_detach(&db);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(walk);
|
||||
ATF_TC_HEAD(walk, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "walk database");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone1.data");
|
||||
atf_tc_set_md_var(tc, "X-nodes", "12");
|
||||
}
|
||||
ATF_TC_BODY(walk, tc) {
|
||||
test_walk(tc);
|
||||
static void
|
||||
walk(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
test_walk("testdata/dbiterator/zone1.data", 12);
|
||||
}
|
||||
|
||||
ATF_TC(walk_nsec3);
|
||||
ATF_TC_HEAD(walk_nsec3, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "walk database");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone2.data");
|
||||
atf_tc_set_md_var(tc, "X-nodes", "33");
|
||||
}
|
||||
ATF_TC_BODY(walk_nsec3, tc) {
|
||||
test_walk(tc);
|
||||
static void
|
||||
walk_nsec3(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
test_walk("testdata/dbiterator/zone2.data", 33);
|
||||
}
|
||||
|
||||
/* reverse: walk database backwards */
|
||||
static void test_reverse(const atf_tc_t *tc) {
|
||||
static void
|
||||
test_reverse(const char *filename) {
|
||||
isc_result_t result;
|
||||
dns_db_t *db = NULL;
|
||||
dns_dbiterator_t *iter = NULL;
|
||||
|
|
@ -158,19 +158,13 @@ static void test_reverse(const atf_tc_t *tc) {
|
|||
dns_fixedname_t f;
|
||||
int i = 0;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
name = dns_fixedname_initname(&f);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
|
||||
atf_tc_get_md_var(tc, "X-filename"));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN, filename);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_createiterator(db, 0, &iter);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
for (result = dns_dbiterator_last(iter);
|
||||
result == ISC_R_SUCCESS;
|
||||
|
|
@ -178,38 +172,34 @@ static void test_reverse(const atf_tc_t *tc) {
|
|||
result = dns_dbiterator_current(iter, &node, name);
|
||||
if (result == DNS_R_NEWORIGIN)
|
||||
result = ISC_R_SUCCESS;
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_db_detachnode(db, &node);
|
||||
i++;
|
||||
}
|
||||
|
||||
ATF_CHECK_EQ(i, 12);
|
||||
assert_int_equal(i, 12);
|
||||
|
||||
dns_dbiterator_destroy(&iter);
|
||||
dns_db_detach(&db);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(reverse);
|
||||
ATF_TC_HEAD(reverse, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "walk database backwards");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone1.data");
|
||||
}
|
||||
ATF_TC_BODY(reverse, tc) {
|
||||
test_reverse(tc);
|
||||
static void
|
||||
reverse(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
test_reverse("testdata/dbiterator/zone1.data");
|
||||
}
|
||||
|
||||
ATF_TC(reverse_nsec3);
|
||||
ATF_TC_HEAD(reverse_nsec3, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "walk database backwards");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone2.data");
|
||||
}
|
||||
ATF_TC_BODY(reverse_nsec3, tc) {
|
||||
test_reverse(tc);
|
||||
static void
|
||||
reverse_nsec3(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
test_reverse("testdata/dbiterator/zone2.data");
|
||||
}
|
||||
|
||||
/* seek: walk database starting at a particular node */
|
||||
static void test_seek(const atf_tc_t *tc) {
|
||||
static void
|
||||
test_seek_node(const char *filename, int nodes) {
|
||||
isc_result_t result;
|
||||
dns_db_t *db = NULL;
|
||||
dns_dbiterator_t *iter = NULL;
|
||||
|
|
@ -218,201 +208,142 @@ static void test_seek(const atf_tc_t *tc) {
|
|||
dns_fixedname_t f1, f2;
|
||||
int i = 0;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
name = dns_fixedname_initname(&f1);
|
||||
seekname = dns_fixedname_initname(&f2);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
|
||||
atf_tc_get_md_var(tc, "X-filename"));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN, filename);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_createiterator(db, 0, &iter);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = make_name("c." TEST_ORIGIN, seekname);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_dbiterator_seek(iter, seekname);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
while (result == ISC_R_SUCCESS) {
|
||||
result = dns_dbiterator_current(iter, &node, name);
|
||||
if (result == DNS_R_NEWORIGIN)
|
||||
result = ISC_R_SUCCESS;
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_db_detachnode(db, &node);
|
||||
result = dns_dbiterator_next(iter);
|
||||
i++;
|
||||
}
|
||||
|
||||
ATF_CHECK_EQ(i, atoi(atf_tc_get_md_var(tc, "X-nodes")));
|
||||
assert_int_equal(i, nodes);
|
||||
|
||||
dns_dbiterator_destroy(&iter);
|
||||
dns_db_detach(&db);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(seek);
|
||||
ATF_TC_HEAD(seek, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "walk database starting at "
|
||||
"a particular node");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone1.data");
|
||||
atf_tc_set_md_var(tc, "X-nodes", "9");
|
||||
}
|
||||
ATF_TC_BODY(seek, tc) {
|
||||
test_seek(tc);
|
||||
static void
|
||||
seek_node(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
test_seek_node("testdata/dbiterator/zone1.data", 9);
|
||||
}
|
||||
|
||||
ATF_TC(seek_nsec3);
|
||||
ATF_TC_HEAD(seek_nsec3, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "walk database starting at "
|
||||
"a particular node");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone2.data");
|
||||
atf_tc_set_md_var(tc, "X-nodes", "30");
|
||||
}
|
||||
ATF_TC_BODY(seek_nsec3, tc) {
|
||||
test_seek(tc);
|
||||
static void
|
||||
seek_node_nsec3(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
test_seek_node("testdata/dbiterator/zone2.data", 30);
|
||||
}
|
||||
|
||||
/*
|
||||
* seek_emty: walk database starting at an empty nonterminal node
|
||||
* (should fail)
|
||||
*/
|
||||
static void test_seek_empty(const atf_tc_t *tc) {
|
||||
static void
|
||||
test_seek_empty(const char *filename) {
|
||||
isc_result_t result;
|
||||
dns_db_t *db = NULL;
|
||||
dns_dbiterator_t *iter = NULL;
|
||||
dns_name_t *seekname;
|
||||
dns_fixedname_t f1;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
seekname = dns_fixedname_initname(&f1);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
|
||||
atf_tc_get_md_var(tc, "X-filename"));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN, filename);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_createiterator(db, 0, &iter);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = make_name("d." TEST_ORIGIN, seekname);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_dbiterator_seek(iter, seekname);
|
||||
ATF_CHECK_EQ(result, DNS_R_PARTIALMATCH);
|
||||
assert_int_equal(result, DNS_R_PARTIALMATCH);
|
||||
|
||||
dns_dbiterator_destroy(&iter);
|
||||
dns_db_detach(&db);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(seek_empty);
|
||||
ATF_TC_HEAD(seek_empty, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "walk database starting at an "
|
||||
"empty nonterminal node");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone1.data");
|
||||
}
|
||||
ATF_TC_BODY(seek_empty, tc) {
|
||||
test_seek_empty(tc);
|
||||
static void
|
||||
seek_empty(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
test_seek_empty("testdata/dbiterator/zone1.data");
|
||||
}
|
||||
|
||||
ATF_TC(seek_empty_nsec3);
|
||||
ATF_TC_HEAD(seek_empty_nsec3, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "walk database starting at an "
|
||||
"empty nonterminal node");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone2.data");
|
||||
}
|
||||
ATF_TC_BODY(seek_empty_nsec3, tc) {
|
||||
test_seek_empty(tc);
|
||||
static void
|
||||
seek_empty_nsec3(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
test_seek_empty("testdata/dbiterator/zone2.data");
|
||||
}
|
||||
|
||||
/*
|
||||
* seek_emty: walk database starting at an empty nonterminal node
|
||||
* (should fail)
|
||||
* seek_nx: walk database starting at a nonexistent node
|
||||
*/
|
||||
static void test_seek_nx(const atf_tc_t *tc) {
|
||||
static void
|
||||
test_seek_nx(const char *filename) {
|
||||
isc_result_t result;
|
||||
dns_db_t *db = NULL;
|
||||
dns_dbiterator_t *iter = NULL;
|
||||
dns_name_t *seekname;
|
||||
dns_fixedname_t f1;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
seekname = dns_fixedname_initname(&f1);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
|
||||
atf_tc_get_md_var(tc, "X-filename"));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN, filename);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_createiterator(db, 0, &iter);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = make_name("nonexistent." TEST_ORIGIN, seekname);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_dbiterator_seek(iter, seekname);
|
||||
ATF_CHECK_EQ(result, DNS_R_PARTIALMATCH);
|
||||
assert_int_equal(result, DNS_R_PARTIALMATCH);
|
||||
|
||||
result = make_name("nonexistent.", seekname);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_dbiterator_seek(iter, seekname);
|
||||
ATF_CHECK_EQ(result, ISC_R_NOTFOUND);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
|
||||
dns_dbiterator_destroy(&iter);
|
||||
dns_db_detach(&db);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(seek_nx);
|
||||
ATF_TC_HEAD(seek_nx, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "attempt to walk database starting "
|
||||
"at a nonexistent node");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone1.data");
|
||||
}
|
||||
ATF_TC_BODY(seek_nx, tc) {
|
||||
test_seek_nx(tc);
|
||||
static void
|
||||
seek_nx(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
test_seek_nx("testdata/dbiterator/zone1.data");
|
||||
}
|
||||
|
||||
ATF_TC(seek_nx_nsec3);
|
||||
ATF_TC_HEAD(seek_nx_nsec3, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "attempt to walk database starting "
|
||||
"at a nonexistent node");
|
||||
atf_tc_set_md_var(tc, "X-filename", "testdata/dbiterator/zone2.data");
|
||||
}
|
||||
ATF_TC_BODY(seek_nx_nsec3, tc) {
|
||||
test_seek_nx(tc);
|
||||
}
|
||||
static void
|
||||
seek_nx_nsec3(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, create);
|
||||
ATF_TP_ADD_TC(tp, create_nsec3);
|
||||
ATF_TP_ADD_TC(tp, walk);
|
||||
ATF_TP_ADD_TC(tp, walk_nsec3);
|
||||
ATF_TP_ADD_TC(tp, reverse);
|
||||
ATF_TP_ADD_TC(tp, reverse_nsec3);
|
||||
ATF_TP_ADD_TC(tp, seek);
|
||||
ATF_TP_ADD_TC(tp, seek_nsec3);
|
||||
ATF_TP_ADD_TC(tp, seek_empty);
|
||||
ATF_TP_ADD_TC(tp, seek_empty_nsec3);
|
||||
ATF_TP_ADD_TC(tp, seek_nx);
|
||||
ATF_TP_ADD_TC(tp, seek_nx_nsec3);
|
||||
return (atf_no_error());
|
||||
test_seek_nx("testdata/dbiterator/zone2.data");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -423,3 +354,39 @@ ATF_TP_ADD_TCS(tp) {
|
|||
* dns_dbiterator_origin
|
||||
* dns_dbiterator_setcleanmode
|
||||
*/
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(create, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(create_nsec3,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(walk, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(walk_nsec3, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(reverse, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(reverse_nsec3,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(seek_node, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(seek_node_nsec3,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(seek_empty, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(seek_empty_nsec3,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(seek_nx, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(seek_nx_nsec3,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -9,17 +9,24 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <isc/util.h>
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <pk11/site.h>
|
||||
|
||||
|
|
@ -31,62 +38,82 @@
|
|||
#include "dnstest.h"
|
||||
|
||||
#if defined(OPENSSL) && !defined(PK11_DH_DISABLE)
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
ATF_TC(isc_dh_computesecret);
|
||||
ATF_TC_HEAD(isc_dh_computesecret, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "OpenSSL DH_compute_key() failure");
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
ATF_TC_BODY(isc_dh_computesecret, tc) {
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* OpenSSL DH_compute_key() failure */
|
||||
static void
|
||||
dh_computesecret(void **state) {
|
||||
dst_key_t *key = NULL;
|
||||
isc_buffer_t buf;
|
||||
unsigned char array[1024];
|
||||
isc_result_t ret;
|
||||
isc_result_t result;
|
||||
dns_fixedname_t fname;
|
||||
dns_name_t *name;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
ret = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
name = dns_fixedname_initname(&fname);
|
||||
isc_buffer_constinit(&buf, "dh.", 3);
|
||||
isc_buffer_add(&buf, 3);
|
||||
ret = dns_name_fromtext(name, &buf, NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
result = dns_name_fromtext(name, &buf, NULL, 0, NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ret = dst_key_fromfile(name, 18602, DST_ALG_DH,
|
||||
DST_TYPE_PUBLIC | DST_TYPE_KEY,
|
||||
"./", mctx, &key);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
result = dst_key_fromfile(name, 18602, DST_ALG_DH,
|
||||
DST_TYPE_PUBLIC | DST_TYPE_KEY,
|
||||
"./", mctx, &key);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_buffer_init(&buf, array, sizeof(array));
|
||||
ret = dst_key_computesecret(key, key, &buf);
|
||||
ATF_REQUIRE_EQ(ret, DST_R_NOTPRIVATEKEY);
|
||||
ret = key->func->computesecret(key, key, &buf);
|
||||
ATF_REQUIRE_EQ(ret, DST_R_COMPUTESECRETFAILURE);
|
||||
result = dst_key_computesecret(key, key, &buf);
|
||||
assert_int_equal(result, DST_R_NOTPRIVATEKEY);
|
||||
result = key->func->computesecret(key, key, &buf);
|
||||
assert_int_equal(result, DST_R_COMPUTESECRETFAILURE);
|
||||
|
||||
dst_key_free(&key);
|
||||
dns_test_end();
|
||||
}
|
||||
#else
|
||||
ATF_TC(untested);
|
||||
ATF_TC_HEAD(untested, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "skipping OpenSSL DH test");
|
||||
}
|
||||
ATF_TC_BODY(untested, tc) {
|
||||
UNUSED(tc);
|
||||
atf_tc_skip("OpenSSL DH not compiled in");
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
|
||||
int
|
||||
main(void) {
|
||||
#if defined(OPENSSL) && !defined(PK11_DH_DISABLE)
|
||||
ATF_TP_ADD_TC(tp, isc_dh_computesecret);
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(dh_computesecret,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
#else
|
||||
ATF_TP_ADD_TC(tp, untested);
|
||||
print_message("1..0 # Skipped: dh test broken with PKCS11");
|
||||
#endif
|
||||
return (atf_no_error());
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,21 +9,30 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/socket.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/timer.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/dispatch.h>
|
||||
#include <dns/name.h>
|
||||
|
|
@ -34,6 +43,27 @@
|
|||
dns_dispatchmgr_t *dispatchmgr = NULL;
|
||||
dns_dispatchset_t *dset = NULL;
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
make_dispatchset(unsigned int ndisps) {
|
||||
isc_result_t result;
|
||||
|
|
@ -61,54 +91,41 @@ make_dispatchset(unsigned int ndisps) {
|
|||
}
|
||||
|
||||
static void
|
||||
teardown(void) {
|
||||
if (dset != NULL)
|
||||
reset(void) {
|
||||
if (dset != NULL) {
|
||||
dns_dispatchset_destroy(&dset);
|
||||
if (dispatchmgr != NULL)
|
||||
}
|
||||
if (dispatchmgr != NULL) {
|
||||
dns_dispatchmgr_destroy(&dispatchmgr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
ATF_TC(dispatchset_create);
|
||||
ATF_TC_HEAD(dispatchset_create, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create dispatch set");
|
||||
}
|
||||
ATF_TC_BODY(dispatchset_create, tc) {
|
||||
/* create dispatch set */
|
||||
static void
|
||||
dispatchset_create(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = make_dispatchset(1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
teardown();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
reset();
|
||||
|
||||
result = make_dispatchset(10);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
teardown();
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
reset();
|
||||
}
|
||||
|
||||
ATF_TC(dispatchset_get);
|
||||
ATF_TC_HEAD(dispatchset_get, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test dispatch set round-robin");
|
||||
}
|
||||
ATF_TC_BODY(dispatchset_get, tc) {
|
||||
/* test dispatch set round-robin */
|
||||
static void
|
||||
dispatchset_get(void **state) {
|
||||
isc_result_t result;
|
||||
dns_dispatch_t *d1, *d2, *d3, *d4, *d5;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = make_dispatchset(1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
d1 = dns_dispatchset_get(dset);
|
||||
d2 = dns_dispatchset_get(dset);
|
||||
|
|
@ -116,15 +133,15 @@ ATF_TC_BODY(dispatchset_get, tc) {
|
|||
d4 = dns_dispatchset_get(dset);
|
||||
d5 = dns_dispatchset_get(dset);
|
||||
|
||||
ATF_CHECK_EQ(d1, d2);
|
||||
ATF_CHECK_EQ(d2, d3);
|
||||
ATF_CHECK_EQ(d3, d4);
|
||||
ATF_CHECK_EQ(d4, d5);
|
||||
assert_int_equal(d1, d2);
|
||||
assert_int_equal(d2, d3);
|
||||
assert_int_equal(d3, d4);
|
||||
assert_int_equal(d4, d5);
|
||||
|
||||
teardown();
|
||||
reset();
|
||||
|
||||
result = make_dispatchset(4);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
d1 = dns_dispatchset_get(dset);
|
||||
d2 = dns_dispatchset_get(dset);
|
||||
|
|
@ -132,14 +149,13 @@ ATF_TC_BODY(dispatchset_get, tc) {
|
|||
d4 = dns_dispatchset_get(dset);
|
||||
d5 = dns_dispatchset_get(dset);
|
||||
|
||||
ATF_CHECK_EQ(d1, d5);
|
||||
ATF_CHECK(d1 != d2);
|
||||
ATF_CHECK(d2 != d3);
|
||||
ATF_CHECK(d3 != d4);
|
||||
ATF_CHECK(d4 != d5);
|
||||
assert_int_equal(d1, d5);
|
||||
assert_true(d1 != d2);
|
||||
assert_true(d2 != d3);
|
||||
assert_true(d3 != d4);
|
||||
assert_true(d4 != d5);
|
||||
|
||||
teardown();
|
||||
dns_test_end();
|
||||
reset();
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -219,7 +235,7 @@ response(isc_task_t *task, isc_event_t *event) {
|
|||
|
||||
if (wasfirst) {
|
||||
result = dns_dispatch_getnext(dispentry, &devent);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
} else {
|
||||
dns_dispatch_removeresponse(&dispentry, &devent);
|
||||
isc_app_shutdown();
|
||||
|
|
@ -234,15 +250,13 @@ startit(isc_task_t *task, isc_event_t *event) {
|
|||
isc_socket_attach(dns_dispatch_getsocket(dispatch), &sock);
|
||||
result = isc_socket_sendto(sock, event->ev_arg, task, senddone, sock,
|
||||
&local, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_event_free(&event);
|
||||
}
|
||||
|
||||
ATF_TC(dispatch_getnext);
|
||||
ATF_TC_HEAD(dispatch_getnext, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test dispatch getnext");
|
||||
}
|
||||
ATF_TC_BODY(dispatch_getnext, tc) {
|
||||
/* test dispatch getnext */
|
||||
static void
|
||||
dispatch_getnext(void **state) {
|
||||
isc_region_t region;
|
||||
isc_result_t result;
|
||||
isc_socket_t *sock = NULL;
|
||||
|
|
@ -253,19 +267,16 @@ ATF_TC_BODY(dispatch_getnext, tc) {
|
|||
unsigned int attrs;
|
||||
unsigned char rbuf[12];
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_mutex_init(&lock);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_task_create(taskmgr, 0, &task);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_dispatchmgr_create(mctx, NULL, &dispatchmgr);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ina.s_addr = htonl(INADDR_LOOPBACK);
|
||||
isc_sockaddr_fromin(&local, &ina, 0);
|
||||
|
|
@ -273,32 +284,32 @@ ATF_TC_BODY(dispatch_getnext, tc) {
|
|||
result = dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr,
|
||||
&local, 512, 6, 1024, 17, 19, attrs,
|
||||
attrs, &dispatch);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Create a local udp nameserver on the loopback.
|
||||
*/
|
||||
result = isc_socket_create(socketmgr, AF_INET, isc_sockettype_udp,
|
||||
&sock);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ina.s_addr = htonl(INADDR_LOOPBACK);
|
||||
isc_sockaddr_fromin(&local, &ina, 0);
|
||||
result = isc_socket_bind(sock, &local, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_socket_getsockname(sock, &local);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
first = true;
|
||||
region.base = rbuf;
|
||||
region.length = sizeof(rbuf);
|
||||
result = isc_socket_recv(sock, ®ion, 1, task, nameserver, sock);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_dispatch_addresponse(dispatch, &local, task, response,
|
||||
NULL, &id, &dispentry);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
memset(message, 0, sizeof(message));
|
||||
message[0] = (id >> 8) & 0xff;
|
||||
|
|
@ -307,12 +318,12 @@ ATF_TC_BODY(dispatch_getnext, tc) {
|
|||
region.base = message;
|
||||
region.length = sizeof(message);
|
||||
result = isc_app_onrun(mctx, task, startit, ®ion);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_app_run();
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK_EQ(responses, 2);
|
||||
assert_int_equal(responses, 2);
|
||||
|
||||
/*
|
||||
* Shutdown nameserver.
|
||||
|
|
@ -326,16 +337,30 @@ ATF_TC_BODY(dispatch_getnext, tc) {
|
|||
*/
|
||||
dns_dispatch_detach(&dispatch);
|
||||
dns_dispatchmgr_destroy(&dispatchmgr);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, dispatchset_create);
|
||||
ATF_TP_ADD_TC(tp, dispatchset_get);
|
||||
ATF_TP_ADD_TC(tp, dispatch_getnext);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(dispatchset_create,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(dispatchset_get,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(dispatch_getnext,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,21 +9,28 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/file.h>
|
||||
#include <isc/stdio.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/types.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/dnstap.h>
|
||||
#include <dns/view.h>
|
||||
|
|
@ -40,85 +47,97 @@
|
|||
#define TAPSAVED "testdata/dnstap/dnstap.saved"
|
||||
#define TAPTEXT "testdata/dnstap/dnstap.text"
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup() {
|
||||
(void) isc_file_remove(TAPFILE);
|
||||
(void) isc_file_remove(TAPSOCK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
ATF_TC(create);
|
||||
ATF_TC_HEAD(create, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "set up dnstap environment");
|
||||
}
|
||||
ATF_TC_BODY(create, tc) {
|
||||
/* set up dnstap environment */
|
||||
static void
|
||||
create_test(void **state) {
|
||||
isc_result_t result;
|
||||
dns_dtenv_t *dtenv = NULL;
|
||||
struct fstrm_iothr_options *fopt;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
cleanup();
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
|
||||
fopt = fstrm_iothr_options_init();
|
||||
ATF_REQUIRE(fopt != NULL);
|
||||
assert_non_null(fopt);
|
||||
fstrm_iothr_options_set_num_input_queues(fopt, 1);
|
||||
|
||||
result = dns_dt_create(mctx, dns_dtmode_file, TAPFILE, &fopt, &dtenv);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
if (dtenv != NULL)
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
if (dtenv != NULL) {
|
||||
dns_dt_detach(&dtenv);
|
||||
if (fopt != NULL)
|
||||
}
|
||||
if (fopt != NULL) {
|
||||
fstrm_iothr_options_destroy(&fopt);
|
||||
}
|
||||
|
||||
ATF_CHECK(isc_file_exists(TAPFILE));
|
||||
assert_true(isc_file_exists(TAPFILE));
|
||||
|
||||
fopt = fstrm_iothr_options_init();
|
||||
ATF_REQUIRE(fopt != NULL);
|
||||
assert_non_null(fopt);
|
||||
fstrm_iothr_options_set_num_input_queues(fopt, 1);
|
||||
|
||||
result = dns_dt_create(mctx, dns_dtmode_unix, TAPSOCK, &fopt, &dtenv);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
if (dtenv != NULL)
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
if (dtenv != NULL) {
|
||||
dns_dt_detach(&dtenv);
|
||||
if (fopt != NULL)
|
||||
}
|
||||
if (fopt != NULL) {
|
||||
fstrm_iothr_options_destroy(&fopt);
|
||||
}
|
||||
|
||||
/* 'create' should succeed, but the file shouldn't exist yet */
|
||||
ATF_CHECK(!isc_file_exists(TAPSOCK));
|
||||
assert_false(isc_file_exists(TAPSOCK));
|
||||
|
||||
fopt = fstrm_iothr_options_init();
|
||||
ATF_REQUIRE(fopt != NULL);
|
||||
assert_non_null(fopt);
|
||||
fstrm_iothr_options_set_num_input_queues(fopt, 1);
|
||||
|
||||
result = dns_dt_create(mctx, 33, TAPSOCK, &fopt, &dtenv);
|
||||
ATF_CHECK_EQ(result, ISC_R_FAILURE);
|
||||
ATF_CHECK_EQ(dtenv, NULL);
|
||||
if (dtenv != NULL)
|
||||
assert_int_equal(result, ISC_R_FAILURE);
|
||||
assert_null(dtenv);
|
||||
if (dtenv != NULL) {
|
||||
dns_dt_detach(&dtenv);
|
||||
if (fopt != NULL)
|
||||
}
|
||||
if (fopt != NULL) {
|
||||
fstrm_iothr_options_destroy(&fopt);
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
dns_dt_shutdown();
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(send);
|
||||
ATF_TC_HEAD(send, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "send dnstap messages");
|
||||
}
|
||||
ATF_TC_BODY(send, tc) {
|
||||
/* send dnstap messages */
|
||||
static void
|
||||
send_test(void **state) {
|
||||
isc_result_t result;
|
||||
dns_dtenv_t *dtenv = NULL;
|
||||
dns_dthandle_t *handle = NULL;
|
||||
|
|
@ -142,21 +161,18 @@ ATF_TC_BODY(send, tc) {
|
|||
isc_time_t p, f;
|
||||
struct fstrm_iothr_options *fopt;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
cleanup();
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_makeview("test", &view);
|
||||
|
||||
fopt = fstrm_iothr_options_init();
|
||||
ATF_REQUIRE(fopt != NULL);
|
||||
assert_non_null(fopt);
|
||||
fstrm_iothr_options_set_num_input_queues(fopt, 1);
|
||||
|
||||
result = dns_dt_create(mctx, dns_dtmode_file, TAPFILE, &fopt, &dtenv);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_dt_attach(dtenv, &view->dtenv);
|
||||
view->dttypes = DNS_DTTYPE_ALL;
|
||||
|
|
@ -168,14 +184,14 @@ ATF_TC_BODY(send, tc) {
|
|||
isc_buffer_constinit(&zb, "example.com.", 12);
|
||||
isc_buffer_add(&zb, 12);
|
||||
result = dns_name_fromtext(zname, &zb, NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
memset(&zr, 0, sizeof(zr));
|
||||
isc_buffer_init(&zb, zone, sizeof(zone));
|
||||
result = dns_compress_init(&cctx, -1, mctx);
|
||||
dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE);
|
||||
result = dns_name_towire(zname, &cctx, &zb);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_compress_invalidate(&cctx);
|
||||
isc_buffer_usedregion(&zb, &zr);
|
||||
|
||||
|
|
@ -190,25 +206,25 @@ ATF_TC_BODY(send, tc) {
|
|||
|
||||
result = dns_test_getdata("testdata/dnstap/query.auth",
|
||||
qambuffer, sizeof(qambuffer), &qasize);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_buffer_init(&qamsg, qambuffer, qasize);
|
||||
isc_buffer_add(&qamsg, qasize);
|
||||
|
||||
result = dns_test_getdata("testdata/dnstap/response.auth",
|
||||
rambuffer, sizeof(rambuffer), &rasize);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_buffer_init(&ramsg, rambuffer, rasize);
|
||||
isc_buffer_add(&ramsg, rasize);
|
||||
|
||||
result = dns_test_getdata("testdata/dnstap/query.recursive", qrmbuffer,
|
||||
sizeof(qrmbuffer), &qrsize);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_buffer_init(&qrmsg, qrmbuffer, qrsize);
|
||||
isc_buffer_add(&qrmsg, qrsize);
|
||||
|
||||
result = dns_test_getdata("testdata/dnstap/response.recursive",
|
||||
rrmbuffer, sizeof(rrmbuffer), &rrsize);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_buffer_init(&rrmsg, rrmbuffer, rrsize);
|
||||
isc_buffer_add(&rrmsg, rrsize);
|
||||
|
||||
|
|
@ -225,8 +241,9 @@ ATF_TC_BODY(send, tc) {
|
|||
break;
|
||||
default:
|
||||
m = &qrmsg;
|
||||
if ((dt & DNS_DTTYPE_RESPONSE) != 0)
|
||||
if ((dt & DNS_DTTYPE_RESPONSE) != 0) {
|
||||
m = &ramsg;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -245,12 +262,8 @@ ATF_TC_BODY(send, tc) {
|
|||
dns_dt_shutdown();
|
||||
dns_view_detach(&view);
|
||||
|
||||
/*
|
||||
* XXX now read back and check content.
|
||||
*/
|
||||
|
||||
result = dns_dt_open(TAPFILE, dns_dtmode_file, mctx, &handle);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
while (dns_dt_getframe(handle, &data, &dsize) == ISC_R_SUCCESS) {
|
||||
dns_dtdata_t *dtdata = NULL;
|
||||
|
|
@ -262,52 +275,48 @@ ATF_TC_BODY(send, tc) {
|
|||
r.length = dsize;
|
||||
|
||||
result = dns_dt_parse(mctx, &r, &dtdata);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
n++;
|
||||
continue;
|
||||
}
|
||||
|
||||
ATF_CHECK_EQ(dtdata->type, expected);
|
||||
if (++n % 8 == 0)
|
||||
assert_int_equal(dtdata->type, expected);
|
||||
if (++n % 8 == 0) {
|
||||
expected <<= 1;
|
||||
}
|
||||
|
||||
dns_dtdata_free(&dtdata);
|
||||
}
|
||||
|
||||
if (fopt != NULL)
|
||||
if (fopt != NULL) {
|
||||
fstrm_iothr_options_destroy(&fopt);
|
||||
if (handle != NULL)
|
||||
}
|
||||
if (handle != NULL) {
|
||||
dns_dt_close(&handle);
|
||||
}
|
||||
cleanup();
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(totext);
|
||||
ATF_TC_HEAD(totext, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dnstap message to text");
|
||||
}
|
||||
ATF_TC_BODY(totext, tc) {
|
||||
/* dnstap message to text */
|
||||
static void
|
||||
totext_test(void **state) {
|
||||
isc_result_t result;
|
||||
dns_dthandle_t *handle = NULL;
|
||||
uint8_t *data;
|
||||
size_t dsize;
|
||||
FILE *fp = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/* make sure text conversion gets the right local time */
|
||||
setenv("TZ", "PST8", 1);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
|
||||
result = dns_dt_open(TAPSAVED, dns_dtmode_file, mctx, &handle);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_stdio_open(TAPTEXT, "r", &fp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
while (dns_dt_getframe(handle, &data, &dsize) == ISC_R_SUCCESS) {
|
||||
dns_dtdata_t *dtdata = NULL;
|
||||
|
|
@ -320,64 +329,69 @@ ATF_TC_BODY(totext, tc) {
|
|||
|
||||
/* read the corresponding line of text */
|
||||
p = fgets(s, sizeof(s), fp);
|
||||
ATF_CHECK_EQ(p, s);
|
||||
if (p == NULL)
|
||||
assert_ptr_equal(p, s);
|
||||
if (p == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
p = strchr(p, '\n');
|
||||
if (p != NULL)
|
||||
if (p != NULL) {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/* parse dnstap frame */
|
||||
result = dns_dt_parse(mctx, &r, &dtdata);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
isc_buffer_allocate(mctx, &b, 2048);
|
||||
ATF_CHECK(b != NULL);
|
||||
if (b == NULL)
|
||||
assert_non_null(b);
|
||||
if (b == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* convert to text and compare */
|
||||
result = dns_dt_datatotext(dtdata, &b);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK_STREQ((char *) isc_buffer_base(b), s);
|
||||
assert_string_equal((char *) isc_buffer_base(b), s);
|
||||
|
||||
dns_dtdata_free(&dtdata);
|
||||
isc_buffer_free(&b);
|
||||
}
|
||||
|
||||
if (handle != NULL)
|
||||
if (handle != NULL) {
|
||||
dns_dt_close(&handle);
|
||||
}
|
||||
cleanup();
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
#endif /* HAVE_DNSTAP */
|
||||
|
||||
int
|
||||
main(void) {
|
||||
#if HAVE_DNSTAP
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(create_test, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(send_test, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(totext_test, _setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
#else
|
||||
ATF_TC(untested);
|
||||
ATF_TC_HEAD(untested, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "skipping dnstap test");
|
||||
print_message("1..0 # Skip dnstap not enabled\n");
|
||||
#endif /* HAVE_DNSTAP */
|
||||
}
|
||||
ATF_TC_BODY(untested, tc) {
|
||||
UNUSED(tc);
|
||||
atf_tc_skip("dnstap not available");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
#ifdef HAVE_DNSTAP
|
||||
ATF_TP_ADD_TC(tp, create);
|
||||
ATF_TP_ADD_TC(tp, send);
|
||||
ATF_TP_ADD_TC(tp, totext);
|
||||
#else
|
||||
ATF_TP_ADD_TC(tp, untested);
|
||||
#endif
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
return (atf_no_error());
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif /* HAVE_CMOCKA */
|
||||
|
|
|
|||
|
|
@ -13,14 +13,21 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if HAVE_CMOCKA
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/entropy.h>
|
||||
|
|
@ -38,6 +45,7 @@
|
|||
#include <isc/timer.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/callbacks.h>
|
||||
#include <dns/db.h>
|
||||
#include <dns/fixedname.h>
|
||||
#include <dns/log.h>
|
||||
|
|
@ -60,7 +68,7 @@ bool app_running = false;
|
|||
int ncpus;
|
||||
bool debug_mem_record = true;
|
||||
|
||||
static bool hash_active = false, dst_active = false;
|
||||
static bool tests_active = false, test_running = false;
|
||||
|
||||
/*
|
||||
* Logging categories: this needs to match the list in bin/named/log.c.
|
||||
|
|
@ -79,16 +87,22 @@ static isc_logcategory_t categories[] = {
|
|||
|
||||
static void
|
||||
cleanup_managers(void) {
|
||||
if (app_running)
|
||||
isc_app_finish();
|
||||
if (socketmgr != NULL)
|
||||
isc_socketmgr_destroy(&socketmgr);
|
||||
if (maintask != NULL)
|
||||
if (maintask != NULL) {
|
||||
isc_task_shutdown(maintask);
|
||||
isc_task_destroy(&maintask);
|
||||
if (taskmgr != NULL)
|
||||
}
|
||||
if (socketmgr != NULL) {
|
||||
isc_socketmgr_destroy(&socketmgr);
|
||||
}
|
||||
if (taskmgr != NULL) {
|
||||
isc_taskmgr_destroy(&taskmgr);
|
||||
if (timermgr != NULL)
|
||||
}
|
||||
if (timermgr != NULL) {
|
||||
isc_timermgr_destroy(&timermgr);
|
||||
}
|
||||
if (app_running) {
|
||||
isc_app_finish();
|
||||
}
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
|
|
@ -111,28 +125,50 @@ create_managers(void) {
|
|||
return (result);
|
||||
}
|
||||
|
||||
int
|
||||
dns_test_init(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
if (debug_mem_record) {
|
||||
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
|
||||
}
|
||||
|
||||
INSIST(mctx == NULL);
|
||||
result = isc_mem_create(0, 0, &mctx);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
|
||||
result = isc_entropy_create(mctx, &ectx);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
|
||||
result = dst_lib_init(mctx, ectx, ISC_ENTROPY_BLOCKING);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
|
||||
result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
|
||||
tests_active = true;
|
||||
return (0);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_test_begin(FILE *logfile, bool start_managers) {
|
||||
isc_result_t result;
|
||||
|
||||
if (start_managers)
|
||||
INSIST(!test_running);
|
||||
test_running = true;
|
||||
|
||||
if (start_managers) {
|
||||
CHECK(isc_app_start());
|
||||
if (debug_mem_record)
|
||||
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
|
||||
CHECK(isc_mem_create(0, 0, &mctx));
|
||||
CHECK(isc_entropy_create(mctx, &ectx));
|
||||
|
||||
CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE));
|
||||
hash_active = true;
|
||||
|
||||
CHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_BLOCKING));
|
||||
dst_active = true;
|
||||
|
||||
}
|
||||
if (logfile != NULL) {
|
||||
isc_logdestination_t destination;
|
||||
isc_logconfig_t *logconfig = NULL;
|
||||
|
||||
INSIST(lctx == NULL);
|
||||
CHECK(isc_log_create(mctx, &lctx, &logconfig));
|
||||
|
||||
isc_log_registercategories(lctx, categories);
|
||||
isc_log_setcontext(lctx);
|
||||
dns_log_init(lctx);
|
||||
|
|
@ -151,16 +187,18 @@ dns_test_begin(FILE *logfile, bool start_managers) {
|
|||
|
||||
dns_result_register();
|
||||
|
||||
if (start_managers)
|
||||
if (start_managers) {
|
||||
CHECK(create_managers());
|
||||
}
|
||||
|
||||
/*
|
||||
* atf-run changes us to a /tmp directory, so tests
|
||||
* The caller might run from another directory, so tests
|
||||
* that access test data files must first chdir to the proper
|
||||
* location.
|
||||
*/
|
||||
if (chdir(TESTS) == -1)
|
||||
if (chdir(TESTS) == -1) {
|
||||
CHECK(ISC_R_FAILURE);
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
|
|
@ -171,24 +209,29 @@ dns_test_begin(FILE *logfile, bool start_managers) {
|
|||
|
||||
void
|
||||
dns_test_end(void) {
|
||||
if (dst_active) {
|
||||
dst_lib_destroy();
|
||||
dst_active = false;
|
||||
}
|
||||
if (hash_active) {
|
||||
isc_hash_destroy();
|
||||
hash_active = false;
|
||||
}
|
||||
if (ectx != NULL)
|
||||
isc_entropy_detach(&ectx);
|
||||
|
||||
cleanup_managers();
|
||||
|
||||
if (lctx != NULL)
|
||||
if (lctx != NULL) {
|
||||
isc_log_destroy(&lctx);
|
||||
}
|
||||
|
||||
if (mctx != NULL)
|
||||
isc_mem_destroy(&mctx);
|
||||
test_running = false;
|
||||
}
|
||||
|
||||
int
|
||||
dns_test_final(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
if (!tests_active) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
isc_hash_destroy();
|
||||
isc_entropy_detach(&ectx);
|
||||
dst_lib_destroy();
|
||||
isc_mem_destroy(&mctx);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -389,7 +432,7 @@ dns_test_tohex(const unsigned char *data, size_t len, char *buf, size_t buflen)
|
|||
memset(buf, 0, buflen);
|
||||
isc_buffer_init(&target, buf, buflen);
|
||||
result = isc_hex_totext((isc_region_t *)&source, 1, " ", &target);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (buf);
|
||||
}
|
||||
|
|
@ -450,11 +493,21 @@ dns_test_getdata(const char *file, unsigned char *buf,
|
|||
return (result);
|
||||
}
|
||||
|
||||
static void
|
||||
nullmsg(dns_rdatacallbacks_t *cb, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
UNUSED(cb);
|
||||
UNUSED(fmt);
|
||||
UNUSED(ap);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
|
||||
dns_rdatatype_t rdtype, unsigned char *dst,
|
||||
size_t dstlen, const char *src)
|
||||
size_t dstlen, const char *src, bool warnings)
|
||||
{
|
||||
dns_rdatacallbacks_t callbacks;
|
||||
isc_buffer_t source, target;
|
||||
isc_lex_t *lex = NULL;
|
||||
isc_result_t result;
|
||||
|
|
@ -493,11 +546,19 @@ dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
|
|||
*/
|
||||
isc_buffer_init(&target, dst, dstlen);
|
||||
|
||||
/*
|
||||
* Set up callbacks so warnings and errors are not printed.
|
||||
*/
|
||||
if (!warnings) {
|
||||
dns_rdatacallbacks_init(&callbacks);
|
||||
callbacks.warn = callbacks.error = nullmsg;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse input string, determining result.
|
||||
*/
|
||||
result = dns_rdata_fromtext(rdata, rdclass, rdtype, lex, dns_rootname,
|
||||
0, mctx, &target, NULL);
|
||||
0, mctx, &target, &callbacks);
|
||||
|
||||
destroy_lexer:
|
||||
isc_lex_destroy(&lex);
|
||||
|
|
@ -514,20 +575,21 @@ dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname) {
|
|||
|
||||
length = strlen(namestr);
|
||||
|
||||
result = isc_buffer_allocate(mctx, &b, length);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
isc_buffer_putmem(b, (const unsigned char *) namestr, length);
|
||||
|
||||
name = dns_fixedname_initname(fname);
|
||||
ATF_REQUIRE(name != NULL);
|
||||
|
||||
result = isc_buffer_allocate(mctx, &b, length);
|
||||
|
||||
isc_buffer_putmem(b, (const unsigned char *) namestr, length);
|
||||
result = dns_name_fromtext(name, b, dns_rootname, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_buffer_free(&b);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes) {
|
||||
dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes,
|
||||
bool warnings)
|
||||
{
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
unsigned char rdata_buf[1024];
|
||||
dns_difftuple_t *tuple = NULL;
|
||||
|
|
@ -571,7 +633,8 @@ dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes) {
|
|||
result = dns_test_rdatafromstring(&rdata, dns_rdataclass_in,
|
||||
rdatatype, rdata_buf,
|
||||
sizeof(rdata_buf),
|
||||
changes[i].rdata);
|
||||
changes[i].rdata,
|
||||
warnings);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -594,3 +657,4 @@ dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes) {
|
|||
|
||||
return (result);
|
||||
}
|
||||
#endif /* HAVE_CMOCKA */
|
||||
|
|
|
|||
|
|
@ -59,12 +59,22 @@ extern bool app_running;
|
|||
extern int ncpus;
|
||||
extern bool debug_mem_record;
|
||||
|
||||
/* Run once before all tests */
|
||||
int
|
||||
dns_test_init(void **);
|
||||
|
||||
/* Can be run before each test case */
|
||||
isc_result_t
|
||||
dns_test_begin(FILE *logfile, bool create_managers);
|
||||
|
||||
/* Can be after each test case */
|
||||
void
|
||||
dns_test_end(void);
|
||||
|
||||
/* Run once after all tests */
|
||||
int
|
||||
dns_test_final(void **);
|
||||
|
||||
isc_result_t
|
||||
dns_test_makeview(const char *name, dns_view_t **viewp);
|
||||
|
||||
|
|
@ -118,11 +128,12 @@ dns_test_tohex(const unsigned char *data, size_t len, char *buf, size_t buflen);
|
|||
* Try parsing text form RDATA in "src" (of class "rdclass" and type "rdtype")
|
||||
* into a structure representing that RDATA at "rdata", storing the
|
||||
* uncompressed wire form of that RDATA at "dst", which is "dstlen" bytes long.
|
||||
* Set 'warnings' to true to print logged warnings from dns_rdata_fromtext().
|
||||
*/
|
||||
isc_result_t
|
||||
dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
|
||||
dns_rdatatype_t rdtype, unsigned char *dst,
|
||||
size_t dstlen, const char *src);
|
||||
size_t dstlen, const char *src, bool warnings);
|
||||
|
||||
void
|
||||
dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname);
|
||||
|
|
@ -130,6 +141,8 @@ dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname);
|
|||
/*%
|
||||
* Given a pointer to an uninitialized dns_diff_t structure in 'diff', make it
|
||||
* contain diff tuples representing zone database changes listed in 'changes'.
|
||||
* Set 'warnings' to true to print logged warnings from dns_rdata_fromtext().
|
||||
*/
|
||||
isc_result_t
|
||||
dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes);
|
||||
dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes,
|
||||
bool warnings);
|
||||
|
|
|
|||
|
|
@ -9,19 +9,26 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/file.h>
|
||||
#include <isc/util.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/stdio.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dst/dst.h>
|
||||
#include <dst/result.h>
|
||||
|
|
@ -30,14 +37,28 @@
|
|||
|
||||
#include "dnstest.h"
|
||||
|
||||
ATF_TC(sig);
|
||||
ATF_TC_HEAD(sig, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "signature ineffability");
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read sig in file at path to buf.
|
||||
*/
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Read sig in file at path to buf. Check signature ineffability */
|
||||
static isc_result_t
|
||||
sig_fromfile(const char *path, isc_buffer_t *buf) {
|
||||
isc_result_t result;
|
||||
|
|
@ -48,19 +69,19 @@ sig_fromfile(const char *path, isc_buffer_t *buf) {
|
|||
off_t size;
|
||||
|
||||
result = isc_stdio_open(path, "rb", &fp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_file_getsizefd(fileno(fp), &size);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
data = isc_mem_get(mctx, (size + 1));
|
||||
ATF_REQUIRE(data != NULL);
|
||||
assert_non_null(data);
|
||||
|
||||
len = (size_t)size;
|
||||
p = data;
|
||||
while (len != 0U) {
|
||||
result = isc_stdio_read(p, 1, len, fp, &rval);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
len -= rval;
|
||||
p += rval;
|
||||
}
|
||||
|
|
@ -73,8 +94,9 @@ sig_fromfile(const char *path, isc_buffer_t *buf) {
|
|||
++p;
|
||||
--len;
|
||||
continue;
|
||||
} else if (len < 2U)
|
||||
} else if (len < 2U) {
|
||||
goto err;
|
||||
}
|
||||
if (('0' <= *p) && (*p <= '9')) {
|
||||
val = *p - '0';
|
||||
} else if (('A' <= *p) && (*p <= 'F')) {
|
||||
|
|
@ -129,19 +151,19 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
|
|||
* Read data from file in a form usable by dst_verify.
|
||||
*/
|
||||
result = isc_stdio_open(datapath, "rb", &fp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_file_getsizefd(fileno(fp), &size);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
data = isc_mem_get(mctx, (size + 1));
|
||||
ATF_REQUIRE(data != NULL);
|
||||
assert_non_null(data);
|
||||
|
||||
p = data;
|
||||
len = (size_t)size;
|
||||
do {
|
||||
result = isc_stdio_read(p, 1, len, fp, &rval);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
len -= rval;
|
||||
p += rval;
|
||||
} while (len);
|
||||
|
|
@ -154,10 +176,10 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
|
|||
isc_buffer_constinit(&b, keyname, strlen(keyname));
|
||||
isc_buffer_add(&b, strlen(keyname));
|
||||
result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dst_key_fromfile(name, id, alg, type, "testdata/dst",
|
||||
mctx, &key);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_buffer_init(&databuf, data, (unsigned int)size);
|
||||
isc_buffer_add(&databuf, (unsigned int)size);
|
||||
|
|
@ -170,7 +192,7 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
|
|||
* Read precomputed signature from file in a form usable by dst_verify.
|
||||
*/
|
||||
result = sig_fromfile(sigpath, &sigbuf);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Verify that the key signed the data.
|
||||
|
|
@ -179,13 +201,13 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
|
|||
|
||||
result = dst_context_create3(key, mctx, DNS_LOGCATEGORY_GENERAL,
|
||||
false, &ctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dst_context_adddata(ctx, &datareg);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dst_context_verify(ctx, &sigreg);
|
||||
|
||||
ATF_REQUIRE((expect && (result == ISC_R_SUCCESS)) ||
|
||||
assert_true((expect && (result == ISC_R_SUCCESS)) ||
|
||||
(!expect && (result != ISC_R_SUCCESS)));
|
||||
|
||||
|
||||
|
|
@ -196,13 +218,10 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
|
|||
return;
|
||||
}
|
||||
|
||||
ATF_TC_BODY(sig, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
sig_test(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
struct {
|
||||
const char *datapath;
|
||||
const char *sigpath;
|
||||
|
|
@ -249,15 +268,25 @@ ATF_TC_BODY(sig, tc) {
|
|||
DST_TYPE_PRIVATE|DST_TYPE_PUBLIC,
|
||||
testcases[i].expect);
|
||||
}
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, sig);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(sig_test, _setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,19 +9,26 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/types.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/geoip.h>
|
||||
|
||||
|
|
@ -33,6 +40,27 @@
|
|||
/* We use GeoIP databases from the 'geoip' system test */
|
||||
#define TEST_GEOIP_DATA "../../../bin/tests/system/geoip/data"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
* (Mostly copied from bin/named/geoip.c)
|
||||
|
|
@ -45,7 +73,6 @@ static void
|
|||
init_geoip_db(GeoIP **dbp, GeoIPDBTypes edition, GeoIPDBTypes fallback,
|
||||
GeoIPOptions method, const char *name)
|
||||
{
|
||||
char *info;
|
||||
GeoIP *db;
|
||||
|
||||
REQUIRE(dbp != NULL);
|
||||
|
|
@ -58,34 +85,21 @@ init_geoip_db(GeoIP **dbp, GeoIPDBTypes edition, GeoIPDBTypes fallback,
|
|||
}
|
||||
|
||||
if (! GeoIP_db_avail(edition)) {
|
||||
fprintf(stderr, "GeoIP %s (type %d) DB not available\n",
|
||||
name, edition);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fprintf(stderr, "initializing GeoIP %s (type %d) DB\n",
|
||||
name, edition);
|
||||
|
||||
db = GeoIP_open_type(edition, method);
|
||||
if (db == NULL) {
|
||||
fprintf(stderr,
|
||||
"failed to initialize GeoIP %s (type %d) DB%s\n",
|
||||
name, edition, fallback == 0
|
||||
? "; geoip matches using this database will fail"
|
||||
: "");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
info = GeoIP_database_info(db);
|
||||
if (info != NULL)
|
||||
fprintf(stderr, "%s\n", info);
|
||||
|
||||
*dbp = db;
|
||||
return;
|
||||
|
||||
fail:
|
||||
if (fallback != 0)
|
||||
if (fallback != 0) {
|
||||
init_geoip_db(dbp, fallback, 0, method, name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -183,259 +197,205 @@ do_lookup_int(const char *addr, uint8_t *scope,
|
|||
return (dns_geoip_match(&na, scope, &geoip, &elt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
/* GeoIP country matching */
|
||||
ATF_TC(country);
|
||||
ATF_TC_HEAD(country, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test country database matching");
|
||||
}
|
||||
ATF_TC_BODY(country, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
country(void **state) {
|
||||
bool match;
|
||||
uint8_t scope;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.country_v4 == NULL) {
|
||||
dns_test_end();
|
||||
atf_tc_skip("Database not available");
|
||||
skip();
|
||||
}
|
||||
|
||||
match = do_lookup_string("10.53.0.1", &scope,
|
||||
dns_geoip_country_code, "AU");
|
||||
ATF_CHECK(match);
|
||||
ATF_CHECK_EQ(scope, 32);
|
||||
assert_true(match);
|
||||
assert_int_equal(scope, 32);
|
||||
|
||||
match = do_lookup_string("10.53.0.1", &scope,
|
||||
dns_geoip_country_code3, "AUS");
|
||||
ATF_CHECK(match);
|
||||
ATF_CHECK_EQ(scope, 32);
|
||||
assert_true(match);
|
||||
assert_int_equal(scope, 32);
|
||||
|
||||
match = do_lookup_string("10.53.0.1", &scope,
|
||||
dns_geoip_country_name, "Australia");
|
||||
ATF_CHECK(match);
|
||||
ATF_CHECK_EQ(scope, 32);
|
||||
assert_true(match);
|
||||
assert_int_equal(scope, 32);
|
||||
|
||||
match = do_lookup_string("192.0.2.128", &scope,
|
||||
dns_geoip_country_code, "O1");
|
||||
ATF_CHECK(match);
|
||||
ATF_CHECK_EQ(scope, 24);
|
||||
assert_true(match);
|
||||
assert_int_equal(scope, 24);
|
||||
|
||||
match = do_lookup_string("192.0.2.128", &scope,
|
||||
dns_geoip_country_name, "Other");
|
||||
ATF_CHECK(match);
|
||||
ATF_CHECK_EQ(scope, 24);
|
||||
|
||||
dns_test_end();
|
||||
assert_true(match);
|
||||
assert_int_equal(scope, 24);
|
||||
}
|
||||
|
||||
/* GeoIP country (ipv6) matching */
|
||||
ATF_TC(country_v6);
|
||||
ATF_TC_HEAD(country_v6, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test country (ipv6) database matching");
|
||||
}
|
||||
ATF_TC_BODY(country_v6, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
country_v6(void **state) {
|
||||
bool match;
|
||||
uint8_t scope;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.country_v6 == NULL) {
|
||||
dns_test_end();
|
||||
atf_tc_skip("Database not available");
|
||||
skip();
|
||||
}
|
||||
|
||||
match = do_lookup_string_v6("fd92:7065:b8e:ffff::1", &scope,
|
||||
dns_geoip_country_code, "AU");
|
||||
ATF_CHECK(match);
|
||||
ATF_CHECK_EQ(scope, 128);
|
||||
assert_true(match);
|
||||
assert_int_equal(scope, 128);
|
||||
|
||||
match = do_lookup_string_v6("fd92:7065:b8e:ffff::1", &scope,
|
||||
dns_geoip_country_code3, "AUS");
|
||||
ATF_CHECK(match);
|
||||
ATF_CHECK_EQ(scope, 128);
|
||||
assert_true(match);
|
||||
assert_int_equal(scope, 128);
|
||||
|
||||
match = do_lookup_string_v6("fd92:7065:b8e:ffff::1", &scope,
|
||||
dns_geoip_country_name, "Australia");
|
||||
ATF_CHECK(match);
|
||||
ATF_CHECK_EQ(scope, 128);
|
||||
|
||||
dns_test_end();
|
||||
assert_true(match);
|
||||
assert_int_equal(scope, 128);
|
||||
}
|
||||
|
||||
/* GeoIP city (ipv4) matching */
|
||||
ATF_TC(city);
|
||||
ATF_TC_HEAD(city, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test city database matching");
|
||||
}
|
||||
ATF_TC_BODY(city, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
city(void **state) {
|
||||
bool match;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.city_v4 == NULL) {
|
||||
dns_test_end();
|
||||
atf_tc_skip("Database not available");
|
||||
skip();
|
||||
}
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL,
|
||||
dns_geoip_city_continentcode, "NA");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL,
|
||||
dns_geoip_city_countrycode, "US");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL,
|
||||
dns_geoip_city_countrycode3, "USA");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL,
|
||||
dns_geoip_city_countryname, "United States");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL,
|
||||
dns_geoip_city_region, "CA");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL,
|
||||
dns_geoip_city_regionname, "California");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL,
|
||||
dns_geoip_city_name, "Redwood City");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL,
|
||||
dns_geoip_city_postalcode, "94063");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_int("10.53.0.1", NULL, dns_geoip_city_areacode, 650);
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_int("10.53.0.1", NULL, dns_geoip_city_metrocode, 807);
|
||||
ATF_CHECK(match);
|
||||
|
||||
dns_test_end();
|
||||
assert_true(match);
|
||||
}
|
||||
|
||||
/* GeoIP city (ipv6) matching */
|
||||
ATF_TC(city_v6);
|
||||
ATF_TC_HEAD(city_v6, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test city (ipv6) database matching");
|
||||
}
|
||||
ATF_TC_BODY(city_v6, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
city_v6(void **state) {
|
||||
bool match;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.city_v6 == NULL) {
|
||||
dns_test_end();
|
||||
atf_tc_skip("Database not available");
|
||||
skip();
|
||||
}
|
||||
|
||||
match = do_lookup_string_v6("fd92:7065:b8e:ffff::1", NULL,
|
||||
dns_geoip_city_continentcode, "NA");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string_v6("fd92:7065:b8e:ffff::1", NULL,
|
||||
dns_geoip_city_countrycode, "US");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string_v6("fd92:7065:b8e:ffff::1", NULL,
|
||||
dns_geoip_city_countrycode3, "USA");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string_v6("fd92:7065:b8e:ffff::1", NULL,
|
||||
dns_geoip_city_countryname,
|
||||
"United States");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string_v6("fd92:7065:b8e:ffff::1", NULL,
|
||||
dns_geoip_city_region, "CA");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string_v6("fd92:7065:b8e:ffff::1", NULL,
|
||||
dns_geoip_city_regionname, "California");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string_v6("fd92:7065:b8e:ffff::1", NULL,
|
||||
dns_geoip_city_name, "Redwood City");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string_v6("fd92:7065:b8e:ffff::1", NULL,
|
||||
dns_geoip_city_postalcode, "94063");
|
||||
ATF_CHECK(match);
|
||||
|
||||
dns_test_end();
|
||||
assert_true(match);
|
||||
}
|
||||
|
||||
|
||||
/* GeoIP region matching */
|
||||
ATF_TC(region);
|
||||
ATF_TC_HEAD(region, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test region database matching");
|
||||
}
|
||||
ATF_TC_BODY(region, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
region(void **state) {
|
||||
bool match;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.region == NULL) {
|
||||
dns_test_end();
|
||||
atf_tc_skip("Database not available");
|
||||
skip();
|
||||
}
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL,
|
||||
dns_geoip_region_code, "CA");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL,
|
||||
dns_geoip_region_name, "California");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL,
|
||||
dns_geoip_region_countrycode, "US");
|
||||
ATF_CHECK(match);
|
||||
|
||||
dns_test_end();
|
||||
assert_true(match);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -444,53 +404,45 @@ ATF_TC_BODY(region, tc) {
|
|||
* should come from city database. With city database unavailable, region
|
||||
* database. Region database unavailable, country database.)
|
||||
*/
|
||||
ATF_TC(best);
|
||||
ATF_TC_HEAD(best, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test best database matching");
|
||||
}
|
||||
ATF_TC_BODY(best, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
best(void **state) {
|
||||
bool match;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.region == NULL) {
|
||||
dns_test_end();
|
||||
atf_tc_skip("Database not available");
|
||||
skip();
|
||||
}
|
||||
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_countrycode, "US");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_countrycode3, "USA");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_countryname, "United States");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_regionname, "Virginia");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_region, "VA");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
GeoIP_delete(geoip.city_v4);
|
||||
geoip.city_v4 = NULL;
|
||||
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_countrycode, "AU");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
/*
|
||||
* Note, region doesn't support code3 or countryname, so
|
||||
|
|
@ -498,214 +450,165 @@ ATF_TC_BODY(best, tc) {
|
|||
*/
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_countrycode3, "CAN");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_countryname, "Canada");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
GeoIP_delete(geoip.region);
|
||||
geoip.region = NULL;
|
||||
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_countrycode, "CA");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_countrycode3, "CAN");
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_countryname, "Canada");
|
||||
ATF_CHECK(match);
|
||||
|
||||
dns_test_end();
|
||||
assert_true(match);
|
||||
}
|
||||
|
||||
|
||||
/* GeoIP asnum matching */
|
||||
ATF_TC(asnum);
|
||||
ATF_TC_HEAD(asnum, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test asnum database matching");
|
||||
}
|
||||
ATF_TC_BODY(asnum, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
asnum(void **state) {
|
||||
bool match;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.as == NULL) {
|
||||
dns_test_end();
|
||||
atf_tc_skip("Database not available");
|
||||
skip();
|
||||
}
|
||||
|
||||
|
||||
match = do_lookup_string("10.53.0.3", NULL, dns_geoip_as_asnum,
|
||||
"AS100003 Three Network Labs");
|
||||
ATF_CHECK(match);
|
||||
|
||||
dns_test_end();
|
||||
assert_true(match);
|
||||
}
|
||||
|
||||
/* GeoIP isp matching */
|
||||
ATF_TC(isp);
|
||||
ATF_TC_HEAD(isp, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test isp database matching");
|
||||
}
|
||||
ATF_TC_BODY(isp, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
isp(void **state) {
|
||||
bool match;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.isp == NULL) {
|
||||
dns_test_end();
|
||||
atf_tc_skip("Database not available");
|
||||
skip();
|
||||
}
|
||||
|
||||
match = do_lookup_string("10.53.0.1", NULL, dns_geoip_isp_name,
|
||||
"One Systems, Inc.");
|
||||
ATF_CHECK(match);
|
||||
|
||||
dns_test_end();
|
||||
assert_true(match);
|
||||
}
|
||||
|
||||
/* GeoIP org matching */
|
||||
ATF_TC(org);
|
||||
ATF_TC_HEAD(org, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test org database matching");
|
||||
}
|
||||
ATF_TC_BODY(org, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
org(void **state) {
|
||||
bool match;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.org == NULL) {
|
||||
dns_test_end();
|
||||
atf_tc_skip("Database not available");
|
||||
skip();
|
||||
}
|
||||
|
||||
match = do_lookup_string("10.53.0.2", NULL, dns_geoip_org_name,
|
||||
"Two Technology Ltd.");
|
||||
ATF_CHECK(match);
|
||||
|
||||
dns_test_end();
|
||||
assert_true(match);
|
||||
}
|
||||
|
||||
/* GeoIP domain matching */
|
||||
ATF_TC(domain);
|
||||
ATF_TC_HEAD(domain, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test domain database matching");
|
||||
}
|
||||
ATF_TC_BODY(domain, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
domain(void **state) {
|
||||
bool match;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.domain == NULL) {
|
||||
dns_test_end();
|
||||
atf_tc_skip("Database not available");
|
||||
skip();
|
||||
}
|
||||
|
||||
match = do_lookup_string("10.53.0.4", NULL,
|
||||
dns_geoip_domain_name, "four.com");
|
||||
ATF_CHECK(match);
|
||||
|
||||
dns_test_end();
|
||||
assert_true(match);
|
||||
}
|
||||
|
||||
/* GeoIP netspeed matching */
|
||||
ATF_TC(netspeed);
|
||||
ATF_TC_HEAD(netspeed, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test netspeed database matching");
|
||||
}
|
||||
ATF_TC_BODY(netspeed, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
netspeed(void **state) {
|
||||
bool match;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.netspeed == NULL) {
|
||||
dns_test_end();
|
||||
atf_tc_skip("Database not available");
|
||||
skip();
|
||||
}
|
||||
|
||||
match = do_lookup_int("10.53.0.1", NULL, dns_geoip_netspeed_id, 0);
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_int("10.53.0.2", NULL, dns_geoip_netspeed_id, 1);
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_int("10.53.0.3", NULL, dns_geoip_netspeed_id, 2);
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
|
||||
match = do_lookup_int("10.53.0.4", NULL, dns_geoip_netspeed_id, 3);
|
||||
ATF_CHECK(match);
|
||||
assert_true(match);
|
||||
}
|
||||
#endif /* HAVE_GEOIP */
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
#else
|
||||
ATF_TC(untested);
|
||||
ATF_TC_HEAD(untested, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "skipping geoip test");
|
||||
}
|
||||
ATF_TC_BODY(untested, tc) {
|
||||
UNUSED(tc);
|
||||
atf_tc_skip("GeoIP not available");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
int
|
||||
main(void) {
|
||||
#ifdef HAVE_GEOIP
|
||||
ATF_TP_ADD_TC(tp, country);
|
||||
ATF_TP_ADD_TC(tp, country_v6);
|
||||
ATF_TP_ADD_TC(tp, city);
|
||||
ATF_TP_ADD_TC(tp, city_v6);
|
||||
ATF_TP_ADD_TC(tp, region);
|
||||
ATF_TP_ADD_TC(tp, best);
|
||||
ATF_TP_ADD_TC(tp, asnum);
|
||||
ATF_TP_ADD_TC(tp, isp);
|
||||
ATF_TP_ADD_TC(tp, org);
|
||||
ATF_TP_ADD_TC(tp, domain);
|
||||
ATF_TP_ADD_TC(tp, netspeed);
|
||||
#else
|
||||
ATF_TP_ADD_TC(tp, untested);
|
||||
#endif
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(country, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(country_v6, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(city, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(city_v6, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(region, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(best, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(asnum, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(isp, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(org, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(domain, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(netspeed, _setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
#else
|
||||
print_message("1..0 # Skip geoip not enabled\n");
|
||||
#endif /* HAVE_GEOIP */
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif /* HAVE_CMOCKA */
|
||||
|
|
|
|||
|
|
@ -9,16 +9,21 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/util.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/string.h>
|
||||
|
|
@ -43,6 +48,27 @@
|
|||
#endif
|
||||
|
||||
#if defined(HAVE_OPENSSL_GOST) || defined(HAVE_PKCS11_GOST)
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test data from Wikipedia GOST (hash function)
|
||||
*/
|
||||
|
|
@ -87,16 +113,13 @@ typedef struct hash_testcase {
|
|||
int repeats;
|
||||
} hash_testcase_t;
|
||||
|
||||
ATF_TC(isc_gost_md);
|
||||
ATF_TC_HEAD(isc_gost_md, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"GOST R 34.11-94 examples from Wikipedia");
|
||||
}
|
||||
ATF_TC_BODY(isc_gost_md, tc) {
|
||||
/* GOST R 34.11-94 examples from Wikipedia */
|
||||
static void
|
||||
isc_gost_md(void **state) {
|
||||
isc_gost_t gost;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -190,37 +213,29 @@ ATF_TC_BODY(isc_gost_md, tc) {
|
|||
{ NULL, 0, NULL, 1 }
|
||||
};
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
|
||||
hash_testcase_t *testcase = testcases;
|
||||
|
||||
while (testcase->input != NULL && testcase->result != NULL) {
|
||||
result = isc_gost_init(&gost);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
for(i = 0; i < testcase->repeats; i++) {
|
||||
result = isc_gost_update(&gost,
|
||||
(const uint8_t *) testcase->input,
|
||||
testcase->input_len);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
result = isc_gost_final(&gost, digest);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
tohexstr(digest, ISC_GOST_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
}
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(isc_gost_private);
|
||||
ATF_TC_HEAD(isc_gost_private, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "GOST R 34.10-2001 private key");
|
||||
}
|
||||
ATF_TC_BODY(isc_gost_private, tc) {
|
||||
isc_result_t result;
|
||||
/* GOST R 34.10-2001 private key */
|
||||
static void
|
||||
isc_gost_private(void **state) {
|
||||
unsigned char privraw[31] = {
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
|
||||
|
|
@ -260,46 +275,43 @@ ATF_TC_BODY(isc_gost_private, tc) {
|
|||
int len;
|
||||
unsigned char *q;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* raw parse */
|
||||
privkey = BN_bin2bn(privraw, (int) sizeof(privraw), NULL);
|
||||
ATF_REQUIRE(privkey != NULL);
|
||||
assert_non_null(privkey);
|
||||
p = gost_dummy_key;
|
||||
pkey = NULL;
|
||||
ATF_REQUIRE(d2i_PrivateKey(NID_id_GostR3410_2001, &pkey, &p,
|
||||
(long) sizeof(gost_dummy_key)) != NULL);
|
||||
ATF_REQUIRE(pkey != NULL);
|
||||
ATF_REQUIRE(EVP_PKEY_bits(pkey) == 256);
|
||||
assert_non_null(d2i_PrivateKey(NID_id_GostR3410_2001, &pkey, &p,
|
||||
(long) sizeof(gost_dummy_key)));
|
||||
assert_non_null(pkey);
|
||||
assert_int_equal(EVP_PKEY_bits(pkey), 256);
|
||||
eckey = EVP_PKEY_get0(pkey);
|
||||
ATF_REQUIRE(eckey != NULL);
|
||||
ATF_REQUIRE(EC_KEY_set_private_key(eckey, privkey) == 1);
|
||||
assert_non_null(eckey);
|
||||
assert_int_equal(EC_KEY_set_private_key(eckey, privkey), 1);
|
||||
BN_clear_free(privkey);
|
||||
|
||||
/* asn1 tofile */
|
||||
len = i2d_PrivateKey(pkey, NULL);
|
||||
ATF_REQUIRE(len == 70);
|
||||
assert_int_equal(len, 70);
|
||||
q = abuf;
|
||||
ATF_REQUIRE(i2d_PrivateKey(pkey, &q) == len);
|
||||
ATF_REQUIRE(memcmp(abuf, privasn1, len) == 0);
|
||||
assert_int_equal(i2d_PrivateKey(pkey, &q), len);
|
||||
assert_int_equal(memcmp(abuf, privasn1, len), 0);
|
||||
EVP_PKEY_free(pkey);
|
||||
|
||||
/* asn1 parse */
|
||||
p = privasn1;
|
||||
pkey = NULL;
|
||||
ATF_REQUIRE(d2i_PrivateKey(NID_id_GostR3410_2001, &pkey, &p,
|
||||
(long) len) != NULL);
|
||||
ATF_REQUIRE(pkey != NULL);
|
||||
assert_non_null(d2i_PrivateKey(NID_id_GostR3410_2001, &pkey, &p,
|
||||
(long) len));
|
||||
assert_non_null(pkey);
|
||||
eckey = EVP_PKEY_get0(pkey);
|
||||
ATF_REQUIRE(eckey != NULL);
|
||||
assert_non_null(eckey);
|
||||
privkey1 = EC_KEY_get0_private_key(eckey);
|
||||
len = BN_num_bytes(privkey1);
|
||||
ATF_REQUIRE(len == 31);
|
||||
ATF_REQUIRE(BN_bn2bin(privkey1, rbuf) == len);
|
||||
ATF_REQUIRE(memcmp(rbuf, privraw, len) == 0);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(len, 31);
|
||||
assert_int_equal(BN_bn2bin(privkey1, rbuf), len);
|
||||
assert_memory_equal(rbuf, privraw, len);
|
||||
#else
|
||||
CK_BBOOL truevalue = TRUE;
|
||||
CK_BBOOL falsevalue = FALSE;
|
||||
|
|
@ -324,56 +336,61 @@ ATF_TC_BODY(isc_gost_private, tc) {
|
|||
CK_ULONG siglen;
|
||||
pk11_context_t pk11_ctx;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
|
||||
/* create the private key */
|
||||
memset(&pk11_ctx, 0, sizeof(pk11_ctx));
|
||||
ATF_REQUIRE(pk11_get_session(&pk11_ctx, OP_GOST, true,
|
||||
false, false, NULL,
|
||||
pk11_get_best_token(OP_GOST)) ==
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(pk11_get_session(&pk11_ctx, OP_GOST, true,
|
||||
false, false, NULL,
|
||||
pk11_get_best_token(OP_GOST)),
|
||||
ISC_R_SUCCESS);
|
||||
pk11_ctx.object = CK_INVALID_HANDLE;
|
||||
pk11_ctx.ontoken = false;
|
||||
ATF_REQUIRE(pkcs_C_CreateObject(pk11_ctx.session, keyTemplate,
|
||||
(CK_ULONG) 9, &pk11_ctx.object) ==
|
||||
CKR_OK);
|
||||
ATF_REQUIRE(pk11_ctx.object != CK_INVALID_HANDLE);
|
||||
assert_int_equal(pkcs_C_CreateObject(pk11_ctx.session, keyTemplate,
|
||||
(CK_ULONG) 9,
|
||||
&pk11_ctx.object),
|
||||
CKR_OK);
|
||||
assert_int_not_equal(pk11_ctx.object, CK_INVALID_HANDLE);
|
||||
|
||||
/* sign something */
|
||||
ATF_REQUIRE(pkcs_C_SignInit(pk11_ctx.session, &mech,
|
||||
pk11_ctx.object) == CKR_OK);
|
||||
assert_int_equal(pkcs_C_SignInit(pk11_ctx.session, &mech,
|
||||
pk11_ctx.object),
|
||||
CKR_OK);
|
||||
siglen = 0;
|
||||
ATF_REQUIRE(pkcs_C_Sign(pk11_ctx.session, sig, 64,
|
||||
NULL, &siglen) == CKR_OK);
|
||||
ATF_REQUIRE(siglen == 64);
|
||||
ATF_REQUIRE(pkcs_C_Sign(pk11_ctx.session, sig, 64,
|
||||
sig, &siglen) == CKR_OK);
|
||||
ATF_REQUIRE(siglen == 64);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(pkcs_C_Sign(pk11_ctx.session, sig, 64,
|
||||
NULL, &siglen),
|
||||
CKR_OK);
|
||||
assert_int_equal(siglen, 64);
|
||||
assert_int_equal(pkcs_C_Sign(pk11_ctx.session, sig, 64,
|
||||
sig, &siglen),
|
||||
CKR_OK);
|
||||
assert_int_equal(siglen, 64);
|
||||
#endif
|
||||
};
|
||||
#else
|
||||
ATF_TC(untested);
|
||||
ATF_TC_HEAD(untested, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "skipping gost test");
|
||||
}
|
||||
ATF_TC_BODY(untested, tc) {
|
||||
UNUSED(tc);
|
||||
atf_tc_skip("GOST not available");
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
|
||||
int
|
||||
main(void) {
|
||||
#if defined(HAVE_OPENSSL_GOST) || defined(HAVE_PKCS11_GOST)
|
||||
ATF_TP_ADD_TC(tp, isc_gost_md);
|
||||
ATF_TP_ADD_TC(tp, isc_gost_private);
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(isc_gost_md,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(isc_gost_private,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
#else
|
||||
ATF_TP_ADD_TC(tp, untested);
|
||||
print_message("1..0 # Skip GOST is unavailable");
|
||||
#endif
|
||||
return (atf_no_error());
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,21 +9,26 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(OPENSSL) || defined(PKCS11CRYPTO)
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/base64.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/name.h>
|
||||
|
|
@ -39,6 +44,29 @@
|
|||
|
||||
#include "dnstest.h"
|
||||
|
||||
#if defined(OPENSSL) || defined(PKCS11CRYPTO)
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
dns_keytable_t *keytable = NULL;
|
||||
dns_ntatable_t *ntatable = NULL;
|
||||
|
||||
|
|
@ -51,7 +79,7 @@ static dns_view_t *view = NULL;
|
|||
|
||||
/*
|
||||
* Test utilities. In general, these assume input parameters are valid
|
||||
* (checking with ATF_REQUIRE_EQ, thus aborting if not) and unlikely run time
|
||||
* (checking with assert_int_equal, thus aborting if not) and unlikely run time
|
||||
* errors (such as memory allocation failure) won't happen. This helps keep
|
||||
* the test code concise.
|
||||
*/
|
||||
|
|
@ -71,8 +99,9 @@ str2name(const char *namestr) {
|
|||
DE_CONST(namestr, deconst_namestr); /* OK, since we don't modify it */
|
||||
isc_buffer_init(&namebuf, deconst_namestr, strlen(deconst_namestr));
|
||||
isc_buffer_add(&namebuf, strlen(namestr));
|
||||
ATF_REQUIRE_EQ(dns_name_fromtext(name, &namebuf, dns_rootname, 0,
|
||||
NULL), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_name_fromtext(name, &namebuf, dns_rootname,
|
||||
0, NULL),
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
return (name);
|
||||
}
|
||||
|
|
@ -99,19 +128,19 @@ create_key(uint16_t flags, uint8_t proto, uint8_t alg,
|
|||
|
||||
isc_buffer_init(&keydatabuf, keydata, sizeof(keydata));
|
||||
isc_buffer_init(&rrdatabuf, rrdata, sizeof(rrdata));
|
||||
ATF_REQUIRE_EQ(isc_base64_decodestring(keystr, &keydatabuf),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_base64_decodestring(keystr, &keydatabuf),
|
||||
ISC_R_SUCCESS);
|
||||
isc_buffer_usedregion(&keydatabuf, &r);
|
||||
keystruct.datalen = r.length;
|
||||
keystruct.data = r.base;
|
||||
ATF_REQUIRE_EQ(dns_rdata_fromstruct(NULL, keystruct.common.rdclass,
|
||||
keystruct.common.rdtype,
|
||||
&keystruct, &rrdatabuf),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_rdata_fromstruct(NULL, keystruct.common.rdclass,
|
||||
keystruct.common.rdtype,
|
||||
&keystruct, &rrdatabuf),
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
ATF_REQUIRE_EQ(dst_key_fromdns(str2name(keynamestr), rdclass,
|
||||
&rrdatabuf, mctx, target),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dst_key_fromdns(str2name(keynamestr), rdclass,
|
||||
&rrdatabuf, mctx, target),
|
||||
ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/* Common setup: create a keytable and ntatable to test with a few keys */
|
||||
|
|
@ -122,87 +151,87 @@ create_tables() {
|
|||
isc_stdtime_t now;
|
||||
|
||||
result = dns_test_makeview("view", &view);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_keytable_create(mctx, &keytable), ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_ntatable_create(view, taskmgr, timermgr,
|
||||
&ntatable), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_create(mctx, &keytable), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_ntatable_create(view, taskmgr, timermgr,
|
||||
&ntatable), ISC_R_SUCCESS);
|
||||
|
||||
/* Add a normal key */
|
||||
create_key(257, 3, 5, "example.com", keystr1, &key);
|
||||
ATF_REQUIRE_EQ(dns_keytable_add(keytable, false, &key),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_add(keytable, false, &key),
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
/* Add a null key */
|
||||
ATF_REQUIRE_EQ(dns_keytable_marksecure(keytable,
|
||||
str2name("null.example")),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_marksecure(keytable,
|
||||
str2name("null.example")),
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
/* Add a negative trust anchor, duration 1 hour */
|
||||
isc_stdtime_get(&now);
|
||||
ATF_REQUIRE_EQ(dns_ntatable_add(ntatable,
|
||||
str2name("insecure.example"),
|
||||
false, now, 3600),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_ntatable_add(ntatable,
|
||||
str2name("insecure.example"),
|
||||
false, now, 3600),
|
||||
ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
destroy_tables() {
|
||||
if (ntatable != NULL)
|
||||
if (ntatable != NULL) {
|
||||
dns_ntatable_detach(&ntatable);
|
||||
if (keytable != NULL)
|
||||
}
|
||||
if (keytable != NULL) {
|
||||
dns_keytable_detach(&keytable);
|
||||
}
|
||||
|
||||
dns_view_detach(&view);
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
ATF_TC(add);
|
||||
ATF_TC_HEAD(add, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "add keys to the keytable");
|
||||
}
|
||||
ATF_TC_BODY(add, tc) {
|
||||
/* add keys to the keytable */
|
||||
static void
|
||||
add_test(void **state) {
|
||||
dst_key_t *key = NULL;
|
||||
dns_keynode_t *keynode = NULL;
|
||||
dns_keynode_t *next_keynode = NULL;
|
||||
dns_keynode_t *null_keynode = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_test_begin(NULL, true), ISC_R_SUCCESS);
|
||||
create_tables();
|
||||
|
||||
/*
|
||||
* Get the keynode for the example.com key. There's no other key for
|
||||
* the name, so nextkeynode() should return NOTFOUND.
|
||||
*/
|
||||
ATF_REQUIRE_EQ(dns_keytable_find(keytable, str2name("example.com"),
|
||||
&keynode), ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_keytable_nextkeynode(keytable, keynode,
|
||||
&next_keynode), ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_find(keytable, str2name("example.com"),
|
||||
&keynode),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_nextkeynode(keytable, keynode,
|
||||
&next_keynode),
|
||||
ISC_R_NOTFOUND);
|
||||
|
||||
/*
|
||||
* Try to add the same key. This should have no effect, so
|
||||
* nextkeynode() should still return NOTFOUND.
|
||||
*/
|
||||
create_key(257, 3, 5, "example.com", keystr1, &key);
|
||||
ATF_REQUIRE_EQ(dns_keytable_add(keytable, false, &key),
|
||||
ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_keytable_nextkeynode(keytable, keynode,
|
||||
&next_keynode), ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_add(keytable, false, &key),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_nextkeynode(keytable, keynode,
|
||||
&next_keynode),
|
||||
ISC_R_NOTFOUND);
|
||||
|
||||
/* Add another key (different keydata) */
|
||||
dns_keytable_detachkeynode(keytable, &keynode);
|
||||
create_key(257, 3, 5, "example.com", keystr2, &key);
|
||||
ATF_REQUIRE_EQ(dns_keytable_add(keytable, false, &key),
|
||||
ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_keytable_find(keytable, str2name("example.com"),
|
||||
&keynode), ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_keytable_nextkeynode(keytable, keynode,
|
||||
&next_keynode), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_add(keytable, false, &key),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_find(keytable, str2name("example.com"),
|
||||
&keynode),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_nextkeynode(keytable, keynode,
|
||||
&next_keynode),
|
||||
ISC_R_SUCCESS);
|
||||
dns_keytable_detachkeynode(keytable, &next_keynode);
|
||||
|
||||
/*
|
||||
|
|
@ -210,15 +239,16 @@ ATF_TC_BODY(add, tc) {
|
|||
* will be updated with the normal key.
|
||||
*/
|
||||
dns_keytable_detachkeynode(keytable, &keynode);
|
||||
ATF_REQUIRE_EQ(dns_keytable_find(keytable, str2name("null.example"),
|
||||
&null_keynode), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_find(keytable, str2name("null.example"),
|
||||
&null_keynode), ISC_R_SUCCESS);
|
||||
create_key(257, 3, 5, "null.example", keystr2, &key);
|
||||
ATF_REQUIRE_EQ(dns_keytable_add(keytable, false, &key),
|
||||
ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_keytable_find(keytable, str2name("null.example"),
|
||||
&keynode), ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(keynode, null_keynode); /* should be the same node */
|
||||
ATF_REQUIRE(dns_keynode_key(keynode) != NULL); /* now have a key */
|
||||
assert_int_equal(dns_keytable_add(keytable, false, &key),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_find(keytable, str2name("null.example"),
|
||||
&keynode),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(keynode, null_keynode); /* should be the same node */
|
||||
assert_non_null(dns_keynode_key(keynode)); /* now have a key */
|
||||
dns_keytable_detachkeynode(keytable, &null_keynode);
|
||||
|
||||
/*
|
||||
|
|
@ -228,81 +258,79 @@ ATF_TC_BODY(add, tc) {
|
|||
* (Note: this and above checks confirm that if a name has a null key
|
||||
* that's the only key for the name).
|
||||
*/
|
||||
ATF_REQUIRE_EQ(dns_keytable_marksecure(keytable,
|
||||
str2name("null.example")),
|
||||
ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_keytable_find(keytable, str2name("null.example"),
|
||||
&null_keynode), ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(keynode, null_keynode);
|
||||
ATF_REQUIRE(dns_keynode_key(keynode) != NULL);
|
||||
ATF_REQUIRE_EQ(dns_keytable_nextkeynode(keytable, keynode,
|
||||
&next_keynode), ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_marksecure(keytable,
|
||||
str2name("null.example")),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_find(keytable, str2name("null.example"),
|
||||
&null_keynode),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(keynode, null_keynode);
|
||||
assert_non_null(dns_keynode_key(keynode));
|
||||
assert_int_equal(dns_keytable_nextkeynode(keytable, keynode,
|
||||
&next_keynode),
|
||||
ISC_R_NOTFOUND);
|
||||
dns_keytable_detachkeynode(keytable, &null_keynode);
|
||||
|
||||
dns_keytable_detachkeynode(keytable, &keynode);
|
||||
destroy_tables();
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(delete);
|
||||
ATF_TC_HEAD(delete, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "delete keys from the keytable");
|
||||
}
|
||||
ATF_TC_BODY(delete, tc) {
|
||||
UNUSED(tc);
|
||||
/* delete keys from the keytable */
|
||||
static void
|
||||
delete_test(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_test_begin(NULL, true), ISC_R_SUCCESS);
|
||||
create_tables();
|
||||
|
||||
/* dns_keytable_delete requires exact match */
|
||||
ATF_REQUIRE_EQ(dns_keytable_delete(keytable, str2name("example.org")),
|
||||
ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dns_keytable_delete(keytable, str2name("s.example.com")),
|
||||
ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dns_keytable_delete(keytable, str2name("example.com")),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_delete(keytable,
|
||||
str2name("example.org")),
|
||||
ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_delete(keytable,
|
||||
str2name("s.example.com")),
|
||||
ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_delete(keytable,
|
||||
str2name("example.com")),
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
/* works also for nodes with a null key */
|
||||
ATF_REQUIRE_EQ(dns_keytable_delete(keytable, str2name("null.example")),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_delete(keytable,
|
||||
str2name("null.example")),
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
/* or a negative trust anchor */
|
||||
ATF_REQUIRE_EQ(dns_ntatable_delete(ntatable,
|
||||
str2name("insecure.example")),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_ntatable_delete(ntatable,
|
||||
str2name("insecure.example")),
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
destroy_tables();
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(deletekeynode);
|
||||
ATF_TC_HEAD(deletekeynode, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "delete key nodes from the keytable");
|
||||
}
|
||||
ATF_TC_BODY(deletekeynode, tc) {
|
||||
/* delete key nodes from the keytable */
|
||||
static void
|
||||
deletekeynode_test(void **state) {
|
||||
dst_key_t *key = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_test_begin(NULL, true), ISC_R_SUCCESS);
|
||||
create_tables();
|
||||
|
||||
/* key name doesn't match */
|
||||
create_key(257, 3, 5, "example.org", keystr1, &key);
|
||||
ATF_REQUIRE_EQ(dns_keytable_deletekeynode(keytable, key),
|
||||
ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_deletekeynode(keytable, key),
|
||||
ISC_R_NOTFOUND);
|
||||
dst_key_free(&key);
|
||||
|
||||
/* subdomain match is the same as no match */
|
||||
create_key(257, 3, 5, "sub.example.com", keystr1, &key);
|
||||
ATF_REQUIRE_EQ(dns_keytable_deletekeynode(keytable, key),
|
||||
ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_deletekeynode(keytable, key),
|
||||
ISC_R_NOTFOUND);
|
||||
dst_key_free(&key);
|
||||
|
||||
/* name matches but key doesn't match (resulting in PARTIALMATCH) */
|
||||
create_key(257, 3, 5, "example.com", keystr2, &key);
|
||||
ATF_REQUIRE_EQ(dns_keytable_deletekeynode(keytable, key),
|
||||
DNS_R_PARTIALMATCH);
|
||||
assert_int_equal(dns_keytable_deletekeynode(keytable, key),
|
||||
DNS_R_PARTIALMATCH);
|
||||
dst_key_free(&key);
|
||||
|
||||
/*
|
||||
|
|
@ -311,12 +339,13 @@ ATF_TC_BODY(deletekeynode, tc) {
|
|||
* NOTFOUND.
|
||||
*/
|
||||
create_key(257, 3, 5, "example.com", keystr1, &key);
|
||||
ATF_REQUIRE_EQ(dns_keytable_deletekeynode(keytable, key),
|
||||
ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_keytable_deletekeynode(keytable, key),
|
||||
ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dns_keytable_delete(keytable, str2name("example.com")),
|
||||
ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_deletekeynode(keytable, key),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_deletekeynode(keytable, key),
|
||||
ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_delete(keytable,
|
||||
str2name("example.com")),
|
||||
ISC_R_NOTFOUND);
|
||||
dst_key_free(&key);
|
||||
|
||||
/*
|
||||
|
|
@ -324,44 +353,47 @@ ATF_TC_BODY(deletekeynode, tc) {
|
|||
* it must be deleted by dns_keytable_delete()
|
||||
*/
|
||||
create_key(257, 3, 5, "null.example", keystr1, &key);
|
||||
ATF_REQUIRE_EQ(dns_keytable_deletekeynode(keytable, key),
|
||||
DNS_R_PARTIALMATCH);
|
||||
ATF_REQUIRE_EQ(dns_keytable_delete(keytable, dst_key_name(key)),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_deletekeynode(keytable, key),
|
||||
DNS_R_PARTIALMATCH);
|
||||
assert_int_equal(dns_keytable_delete(keytable, dst_key_name(key)),
|
||||
ISC_R_SUCCESS);
|
||||
dst_key_free(&key);
|
||||
|
||||
destroy_tables();
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(find);
|
||||
ATF_TC_HEAD(find, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "check find-variant operations");
|
||||
}
|
||||
ATF_TC_BODY(find, tc) {
|
||||
/* check find-variant operations */
|
||||
static void
|
||||
find_test(void **state) {
|
||||
dns_keynode_t *keynode = NULL;
|
||||
dns_fixedname_t fname;
|
||||
dns_name_t *name;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_test_begin(NULL, true), ISC_R_SUCCESS);
|
||||
create_tables();
|
||||
|
||||
/*
|
||||
* dns_keytable_find() requires exact name match. It matches node
|
||||
* that has a null key, too.
|
||||
*/
|
||||
ATF_REQUIRE_EQ(dns_keytable_find(keytable, str2name("example.org"),
|
||||
&keynode), ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dns_keytable_find(keytable, str2name("sub.example.com"),
|
||||
&keynode), ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dns_keytable_find(keytable, str2name("example.com"),
|
||||
&keynode), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_find(keytable, str2name("example.org"),
|
||||
&keynode),
|
||||
ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_find(keytable,
|
||||
str2name("sub.example.com"),
|
||||
&keynode),
|
||||
ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_find(keytable,
|
||||
str2name("example.com"),
|
||||
&keynode),
|
||||
ISC_R_SUCCESS);
|
||||
dns_keytable_detachkeynode(keytable, &keynode);
|
||||
ATF_REQUIRE_EQ(dns_keytable_find(keytable, str2name("null.example"),
|
||||
&keynode), ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_keynode_key(keynode), NULL);
|
||||
assert_int_equal(dns_keytable_find(keytable,
|
||||
str2name("null.example"),
|
||||
&keynode),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keynode_key(keynode), NULL);
|
||||
dns_keytable_detachkeynode(keytable, &keynode);
|
||||
|
||||
/*
|
||||
|
|
@ -369,70 +401,69 @@ ATF_TC_BODY(find, tc) {
|
|||
* nodes with a null key.
|
||||
*/
|
||||
name = dns_fixedname_initname(&fname);
|
||||
ATF_REQUIRE_EQ(dns_keytable_finddeepestmatch(keytable,
|
||||
str2name("example.com"),
|
||||
name), ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_name_equal(name, str2name("example.com")), true);
|
||||
ATF_REQUIRE_EQ(dns_keytable_finddeepestmatch(keytable,
|
||||
str2name("s.example.com"),
|
||||
name), ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_name_equal(name, str2name("example.com")), true);
|
||||
ATF_REQUIRE_EQ(dns_keytable_finddeepestmatch(keytable,
|
||||
str2name("example.org"),
|
||||
name), ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dns_keytable_finddeepestmatch(keytable,
|
||||
str2name("null.example"),
|
||||
name), ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dns_name_equal(name, str2name("null.example")),
|
||||
true);
|
||||
assert_int_equal(dns_keytable_finddeepestmatch(keytable,
|
||||
str2name("example.com"),
|
||||
name),
|
||||
ISC_R_SUCCESS);
|
||||
assert_true(dns_name_equal(name, str2name("example.com")));
|
||||
assert_int_equal(dns_keytable_finddeepestmatch(keytable,
|
||||
str2name("s.example.com"),
|
||||
name),
|
||||
ISC_R_SUCCESS);
|
||||
assert_true(dns_name_equal(name, str2name("example.com")));
|
||||
assert_int_equal(dns_keytable_finddeepestmatch(keytable,
|
||||
str2name("example.org"),
|
||||
name),
|
||||
ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_finddeepestmatch(keytable,
|
||||
str2name("null.example"),
|
||||
name),
|
||||
ISC_R_SUCCESS);
|
||||
assert_true(dns_name_equal(name, str2name("null.example")));
|
||||
|
||||
/*
|
||||
* dns_keytable_findkeynode() requires exact name, algorithm, keytag
|
||||
* match. If algorithm or keytag doesn't match, should result in
|
||||
* PARTIALMATCH. Same for a node with a null key.
|
||||
*/
|
||||
ATF_REQUIRE_EQ(dns_keytable_findkeynode(keytable,
|
||||
str2name("example.org"),
|
||||
5, keytag1, &keynode),
|
||||
ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dns_keytable_findkeynode(keytable,
|
||||
str2name("sub.example.com"),
|
||||
5, keytag1, &keynode),
|
||||
ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dns_keytable_findkeynode(keytable,
|
||||
str2name("example.com"),
|
||||
4, keytag1, &keynode),
|
||||
DNS_R_PARTIALMATCH); /* different algorithm */
|
||||
ATF_REQUIRE_EQ(dns_keytable_findkeynode(keytable,
|
||||
str2name("example.com"),
|
||||
5, keytag1 + 1, &keynode),
|
||||
DNS_R_PARTIALMATCH); /* different keytag */
|
||||
ATF_REQUIRE_EQ(dns_keytable_findkeynode(keytable,
|
||||
str2name("null.example"),
|
||||
5, 0, &keynode),
|
||||
DNS_R_PARTIALMATCH); /* null key */
|
||||
ATF_REQUIRE_EQ(dns_keytable_findkeynode(keytable,
|
||||
str2name("example.com"),
|
||||
5, keytag1, &keynode),
|
||||
ISC_R_SUCCESS); /* complete match */
|
||||
assert_int_equal(dns_keytable_findkeynode(keytable,
|
||||
str2name("example.org"),
|
||||
5, keytag1, &keynode),
|
||||
ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_findkeynode(keytable,
|
||||
str2name("sub.example.com"),
|
||||
5, keytag1, &keynode),
|
||||
ISC_R_NOTFOUND);
|
||||
assert_int_equal(dns_keytable_findkeynode(keytable,
|
||||
str2name("example.com"),
|
||||
4, keytag1, &keynode),
|
||||
DNS_R_PARTIALMATCH); /* different algorithm */
|
||||
assert_int_equal(dns_keytable_findkeynode(keytable,
|
||||
str2name("example.com"),
|
||||
5, keytag1 + 1, &keynode),
|
||||
DNS_R_PARTIALMATCH); /* different keytag */
|
||||
assert_int_equal(dns_keytable_findkeynode(keytable,
|
||||
str2name("null.example"),
|
||||
5, 0, &keynode),
|
||||
DNS_R_PARTIALMATCH); /* null key */
|
||||
assert_int_equal(dns_keytable_findkeynode(keytable,
|
||||
str2name("example.com"),
|
||||
5, keytag1, &keynode),
|
||||
ISC_R_SUCCESS); /* complete match */
|
||||
dns_keytable_detachkeynode(keytable, &keynode);
|
||||
|
||||
destroy_tables();
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(issecuredomain);
|
||||
ATF_TC_HEAD(issecuredomain, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "check issecuredomain()");
|
||||
}
|
||||
ATF_TC_BODY(issecuredomain, tc) {
|
||||
/* check issecuredomain() */
|
||||
static void
|
||||
issecuredomain_test(void **state) {
|
||||
bool issecure;
|
||||
const char **n;
|
||||
const char *names[] = {"example.com", "sub.example.com",
|
||||
"null.example", "sub.null.example", NULL};
|
||||
|
||||
UNUSED(tc);
|
||||
ATF_REQUIRE_EQ(dns_test_begin(NULL, true), ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
create_tables();
|
||||
|
||||
/*
|
||||
|
|
@ -442,181 +473,176 @@ ATF_TC_BODY(issecuredomain, tc) {
|
|||
* of installing a null key).
|
||||
*/
|
||||
for (n = names; *n != NULL; n++) {
|
||||
ATF_REQUIRE_EQ(dns_keytable_issecuredomain(keytable,
|
||||
str2name(*n),
|
||||
NULL,
|
||||
&issecure),
|
||||
ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(issecure, true);
|
||||
assert_int_equal(dns_keytable_issecuredomain(keytable,
|
||||
str2name(*n),
|
||||
NULL,
|
||||
&issecure),
|
||||
ISC_R_SUCCESS);
|
||||
assert_true(issecure);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the key table has no entry (not even a null one) for a domain or
|
||||
* any of its ancestors, that domain is considered insecure.
|
||||
*/
|
||||
ATF_REQUIRE_EQ(dns_keytable_issecuredomain(keytable,
|
||||
str2name("example.org"),
|
||||
NULL,
|
||||
&issecure),
|
||||
ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(issecure, false);
|
||||
assert_int_equal(dns_keytable_issecuredomain(keytable,
|
||||
str2name("example.org"),
|
||||
NULL,
|
||||
&issecure),
|
||||
ISC_R_SUCCESS);
|
||||
assert_false(issecure);
|
||||
|
||||
destroy_tables();
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(dump);
|
||||
ATF_TC_HEAD(dump, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "check dns_keytable_dump()");
|
||||
}
|
||||
ATF_TC_BODY(dump, tc) {
|
||||
UNUSED(tc);
|
||||
/* check dns_keytable_dump() */
|
||||
static void
|
||||
dump_test(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_test_begin(NULL, true), ISC_R_SUCCESS);
|
||||
create_tables();
|
||||
|
||||
/*
|
||||
* Right now, we only confirm the dump attempt doesn't cause disruption
|
||||
* (so we don't check the dump content).
|
||||
*/
|
||||
ATF_REQUIRE_EQ(dns_keytable_dump(keytable, stdout), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_keytable_dump(keytable, stdout), ISC_R_SUCCESS);
|
||||
|
||||
destroy_tables();
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(nta);
|
||||
ATF_TC_HEAD(nta, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "check negative trust anchors");
|
||||
}
|
||||
ATF_TC_BODY(nta, tc) {
|
||||
/* check negative trust anchors */
|
||||
static void
|
||||
nta_test(void **state) {
|
||||
isc_result_t result;
|
||||
dst_key_t *key = NULL;
|
||||
bool issecure, covered;
|
||||
dns_view_t *myview = NULL;
|
||||
isc_stdtime_t now;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_makeview("view", &myview);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_task_create(taskmgr, 0, &myview->task);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_view_initsecroots(myview, mctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_view_getsecroots(myview, &keytable);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_view_initntatable(myview, taskmgr, timermgr);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_view_getntatable(myview, &ntatable);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
create_key(257, 3, 5, "example", keystr1, &key);
|
||||
result = dns_keytable_add(keytable, false, &key);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_stdtime_get(&now);
|
||||
result = dns_ntatable_add(ntatable,
|
||||
str2name("insecure.example"),
|
||||
false, now, 1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Should be secure */
|
||||
result = dns_view_issecuredomain(myview,
|
||||
str2name("test.secure.example"),
|
||||
now, true, &issecure);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(issecure);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(issecure);
|
||||
|
||||
/* Should not be secure */
|
||||
result = dns_view_issecuredomain(myview,
|
||||
str2name("test.insecure.example"),
|
||||
now, true, &issecure);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(!issecure);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_false(issecure);
|
||||
|
||||
/* NTA covered */
|
||||
covered = dns_view_ntacovers(myview, now, str2name("insecure.example"),
|
||||
dns_rootname);
|
||||
ATF_CHECK(covered);
|
||||
assert_true(covered);
|
||||
|
||||
/* Not NTA covered */
|
||||
covered = dns_view_ntacovers(myview, now, str2name("secure.example"),
|
||||
dns_rootname);
|
||||
ATF_CHECK(!covered);
|
||||
assert_false(covered);
|
||||
|
||||
/* As of now + 2, the NTA should be clear */
|
||||
result = dns_view_issecuredomain(myview,
|
||||
str2name("test.insecure.example"),
|
||||
now + 2, true, &issecure);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(issecure);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(issecure);
|
||||
|
||||
/* Now check deletion */
|
||||
result = dns_view_issecuredomain(myview, str2name("test.new.example"),
|
||||
now, true, &issecure);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(issecure);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(issecure);
|
||||
|
||||
result = dns_ntatable_add(ntatable, str2name("new.example"),
|
||||
false, now, 3600);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_view_issecuredomain(myview, str2name("test.new.example"),
|
||||
now, true, &issecure);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(!issecure);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_false(issecure);
|
||||
|
||||
result = dns_ntatable_delete(ntatable, str2name("new.example"));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_view_issecuredomain(myview, str2name("test.new.example"),
|
||||
now, true, &issecure);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(issecure);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(issecure);
|
||||
|
||||
/* Clean up */
|
||||
dns_ntatable_detach(&ntatable);
|
||||
dns_keytable_detach(&keytable);
|
||||
dns_view_detach(&myview);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
#else
|
||||
#include <isc/util.h>
|
||||
|
||||
ATF_TC(untested);
|
||||
ATF_TC_HEAD(untested, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "skipping keytable test");
|
||||
}
|
||||
ATF_TC_BODY(untested, tc) {
|
||||
UNUSED(tc);
|
||||
atf_tc_skip("DNSSEC not available");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
int
|
||||
main(void) {
|
||||
#if defined(OPENSSL) || defined(PKCS11CRYPTO)
|
||||
ATF_TP_ADD_TC(tp, add);
|
||||
ATF_TP_ADD_TC(tp, delete);
|
||||
ATF_TP_ADD_TC(tp, deletekeynode);
|
||||
ATF_TP_ADD_TC(tp, find);
|
||||
ATF_TP_ADD_TC(tp, issecuredomain);
|
||||
ATF_TP_ADD_TC(tp, dump);
|
||||
ATF_TP_ADD_TC(tp, nta);
|
||||
#else
|
||||
ATF_TP_ADD_TC(tp, untested);
|
||||
#endif
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(add_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(delete_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(deletekeynode_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(find_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(issecuredomain_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(dump_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(nta_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
#else
|
||||
print_message("1..0 # Skipped: keytable requires crypto\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,16 +10,24 @@
|
|||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/xml.h>
|
||||
|
|
@ -36,9 +44,26 @@
|
|||
|
||||
#include "dnstest.h"
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#define BUFLEN 255
|
||||
#define BIGBUFLEN (70 * 1024)
|
||||
|
|
@ -100,17 +125,20 @@ setup_master(void (*warn)(struct dns_rdatacallbacks *, const char *, ...),
|
|||
|
||||
result = dns_name_fromtext(&dns_origin, &source, dns_rootname,
|
||||
0, &target);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return(result);
|
||||
}
|
||||
|
||||
dns_rdatacallbacks_init_stdio(&callbacks);
|
||||
callbacks.add = add_callback;
|
||||
callbacks.rawdata = rawdata_callback;
|
||||
callbacks.zone = NULL;
|
||||
if (warn != NULL)
|
||||
if (warn != NULL) {
|
||||
callbacks.warn = warn;
|
||||
if (error != NULL)
|
||||
}
|
||||
if (error != NULL) {
|
||||
callbacks.error = error;
|
||||
}
|
||||
headerset = false;
|
||||
return (result);
|
||||
}
|
||||
|
|
@ -123,8 +151,9 @@ test_master(const char *testfile, dns_masterformat_t format,
|
|||
isc_result_t result;
|
||||
|
||||
result = setup_master(warn, error);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return(result);
|
||||
}
|
||||
|
||||
result = dns_master_loadfile2(testfile, &dns_origin, &dns_origin,
|
||||
dns_rdataclass_in, true,
|
||||
|
|
@ -139,342 +168,242 @@ include_callback(const char *filename, void *arg) {
|
|||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
* Successful load test:
|
||||
* dns_master_loadfile() loads a valid master file and returns success
|
||||
*/
|
||||
|
||||
/* Successful load test */
|
||||
ATF_TC(load);
|
||||
ATF_TC_HEAD(load, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() loads a "
|
||||
"valid master file and returns success");
|
||||
}
|
||||
ATF_TC_BODY(load, tc) {
|
||||
static void
|
||||
load_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master1.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/* Unepxected end of file test */
|
||||
ATF_TC(unexpected);
|
||||
ATF_TC_HEAD(unexpected, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() returns "
|
||||
"DNS_R_UNEXPECTED when file ends "
|
||||
"too soon");
|
||||
}
|
||||
ATF_TC_BODY(unexpected, tc) {
|
||||
/*
|
||||
* Unexpected end of file test:
|
||||
* dns_master_loadfile() returns DNS_R_UNEXPECTED when file ends too soon
|
||||
*/
|
||||
static void
|
||||
unexpected_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master2.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_UNEXPECTEDEND);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_UNEXPECTEDEND);
|
||||
}
|
||||
|
||||
|
||||
/* No owner test */
|
||||
ATF_TC(noowner);
|
||||
ATF_TC_HEAD(noowner, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() accepts broken "
|
||||
"zones with no TTL for first record "
|
||||
"if it is an SOA");
|
||||
}
|
||||
ATF_TC_BODY(noowner, tc) {
|
||||
/*
|
||||
* No owner test:
|
||||
* dns_master_loadfile() accepts broken zones with no TTL for first record
|
||||
* if it is an SOA
|
||||
*/
|
||||
static void
|
||||
noowner_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master3.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, DNS_R_NOOWNER);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, DNS_R_NOOWNER);
|
||||
}
|
||||
|
||||
|
||||
/* No TTL test */
|
||||
ATF_TC(nottl);
|
||||
ATF_TC_HEAD(nottl, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() returns "
|
||||
"DNS_R_NOOWNER when no owner name "
|
||||
"is specified");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(nottl, tc) {
|
||||
/*
|
||||
* No TTL test:
|
||||
* dns_master_loadfile() returns DNS_R_NOOWNER when no owner name is
|
||||
* specified
|
||||
*/
|
||||
static void
|
||||
nottl_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master4.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/* Bad class test */
|
||||
ATF_TC(badclass);
|
||||
ATF_TC_HEAD(badclass, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() returns "
|
||||
"DNS_R_BADCLASS when record class "
|
||||
"doesn't match zone class");
|
||||
}
|
||||
ATF_TC_BODY(badclass, tc) {
|
||||
/*
|
||||
* Bad class test:
|
||||
* dns_master_loadfile() returns DNS_R_BADCLASS when record class doesn't
|
||||
* match zone class
|
||||
*/
|
||||
static void
|
||||
badclass_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master5.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, DNS_R_BADCLASS);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, DNS_R_BADCLASS);
|
||||
}
|
||||
|
||||
/* Too big rdata test */
|
||||
ATF_TC(toobig);
|
||||
ATF_TC_HEAD(toobig, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() returns "
|
||||
"ISC_R_NOSPACE when record is too big");
|
||||
}
|
||||
ATF_TC_BODY(toobig, tc) {
|
||||
/*
|
||||
* Too big rdata test:
|
||||
* dns_master_loadfile() returns ISC_R_NOSPACE when record is too big
|
||||
*/
|
||||
static void
|
||||
toobig_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master15.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOSPACE);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_NOSPACE);
|
||||
}
|
||||
|
||||
/* Maximum rdata test */
|
||||
ATF_TC(maxrdata);
|
||||
ATF_TC_HEAD(maxrdata, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() returns "
|
||||
"ISC_R_SUCCESS when record is maximum "
|
||||
"size");
|
||||
}
|
||||
ATF_TC_BODY(maxrdata, tc) {
|
||||
/*
|
||||
* Maximum rdata test:
|
||||
* dns_master_loadfile() returns ISC_R_SUCCESS when record is maximum size
|
||||
*/
|
||||
static void
|
||||
maxrdata_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master16.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/* DNSKEY test */
|
||||
ATF_TC(dnskey);
|
||||
ATF_TC_HEAD(dnskey, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() understands "
|
||||
"DNSKEY with key material");
|
||||
}
|
||||
ATF_TC_BODY(dnskey, tc) {
|
||||
/*
|
||||
* DNSKEY test:
|
||||
* dns_master_loadfile() understands DNSKEY with key material
|
||||
*/
|
||||
static void
|
||||
dnskey_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master6.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/* DNSKEY with no key material test */
|
||||
ATF_TC(dnsnokey);
|
||||
ATF_TC_HEAD(dnsnokey, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() understands "
|
||||
"DNSKEY with no key material");
|
||||
}
|
||||
ATF_TC_BODY(dnsnokey, tc) {
|
||||
/*
|
||||
* DNSKEY with no key material test:
|
||||
* dns_master_loadfile() understands DNSKEY with no key material
|
||||
*/
|
||||
static void
|
||||
dnsnokey_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master7.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/* Include test */
|
||||
ATF_TC(include);
|
||||
ATF_TC_HEAD(include, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() understands "
|
||||
"$INCLUDE");
|
||||
}
|
||||
ATF_TC_BODY(include, tc) {
|
||||
/*
|
||||
* Include test:
|
||||
* dns_master_loadfile() understands $INCLUDE
|
||||
*/
|
||||
static void
|
||||
include_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master8.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, DNS_R_SEENINCLUDE);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, DNS_R_SEENINCLUDE);
|
||||
}
|
||||
|
||||
/* Include file list test */
|
||||
ATF_TC(master_includelist);
|
||||
ATF_TC_HEAD(master_includelist, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile4() returns "
|
||||
"names of included file");
|
||||
}
|
||||
ATF_TC_BODY(master_includelist, tc) {
|
||||
/*
|
||||
* Include file list test:
|
||||
* dns_master_loadfile4() returns names of included file
|
||||
*/
|
||||
static void
|
||||
master_includelist_test(void **state) {
|
||||
isc_result_t result;
|
||||
char *filename = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = setup_master(NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_master_loadfile4("testdata/master/master8.data",
|
||||
&dns_origin, &dns_origin,
|
||||
dns_rdataclass_in, 0, true,
|
||||
&callbacks, include_callback,
|
||||
&filename, mctx, dns_masterformat_text);
|
||||
ATF_CHECK_EQ(result, DNS_R_SEENINCLUDE);
|
||||
ATF_CHECK(filename != NULL);
|
||||
if (filename != NULL) {
|
||||
ATF_CHECK_STREQ(filename, "testdata/master/master7.data");
|
||||
isc_mem_free(mctx, filename);
|
||||
}
|
||||
assert_int_equal(result, DNS_R_SEENINCLUDE);
|
||||
assert_non_null(filename);
|
||||
|
||||
dns_test_end();
|
||||
assert_string_equal(filename, "testdata/master/master7.data");
|
||||
isc_mem_free(mctx, filename);
|
||||
}
|
||||
|
||||
/* Include failure test */
|
||||
ATF_TC(includefail);
|
||||
ATF_TC_HEAD(includefail, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() understands "
|
||||
"$INCLUDE failures");
|
||||
}
|
||||
ATF_TC_BODY(includefail, tc) {
|
||||
/*
|
||||
* Include failure test:
|
||||
* dns_master_loadfile() understands $INCLUDE failures
|
||||
*/
|
||||
static void
|
||||
includefail_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master9.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, DNS_R_BADCLASS);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, DNS_R_BADCLASS);
|
||||
}
|
||||
|
||||
|
||||
/* Non-empty blank lines test */
|
||||
ATF_TC(blanklines);
|
||||
ATF_TC_HEAD(blanklines, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() handles "
|
||||
"non-empty blank lines");
|
||||
}
|
||||
ATF_TC_BODY(blanklines, tc) {
|
||||
/*
|
||||
* Non-empty blank lines test:
|
||||
* dns_master_loadfile() handles non-empty blank lines
|
||||
*/
|
||||
static void
|
||||
blanklines_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master10.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/* SOA leading zeroes test */
|
||||
ATF_TC(leadingzero);
|
||||
ATF_TC_HEAD(leadingzero, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() allows "
|
||||
"leading zeroes in SOA");
|
||||
}
|
||||
ATF_TC_BODY(leadingzero, tc) {
|
||||
/*
|
||||
* SOA leading zeroes test:
|
||||
* dns_master_loadfile() allows leading zeroes in SOA
|
||||
*/
|
||||
|
||||
static void
|
||||
leadingzero_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = test_master("testdata/master/master11.data",
|
||||
dns_masterformat_text, NULL, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
ATF_TC(totext);
|
||||
ATF_TC_HEAD(totext, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "masterfile totext tests");
|
||||
}
|
||||
ATF_TC_BODY(totext, tc) {
|
||||
/* masterfile totext tests */
|
||||
static void
|
||||
totext_test(void **state) {
|
||||
isc_result_t result;
|
||||
dns_rdataset_t rdataset;
|
||||
dns_rdatalist_t rdatalist;
|
||||
isc_buffer_t target;
|
||||
unsigned char buf[BIGBUFLEN];
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* First, test with an empty rdataset */
|
||||
dns_rdatalist_init(&rdatalist);
|
||||
|
|
@ -484,70 +413,61 @@ ATF_TC_BODY(totext, tc) {
|
|||
|
||||
dns_rdataset_init(&rdataset);
|
||||
result = dns_rdatalist_tordataset(&rdatalist, &rdataset);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_buffer_init(&target, buf, BIGBUFLEN);
|
||||
result = dns_master_rdatasettotext(dns_rootname,
|
||||
&rdataset, &dns_master_style_debug,
|
||||
&target);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ(isc_buffer_usedlength(&target), 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_buffer_usedlength(&target), 0);
|
||||
|
||||
/*
|
||||
* XXX: We will also need to add tests for dumping various
|
||||
* rdata types, classes, etc, and comparing the results against
|
||||
* known-good output.
|
||||
*/
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/* Raw load */
|
||||
ATF_TC(loadraw);
|
||||
ATF_TC_HEAD(loadraw, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() loads a "
|
||||
"valid raw file and returns success");
|
||||
}
|
||||
ATF_TC_BODY(loadraw, tc) {
|
||||
/*
|
||||
* Raw load test:
|
||||
* dns_master_loadfile() loads a valid raw file and returns success
|
||||
*/
|
||||
static void
|
||||
loadraw_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Raw format version 0 */
|
||||
result = test_master("testdata/master/master12.data",
|
||||
dns_masterformat_raw, NULL, NULL);
|
||||
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
||||
ATF_CHECK(headerset);
|
||||
ATF_CHECK_EQ(header.flags, 0);
|
||||
assert_string_equal(isc_result_totext(result), "success");
|
||||
assert_true(headerset);
|
||||
assert_int_equal(header.flags, 0);
|
||||
|
||||
/* Raw format version 1, no source serial */
|
||||
result = test_master("testdata/master/master13.data",
|
||||
dns_masterformat_raw, NULL, NULL);
|
||||
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
||||
ATF_CHECK(headerset);
|
||||
ATF_CHECK_EQ(header.flags, 0);
|
||||
assert_string_equal(isc_result_totext(result), "success");
|
||||
assert_true(headerset);
|
||||
assert_int_equal(header.flags, 0);
|
||||
|
||||
/* Raw format version 1, source serial == 2011120101 */
|
||||
result = test_master("testdata/master/master14.data",
|
||||
dns_masterformat_raw, NULL, NULL);
|
||||
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
||||
ATF_CHECK(headerset);
|
||||
ATF_CHECK((header.flags & DNS_MASTERRAW_SOURCESERIALSET) != 0);
|
||||
ATF_CHECK_EQ(header.sourceserial, 2011120101);
|
||||
|
||||
dns_test_end();
|
||||
assert_string_equal(isc_result_totext(result), "success");
|
||||
assert_true(headerset);
|
||||
assert_true((header.flags & DNS_MASTERRAW_SOURCESERIALSET) != 0);
|
||||
assert_int_equal(header.sourceserial, 2011120101);
|
||||
}
|
||||
|
||||
/* Raw dump*/
|
||||
ATF_TC(dumpraw);
|
||||
ATF_TC_HEAD(dumpraw, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_dump*() functions "
|
||||
"dump valid raw files");
|
||||
}
|
||||
ATF_TC_BODY(dumpraw, tc) {
|
||||
/*
|
||||
* Raw dump test:
|
||||
* dns_master_dump*() functions dump valid raw files
|
||||
*/
|
||||
static void
|
||||
dumpraw_test(void **state) {
|
||||
isc_result_t result;
|
||||
dns_db_t *db = NULL;
|
||||
dns_dbversion_t *version = NULL;
|
||||
|
|
@ -557,7 +477,7 @@ ATF_TC_BODY(dumpraw, tc) {
|
|||
unsigned char namebuf[BUFLEN];
|
||||
int len;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
strlcpy(myorigin, TEST_ORIGIN, sizeof(myorigin));
|
||||
len = strlen(myorigin);
|
||||
|
|
@ -568,29 +488,26 @@ ATF_TC_BODY(dumpraw, tc) {
|
|||
dns_name_init(&dnsorigin, NULL);
|
||||
result = dns_name_fromtext(&dnsorigin, &source, dns_rootname,
|
||||
0, &target);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_create(mctx, "rbt", &dnsorigin, dns_dbtype_zone,
|
||||
dns_rdataclass_in, 0, NULL, &db);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_db_load(db, "testdata/master/master1.data");
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_db_currentversion(db, &version);
|
||||
|
||||
result = dns_master_dump2(mctx, db, version,
|
||||
&dns_master_style_default, "test.dump",
|
||||
dns_masterformat_raw);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = test_master("test.dump", dns_masterformat_raw, NULL, NULL);
|
||||
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
||||
ATF_CHECK(headerset);
|
||||
ATF_CHECK_EQ(header.flags, 0);
|
||||
assert_string_equal(isc_result_totext(result), "success");
|
||||
assert_true(headerset);
|
||||
assert_int_equal(header.flags, 0);
|
||||
|
||||
dns_master_initrawheader(&header);
|
||||
header.sourceserial = 12345;
|
||||
|
|
@ -600,18 +517,17 @@ ATF_TC_BODY(dumpraw, tc) {
|
|||
result = dns_master_dump3(mctx, db, version,
|
||||
&dns_master_style_default, "test.dump",
|
||||
dns_masterformat_raw, &header);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = test_master("test.dump", dns_masterformat_raw, NULL, NULL);
|
||||
ATF_CHECK_STREQ(isc_result_totext(result), "success");
|
||||
ATF_CHECK(headerset);
|
||||
ATF_CHECK((header.flags & DNS_MASTERRAW_SOURCESERIALSET) != 0);
|
||||
ATF_CHECK_EQ(header.sourceserial, 12345);
|
||||
assert_string_equal(isc_result_totext(result), "success");
|
||||
assert_true(headerset);
|
||||
assert_true((header.flags & DNS_MASTERRAW_SOURCESERIALSET) != 0);
|
||||
assert_int_equal(header.sourceserial, 12345);
|
||||
|
||||
unlink("test.dump");
|
||||
dns_db_closeversion(db, &version, false);
|
||||
dns_db_detach(&db);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
static const char *warn_expect_value;
|
||||
|
|
@ -624,61 +540,88 @@ warn_expect(struct dns_rdatacallbacks *mycallbacks, const char *fmt, ...) {
|
|||
|
||||
UNUSED(mycallbacks);
|
||||
|
||||
warn_expect_result = false;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
va_end(ap);
|
||||
if (warn_expect_value != NULL && strstr(buf, warn_expect_value) != NULL)
|
||||
|
||||
if (warn_expect_value != NULL &&
|
||||
strstr(buf, warn_expect_value) != NULL)
|
||||
{
|
||||
warn_expect_result = true;
|
||||
}
|
||||
|
||||
/* Origin change test */
|
||||
ATF_TC(neworigin);
|
||||
ATF_TC_HEAD(neworigin, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() rejects "
|
||||
"zones with inherited name following "
|
||||
"$ORIGIN");
|
||||
}
|
||||
ATF_TC_BODY(neworigin, tc) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
warn_expect_value = "record with inherited owner";
|
||||
warn_expect_result = false;
|
||||
result = test_master("testdata/master/master17.data",
|
||||
dns_masterformat_text, warn_expect, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_MSG(warn_expect_result, "'%s' warning not emitted",
|
||||
warn_expect_value);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
* Origin change test:
|
||||
* dns_master_loadfile() rejects zones with inherited name following $ORIGIN
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, load);
|
||||
ATF_TP_ADD_TC(tp, unexpected);
|
||||
ATF_TP_ADD_TC(tp, noowner);
|
||||
ATF_TP_ADD_TC(tp, nottl);
|
||||
ATF_TP_ADD_TC(tp, badclass);
|
||||
ATF_TP_ADD_TC(tp, dnskey);
|
||||
ATF_TP_ADD_TC(tp, dnsnokey);
|
||||
ATF_TP_ADD_TC(tp, include);
|
||||
ATF_TP_ADD_TC(tp, master_includelist);
|
||||
ATF_TP_ADD_TC(tp, includefail);
|
||||
ATF_TP_ADD_TC(tp, blanklines);
|
||||
ATF_TP_ADD_TC(tp, leadingzero);
|
||||
ATF_TP_ADD_TC(tp, totext);
|
||||
ATF_TP_ADD_TC(tp, loadraw);
|
||||
ATF_TP_ADD_TC(tp, dumpraw);
|
||||
ATF_TP_ADD_TC(tp, toobig);
|
||||
ATF_TP_ADD_TC(tp, maxrdata);
|
||||
ATF_TP_ADD_TC(tp, neworigin);
|
||||
static void
|
||||
neworigin_test(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
return (atf_no_error());
|
||||
UNUSED(state);
|
||||
|
||||
warn_expect_value = "record with inherited owner";
|
||||
result = test_master("testdata/master/master17.data",
|
||||
dns_masterformat_text, warn_expect, NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(warn_expect_result);
|
||||
}
|
||||
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(load_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(unexpected_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(noowner_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(nottl_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(badclass_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(dnskey_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(dnsnokey_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(include_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(master_includelist_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(includefail_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(blanklines_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(leadingzero_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(totext_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(loadraw_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(dumpraw_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(toobig_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(maxrdata_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(neworigin_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,17 +9,22 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/commandline.h>
|
||||
|
|
@ -35,15 +40,30 @@
|
|||
|
||||
#include "dnstest.h"
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
ATF_TC(fullcompare);
|
||||
ATF_TC_HEAD(fullcompare, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_name_fullcompare test");
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
ATF_TC_BODY(fullcompare, tc) {
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* dns_name_fullcompare test */
|
||||
static void
|
||||
fullcompare_test(void **state) {
|
||||
dns_fixedname_t fixed1;
|
||||
dns_fixedname_t fixed2;
|
||||
dns_name_t *name1;
|
||||
|
|
@ -84,7 +104,7 @@ ATF_TC_BODY(fullcompare, tc) {
|
|||
{ NULL, NULL, dns_namereln_none, 0, 0 }
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
name1 = dns_fixedname_initname(&fixed1);
|
||||
name2 = dns_fixedname_initname(&fixed2);
|
||||
|
|
@ -97,28 +117,28 @@ ATF_TC_BODY(fullcompare, tc) {
|
|||
} else {
|
||||
result = dns_name_fromstring2(name1, data[i].name1,
|
||||
NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
if (data[i].name2[0] == 0) {
|
||||
dns_fixedname_init(&fixed2);
|
||||
} else {
|
||||
result = dns_name_fromstring2(name2, data[i].name2,
|
||||
NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
relation = dns_name_fullcompare(name1, name1, &order, &nlabels);
|
||||
ATF_REQUIRE_EQ(relation, dns_namereln_equal);
|
||||
ATF_REQUIRE_EQ(order, 0);
|
||||
ATF_REQUIRE_EQ(nlabels, name1->labels);
|
||||
assert_int_equal(relation, dns_namereln_equal);
|
||||
assert_int_equal(order, 0);
|
||||
assert_int_equal(nlabels, name1->labels);
|
||||
|
||||
/* Some random initializer */
|
||||
order = 3001;
|
||||
nlabels = 3001;
|
||||
|
||||
relation = dns_name_fullcompare(name1, name2, &order, &nlabels);
|
||||
ATF_REQUIRE_EQ(relation, data[i].relation);
|
||||
ATF_REQUIRE_EQ(order, data[i].order);
|
||||
ATF_REQUIRE_EQ(nlabels, data[i].nlabels);
|
||||
assert_int_equal(relation, data[i].relation);
|
||||
assert_int_equal(order, data[i].order);
|
||||
assert_int_equal(nlabels, data[i].nlabels);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -136,11 +156,11 @@ compress_test(dns_name_t *name1, dns_name_t *name2, dns_name_t *name3,
|
|||
isc_buffer_init(&source, buf1, sizeof(buf1));
|
||||
isc_buffer_init(&target, buf2, sizeof(buf2));
|
||||
|
||||
ATF_REQUIRE_EQ(dns_name_towire(name1, cctx, &source), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_name_towire(name1, cctx, &source), ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK_EQ(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ(dns_name_towire(name3, cctx, &source), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_name_towire(name3, cctx, &source), ISC_R_SUCCESS);
|
||||
|
||||
isc_buffer_setactive(&source, source.used);
|
||||
|
||||
|
|
@ -155,15 +175,13 @@ compress_test(dns_name_t *name1, dns_name_t *name2, dns_name_t *name3,
|
|||
&target) == ISC_R_SUCCESS);
|
||||
dns_decompress_invalidate(dctx);
|
||||
|
||||
ATF_CHECK_EQ(target.used, length);
|
||||
ATF_CHECK(memcmp(target.base, expected, target.used) == 0);
|
||||
assert_int_equal(target.used, length);
|
||||
assert_true(memcmp(target.base, expected, target.used) == 0);
|
||||
}
|
||||
|
||||
ATF_TC(compression);
|
||||
ATF_TC_HEAD(compression, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "name compression test");
|
||||
}
|
||||
ATF_TC_BODY(compression, tc) {
|
||||
/* name compression test */
|
||||
static void
|
||||
compression_test(void **state) {
|
||||
unsigned int allowed;
|
||||
dns_compress_t cctx;
|
||||
dns_decompress_t dctx;
|
||||
|
|
@ -177,7 +195,7 @@ ATF_TC_BODY(compression, tc) {
|
|||
unsigned char plain[] = "\003yyy\003foo\0\003bar\003yyy\003foo\0\003"
|
||||
"bar\003yyy\003foo\0\003xxx\003bar\003foo";
|
||||
|
||||
ATF_REQUIRE_EQ(dns_test_begin(NULL, false), ISC_R_SUCCESS);;
|
||||
UNUSED(state);
|
||||
|
||||
dns_name_init(&name1, NULL);
|
||||
r.base = plain1;
|
||||
|
|
@ -196,7 +214,7 @@ ATF_TC_BODY(compression, tc) {
|
|||
|
||||
/* Test 1: NONE */
|
||||
allowed = DNS_COMPRESS_NONE;
|
||||
ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
dns_compress_setmethods(&cctx, allowed);
|
||||
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
|
||||
dns_decompress_setmethods(&dctx, allowed);
|
||||
|
|
@ -209,7 +227,7 @@ ATF_TC_BODY(compression, tc) {
|
|||
|
||||
/* Test2: GLOBAL14 */
|
||||
allowed = DNS_COMPRESS_GLOBAL14;
|
||||
ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
dns_compress_setmethods(&cctx, allowed);
|
||||
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
|
||||
dns_decompress_setmethods(&dctx, allowed);
|
||||
|
|
@ -222,7 +240,7 @@ ATF_TC_BODY(compression, tc) {
|
|||
|
||||
/* Test3: ALL */
|
||||
allowed = DNS_COMPRESS_ALL;
|
||||
ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
dns_compress_setmethods(&cctx, allowed);
|
||||
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
|
||||
dns_decompress_setmethods(&dctx, allowed);
|
||||
|
|
@ -235,7 +253,7 @@ ATF_TC_BODY(compression, tc) {
|
|||
|
||||
/* Test4: NONE disabled */
|
||||
allowed = DNS_COMPRESS_NONE;
|
||||
ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
dns_compress_setmethods(&cctx, allowed);
|
||||
dns_compress_disable(&cctx);
|
||||
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
|
||||
|
|
@ -249,7 +267,7 @@ ATF_TC_BODY(compression, tc) {
|
|||
|
||||
/* Test5: GLOBAL14 disabled */
|
||||
allowed = DNS_COMPRESS_GLOBAL14;
|
||||
ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
dns_compress_setmethods(&cctx, allowed);
|
||||
dns_compress_disable(&cctx);
|
||||
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
|
||||
|
|
@ -263,7 +281,7 @@ ATF_TC_BODY(compression, tc) {
|
|||
|
||||
/* Test6: ALL disabled */
|
||||
allowed = DNS_COMPRESS_ALL;
|
||||
ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
|
||||
dns_compress_setmethods(&cctx, allowed);
|
||||
dns_compress_disable(&cctx);
|
||||
dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
|
||||
|
|
@ -274,15 +292,11 @@ ATF_TC_BODY(compression, tc) {
|
|||
|
||||
dns_compress_rollback(&cctx, 0);
|
||||
dns_compress_invalidate(&cctx);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(istat);
|
||||
ATF_TC_HEAD(istat, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "is trust-anchor-telemetry test");
|
||||
}
|
||||
ATF_TC_BODY(istat, tc) {
|
||||
/* is trust-anchor-telemetry test */
|
||||
static void
|
||||
istat_test(void **state) {
|
||||
dns_fixedname_t fixed;
|
||||
dns_name_t *name;
|
||||
isc_result_t result;
|
||||
|
|
@ -315,74 +329,73 @@ ATF_TC_BODY(istat, tc) {
|
|||
{ "_ta-1234-abcf-EcD89.example", false }
|
||||
};
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
name = dns_fixedname_initname(&fixed);
|
||||
|
||||
for (i = 0; i < sizeof(data)/sizeof(data[0]); i++) {
|
||||
for (i = 0; i < (sizeof(data) / sizeof(data[0])); i++) {
|
||||
result = dns_name_fromstring(name, data[i].name, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ_MSG(dns_name_istat(name), data[i].istat,
|
||||
"testing %s - expected %u", data[i].name, data[i].istat);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(dns_name_istat(name), data[i].istat);
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(init);
|
||||
ATF_TC_HEAD(init, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_nane_init");
|
||||
}
|
||||
ATF_TC_BODY(init, tc) {
|
||||
/* dns_nane_init */
|
||||
static void
|
||||
init_test(void **state) {
|
||||
dns_name_t name;
|
||||
unsigned char offsets[1];
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
dns_name_init(&name, offsets);
|
||||
|
||||
ATF_CHECK_EQ(name.ndata, NULL);
|
||||
ATF_CHECK_EQ(name.length, 0);
|
||||
ATF_CHECK_EQ(name.labels, 0);
|
||||
ATF_CHECK_EQ(name.attributes, 0);
|
||||
ATF_CHECK_EQ(name.offsets, offsets);
|
||||
ATF_CHECK_EQ(name.buffer, NULL);
|
||||
assert_null(name.ndata);
|
||||
assert_int_equal(name.length, 0);
|
||||
assert_int_equal(name.labels, 0);
|
||||
assert_int_equal(name.attributes, 0);
|
||||
assert_int_equal(name.offsets, offsets);
|
||||
assert_null(name.buffer);
|
||||
}
|
||||
|
||||
ATF_TC(invalidate);
|
||||
ATF_TC_HEAD(invalidate, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_nane_invalidate");
|
||||
}
|
||||
ATF_TC_BODY(invalidate, tc) {
|
||||
/* dns_nane_invalidate */
|
||||
static void
|
||||
invalidate_test(void **state) {
|
||||
dns_name_t name;
|
||||
unsigned char offsets[1];
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
dns_name_init(&name, offsets);
|
||||
dns_name_invalidate(&name);
|
||||
|
||||
ATF_CHECK_EQ(name.ndata, NULL);
|
||||
ATF_CHECK_EQ(name.length, 0);
|
||||
ATF_CHECK_EQ(name.labels, 0);
|
||||
ATF_CHECK_EQ(name.attributes, 0);
|
||||
ATF_CHECK_EQ(name.offsets, NULL);
|
||||
ATF_CHECK_EQ(name.buffer, NULL);
|
||||
assert_null(name.ndata);
|
||||
assert_int_equal(name.length, 0);
|
||||
assert_int_equal(name.labels, 0);
|
||||
assert_int_equal(name.attributes, 0);
|
||||
assert_null(name.offsets);
|
||||
assert_null(name.buffer);
|
||||
}
|
||||
|
||||
ATF_TC(buffer);
|
||||
ATF_TC_HEAD(buffer, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_nane_setbuffer/hasbuffer");
|
||||
}
|
||||
ATF_TC_BODY(buffer, tc) {
|
||||
/* dns_nane_setbuffer/hasbuffer */
|
||||
static void
|
||||
buffer_test(void **state) {
|
||||
dns_name_t name;
|
||||
unsigned char buf[BUFSIZ];
|
||||
isc_buffer_t b;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
isc_buffer_init(&b, buf, BUFSIZ);
|
||||
dns_name_init(&name, NULL);
|
||||
dns_name_setbuffer(&name, &b);
|
||||
ATF_CHECK_EQ(name.buffer, &b);
|
||||
ATF_CHECK(dns_name_hasbuffer(&name));
|
||||
assert_int_equal(name.buffer, &b);
|
||||
assert_true(dns_name_hasbuffer(&name));
|
||||
}
|
||||
|
||||
ATF_TC(isabsolute);
|
||||
ATF_TC_HEAD(isabsolute, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_nane_isabsolute");
|
||||
}
|
||||
ATF_TC_BODY(isabsolute, tc) {
|
||||
/* dns_nane_isabsolute */
|
||||
static void
|
||||
isabsolute_test(void **state) {
|
||||
struct {
|
||||
const char *namestr;
|
||||
bool expect;
|
||||
|
|
@ -393,7 +406,9 @@ ATF_TC_BODY(isabsolute, tc) {
|
|||
};
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) {
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) {
|
||||
isc_result_t result;
|
||||
dns_name_t name;
|
||||
unsigned char data[BUFSIZ];
|
||||
|
|
@ -408,17 +423,16 @@ ATF_TC_BODY(isabsolute, tc) {
|
|||
isc_buffer_init(&nb, data, BUFSIZ);
|
||||
dns_name_setbuffer(&name, &nb);
|
||||
result = dns_name_fromtext(&name, &b, NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK_EQ(dns_name_isabsolute(&name), testcases[i].expect);
|
||||
assert_int_equal(dns_name_isabsolute(&name),
|
||||
testcases[i].expect);
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(hash);
|
||||
ATF_TC_HEAD(hash, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_nane_hash");
|
||||
}
|
||||
ATF_TC_BODY(hash, tc) {
|
||||
/* dns_nane_hash */
|
||||
static void
|
||||
hash_test(void **state) {
|
||||
struct {
|
||||
const char *name1;
|
||||
const char *name2;
|
||||
|
|
@ -434,7 +448,9 @@ ATF_TC_BODY(hash, tc) {
|
|||
};
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) {
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) {
|
||||
isc_result_t result;
|
||||
dns_fixedname_t f1, f2;
|
||||
dns_name_t *n1, *n2;
|
||||
|
|
@ -445,10 +461,10 @@ ATF_TC_BODY(hash, tc) {
|
|||
|
||||
result = dns_name_fromstring2(n1, testcases[i].name1,
|
||||
NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_name_fromstring2(n2, testcases[i].name2,
|
||||
NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Check case-insensitive hashing first */
|
||||
h1 = dns_name_hash(n1, false);
|
||||
|
|
@ -457,7 +473,7 @@ ATF_TC_BODY(hash, tc) {
|
|||
printf("%s hashes to %u, %s to %u, case insensitive\n",
|
||||
testcases[i].name1, h1, testcases[i].name2, h2);
|
||||
|
||||
ATF_REQUIRE_EQ((h1 == h2), testcases[i].expect);
|
||||
assert_int_equal((h1 == h2), testcases[i].expect);
|
||||
|
||||
/* Now case-sensitive */
|
||||
h1 = dns_name_hash(n1, false);
|
||||
|
|
@ -466,15 +482,13 @@ ATF_TC_BODY(hash, tc) {
|
|||
printf("%s hashes to %u, %s to %u, case sensitive\n",
|
||||
testcases[i].name1, h1, testcases[i].name2, h2);
|
||||
|
||||
ATF_REQUIRE_EQ((h1 == h2), testcases[i].expect);
|
||||
assert_int_equal((h1 == h2), testcases[i].expect);
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(issubdomain);
|
||||
ATF_TC_HEAD(issubdomain, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_nane_issubdomain");
|
||||
}
|
||||
ATF_TC_BODY(issubdomain, tc) {
|
||||
/* dns_nane_issubdomain */
|
||||
static void
|
||||
issubdomain_test(void **state) {
|
||||
struct {
|
||||
const char *name1;
|
||||
const char *name2;
|
||||
|
|
@ -490,7 +504,9 @@ ATF_TC_BODY(issubdomain, tc) {
|
|||
};
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) {
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) {
|
||||
isc_result_t result;
|
||||
dns_fixedname_t f1, f2;
|
||||
dns_name_t *n1, *n2;
|
||||
|
|
@ -500,26 +516,24 @@ ATF_TC_BODY(issubdomain, tc) {
|
|||
|
||||
result = dns_name_fromstring2(n1, testcases[i].name1,
|
||||
NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_name_fromstring2(n2, testcases[i].name2,
|
||||
NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
printf("check: %s %s a subdomain of %s\n",
|
||||
testcases[i].name1,
|
||||
testcases[i].expect ? "is" : "is not",
|
||||
testcases[i].name2);
|
||||
|
||||
ATF_CHECK_EQ(dns_name_issubdomain(n1, n2),
|
||||
assert_int_equal(dns_name_issubdomain(n1, n2),
|
||||
testcases[i].expect);
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(countlabels);
|
||||
ATF_TC_HEAD(countlabels, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_nane_countlabels");
|
||||
}
|
||||
ATF_TC_BODY(countlabels, tc) {
|
||||
/* dns_nane_countlabels */
|
||||
static void
|
||||
countlabels_test(void **state) {
|
||||
struct {
|
||||
const char *namestr;
|
||||
unsigned int expect;
|
||||
|
|
@ -533,7 +547,9 @@ ATF_TC_BODY(countlabels, tc) {
|
|||
};
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) {
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) {
|
||||
isc_result_t result;
|
||||
dns_fixedname_t fname;
|
||||
dns_name_t *name;
|
||||
|
|
@ -542,21 +558,19 @@ ATF_TC_BODY(countlabels, tc) {
|
|||
|
||||
result = dns_name_fromstring2(name, testcases[i].namestr,
|
||||
NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
printf("%s: expect %u labels\n",
|
||||
testcases[i].namestr, testcases[i].expect);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_name_countlabels(name),
|
||||
assert_int_equal(dns_name_countlabels(name),
|
||||
testcases[i].expect);
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(getlabel);
|
||||
ATF_TC_HEAD(getlabel, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_nane_getlabel");
|
||||
}
|
||||
ATF_TC_BODY(getlabel, tc) {
|
||||
/* dns_nane_getlabel */
|
||||
static void
|
||||
getlabel_test(void **state) {
|
||||
struct {
|
||||
const char *name1;
|
||||
unsigned int pos1;
|
||||
|
|
@ -569,7 +583,9 @@ ATF_TC_BODY(getlabel, tc) {
|
|||
};
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) {
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) {
|
||||
isc_result_t result;
|
||||
dns_fixedname_t f1, f2;
|
||||
dns_name_t *n1, *n2;
|
||||
|
|
@ -582,28 +598,26 @@ ATF_TC_BODY(getlabel, tc) {
|
|||
|
||||
result = dns_name_fromstring2(n1, testcases[i].name1,
|
||||
NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_name_fromstring2(n2, testcases[i].name2,
|
||||
NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_name_getlabel(n1, testcases[i].pos1, &l1);
|
||||
dns_name_getlabel(n2, testcases[i].pos2, &l2);
|
||||
ATF_CHECK_EQ(l1.length, l2.length);
|
||||
assert_int_equal(l1.length, l2.length);
|
||||
|
||||
p1 = l1.base;
|
||||
p2 = l2.base;
|
||||
for (j = 0; j < l1.length; j++) {
|
||||
ATF_REQUIRE_EQ(*p1++, *p2++);
|
||||
assert_int_equal(*p1++, *p2++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(getlabelsequence);
|
||||
ATF_TC_HEAD(getlabelsequence, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_nane_getlabelsequence");
|
||||
}
|
||||
ATF_TC_BODY(getlabelsequence, tc) {
|
||||
/* dns_nane_getlabelsequence */
|
||||
static void
|
||||
getlabelsequence_test(void **state) {
|
||||
struct {
|
||||
const char *name1;
|
||||
unsigned int pos1;
|
||||
|
|
@ -618,7 +632,9 @@ ATF_TC_BODY(getlabelsequence, tc) {
|
|||
};
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < (sizeof(testcases)/sizeof(testcases[0])); i++) {
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < (sizeof(testcases) / sizeof(testcases[0])); i++) {
|
||||
isc_result_t result;
|
||||
dns_name_t t1, t2;
|
||||
dns_fixedname_t f1, f2;
|
||||
|
|
@ -634,17 +650,17 @@ ATF_TC_BODY(getlabelsequence, tc) {
|
|||
|
||||
result = dns_name_fromstring2(n1, testcases[i].name1,
|
||||
NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_name_fromstring2(n2, testcases[i].name2,
|
||||
NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_name_getlabelsequence(n1, testcases[i].pos1,
|
||||
testcases[i].range, &t1);
|
||||
dns_name_getlabelsequence(n2, testcases[i].pos2,
|
||||
testcases[i].range, &t2);
|
||||
|
||||
ATF_REQUIRE(dns_name_equal(&t1, &t2));
|
||||
assert_true(dns_name_equal(&t1, &t2));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -656,11 +672,7 @@ ATF_TC_BODY(getlabelsequence, tc) {
|
|||
* name parser, but we don't require it as part of the unit test runs.
|
||||
*/
|
||||
|
||||
ATF_TC(benchmark);
|
||||
ATF_TC_HEAD(benchmark, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"Benchmark dns_name_fromwire() implementation");
|
||||
}
|
||||
/* Benchmark dns_name_fromwire() implementation */
|
||||
|
||||
static void *
|
||||
fromwire_thread(void *arg) {
|
||||
|
|
@ -701,7 +713,8 @@ fromwire_thread(void *arg) {
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
ATF_TC_BODY(benchmark, tc) {
|
||||
static void
|
||||
benchmark_test(void **state) {
|
||||
isc_result_t result;
|
||||
unsigned int i;
|
||||
isc_time_t ts1, ts2;
|
||||
|
|
@ -709,64 +722,73 @@ ATF_TC_BODY(benchmark, tc) {
|
|||
unsigned int nthreads;
|
||||
isc_thread_t threads[32];
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
debug_mem_record = false;
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_time_now(&ts1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
nthreads = ISC_MIN(isc_os_ncpus(), 32);
|
||||
nthreads = ISC_MAX(nthreads, 1);
|
||||
for (i = 0; i < nthreads; i++) {
|
||||
result = isc_thread_create(fromwire_thread, NULL, &threads[i]);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
for (i = 0; i < nthreads; i++) {
|
||||
result = isc_thread_join(threads[i], NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
result = isc_time_now(&ts2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
t = isc_time_microdiff(&ts2, &ts1);
|
||||
|
||||
printf("%u dns_name_fromwire() calls, %f seconds, %f calls/second\n",
|
||||
nthreads * 32000000, t / 1000000.0,
|
||||
(nthreads * 32000000) / (t / 1000000.0));
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
#endif /* DNS_BENCHMARK_TESTS */
|
||||
#endif /* ISC_PLATFORM_USETHREADS */
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, fullcompare);
|
||||
ATF_TP_ADD_TC(tp, compression);
|
||||
ATF_TP_ADD_TC(tp, istat);
|
||||
ATF_TP_ADD_TC(tp, init);
|
||||
ATF_TP_ADD_TC(tp, invalidate);
|
||||
ATF_TP_ADD_TC(tp, buffer);
|
||||
ATF_TP_ADD_TC(tp, isabsolute);
|
||||
ATF_TP_ADD_TC(tp, hash);
|
||||
ATF_TP_ADD_TC(tp, issubdomain);
|
||||
ATF_TP_ADD_TC(tp, countlabels);
|
||||
ATF_TP_ADD_TC(tp, getlabel);
|
||||
ATF_TP_ADD_TC(tp, getlabelsequence);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(fullcompare_test),
|
||||
cmocka_unit_test_setup_teardown(compression_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test(istat_test),
|
||||
cmocka_unit_test(init_test),
|
||||
cmocka_unit_test(invalidate_test),
|
||||
cmocka_unit_test(buffer_test),
|
||||
cmocka_unit_test(isabsolute_test),
|
||||
cmocka_unit_test(hash_test),
|
||||
cmocka_unit_test(issubdomain_test),
|
||||
cmocka_unit_test(countlabels_test),
|
||||
cmocka_unit_test(getlabel_test),
|
||||
cmocka_unit_test(getlabelsequence_test),
|
||||
#ifdef ISC_PLATFORM_USETHREADS
|
||||
#ifdef DNS_BENCHMARK_TESTS
|
||||
ATF_TP_ADD_TC(tp, benchmark);
|
||||
cmocka_unit_test_setup_teardown(benchmark_test,
|
||||
_setup, _teardown),
|
||||
#endif /* DNS_BENCHMARK_TESTS */
|
||||
#endif /* ISC_PLATFORM_USETHREADS */
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,24 +9,51 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/db.h>
|
||||
#include <dns/nsec3.h>
|
||||
|
||||
#include "dnstest.h"
|
||||
|
||||
#if defined(OPENSSL) || defined(PKCS11CRYPTO)
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
iteration_test(const char *file, unsigned int expected) {
|
||||
|
|
@ -35,12 +62,12 @@ iteration_test(const char *file, unsigned int expected) {
|
|||
unsigned int iterations;
|
||||
|
||||
result = dns_test_loaddb(&db, dns_dbtype_zone, "test", file);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS, "%s", file);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_nsec3_maxiterations(db, NULL, mctx, &iterations);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS, "%s", file);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK_EQ_MSG(iterations, expected, "%s", file);
|
||||
assert_int_equal(iterations, expected);
|
||||
|
||||
dns_db_detach(&db);
|
||||
}
|
||||
|
|
@ -76,21 +103,17 @@ nsec3param_salttotext_test(const nsec3param_salttotext_test_params_t *params) {
|
|||
result = dns_test_rdatafromstring(&rdata, dns_rdataclass_in,
|
||||
dns_rdatatype_nsec3param, buf,
|
||||
sizeof(buf),
|
||||
params->nsec3param_text);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
params->nsec3param_text, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_rdata_tostruct(&rdata, &nsec3param, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Check typical use.
|
||||
*/
|
||||
result = dns_nsec3param_salttotext(&nsec3param, salt, sizeof(salt));
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"\"%s\": expected success, got %s\n",
|
||||
params->nsec3param_text, isc_result_totext(result));
|
||||
ATF_CHECK_EQ_MSG(strcmp(salt, params->expected_salt), 0,
|
||||
"\"%s\": expected salt \"%s\", got \"%s\"",
|
||||
params->nsec3param_text, params->expected_salt, salt);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(salt, params->expected_salt);
|
||||
|
||||
/*
|
||||
* Ensure available space in the buffer is checked before the salt is
|
||||
|
|
@ -98,61 +121,37 @@ nsec3param_salttotext_test(const nsec3param_salttotext_test_params_t *params) {
|
|||
* terminating NULL byte.
|
||||
*/
|
||||
length = strlen(params->expected_salt);
|
||||
ATF_REQUIRE(length < sizeof(salt) - 1); /* prevent buffer overwrite */
|
||||
ATF_REQUIRE(length > 0U); /* prevent length underflow */
|
||||
assert_true(length < sizeof(salt) - 1); /* prevent buffer overwrite */
|
||||
assert_true(length > 0U); /* prevent length underflow */
|
||||
|
||||
result = dns_nsec3param_salttotext(&nsec3param, salt, length - 1);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_NOSPACE,
|
||||
"\"%s\": expected a %lu-byte target buffer to be "
|
||||
"rejected, got %s\n",
|
||||
params->nsec3param_text, (unsigned long)(length - 1),
|
||||
isc_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_NOSPACE);
|
||||
|
||||
result = dns_nsec3param_salttotext(&nsec3param, salt, length);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_NOSPACE,
|
||||
"\"%s\": expected a %lu-byte target buffer to be "
|
||||
"rejected, got %s\n",
|
||||
params->nsec3param_text, (unsigned long)length,
|
||||
isc_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_NOSPACE);
|
||||
|
||||
result = dns_nsec3param_salttotext(&nsec3param, salt, length + 1);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"\"%s\": expected a %lu-byte target buffer to be "
|
||||
"accepted, got %s\n",
|
||||
params->nsec3param_text, (unsigned long)(length + 1),
|
||||
isc_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
* check that appropriate max iterations is returned for different
|
||||
* key size mixes
|
||||
*/
|
||||
|
||||
ATF_TC(max_iterations);
|
||||
ATF_TC_HEAD(max_iterations, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "check that appropriate max iterations "
|
||||
" is returned for different key size mixes");
|
||||
}
|
||||
ATF_TC_BODY(max_iterations, tc) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
static void
|
||||
max_iterations(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
iteration_test("testdata/nsec3/1024.db", 150);
|
||||
iteration_test("testdata/nsec3/2048.db", 500);
|
||||
iteration_test("testdata/nsec3/4096.db", 2500);
|
||||
iteration_test("testdata/nsec3/min-1024.db", 150);
|
||||
iteration_test("testdata/nsec3/min-2048.db", 500);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(nsec3param_salttotext);
|
||||
ATF_TC_HEAD(nsec3param_salttotext, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "check dns_nsec3param_salttotext()");
|
||||
}
|
||||
ATF_TC_BODY(nsec3param_salttotext, tc) {
|
||||
isc_result_t result;
|
||||
/* check dns_nsec3param_salttotext() */
|
||||
static void
|
||||
nsec3param_salttotext(void **state) {
|
||||
size_t i;
|
||||
|
||||
const nsec3param_salttotext_test_params_t tests[] = {
|
||||
|
|
@ -169,39 +168,38 @@ ATF_TC_BODY(nsec3param_salttotext, tc) {
|
|||
{ "0 0 0 -", "-" },
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
|
||||
nsec3param_salttotext_test(&tests[i]);
|
||||
}
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
#else
|
||||
ATF_TC(untested);
|
||||
ATF_TC_HEAD(untested, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "skipping nsec3 test");
|
||||
}
|
||||
ATF_TC_BODY(untested, tc) {
|
||||
UNUSED(tc);
|
||||
atf_tc_skip("DNSSEC not available");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
int
|
||||
main(void) {
|
||||
#if defined(OPENSSL) || defined(PKCS11CRYPTO)
|
||||
ATF_TP_ADD_TC(tp, max_iterations);
|
||||
ATF_TP_ADD_TC(tp, nsec3param_salttotext);
|
||||
#else
|
||||
ATF_TP_ADD_TC(tp, untested);
|
||||
#endif
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(max_iterations,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(nsec3param_salttotext,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
#else
|
||||
print_message("1..0 # Skipped: nsec3 test requires crypto\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,35 +9,59 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/peer.h>
|
||||
|
||||
#include "dnstest.h"
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
ATF_TC(dscp);
|
||||
ATF_TC_HEAD(dscp, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"Test DSCP set/get functions");
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
ATF_TC_BODY(dscp, tc) {
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Test DSCP set/get functions */
|
||||
static void
|
||||
dscp_test(void **state) {
|
||||
isc_result_t result;
|
||||
isc_netaddr_t netaddr;
|
||||
struct in_addr ina;
|
||||
dns_peer_t *peer = NULL;
|
||||
isc_dscp_t dscp;
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* Create peer structure for the loopback address.
|
||||
|
|
@ -45,7 +69,7 @@ ATF_TC_BODY(dscp, tc) {
|
|||
ina.s_addr = INADDR_LOOPBACK;
|
||||
isc_netaddr_fromin(&netaddr, &ina);
|
||||
result = dns_peer_new(mctx, &netaddr, &peer);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* All should be not set on creation.
|
||||
|
|
@ -53,16 +77,16 @@ ATF_TC_BODY(dscp, tc) {
|
|||
*/
|
||||
dscp = 100;
|
||||
result = dns_peer_getquerydscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dscp, 100);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
assert_int_equal(dscp, 100);
|
||||
|
||||
result = dns_peer_getnotifydscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dscp, 100);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
assert_int_equal(dscp, 100);
|
||||
|
||||
result = dns_peer_gettransferdscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dscp, 100);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
assert_int_equal(dscp, 100);
|
||||
|
||||
/*
|
||||
* Test that setting query dscp does not affect the other
|
||||
|
|
@ -71,19 +95,19 @@ ATF_TC_BODY(dscp, tc) {
|
|||
*/
|
||||
dscp = 100;
|
||||
result = dns_peer_setquerydscp(peer, 1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_peer_getnotifydscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dscp, 100);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
assert_int_equal(dscp, 100);
|
||||
|
||||
result = dns_peer_gettransferdscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dscp, 100);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
assert_int_equal(dscp, 100);
|
||||
|
||||
result = dns_peer_getquerydscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dscp, 1);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(dscp, 1);
|
||||
|
||||
/*
|
||||
* Test that setting notify dscp does not affect the other
|
||||
|
|
@ -93,19 +117,19 @@ ATF_TC_BODY(dscp, tc) {
|
|||
*/
|
||||
dscp = 100;
|
||||
result = dns_peer_setnotifydscp(peer, 2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_peer_gettransferdscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(dscp, 100);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
assert_int_equal(dscp, 100);
|
||||
|
||||
result = dns_peer_getquerydscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dscp, 1);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(dscp, 1);
|
||||
|
||||
result = dns_peer_getnotifydscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dscp, 2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(dscp, 2);
|
||||
|
||||
/*
|
||||
* Test that setting notify dscp does not affect the other
|
||||
|
|
@ -113,28 +137,40 @@ ATF_TC_BODY(dscp, tc) {
|
|||
*/
|
||||
dscp = 100;
|
||||
result = dns_peer_settransferdscp(peer, 3);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_peer_getquerydscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dscp, 1);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(dscp, 1);
|
||||
|
||||
result = dns_peer_getnotifydscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dscp, 2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(dscp, 2);
|
||||
|
||||
result = dns_peer_gettransferdscp(peer, &dscp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(dscp, 3);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(dscp, 3);
|
||||
|
||||
dns_peer_detach(&peer);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, dscp);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(dscp_test, _setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,17 +10,25 @@
|
|||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/nsec3.h>
|
||||
#include <dns/private.h>
|
||||
|
|
@ -33,6 +41,27 @@
|
|||
|
||||
static dns_rdatatype_t privatetype = 65534;
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
unsigned char alg;
|
||||
dns_keytag_t keyid;
|
||||
|
|
@ -50,9 +79,6 @@ typedef struct {
|
|||
bool nonsec;
|
||||
} nsec3_testcase_t;
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
static void
|
||||
make_signing(signing_testcase_t *testcase, dns_rdata_t *private,
|
||||
unsigned char *buf, size_t len)
|
||||
|
|
@ -100,12 +126,14 @@ make_nsec3(nsec3_testcase_t *testcase, dns_rdata_t *private,
|
|||
params.flags = testcase->flags;
|
||||
if (testcase->remove) {
|
||||
params.flags |= DNS_NSEC3FLAG_REMOVE;
|
||||
if (testcase->nonsec)
|
||||
if (testcase->nonsec) {
|
||||
params.flags |= DNS_NSEC3FLAG_NONSEC;
|
||||
}
|
||||
} else {
|
||||
params.flags |= DNS_NSEC3FLAG_CREATE;
|
||||
if (testcase->pending)
|
||||
if (testcase->pending) {
|
||||
params.flags |= DNS_NSEC3FLAG_INITIAL;
|
||||
}
|
||||
}
|
||||
|
||||
isc_buffer_init(&buf, bufdata, sizeof(bufdata));
|
||||
|
|
@ -118,16 +146,9 @@ make_nsec3(nsec3_testcase_t *testcase, dns_rdata_t *private,
|
|||
pbuf, DNS_NSEC3PARAM_BUFFERSIZE + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
ATF_TC(private_signing_totext);
|
||||
ATF_TC_HEAD(private_signing_totext, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"convert private signing records to text");
|
||||
}
|
||||
ATF_TC_BODY(private_signing_totext, tc) {
|
||||
isc_result_t result;
|
||||
/* convert private signing records to text */
|
||||
static void
|
||||
private_signing_totext_test(void **state) {
|
||||
dns_rdata_t private;
|
||||
int i;
|
||||
|
||||
|
|
@ -145,10 +166,7 @@ ATF_TC_BODY(private_signing_totext, tc) {
|
|||
};
|
||||
int ncases = 4;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < ncases; i++) {
|
||||
unsigned char data[5];
|
||||
|
|
@ -159,18 +177,14 @@ ATF_TC_BODY(private_signing_totext, tc) {
|
|||
|
||||
make_signing(&testcases[i], &private, data, sizeof(data));
|
||||
dns_private_totext(&private, &buf);
|
||||
ATF_CHECK_STREQ(output, results[i]);
|
||||
assert_string_equal(output, results[i]);
|
||||
}
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(private_nsec3_totext);
|
||||
ATF_TC_HEAD(private_nsec3_totext, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "convert private chain records to text");
|
||||
}
|
||||
ATF_TC_BODY(private_nsec3_totext, tc) {
|
||||
isc_result_t result;
|
||||
/* convert private chain records to text */
|
||||
static void
|
||||
private_nsec3_totext_test(void **state) {
|
||||
dns_rdata_t private;
|
||||
int i;
|
||||
|
||||
|
|
@ -190,10 +204,7 @@ ATF_TC_BODY(private_nsec3_totext, tc) {
|
|||
};
|
||||
int ncases = 5;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < ncases; i++) {
|
||||
unsigned char data[DNS_NSEC3PARAM_BUFFERSIZE + 1];
|
||||
|
|
@ -204,17 +215,30 @@ ATF_TC_BODY(private_nsec3_totext, tc) {
|
|||
|
||||
make_nsec3(&testcases[i], &private, data);
|
||||
dns_private_totext(&private, &buf);
|
||||
ATF_CHECK_STREQ(output, results[i]);
|
||||
assert_string_equal(output, results[i]);
|
||||
}
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, private_signing_totext);
|
||||
ATF_TP_ADD_TC(tp, private_nsec3_totext);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(private_signing_totext_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(private_nsec3_totext_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,17 +10,23 @@
|
|||
*/
|
||||
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/mem.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/random.h>
|
||||
|
|
@ -56,6 +62,27 @@
|
|||
#define MAP_FILE 0
|
||||
#endif
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
typedef struct data_holder {
|
||||
int len;
|
||||
const char *data;
|
||||
|
|
@ -118,8 +145,9 @@ write_data(FILE *file, unsigned char *datap, void *arg, uint64_t *crc) {
|
|||
(data->len != 0 && data->data != NULL));
|
||||
|
||||
result = isc_stdio_tell(file, &where);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
temp = *data;
|
||||
temp.data = (data->len == 0
|
||||
|
|
@ -128,22 +156,22 @@ write_data(FILE *file, unsigned char *datap, void *arg, uint64_t *crc) {
|
|||
|
||||
isc_crc64_update(crc, (void *)&temp, sizeof(temp));
|
||||
ret = fwrite(&temp, sizeof(data_holder_t), 1, file);
|
||||
if (ret != 1)
|
||||
if (ret != 1) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
if (data->len > 0) {
|
||||
isc_crc64_update(crc, (const void *)data->data, data->len);
|
||||
ret = fwrite(data->data, data->len, 1, file);
|
||||
if (ret != 1)
|
||||
if (ret != 1) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
fix_data(dns_rbtnode_t *p, void *base, size_t max, void *arg,
|
||||
uint64_t *crc)
|
||||
{
|
||||
fix_data(dns_rbtnode_t *p, void *base, size_t max, void *arg, uint64_t *crc) {
|
||||
data_holder_t *data = p->data;
|
||||
size_t size;
|
||||
|
||||
|
|
@ -155,31 +183,29 @@ fix_data(dns_rbtnode_t *p, void *base, size_t max, void *arg,
|
|||
REQUIRE(p != NULL);
|
||||
|
||||
|
||||
if (data == NULL)
|
||||
printf("fixing data: data NULL\n");
|
||||
else
|
||||
printf("fixing data: len %d, data %p\n", data->len, data->data);
|
||||
|
||||
if (data == NULL ||
|
||||
(data->len == 0 && data->data != NULL) ||
|
||||
(data->len != 0 && data->data == NULL))
|
||||
{
|
||||
return (ISC_R_INVALIDFILE);
|
||||
}
|
||||
|
||||
size = max - ((char *)p - (char *)base);
|
||||
|
||||
if (data->len > (int) size || data->data > (const char *) max) {
|
||||
printf("data invalid\n");
|
||||
return (ISC_R_INVALIDFILE);
|
||||
}
|
||||
|
||||
isc_crc64_update(crc, (void *)data, sizeof(*data));
|
||||
|
||||
data->data = (data->len == 0)
|
||||
? NULL
|
||||
: (char *)data + sizeof(data_holder_t);
|
||||
data->data = NULL;
|
||||
if (data->len != 0) {
|
||||
data->data = (char *)data + sizeof(data_holder_t);
|
||||
}
|
||||
|
||||
if (data->len > 0)
|
||||
if (data->len > 0) {
|
||||
isc_crc64_update(crc, (const void *)data->data, data->len);
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
|
@ -213,7 +239,7 @@ add_test_data(isc_mem_t *mymctx, dns_rbt_t *rbt) {
|
|||
|
||||
if (name != NULL) {
|
||||
result = dns_rbt_addname(rbt, name, &testdatap->data);
|
||||
ATF_CHECK_STREQ(dns_result_totext(result), "success");
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
testdatap++;
|
||||
}
|
||||
|
|
@ -255,25 +281,22 @@ check_test_data(dns_rbt_t *rbt) {
|
|||
data = NULL;
|
||||
result = dns_rbt_findname(rbt, name, 0, foundname,
|
||||
(void *) &data);
|
||||
ATF_CHECK_STREQ(dns_result_totext(result), "success");
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
testdatap++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
data_printer(FILE *out, void *datap)
|
||||
{
|
||||
data_printer(FILE *out, void *datap) {
|
||||
data_holder_t *data = (data_holder_t *)datap;
|
||||
|
||||
fprintf(out, "%d bytes, %s", data->len, data->data);
|
||||
}
|
||||
|
||||
ATF_TC(serialize);
|
||||
ATF_TC_HEAD(serialize, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Test writing an rbt to file");
|
||||
}
|
||||
ATF_TC_BODY(serialize, tc) {
|
||||
/* Test writing an rbt to file */
|
||||
static void
|
||||
serialize_test(void **state) {
|
||||
dns_rbt_t *rbt = NULL;
|
||||
isc_result_t result;
|
||||
FILE *rbtfile = NULL;
|
||||
|
|
@ -283,14 +306,12 @@ ATF_TC_BODY(serialize, tc) {
|
|||
off_t filesize = 0;
|
||||
char *base;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_CHECK_STREQ(dns_result_totext(result), "success");
|
||||
result = dns_rbt_create(mctx, delete_data, NULL, &rbt);
|
||||
ATF_CHECK_STREQ(dns_result_totext(result), "success");
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
add_test_data(mctx, rbt);
|
||||
|
||||
|
|
@ -299,28 +320,22 @@ ATF_TC_BODY(serialize, tc) {
|
|||
/*
|
||||
* Serialize the tree.
|
||||
*/
|
||||
printf("serialization begins.\n");
|
||||
rbtfile = fopen("./zone.bin", "w+b");
|
||||
ATF_REQUIRE(rbtfile != NULL);
|
||||
assert_non_null(rbtfile);
|
||||
result = dns_rbt_serialize_tree(rbtfile, rbt, write_data, NULL,
|
||||
&offset);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
assert_true(result == ISC_R_SUCCESS);
|
||||
dns_rbt_destroy(&rbt);
|
||||
|
||||
/*
|
||||
* Deserialize the tree
|
||||
*/
|
||||
printf("deserialization begins.\n");
|
||||
|
||||
/*
|
||||
* Deserialize the tree.
|
||||
* Map in the whole file in one go
|
||||
*/
|
||||
fd = open("zone.bin", O_RDWR);
|
||||
isc_file_getsizefd(fd, &filesize);
|
||||
base = mmap(NULL, filesize,
|
||||
PROT_READ|PROT_WRITE,
|
||||
base = mmap(NULL, filesize, PROT_READ|PROT_WRITE,
|
||||
MAP_FILE|MAP_PRIVATE, fd, 0);
|
||||
ATF_REQUIRE(base != NULL && base != MAP_FAILED);
|
||||
assert_true(base != NULL && base != MAP_FAILED);
|
||||
close(fd);
|
||||
|
||||
result = dns_rbt_deserialize_tree(base, filesize, 0, mctx,
|
||||
|
|
@ -328,9 +343,10 @@ ATF_TC_BODY(serialize, tc) {
|
|||
NULL, &rbt_deserialized);
|
||||
|
||||
/* Test to make sure we have a valid tree */
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
if (rbt_deserialized == NULL)
|
||||
atf_tc_fail("deserialized rbt is null!"); /* Abort execution. */
|
||||
assert_true(result == ISC_R_SUCCESS);
|
||||
if (rbt_deserialized == NULL) {
|
||||
fail_msg("deserialized rbt is null!"); /* Abort execution. */
|
||||
}
|
||||
|
||||
check_test_data(rbt_deserialized);
|
||||
|
||||
|
|
@ -339,14 +355,11 @@ ATF_TC_BODY(serialize, tc) {
|
|||
dns_rbt_destroy(&rbt_deserialized);
|
||||
munmap(base, filesize);
|
||||
unlink("zone.bin");
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(deserialize_corrupt);
|
||||
ATF_TC_HEAD(deserialize_corrupt, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Test reading a corrupt map file");
|
||||
}
|
||||
ATF_TC_BODY(deserialize_corrupt, tc) {
|
||||
/* Test reading a corrupt map file */
|
||||
static void
|
||||
deserialize_corrupt_test(void **state) {
|
||||
dns_rbt_t *rbt = NULL;
|
||||
isc_result_t result;
|
||||
FILE *rbtfile = NULL;
|
||||
|
|
@ -357,23 +370,20 @@ ATF_TC_BODY(deserialize_corrupt, tc) {
|
|||
uint32_t r;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Set up map file */
|
||||
result = dns_rbt_create(mctx, delete_data, NULL, &rbt);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
add_test_data(mctx, rbt);
|
||||
rbtfile = fopen("./zone.bin", "w+b");
|
||||
ATF_REQUIRE(rbtfile != NULL);
|
||||
assert_non_null(rbtfile);
|
||||
result = dns_rbt_serialize_tree(rbtfile, rbt, write_data, NULL,
|
||||
&offset);
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS);
|
||||
assert_true(result == ISC_R_SUCCESS);
|
||||
dns_rbt_destroy(&rbt);
|
||||
|
||||
/* Read back with random fuzzing */
|
||||
|
|
@ -382,10 +392,9 @@ ATF_TC_BODY(deserialize_corrupt, tc) {
|
|||
|
||||
fd = open("zone.bin", O_RDWR);
|
||||
isc_file_getsizefd(fd, &filesize);
|
||||
base = mmap(NULL, filesize,
|
||||
PROT_READ|PROT_WRITE,
|
||||
base = mmap(NULL, filesize, PROT_READ|PROT_WRITE,
|
||||
MAP_FILE|MAP_PRIVATE, fd, 0);
|
||||
ATF_REQUIRE(base != NULL && base != MAP_FAILED);
|
||||
assert_true(base != NULL && base != MAP_FAILED);
|
||||
close(fd);
|
||||
|
||||
/* Randomly fuzz a portion of the memory */
|
||||
|
|
@ -403,54 +412,64 @@ ATF_TC_BODY(deserialize_corrupt, tc) {
|
|||
delete_data, NULL,
|
||||
fix_data, NULL,
|
||||
NULL, &rbt_deserialized);
|
||||
printf("%d: %s\n", i, isc_result_totext(result));
|
||||
|
||||
/* Test to make sure we have a valid tree */
|
||||
ATF_REQUIRE(result == ISC_R_SUCCESS ||
|
||||
assert_true(result == ISC_R_SUCCESS ||
|
||||
result == ISC_R_INVALIDFILE);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
ATF_REQUIRE(rbt_deserialized == NULL);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
assert_null(rbt_deserialized);
|
||||
}
|
||||
|
||||
if (rbt_deserialized != NULL)
|
||||
if (rbt_deserialized != NULL) {
|
||||
dns_rbt_destroy(&rbt_deserialized);
|
||||
}
|
||||
|
||||
munmap(base, filesize);
|
||||
}
|
||||
|
||||
unlink("zone.bin");
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/* Test the dns_rbt_serialize_align() function */
|
||||
static void
|
||||
serialize_align_test(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
ATF_TC(serialize_align);
|
||||
ATF_TC_HEAD(serialize_align, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"Test the dns_rbt_serialize_align() function.");
|
||||
}
|
||||
ATF_TC_BODY(serialize_align, tc) {
|
||||
UNUSED(tc);
|
||||
|
||||
ATF_CHECK(dns_rbt_serialize_align(0) == 0);
|
||||
ATF_CHECK(dns_rbt_serialize_align(1) == 8);
|
||||
ATF_CHECK(dns_rbt_serialize_align(2) == 8);
|
||||
ATF_CHECK(dns_rbt_serialize_align(3) == 8);
|
||||
ATF_CHECK(dns_rbt_serialize_align(4) == 8);
|
||||
ATF_CHECK(dns_rbt_serialize_align(5) == 8);
|
||||
ATF_CHECK(dns_rbt_serialize_align(6) == 8);
|
||||
ATF_CHECK(dns_rbt_serialize_align(7) == 8);
|
||||
ATF_CHECK(dns_rbt_serialize_align(8) == 8);
|
||||
ATF_CHECK(dns_rbt_serialize_align(9) == 16);
|
||||
ATF_CHECK(dns_rbt_serialize_align(0xff) == 0x100);
|
||||
ATF_CHECK(dns_rbt_serialize_align(0x301) == 0x308);
|
||||
assert_true(dns_rbt_serialize_align(0) == 0);
|
||||
assert_true(dns_rbt_serialize_align(1) == 8);
|
||||
assert_true(dns_rbt_serialize_align(2) == 8);
|
||||
assert_true(dns_rbt_serialize_align(3) == 8);
|
||||
assert_true(dns_rbt_serialize_align(4) == 8);
|
||||
assert_true(dns_rbt_serialize_align(5) == 8);
|
||||
assert_true(dns_rbt_serialize_align(6) == 8);
|
||||
assert_true(dns_rbt_serialize_align(7) == 8);
|
||||
assert_true(dns_rbt_serialize_align(8) == 8);
|
||||
assert_true(dns_rbt_serialize_align(9) == 16);
|
||||
assert_true(dns_rbt_serialize_align(0xff) == 0x100);
|
||||
assert_true(dns_rbt_serialize_align(0x301) == 0x308);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, serialize);
|
||||
ATF_TP_ADD_TC(tp, deserialize_corrupt);
|
||||
ATF_TP_ADD_TC(tp, serialize_align);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(serialize_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(deserialize_corrupt_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test(serialize_align_test),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -9,27 +9,33 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/hex.h>
|
||||
#include <isc/lex.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/stdio.h>
|
||||
#include <isc/types.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/callbacks.h>
|
||||
#include <dns/rdata.h>
|
||||
|
||||
#include "dnstest.h"
|
||||
|
||||
/*****
|
||||
***** Commonly used structures
|
||||
*****/
|
||||
/*
|
||||
* An array of these structures is passed to compare_ok().
|
||||
*/
|
||||
|
|
@ -41,31 +47,44 @@ struct compare_ok {
|
|||
};
|
||||
typedef struct compare_ok compare_ok_t;
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* An array of these structures is passed to check_text_ok().
|
||||
*/
|
||||
struct text_ok {
|
||||
typedef struct text_ok {
|
||||
const char *text_in; /* text passed to fromtext_*() */
|
||||
const char *text_out; /* text expected from totext_*();
|
||||
NULL indicates text_in is invalid */
|
||||
int lineno; /* source line defining this RDATA */
|
||||
};
|
||||
typedef struct text_ok text_ok_t;
|
||||
} text_ok_t;
|
||||
|
||||
/*
|
||||
* An array of these structures is passed to check_wire_ok().
|
||||
*/
|
||||
struct wire_ok {
|
||||
typedef struct wire_ok {
|
||||
unsigned char data[512]; /* RDATA in wire format */
|
||||
size_t len; /* octets of data to parse */
|
||||
bool ok; /* is this RDATA valid? */
|
||||
int lineno; /* source line defining this RDATA */
|
||||
};
|
||||
typedef struct wire_ok wire_ok_t;
|
||||
|
||||
/*****
|
||||
***** Convenience macros for creating the above structures
|
||||
*****/
|
||||
bool ok; /* is this RDATA valid? */
|
||||
} wire_ok_t;
|
||||
|
||||
#define COMPARE(r1, r2, answer) \
|
||||
{ r1, r2, answer, __LINE__ }
|
||||
|
|
@ -73,24 +92,20 @@ typedef struct wire_ok wire_ok_t;
|
|||
{ NULL, NULL, 0, __LINE__ }
|
||||
|
||||
#define TEXT_VALID_CHANGED(data_in, data_out) \
|
||||
{ data_in, data_out, __LINE__ }
|
||||
#define TEXT_VALID(data) { data, data, __LINE__ }
|
||||
#define TEXT_INVALID(data) { data, NULL, __LINE__ }
|
||||
{ data_in, data_out }
|
||||
#define TEXT_VALID(data) { data, data }
|
||||
#define TEXT_INVALID(data) { data, NULL }
|
||||
#define TEXT_SENTINEL() TEXT_INVALID(NULL)
|
||||
|
||||
#define VARGC(...) (sizeof((unsigned char[]){ __VA_ARGS__ }))
|
||||
#define WIRE_TEST(ok, ...) { \
|
||||
{ __VA_ARGS__ }, VARGC(__VA_ARGS__), \
|
||||
ok, __LINE__ \
|
||||
ok \
|
||||
}
|
||||
#define WIRE_VALID(...) WIRE_TEST(true, __VA_ARGS__)
|
||||
#define WIRE_INVALID(...) WIRE_TEST(false, __VA_ARGS__)
|
||||
#define WIRE_SENTINEL() WIRE_TEST(false)
|
||||
|
||||
/*****
|
||||
***** Checking functions used by test cases
|
||||
*****/
|
||||
|
||||
/*
|
||||
* Test whether converting rdata to a type-specific struct and then back to
|
||||
* rdata results in the same uncompressed wire form. This checks whether
|
||||
|
|
@ -101,52 +116,37 @@ typedef struct wire_ok wire_ok_t;
|
|||
* check_text_ok_single() and check_wire_ok_single().
|
||||
*/
|
||||
static void
|
||||
check_struct_conversions(dns_rdata_t *rdata, size_t structsize, int lineno) {
|
||||
check_struct_conversions(dns_rdata_t *rdata, size_t structsize) {
|
||||
dns_rdataclass_t rdclass = rdata->rdclass;
|
||||
dns_rdatatype_t type = rdata->type;
|
||||
isc_result_t result;
|
||||
isc_buffer_t target;
|
||||
void *rdata_struct;
|
||||
char buf[1024], hex[BUFSIZ];
|
||||
char buf[1024];
|
||||
|
||||
rdata_struct = isc_mem_allocate(mctx, structsize);
|
||||
ATF_REQUIRE(rdata_struct != NULL);
|
||||
assert_non_null(rdata_struct);
|
||||
|
||||
/*
|
||||
* Convert from uncompressed wire form into type-specific struct.
|
||||
*/
|
||||
result = dns_rdata_tostruct(rdata, rdata_struct, NULL);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"%s (%u): dns_rdata_tostruct() failed",
|
||||
dns_test_tohex(rdata->data, rdata->length,
|
||||
hex, sizeof(hex)),
|
||||
rdata->length);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Convert from type-specific struct into uncompressed wire form.
|
||||
*/
|
||||
isc_buffer_init(&target, buf, sizeof(buf));
|
||||
result = dns_rdata_fromstruct(NULL, rdclass, type, rdata_struct,
|
||||
&target);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"line %d: %s (%u): dns_rdata_fromstruct() failed",
|
||||
lineno, dns_test_tohex(rdata->data, rdata->length,
|
||||
hex, sizeof(hex)),
|
||||
rdata->length);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Ensure results are consistent.
|
||||
*/
|
||||
ATF_REQUIRE_EQ_MSG(isc_buffer_usedlength(&target), rdata->length,
|
||||
"line %d: %s (%u): wire form data length changed "
|
||||
"after converting to type-specific struct and back",
|
||||
lineno, dns_test_tohex(rdata->data, rdata->length,
|
||||
hex, sizeof(hex)),
|
||||
rdata->length);
|
||||
ATF_REQUIRE_EQ_MSG(memcmp(buf, rdata->data, rdata->length), 0,
|
||||
"line %d: %s (%u): wire form data different after "
|
||||
"converting to type-specific struct and back",
|
||||
lineno, dns_test_tohex(rdata->data, rdata->length,
|
||||
hex, sizeof(hex)),
|
||||
rdata->length);
|
||||
assert_int_equal(isc_buffer_usedlength(&target), rdata->length);
|
||||
|
||||
assert_memory_equal(buf, rdata->data, rdata->length);
|
||||
|
||||
isc_mem_free(mctx, rdata_struct);
|
||||
}
|
||||
|
|
@ -171,21 +171,16 @@ check_text_ok_single(const text_ok_t *text_ok, dns_rdataclass_t rdclass,
|
|||
*/
|
||||
result = dns_test_rdatafromstring(&rdata, rdclass, type, buf_fromtext,
|
||||
sizeof(buf_fromtext),
|
||||
text_ok->text_in);
|
||||
text_ok->text_in, false);
|
||||
/*
|
||||
* Check whether result is as expected.
|
||||
*/
|
||||
if (text_ok->text_out != NULL) {
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"line %d: '%s': "
|
||||
"expected success, got failure",
|
||||
text_ok->lineno, text_ok->text_in);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
} else {
|
||||
ATF_REQUIRE_MSG(result != ISC_R_SUCCESS,
|
||||
"line %d: '%s': "
|
||||
"expected failure, got success",
|
||||
text_ok->lineno, text_ok->text_in);
|
||||
assert_int_not_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* If text form RDATA was not parsed correctly, performing any
|
||||
* additional checks is pointless.
|
||||
|
|
@ -199,20 +194,14 @@ check_text_ok_single(const text_ok_t *text_ok, dns_rdataclass_t rdclass,
|
|||
*/
|
||||
isc_buffer_init(&target, buf_totext, sizeof(buf_totext));
|
||||
result = dns_rdata_totext(&rdata, NULL, &target);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"line %d: '%s': "
|
||||
"failed to convert rdata back to text form",
|
||||
text_ok->lineno, text_ok->text_in);
|
||||
ATF_REQUIRE_EQ_MSG(strcmp(buf_totext, text_ok->text_out), 0,
|
||||
"line %d: '%s': "
|
||||
"converts back to '%s', expected '%s'",
|
||||
text_ok->lineno, text_ok->text_in, buf_totext,
|
||||
text_ok->text_out);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf_totext, text_ok->text_out);
|
||||
|
||||
/*
|
||||
* Perform two-way conversion checks between uncompressed wire form and
|
||||
* type-specific struct.
|
||||
*/
|
||||
check_struct_conversions(&rdata, structsize, text_ok->lineno);
|
||||
check_struct_conversions(&rdata, structsize);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -228,7 +217,6 @@ check_wire_ok_single(const wire_ok_t *wire_ok, dns_rdataclass_t rdclass,
|
|||
dns_decompress_t dctx;
|
||||
isc_result_t result;
|
||||
dns_rdata_t rdata;
|
||||
char hex[BUFSIZ];
|
||||
|
||||
/*
|
||||
* Set up len-octet buffer pointing at data.
|
||||
|
|
@ -252,28 +240,16 @@ check_wire_ok_single(const wire_ok_t *wire_ok, dns_rdataclass_t rdclass,
|
|||
* Check whether result is as expected.
|
||||
*/
|
||||
if (wire_ok->ok) {
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"line %d: %s (%lu): "
|
||||
"expected success, got failure",
|
||||
wire_ok->lineno,
|
||||
dns_test_tohex(wire_ok->data, wire_ok->len,
|
||||
hex, sizeof(hex)),
|
||||
(unsigned long)wire_ok->len);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
} else {
|
||||
ATF_REQUIRE_MSG(result != ISC_R_SUCCESS,
|
||||
"line %d: %s (%lu): "
|
||||
"expected failure, got success",
|
||||
wire_ok->lineno,
|
||||
dns_test_tohex(wire_ok->data, wire_ok->len,
|
||||
hex, sizeof(hex)),
|
||||
(unsigned long)wire_ok->len);
|
||||
assert_int_not_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
/*
|
||||
* If data was parsed correctly, perform two-way conversion checks
|
||||
* between uncompressed wire form and type-specific struct.
|
||||
*/
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
check_struct_conversions(&rdata, structsize, wire_ok->lineno);
|
||||
check_struct_conversions(&rdata, structsize);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -339,44 +315,42 @@ check_compare_ok_single(const compare_ok_t *compare_ok,
|
|||
|
||||
result = dns_test_rdatafromstring(&rdata1, rdclass, type,
|
||||
buf1, sizeof(buf1),
|
||||
compare_ok->text1);
|
||||
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "line %d: '%s': "
|
||||
"expected success, got failure",
|
||||
compare_ok->lineno, compare_ok->text1);
|
||||
compare_ok->text1, false);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fail_msg("# line %d: '%s': expected success, got failure",
|
||||
compare_ok->lineno, compare_ok->text1);
|
||||
}
|
||||
|
||||
result = dns_test_rdatafromstring(&rdata2, rdclass, type,
|
||||
buf2, sizeof(buf2),
|
||||
compare_ok->text2);
|
||||
compare_ok->text2, false);
|
||||
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "line %d: '%s': "
|
||||
"expected success, got failure",
|
||||
compare_ok->lineno, compare_ok->text2);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fail_msg("# line %d: '%s': expected success, got failure",
|
||||
compare_ok->lineno, compare_ok->text2);
|
||||
}
|
||||
|
||||
answer = dns_rdata_compare(&rdata1, &rdata2);
|
||||
if (compare_ok->answer == 0) {
|
||||
ATF_REQUIRE_MSG(answer == 0,
|
||||
"line %d: dns_rdata_compare('%s', '%s'): "
|
||||
"expected equal, got %s",
|
||||
compare_ok->lineno,
|
||||
compare_ok->text1, compare_ok->text2,
|
||||
(answer > 0) ? "greater than" : "less than");
|
||||
if (compare_ok->answer == 0 && answer != 0) {
|
||||
fail_msg("# line %d: dns_rdata_compare('%s', '%s'): "
|
||||
"expected equal, got %s",
|
||||
compare_ok->lineno,
|
||||
compare_ok->text1, compare_ok->text2,
|
||||
(answer > 0) ? "greater than" : "less than");
|
||||
}
|
||||
if (compare_ok->answer < 0) {
|
||||
ATF_REQUIRE_MSG(answer < 0,
|
||||
"line %d: dns_rdata_compare('%s', '%s'): "
|
||||
"expected less than, got %s",
|
||||
compare_ok->lineno,
|
||||
compare_ok->text1, compare_ok->text2,
|
||||
(answer == 0) ? "equal" : "greater than");
|
||||
if (compare_ok->answer < 0 && answer >= 0) {
|
||||
fail_msg("# line %d: dns_rdata_compare('%s', '%s'): "
|
||||
"expected less than, got %s",
|
||||
compare_ok->lineno,
|
||||
compare_ok->text1, compare_ok->text2,
|
||||
(answer == 0) ? "equal" : "greater than");
|
||||
}
|
||||
if (compare_ok->answer > 0) {
|
||||
ATF_REQUIRE_MSG(answer > 0,
|
||||
"line %d: dns_rdata_compare('%s', '%s'): "
|
||||
"expected greater than, got %s",
|
||||
compare_ok->lineno,
|
||||
compare_ok->text1, compare_ok->text2,
|
||||
(answer == 0) ? "equal" : "less than");
|
||||
if (compare_ok->answer > 0 && answer <= 0) {
|
||||
fail_msg("line %d: dns_rdata_compare('%s', '%s'): "
|
||||
"expected greater than, got %s",
|
||||
compare_ok->lineno,
|
||||
compare_ok->text1, compare_ok->text2,
|
||||
(answer == 0) ? "equal" : "less than");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -399,9 +373,7 @@ check_compare_ok(const compare_ok_t *compare_ok,
|
|||
|
||||
/*
|
||||
* Test whether supplied sets of text form and/or wire form RDATA are handled
|
||||
* as expected. This is just a helper function which should be the only
|
||||
* function called for a test case using it, due to the use of dns_test_begin()
|
||||
* and dns_test_end().
|
||||
* as expected.
|
||||
*
|
||||
* The empty_ok argument denotes whether an attempt to parse a zero-length wire
|
||||
* data buffer should succeed or not (it is valid for some RR types). There is
|
||||
|
|
@ -415,11 +387,6 @@ check_rdata(const text_ok_t *text_ok, const wire_ok_t *wire_ok,
|
|||
bool empty_ok, dns_rdataclass_t rdclass,
|
||||
dns_rdatatype_t type, size_t structsize)
|
||||
{
|
||||
isc_result_t result;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
if (text_ok != NULL) {
|
||||
check_text_ok(text_ok, rdclass, type, structsize);
|
||||
}
|
||||
|
|
@ -429,19 +396,11 @@ check_rdata(const text_ok_t *text_ok, const wire_ok_t *wire_ok,
|
|||
if (compare_ok != NULL) {
|
||||
check_compare_ok(compare_ok, rdclass, type);
|
||||
}
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*****
|
||||
***** Individual unit tests
|
||||
*****/
|
||||
|
||||
ATF_TC(apl);
|
||||
ATF_TC_HEAD(apl, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "APL RDATA manipulations");
|
||||
}
|
||||
ATF_TC_BODY(apl, tc) {
|
||||
/* APL RDATA manipulations */
|
||||
static void
|
||||
apl(void **state) {
|
||||
text_ok_t text_ok[] = {
|
||||
/* empty list */
|
||||
TEXT_VALID(""),
|
||||
|
|
@ -489,17 +448,51 @@ ATF_TC_BODY(apl, tc) {
|
|||
WIRE_SENTINEL()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(text_ok, wire_ok, NULL, true, dns_rdataclass_in,
|
||||
dns_rdatatype_apl, sizeof(dns_rdata_in_apl_t));
|
||||
}
|
||||
|
||||
ATF_TC(atma);
|
||||
ATF_TC_HEAD(atma, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "ATMA RDATA manipulations");
|
||||
}
|
||||
ATF_TC_BODY(atma, tc) {
|
||||
/*
|
||||
* http://broadband-forum.org/ftp/pub/approved-specs/af-saa-0069.000.pdf
|
||||
*
|
||||
* ATMA RR’s have the following RDATA format:
|
||||
*
|
||||
* 1 1 1 1 1 1
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | FORMAT | |
|
||||
* +--+--+--+--+--+--+--+--+ |
|
||||
* / ADDRESS /
|
||||
* | |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*
|
||||
* The fields have the following meaning:
|
||||
*
|
||||
* * FORMAT: One octet that indicates the format of ADDRESS. The two
|
||||
* possible values for FORMAT are value 0 indicating ATM End System Address
|
||||
* (AESA) format and value 1 indicating E.164 format.
|
||||
*
|
||||
* * ADDRESS: Variable length string of octets containing the ATM address of
|
||||
* the node to which this RR pertains.
|
||||
*
|
||||
* When the format value is 0, indicating that the address is in AESA format,
|
||||
* the address is coded as described in ISO 8348/AD 2 using the preferred
|
||||
* binary encoding of the ISO NSAP format. When the format value is 1,
|
||||
* indicating that the address is in E.164 format, the Address/Number Digits
|
||||
* appear in the order in which they would be entered on a numeric keypad.
|
||||
* Digits are coded in IA5 characters with the leftmost bit of each digit set
|
||||
* to 0. This ATM address appears in ATM End System Address Octets field (AESA
|
||||
* format) or the Address/Number Digits field (E.164 format) of the Called
|
||||
* party number information element [ATMUNI3.1]. Subaddress information is
|
||||
* intentionally not included because E.164 subaddress information is used for
|
||||
* routing.
|
||||
*
|
||||
* ATMA RRs cause no additional section processing.
|
||||
*/
|
||||
static void
|
||||
atma(void **state) {
|
||||
text_ok_t text_ok[] = {
|
||||
TEXT_VALID("00"),
|
||||
TEXT_VALID_CHANGED("0.0", "00"),
|
||||
|
|
@ -564,7 +557,7 @@ ATF_TC_BODY(atma, tc) {
|
|||
WIRE_SENTINEL()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
|
||||
dns_rdatatype_atma, sizeof(dns_rdata_in_atma_t));
|
||||
|
|
@ -634,11 +627,8 @@ ATF_TC_BODY(atma, tc) {
|
|||
* must understand the semantics associated with a bit in the Type Bit
|
||||
* Map field that has been set to 1.
|
||||
*/
|
||||
ATF_TC(csync);
|
||||
ATF_TC_HEAD(csync, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "CSYNC RDATA manipulations");
|
||||
}
|
||||
ATF_TC_BODY(csync, tc) {
|
||||
static void
|
||||
csync(void **state) {
|
||||
text_ok_t text_ok[] = {
|
||||
TEXT_INVALID(""),
|
||||
TEXT_INVALID("0"),
|
||||
|
|
@ -695,7 +685,7 @@ ATF_TC_BODY(csync, tc) {
|
|||
WIRE_SENTINEL()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
|
||||
dns_rdatatype_csync, sizeof(dns_rdata_csync_t));
|
||||
|
|
@ -761,11 +751,8 @@ ATF_TC_BODY(csync, tc) {
|
|||
* character ("-", ASCII 45). White space is permitted within Base64
|
||||
* data.
|
||||
*/
|
||||
ATF_TC(doa);
|
||||
ATF_TC_HEAD(doa, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "DOA RDATA manipulations");
|
||||
}
|
||||
ATF_TC_BODY(doa, tc) {
|
||||
static void
|
||||
doa(void **state) {
|
||||
text_ok_t text_ok[] = {
|
||||
/*
|
||||
* Valid, non-empty DOA-DATA.
|
||||
|
|
@ -913,7 +900,7 @@ ATF_TC_BODY(doa, tc) {
|
|||
WIRE_SENTINEL()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
|
||||
dns_rdatatype_doa, sizeof(dns_rdata_doa_t));
|
||||
|
|
@ -979,12 +966,8 @@ ATF_TC_BODY(doa, tc) {
|
|||
* All fields are in network byte order ("big-endian", per [RFC1700],
|
||||
* Data Notation).
|
||||
*/
|
||||
ATF_TC(edns_client_subnet);
|
||||
ATF_TC_HEAD(edns_client_subnet, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"OPT RDATA with EDNS Client Subnet manipulations");
|
||||
}
|
||||
ATF_TC_BODY(edns_client_subnet, tc) {
|
||||
static void
|
||||
edns_client_subnet(void **state) {
|
||||
wire_ok_t wire_ok[] = {
|
||||
/*
|
||||
* Option code with no content.
|
||||
|
|
@ -1079,7 +1062,7 @@ ATF_TC_BODY(edns_client_subnet, tc) {
|
|||
WIRE_SENTINEL()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(NULL, wire_ok, NULL, true, dns_rdataclass_in,
|
||||
dns_rdatatype_opt, sizeof(dns_rdata_opt_t));
|
||||
|
|
@ -1094,11 +1077,8 @@ ATF_TC_BODY(edns_client_subnet, tc) {
|
|||
* significant. For readability, whitespace may be included in the value
|
||||
* field and should be ignored when reading a master file.
|
||||
*/
|
||||
ATF_TC(eid);
|
||||
ATF_TC_HEAD(eid, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "EID RDATA manipulations");
|
||||
}
|
||||
ATF_TC_BODY(eid, tc) {
|
||||
static void
|
||||
eid(void **state) {
|
||||
text_ok_t text_ok[] = {
|
||||
TEXT_VALID("AABBCC"),
|
||||
TEXT_VALID_CHANGED("AA bb cc", "AABBCC"),
|
||||
|
|
@ -1120,21 +1100,17 @@ ATF_TC_BODY(eid, tc) {
|
|||
WIRE_SENTINEL()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
|
||||
dns_rdatatype_eid, sizeof(dns_rdata_in_eid_t));
|
||||
}
|
||||
|
||||
/*
|
||||
* Successful load test.
|
||||
* test that an oversized HIP record will be rejected
|
||||
*/
|
||||
ATF_TC(hip);
|
||||
ATF_TC_HEAD(hip, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "that a oversized HIP record will "
|
||||
"be rejected");
|
||||
}
|
||||
ATF_TC_BODY(hip, tc) {
|
||||
static void
|
||||
hip(void **state) {
|
||||
unsigned char hipwire[DNS_RDATA_MAXLENGTH] = {
|
||||
0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
|
||||
0x04, 0x41, 0x42, 0x43, 0x44, 0x00 };
|
||||
|
|
@ -1145,10 +1121,7 @@ ATF_TC_BODY(hip, tc) {
|
|||
isc_result_t result;
|
||||
size_t i;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* Fill the rest of input buffer with compression pointers.
|
||||
|
|
@ -1168,9 +1141,7 @@ ATF_TC_BODY(hip, tc) {
|
|||
dns_rdatatype_hip, &source, &dctx,
|
||||
0, &target);
|
||||
dns_decompress_invalidate(&dctx);
|
||||
ATF_REQUIRE_EQ(result, DNS_R_FORMERR);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(result, DNS_R_FORMERR);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -1234,11 +1205,8 @@ ATF_TC_BODY(hip, tc) {
|
|||
* as one or two <character-string>s, i.e., count followed by
|
||||
* characters.
|
||||
*/
|
||||
ATF_TC(isdn);
|
||||
ATF_TC_HEAD(isdn, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "ISDN RDATA manipulations");
|
||||
}
|
||||
ATF_TC_BODY(isdn, tc) {
|
||||
static void
|
||||
isdn(void **state) {
|
||||
wire_ok_t wire_ok[] = {
|
||||
/*
|
||||
* "".
|
||||
|
|
@ -1262,7 +1230,7 @@ ATF_TC_BODY(isdn, tc) {
|
|||
WIRE_SENTINEL()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in,
|
||||
dns_rdatatype_isdn, sizeof(dns_rdata_isdn_t));
|
||||
|
|
@ -1277,11 +1245,8 @@ ATF_TC_BODY(isdn, tc) {
|
|||
* significant. For readability, whitespace may be included in the value
|
||||
* field and should be ignored when reading a master file.
|
||||
*/
|
||||
ATF_TC(nimloc);
|
||||
ATF_TC_HEAD(nimloc, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "NIMLOC RDATA manipulations");
|
||||
}
|
||||
ATF_TC_BODY(nimloc, tc) {
|
||||
static void
|
||||
nimloc(void **state) {
|
||||
text_ok_t text_ok[] = {
|
||||
TEXT_VALID("AABBCC"),
|
||||
TEXT_VALID_CHANGED("AA bb cc", "AABBCC"),
|
||||
|
|
@ -1303,7 +1268,7 @@ ATF_TC_BODY(nimloc, tc) {
|
|||
WIRE_SENTINEL()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
|
||||
dns_rdatatype_nimloc, sizeof(dns_rdata_in_nimloc_t));
|
||||
|
|
@ -1375,11 +1340,8 @@ ATF_TC_BODY(nimloc, tc) {
|
|||
* Bits representing pseudo-types MUST be clear, as they do not appear
|
||||
* in zone data. If encountered, they MUST be ignored upon being read.
|
||||
*/
|
||||
ATF_TC(nsec);
|
||||
ATF_TC_HEAD(nsec, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "NSEC RDATA manipulations");
|
||||
}
|
||||
ATF_TC_BODY(nsec, tc) {
|
||||
static void
|
||||
nsec(void **state) {
|
||||
text_ok_t text_ok[] = {
|
||||
TEXT_INVALID(""),
|
||||
TEXT_INVALID("."),
|
||||
|
|
@ -1394,7 +1356,7 @@ ATF_TC_BODY(nsec, tc) {
|
|||
WIRE_INVALID()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
|
||||
dns_rdatatype_nsec, sizeof(dns_rdata_nsec_t));
|
||||
|
|
@ -1405,11 +1367,8 @@ ATF_TC_BODY(nsec, tc) {
|
|||
*
|
||||
* RFC 5155.
|
||||
*/
|
||||
ATF_TC(nsec3);
|
||||
ATF_TC_HEAD(nsec3, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "NSEC3 RDATA manipulations");
|
||||
}
|
||||
ATF_TC_BODY(nsec3, tc) {
|
||||
static void
|
||||
nsec3(void **state) {
|
||||
text_ok_t text_ok[] = {
|
||||
TEXT_INVALID(""),
|
||||
TEXT_INVALID("."),
|
||||
|
|
@ -1423,20 +1382,15 @@ ATF_TC_BODY(nsec3, tc) {
|
|||
TEXT_SENTINEL()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(text_ok, NULL, NULL, false, dns_rdataclass_in,
|
||||
dns_rdatatype_nsec3, sizeof(dns_rdata_nsec3_t));
|
||||
}
|
||||
|
||||
/*
|
||||
* NXT Tests.
|
||||
*/
|
||||
ATF_TC(nxt);
|
||||
ATF_TC_HEAD(nxt, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "NXT RDATA manipulations");
|
||||
}
|
||||
ATF_TC_BODY(nxt, tc) {
|
||||
/* NXT RDATA manipulations */
|
||||
static void
|
||||
nxt(void **state) {
|
||||
compare_ok_t compare_ok[] = {
|
||||
COMPARE("a. A SIG", "a. A SIG", 0),
|
||||
/*
|
||||
|
|
@ -1456,7 +1410,7 @@ ATF_TC_BODY(nxt, tc) {
|
|||
COMPARE_SENTINEL()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(NULL, NULL, compare_ok, false, dns_rdataclass_in,
|
||||
dns_rdatatype_nxt, sizeof(dns_rdata_nxt_t));
|
||||
|
|
@ -1501,11 +1455,8 @@ ATF_TC_BODY(nxt, tc) {
|
|||
* port 25; if zero, SMTP service is not supported on the specified
|
||||
* address.
|
||||
*/
|
||||
ATF_TC(wks);
|
||||
ATF_TC_HEAD(wks, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "WKS RDATA manipulations");
|
||||
}
|
||||
ATF_TC_BODY(wks, tc) {
|
||||
static void
|
||||
wks(void **state) {
|
||||
wire_ok_t wire_ok[] = {
|
||||
/*
|
||||
* Too short.
|
||||
|
|
@ -1529,30 +1480,42 @@ ATF_TC_BODY(wks, tc) {
|
|||
WIRE_SENTINEL()
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in,
|
||||
dns_rdatatype_wks, sizeof(dns_rdata_in_wks_t));
|
||||
}
|
||||
|
||||
/*****
|
||||
***** Main
|
||||
*****/
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(apl, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(atma, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(csync, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(doa, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(eid, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(edns_client_subnet,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(hip, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(isdn, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(nimloc, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(nsec, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(nsec3, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(nxt, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(wks, _setup, _teardown),
|
||||
};
|
||||
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, apl);
|
||||
ATF_TP_ADD_TC(tp, atma);
|
||||
ATF_TP_ADD_TC(tp, csync);
|
||||
ATF_TP_ADD_TC(tp, doa);
|
||||
ATF_TP_ADD_TC(tp, eid);
|
||||
ATF_TP_ADD_TC(tp, edns_client_subnet);
|
||||
ATF_TP_ADD_TC(tp, hip);
|
||||
ATF_TP_ADD_TC(tp, isdn);
|
||||
ATF_TP_ADD_TC(tp, nimloc);
|
||||
ATF_TP_ADD_TC(tp, nsec);
|
||||
ATF_TP_ADD_TC(tp, nsec3);
|
||||
ATF_TP_ADD_TC(tp, nxt);
|
||||
ATF_TP_ADD_TC(tp, wks);
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,33 +9,53 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/rdataset.h>
|
||||
#include <dns/rdatastruct.h>
|
||||
|
||||
#include "dnstest.h"
|
||||
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
/* Successful load test */
|
||||
ATF_TC(trimttl);
|
||||
ATF_TC_HEAD(trimttl, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_master_loadfile() loads a "
|
||||
"valid master file and returns success");
|
||||
}
|
||||
ATF_TC_BODY(trimttl, tc) {
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* test trimming of rdataset TTLs */
|
||||
static void
|
||||
trimttl(void **state) {
|
||||
dns_rdataset_t rdataset, sigrdataset;
|
||||
dns_rdata_rrsig_t rrsig;
|
||||
isc_stdtime_t ttltimenow, ttltimeexpire;
|
||||
|
|
@ -43,14 +63,11 @@ ATF_TC_BODY(trimttl, tc) {
|
|||
ttltimenow = 10000000;
|
||||
ttltimeexpire = ttltimenow + 800;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
dns_rdataset_init(&rdataset);
|
||||
dns_rdataset_init(&sigrdataset);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
rdataset.ttl = 900;
|
||||
sigrdataset.ttl = 1000;
|
||||
rrsig.timeexpire = ttltimeexpire;
|
||||
|
|
@ -58,8 +75,8 @@ ATF_TC_BODY(trimttl, tc) {
|
|||
|
||||
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
|
||||
true);
|
||||
ATF_REQUIRE_EQ(rdataset.ttl, 800);
|
||||
ATF_REQUIRE_EQ(sigrdataset.ttl, 800);
|
||||
assert_int_equal(rdataset.ttl, 800);
|
||||
assert_int_equal(sigrdataset.ttl, 800);
|
||||
|
||||
rdataset.ttl = 900;
|
||||
sigrdataset.ttl = 1000;
|
||||
|
|
@ -68,8 +85,8 @@ ATF_TC_BODY(trimttl, tc) {
|
|||
|
||||
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
|
||||
true);
|
||||
ATF_REQUIRE_EQ(rdataset.ttl, 120);
|
||||
ATF_REQUIRE_EQ(sigrdataset.ttl, 120);
|
||||
assert_int_equal(rdataset.ttl, 120);
|
||||
assert_int_equal(sigrdataset.ttl, 120);
|
||||
|
||||
rdataset.ttl = 900;
|
||||
sigrdataset.ttl = 1000;
|
||||
|
|
@ -78,8 +95,8 @@ ATF_TC_BODY(trimttl, tc) {
|
|||
|
||||
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
|
||||
false);
|
||||
ATF_REQUIRE_EQ(rdataset.ttl, 0);
|
||||
ATF_REQUIRE_EQ(sigrdataset.ttl, 0);
|
||||
assert_int_equal(rdataset.ttl, 0);
|
||||
assert_int_equal(sigrdataset.ttl, 0);
|
||||
|
||||
sigrdataset.ttl = 900;
|
||||
rdataset.ttl = 1000;
|
||||
|
|
@ -88,8 +105,8 @@ ATF_TC_BODY(trimttl, tc) {
|
|||
|
||||
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
|
||||
true);
|
||||
ATF_REQUIRE_EQ(rdataset.ttl, 800);
|
||||
ATF_REQUIRE_EQ(sigrdataset.ttl, 800);
|
||||
assert_int_equal(rdataset.ttl, 800);
|
||||
assert_int_equal(sigrdataset.ttl, 800);
|
||||
|
||||
sigrdataset.ttl = 900;
|
||||
rdataset.ttl = 1000;
|
||||
|
|
@ -98,8 +115,8 @@ ATF_TC_BODY(trimttl, tc) {
|
|||
|
||||
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
|
||||
true);
|
||||
ATF_REQUIRE_EQ(rdataset.ttl, 120);
|
||||
ATF_REQUIRE_EQ(sigrdataset.ttl, 120);
|
||||
assert_int_equal(rdataset.ttl, 120);
|
||||
assert_int_equal(sigrdataset.ttl, 120);
|
||||
|
||||
sigrdataset.ttl = 900;
|
||||
rdataset.ttl = 1000;
|
||||
|
|
@ -108,18 +125,27 @@ ATF_TC_BODY(trimttl, tc) {
|
|||
|
||||
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
|
||||
false);
|
||||
ATF_REQUIRE_EQ(rdataset.ttl, 0);
|
||||
ATF_REQUIRE_EQ(sigrdataset.ttl, 0);
|
||||
|
||||
dns_test_end();
|
||||
assert_int_equal(rdataset.ttl, 0);
|
||||
assert_int_equal(sigrdataset.ttl, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, trimttl);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(trimttl, _setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,40 +9,67 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/stats.h>
|
||||
|
||||
#include "dnstest.h"
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
set_typestats(dns_stats_t *stats, dns_rdatatype_t type,
|
||||
bool stale)
|
||||
{
|
||||
set_typestats(dns_stats_t *stats, dns_rdatatype_t type, bool stale) {
|
||||
dns_rdatastatstype_t which;
|
||||
unsigned int attributes;
|
||||
|
||||
attributes = 0;
|
||||
if (stale) attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
if (stale) {
|
||||
attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
}
|
||||
which = DNS_RDATASTATSTYPE_VALUE(type, attributes);
|
||||
dns_rdatasetstats_increment(stats, which);
|
||||
|
||||
attributes = DNS_RDATASTATSTYPE_ATTR_NXRRSET;
|
||||
if (stale) attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
if (stale) {
|
||||
attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
}
|
||||
which = DNS_RDATASTATSTYPE_VALUE(type, attributes);
|
||||
dns_rdatasetstats_increment(stats, which);
|
||||
}
|
||||
|
|
@ -53,7 +80,9 @@ set_nxdomainstats(dns_stats_t *stats, bool stale) {
|
|||
unsigned int attributes;
|
||||
|
||||
attributes = DNS_RDATASTATSTYPE_ATTR_NXDOMAIN;
|
||||
if (stale) attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
if (stale) {
|
||||
attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
}
|
||||
which = DNS_RDATASTATSTYPE_VALUE(0, attributes);
|
||||
dns_rdatasetstats_increment(stats, which);
|
||||
}
|
||||
|
|
@ -80,10 +109,11 @@ checkit1(dns_rdatastatstype_t which, uint64_t value, void *arg) {
|
|||
ATTRIBUTE_SET(DNS_RDATASTATSTYPE_ATTR_NXDOMAIN) ? "X" : " ",
|
||||
type, (unsigned)value);
|
||||
#endif
|
||||
if ((attributes & DNS_RDATASTATSTYPE_ATTR_STALE) == 0)
|
||||
ATF_REQUIRE_EQ(value, 1);
|
||||
else
|
||||
ATF_REQUIRE_EQ(value, 0);
|
||||
if ((attributes & DNS_RDATASTATSTYPE_ATTR_STALE) == 0) {
|
||||
assert_int_equal(value, 1);
|
||||
} else {
|
||||
assert_int_equal(value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -107,31 +137,27 @@ checkit2(dns_rdatastatstype_t which, uint64_t value, void *arg) {
|
|||
ATTRIBUTE_SET(DNS_RDATASTATSTYPE_ATTR_NXDOMAIN) ? "X" : " ",
|
||||
type, (unsigned)value);
|
||||
#endif
|
||||
if ((attributes & DNS_RDATASTATSTYPE_ATTR_STALE) == 0)
|
||||
ATF_REQUIRE_EQ(value, 0);
|
||||
else
|
||||
ATF_REQUIRE_EQ(value, 1);
|
||||
if ((attributes & DNS_RDATASTATSTYPE_ATTR_STALE) == 0) {
|
||||
assert_int_equal(value, 0);
|
||||
} else {
|
||||
assert_int_equal(value, 1);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
ATF_TC(rdatasetstats);
|
||||
ATF_TC_HEAD(rdatasetstats, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test that rdatasetstats counters are properly set");
|
||||
}
|
||||
ATF_TC_BODY(rdatasetstats, tc) {
|
||||
/* test that rdatasetstats counters are properly set */
|
||||
static void
|
||||
rdatasetstats(void **state) {
|
||||
unsigned int i;
|
||||
dns_stats_t *stats = NULL;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_rdatasetstats_create(mctx, &stats);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* First 256 types. */
|
||||
for (i = 0; i <= 255; i++)
|
||||
|
|
@ -160,13 +186,26 @@ ATF_TC_BODY(rdatasetstats, tc) {
|
|||
dns_rdatasetstats_dump(stats, checkit2, NULL, 1);
|
||||
|
||||
dns_stats_detach(&stats);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, rdatasetstats);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(rdatasetstats,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,16 +9,25 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/socket.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/timer.h>
|
||||
|
|
@ -34,34 +43,41 @@ static dns_dispatchmgr_t *dispatchmgr = NULL;
|
|||
static dns_dispatch_t *dispatch = NULL;
|
||||
static dns_view_t *view = NULL;
|
||||
|
||||
|
||||
static void
|
||||
setup(void) {
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
isc_sockaddr_t local;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_dispatchmgr_create(mctx, NULL, &dispatchmgr);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_makeview("view", &view);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_sockaddr_any(&local);
|
||||
result = dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr, &local,
|
||||
4096, 100, 100, 100, 500, 0, 0,
|
||||
&dispatch);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
teardown(void) {
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_dispatch_detach(&dispatch);
|
||||
dns_view_detach(&view);
|
||||
dns_dispatchmgr_destroy(&dispatchmgr);
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -70,9 +86,9 @@ mkres(dns_resolver_t **resolverp) {
|
|||
isc_result_t result;
|
||||
|
||||
result = dns_resolver_create(view, taskmgr, 1, 1,
|
||||
socketmgr, timermgr, 0,
|
||||
dispatchmgr, dispatch, NULL, resolverp);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
socketmgr, timermgr, 0,
|
||||
dispatchmgr, dispatch, NULL, resolverp);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -81,75 +97,60 @@ destroy_resolver(dns_resolver_t **resolverp) {
|
|||
dns_resolver_detach(resolverp);
|
||||
}
|
||||
|
||||
ATF_TC(create);
|
||||
ATF_TC_HEAD(create, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_resolver_create");
|
||||
}
|
||||
ATF_TC_BODY(create, tc) {
|
||||
/* dns_resolver_create */
|
||||
static void
|
||||
create_test(void **state) {
|
||||
dns_resolver_t *resolver = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
setup();
|
||||
mkres(&resolver);
|
||||
destroy_resolver(&resolver);
|
||||
teardown();
|
||||
}
|
||||
|
||||
ATF_TC(gettimeout);
|
||||
ATF_TC_HEAD(gettimeout, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_resolver_gettimeout");
|
||||
}
|
||||
ATF_TC_BODY(gettimeout, tc) {
|
||||
/* dns_resolver_gettimeout */
|
||||
static void
|
||||
gettimeout_test(void **state) {
|
||||
dns_resolver_t *resolver = NULL;
|
||||
unsigned int timeout;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
setup();
|
||||
mkres(&resolver);
|
||||
|
||||
timeout = dns_resolver_gettimeout(resolver);
|
||||
ATF_CHECK(timeout > 0);
|
||||
assert_true(timeout > 0);
|
||||
|
||||
destroy_resolver(&resolver);
|
||||
teardown();
|
||||
}
|
||||
|
||||
ATF_TC(settimeout);
|
||||
ATF_TC_HEAD(settimeout, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_resolver_settimeout");
|
||||
}
|
||||
ATF_TC_BODY(settimeout, tc) {
|
||||
/* dns_resolver_settimeout */
|
||||
static void
|
||||
settimeout_test(void **state) {
|
||||
dns_resolver_t *resolver = NULL;
|
||||
unsigned int default_timeout, timeout;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
setup();
|
||||
|
||||
mkres(&resolver);
|
||||
|
||||
default_timeout = dns_resolver_gettimeout(resolver);
|
||||
dns_resolver_settimeout(resolver, default_timeout + 1);
|
||||
timeout = dns_resolver_gettimeout(resolver);
|
||||
ATF_CHECK(timeout == default_timeout + 1);
|
||||
assert_true(timeout == default_timeout + 1);
|
||||
|
||||
destroy_resolver(&resolver);
|
||||
teardown();
|
||||
}
|
||||
|
||||
ATF_TC(settimeout_default);
|
||||
ATF_TC_HEAD(settimeout_default, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_resolver_settimeout to default");
|
||||
}
|
||||
ATF_TC_BODY(settimeout_default, tc) {
|
||||
/* dns_resolver_settimeout */
|
||||
static void
|
||||
settimeout_default_test(void **state) {
|
||||
dns_resolver_t *resolver = NULL;
|
||||
unsigned int default_timeout, timeout;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
setup();
|
||||
|
||||
mkres(&resolver);
|
||||
|
||||
|
|
@ -157,28 +158,23 @@ ATF_TC_BODY(settimeout_default, tc) {
|
|||
dns_resolver_settimeout(resolver, default_timeout + 10);
|
||||
|
||||
timeout = dns_resolver_gettimeout(resolver);
|
||||
ATF_CHECK_EQ(timeout, default_timeout + 10);
|
||||
assert_int_equal(timeout, default_timeout + 10);
|
||||
|
||||
dns_resolver_settimeout(resolver, 0);
|
||||
timeout = dns_resolver_gettimeout(resolver);
|
||||
ATF_CHECK_EQ(timeout, default_timeout);
|
||||
assert_int_equal(timeout, default_timeout);
|
||||
|
||||
destroy_resolver(&resolver);
|
||||
teardown();
|
||||
}
|
||||
|
||||
ATF_TC(settimeout_belowmin);
|
||||
ATF_TC_HEAD(settimeout_belowmin, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"dns_resolver_settimeout below minimum");
|
||||
}
|
||||
ATF_TC_BODY(settimeout_belowmin, tc) {
|
||||
/* dns_resolver_settimeout below minimum */
|
||||
static void
|
||||
settimeout_belowmin_test(void **state) {
|
||||
dns_resolver_t *resolver = NULL;
|
||||
unsigned int default_timeout, timeout;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
setup();
|
||||
|
||||
mkres(&resolver);
|
||||
|
||||
|
|
@ -186,43 +182,56 @@ ATF_TC_BODY(settimeout_belowmin, tc) {
|
|||
dns_resolver_settimeout(resolver, 9);
|
||||
|
||||
timeout = dns_resolver_gettimeout(resolver);
|
||||
ATF_CHECK_EQ(timeout, default_timeout);
|
||||
assert_int_equal(timeout, default_timeout);
|
||||
|
||||
destroy_resolver(&resolver);
|
||||
teardown();
|
||||
}
|
||||
|
||||
ATF_TC(settimeout_overmax);
|
||||
ATF_TC_HEAD(settimeout_overmax, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns_resolver_settimeout over maximum");
|
||||
}
|
||||
ATF_TC_BODY(settimeout_overmax, tc) {
|
||||
/* dns_resolver_settimeout over maximum */
|
||||
static void
|
||||
settimeout_overmax_test(void **state) {
|
||||
dns_resolver_t *resolver = NULL;
|
||||
unsigned int timeout;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
setup();
|
||||
|
||||
mkres(&resolver);
|
||||
|
||||
dns_resolver_settimeout(resolver, 4000000);
|
||||
timeout = dns_resolver_gettimeout(resolver);
|
||||
ATF_CHECK(timeout < 4000000 && timeout > 0);
|
||||
|
||||
assert_in_range(timeout, 0, 3999999);
|
||||
destroy_resolver(&resolver);
|
||||
teardown();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, create);
|
||||
ATF_TP_ADD_TC(tp, gettimeout);
|
||||
ATF_TP_ADD_TC(tp, settimeout);
|
||||
ATF_TP_ADD_TC(tp, settimeout_default);
|
||||
ATF_TP_ADD_TC(tp, settimeout_belowmin);
|
||||
ATF_TP_ADD_TC(tp, settimeout_overmax);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(create_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(gettimeout_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(settimeout_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(settimeout_default_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(settimeout_belowmin_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(settimeout_overmax_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,14 +10,21 @@
|
|||
*/
|
||||
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/util.h>
|
||||
#include <isc/print.h>
|
||||
|
|
@ -29,6 +36,26 @@
|
|||
#include "../dst_internal.h"
|
||||
|
||||
#if defined(OPENSSL) || defined(PKCS11CRYPTO)
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static unsigned char d[10] = {
|
||||
0xa, 0x10, 0xbb, 0, 0xfe, 0x15, 0x1, 0x88, 0xcc, 0x7d
|
||||
|
|
@ -176,11 +203,9 @@ static unsigned char sigsha512[512] = {
|
|||
0xff, 0x6a, 0x63, 0x8b, 0xe1, 0x2e, 0xa3, 0xa7
|
||||
};
|
||||
|
||||
ATF_TC(isc_rsa_verify);
|
||||
ATF_TC_HEAD(isc_rsa_verify, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "RSA verify");
|
||||
}
|
||||
ATF_TC_BODY(isc_rsa_verify, tc) {
|
||||
/* RSA verify */
|
||||
static void
|
||||
isc_rsa_verify_test(void **state) {
|
||||
isc_result_t ret;
|
||||
dns_fixedname_t fname;
|
||||
isc_buffer_t buf;
|
||||
|
|
@ -189,36 +214,33 @@ ATF_TC_BODY(isc_rsa_verify, tc) {
|
|||
dst_context_t *ctx = NULL;
|
||||
isc_region_t r;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
ret = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
name = dns_fixedname_initname(&fname);
|
||||
isc_buffer_constinit(&buf, "rsa.", 4);
|
||||
isc_buffer_add(&buf, 4);
|
||||
ret = dns_name_fromtext(name, &buf, NULL, 0, NULL);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
ret = dst_key_fromfile(name, 29235, DST_ALG_RSASHA1,
|
||||
DST_TYPE_PUBLIC, "./", mctx, &key);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
/* RSASHA1 */
|
||||
|
||||
ret = dst_context_create3(key, mctx, DNS_LOGCATEGORY_DNSSEC,
|
||||
false, &ctx);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
r.base = d;
|
||||
r.length = 10;
|
||||
ret = dst_context_adddata(ctx, &r);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
r.base = sigsha1;
|
||||
r.length = 256;
|
||||
ret = dst_context_verify(ctx, &r);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
dst_context_destroy(&ctx);
|
||||
|
||||
|
|
@ -229,17 +251,17 @@ ATF_TC_BODY(isc_rsa_verify, tc) {
|
|||
|
||||
ret = dst_context_create3(key, mctx, DNS_LOGCATEGORY_DNSSEC,
|
||||
false, &ctx);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
r.base = d;
|
||||
r.length = 10;
|
||||
ret = dst_context_adddata(ctx, &r);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
r.base = sigmd5;
|
||||
r.length = 256;
|
||||
ret = dst_context_verify(ctx, &r);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
dst_context_destroy(&ctx);
|
||||
#endif
|
||||
|
|
@ -250,17 +272,17 @@ ATF_TC_BODY(isc_rsa_verify, tc) {
|
|||
|
||||
ret = dst_context_create3(key, mctx, DNS_LOGCATEGORY_DNSSEC,
|
||||
false, &ctx);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
r.base = d;
|
||||
r.length = 10;
|
||||
ret = dst_context_adddata(ctx, &r);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
r.base = sigsha256;
|
||||
r.length = 256;
|
||||
ret = dst_context_verify(ctx, &r);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
dst_context_destroy(&ctx);
|
||||
|
||||
|
|
@ -270,43 +292,47 @@ ATF_TC_BODY(isc_rsa_verify, tc) {
|
|||
|
||||
ret = dst_context_create3(key, mctx, DNS_LOGCATEGORY_DNSSEC,
|
||||
false, &ctx);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
r.base = d;
|
||||
r.length = 10;
|
||||
ret = dst_context_adddata(ctx, &r);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
r.base = sigsha512;
|
||||
r.length = 256;
|
||||
ret = dst_context_verify(ctx, &r);
|
||||
ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS);
|
||||
assert_int_equal(ret, ISC_R_SUCCESS);
|
||||
|
||||
dst_context_destroy(&ctx);
|
||||
|
||||
|
||||
dst_key_free(&key);
|
||||
dns_test_end();
|
||||
}
|
||||
#else
|
||||
ATF_TC(untested);
|
||||
ATF_TC_HEAD(untested, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "skipping RSA test");
|
||||
}
|
||||
ATF_TC_BODY(untested, tc) {
|
||||
UNUSED(tc);
|
||||
atf_tc_skip("RSA not available");
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
|
||||
int
|
||||
main(void) {
|
||||
#if defined(OPENSSL) || defined(PKCS11CRYPTO)
|
||||
ATF_TP_ADD_TC(tp, isc_rsa_verify);
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(isc_rsa_verify_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
#else
|
||||
ATF_TP_ADD_TC(tp, untested);
|
||||
print_message("1..0 # Skipped: RSA not available\n");
|
||||
#endif
|
||||
return (atf_no_error());
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,16 +9,24 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <isc/util.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#if defined(OPENSSL) || defined(PKCS11CRYPTO)
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/db.h>
|
||||
#include <dns/diff.h>
|
||||
|
|
@ -45,6 +53,27 @@
|
|||
|
||||
#include "dnstest.h"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*%
|
||||
* Structure characterizing a single diff tuple in the dns_diff_t structure
|
||||
* prepared by dns__zone_updatesigs().
|
||||
|
|
@ -69,11 +98,11 @@ typedef struct {
|
|||
|
||||
/*%
|
||||
* Check whether the 'found' tuple matches the 'expected' tuple. 'found' is
|
||||
* the 'index'th tuple output by dns__zone_updatesigs() in test 'test'.
|
||||
* the 'idx'th tuple output by dns__zone_updatesigs() in test 'test'.
|
||||
*/
|
||||
static void
|
||||
compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
||||
const updatesigs_test_params_t *test, size_t index)
|
||||
size_t idx)
|
||||
{
|
||||
char found_covers[DNS_RDATATYPE_FORMATSIZE] = { };
|
||||
char found_type[DNS_RDATATYPE_FORMATSIZE] = { };
|
||||
|
|
@ -88,38 +117,26 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
|||
|
||||
REQUIRE(expected != NULL);
|
||||
REQUIRE(found != NULL);
|
||||
REQUIRE(index > 0);
|
||||
REQUIRE(idx > 0);
|
||||
|
||||
/*
|
||||
* Check operation.
|
||||
*/
|
||||
ATF_CHECK_EQ_MSG(expected->op, found->op,
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected op %d, found %d",
|
||||
test->description, index,
|
||||
expected->op, found->op);
|
||||
assert_int_equal(expected->op, found->op);
|
||||
|
||||
/*
|
||||
* Check owner name.
|
||||
*/
|
||||
expected_name = dns_fixedname_initname(&expected_fname);
|
||||
result = dns_name_fromstring(expected_name, expected->owner, 0, mctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_name_format(&found->name, found_name, sizeof(found_name));
|
||||
ATF_CHECK_MSG(dns_name_equal(expected_name, &found->name),
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected owner \"%s\", found \"%s\"",
|
||||
test->description, index,
|
||||
expected->owner, found_name);
|
||||
assert_true(dns_name_equal(expected_name, &found->name));
|
||||
|
||||
/*
|
||||
* Check TTL.
|
||||
*/
|
||||
ATF_CHECK_EQ_MSG(expected->ttl, found->ttl,
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected TTL %u, found %u",
|
||||
test->description, index,
|
||||
expected->ttl, found->ttl);
|
||||
assert_int_equal(expected->ttl, found->ttl);
|
||||
|
||||
/*
|
||||
* Parse expected RR type.
|
||||
|
|
@ -128,14 +145,14 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
|||
typeregion.length = strlen(expected->type);
|
||||
result = dns_rdatatype_fromtext(&expected_type,
|
||||
(isc_textregion_t*)&typeregion);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Format found RR type for reporting purposes.
|
||||
*/
|
||||
isc_buffer_init(&typebuf, found_type, sizeof(found_type));
|
||||
result = dns_rdatatype_totext(found->rdata.type, &typebuf);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Check RR type.
|
||||
|
|
@ -146,11 +163,7 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
|||
/*
|
||||
* Found tuple must be of type RRSIG.
|
||||
*/
|
||||
ATF_CHECK_EQ_MSG(found->rdata.type, dns_rdatatype_rrsig,
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected type RRSIG, found %s",
|
||||
test->description, index,
|
||||
found_type);
|
||||
assert_int_equal(found->rdata.type, dns_rdatatype_rrsig);
|
||||
if (found->rdata.type != dns_rdatatype_rrsig) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -158,25 +171,17 @@ compare_tuples(const zonediff_t *expected, dns_difftuple_t *found,
|
|||
* The signature must cover an RRset of type 'expected->type'.
|
||||
*/
|
||||
result = dns_rdata_tostruct(&found->rdata, &rrsig, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_buffer_init(&typebuf, found_covers, sizeof(found_covers));
|
||||
result = dns_rdatatype_totext(rrsig.covered, &typebuf);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ_MSG(expected_type, rrsig.covered,
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected RRSIG to cover %s, found covers %s",
|
||||
test->description, index,
|
||||
expected->type, found_covers);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(expected_type, rrsig.covered);
|
||||
break;
|
||||
default:
|
||||
/*
|
||||
* Found tuple must be of type 'expected->type'.
|
||||
*/
|
||||
ATF_CHECK_EQ_MSG(expected_type, found->rdata.type,
|
||||
"test \"%s\": tuple %zu: "
|
||||
"expected type %s, found %s",
|
||||
test->description, index,
|
||||
expected->type, found_type);
|
||||
assert_int_equal(expected_type, found->rdata.type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -191,7 +196,7 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
|||
dns_db_t *db, dst_key_t *zone_keys[], unsigned int nkeys,
|
||||
isc_stdtime_t now)
|
||||
{
|
||||
size_t tuples_expected, tuples_found, index;
|
||||
size_t tuples_expected, tuples_found, idx;
|
||||
dns_dbversion_t *version = NULL;
|
||||
dns_diff_t raw_diff, zone_diff;
|
||||
const zonediff_t *expected;
|
||||
|
|
@ -214,13 +219,13 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
|||
* Create a new version of the zone's database.
|
||||
*/
|
||||
result = dns_db_newversion(db, &version);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Create a diff representing the supplied changes.
|
||||
*/
|
||||
result = dns_test_difffromchanges(&raw_diff, test->changes);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
result = dns_test_difffromchanges(&raw_diff, test->changes, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Apply the "raw" diff to the new version of the zone's database as
|
||||
|
|
@ -240,25 +245,16 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
|||
result = dns__zone_updatesigs(&raw_diff, db, version, zone_keys, nkeys,
|
||||
zone, now - 3600, now + 3600, now,
|
||||
true, false, &zonediff);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"test \"%s\": expected success, got %s",
|
||||
test->description, isc_result_totext(result));
|
||||
ATF_CHECK_MSG(ISC_LIST_EMPTY(raw_diff.tuples),
|
||||
"test \"%s\": raw diff was not emptied",
|
||||
test->description);
|
||||
ATF_CHECK_MSG(!ISC_LIST_EMPTY(zone_diff.tuples),
|
||||
"test \"%s\": zone diff was not created",
|
||||
test->description);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(ISC_LIST_EMPTY(raw_diff.tuples));
|
||||
assert_false(ISC_LIST_EMPTY(zone_diff.tuples));
|
||||
|
||||
/*
|
||||
* Ensure that the number of tuples in the zone diff is as expected.
|
||||
*/
|
||||
|
||||
tuples_expected = 0;
|
||||
for (expected = test->zonediff;
|
||||
expected->owner != NULL;
|
||||
expected++)
|
||||
{
|
||||
for (expected = test->zonediff; expected->owner != NULL; expected++) {
|
||||
tuples_expected++;
|
||||
}
|
||||
|
||||
|
|
@ -270,24 +266,20 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
|||
tuples_found++;
|
||||
}
|
||||
|
||||
ATF_REQUIRE_EQ_MSG(tuples_expected, tuples_found,
|
||||
"test \"%s\": "
|
||||
"expected %zu tuples in output, found %zu",
|
||||
test->description,
|
||||
tuples_expected, tuples_found);
|
||||
assert_int_equal(tuples_expected, tuples_found);
|
||||
|
||||
/*
|
||||
* Ensure that every tuple in the zone diff matches expectations.
|
||||
*/
|
||||
expected = test->zonediff;
|
||||
index = 1;
|
||||
idx = 1;
|
||||
for (found = ISC_LIST_HEAD(zone_diff.tuples);
|
||||
found != NULL;
|
||||
found = ISC_LIST_NEXT(found, link))
|
||||
{
|
||||
compare_tuples(expected, found, test, index);
|
||||
compare_tuples(expected, found, idx);
|
||||
expected++;
|
||||
index++;
|
||||
idx++;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -298,11 +290,9 @@ updatesigs_test(const updatesigs_test_params_t *test, dns_zone_t *zone,
|
|||
dns_diff_clear(&raw_diff);
|
||||
}
|
||||
|
||||
ATF_TC(updatesigs);
|
||||
ATF_TC_HEAD(updatesigs, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dns__zone_updatesigs() tests");
|
||||
}
|
||||
ATF_TC_BODY(updatesigs, tc) {
|
||||
/* dns__zone_updatesigs() tests */
|
||||
static void
|
||||
updatesigs_next_test(void **state) {
|
||||
dst_key_t *zone_keys[DNS_MAXZONEKEYS];
|
||||
dns_zone_t *zone = NULL;
|
||||
dns_db_t *db = NULL;
|
||||
|
|
@ -311,28 +301,27 @@ ATF_TC_BODY(updatesigs, tc) {
|
|||
isc_stdtime_t now;
|
||||
size_t i;
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* Prepare a zone along with its signing keys.
|
||||
*/
|
||||
|
||||
result = dns_test_makezone("example", &zone, NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_loaddb(&db, dns_dbtype_zone, "example",
|
||||
"testdata/master/master18.data");
|
||||
ATF_REQUIRE_EQ(result, DNS_R_SEENINCLUDE);
|
||||
assert_int_equal(result, DNS_R_SEENINCLUDE);
|
||||
|
||||
result = dns_zone_setkeydirectory(zone, "testkeys");
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_stdtime_get(&now);
|
||||
result = dns__zone_findkeys(zone, db, NULL, now, mctx, DNS_MAXZONEKEYS,
|
||||
zone_keys, &nkeys);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(nkeys, 2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(nkeys, 2);
|
||||
|
||||
/*
|
||||
* Define the tests to be run. Note that changes to zone database
|
||||
|
|
@ -454,26 +443,31 @@ ATF_TC_BODY(updatesigs, tc) {
|
|||
}
|
||||
dns_db_detach(&db);
|
||||
dns_zone_detach(&zone);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
#else
|
||||
ATF_TC(untested);
|
||||
ATF_TC_HEAD(untested, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "skipping dns__zone_updatesigs() test");
|
||||
}
|
||||
ATF_TC_BODY(untested, tc) {
|
||||
UNUSED(tc);
|
||||
atf_tc_skip("DNSSEC support not compiled in");
|
||||
}
|
||||
#endif
|
||||
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
int
|
||||
main(void) {
|
||||
#if defined(OPENSSL) || defined(PKCS11CRYPTO)
|
||||
ATF_TP_ADD_TC(tp, updatesigs);
|
||||
#else
|
||||
ATF_TP_ADD_TC(tp, untested);
|
||||
#endif
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(updatesigs_next_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
#else
|
||||
print_message("1..0 # Skipped: sigs test requires crypto\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,31 +10,55 @@
|
|||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/time.h>
|
||||
|
||||
#include "dnstest.h"
|
||||
|
||||
#define TEST_ORIGIN "test"
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* value = 0xfffffffff <-> 19691231235959 */
|
||||
ATF_TC(epoch_minus_one);
|
||||
ATF_TC_HEAD(epoch_minus_one, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "0xffffffff <-> 19691231235959");
|
||||
}
|
||||
ATF_TC_BODY(epoch_minus_one, tc) {
|
||||
static void
|
||||
epoch_minus_one_test(void **state) {
|
||||
const char *test_text = "19691231235959";
|
||||
const uint32_t test_time = 0xffffffff;
|
||||
isc_result_t result;
|
||||
|
|
@ -42,27 +66,21 @@ ATF_TC_BODY(epoch_minus_one, tc) {
|
|||
uint32_t when;
|
||||
char buf[128];
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
isc_buffer_init(&target, buf, sizeof(buf));
|
||||
result = dns_time32_totext(test_time, &target);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_STREQ(buf, test_text);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, test_text);
|
||||
result = dns_time32_fromtext(test_text, &when);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(when, test_time);
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(when, test_time);
|
||||
}
|
||||
|
||||
/* value = 0x000000000 <-> 19700101000000*/
|
||||
ATF_TC(epoch);
|
||||
ATF_TC_HEAD(epoch, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "0x00000000 <-> 19700101000000");
|
||||
}
|
||||
ATF_TC_BODY(epoch, tc) {
|
||||
static void
|
||||
epoch_test(void **state) {
|
||||
const char *test_text = "19700101000000";
|
||||
const uint32_t test_time = 0x00000000;
|
||||
isc_result_t result;
|
||||
|
|
@ -70,27 +88,21 @@ ATF_TC_BODY(epoch, tc) {
|
|||
uint32_t when;
|
||||
char buf[128];
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
isc_buffer_init(&target, buf, sizeof(buf));
|
||||
result = dns_time32_totext(test_time, &target);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_STREQ(buf, test_text);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, test_text);
|
||||
result = dns_time32_fromtext(test_text, &when);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(when, test_time);
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(when, test_time);
|
||||
}
|
||||
|
||||
/* value = 0x7fffffff <-> 20380119031407 */
|
||||
ATF_TC(half_maxint);
|
||||
ATF_TC_HEAD(half_maxint, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "0x7fffffff <-> 20380119031407");
|
||||
}
|
||||
ATF_TC_BODY(half_maxint, tc) {
|
||||
static void
|
||||
half_maxint_test(void **state) {
|
||||
const char *test_text = "20380119031407";
|
||||
const uint32_t test_time = 0x7fffffff;
|
||||
isc_result_t result;
|
||||
|
|
@ -98,27 +110,21 @@ ATF_TC_BODY(half_maxint, tc) {
|
|||
uint32_t when;
|
||||
char buf[128];
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
isc_buffer_init(&target, buf, sizeof(buf));
|
||||
result = dns_time32_totext(test_time, &target);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_STREQ(buf, test_text);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, test_text);
|
||||
result = dns_time32_fromtext(test_text, &when);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(when, test_time);
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(when, test_time);
|
||||
}
|
||||
|
||||
/* value = 0x80000000 <-> 20380119031408 */
|
||||
ATF_TC(half_plus_one);
|
||||
ATF_TC_HEAD(half_plus_one, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "0x80000000 <-> 20380119031408");
|
||||
}
|
||||
ATF_TC_BODY(half_plus_one, tc) {
|
||||
static void
|
||||
half_plus_one_test(void **state) {
|
||||
const char *test_text = "20380119031408";
|
||||
const uint32_t test_time = 0x80000000;
|
||||
isc_result_t result;
|
||||
|
|
@ -126,27 +132,21 @@ ATF_TC_BODY(half_plus_one, tc) {
|
|||
uint32_t when;
|
||||
char buf[128];
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
isc_buffer_init(&target, buf, sizeof(buf));
|
||||
result = dns_time32_totext(test_time, &target);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_STREQ(buf, test_text);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, test_text);
|
||||
result = dns_time32_fromtext(test_text, &when);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(when, test_time);
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(when, test_time);
|
||||
}
|
||||
|
||||
/* value = 0xef68f5d0 <-> 19610307130000 */
|
||||
ATF_TC(fifty_before);
|
||||
ATF_TC_HEAD(fifty_before, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "0xef68f5d0 <-> 19610307130000");
|
||||
}
|
||||
ATF_TC_BODY(fifty_before, tc) {
|
||||
static void
|
||||
fifty_before_test(void **state) {
|
||||
isc_result_t result;
|
||||
const char *test_text = "19610307130000";
|
||||
const uint32_t test_time = 0xef68f5d0;
|
||||
|
|
@ -154,27 +154,21 @@ ATF_TC_BODY(fifty_before, tc) {
|
|||
uint32_t when;
|
||||
char buf[128];
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
isc_buffer_init(&target, buf, sizeof(buf));
|
||||
result = dns_time32_totext(test_time, &target);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_STREQ(buf, test_text);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, test_text);
|
||||
result = dns_time32_fromtext(test_text, &when);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(when, test_time);
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(when, test_time);
|
||||
}
|
||||
|
||||
/* value = 0x4d74d6d0 <-> 20110307130000 */
|
||||
ATF_TC(some_ago);
|
||||
ATF_TC_HEAD(some_ago, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "0x4d74d6d0 <-> 20110307130000");
|
||||
}
|
||||
ATF_TC_BODY(some_ago, tc) {
|
||||
static void
|
||||
some_ago_test(void **state) {
|
||||
const char *test_text = "20110307130000";
|
||||
const uint32_t test_time = 0x4d74d6d0;
|
||||
isc_result_t result;
|
||||
|
|
@ -182,32 +176,46 @@ ATF_TC_BODY(some_ago, tc) {
|
|||
uint32_t when;
|
||||
char buf[128];
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
isc_buffer_init(&target, buf, sizeof(buf));
|
||||
result = dns_time32_totext(test_time, &target);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_STREQ(buf, test_text);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, test_text);
|
||||
result = dns_time32_fromtext(test_text, &when);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(when, test_time);
|
||||
dns_test_end();
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(when, test_time);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, epoch_minus_one);
|
||||
ATF_TP_ADD_TC(tp, epoch);
|
||||
ATF_TP_ADD_TC(tp, half_maxint);
|
||||
ATF_TP_ADD_TC(tp, half_plus_one);
|
||||
ATF_TP_ADD_TC(tp, fifty_before);
|
||||
ATF_TP_ADD_TC(tp, some_ago);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(epoch_minus_one_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(epoch_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(half_maxint_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(half_plus_one_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(fifty_before_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(some_ago_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,13 +9,25 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
#include <atf-c.h>
|
||||
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/mem.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
|
||||
#include <dns/rdatalist.h>
|
||||
#include <dns/rdataset.h>
|
||||
|
|
@ -23,6 +35,28 @@
|
|||
|
||||
#include "dnstest.h"
|
||||
|
||||
#define TEST_ORIGIN "test"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int debug = 0;
|
||||
|
||||
|
|
@ -94,12 +128,13 @@ add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) {
|
|||
|
||||
CHECK(dst_key_sigsize(key->key, &sigsize));
|
||||
tsig.signature = (unsigned char *) isc_mem_get(mctx, sigsize);
|
||||
if (tsig.signature == NULL)
|
||||
if (tsig.signature == NULL) {
|
||||
CHECK(ISC_R_NOMEMORY);
|
||||
}
|
||||
isc_buffer_init(&sigbuf, tsig.signature, sigsize);
|
||||
CHECK(dst_context_sign(tsigctx, &sigbuf));
|
||||
tsig.siglen = isc_buffer_usedlength(&sigbuf);
|
||||
ATF_CHECK_EQ(sigsize, tsig.siglen);
|
||||
assert_int_equal(sigsize, tsig.siglen);
|
||||
|
||||
CHECK(isc_buffer_allocate(mctx, &dynbuf, 512));
|
||||
CHECK(dns_rdata_fromstruct(&rdata, dns_rdataclass_any,
|
||||
|
|
@ -117,15 +152,19 @@ add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) {
|
|||
* Fixup additional record count.
|
||||
*/
|
||||
((unsigned char*)target->base)[11]++;
|
||||
if (((unsigned char*)target->base)[11] == 0)
|
||||
if (((unsigned char*)target->base)[11] == 0) {
|
||||
((unsigned char*)target->base)[10]++;
|
||||
}
|
||||
cleanup:
|
||||
if (tsig.signature != NULL)
|
||||
if (tsig.signature != NULL) {
|
||||
isc_mem_put(mctx, tsig.signature, sigsize);
|
||||
if (dynbuf != NULL)
|
||||
}
|
||||
if (dynbuf != NULL) {
|
||||
isc_buffer_free(&dynbuf);
|
||||
if (invalidate_ctx)
|
||||
}
|
||||
if (invalidate_ctx) {
|
||||
dns_compress_invalidate(&cctx);
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
|
@ -137,13 +176,12 @@ printmessage(dns_message_t *msg) {
|
|||
int len = 1024;
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
|
||||
if (!debug)
|
||||
if (!debug) {
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
buf = isc_mem_get(mctx, len);
|
||||
if (buf == NULL)
|
||||
return;
|
||||
|
||||
isc_buffer_init(&b, buf, len);
|
||||
result = dns_message_totext(msg, &dns_master_style_debug,
|
||||
|
|
@ -151,12 +189,14 @@ printmessage(dns_message_t *msg) {
|
|||
if (result == ISC_R_NOSPACE) {
|
||||
isc_mem_put(mctx, buf, len);
|
||||
len *= 2;
|
||||
} else if (result == ISC_R_SUCCESS)
|
||||
} else if (result == ISC_R_SUCCESS) {
|
||||
printf("%.*s\n", (int) isc_buffer_usedlength(&b), buf);
|
||||
}
|
||||
} while (result == ISC_R_NOSPACE);
|
||||
|
||||
if (buf != NULL)
|
||||
if (buf != NULL) {
|
||||
isc_mem_put(mctx, buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -169,10 +209,8 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key,
|
|||
isc_result_t result;
|
||||
|
||||
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &msg);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_message_create: %s",
|
||||
dns_result_totext(result));
|
||||
ATF_REQUIRE(msg != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(msg);
|
||||
|
||||
msg->id = 50;
|
||||
msg->rcode = dns_rcode_noerror;
|
||||
|
|
@ -182,55 +220,44 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key,
|
|||
* XXXMPA: this hack needs to be replaced with use of
|
||||
* dns_message_reply() at some point.
|
||||
*/
|
||||
if ((flags & DNS_MESSAGEFLAG_QR) != 0)
|
||||
if ((flags & DNS_MESSAGEFLAG_QR) != 0) {
|
||||
msg->verified_sig = 1;
|
||||
}
|
||||
|
||||
if (tsigin == tsigout)
|
||||
if (tsigin == tsigout) {
|
||||
msg->tcp_continuation = 1;
|
||||
}
|
||||
|
||||
if (tsigctx == NULL) {
|
||||
result = dns_message_settsigkey(msg, key);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_message_settsigkey: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_message_setquerytsig(msg, *tsigin);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_message_setquerytsig: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
result = dns_compress_init(&cctx, -1, mctx);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_compress_init: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_message_renderbegin(msg, &cctx, buf);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_message_renderbegin: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_message_renderend(msg);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_message_renderend: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
if (tsigctx != NULL) {
|
||||
isc_region_t r;
|
||||
|
||||
isc_buffer_usedregion(buf, &r);
|
||||
result = dst_context_adddata(tsigctx, &r);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dst_context_adddata: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
} else {
|
||||
if (tsigin == tsigout && *tsigin != NULL)
|
||||
if (tsigin == tsigout && *tsigin != NULL) {
|
||||
isc_buffer_free(tsigin);
|
||||
}
|
||||
|
||||
result = dns_message_getquerytsig(msg, mctx, tsigout);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_message_getquerytsig: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
dns_compress_invalidate(&cctx);
|
||||
|
|
@ -238,15 +265,13 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key,
|
|||
}
|
||||
|
||||
/*
|
||||
* Test tsig tcp-continuation validation:
|
||||
* Check that a simulated three message TCP sequence where the first
|
||||
* and last messages contain TSIGs but the intermediate message doesn't
|
||||
* correctly verifies.
|
||||
*/
|
||||
ATF_TC(tsig_tcp);
|
||||
ATF_TC_HEAD(tsig_tcp, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test tsig tcp-continuation validation");
|
||||
}
|
||||
ATF_TC_BODY(tsig_tcp, tc) {
|
||||
static void
|
||||
tsig_tcp_test(void **state) {
|
||||
dns_name_t *tsigowner = NULL;
|
||||
dns_fixedname_t fkeyname;
|
||||
dns_message_t *msg = NULL;
|
||||
|
|
@ -262,31 +287,28 @@ ATF_TC_BODY(tsig_tcp, tc) {
|
|||
dst_context_t *tsigctx = NULL;
|
||||
dst_context_t *outctx = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(stderr, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* isc_log_setdebuglevel(lctx, 99); */
|
||||
|
||||
keyname = dns_fixedname_initname(&fkeyname);
|
||||
result = dns_name_fromstring(keyname, "test", 0, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_tsigkeyring_create(mctx, &ring);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_tsigkey_create(keyname, dns_tsig_hmacsha256_name,
|
||||
secret, sizeof(secret), false,
|
||||
NULL, 0, 0, mctx, ring, &key);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE(key != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(key);
|
||||
|
||||
/*
|
||||
* Create request.
|
||||
*/
|
||||
result = isc_buffer_allocate(mctx, &buf, 65535);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
render(buf, 0, key, &tsigout, &querytsig, NULL);
|
||||
isc_buffer_free(&buf);
|
||||
|
||||
|
|
@ -294,48 +316,39 @@ ATF_TC_BODY(tsig_tcp, tc) {
|
|||
* Create response message 1.
|
||||
*/
|
||||
result = isc_buffer_allocate(mctx, &buf, 65535);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
render(buf, DNS_MESSAGEFLAG_QR, key, &querytsig, &tsigout, NULL);
|
||||
|
||||
/*
|
||||
* Process response message 1.
|
||||
*/
|
||||
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_create: %s",
|
||||
dns_result_totext(result));
|
||||
ATF_REQUIRE(msg != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(msg);
|
||||
|
||||
result = dns_message_settsigkey(msg, key);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_settsigkey: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_message_parse(msg, buf, 0);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_parse: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
printmessage(msg);
|
||||
|
||||
result = dns_message_setquerytsig(msg, querytsig);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_message_setquerytsig: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_tsig_verify(buf, msg, NULL, NULL);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_tsig_verify: %s",
|
||||
dns_result_totext(result));
|
||||
ATF_CHECK_EQ(msg->verified_sig, 1);
|
||||
ATF_CHECK_EQ(msg->tsigstatus, dns_rcode_noerror);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(msg->verified_sig, 1);
|
||||
assert_int_equal(msg->tsigstatus, dns_rcode_noerror);
|
||||
|
||||
/*
|
||||
* Check that we have a TSIG in the first message.
|
||||
*/
|
||||
ATF_REQUIRE(dns_message_gettsig(msg, &tsigowner) != NULL);
|
||||
assert_non_null(dns_message_gettsig(msg, &tsigowner));
|
||||
|
||||
result = dns_message_getquerytsig(msg, mctx, &tsigin);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_message_getquerytsig: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
tsigctx = msg->tsigctx;
|
||||
msg->tsigctx = NULL;
|
||||
|
|
@ -344,63 +357,56 @@ ATF_TC_BODY(tsig_tcp, tc) {
|
|||
|
||||
result = dst_context_create3(key->key, mctx, DNS_LOGCATEGORY_DNSSEC,
|
||||
false, &outctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE(outctx != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(outctx);
|
||||
|
||||
/*
|
||||
* Start digesting.
|
||||
*/
|
||||
result = add_mac(outctx, tsigout);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Create response message 2.
|
||||
*/
|
||||
result = isc_buffer_allocate(mctx, &buf, 65535);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
render(buf, DNS_MESSAGEFLAG_QR, key, &tsigout, &tsigout, outctx);
|
||||
|
||||
/*
|
||||
* Process response message 2.
|
||||
*/
|
||||
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_create: %s",
|
||||
dns_result_totext(result));
|
||||
ATF_REQUIRE(msg != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(msg);
|
||||
|
||||
msg->tcp_continuation = 1;
|
||||
msg->tsigctx = tsigctx;
|
||||
tsigctx = NULL;
|
||||
|
||||
result = dns_message_settsigkey(msg, key);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_settsigkey: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_message_parse(msg, buf, 0);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_parse: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
printmessage(msg);
|
||||
|
||||
result = dns_message_setquerytsig(msg, tsigin);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_message_setquerytsig: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_tsig_verify(buf, msg, NULL, NULL);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_tsig_verify: %s",
|
||||
dns_result_totext(result));
|
||||
ATF_CHECK_EQ(msg->verified_sig, 0);
|
||||
ATF_CHECK_EQ(msg->tsigstatus, dns_rcode_noerror);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(msg->verified_sig, 0);
|
||||
assert_int_equal(msg->tsigstatus, dns_rcode_noerror);
|
||||
|
||||
/*
|
||||
* Check that we don't have a TSIG in the second message.
|
||||
*/
|
||||
tsigowner = NULL;
|
||||
ATF_REQUIRE(dns_message_gettsig(msg, &tsigowner) == NULL);
|
||||
assert_true(dns_message_gettsig(msg, &tsigowner) == NULL);
|
||||
|
||||
tsigctx = msg->tsigctx;
|
||||
msg->tsigctx = NULL;
|
||||
|
|
@ -411,81 +417,90 @@ ATF_TC_BODY(tsig_tcp, tc) {
|
|||
* Create response message 3.
|
||||
*/
|
||||
result = isc_buffer_allocate(mctx, &buf, 65535);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
render(buf, DNS_MESSAGEFLAG_QR, key, &tsigout, &tsigout, outctx);
|
||||
|
||||
result = add_tsig(outctx, key, buf);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "add_tsig: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Process response message 3.
|
||||
*/
|
||||
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_create: %s",
|
||||
dns_result_totext(result));
|
||||
ATF_REQUIRE(msg != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(msg);
|
||||
|
||||
msg->tcp_continuation = 1;
|
||||
msg->tsigctx = tsigctx;
|
||||
tsigctx = NULL;
|
||||
|
||||
result = dns_message_settsigkey(msg, key);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_settsigkey: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_message_parse(msg, buf, 0);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "dns_message_parse: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
printmessage(msg);
|
||||
|
||||
/*
|
||||
* Check that we had a TSIG in the third message.
|
||||
*/
|
||||
ATF_REQUIRE(dns_message_gettsig(msg, &tsigowner) != NULL);
|
||||
assert_non_null(dns_message_gettsig(msg, &tsigowner));
|
||||
|
||||
result = dns_message_setquerytsig(msg, tsigin);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_message_setquerytsig: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_tsig_verify(buf, msg, NULL, NULL);
|
||||
ATF_CHECK_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_tsig_verify: %s",
|
||||
dns_result_totext(result));
|
||||
ATF_CHECK_EQ(msg->verified_sig, 1);
|
||||
ATF_CHECK_EQ(msg->tsigstatus, dns_rcode_noerror);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(msg->verified_sig, 1);
|
||||
assert_int_equal(msg->tsigstatus, dns_rcode_noerror);
|
||||
|
||||
if (tsigin != NULL)
|
||||
if (tsigin != NULL) {
|
||||
isc_buffer_free(&tsigin);
|
||||
}
|
||||
|
||||
result = dns_message_getquerytsig(msg, mctx, &tsigin);
|
||||
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
|
||||
"dns_message_getquerytsig: %s",
|
||||
dns_result_totext(result));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_buffer_free(&buf);
|
||||
dns_message_destroy(&msg);
|
||||
|
||||
if (outctx != NULL)
|
||||
if (outctx != NULL) {
|
||||
dst_context_destroy(&outctx);
|
||||
if (querytsig != NULL)
|
||||
}
|
||||
if (querytsig != NULL) {
|
||||
isc_buffer_free(&querytsig);
|
||||
if (tsigin != NULL)
|
||||
}
|
||||
if (tsigin != NULL) {
|
||||
isc_buffer_free(&tsigin);
|
||||
if (tsigout != NULL)
|
||||
}
|
||||
if (tsigout != NULL) {
|
||||
isc_buffer_free(&tsigout);
|
||||
}
|
||||
dns_tsigkey_detach(&key);
|
||||
if (ring != NULL)
|
||||
if (ring != NULL) {
|
||||
dns_tsigkeyring_detach(&ring);
|
||||
dns_test_end();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, tsig_tcp);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(tsig_tcp_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,334 +10,314 @@
|
|||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/serial.h>
|
||||
#include <isc/stdtime.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/update.h>
|
||||
|
||||
#include "dnstest.h"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
setenv("TZ", "", 1);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static uint32_t mystdtime;
|
||||
|
||||
static void set_mystdtime(int year, int month, int day) {
|
||||
static void
|
||||
set_mystdtime(int year, int month, int day) {
|
||||
struct tm tm;
|
||||
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
tm.tm_year = year - 1900;
|
||||
tm.tm_mon = month - 1;
|
||||
tm.tm_mday = day;
|
||||
mystdtime = timegm(&tm) ;
|
||||
mystdtime = timegm(&tm);
|
||||
}
|
||||
|
||||
void isc_stdtime_get(isc_stdtime_t *now) {
|
||||
*now = mystdtime;
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
ATF_TC(increment);
|
||||
ATF_TC_HEAD(increment, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "simple increment by 1");
|
||||
}
|
||||
ATF_TC_BODY(increment, tc) {
|
||||
/* simple increment by 1 */
|
||||
static void
|
||||
increment_test(void **state) {
|
||||
uint32_t old = 50;
|
||||
uint32_t serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_increment);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK_MSG(serial != 0, "serial (%d) should not equal 0", serial);
|
||||
ATF_REQUIRE_EQ(serial, 51);
|
||||
dns_test_end();
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, 51);
|
||||
}
|
||||
|
||||
/* 0xfffffffff -> 1 */
|
||||
ATF_TC(increment_past_zero);
|
||||
ATF_TC_HEAD(increment_past_zero, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "increment past zero, ffffffff -> 1");
|
||||
}
|
||||
ATF_TC_BODY(increment_past_zero, tc) {
|
||||
/* increment past zero, 0xfffffffff -> 1 */
|
||||
static void
|
||||
increment_past_zero_test(void **state) {
|
||||
uint32_t old = 0xffffffffu;
|
||||
uint32_t serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_increment);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK(serial != 0);
|
||||
ATF_REQUIRE_EQ(serial, 1u);
|
||||
dns_test_end();
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, 1u);
|
||||
}
|
||||
|
||||
ATF_TC(past_to_unix);
|
||||
ATF_TC_HEAD(past_to_unix, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "past to unixtime");
|
||||
}
|
||||
ATF_TC_BODY(past_to_unix, tc) {
|
||||
/* past to unixtime */
|
||||
static void
|
||||
past_to_unix_test(void **state) {
|
||||
uint32_t old;
|
||||
uint32_t serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
set_mystdtime(2011, 6, 22);
|
||||
old = mystdtime - 1;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_unixtime);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK(serial != 0);
|
||||
ATF_REQUIRE_EQ(serial, mystdtime);
|
||||
dns_test_end();
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, mystdtime);
|
||||
}
|
||||
|
||||
ATF_TC(now_to_unix);
|
||||
ATF_TC_HEAD(now_to_unix, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "now to unixtime");
|
||||
}
|
||||
ATF_TC_BODY(now_to_unix, tc) {
|
||||
/* now to unixtime */
|
||||
static void
|
||||
now_to_unix_test(void **state) {
|
||||
uint32_t old;
|
||||
uint32_t serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
set_mystdtime(2011, 6, 22);
|
||||
old = mystdtime;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_unixtime);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK(serial != 0);
|
||||
ATF_REQUIRE_EQ(serial, old + 1);
|
||||
dns_test_end();
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, old + 1);
|
||||
}
|
||||
|
||||
ATF_TC(future_to_unix);
|
||||
ATF_TC_HEAD(future_to_unix, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "future to unixtime");
|
||||
}
|
||||
ATF_TC_BODY(future_to_unix, tc) {
|
||||
/* future to unixtime */
|
||||
static void
|
||||
future_to_unix_test(void **state) {
|
||||
uint32_t old;
|
||||
uint32_t serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
set_mystdtime(2011, 6, 22);
|
||||
old = mystdtime + 1;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_unixtime);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK(serial != 0);
|
||||
ATF_REQUIRE_EQ(serial, old + 1);
|
||||
dns_test_end();
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, old + 1);
|
||||
}
|
||||
|
||||
ATF_TC(undefined_plus1_to_unix);
|
||||
ATF_TC_HEAD(undefined_plus1_to_unix, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "undefined plus 1 to unixtime");
|
||||
}
|
||||
ATF_TC_BODY(undefined_plus1_to_unix, tc) {
|
||||
/* undefined plus 1 to unixtime */
|
||||
static void
|
||||
undefined_plus1_to_unix_test(void **state) {
|
||||
uint32_t old;
|
||||
uint32_t serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
set_mystdtime(2011, 6, 22);
|
||||
old = mystdtime ^ 0x80000000u;
|
||||
old += 1;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_unixtime);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK(serial != 0);
|
||||
ATF_REQUIRE_EQ(serial, mystdtime);
|
||||
dns_test_end();
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, mystdtime);
|
||||
}
|
||||
|
||||
ATF_TC(undefined_minus1_to_unix);
|
||||
ATF_TC_HEAD(undefined_minus1_to_unix, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "undefined minus 1 to unixtime");
|
||||
}
|
||||
ATF_TC_BODY(undefined_minus1_to_unix, tc) {
|
||||
/* undefined minus 1 to unixtime */
|
||||
static void
|
||||
undefined_minus1_to_unix_test(void **state) {
|
||||
uint32_t old;
|
||||
uint32_t serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
set_mystdtime(2011, 6, 22);
|
||||
old = mystdtime ^ 0x80000000u;
|
||||
old -= 1;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_unixtime);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK(serial != 0);
|
||||
ATF_REQUIRE_EQ(serial, old + 1);
|
||||
dns_test_end();
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, old + 1);
|
||||
}
|
||||
|
||||
ATF_TC(undefined_to_unix);
|
||||
ATF_TC_HEAD(undefined_to_unix, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "undefined to unixtime");
|
||||
}
|
||||
ATF_TC_BODY(undefined_to_unix, tc) {
|
||||
/* undefined to unixtime */
|
||||
static void
|
||||
undefined_to_unix_test(void **state) {
|
||||
uint32_t old;
|
||||
uint32_t serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
set_mystdtime(2011, 6, 22);
|
||||
old = mystdtime ^ 0x80000000u;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_unixtime);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK(serial != 0);
|
||||
ATF_REQUIRE_EQ(serial, old + 1);
|
||||
dns_test_end();
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, old + 1);
|
||||
}
|
||||
|
||||
ATF_TC(unixtime_zero);
|
||||
ATF_TC_HEAD(unixtime_zero, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "handle unixtime being zero");
|
||||
}
|
||||
ATF_TC_BODY(unixtime_zero, tc) {
|
||||
/* handle unixtime being zero */
|
||||
static void
|
||||
unixtime_zero_test(void **state) {
|
||||
uint32_t old;
|
||||
uint32_t serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
mystdtime = 0;
|
||||
old = 0xfffffff0;
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_unixtime);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK(serial != 0);
|
||||
ATF_REQUIRE_EQ(serial, old + 1);
|
||||
dns_test_end();
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, old + 1);
|
||||
}
|
||||
|
||||
ATF_TC(past_to_date);
|
||||
ATF_TC_HEAD(past_to_date, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "past to date");
|
||||
}
|
||||
ATF_TC_BODY(past_to_date, tc) {
|
||||
/* past to date */
|
||||
static void
|
||||
past_to_date_test(void **state) {
|
||||
uint32_t old, serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
set_mystdtime(2014, 3, 31);
|
||||
old = dns_update_soaserial(0, dns_updatemethod_date);
|
||||
set_mystdtime(2014, 4, 1);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_date);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK(serial != 0);
|
||||
ATF_REQUIRE_EQ(serial, 2014040100);
|
||||
dns_test_end();
|
||||
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, 2014040100);
|
||||
}
|
||||
|
||||
ATF_TC(now_to_date);
|
||||
ATF_TC_HEAD(now_to_date, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "now to date");
|
||||
}
|
||||
ATF_TC_BODY(now_to_date, tc) {
|
||||
/* now to date */
|
||||
static void
|
||||
now_to_date_test(void **state) {
|
||||
uint32_t old;
|
||||
uint32_t serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
set_mystdtime(2014, 4, 1);
|
||||
old = dns_update_soaserial(0, dns_updatemethod_date);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_date);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK(serial != 0);
|
||||
ATF_REQUIRE_EQ(serial, 2014040101);
|
||||
dns_test_end();
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, 2014040101);
|
||||
}
|
||||
|
||||
ATF_TC(future_to_date);
|
||||
ATF_TC_HEAD(future_to_date, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "future to date");
|
||||
}
|
||||
ATF_TC_BODY(future_to_date, tc) {
|
||||
/* future to date */
|
||||
static void
|
||||
future_to_date_test(void **state) {
|
||||
uint32_t old;
|
||||
uint32_t serial;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
set_mystdtime(2014, 4, 1);
|
||||
old = dns_update_soaserial(0, dns_updatemethod_date);
|
||||
set_mystdtime(2014, 3, 31);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
serial = dns_update_soaserial(old, dns_updatemethod_date);
|
||||
ATF_REQUIRE_EQ(isc_serial_lt(old, serial), true);
|
||||
ATF_CHECK(serial != 0);
|
||||
ATF_REQUIRE_EQ(serial, 2014040101);
|
||||
dns_test_end();
|
||||
assert_true(isc_serial_lt(old, serial));
|
||||
assert_int_not_equal(serial, 0);
|
||||
assert_int_equal(serial, 2014040101);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, increment);
|
||||
ATF_TP_ADD_TC(tp, increment_past_zero);
|
||||
ATF_TP_ADD_TC(tp, past_to_unix);
|
||||
ATF_TP_ADD_TC(tp, now_to_unix);
|
||||
ATF_TP_ADD_TC(tp, future_to_unix);
|
||||
ATF_TP_ADD_TC(tp, undefined_to_unix);
|
||||
ATF_TP_ADD_TC(tp, undefined_plus1_to_unix);
|
||||
ATF_TP_ADD_TC(tp, undefined_minus1_to_unix);
|
||||
ATF_TP_ADD_TC(tp, unixtime_zero);
|
||||
ATF_TP_ADD_TC(tp, past_to_date);
|
||||
ATF_TP_ADD_TC(tp, now_to_date);
|
||||
ATF_TP_ADD_TC(tp, future_to_date);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(increment_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(increment_past_zero_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(past_to_unix_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(now_to_unix_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(future_to_unix_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(undefined_to_unix_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(undefined_plus1_to_unix_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(undefined_minus1_to_unix_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(unixtime_zero_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(past_to_date_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(now_to_date_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(future_to_date_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,18 +9,26 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/timer.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/name.h>
|
||||
#include <dns/view.h>
|
||||
|
|
@ -28,127 +36,121 @@
|
|||
|
||||
#include "dnstest.h"
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
ATF_TC(zonemgr_create);
|
||||
ATF_TC_HEAD(zonemgr_create, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create zone manager");
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
ATF_TC_BODY(zonemgr_create, tc) {
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* create zone manager */
|
||||
static void
|
||||
zonemgr_create(void **state) {
|
||||
dns_zonemgr_t *myzonemgr = NULL;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
||||
&myzonemgr);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
dns_zonemgr_shutdown(myzonemgr);
|
||||
dns_zonemgr_detach(&myzonemgr);
|
||||
ATF_REQUIRE_EQ(myzonemgr, NULL);
|
||||
|
||||
dns_test_end();
|
||||
assert_null(myzonemgr);
|
||||
}
|
||||
|
||||
|
||||
ATF_TC(zonemgr_managezone);
|
||||
ATF_TC_HEAD(zonemgr_managezone, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "manage and release a zone");
|
||||
}
|
||||
ATF_TC_BODY(zonemgr_managezone, tc) {
|
||||
/* manage and release a zone */
|
||||
static void
|
||||
zonemgr_managezone(void **state) {
|
||||
dns_zonemgr_t *myzonemgr = NULL;
|
||||
dns_zone_t *zone = NULL;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
||||
&myzonemgr);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_makezone("foo", &zone, NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* This should not succeed until the dns_zonemgr_setsize() is run */
|
||||
result = dns_zonemgr_managezone(myzonemgr, zone);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_FAILURE);
|
||||
assert_int_equal(result, ISC_R_FAILURE);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
|
||||
assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
|
||||
|
||||
result = dns_zonemgr_setsize(myzonemgr, 1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Now it should succeed */
|
||||
result = dns_zonemgr_managezone(myzonemgr, zone);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 1);
|
||||
assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 1);
|
||||
|
||||
dns_zonemgr_releasezone(myzonemgr, zone);
|
||||
dns_zone_detach(&zone);
|
||||
|
||||
ATF_REQUIRE_EQ(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
|
||||
assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
|
||||
|
||||
dns_zonemgr_shutdown(myzonemgr);
|
||||
dns_zonemgr_detach(&myzonemgr);
|
||||
ATF_REQUIRE_EQ(myzonemgr, NULL);
|
||||
|
||||
dns_test_end();
|
||||
assert_null(myzonemgr);
|
||||
}
|
||||
|
||||
ATF_TC(zonemgr_createzone);
|
||||
ATF_TC_HEAD(zonemgr_createzone, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create and release a zone");
|
||||
}
|
||||
ATF_TC_BODY(zonemgr_createzone, tc) {
|
||||
/* create and release a zone */
|
||||
static void
|
||||
zonemgr_createzone(void **state) {
|
||||
dns_zonemgr_t *myzonemgr = NULL;
|
||||
dns_zone_t *zone = NULL;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
||||
&myzonemgr);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* This should not succeed until the dns_zonemgr_setsize() is run */
|
||||
result = dns_zonemgr_createzone(myzonemgr, &zone);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_FAILURE);
|
||||
assert_int_equal(result, ISC_R_FAILURE);
|
||||
|
||||
result = dns_zonemgr_setsize(myzonemgr, 1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Now it should succeed */
|
||||
result = dns_zonemgr_createzone(myzonemgr, &zone);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(zone != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(zone);
|
||||
|
||||
if (zone != NULL)
|
||||
dns_zone_detach(&zone);
|
||||
|
||||
dns_zonemgr_shutdown(myzonemgr);
|
||||
dns_zonemgr_detach(&myzonemgr);
|
||||
ATF_REQUIRE_EQ(myzonemgr, NULL);
|
||||
|
||||
dns_test_end();
|
||||
assert_null(myzonemgr);
|
||||
}
|
||||
|
||||
ATF_TC(zonemgr_unreachable);
|
||||
ATF_TC_HEAD(zonemgr_unreachable, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "manage and release a zone");
|
||||
}
|
||||
ATF_TC_BODY(zonemgr_unreachable, tc) {
|
||||
/* manage and release a zone */
|
||||
static void
|
||||
zonemgr_unreachable(void **state) {
|
||||
dns_zonemgr_t *myzonemgr = NULL;
|
||||
dns_zone_t *zone = NULL;
|
||||
isc_sockaddr_t addr1, addr2;
|
||||
|
|
@ -156,80 +158,62 @@ ATF_TC_BODY(zonemgr_unreachable, tc) {
|
|||
isc_result_t result;
|
||||
isc_time_t now;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
TIME_NOW(&now);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
|
||||
&myzonemgr);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_makezone("foo", &zone, NULL, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_zonemgr_setsize(myzonemgr, 1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_zonemgr_managezone(myzonemgr, zone);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
in.s_addr = inet_addr("10.53.0.1");
|
||||
isc_sockaddr_fromin(&addr1, &in, 2112);
|
||||
in.s_addr = inet_addr("10.53.0.2");
|
||||
isc_sockaddr_fromin(&addr2, &in, 5150);
|
||||
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
/*
|
||||
* We require multiple unreachableadd calls to mark a server as
|
||||
* unreachable.
|
||||
*/
|
||||
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
||||
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
||||
ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
|
||||
in.s_addr = inet_addr("10.53.0.3");
|
||||
isc_sockaddr_fromin(&addr2, &in, 5150);
|
||||
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
/*
|
||||
* We require multiple unreachableadd calls to mark a server as
|
||||
* unreachable.
|
||||
*/
|
||||
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
||||
dns_zonemgr_unreachableadd(myzonemgr, &addr1, &addr2, &now);
|
||||
ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
|
||||
dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
|
||||
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
|
||||
in.s_addr = inet_addr("10.53.0.2");
|
||||
isc_sockaddr_fromin(&addr2, &in, 5150);
|
||||
ATF_CHECK(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
assert_true(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
dns_zonemgr_unreachabledel(myzonemgr, &addr1, &addr2);
|
||||
ATF_CHECK(! dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
assert_false(dns_zonemgr_unreachable(myzonemgr, &addr1, &addr2, &now));
|
||||
|
||||
dns_zonemgr_releasezone(myzonemgr, zone);
|
||||
dns_zone_detach(&zone);
|
||||
dns_zonemgr_shutdown(myzonemgr);
|
||||
dns_zonemgr_detach(&myzonemgr);
|
||||
ATF_REQUIRE_EQ(myzonemgr, NULL);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, zonemgr_create);
|
||||
ATF_TP_ADD_TC(tp, zonemgr_managezone);
|
||||
ATF_TP_ADD_TC(tp, zonemgr_createzone);
|
||||
ATF_TP_ADD_TC(tp, zonemgr_unreachable);
|
||||
return (atf_no_error());
|
||||
assert_null(myzonemgr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -251,3 +235,31 @@ ATF_TP_ADD_TCS(tp) {
|
|||
* - dns_zonemgr_setserialqueryrate
|
||||
* - dns_zonemgr_getserialqueryrate
|
||||
*/
|
||||
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(zonemgr_create,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(zonemgr_managezone,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(zonemgr_createzone,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(zonemgr_unreachable,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,20 +9,28 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/timer.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/db.h>
|
||||
#include <dns/name.h>
|
||||
|
|
@ -38,9 +46,27 @@ struct args {
|
|||
bool arg3;
|
||||
};
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
count_zone(dns_zone_t *zone, void *uap) {
|
||||
int *nzones = (int *)uap;
|
||||
|
|
@ -94,55 +120,43 @@ start_zone_asyncload(isc_task_t *task, isc_event_t *event) {
|
|||
isc_event_free(&event);
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
ATF_TC(apply);
|
||||
ATF_TC_HEAD(apply, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "apply a function to a zone table");
|
||||
}
|
||||
ATF_TC_BODY(apply, tc) {
|
||||
/* apply a function to a zone table */
|
||||
static void
|
||||
apply(void **state) {
|
||||
isc_result_t result;
|
||||
dns_zone_t *zone = NULL;
|
||||
dns_view_t *view = NULL;
|
||||
int nzones = 0;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_makezone("foo", &zone, NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
view = dns_zone_getview(zone);
|
||||
ATF_REQUIRE(view->zonetable != NULL);
|
||||
assert_non_null(view->zonetable);
|
||||
|
||||
ATF_CHECK_EQ(0, nzones);
|
||||
assert_int_equal(nzones, 0);
|
||||
result = dns_zt_apply(view->zonetable, false, count_zone, &nzones);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ(1, nzones);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(nzones, 1);
|
||||
|
||||
/* These steps are necessary so the zone can be detached properly */
|
||||
result = dns_test_setupzonemgr();
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_test_managezone(zone);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_test_releasezone(zone);
|
||||
dns_test_closezonemgr();
|
||||
|
||||
/* The view was left attached in dns_test_makezone() */
|
||||
dns_view_detach(&view);
|
||||
dns_zone_detach(&zone);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(asyncload_zone);
|
||||
ATF_TC_HEAD(asyncload_zone, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "asynchronous zone load");
|
||||
}
|
||||
ATF_TC_BODY(asyncload_zone, tc) {
|
||||
/* asynchronous zone load */
|
||||
static void
|
||||
asyncload_zone(void **state) {
|
||||
isc_result_t result;
|
||||
int n;
|
||||
dns_zone_t *zone = NULL;
|
||||
|
|
@ -154,28 +168,25 @@ ATF_TC_BODY(asyncload_zone, tc) {
|
|||
int i = 0;
|
||||
struct args args;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_makezone("foo", &zone, NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_setupzonemgr();
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_test_managezone(zone);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
view = dns_zone_getview(zone);
|
||||
ATF_REQUIRE(view->zonetable != NULL);
|
||||
assert_non_null(view->zonetable);
|
||||
|
||||
ATF_CHECK(!dns__zone_loadpending(zone));
|
||||
ATF_CHECK(!done);
|
||||
assert_false(dns__zone_loadpending(zone));
|
||||
assert_false(done);
|
||||
zonefile = fopen("./zone.data", "wb");
|
||||
ATF_CHECK(zonefile != NULL);
|
||||
assert_non_null(zonefile);
|
||||
origfile = fopen("./testdata/zt/zone1.db", "r+b");
|
||||
ATF_CHECK(origfile != NULL);
|
||||
assert_non_null(origfile);
|
||||
n = fread(buf, 1, 4096, origfile);
|
||||
fclose(origfile);
|
||||
fwrite(buf, 1, n, zonefile);
|
||||
|
|
@ -191,10 +202,10 @@ ATF_TC_BODY(asyncload_zone, tc) {
|
|||
isc_app_run();
|
||||
while (dns__zone_loadpending(zone) && i++ < 5000)
|
||||
dns_test_nap(1000);
|
||||
ATF_CHECK(done);
|
||||
assert_true(done);
|
||||
/* The zone should now be loaded; test it */
|
||||
result = dns_zone_getdb(zone, &db);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_db_detach(&db);
|
||||
/*
|
||||
* Add something to zone file, reload zone with newonly - it should
|
||||
|
|
@ -213,10 +224,10 @@ ATF_TC_BODY(asyncload_zone, tc) {
|
|||
|
||||
while (dns__zone_loadpending(zone) && i++ < 5000)
|
||||
dns_test_nap(1000);
|
||||
ATF_CHECK(done);
|
||||
assert_true(done);
|
||||
/* The zone should now be loaded; test it */
|
||||
result = dns_zone_getdb(zone, &db);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_db_detach(&db);
|
||||
|
||||
/* Now reload it without newonly - it should be reloaded */
|
||||
|
|
@ -229,12 +240,12 @@ ATF_TC_BODY(asyncload_zone, tc) {
|
|||
|
||||
while (dns__zone_loadpending(zone) && i++ < 5000)
|
||||
dns_test_nap(1000);
|
||||
ATF_CHECK(done);
|
||||
assert_true(done);
|
||||
/* The zone should now be loaded; test it */
|
||||
result = dns_zone_getdb(zone, &db);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK(db != NULL);
|
||||
assert_non_null(db);
|
||||
if (db != NULL)
|
||||
dns_db_detach(&db);
|
||||
|
||||
|
|
@ -243,15 +254,11 @@ ATF_TC_BODY(asyncload_zone, tc) {
|
|||
|
||||
dns_zone_detach(&zone);
|
||||
dns_view_detach(&view);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(asyncload_zt);
|
||||
ATF_TC_HEAD(asyncload_zt, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "asynchronous zone table load");
|
||||
}
|
||||
ATF_TC_BODY(asyncload_zt, tc) {
|
||||
/* asynchronous zone table load */
|
||||
static void
|
||||
asyncload_zt(void **state) {
|
||||
isc_result_t result;
|
||||
dns_zone_t *zone1 = NULL, *zone2 = NULL, *zone3 = NULL;
|
||||
dns_view_t *view;
|
||||
|
|
@ -261,40 +268,37 @@ ATF_TC_BODY(asyncload_zt, tc) {
|
|||
int i = 0;
|
||||
struct args args;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_makezone("foo", &zone1, NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_zone_setfile(zone1, "testdata/zt/zone1.db");
|
||||
view = dns_zone_getview(zone1);
|
||||
|
||||
result = dns_test_makezone("bar", &zone2, view, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_zone_setfile(zone2, "testdata/zt/zone1.db");
|
||||
|
||||
/* This one will fail to load */
|
||||
result = dns_test_makezone("fake", &zone3, view, false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
dns_zone_setfile(zone3, "testdata/zt/nonexistent.db");
|
||||
|
||||
zt = view->zonetable;
|
||||
ATF_REQUIRE(zt != NULL);
|
||||
assert_non_null(zt);
|
||||
|
||||
result = dns_test_setupzonemgr();
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_test_managezone(zone1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_test_managezone(zone2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = dns_test_managezone(zone3);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK(!dns__zone_loadpending(zone1));
|
||||
ATF_CHECK(!dns__zone_loadpending(zone2));
|
||||
ATF_CHECK(!done);
|
||||
assert_false(dns__zone_loadpending(zone1));
|
||||
assert_false(dns__zone_loadpending(zone2));
|
||||
assert_false(done);
|
||||
|
||||
args.arg1 = zt;
|
||||
args.arg2 = &done;
|
||||
|
|
@ -303,18 +307,18 @@ ATF_TC_BODY(asyncload_zt, tc) {
|
|||
isc_app_run();
|
||||
while (!done && i++ < 5000)
|
||||
dns_test_nap(1000);
|
||||
ATF_CHECK(done);
|
||||
assert_true(done);
|
||||
|
||||
/* Both zones should now be loaded; test them */
|
||||
result = dns_zone_getdb(zone1, &db);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(db != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(db);
|
||||
if (db != NULL)
|
||||
dns_db_detach(&db);
|
||||
|
||||
result = dns_zone_getdb(zone2, &db);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(db != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(db);
|
||||
if (db != NULL)
|
||||
dns_db_detach(&db);
|
||||
|
||||
|
|
@ -327,16 +331,29 @@ ATF_TC_BODY(asyncload_zt, tc) {
|
|||
dns_zone_detach(&zone2);
|
||||
dns_zone_detach(&zone3);
|
||||
dns_view_detach(&view);
|
||||
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, apply);
|
||||
ATF_TP_ADD_TC(tp, asyncload_zone);
|
||||
ATF_TP_ADD_TC(tp, asyncload_zt);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(apply, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(asyncload_zone,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(asyncload_zt,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, dns_test_init, dns_test_final));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: tests
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: resconf_test
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
syntax(2)
|
||||
test_suite('bind9')
|
||||
|
||||
atf_test_program{name='resconf_test'}
|
||||
tap_test_program{name='resconf_test'}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ srcdir = @srcdir@
|
|||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
# Attempt to disable parallel processing.
|
||||
.NOTPARALLEL:
|
||||
.NO_PARALLEL:
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
@BIND9_MAKE_INCLUDES@
|
||||
|
|
@ -31,7 +27,8 @@ ISCDEPLIBS = ../../isc/libisc.@A@
|
|||
IRSLIBS = ../libirs.@A@
|
||||
IRSDEPLIBS = ../libirs.@A@
|
||||
|
||||
LIBS = ${IRSLIBS} ${CFGLIBS} ${DNSLIBS} ${ISCLIBS} @LIBS@ @ATFLIBS@
|
||||
CFLAGS = @CFLAGS@ @CMOCKA_CFLAGS@
|
||||
LIBS = ${IRSLIBS} ${CFGLIBS} ${DNSLIBS} ${ISCLIBS} @LIBS@ @CMOCKA_LIBS@
|
||||
|
||||
OBJS =
|
||||
SRCS = resconf_test.c
|
||||
|
|
@ -42,8 +39,8 @@ TARGETS = resconf_test@EXEEXT@
|
|||
@BIND9_MAKE_RULES@
|
||||
|
||||
resconf_test@EXEEXT@: resconf_test.@O@ ${CFGDEPLIBS} ${DNSDEPLIBS} ${IRSDEPLIBS} ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
resconf_test.@O@ ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ resconf_test.@O@ ${LIBS}
|
||||
|
||||
unit::
|
||||
sh ${top_builddir}/unit/unittest.sh
|
||||
|
|
|
|||
|
|
@ -11,14 +11,22 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/mem.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <irs/types.h>
|
||||
|
|
@ -31,21 +39,19 @@ setup_test() {
|
|||
isc_result_t result;
|
||||
|
||||
result = isc_mem_create(0, 0, &mctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* atf-run changes us to a /tmp directory, so tests
|
||||
* the caller might run from another directory, but tests
|
||||
* that access test data files must first chdir to the proper
|
||||
* location.
|
||||
*/
|
||||
ATF_REQUIRE(chdir(TESTS) != -1);
|
||||
assert_return_code(chdir(TESTS), 0);
|
||||
}
|
||||
|
||||
ATF_TC(irs_resconf_load);
|
||||
ATF_TC_HEAD(irs_resconf_load, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "irs_resconf_load");
|
||||
}
|
||||
ATF_TC_BODY(irs_resconf_load, tc) {
|
||||
/* test irs_resconf_load() */
|
||||
static void
|
||||
irs_resconf_load_test(void **state) {
|
||||
isc_result_t result;
|
||||
irs_resconf_t *resconf = NULL;
|
||||
unsigned int i;
|
||||
|
|
@ -107,33 +113,58 @@ ATF_TC_BODY(irs_resconf_load, tc) {
|
|||
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
setup_test();
|
||||
|
||||
for (i = 0; i < sizeof(tests)/sizeof(tests[1]); i++) {
|
||||
result = irs_resconf_load(mctx, tests[i].file, &resconf);
|
||||
ATF_CHECK_EQ_MSG(result, tests[i].loadres, "%s", tests[i].file);
|
||||
if (result == ISC_R_SUCCESS)
|
||||
ATF_CHECK_MSG(resconf != NULL, "%s", tests[i].file);
|
||||
else
|
||||
ATF_CHECK_MSG(resconf == NULL, "%s", tests[i].file);
|
||||
if (result != tests[i].loadres) {
|
||||
fail_msg("# unexpected result %s loading %s",
|
||||
isc_result_totext(result), tests[i].file);
|
||||
}
|
||||
|
||||
if (result == ISC_R_SUCCESS && resconf == NULL) {
|
||||
fail_msg("# NULL on success loading %s",
|
||||
tests[i].file);
|
||||
} else if (result != ISC_R_SUCCESS && resconf != NULL) {
|
||||
fail_msg("# non-NULL on failure loading %s",
|
||||
tests[i].file);
|
||||
}
|
||||
|
||||
if (resconf != NULL && tests[i].check != NULL) {
|
||||
result = (tests[i].check)(resconf);
|
||||
ATF_CHECK_EQ_MSG(result, tests[i].checkres, "%s",
|
||||
if (result != tests[i].checkres) {
|
||||
fail_msg("# unexpected result %s loading %s",
|
||||
isc_result_totext(result),
|
||||
tests[i].file);
|
||||
}
|
||||
}
|
||||
if (resconf != NULL)
|
||||
if (resconf != NULL) {
|
||||
irs_resconf_destroy(&resconf);
|
||||
}
|
||||
}
|
||||
|
||||
isc_mem_detach(&mctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, irs_resconf_load);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(irs_resconf_load_test),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: tests
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: aes_test
|
||||
tp: atomic_test
|
||||
tp: buffer_test
|
||||
tp: counter_test
|
||||
tp: errno_test
|
||||
tp: file_test
|
||||
tp: hash_test
|
||||
tp: heap_test
|
||||
tp: ht_test
|
||||
tp: inet_ntop_test
|
||||
tp: lex_test
|
||||
tp: mem_test
|
||||
tp: netaddr_test
|
||||
tp: parse_test
|
||||
tp: pool_test
|
||||
tp: print_test
|
||||
tp: queue_test
|
||||
tp: radix_test
|
||||
tp: random_test
|
||||
tp: regex_test
|
||||
tp: safe_test
|
||||
tp: sockaddr_test
|
||||
tp: socket_test
|
||||
tp: symtab_test
|
||||
tp: task_test
|
||||
tp: taskpool_test
|
||||
tp: time_test
|
||||
tp: timer_test
|
||||
|
|
@ -1,32 +1,32 @@
|
|||
syntax(2)
|
||||
test_suite('bind9')
|
||||
|
||||
atf_test_program{name='aes_test'}
|
||||
atf_test_program{name='atomic_test'}
|
||||
atf_test_program{name='buffer_test'}
|
||||
atf_test_program{name='counter_test'}
|
||||
atf_test_program{name='errno_test'}
|
||||
atf_test_program{name='file_test'}
|
||||
atf_test_program{name='hash_test'}
|
||||
atf_test_program{name='heap_test'}
|
||||
atf_test_program{name='ht_test'}
|
||||
atf_test_program{name='inet_ntop_test'}
|
||||
atf_test_program{name='lex_test'}
|
||||
atf_test_program{name='mem_test'}
|
||||
atf_test_program{name='netaddr_test'}
|
||||
atf_test_program{name='parse_test'}
|
||||
atf_test_program{name='pool_test'}
|
||||
atf_test_program{name='print_test'}
|
||||
atf_test_program{name='queue_test'}
|
||||
atf_test_program{name='radix_test'}
|
||||
atf_test_program{name='random_test'}
|
||||
atf_test_program{name='regex_test'}
|
||||
tap_test_program{name='aes_test'}
|
||||
tap_test_program{name='atomic_test'}
|
||||
tap_test_program{name='buffer_test'}
|
||||
tap_test_program{name='counter_test'}
|
||||
tap_test_program{name='errno_test'}
|
||||
tap_test_program{name='file_test'}
|
||||
tap_test_program{name='hash_test'}
|
||||
tap_test_program{name='heap_test'}
|
||||
tap_test_program{name='ht_test'}
|
||||
tap_test_program{name='inet_ntop_test'}
|
||||
tap_test_program{name='lex_test'}
|
||||
tap_test_program{name='mem_test'}
|
||||
tap_test_program{name='netaddr_test'}
|
||||
tap_test_program{name='parse_test'}
|
||||
tap_test_program{name='pool_test'}
|
||||
tap_test_program{name='print_test'}
|
||||
tap_test_program{name='queue_test'}
|
||||
tap_test_program{name='radix_test'}
|
||||
tap_test_program{name='random_test'}
|
||||
tap_test_program{name='regex_test'}
|
||||
tap_test_program{name='result_test'}
|
||||
atf_test_program{name='safe_test'}
|
||||
atf_test_program{name='sockaddr_test'}
|
||||
atf_test_program{name='socket_test'}
|
||||
atf_test_program{name='symtab_test'}
|
||||
atf_test_program{name='task_test'}
|
||||
atf_test_program{name='taskpool_test'}
|
||||
atf_test_program{name='time_test'}
|
||||
atf_test_program{name='timer_test'}
|
||||
tap_test_program{name='safe_test'}
|
||||
tap_test_program{name='sockaddr_test'}
|
||||
tap_test_program{name='socket_test'}
|
||||
tap_test_program{name='symtab_test'}
|
||||
tap_test_program{name='task_test'}
|
||||
tap_test_program{name='taskpool_test'}
|
||||
tap_test_program{name='time_test'}
|
||||
tap_test_program{name='timer_test'}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ srcdir = @srcdir@
|
|||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
# Attempt to disable parallel processing.
|
||||
.NOTPARALLEL:
|
||||
.NO_PARALLEL:
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
@BIND9_MAKE_INCLUDES@
|
||||
|
|
@ -25,10 +21,8 @@ CDEFINES = @CRYPTO@ -DTESTS="\"${top_builddir}/lib/isc/tests/\""
|
|||
ISCLIBS = ../libisc.@A@ @ISC_OPENSSL_LIBS@
|
||||
ISCDEPLIBS = ../libisc.@A@
|
||||
|
||||
LIBS = @LIBS@ @ATFLIBS@
|
||||
|
||||
CMOCKA_CFLAGS = @CMOCKA_CFLAGS@
|
||||
CMOCKA_LIBS = @CMOCKA_LIBS@
|
||||
LIBS = @LIBS@ @CMOCKA_LIBS@
|
||||
CFLAGS = @CFLAGS@ @CMOCKA_CFLAGS@
|
||||
|
||||
OBJS = isctest.@O@
|
||||
SRCS = isctest.c aes_test.c atomic_test.c buffer_test.c \
|
||||
|
|
@ -55,123 +49,151 @@ TARGETS = aes_test@EXEEXT@ atomic_test@EXEEXT@ buffer_test@EXEEXT@ \
|
|||
@BIND9_MAKE_RULES@
|
||||
|
||||
atomic_test@EXEEXT@: atomic_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
atomic_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ atomic_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
aes_test@EXEEXT@: aes_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
aes_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ aes_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
buffer_test@EXEEXT@: buffer_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
buffer_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ buffer_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
counter_test@EXEEXT@: counter_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
counter_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ counter_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
errno_test@EXEEXT@: errno_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
errno_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ errno_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
file_test@EXEEXT@: file_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
file_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ file_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
hash_test@EXEEXT@: hash_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
hash_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ hash_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
heap_test@EXEEXT@: heap_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
heap_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ heap_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
ht_test@EXEEXT@: ht_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
ht_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ ht_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
inet_ntop_test.c.@O@: ${top_srcdir}/lib/isc/ntop_test.c
|
||||
inet_ntop_test@EXEEXT@: inet_ntop_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
inet_ntop_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ inet_ntop_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
lex_test@EXEEXT@: lex_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
lex_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ lex_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
mem_test@EXEEXT@: mem_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ mem_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
netaddr_test@EXEEXT@: netaddr_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ netaddr_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
parse_test@EXEEXT@: parse_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
parse_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ parse_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
pool_test@EXEEXT@: pool_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
pool_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ pool_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
print_test.@O@: ${top_srcdir}/lib/isc/print.c
|
||||
print_test@EXEEXT@: print_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
print_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ print_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
queue_test@EXEEXT@: queue_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
queue_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ queue_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
radix_test@EXEEXT@: radix_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
radix_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ radix_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
random_test@EXEEXT@: random_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
random_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ random_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS} -lm
|
||||
|
||||
regex_test@EXEEXT@: regex_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
regex_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
|
||||
mem_test@EXEEXT@: mem_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
mem_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
|
||||
netaddr_test@EXEEXT@: netaddr_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
netaddr_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ regex_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
result_test@EXEEXT@: result_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ result_test.@O@ \
|
||||
${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
safe_test@EXEEXT@: safe_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
safe_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
|
||||
sockaddr_test@EXEEXT@: sockaddr_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
sockaddr_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ safe_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
socket_test@EXEEXT@: socket_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
socket_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ socket_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
sockaddr_test@EXEEXT@: sockaddr_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ sockaddr_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
symtab_test@EXEEXT@: symtab_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
symtab_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ symtab_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
task_test@EXEEXT@: task_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
task_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ task_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
taskpool_test@EXEEXT@: taskpool_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
taskpool_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ taskpool_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
time_test@EXEEXT@: time_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
time_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ time_test.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
timer_test@EXEEXT@: timer_test.@O@ isctest.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
timer_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ timer_test.@O@ isctest.@O@ \
|
||||
${ISCLIBS} ${LIBS}
|
||||
|
||||
unit::
|
||||
sh ${top_builddir}/unit/unittest.sh
|
||||
|
|
|
|||
|
|
@ -9,20 +9,25 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/aes.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/hex.h>
|
||||
#include <isc/platform.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/region.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
|
|
@ -57,15 +62,15 @@ tohexstr(unsigned char *d, char *out) {
|
|||
}
|
||||
|
||||
size_t
|
||||
fromhexstr(const char *in, unsigned char *d)
|
||||
{
|
||||
fromhexstr(const char *in, unsigned char *d) {
|
||||
isc_buffer_t b;
|
||||
isc_result_t ret;
|
||||
|
||||
isc_buffer_init(&b, d, ISC_AES256_KEYLENGTH + 1);
|
||||
ret = isc_hex_decodestring(in, &b);
|
||||
if (ret != ISC_R_SUCCESS)
|
||||
return 0;
|
||||
if (ret != ISC_R_SUCCESS) {
|
||||
return (0);
|
||||
}
|
||||
return isc_buffer_usedlength(&b);
|
||||
}
|
||||
|
||||
|
|
@ -75,14 +80,9 @@ typedef struct aes_testcase {
|
|||
const char *result;
|
||||
} aes_testcase_t;
|
||||
|
||||
|
||||
ATF_TC(isc_aes128);
|
||||
ATF_TC_HEAD(isc_aes128, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "AES 128 test vectors");
|
||||
}
|
||||
ATF_TC_BODY(isc_aes128, tc) {
|
||||
UNUSED(tc);
|
||||
|
||||
/* AES 128 test vectors */
|
||||
static void
|
||||
isc_aes128_test(void **state) {
|
||||
aes_testcase_t testcases[] = {
|
||||
/* Test 1 (KAT ECBVarTxt128 #3) */
|
||||
{
|
||||
|
|
@ -125,26 +125,24 @@ ATF_TC_BODY(isc_aes128, tc) {
|
|||
|
||||
aes_testcase_t *testcase = testcases;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
while (testcase->key != NULL) {
|
||||
len = fromhexstr(testcase->key, key);
|
||||
ATF_CHECK_EQ(len, ISC_AES128_KEYLENGTH);
|
||||
assert_int_equal(len, ISC_AES128_KEYLENGTH);
|
||||
len = fromhexstr(testcase->input, plaintext);
|
||||
ATF_CHECK_EQ(len, ISC_AES_BLOCK_LENGTH);
|
||||
assert_int_equal(len, ISC_AES_BLOCK_LENGTH);
|
||||
isc_aes128_crypt(key, plaintext, ciphertext);
|
||||
ATF_CHECK(tohexstr(ciphertext, str) == ISC_R_SUCCESS);
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_int_equal(tohexstr(ciphertext, str), ISC_R_SUCCESS);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(isc_aes192);
|
||||
ATF_TC_HEAD(isc_aes192, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "AES 192 test vectors");
|
||||
}
|
||||
ATF_TC_BODY(isc_aes192, tc) {
|
||||
UNUSED(tc);
|
||||
|
||||
/* AES 192 test vectors */
|
||||
static void
|
||||
isc_aes192_test(void **state) {
|
||||
aes_testcase_t testcases[] = {
|
||||
/* Test 1 (KAT ECBVarTxt192 #3) */
|
||||
{
|
||||
|
|
@ -187,26 +185,24 @@ ATF_TC_BODY(isc_aes192, tc) {
|
|||
|
||||
aes_testcase_t *testcase = testcases;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
while (testcase->key != NULL) {
|
||||
len = fromhexstr(testcase->key, key);
|
||||
ATF_CHECK_EQ(len, ISC_AES192_KEYLENGTH);
|
||||
assert_int_equal(len, ISC_AES192_KEYLENGTH);
|
||||
len = fromhexstr(testcase->input, plaintext);
|
||||
ATF_CHECK_EQ(len, ISC_AES_BLOCK_LENGTH);
|
||||
assert_int_equal(len, ISC_AES_BLOCK_LENGTH);
|
||||
isc_aes192_crypt(key, plaintext, ciphertext);
|
||||
ATF_CHECK(tohexstr(ciphertext, str) == ISC_R_SUCCESS);
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_int_equal(tohexstr(ciphertext, str), ISC_R_SUCCESS);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(isc_aes256);
|
||||
ATF_TC_HEAD(isc_aes256, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "AES 256 test vectors");
|
||||
}
|
||||
ATF_TC_BODY(isc_aes256, tc) {
|
||||
UNUSED(tc);
|
||||
|
||||
/* AES 256 test vectors */
|
||||
static void
|
||||
isc_aes256_test(void **state) {
|
||||
aes_testcase_t testcases[] = {
|
||||
/* Test 1 (KAT ECBVarTxt256 #3) */
|
||||
{
|
||||
|
|
@ -255,40 +251,46 @@ ATF_TC_BODY(isc_aes256, tc) {
|
|||
|
||||
aes_testcase_t *testcase = testcases;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
while (testcase->key != NULL) {
|
||||
len = fromhexstr(testcase->key, key);
|
||||
ATF_CHECK_EQ(len, ISC_AES256_KEYLENGTH);
|
||||
assert_int_equal(len, ISC_AES256_KEYLENGTH);
|
||||
len = fromhexstr(testcase->input, plaintext);
|
||||
ATF_CHECK_EQ(len, ISC_AES_BLOCK_LENGTH);
|
||||
assert_int_equal(len, ISC_AES_BLOCK_LENGTH);
|
||||
isc_aes256_crypt(key, plaintext, ciphertext);
|
||||
ATF_CHECK(tohexstr(ciphertext, str) == ISC_R_SUCCESS);
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_int_equal(tohexstr(ciphertext, str), ISC_R_SUCCESS);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
}
|
||||
}
|
||||
#else
|
||||
ATF_TC(untested);
|
||||
ATF_TC_HEAD(untested, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "skipping aes test");
|
||||
}
|
||||
ATF_TC_BODY(untested, tc) {
|
||||
UNUSED(tc);
|
||||
atf_tc_skip("AES not available");
|
||||
}
|
||||
#endif
|
||||
#endif /* ISC_PLATFORM_WANTAES */
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
int
|
||||
main(void) {
|
||||
#ifdef ISC_PLATFORM_WANTAES
|
||||
ATF_TP_ADD_TC(tp, isc_aes128);
|
||||
ATF_TP_ADD_TC(tp, isc_aes192);
|
||||
ATF_TP_ADD_TC(tp, isc_aes256);
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(isc_aes128_test),
|
||||
cmocka_unit_test(isc_aes192_test),
|
||||
cmocka_unit_test(isc_aes256_test),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
#else
|
||||
ATF_TP_ADD_TC(tp, untested);
|
||||
#endif
|
||||
return (atf_no_error());
|
||||
print_message("1..0 # Skipped: AES disabled");
|
||||
#endif /* ISC_PLATFORM_WANTAES */
|
||||
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,14 +11,23 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <isc/atomic.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
|
|
@ -35,6 +44,23 @@ typedef struct {
|
|||
|
||||
counter_t counters[TASKS];
|
||||
|
||||
#if defined(ISC_PLATFORM_HAVEXADD) || \
|
||||
defined(ISC_PLATFORM_HAVEXADDQ) || \
|
||||
defined(ISC_PLATFORM_HAVEATOMICSTORE) || \
|
||||
defined(ISC_PLATFORM_HAVEATOMICSTOREQ)
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ISC_PLATFORM_HAVEXADD)
|
||||
static int32_t counter_32;
|
||||
|
||||
|
|
@ -55,20 +81,14 @@ do_xadd(isc_task_t *task, isc_event_t *ev) {
|
|||
}
|
||||
}
|
||||
|
||||
ATF_TC(atomic_xadd);
|
||||
ATF_TC_HEAD(atomic_xadd, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "atomic XADD");
|
||||
}
|
||||
ATF_TC_BODY(atomic_xadd, tc) {
|
||||
isc_result_t result;
|
||||
/* Atomic XADD */
|
||||
static void
|
||||
atomic_xadd(void **state) {
|
||||
isc_task_t *tasks[TASKS];
|
||||
isc_event_t *event = NULL;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
memset(counters, 0, sizeof(counters));
|
||||
counter_32 = 0;
|
||||
|
|
@ -78,21 +98,18 @@ ATF_TC_BODY(atomic_xadd, tc) {
|
|||
*/
|
||||
for (i = 0 ; i < TASKS ; i++) {
|
||||
tasks[i] = NULL;
|
||||
ATF_REQUIRE_EQ(isc_task_create(taskmgr, 0, &tasks[i]),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_task_create(taskmgr, 0, &tasks[i]),
|
||||
ISC_R_SUCCESS);
|
||||
event = isc_event_allocate(mctx, NULL, 1000, do_xadd,
|
||||
&counters[i],
|
||||
sizeof(struct isc_event));
|
||||
ATF_REQUIRE(event != NULL);
|
||||
assert_non_null(event);
|
||||
isc_task_sendanddetach(&tasks[i], &event);
|
||||
}
|
||||
|
||||
isc_test_end();
|
||||
|
||||
printf("32-bit counter %d, expected %d\n",
|
||||
counter_32, EXPECTED_COUNT_32);
|
||||
|
||||
ATF_CHECK_EQ(counter_32, EXPECTED_COUNT_32);
|
||||
assert_int_equal(counter_32, EXPECTED_COUNT_32);
|
||||
counter_32 = 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -117,20 +134,14 @@ do_xaddq(isc_task_t *task, isc_event_t *ev) {
|
|||
}
|
||||
}
|
||||
|
||||
ATF_TC(atomic_xaddq);
|
||||
ATF_TC_HEAD(atomic_xaddq, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "atomic XADDQ");
|
||||
}
|
||||
ATF_TC_BODY(atomic_xaddq, tc) {
|
||||
isc_result_t result;
|
||||
/* Atomic XADDQ */
|
||||
static void
|
||||
atomic_xaddq(void **state) {
|
||||
isc_task_t *tasks[TASKS];
|
||||
isc_event_t *event = NULL;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
memset(counters, 0, sizeof(counters));
|
||||
counter_64 = 0;
|
||||
|
|
@ -140,22 +151,18 @@ ATF_TC_BODY(atomic_xaddq, tc) {
|
|||
*/
|
||||
for (i = 0 ; i < TASKS ; i++) {
|
||||
tasks[i] = NULL;
|
||||
ATF_REQUIRE_EQ(isc_task_create(taskmgr, 0, &tasks[i]),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_task_create(taskmgr, 0, &tasks[i]),
|
||||
ISC_R_SUCCESS);
|
||||
event = isc_event_allocate(mctx, NULL, 1000, do_xaddq,
|
||||
&counters[i],
|
||||
sizeof(struct isc_event));
|
||||
ATF_REQUIRE(event != NULL);
|
||||
assert_non_null(event);
|
||||
isc_task_sendanddetach(&tasks[i], &event);
|
||||
}
|
||||
|
||||
isc_test_end();
|
||||
|
||||
printf("64-bit counter %" PRId64 ", "
|
||||
"expected %" PRId64 "\n",
|
||||
counter_64, EXPECTED_COUNT_64);
|
||||
|
||||
ATF_CHECK_EQ(counter_64, EXPECTED_COUNT_64);
|
||||
assert_int_equal(counter_64, EXPECTED_COUNT_64);
|
||||
counter_32 = 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -185,22 +192,16 @@ do_store(isc_task_t *task, isc_event_t *ev) {
|
|||
}
|
||||
}
|
||||
|
||||
ATF_TC(atomic_store);
|
||||
ATF_TC_HEAD(atomic_store, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "atomic STORE");
|
||||
}
|
||||
ATF_TC_BODY(atomic_store, tc) {
|
||||
isc_result_t result;
|
||||
/* Atomic STORE */
|
||||
static void
|
||||
atomic_store(void **state) {
|
||||
isc_task_t *tasks[TASKS];
|
||||
isc_event_t *event = NULL;
|
||||
uint32_t val;
|
||||
uint32_t r;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
memset(counters, 0, sizeof(counters));
|
||||
store_32 = 0;
|
||||
|
|
@ -211,12 +212,12 @@ ATF_TC_BODY(atomic_store, tc) {
|
|||
*/
|
||||
for (i = 0 ; i < TASKS ; i++) {
|
||||
tasks[i] = NULL;
|
||||
ATF_REQUIRE_EQ(isc_task_create(taskmgr, 0, &tasks[i]),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_task_create(taskmgr, 0, &tasks[i]),
|
||||
ISC_R_SUCCESS);
|
||||
event = isc_event_allocate(mctx, NULL, 1000, do_store,
|
||||
&counters[i],
|
||||
sizeof(struct isc_event));
|
||||
ATF_REQUIRE(event != NULL);
|
||||
assert_non_null(event);
|
||||
isc_task_sendanddetach(&tasks[i], &event);
|
||||
}
|
||||
|
||||
|
|
@ -225,10 +226,7 @@ ATF_TC_BODY(atomic_store, tc) {
|
|||
r = store_32 & 0xff;
|
||||
val = (r << 24) | (r << 16) | (r << 8) | r;
|
||||
|
||||
printf("32-bit store 0x%x, expected 0x%x\n",
|
||||
(uint32_t) store_32, val);
|
||||
|
||||
ATF_CHECK_EQ((uint32_t) store_32, val);
|
||||
assert_int_equal((uint32_t) store_32, val);
|
||||
store_32 = 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -262,22 +260,16 @@ do_storeq(isc_task_t *task, isc_event_t *ev) {
|
|||
}
|
||||
}
|
||||
|
||||
ATF_TC(atomic_storeq);
|
||||
ATF_TC_HEAD(atomic_storeq, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "atomic STOREQ");
|
||||
}
|
||||
ATF_TC_BODY(atomic_storeq, tc) {
|
||||
isc_result_t result;
|
||||
/* Atomic STOREQ */
|
||||
static void
|
||||
atomic_storeq(void **state) {
|
||||
isc_task_t *tasks[TASKS];
|
||||
isc_event_t *event = NULL;
|
||||
uint64_t val;
|
||||
uint32_t r;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
memset(counters, 0, sizeof(counters));
|
||||
store_64 = 0;
|
||||
|
|
@ -288,12 +280,12 @@ ATF_TC_BODY(atomic_storeq, tc) {
|
|||
*/
|
||||
for (i = 0 ; i < TASKS ; i++) {
|
||||
tasks[i] = NULL;
|
||||
ATF_REQUIRE_EQ(isc_task_create(taskmgr, 0, &tasks[i]),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_task_create(taskmgr, 0, &tasks[i]),
|
||||
ISC_R_SUCCESS);
|
||||
event = isc_event_allocate(mctx, NULL, 1000, do_storeq,
|
||||
&counters[i],
|
||||
sizeof(struct isc_event));
|
||||
ATF_REQUIRE(event != NULL);
|
||||
assert_non_null(event);
|
||||
isc_task_sendanddetach(&tasks[i], &event);
|
||||
}
|
||||
|
||||
|
|
@ -306,49 +298,46 @@ ATF_TC_BODY(atomic_storeq, tc) {
|
|||
(uint64_t) r);
|
||||
val |= ((uint64_t) val << 32);
|
||||
|
||||
printf("64-bit store 0x%" PRIx64 ", "
|
||||
"expected 0x%" PRIx64 "\n",
|
||||
(uint64_t) store_64, val);
|
||||
|
||||
ATF_CHECK_EQ((uint64_t) store_64, val);
|
||||
assert_int_equal((uint64_t) store_64, val);
|
||||
store_64 = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(ISC_PLATFORM_HAVEXADD) && \
|
||||
!defined(ISC_PLATFORM_HAVEXADDQ) && \
|
||||
!defined(ISC_PLATFORM_HAVEATOMICSTOREQ)
|
||||
ATF_TC(untested);
|
||||
ATF_TC_HEAD(untested, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "skipping aes test");
|
||||
}
|
||||
ATF_TC_BODY(untested, tc) {
|
||||
UNUSED(tc);
|
||||
atf_tc_skip("AES not available");
|
||||
}
|
||||
#endif /* !HAVEXADD, !HAVEXADDQ, !HAVEATOMICSTOREQ */
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
int
|
||||
main(void) {
|
||||
#if defined(ISC_PLATFORM_HAVEXADD) || \
|
||||
defined(ISC_PLATFORM_HAVEXADDQ) || \
|
||||
defined(ISC_PLATFORM_HAVEATOMICSTORE) || \
|
||||
defined(ISC_PLATFORM_HAVEATOMICSTOREQ)
|
||||
const struct CMUnitTest tests[] = {
|
||||
#if defined(ISC_PLATFORM_HAVEXADD)
|
||||
ATF_TP_ADD_TC(tp, atomic_xadd);
|
||||
cmocka_unit_test_setup(atomic_xadd, _setup),
|
||||
#endif
|
||||
#if defined(ISC_PLATFORM_HAVEXADDQ)
|
||||
ATF_TP_ADD_TC(tp, atomic_xaddq);
|
||||
cmocka_unit_test_setup(atomic_xaddq, _setup),
|
||||
#endif
|
||||
#ifdef ISC_PLATFORM_HAVEATOMICSTORE
|
||||
ATF_TP_ADD_TC(tp, atomic_store);
|
||||
cmocka_unit_test_setup(atomic_store, _setup),
|
||||
#endif
|
||||
#if defined(ISC_PLATFORM_HAVEATOMICSTOREQ)
|
||||
ATF_TP_ADD_TC(tp, atomic_storeq);
|
||||
#endif
|
||||
#if !defined(ISC_PLATFORM_HAVEXADD) && \
|
||||
!defined(ISC_PLATFORM_HAVEXADDQ) && \
|
||||
!defined(ISC_PLATFORM_HAVEATOMICSTOREQ)
|
||||
ATF_TP_ADD_TC(tp, untested);
|
||||
cmocka_unit_test_setup(atomic_storeq, _setup),
|
||||
#endif
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
#else
|
||||
print_message("1..0 # Skipped: atomic operations not available\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,77 +11,104 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
#include "isctest.h"
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/region.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/types.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
ATF_TC(isc_buffer_reserve);
|
||||
ATF_TC_HEAD(isc_buffer_reserve, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "reserve space in dynamic buffers");
|
||||
#include "isctest.h"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_buffer_reserve, tc) {
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* reserve space in dynamic buffers */
|
||||
static void
|
||||
isc_buffer_reserve_test(void **state) {
|
||||
isc_result_t result;
|
||||
isc_buffer_t *b;
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
b = NULL;
|
||||
result = isc_buffer_allocate(mctx, &b, 1024);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ(b->length, 1024);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(b->length, 1024);
|
||||
|
||||
/*
|
||||
* 1024 bytes should already be available, so this call does
|
||||
* nothing.
|
||||
*/
|
||||
result = isc_buffer_reserve(&b, 1024);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(ISC_BUFFER_VALID(b));
|
||||
ATF_REQUIRE(b != NULL);
|
||||
ATF_CHECK_EQ(b->length, 1024);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
assert_int_equal(b->length, 1024);
|
||||
|
||||
/*
|
||||
* This call should grow it to 2048 bytes as only 1024 bytes are
|
||||
* available in the buffer.
|
||||
*/
|
||||
result = isc_buffer_reserve(&b, 1025);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(ISC_BUFFER_VALID(b));
|
||||
ATF_REQUIRE(b != NULL);
|
||||
ATF_CHECK_EQ(b->length, 2048);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
assert_int_equal(b->length, 2048);
|
||||
|
||||
/*
|
||||
* 2048 bytes should already be available, so this call does
|
||||
* nothing.
|
||||
*/
|
||||
result = isc_buffer_reserve(&b, 2000);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(ISC_BUFFER_VALID(b));
|
||||
ATF_REQUIRE(b != NULL);
|
||||
ATF_CHECK_EQ(b->length, 2048);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
assert_int_equal(b->length, 2048);
|
||||
|
||||
/*
|
||||
* This call should grow it to 4096 bytes as only 2048 bytes are
|
||||
* available in the buffer.
|
||||
*/
|
||||
result = isc_buffer_reserve(&b, 3000);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(ISC_BUFFER_VALID(b));
|
||||
ATF_REQUIRE(b != NULL);
|
||||
ATF_CHECK_EQ(b->length, 4096);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
assert_int_equal(b->length, 4096);
|
||||
|
||||
/* Consume some of the buffer so we can run the next test. */
|
||||
isc_buffer_add(b, 4096);
|
||||
|
|
@ -90,70 +117,58 @@ ATF_TC_BODY(isc_buffer_reserve, tc) {
|
|||
* This call should fail and leave buffer untouched.
|
||||
*/
|
||||
result = isc_buffer_reserve(&b, UINT_MAX);
|
||||
ATF_CHECK_EQ(result, ISC_R_NOMEMORY);
|
||||
ATF_CHECK(ISC_BUFFER_VALID(b));
|
||||
ATF_REQUIRE(b != NULL);
|
||||
ATF_CHECK_EQ(b->length, 4096);
|
||||
assert_int_equal(result, ISC_R_NOMEMORY);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
assert_int_equal(b->length, 4096);
|
||||
|
||||
isc_buffer_free(&b);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(isc_buffer_reallocate);
|
||||
ATF_TC_HEAD(isc_buffer_reallocate, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "reallocate dynamic buffers");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_buffer_reallocate, tc) {
|
||||
/* reallocate dynamic buffers */
|
||||
static void
|
||||
isc_buffer_reallocate_test(void **state) {
|
||||
isc_result_t result;
|
||||
isc_buffer_t *b;
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
b = NULL;
|
||||
result = isc_buffer_allocate(mctx, &b, 1024);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE(b != NULL);
|
||||
ATF_CHECK_EQ(b->length, 1024);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(b);
|
||||
assert_int_equal(b->length, 1024);
|
||||
|
||||
result = isc_buffer_reallocate(&b, 512);
|
||||
ATF_CHECK_EQ(result, ISC_R_NOSPACE);
|
||||
ATF_CHECK(ISC_BUFFER_VALID(b));
|
||||
ATF_REQUIRE(b != NULL);
|
||||
ATF_CHECK_EQ(b->length, 1024);
|
||||
assert_int_equal(result, ISC_R_NOSPACE);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
assert_int_equal(b->length, 1024);
|
||||
|
||||
result = isc_buffer_reallocate(&b, 1536);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(ISC_BUFFER_VALID(b));
|
||||
ATF_REQUIRE(b != NULL);
|
||||
ATF_CHECK_EQ(b->length, 1536);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_true(ISC_BUFFER_VALID(b));
|
||||
assert_non_null(b);
|
||||
assert_int_equal(b->length, 1536);
|
||||
|
||||
isc_buffer_free(&b);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(isc_buffer_dynamic);
|
||||
ATF_TC_HEAD(isc_buffer_dynamic, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "dynamic buffer automatic reallocation");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_buffer_dynamic, tc) {
|
||||
/* dynamic buffer automatic reallocation */
|
||||
static void
|
||||
isc_buffer_dynamic_test(void **state) {
|
||||
isc_result_t result;
|
||||
isc_buffer_t *b;
|
||||
size_t last_length = 10;
|
||||
int i;
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
b = NULL;
|
||||
result = isc_buffer_allocate(mctx, &b, last_length);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE(b != NULL);
|
||||
ATF_CHECK_EQ(b->length, last_length);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(b);
|
||||
assert_int_equal(b->length, last_length);
|
||||
|
||||
isc_buffer_setautorealloc(b, true);
|
||||
|
||||
|
|
@ -162,47 +177,42 @@ ATF_TC_BODY(isc_buffer_dynamic, tc) {
|
|||
for (i = 0; i < 1000; i++) {
|
||||
isc_buffer_putstr(b, "thisisa24charslongstring");
|
||||
}
|
||||
ATF_CHECK(b->length-last_length >= 1000*24);
|
||||
assert_true(b->length-last_length >= 1000*24);
|
||||
last_length+=1000*24;
|
||||
|
||||
for (i = 0; i < 10000; i++) {
|
||||
isc_buffer_putuint8(b, 1);
|
||||
}
|
||||
|
||||
ATF_CHECK(b->length-last_length >= 10000*1);
|
||||
assert_true(b->length-last_length >= 10000*1);
|
||||
last_length += 10000*1;
|
||||
|
||||
for (i = 0; i < 10000; i++) {
|
||||
isc_buffer_putuint16(b, 1);
|
||||
}
|
||||
|
||||
ATF_CHECK(b->length-last_length >= 10000*2);
|
||||
assert_true(b->length-last_length >= 10000*2);
|
||||
|
||||
last_length += 10000*2;
|
||||
for (i = 0; i < 10000; i++) {
|
||||
isc_buffer_putuint24(b, 1);
|
||||
}
|
||||
ATF_CHECK(b->length-last_length >= 10000*3);
|
||||
assert_true(b->length-last_length >= 10000*3);
|
||||
|
||||
last_length+=10000*3;
|
||||
|
||||
for (i = 0; i < 10000; i++) {
|
||||
isc_buffer_putuint32(b, 1);
|
||||
}
|
||||
ATF_CHECK(b->length-last_length >= 10000*4);
|
||||
assert_true(b->length-last_length >= 10000*4);
|
||||
|
||||
|
||||
isc_buffer_free(&b);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(isc_buffer_copyregion);
|
||||
ATF_TC_HEAD(isc_buffer_copyregion, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "copy a region into a buffer");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_buffer_copyregion, tc) {
|
||||
/* copy a region into a buffer */
|
||||
static void
|
||||
isc_buffer_copyregion_test(void **state) {
|
||||
unsigned char data[] = { 0x11, 0x22, 0x33, 0x44 };
|
||||
isc_buffer_t *b = NULL;
|
||||
isc_result_t result;
|
||||
|
|
@ -212,43 +222,57 @@ ATF_TC_BODY(isc_buffer_copyregion, tc) {
|
|||
.length = sizeof(data),
|
||||
};
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_buffer_allocate(mctx, &b, sizeof(data));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Fill originally allocated buffer space.
|
||||
*/
|
||||
result = isc_buffer_copyregion(b, &r);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Appending more data to the buffer should fail.
|
||||
*/
|
||||
result = isc_buffer_copyregion(b, &r);
|
||||
ATF_CHECK_EQ(result, ISC_R_NOSPACE);
|
||||
assert_int_equal(result, ISC_R_NOSPACE);
|
||||
|
||||
/*
|
||||
* Enable auto reallocation and retry. Appending should now succeed.
|
||||
*/
|
||||
isc_buffer_setautorealloc(b, true);
|
||||
result = isc_buffer_copyregion(b, &r);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_buffer_free(&b);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_buffer_reserve);
|
||||
ATF_TP_ADD_TC(tp, isc_buffer_reallocate);
|
||||
ATF_TP_ADD_TC(tp, isc_buffer_dynamic);
|
||||
ATF_TP_ADD_TC(tp, isc_buffer_copyregion);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(isc_buffer_reserve_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(isc_buffer_reallocate_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(isc_buffer_dynamic_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(isc_buffer_copyregion_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,55 +10,97 @@
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/counter.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
ATF_TC(isc_counter);
|
||||
ATF_TC_HEAD(isc_counter, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "isc counter object");
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
ATF_TC_BODY(isc_counter, tc) {
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* test isc_counter object */
|
||||
static void
|
||||
isc_counter_test(void **state) {
|
||||
isc_result_t result;
|
||||
isc_counter_t *counter = NULL;
|
||||
int i;
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_counter_create(mctx, 0, &counter);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
result = isc_counter_increment(counter);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
ATF_CHECK_EQ(isc_counter_used(counter), 10);
|
||||
assert_int_equal(isc_counter_used(counter), 10);
|
||||
|
||||
isc_counter_setlimit(counter, 15);
|
||||
for (i = 0; i < 10; i++) {
|
||||
result = isc_counter_increment(counter);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ATF_CHECK_EQ(isc_counter_used(counter), 15);
|
||||
assert_int_equal(isc_counter_used(counter), 15);
|
||||
|
||||
isc_counter_detach(&counter);
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_counter);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(isc_counter_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,13 +11,22 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/errno.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
typedef struct {
|
||||
int err;
|
||||
|
|
@ -80,26 +89,38 @@ testpair_t testpair[] = {
|
|||
{ 0, ISC_R_UNEXPECTED }
|
||||
};
|
||||
|
||||
ATF_TC(isc_errno_toresult);
|
||||
ATF_TC_HEAD(isc_errno_toresult, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "convert errno to ISC result");
|
||||
}
|
||||
ATF_TC_BODY(isc_errno_toresult, tc) {
|
||||
/* convert errno to ISC result */
|
||||
static void
|
||||
isc_errno_toresult_test(void **state) {
|
||||
isc_result_t result, expect;
|
||||
size_t i;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < sizeof(testpair)/sizeof(testpair[0]); i++) {
|
||||
result = isc_errno_toresult(testpair[i].err);
|
||||
expect = testpair[i].result;
|
||||
ATF_CHECK(result == expect);
|
||||
assert_int_equal(result, expect);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_errno_toresult);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(isc_errno_toresult_test),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,20 +11,24 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/file.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/result.h>
|
||||
|
||||
ATF_TC(isc_file_sanitize);
|
||||
ATF_TC_HEAD(isc_file_sanitize, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "sanitized filenames");
|
||||
}
|
||||
#include <isc/util.h>
|
||||
|
||||
#define NAME "internal"
|
||||
#define SHA "3bed2cb3a3acf7b6a8ef408420cc682d5520e26976d354254f528c965612054f"
|
||||
|
|
@ -44,93 +48,109 @@ touch(const char *filename) {
|
|||
|
||||
unlink(filename);
|
||||
fd = creat(filename, 0644);
|
||||
if (fd != -1)
|
||||
if (fd != -1) {
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_file_sanitize, tc) {
|
||||
/* test sanitized filenames */
|
||||
static void
|
||||
isc_file_sanitize_test(void **state) {
|
||||
isc_result_t result;
|
||||
char buf[1024];
|
||||
|
||||
ATF_CHECK(chdir(TESTS) != -1);
|
||||
UNUSED(state);
|
||||
|
||||
assert_return_code(chdir(TESTS), 0);
|
||||
|
||||
result = isc_file_sanitize("testdata/file", NAME, "test", buf, 1024);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(strcmp(buf, F(NAME)) == 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(strcmp(buf, F(NAME)), 0);
|
||||
|
||||
touch(F(TRUNC_SHA));
|
||||
result = isc_file_sanitize("testdata/file", NAME, "test", buf, 1024);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(strcmp(buf, F(TRUNC_SHA)) == 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(strcmp(buf, F(TRUNC_SHA)), 0);
|
||||
|
||||
touch(F(SHA));
|
||||
result = isc_file_sanitize("testdata/file", NAME, "test", buf, 1024);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(strcmp(buf, F(SHA)) == 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(strcmp(buf, F(SHA)), 0);
|
||||
|
||||
result = isc_file_sanitize("testdata/file", BAD1, "test", buf, 1024);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(strcmp(buf, F(BADHASH1)) == 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(strcmp(buf, F(BADHASH1)), 0);
|
||||
|
||||
result = isc_file_sanitize("testdata/file", BAD2, "test", buf, 1024);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK(strcmp(buf, F(BADHASH2)) == 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(strcmp(buf, F(BADHASH2)), 0);
|
||||
|
||||
unlink(F(TRUNC_SHA));
|
||||
unlink(F(SHA));
|
||||
}
|
||||
|
||||
ATF_TC(isc_file_template);
|
||||
ATF_TC_HEAD(isc_file_template, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "file template");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_file_template, tc) {
|
||||
/* test filename templates */
|
||||
static void
|
||||
isc_file_template_test(void **state) {
|
||||
isc_result_t result;
|
||||
char buf[1024];
|
||||
|
||||
ATF_CHECK(chdir(TESTS) != -1);
|
||||
UNUSED(state);
|
||||
|
||||
assert_return_code(chdir(TESTS), 0);
|
||||
|
||||
result = isc_file_template("/absolute/path", "file-XXXXXXXX",
|
||||
buf, sizeof(buf));
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_STREQ(buf, "/absolute/file-XXXXXXXX");
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, "/absolute/file-XXXXXXXX");
|
||||
|
||||
result = isc_file_template("relative/path", "file-XXXXXXXX",
|
||||
buf, sizeof(buf));
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_STREQ(buf, "relative/file-XXXXXXXX");
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, "relative/file-XXXXXXXX");
|
||||
|
||||
result = isc_file_template("/trailing/slash/", "file-XXXXXXXX",
|
||||
buf, sizeof(buf));
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_STREQ(buf, "/trailing/slash/file-XXXXXXXX");
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, "/trailing/slash/file-XXXXXXXX");
|
||||
|
||||
result = isc_file_template("relative/trailing/slash/", "file-XXXXXXXX",
|
||||
buf, sizeof(buf));
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_STREQ(buf, "relative/trailing/slash/file-XXXXXXXX");
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, "relative/trailing/slash/file-XXXXXXXX");
|
||||
|
||||
result = isc_file_template("/", "file-XXXXXXXX", buf, sizeof(buf));
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_STREQ(buf, "/file-XXXXXXXX");
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, "/file-XXXXXXXX");
|
||||
|
||||
result = isc_file_template("noslash", "file-XXXXXXXX",
|
||||
buf, sizeof(buf));
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_STREQ(buf, "file-XXXXXXXX");
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, "file-XXXXXXXX");
|
||||
|
||||
result = isc_file_template(NULL, "file-XXXXXXXX", buf, sizeof(buf));
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_STREQ(buf, "file-XXXXXXXX");
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(buf, "file-XXXXXXXX");
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_file_sanitize);
|
||||
ATF_TP_ADD_TC(tp, isc_file_template);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(isc_file_sanitize_test),
|
||||
cmocka_unit_test(isc_file_template_test),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,15 +9,22 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/hash.h>
|
||||
|
||||
|
|
@ -83,15 +90,13 @@ typedef struct hash_test_key {
|
|||
|
||||
/* non-hmac tests */
|
||||
|
||||
ATF_TC(isc_sha1);
|
||||
ATF_TC_HEAD(isc_sha1, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "sha1 examples from RFC4634");
|
||||
}
|
||||
ATF_TC_BODY(isc_sha1, tc) {
|
||||
/* SHA1 examples from RFC 4634 */
|
||||
static void
|
||||
isc_sha1_test(void **state) {
|
||||
isc_sha1_t sha1;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -206,21 +211,19 @@ ATF_TC_BODY(isc_sha1, tc) {
|
|||
}
|
||||
isc_sha1_final(&sha1, digest);
|
||||
tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(isc_sha224);
|
||||
ATF_TC_HEAD(isc_sha224, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
|
||||
}
|
||||
ATF_TC_BODY(isc_sha224, tc) {
|
||||
/* SHA224 examples from RFC 4634 */
|
||||
static void
|
||||
isc_sha224_test(void **state) {
|
||||
isc_sha224_t sha224;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -339,21 +342,19 @@ ATF_TC_BODY(isc_sha224, tc) {
|
|||
* isc_sha224_final(&sha224, digest);
|
||||
*/
|
||||
tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(isc_sha256);
|
||||
ATF_TC_HEAD(isc_sha256, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
|
||||
}
|
||||
ATF_TC_BODY(isc_sha256, tc) {
|
||||
/* SHA256 examples from RFC 4634 */
|
||||
static void
|
||||
isc_sha256_test(void **state) {
|
||||
isc_sha256_t sha256;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -471,21 +472,19 @@ ATF_TC_BODY(isc_sha256, tc) {
|
|||
* isc_sha224_final(&sha224, digest);
|
||||
*/
|
||||
tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(isc_sha384);
|
||||
ATF_TC_HEAD(isc_sha384, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
|
||||
}
|
||||
ATF_TC_BODY(isc_sha384, tc) {
|
||||
/* SHA384 examples from RFC 4634 */
|
||||
static void
|
||||
isc_sha384_test(void **state) {
|
||||
isc_sha384_t sha384;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -617,21 +616,19 @@ ATF_TC_BODY(isc_sha384, tc) {
|
|||
* isc_sha224_final(&sha224, digest);
|
||||
*/
|
||||
tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(isc_sha512);
|
||||
ATF_TC_HEAD(isc_sha512, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
|
||||
}
|
||||
ATF_TC_BODY(isc_sha512, tc) {
|
||||
/* SHA512 examples from RFC 4634 */
|
||||
static void
|
||||
isc_sha512_test(void **state) {
|
||||
isc_sha512_t sha512;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -764,22 +761,20 @@ ATF_TC_BODY(isc_sha512, tc) {
|
|||
* isc_sha224_final(&sha224, digest);
|
||||
*/
|
||||
tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef PK11_MD5_DISABLE
|
||||
ATF_TC(isc_md5);
|
||||
ATF_TC_HEAD(isc_md5, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "md5 example from RFC1321");
|
||||
}
|
||||
ATF_TC_BODY(isc_md5, tc) {
|
||||
/* MD5 examples from RFC 1321 */
|
||||
static void
|
||||
isc_md5_test(void **state) {
|
||||
isc_md5_t md5;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -838,22 +833,19 @@ ATF_TC_BODY(isc_md5, tc) {
|
|||
}
|
||||
isc_md5_final(&md5, digest);
|
||||
tohexstr(digest, ISC_MD5_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* HMAC-SHA1 test */
|
||||
ATF_TC(isc_hmacsha1);
|
||||
ATF_TC_HEAD(isc_hmacsha1, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "HMAC-SHA1 examples from RFC2104");
|
||||
}
|
||||
ATF_TC_BODY(isc_hmacsha1, tc) {
|
||||
/* HMAC-SHA1 examples from RFC 2104 */
|
||||
static void
|
||||
isc_hmacsha1_test(void **state) {
|
||||
isc_hmacsha1_t hmacsha1;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
* through the hash function and the results are compared to the
|
||||
|
|
@ -968,22 +960,19 @@ ATF_TC_BODY(isc_hmacsha1, tc) {
|
|||
testcase->input_len);
|
||||
isc_hmacsha1_sign(&hmacsha1, digest, ISC_SHA1_DIGESTLENGTH);
|
||||
tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
test_key++;
|
||||
}
|
||||
}
|
||||
|
||||
/* HMAC-SHA224 test */
|
||||
ATF_TC(isc_hmacsha224);
|
||||
ATF_TC_HEAD(isc_hmacsha224, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "HMAC-SHA224 examples from RFC4634");
|
||||
}
|
||||
ATF_TC_BODY(isc_hmacsha224, tc) {
|
||||
/* HMAC-SHA224 examples from RFC 4634 */
|
||||
static void
|
||||
isc_hmacsha224_test(void **state) {
|
||||
isc_hmacsha224_t hmacsha224;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -1129,24 +1118,22 @@ ATF_TC_BODY(isc_hmacsha224, tc) {
|
|||
isc_hmacsha224_update(&hmacsha224,
|
||||
(const uint8_t *) testcase->input,
|
||||
testcase->input_len);
|
||||
isc_hmacsha224_sign(&hmacsha224, digest, ISC_SHA224_DIGESTLENGTH);
|
||||
isc_hmacsha224_sign(&hmacsha224, digest,
|
||||
ISC_SHA224_DIGESTLENGTH);
|
||||
tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
test_key++;
|
||||
}
|
||||
}
|
||||
|
||||
/* HMAC-SHA256 test */
|
||||
ATF_TC(isc_hmacsha256);
|
||||
ATF_TC_HEAD(isc_hmacsha256, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "HMAC-SHA256 examples from RFC4634");
|
||||
}
|
||||
ATF_TC_BODY(isc_hmacsha256, tc) {
|
||||
/* HMAC-SHA256 examples from RFC 4634 */
|
||||
static void
|
||||
isc_hmacsha256_test(void **state) {
|
||||
isc_hmacsha256_t hmacsha256;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -1292,24 +1279,22 @@ ATF_TC_BODY(isc_hmacsha256, tc) {
|
|||
isc_hmacsha256_update(&hmacsha256,
|
||||
(const uint8_t *) testcase->input,
|
||||
testcase->input_len);
|
||||
isc_hmacsha256_sign(&hmacsha256, digest, ISC_SHA256_DIGESTLENGTH);
|
||||
isc_hmacsha256_sign(&hmacsha256, digest,
|
||||
ISC_SHA256_DIGESTLENGTH);
|
||||
tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
test_key++;
|
||||
}
|
||||
}
|
||||
|
||||
/* HMAC-SHA384 test */
|
||||
ATF_TC(isc_hmacsha384);
|
||||
ATF_TC_HEAD(isc_hmacsha384, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "HMAC-SHA384 examples from RFC4634");
|
||||
}
|
||||
ATF_TC_BODY(isc_hmacsha384, tc) {
|
||||
/* HMAC-SHA384 examples from RFC 4634 */
|
||||
static void
|
||||
isc_hmacsha384_test(void **state) {
|
||||
isc_hmacsha384_t hmacsha384;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -1461,24 +1446,22 @@ ATF_TC_BODY(isc_hmacsha384, tc) {
|
|||
isc_hmacsha384_update(&hmacsha384,
|
||||
(const uint8_t *) testcase->input,
|
||||
testcase->input_len);
|
||||
isc_hmacsha384_sign(&hmacsha384, digest, ISC_SHA384_DIGESTLENGTH);
|
||||
isc_hmacsha384_sign(&hmacsha384, digest,
|
||||
ISC_SHA384_DIGESTLENGTH);
|
||||
tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
test_key++;
|
||||
}
|
||||
}
|
||||
|
||||
/* HMAC-SHA512 test */
|
||||
ATF_TC(isc_hmacsha512);
|
||||
ATF_TC_HEAD(isc_hmacsha512, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "HMAC-SHA512 examples from RFC4634");
|
||||
}
|
||||
ATF_TC_BODY(isc_hmacsha512, tc) {
|
||||
/* HMAC-SHA512 examples from RFC 4634 */
|
||||
static void
|
||||
isc_hmacsha512_test(void **state) {
|
||||
isc_hmacsha512_t hmacsha512;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -1630,26 +1613,23 @@ ATF_TC_BODY(isc_hmacsha512, tc) {
|
|||
isc_hmacsha512_update(&hmacsha512,
|
||||
(const uint8_t *) testcase->input,
|
||||
testcase->input_len);
|
||||
isc_hmacsha512_sign(&hmacsha512, digest, ISC_SHA512_DIGESTLENGTH);
|
||||
isc_hmacsha512_sign(&hmacsha512, digest,
|
||||
ISC_SHA512_DIGESTLENGTH);
|
||||
tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
test_key++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifndef PK11_MD5_DISABLE
|
||||
/* HMAC-MD5 Test */
|
||||
ATF_TC(isc_hmacmd5);
|
||||
ATF_TC_HEAD(isc_hmacmd5, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "HMAC-MD5 examples from RFC2104");
|
||||
}
|
||||
ATF_TC_BODY(isc_hmacmd5, tc) {
|
||||
/* HMAC-MD5 examples from RFC 2104 */
|
||||
static void
|
||||
isc_hmacmd5_test(void **state) {
|
||||
isc_hmacmd5_t hmacmd5;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* These are the various test vectors. All of these are passed
|
||||
|
|
@ -1776,7 +1756,7 @@ ATF_TC_BODY(isc_hmacmd5, tc) {
|
|||
testcase->input_len);
|
||||
isc_hmacmd5_sign(&hmacmd5, digest);
|
||||
tohexstr(digest, ISC_MD5_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
test_key++;
|
||||
|
|
@ -1784,16 +1764,13 @@ ATF_TC_BODY(isc_hmacmd5, tc) {
|
|||
}
|
||||
#endif
|
||||
|
||||
/* CRC64 Test */
|
||||
ATF_TC(isc_crc64);
|
||||
ATF_TC_HEAD(isc_crc64, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "64-bit cyclic redundancy check");
|
||||
}
|
||||
ATF_TC_BODY(isc_crc64, tc) {
|
||||
/* 64-bit cyclic redundancy check */
|
||||
static void
|
||||
isc_crc64_test(void **state) {
|
||||
uint64_t crc;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
hash_testcase_t testcases[] = {
|
||||
{
|
||||
|
|
@ -1841,21 +1818,19 @@ ATF_TC_BODY(isc_crc64, tc) {
|
|||
isc_crc64_final(&crc);
|
||||
snprintf(str, sizeof(str),
|
||||
"0x%016" PRIX64, crc);
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
assert_string_equal(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(isc_hash_function);
|
||||
ATF_TC_HEAD(isc_hash_function, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Hash function test");
|
||||
}
|
||||
ATF_TC_BODY(isc_hash_function, tc) {
|
||||
/*Hash function test */
|
||||
static void
|
||||
isc_hash_function_test(void **state) {
|
||||
unsigned int h1;
|
||||
unsigned int h2;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/* Incremental hashing */
|
||||
|
||||
|
|
@ -1867,42 +1842,40 @@ ATF_TC_BODY(isc_hash_function, tc) {
|
|||
h2 = isc_hash_function("This is a long test", 20,
|
||||
true, NULL);
|
||||
|
||||
ATF_CHECK_EQ(h1, h2);
|
||||
assert_int_equal(h1, h2);
|
||||
|
||||
/* Immutability of hash function */
|
||||
h1 = isc_hash_function(NULL, 0, true, NULL);
|
||||
h2 = isc_hash_function(NULL, 0, true, NULL);
|
||||
|
||||
ATF_CHECK_EQ(h1, h2);
|
||||
assert_int_equal(h1, h2);
|
||||
|
||||
/* Hash function characteristics */
|
||||
h1 = isc_hash_function("Hello world", 12, true, NULL);
|
||||
h2 = isc_hash_function("Hello world", 12, true, NULL);
|
||||
|
||||
ATF_CHECK_EQ(h1, h2);
|
||||
assert_int_equal(h1, h2);
|
||||
|
||||
/* Case */
|
||||
h1 = isc_hash_function("Hello world", 12, false, NULL);
|
||||
h2 = isc_hash_function("heLLo WorLd", 12, false, NULL);
|
||||
|
||||
ATF_CHECK_EQ(h1, h2);
|
||||
assert_int_equal(h1, h2);
|
||||
|
||||
/* Unequal */
|
||||
h1 = isc_hash_function("Hello world", 12, true, NULL);
|
||||
h2 = isc_hash_function("heLLo WorLd", 12, true, NULL);
|
||||
|
||||
ATF_CHECK(h1 != h2);
|
||||
assert_int_not_equal(h1, h2);
|
||||
}
|
||||
|
||||
ATF_TC(isc_hash_function_reverse);
|
||||
ATF_TC_HEAD(isc_hash_function_reverse, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Reverse hash function test");
|
||||
}
|
||||
ATF_TC_BODY(isc_hash_function_reverse, tc) {
|
||||
/* Reverse hash function test */
|
||||
static void
|
||||
isc_hash_function_reverse_test(void **state) {
|
||||
unsigned int h1;
|
||||
unsigned int h2;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/* Incremental hashing */
|
||||
|
||||
|
|
@ -1914,125 +1887,127 @@ ATF_TC_BODY(isc_hash_function_reverse, tc) {
|
|||
h2 = isc_hash_function_reverse("\007example\003org\000", 13,
|
||||
true, NULL);
|
||||
|
||||
ATF_CHECK_EQ(h1, h2);
|
||||
assert_int_equal(h1, h2);
|
||||
|
||||
/* Immutability of hash function */
|
||||
h1 = isc_hash_function_reverse(NULL, 0, true, NULL);
|
||||
h2 = isc_hash_function_reverse(NULL, 0, true, NULL);
|
||||
|
||||
ATF_CHECK_EQ(h1, h2);
|
||||
assert_int_equal(h1, h2);
|
||||
|
||||
/* Hash function characteristics */
|
||||
h1 = isc_hash_function_reverse("Hello world", 12, true, NULL);
|
||||
h2 = isc_hash_function_reverse("Hello world", 12, true, NULL);
|
||||
|
||||
ATF_CHECK_EQ(h1, h2);
|
||||
assert_int_equal(h1, h2);
|
||||
|
||||
/* Case */
|
||||
h1 = isc_hash_function_reverse("Hello world", 12, false, NULL);
|
||||
h2 = isc_hash_function_reverse("heLLo WorLd", 12, false, NULL);
|
||||
|
||||
ATF_CHECK_EQ(h1, h2);
|
||||
assert_int_equal(h1, h2);
|
||||
|
||||
/* Unequal */
|
||||
h1 = isc_hash_function_reverse("Hello world", 12, true, NULL);
|
||||
h2 = isc_hash_function_reverse("heLLo WorLd", 12, true, NULL);
|
||||
|
||||
ATF_CHECK(h1 != h2);
|
||||
assert_true(h1 != h2);
|
||||
}
|
||||
|
||||
ATF_TC(isc_hash_initializer);
|
||||
ATF_TC_HEAD(isc_hash_initializer, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Hash function initializer test");
|
||||
}
|
||||
ATF_TC_BODY(isc_hash_initializer, tc) {
|
||||
/* Hash function initializer test */
|
||||
static void
|
||||
isc_hash_initializer_test(void **state) {
|
||||
unsigned int h1;
|
||||
unsigned int h2;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
h1 = isc_hash_function("Hello world", 12, true, NULL);
|
||||
h2 = isc_hash_function("Hello world", 12, true, NULL);
|
||||
|
||||
ATF_CHECK_EQ(h1, h2);
|
||||
assert_int_equal(h1, h2);
|
||||
|
||||
isc_hash_set_initializer(isc_hash_get_initializer());
|
||||
|
||||
/* Hash value must not change */
|
||||
h2 = isc_hash_function("Hello world", 12, true, NULL);
|
||||
|
||||
ATF_CHECK_EQ(h1, h2);
|
||||
assert_int_equal(h1, h2);
|
||||
}
|
||||
|
||||
#ifndef PK11_MD5_DISABLE
|
||||
ATF_TC(md5_check);
|
||||
ATF_TC_HEAD(md5_check, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Startup MD5 check test");
|
||||
}
|
||||
ATF_TC_BODY(md5_check, tc) {
|
||||
UNUSED(tc);
|
||||
/* Startup MD5 check test */
|
||||
static void
|
||||
md5_check_test(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
ATF_REQUIRE(isc_md5_check(false));
|
||||
ATF_CHECK(!isc_md5_check(true));
|
||||
assert_true(isc_md5_check(false));
|
||||
assert_false(isc_md5_check(true));
|
||||
|
||||
ATF_REQUIRE(isc_hmacmd5_check(0));
|
||||
ATF_CHECK(!isc_hmacmd5_check(1));
|
||||
ATF_CHECK(!isc_hmacmd5_check(2));
|
||||
ATF_CHECK(!isc_hmacmd5_check(3));
|
||||
ATF_CHECK(!isc_hmacmd5_check(4));
|
||||
assert_true(isc_hmacmd5_check(0));
|
||||
assert_false(isc_hmacmd5_check(1));
|
||||
assert_false(isc_hmacmd5_check(2));
|
||||
assert_false(isc_hmacmd5_check(3));
|
||||
assert_false(isc_hmacmd5_check(4));
|
||||
}
|
||||
#endif
|
||||
|
||||
ATF_TC(sha1_check);
|
||||
ATF_TC_HEAD(sha1_check, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Startup SHA-1 check test");
|
||||
}
|
||||
ATF_TC_BODY(sha1_check, tc) {
|
||||
UNUSED(tc);
|
||||
/* Startup SHA-1 check test */
|
||||
static void
|
||||
sha1_check_test(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
ATF_REQUIRE(isc_sha1_check(false));
|
||||
ATF_CHECK(!isc_sha1_check(true));
|
||||
assert_true(isc_sha1_check(false));
|
||||
assert_false(isc_sha1_check(true));
|
||||
|
||||
ATF_REQUIRE(isc_hmacsha1_check(0));
|
||||
ATF_CHECK(!isc_hmacsha1_check(1));
|
||||
ATF_CHECK(!isc_hmacsha1_check(2));
|
||||
ATF_CHECK(!isc_hmacsha1_check(3));
|
||||
ATF_CHECK(!isc_hmacsha1_check(4));
|
||||
assert_true(isc_hmacsha1_check(0));
|
||||
assert_false(isc_hmacsha1_check(1));
|
||||
assert_false(isc_hmacsha1_check(2));
|
||||
assert_false(isc_hmacsha1_check(3));
|
||||
assert_false(isc_hmacsha1_check(4));
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
/*
|
||||
* Tests of hash functions, including isc_hash and the
|
||||
* various cryptographic hashes.
|
||||
*/
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
#ifndef PK11_MD5_DISABLE
|
||||
ATF_TP_ADD_TC(tp, md5_check);
|
||||
cmocka_unit_test(md5_check_test),
|
||||
#endif
|
||||
ATF_TP_ADD_TC(tp, sha1_check);
|
||||
cmocka_unit_test(sha1_check_test),
|
||||
|
||||
ATF_TP_ADD_TC(tp, isc_hash_function);
|
||||
ATF_TP_ADD_TC(tp, isc_hash_function_reverse);
|
||||
ATF_TP_ADD_TC(tp, isc_hash_initializer);
|
||||
cmocka_unit_test(isc_hash_function_test),
|
||||
cmocka_unit_test(isc_hash_function_reverse_test),
|
||||
cmocka_unit_test(isc_hash_initializer_test),
|
||||
#ifndef PK11_MD5_DISABLE
|
||||
ATF_TP_ADD_TC(tp, isc_hmacmd5);
|
||||
cmocka_unit_test(isc_hmacmd5_test),
|
||||
#endif
|
||||
ATF_TP_ADD_TC(tp, isc_hmacsha1);
|
||||
ATF_TP_ADD_TC(tp, isc_hmacsha224);
|
||||
ATF_TP_ADD_TC(tp, isc_hmacsha256);
|
||||
ATF_TP_ADD_TC(tp, isc_hmacsha384);
|
||||
ATF_TP_ADD_TC(tp, isc_hmacsha512);
|
||||
cmocka_unit_test(isc_hmacsha1_test),
|
||||
cmocka_unit_test(isc_hmacsha224_test),
|
||||
cmocka_unit_test(isc_hmacsha256_test),
|
||||
cmocka_unit_test(isc_hmacsha384_test),
|
||||
cmocka_unit_test(isc_hmacsha512_test),
|
||||
#ifndef PK11_MD5_DISABLE
|
||||
ATF_TP_ADD_TC(tp, isc_md5);
|
||||
cmocka_unit_test(isc_md5_test),
|
||||
#endif
|
||||
ATF_TP_ADD_TC(tp, isc_sha1);
|
||||
ATF_TP_ADD_TC(tp, isc_sha224);
|
||||
ATF_TP_ADD_TC(tp, isc_sha256);
|
||||
ATF_TP_ADD_TC(tp, isc_sha384);
|
||||
ATF_TP_ADD_TC(tp, isc_sha512);
|
||||
ATF_TP_ADD_TC(tp, isc_crc64);
|
||||
cmocka_unit_test(isc_sha1_test),
|
||||
cmocka_unit_test(isc_sha224_test),
|
||||
cmocka_unit_test(isc_sha256_test),
|
||||
cmocka_unit_test(isc_sha384_test),
|
||||
cmocka_unit_test(isc_sha512_test),
|
||||
cmocka_unit_test(isc_crc64_test),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -13,15 +13,23 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/heap.h>
|
||||
#include <isc/mem.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
struct e {
|
||||
|
|
@ -44,44 +52,54 @@ idx(void *p, unsigned int i) {
|
|||
e->index = i;
|
||||
}
|
||||
|
||||
ATF_TC(isc_heap_delete);
|
||||
ATF_TC_HEAD(isc_heap_delete, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test isc_heap_delete");
|
||||
}
|
||||
ATF_TC_BODY(isc_heap_delete, tc) {
|
||||
/* test isc_heap_delete() */
|
||||
static void
|
||||
isc_heap_delete_test(void **state) {
|
||||
isc_mem_t *mctx = NULL;
|
||||
isc_heap_t *heap = NULL;
|
||||
isc_result_t result;
|
||||
struct e e1 = { 100, 0 };
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_mem_create(0, 0, &mctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_heap_create(mctx, compare, idx, 0, &heap);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE(heap != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(heap);
|
||||
|
||||
isc_heap_insert(heap, &e1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(e1.index, 1);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(e1.index, 1);
|
||||
|
||||
isc_heap_delete(heap, e1.index);
|
||||
ATF_CHECK_EQ(e1.index, 0);
|
||||
assert_int_equal(e1.index, 0);
|
||||
|
||||
isc_heap_destroy(&heap);
|
||||
ATF_REQUIRE_EQ(heap, NULL);
|
||||
assert_int_equal(heap, NULL);
|
||||
|
||||
isc_mem_detach(&mctx);
|
||||
ATF_REQUIRE_EQ(mctx, NULL);
|
||||
assert_int_equal(mctx, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_heap_delete);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(isc_heap_delete_test),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,16 +9,21 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/hash.h>
|
||||
#include <isc/ht.h>
|
||||
|
|
@ -30,8 +35,9 @@
|
|||
static void *
|
||||
default_memalloc(void *arg, size_t size) {
|
||||
UNUSED(arg);
|
||||
if (size == 0U)
|
||||
if (size == 0U) {
|
||||
size = 1;
|
||||
}
|
||||
return (malloc(size));
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +47,8 @@ default_memfree(void *arg, void *ptr) {
|
|||
free(ptr);
|
||||
}
|
||||
|
||||
static void test_ht_full(int bits, uintptr_t count) {
|
||||
static void
|
||||
test_ht_full(int bits, uintptr_t count) {
|
||||
isc_ht_t *ht = NULL;
|
||||
isc_result_t result;
|
||||
isc_mem_t *mctx = NULL;
|
||||
|
|
@ -49,11 +56,11 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
|
||||
result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
|
||||
NULL, &mctx, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_ht_init(&ht, mctx, bits);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE(ht != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(ht);
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
/*
|
||||
|
|
@ -64,7 +71,7 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_add(ht, key, 16, (void *) i);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
|
|
@ -73,8 +80,8 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_find(ht, key, 16, &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(i, (uintptr_t) f);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_ptr_equal((void *) i, (uintptr_t) f);
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
|
|
@ -82,7 +89,7 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_add(ht, key, 16, (void *) i);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_EXISTS);
|
||||
assert_int_equal(result, ISC_R_EXISTS);
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
|
|
@ -95,7 +102,7 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_add(ht, (const unsigned char *) key,
|
||||
strlen(key), (void *) i);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
|
|
@ -107,8 +114,8 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, " KEY of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_find(ht, key, 16, &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(f, NULL);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
assert_null(f);
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
|
|
@ -118,8 +125,8 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_find(ht, (const unsigned char *) key,
|
||||
strlen(key), &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(f, (void *) i);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_ptr_equal(f, (void *) i);
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
|
|
@ -128,10 +135,10 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_delete(ht, key, 16);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = isc_ht_find(ht, key, 16, &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(f, NULL);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
assert_null(f);
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
|
|
@ -142,7 +149,7 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, " KEY of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_add(ht, key, 16, (void *) i);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
|
|
@ -152,11 +159,11 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_delete(ht, (const unsigned char *) key,
|
||||
strlen(key));
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = isc_ht_find(ht, (const unsigned char *) key,
|
||||
strlen(key), &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(f, NULL);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
assert_null(f);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -169,8 +176,8 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, " KEY of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_find(ht, key, 16, &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(i, (uintptr_t) f);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_ptr_equal((void *) i, (uintptr_t) f);
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
|
|
@ -179,15 +186,18 @@ static void test_ht_full(int bits, uintptr_t count) {
|
|||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, " key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_find(ht, key, 16, &f);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);
|
||||
ATF_REQUIRE_EQ(f, NULL);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
assert_null(f);
|
||||
}
|
||||
|
||||
isc_ht_destroy(&ht);
|
||||
ATF_REQUIRE_EQ(ht, NULL);
|
||||
assert_null(ht);
|
||||
|
||||
isc_mem_detach(&mctx);
|
||||
}
|
||||
|
||||
static void test_ht_iterator() {
|
||||
static void
|
||||
test_ht_iterator() {
|
||||
isc_ht_t *ht = NULL;
|
||||
isc_result_t result;
|
||||
isc_mem_t *mctx = NULL;
|
||||
|
|
@ -202,11 +212,11 @@ static void test_ht_iterator() {
|
|||
|
||||
result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
|
||||
NULL, &mctx, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_ht_init(&ht, mctx, 16);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE(ht != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(ht);
|
||||
for (i = 1; i <= count; i++) {
|
||||
/*
|
||||
* Note that the string we're snprintfing is always > 16 bytes
|
||||
|
|
@ -215,12 +225,12 @@ static void test_ht_iterator() {
|
|||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, "key of a raw hashtable!!", sizeof(key));
|
||||
result = isc_ht_add(ht, key, 16, (void *) i);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
walked = 0;
|
||||
result = isc_ht_iter_create(ht, &iter);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
for (result = isc_ht_iter_first(iter);
|
||||
result == ISC_R_SUCCESS;
|
||||
|
|
@ -228,15 +238,15 @@ static void test_ht_iterator() {
|
|||
{
|
||||
isc_ht_iter_current(iter, &v);
|
||||
isc_ht_iter_currentkey(iter, &tkey, &tksize);
|
||||
ATF_REQUIRE_EQ(tksize, 16);
|
||||
assert_int_equal(tksize, 16);
|
||||
i = (uintptr_t)v;
|
||||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, "key of a raw hashtable!!", sizeof(key));
|
||||
ATF_REQUIRE_EQ(memcmp(key, tkey, 16), 0);
|
||||
assert_memory_equal(key, tkey, 16);
|
||||
walked++;
|
||||
}
|
||||
ATF_REQUIRE_EQ(walked, count);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOMORE);
|
||||
assert_int_equal(walked, count);
|
||||
assert_int_equal(result, ISC_R_NOMORE);
|
||||
|
||||
/* erase odd */
|
||||
walked = 0;
|
||||
|
|
@ -244,11 +254,11 @@ static void test_ht_iterator() {
|
|||
while (result == ISC_R_SUCCESS) {
|
||||
isc_ht_iter_current(iter, &v);
|
||||
isc_ht_iter_currentkey(iter, &tkey, &tksize);
|
||||
ATF_REQUIRE_EQ(tksize, 16);
|
||||
assert_int_equal(tksize, 16);
|
||||
i = (uintptr_t)v;
|
||||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, "key of a raw hashtable!!", sizeof(key));
|
||||
ATF_REQUIRE_EQ(memcmp(key, tkey, 16), 0);
|
||||
assert_memory_equal(key, tkey, 16);
|
||||
if ((uintptr_t)v % 2 == 0) {
|
||||
result = isc_ht_iter_delcurrent_next(iter);
|
||||
} else {
|
||||
|
|
@ -256,8 +266,8 @@ static void test_ht_iterator() {
|
|||
}
|
||||
walked++;
|
||||
}
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOMORE);
|
||||
ATF_REQUIRE_EQ(walked, count);
|
||||
assert_int_equal(result, ISC_R_NOMORE);
|
||||
assert_int_equal(walked, count);
|
||||
|
||||
/* erase even */
|
||||
walked = 0;
|
||||
|
|
@ -265,11 +275,11 @@ static void test_ht_iterator() {
|
|||
while (result == ISC_R_SUCCESS) {
|
||||
isc_ht_iter_current(iter, &v);
|
||||
isc_ht_iter_currentkey(iter, &tkey, &tksize);
|
||||
ATF_REQUIRE_EQ(tksize, 16);
|
||||
assert_int_equal(tksize, 16);
|
||||
i = (uintptr_t)v;
|
||||
snprintf((char *)key, sizeof(key), "%u", (unsigned int)i);
|
||||
strlcat((char *)key, "key of a raw hashtable!!", sizeof(key));
|
||||
ATF_REQUIRE_EQ(memcmp(key, tkey, 16), 0);
|
||||
assert_memory_equal(key, tkey, 16);
|
||||
if ((uintptr_t)v % 2 == 1) {
|
||||
result = isc_ht_iter_delcurrent_next(iter);
|
||||
} else {
|
||||
|
|
@ -277,8 +287,8 @@ static void test_ht_iterator() {
|
|||
}
|
||||
walked++;
|
||||
}
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOMORE);
|
||||
ATF_REQUIRE_EQ(walked, count/2);
|
||||
assert_int_equal(result, ISC_R_NOMORE);
|
||||
assert_int_equal(walked, count/2);
|
||||
|
||||
walked = 0;
|
||||
for (result = isc_ht_iter_first(iter);
|
||||
|
|
@ -288,75 +298,67 @@ static void test_ht_iterator() {
|
|||
walked++;
|
||||
}
|
||||
|
||||
ATF_REQUIRE_EQ(result, ISC_R_NOMORE);
|
||||
ATF_REQUIRE_EQ(walked, 0);
|
||||
assert_int_equal(result, ISC_R_NOMORE);
|
||||
assert_int_equal(walked, 0);
|
||||
|
||||
isc_ht_iter_destroy(&iter);
|
||||
assert_null(iter);
|
||||
|
||||
isc_ht_destroy(&ht);
|
||||
ATF_REQUIRE_EQ(ht, NULL);
|
||||
assert_null(ht);
|
||||
|
||||
isc_mem_detach(&mctx);
|
||||
}
|
||||
|
||||
ATF_TC(isc_ht_20);
|
||||
ATF_TC_HEAD(isc_ht_20, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "20 bit, 200K elements test");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_ht_20, tc) {
|
||||
UNUSED(tc);
|
||||
/* 20 bit, 200K elements test */
|
||||
static void
|
||||
isc_ht_20(void **state) {
|
||||
UNUSED(state);
|
||||
test_ht_full(20, 200000);
|
||||
}
|
||||
|
||||
|
||||
ATF_TC(isc_ht_8);
|
||||
ATF_TC_HEAD(isc_ht_8, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "8 bit, 20000 elements crowded test");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_ht_8, tc) {
|
||||
UNUSED(tc);
|
||||
/* 8 bit, 20000 elements crowded test */
|
||||
static void
|
||||
isc_ht_8(void **state) {
|
||||
UNUSED(state);
|
||||
test_ht_full(8, 20000);
|
||||
}
|
||||
|
||||
ATF_TC(isc_ht_1);
|
||||
ATF_TC_HEAD(isc_ht_1, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "1 bit, 100 elements corner case test");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_ht_1, tc) {
|
||||
UNUSED(tc);
|
||||
/* 8 bit, 100 elements corner case test */
|
||||
static void
|
||||
isc_ht_1(void **state) {
|
||||
UNUSED(state);
|
||||
test_ht_full(1, 100);
|
||||
}
|
||||
|
||||
/* xxxwpk we should limit the size of hashtable, 32bit doesn't make sense */
|
||||
#if 0
|
||||
ATF_TC(isc_ht_32);
|
||||
ATF_TC_HEAD(isc_ht_32, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "32 bit, 10000 elements corner case test");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_ht_32, tc) {
|
||||
UNUSED(tc);
|
||||
test_ht_full(32, 10000);
|
||||
}
|
||||
#endif
|
||||
|
||||
ATF_TC(isc_ht_iterator);
|
||||
ATF_TC_HEAD(isc_ht_iterator, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "hashtable iterator");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_ht_iterator, tc) {
|
||||
UNUSED(tc);
|
||||
/* test hashtable iterator */
|
||||
static void
|
||||
isc_ht_iterator_test(void **state) {
|
||||
UNUSED(state);
|
||||
test_ht_iterator();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_ht_20);
|
||||
ATF_TP_ADD_TC(tp, isc_ht_8);
|
||||
ATF_TP_ADD_TC(tp, isc_ht_1);
|
||||
/* ATF_TP_ADD_TC(tp, isc_ht_32); */
|
||||
ATF_TP_ADD_TC(tp, isc_ht_iterator);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(isc_ht_20),
|
||||
cmocka_unit_test(isc_ht_8),
|
||||
cmocka_unit_test(isc_ht_1),
|
||||
cmocka_unit_test(isc_ht_iterator_test),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,7 +11,18 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
/*
|
||||
* Force the prototype for isc_net_ntop to be declared.
|
||||
|
|
@ -21,11 +32,9 @@
|
|||
#define ISC_PLATFORM_NEEDNTOP
|
||||
#include "../inet_ntop.c"
|
||||
|
||||
ATF_TC(isc_net_ntop);
|
||||
ATF_TC_HEAD(isc_net_ntop, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "isc_net_ntop implementation");
|
||||
}
|
||||
ATF_TC_BODY(isc_net_ntop, tc) {
|
||||
/* Test isc_net_ntop implementation */
|
||||
static void
|
||||
isc_net_ntop_test(void **state) {
|
||||
char buf[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
|
||||
int r;
|
||||
size_t i;
|
||||
|
|
@ -45,18 +54,33 @@ ATF_TC_BODY(isc_net_ntop, tc) {
|
|||
{ AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" }
|
||||
};
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) {
|
||||
r = inet_pton(testdata[i].family, testdata[i].address, abuf);
|
||||
ATF_REQUIRE_EQ_MSG(r, 1, "%s", testdata[i].address);
|
||||
assert_int_equal(r, 1);
|
||||
isc_net_ntop(testdata[i].family, abuf, buf, sizeof(buf));
|
||||
ATF_CHECK_STREQ(buf, testdata[i].address);
|
||||
assert_string_equal(buf, testdata[i].address);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_net_ntop);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(isc_net_ntop_test),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/entropy.h>
|
||||
#include <isc/hash.h>
|
||||
|
|
@ -41,7 +40,7 @@ isc_socketmgr_t *socketmgr = NULL;
|
|||
isc_task_t *maintask = NULL;
|
||||
int ncpus;
|
||||
|
||||
static bool hash_active = false;
|
||||
static bool hash_active = false, test_running = false;
|
||||
|
||||
/*
|
||||
* Logging categories: this needs to match the list in bin/named/log.c.
|
||||
|
|
@ -60,14 +59,19 @@ static isc_logcategory_t categories[] = {
|
|||
|
||||
static void
|
||||
cleanup_managers(void) {
|
||||
if (maintask != NULL)
|
||||
if (maintask != NULL) {
|
||||
isc_task_shutdown(maintask);
|
||||
isc_task_destroy(&maintask);
|
||||
if (socketmgr != NULL)
|
||||
}
|
||||
if (socketmgr != NULL) {
|
||||
isc_socketmgr_destroy(&socketmgr);
|
||||
if (taskmgr != NULL)
|
||||
}
|
||||
if (taskmgr != NULL) {
|
||||
isc_taskmgr_destroy(&taskmgr);
|
||||
if (timermgr != NULL)
|
||||
}
|
||||
if (timermgr != NULL) {
|
||||
isc_timermgr_destroy(&timermgr);
|
||||
}
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
|
|
@ -107,7 +111,12 @@ isc_test_begin(FILE *logfile, bool start_managers,
|
|||
{
|
||||
isc_result_t result;
|
||||
|
||||
INSIST(!test_running);
|
||||
test_running = true;
|
||||
|
||||
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
|
||||
|
||||
INSIST(mctx == NULL);
|
||||
CHECK(isc_mem_create(0, 0, &mctx));
|
||||
CHECK(isc_entropy_create(mctx, &ectx));
|
||||
|
||||
|
|
@ -118,7 +127,9 @@ isc_test_begin(FILE *logfile, bool start_managers,
|
|||
isc_logdestination_t destination;
|
||||
isc_logconfig_t *logconfig = NULL;
|
||||
|
||||
INSIST(lctx == NULL);
|
||||
CHECK(isc_log_create(mctx, &lctx, &logconfig));
|
||||
|
||||
isc_log_registercategories(lctx, categories);
|
||||
isc_log_setcontext(lctx);
|
||||
|
||||
|
|
@ -152,23 +163,31 @@ isc_test_begin(FILE *logfile, bool start_managers,
|
|||
|
||||
void
|
||||
isc_test_end(void) {
|
||||
if (maintask != NULL)
|
||||
if (maintask != NULL) {
|
||||
isc_task_detach(&maintask);
|
||||
if (taskmgr != NULL)
|
||||
}
|
||||
if (taskmgr != NULL) {
|
||||
isc_taskmgr_destroy(&taskmgr);
|
||||
}
|
||||
|
||||
if (hash_active) {
|
||||
isc_hash_destroy();
|
||||
hash_active = false;
|
||||
}
|
||||
if (ectx != NULL)
|
||||
if (ectx != NULL) {
|
||||
isc_entropy_detach(&ectx);
|
||||
}
|
||||
|
||||
cleanup_managers();
|
||||
|
||||
if (lctx != NULL)
|
||||
if (lctx != NULL) {
|
||||
isc_log_destroy(&lctx);
|
||||
if (mctx != NULL)
|
||||
}
|
||||
if (mctx != NULL) {
|
||||
isc_mem_destroy(&mctx);
|
||||
}
|
||||
|
||||
test_running = false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -11,23 +11,28 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/lex.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
ATF_TC(lex_0xff);
|
||||
ATF_TC_HEAD(lex_0xff, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "check handling of 0xff");
|
||||
}
|
||||
ATF_TC_BODY(lex_0xff, tc) {
|
||||
/* check handling of 0xff */
|
||||
static void
|
||||
lex_0xff(void **state) {
|
||||
isc_mem_t *mctx = NULL;
|
||||
isc_result_t result;
|
||||
isc_lex_t *lex = NULL;
|
||||
|
|
@ -36,29 +41,27 @@ ATF_TC_BODY(lex_0xff, tc) {
|
|||
|
||||
unsigned char death[] = { EOF, 'A' };
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_mem_create(0, 0, &mctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_lex_create(mctx, 1024, &lex);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_buffer_init(&death_buf, &death[0], sizeof(death));
|
||||
isc_buffer_add(&death_buf, sizeof(death));
|
||||
|
||||
result = isc_lex_openbuffer(lex, &death_buf);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_lex_gettoken(lex, 0, &token);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
ATF_TC(lex_setline);
|
||||
ATF_TC_HEAD(lex_setline, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "check setting of source line");
|
||||
}
|
||||
ATF_TC_BODY(lex_setline, tc) {
|
||||
/* check setting of source line */
|
||||
static void
|
||||
lex_setline(void **state) {
|
||||
isc_mem_t *mctx = NULL;
|
||||
isc_result_t result;
|
||||
isc_lex_t *lex = NULL;
|
||||
|
|
@ -68,44 +71,56 @@ ATF_TC_BODY(lex_setline, tc) {
|
|||
unsigned long line;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_mem_create(0, 0, &mctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_lex_create(mctx, 1024, &lex);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_buffer_init(&buf, &text[0], sizeof(text));
|
||||
isc_buffer_add(&buf, sizeof(text));
|
||||
|
||||
result = isc_lex_openbuffer(lex, &buf);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_lex_setsourceline(lex, 100);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
result = isc_lex_gettoken(lex, 0, &token);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
line = isc_lex_getsourceline(lex);
|
||||
ATF_REQUIRE_EQ(line, 100U + i);
|
||||
assert_int_equal(line, 100U + i);
|
||||
}
|
||||
|
||||
result = isc_lex_gettoken(lex, 0, &token);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_EOF);
|
||||
assert_int_equal(result, ISC_R_EOF);
|
||||
|
||||
line = isc_lex_getsourceline(lex);
|
||||
ATF_REQUIRE_EQ(line, 105U);
|
||||
assert_int_equal(line, 105U);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, lex_0xff);
|
||||
ATF_TP_ADD_TC(tp, lex_setline);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(lex_0xff),
|
||||
cmocka_unit_test(lex_setline),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,23 +10,55 @@
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
#include "isctest.h"
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/mem.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/stdio.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void *
|
||||
default_memalloc(void *arg, size_t size) {
|
||||
UNUSED(arg);
|
||||
if (size == 0U)
|
||||
if (size == 0U) {
|
||||
size = 1;
|
||||
}
|
||||
return (malloc(size));
|
||||
}
|
||||
|
||||
|
|
@ -36,11 +68,6 @@ default_memfree(void *arg, void *ptr) {
|
|||
free(ptr);
|
||||
}
|
||||
|
||||
ATF_TC(isc_mem);
|
||||
ATF_TC_HEAD(isc_mem, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "general memory system tests");
|
||||
}
|
||||
|
||||
#define MP1_FREEMAX 10
|
||||
#define MP1_FILLCNT 10
|
||||
#define MP1_MAXALLOC 30
|
||||
|
|
@ -48,7 +75,9 @@ ATF_TC_HEAD(isc_mem, tc) {
|
|||
#define MP2_FREEMAX 25
|
||||
#define MP2_FILLCNT 25
|
||||
|
||||
ATF_TC_BODY(isc_mem, tc) {
|
||||
/* general memory system tests */
|
||||
static void
|
||||
isc_mem_test(void **state) {
|
||||
isc_result_t result;
|
||||
void *items1[50];
|
||||
void *items2[50];
|
||||
|
|
@ -58,17 +87,16 @@ ATF_TC_BODY(isc_mem, tc) {
|
|||
unsigned int i, j;
|
||||
int rval;
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_mem_create(0, 0, &localmctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_mempool_create(localmctx, 24, &mp1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_mempool_create(localmctx, 31, &mp2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_mempool_setfreemax(mp1, MP1_FREEMAX);
|
||||
isc_mempool_setfillcount(mp1, MP1_FILLCNT);
|
||||
|
|
@ -79,14 +107,14 @@ ATF_TC_BODY(isc_mem, tc) {
|
|||
*/
|
||||
for (i = 0; i < MP1_MAXALLOC; i++) {
|
||||
items1[i] = isc_mempool_get(mp1);
|
||||
ATF_CHECK(items1[i] != NULL);
|
||||
assert_non_null(items1[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to allocate one more. This should fail.
|
||||
*/
|
||||
tmp = isc_mempool_get(mp1);
|
||||
ATF_CHECK_EQ(tmp, NULL);
|
||||
assert_null(tmp);
|
||||
|
||||
/*
|
||||
* Free the first 11 items. Verify that there are 10 free items on
|
||||
|
|
@ -98,10 +126,10 @@ ATF_TC_BODY(isc_mem, tc) {
|
|||
}
|
||||
|
||||
rval = isc_mempool_getfreecount(mp1);
|
||||
ATF_CHECK_EQ(rval, 10);
|
||||
assert_int_equal(rval, 10);
|
||||
|
||||
rval = isc_mempool_getallocated(mp1);
|
||||
ATF_CHECK_EQ(rval, 19);
|
||||
assert_int_equal(rval, 19);
|
||||
|
||||
/*
|
||||
* Now, beat up on mp2 for a while. Allocate 50 items, then free
|
||||
|
|
@ -114,7 +142,7 @@ ATF_TC_BODY(isc_mem, tc) {
|
|||
for (j = 0; j < 500000; j++) {
|
||||
for (i = 0; i < 50; i++) {
|
||||
items2[i] = isc_mempool_get(mp2);
|
||||
ATF_CHECK(items2[i] != NULL);
|
||||
assert_non_null(items2[i]);
|
||||
}
|
||||
for (i = 0; i < 50; i++) {
|
||||
isc_mempool_put(mp2, items2[i]);
|
||||
|
|
@ -137,42 +165,40 @@ ATF_TC_BODY(isc_mem, tc) {
|
|||
|
||||
result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
|
||||
NULL, &localmctx, ISC_MEMFLAG_INTERNAL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_mempool_create(localmctx, 2, &mp1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
tmp = isc_mempool_get(mp1);
|
||||
ATF_CHECK(tmp != NULL);
|
||||
assert_non_null(tmp);
|
||||
|
||||
isc_mempool_put(mp1, tmp);
|
||||
|
||||
isc_mempool_destroy(&mp1);
|
||||
|
||||
isc_test_end();
|
||||
isc_mem_destroy(&localmctx);
|
||||
|
||||
}
|
||||
|
||||
ATF_TC(isc_mem_total);
|
||||
ATF_TC_HEAD(isc_mem_total, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test TotalUse calculation");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_mem_total, tc) {
|
||||
/* test TotalUse calculation */
|
||||
static void
|
||||
isc_mem_total_test(void **state) {
|
||||
isc_result_t result;
|
||||
isc_mem_t *mctx2 = NULL;
|
||||
size_t before, after;
|
||||
ssize_t diff;
|
||||
int i;
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
/* Local alloc, free */
|
||||
mctx2 = NULL;
|
||||
result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
|
||||
NULL, &mctx2, 0);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
before = isc_mem_total(mctx2);
|
||||
|
||||
|
|
@ -186,11 +212,8 @@ ATF_TC_BODY(isc_mem_total, tc) {
|
|||
after = isc_mem_total(mctx2);
|
||||
diff = after - before;
|
||||
|
||||
printf("total_before=%lu, total_after=%lu, total_diff=%lu\n",
|
||||
(unsigned long)before, (unsigned long)after,
|
||||
(unsigned long)diff);
|
||||
/* 2048 +8 bytes extra for size_info */
|
||||
ATF_CHECK_EQ(diff, (2048 + 8) * 100000);
|
||||
assert_int_equal(diff, (2048 + 8) * 100000);
|
||||
|
||||
/* ISC_MEMFLAG_INTERNAL */
|
||||
|
||||
|
|
@ -206,67 +229,77 @@ ATF_TC_BODY(isc_mem_total, tc) {
|
|||
after = isc_mem_total(mctx);
|
||||
diff = after - before;
|
||||
|
||||
printf("total_before=%lu, total_after=%lu, total_diff=%lu\n",
|
||||
(unsigned long)before, (unsigned long)after,
|
||||
(unsigned long)diff);
|
||||
/* 2048 +8 bytes extra for size_info */
|
||||
ATF_CHECK_EQ(diff, (2048 + 8) * 100000);
|
||||
assert_int_equal(diff, (2048 + 8) * 100000);
|
||||
|
||||
out:
|
||||
if (mctx2 != NULL)
|
||||
if (mctx2 != NULL) {
|
||||
isc_mem_destroy(&mctx2);
|
||||
}
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(isc_mem_inuse);
|
||||
ATF_TC_HEAD(isc_mem_inuse, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test InUse calculation");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_mem_inuse, tc) {
|
||||
/* test InUse calculation */
|
||||
static void
|
||||
isc_mem_inuse_test(void **state) {
|
||||
isc_result_t result;
|
||||
isc_mem_t *mctx2 = NULL;
|
||||
size_t before, during, after;
|
||||
size_t before, after;
|
||||
ssize_t diff;
|
||||
void *ptr;
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
mctx2 = NULL;
|
||||
result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
|
||||
NULL, &mctx2, 0);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
before = isc_mem_inuse(mctx2);
|
||||
ptr = isc_mem_allocate(mctx2, 1024000);
|
||||
during = isc_mem_inuse(mctx2);
|
||||
isc_mem_free(mctx2, ptr);
|
||||
after = isc_mem_inuse(mctx2);
|
||||
|
||||
diff = after - before;
|
||||
|
||||
printf("inuse_before=%lu, inuse_during=%lu, inuse_after=%lu\n",
|
||||
(unsigned long)before, (unsigned long)during,
|
||||
(unsigned long)after);
|
||||
ATF_REQUIRE_EQ(diff, 0);
|
||||
assert_int_equal(diff, 0);
|
||||
|
||||
out:
|
||||
if (mctx2 != NULL)
|
||||
if (mctx2 != NULL) {
|
||||
isc_mem_destroy(&mctx2);
|
||||
}
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_mem);
|
||||
ATF_TP_ADD_TC(tp, isc_mem_total);
|
||||
ATF_TP_ADD_TC(tp, isc_mem_inuse);
|
||||
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(isc_mem_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(isc_mem_total_test,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(isc_mem_inuse_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,25 +9,29 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/netaddr.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/sockaddr.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
ATF_TC(netaddr_isnetzero);
|
||||
ATF_TC_HEAD(netaddr_isnetzero, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test netaddr_isnetzero");
|
||||
}
|
||||
ATF_TC_BODY(netaddr_isnetzero, tc) {
|
||||
/* test isc_netaddr_isnetzero() */
|
||||
static void
|
||||
netaddr_isnetzero(void **state) {
|
||||
unsigned int i;
|
||||
struct in_addr ina;
|
||||
struct {
|
||||
|
|
@ -48,22 +52,19 @@ ATF_TC_BODY(netaddr_isnetzero, tc) {
|
|||
bool result;
|
||||
isc_netaddr_t netaddr;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
|
||||
ina.s_addr = inet_addr(tests[i].address);
|
||||
isc_netaddr_fromin(&netaddr, &ina);
|
||||
result = isc_netaddr_isnetzero(&netaddr);
|
||||
ATF_CHECK_EQ_MSG(result, tests[i].expect,
|
||||
"%s", tests[i].address);
|
||||
assert_int_equal(result, tests[i].expect);
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(netaddr_masktoprefixlen);
|
||||
ATF_TC_HEAD(netaddr_masktoprefixlen, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"isc_netaddr_masktoprefixlen() "
|
||||
"calculates correct prefix lengths ");
|
||||
}
|
||||
ATF_TC_BODY(netaddr_masktoprefixlen, tc) {
|
||||
/* test isc_netaddr_masktoprefixlen() calculates correct prefix lengths */
|
||||
static void
|
||||
netaddr_masktoprefixlen(void **state) {
|
||||
struct in_addr na_a;
|
||||
struct in_addr na_b;
|
||||
struct in_addr na_c;
|
||||
|
|
@ -74,41 +75,38 @@ ATF_TC_BODY(netaddr_masktoprefixlen, tc) {
|
|||
isc_netaddr_t ina_d;
|
||||
unsigned int plen;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
ATF_CHECK(inet_pton(AF_INET, "0.0.0.0", &na_a) >= 0);
|
||||
ATF_CHECK(inet_pton(AF_INET, "255.255.255.254", &na_b) >= 0);
|
||||
ATF_CHECK(inet_pton(AF_INET, "255.255.255.255", &na_c) >= 0);
|
||||
ATF_CHECK(inet_pton(AF_INET, "255.255.255.0", &na_d) >= 0);
|
||||
assert_true(inet_pton(AF_INET, "0.0.0.0", &na_a) >= 0);
|
||||
assert_true(inet_pton(AF_INET, "255.255.255.254", &na_b) >= 0);
|
||||
assert_true(inet_pton(AF_INET, "255.255.255.255", &na_c) >= 0);
|
||||
assert_true(inet_pton(AF_INET, "255.255.255.0", &na_d) >= 0);
|
||||
|
||||
isc_netaddr_fromin(&ina_a, &na_a);
|
||||
isc_netaddr_fromin(&ina_b, &na_b);
|
||||
isc_netaddr_fromin(&ina_c, &na_c);
|
||||
isc_netaddr_fromin(&ina_d, &na_d);
|
||||
|
||||
ATF_CHECK_EQ(isc_netaddr_masktoprefixlen(&ina_a, &plen),
|
||||
ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ(plen, 0);
|
||||
assert_int_equal(isc_netaddr_masktoprefixlen(&ina_a, &plen),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(plen, 0);
|
||||
|
||||
ATF_CHECK_EQ(isc_netaddr_masktoprefixlen(&ina_b, &plen),
|
||||
assert_int_equal(isc_netaddr_masktoprefixlen(&ina_b, &plen),
|
||||
ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ(plen, 31);
|
||||
assert_int_equal(plen, 31);
|
||||
|
||||
ATF_CHECK_EQ(isc_netaddr_masktoprefixlen(&ina_c, &plen),
|
||||
ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ(plen, 32);
|
||||
assert_int_equal(isc_netaddr_masktoprefixlen(&ina_c, &plen),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(plen, 32);
|
||||
|
||||
ATF_CHECK_EQ(isc_netaddr_masktoprefixlen(&ina_d, &plen),
|
||||
ISC_R_SUCCESS);
|
||||
ATF_CHECK_EQ(plen, 24);
|
||||
assert_int_equal(isc_netaddr_masktoprefixlen(&ina_d, &plen),
|
||||
ISC_R_SUCCESS);
|
||||
assert_int_equal(plen, 24);
|
||||
}
|
||||
|
||||
ATF_TC(netaddr_multicast);
|
||||
ATF_TC_HEAD(netaddr_multicast, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"check multicast addresses are detected properly");
|
||||
}
|
||||
ATF_TC_BODY(netaddr_multicast, tc) {
|
||||
/* check multicast addresses are detected properly */
|
||||
static void
|
||||
netaddr_multicast(void **state) {
|
||||
unsigned int i;
|
||||
struct {
|
||||
int family;
|
||||
|
|
@ -123,6 +121,8 @@ ATF_TC_BODY(netaddr_multicast, tc) {
|
|||
{ AF_INET6, "ff02::1", true }
|
||||
};
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
|
||||
isc_netaddr_t na;
|
||||
struct in_addr in;
|
||||
|
|
@ -132,26 +132,39 @@ ATF_TC_BODY(netaddr_multicast, tc) {
|
|||
if (tests[i].family == AF_INET) {
|
||||
r = inet_pton(AF_INET, tests[i].addr,
|
||||
(unsigned char *)&in);
|
||||
ATF_REQUIRE_EQ(r, 1);
|
||||
assert_int_equal(r, 1);
|
||||
isc_netaddr_fromin(&na, &in);
|
||||
} else {
|
||||
r = inet_pton(AF_INET6, tests[i].addr,
|
||||
(unsigned char *)&in6);
|
||||
ATF_REQUIRE_EQ(r, 1);
|
||||
assert_int_equal(r, 1);
|
||||
isc_netaddr_fromin6(&na, &in6);
|
||||
}
|
||||
|
||||
ATF_CHECK_EQ(isc_netaddr_ismulticast(&na),
|
||||
tests[i].is_multicast);
|
||||
assert_int_equal(isc_netaddr_ismulticast(&na),
|
||||
tests[i].is_multicast);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, netaddr_isnetzero);
|
||||
ATF_TP_ADD_TC(tp, netaddr_masktoprefixlen);
|
||||
ATF_TP_ADD_TC(tp, netaddr_multicast);
|
||||
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(netaddr_isnetzero),
|
||||
cmocka_unit_test(netaddr_masktoprefixlen),
|
||||
cmocka_unit_test(netaddr_multicast),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -13,52 +13,85 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/parseint.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
/* Test for 32 bit overflow on 64 bit machines in isc_parse_uint32 */
|
||||
ATF_TC(parse_overflow);
|
||||
ATF_TC_HEAD(parse_overflow, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Check for 32 bit overflow");
|
||||
}
|
||||
ATF_TC_BODY(parse_overflow, tc) {
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
uint32_t output;
|
||||
UNUSED(tc);
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_parse_uint32(&output, "1234567890", 10);
|
||||
ATF_CHECK_EQ(ISC_R_SUCCESS, result);
|
||||
ATF_CHECK_EQ(1234567890, output);
|
||||
return (0);
|
||||
}
|
||||
|
||||
result = isc_parse_uint32(&output, "123456789012345", 10);
|
||||
ATF_CHECK_EQ(ISC_R_RANGE, result);
|
||||
|
||||
result = isc_parse_uint32(&output, "12345678901234567890", 10);
|
||||
ATF_CHECK_EQ(ISC_R_RANGE, result);
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, parse_overflow);
|
||||
/* Test for 32 bit overflow on 64 bit machines in isc_parse_uint32 */
|
||||
static void
|
||||
parse_overflow(void **state) {
|
||||
isc_result_t result;
|
||||
uint32_t output;
|
||||
|
||||
return (atf_no_error());
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_parse_uint32(&output, "1234567890", 10);
|
||||
assert_int_equal(ISC_R_SUCCESS, result);
|
||||
assert_int_equal(1234567890, output);
|
||||
|
||||
result = isc_parse_uint32(&output, "123456789012345", 10);
|
||||
assert_int_equal(ISC_R_RANGE, result);
|
||||
|
||||
result = isc_parse_uint32(&output, "12345678901234567890", 10);
|
||||
assert_int_equal(ISC_R_RANGE, result);
|
||||
}
|
||||
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(parse_overflow,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,19 +9,49 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/mem.h>
|
||||
#include <isc/pool.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
poolinit(void **target, void *arg) {
|
||||
isc_result_t result;
|
||||
|
|
@ -43,116 +73,90 @@ poolfree(void **target) {
|
|||
*target = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
/* Create a pool */
|
||||
ATF_TC(create_pool);
|
||||
ATF_TC_HEAD(create_pool, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create a pool");
|
||||
}
|
||||
ATF_TC_BODY(create_pool, tc) {
|
||||
static void
|
||||
create_pool(void **state) {
|
||||
isc_result_t result;
|
||||
isc_pool_t *pool = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_pool_create(mctx, 8, poolfree, poolinit, taskmgr, &pool);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_pool_count(pool), 8);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool), 8);
|
||||
|
||||
isc_pool_destroy(&pool);
|
||||
ATF_REQUIRE_EQ(pool, NULL);
|
||||
|
||||
isc_test_end();
|
||||
assert_null(pool);
|
||||
}
|
||||
|
||||
/* Resize a pool */
|
||||
ATF_TC(expand_pool);
|
||||
ATF_TC_HEAD(expand_pool, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "expand a pool");
|
||||
}
|
||||
ATF_TC_BODY(expand_pool, tc) {
|
||||
static void
|
||||
expand_pool(void **state) {
|
||||
isc_result_t result;
|
||||
isc_pool_t *pool1 = NULL, *pool2 = NULL, *hold = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_pool_create(mctx, 10, poolfree, poolinit, taskmgr, &pool1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_pool_count(pool1), 10);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool1), 10);
|
||||
|
||||
/* resizing to a smaller size should have no effect */
|
||||
hold = pool1;
|
||||
result = isc_pool_expand(&pool1, 5, &pool2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_pool_count(pool2), 10);
|
||||
ATF_REQUIRE_EQ(pool2, hold);
|
||||
ATF_REQUIRE_EQ(pool1, NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool2), 10);
|
||||
assert_ptr_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
pool1 = pool2;
|
||||
pool2 = NULL;
|
||||
|
||||
/* resizing to the same size should have no effect */
|
||||
hold = pool1;
|
||||
result = isc_pool_expand(&pool1, 10, &pool2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_pool_count(pool2), 10);
|
||||
ATF_REQUIRE_EQ(pool2, hold);
|
||||
ATF_REQUIRE_EQ(pool1, NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool2), 10);
|
||||
assert_ptr_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
pool1 = pool2;
|
||||
pool2 = NULL;
|
||||
|
||||
/* resizing to larger size should make a new pool */
|
||||
hold = pool1;
|
||||
result = isc_pool_expand(&pool1, 20, &pool2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_pool_count(pool2), 20);
|
||||
ATF_REQUIRE(pool2 != hold);
|
||||
ATF_REQUIRE_EQ(pool1, NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool2), 20);
|
||||
assert_ptr_not_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
|
||||
isc_pool_destroy(&pool2);
|
||||
ATF_REQUIRE_EQ(pool2, NULL);
|
||||
|
||||
isc_test_end();
|
||||
assert_null(pool2);
|
||||
}
|
||||
|
||||
/* Get objects */
|
||||
ATF_TC(get_objects);
|
||||
ATF_TC_HEAD(get_objects, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "get objects");
|
||||
}
|
||||
ATF_TC_BODY(get_objects, tc) {
|
||||
static void
|
||||
get_objects(void **state) {
|
||||
isc_result_t result;
|
||||
isc_pool_t *pool = NULL;
|
||||
void *item;
|
||||
isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_pool_create(mctx, 2, poolfree, poolinit, taskmgr, &pool);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_pool_count(pool), 2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool), 2);
|
||||
|
||||
item = isc_pool_get(pool);
|
||||
ATF_REQUIRE(item != NULL);
|
||||
assert_non_null(item);
|
||||
isc_task_attach((isc_task_t *) item, &task1);
|
||||
|
||||
item = isc_pool_get(pool);
|
||||
ATF_REQUIRE(item != NULL);
|
||||
assert_non_null(item);
|
||||
isc_task_attach((isc_task_t *) item, &task2);
|
||||
|
||||
item = isc_pool_get(pool);
|
||||
ATF_REQUIRE(item != NULL);
|
||||
assert_non_null(item);
|
||||
isc_task_attach((isc_task_t *) item, &task3);
|
||||
|
||||
isc_task_detach(&task1);
|
||||
|
|
@ -160,20 +164,31 @@ ATF_TC_BODY(get_objects, tc) {
|
|||
isc_task_detach(&task3);
|
||||
|
||||
isc_pool_destroy(&pool);
|
||||
ATF_REQUIRE_EQ(pool, NULL);
|
||||
|
||||
isc_test_end();
|
||||
assert_null(pool);
|
||||
}
|
||||
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(create_pool,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(expand_pool,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(get_objects,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, create_pool);
|
||||
ATF_TP_ADD_TC(tp, expand_pool);
|
||||
ATF_TP_ADD_TC(tp, get_objects);
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,7 +11,11 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -19,6 +23,12 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/util.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
/*
|
||||
* Workout if we need to force the inclusion of print.c so we can test
|
||||
* it on all platforms even if we don't include it in libisc.
|
||||
|
|
@ -28,25 +38,18 @@
|
|||
!defined(ISC_PLATFORM_NEEDFPRINTF) && \
|
||||
!defined(ISC_PLATFORM_NEEDSPRINTF) && \
|
||||
!defined(ISC_PLATFORM_NEEDVSNPRINTF)
|
||||
#define ISC__PRINT_SOURCE
|
||||
#include "../print.c"
|
||||
#else
|
||||
#if !defined(ISC_PLATFORM_NEEDPRINTF) || \
|
||||
!defined(ISC_PLATFORM_NEEDFPRINTF) || \
|
||||
!defined(ISC_PLATFORM_NEEDSPRINTF) || \
|
||||
!defined(ISC_PLATFORM_NEEDVSNPRINTF)
|
||||
#define ISC__PRINT_SOURCE
|
||||
#endif
|
||||
#include <isc/print.h>
|
||||
#include <isc/types.h>
|
||||
#include <isc/util.h>
|
||||
# define ISC__PRINT_SOURCE
|
||||
# define ISC_PLATFORM_NEEDPRINTF
|
||||
# define ISC_PLATFORM_NEEDFPRINTF
|
||||
# define ISC_PLATFORM_NEEDSPRINTF
|
||||
# define ISC_PLATFORM_NEEDVSNPRINTF
|
||||
# include <isc/print.h>
|
||||
# include "../print.c"
|
||||
#endif
|
||||
|
||||
ATF_TC(snprintf);
|
||||
ATF_TC_HEAD(snprintf, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "snprintf implementation");
|
||||
}
|
||||
ATF_TC_BODY(snprintf, tc) {
|
||||
/* Test snprintf() implementation */
|
||||
static void
|
||||
snprintf_test(void **state) {
|
||||
char buf[10000];
|
||||
uint64_t ll = 8589934592ULL;
|
||||
uint64_t nn = 20000000000000ULL;
|
||||
|
|
@ -55,7 +58,7 @@ ATF_TC_BODY(snprintf, tc) {
|
|||
int n;
|
||||
size_t size;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
/*
|
||||
* 4294967296 <= 8589934592 < 1000000000^2 to verify fix for
|
||||
|
|
@ -64,121 +67,133 @@ ATF_TC_BODY(snprintf, tc) {
|
|||
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%" PRIu64, ll);
|
||||
ATF_CHECK_EQ(n, 10);
|
||||
ATF_CHECK_STREQ(buf, "8589934592");
|
||||
assert_int_equal(n, 10);
|
||||
assert_string_equal(buf, "8589934592");
|
||||
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%" PRIu64, ll);
|
||||
ATF_CHECK_EQ(n, 10);
|
||||
ATF_CHECK_STREQ(buf, "8589934592");
|
||||
assert_int_equal(n, 10);
|
||||
assert_string_equal(buf, "8589934592");
|
||||
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%" PRIu64, nn);
|
||||
ATF_CHECK_EQ(n, 14);
|
||||
ATF_CHECK_STREQ(buf, "20000000000000");
|
||||
assert_int_equal(n, 14);
|
||||
assert_string_equal(buf, "20000000000000");
|
||||
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%" PRIu64, nn);
|
||||
ATF_CHECK_EQ(n, 14);
|
||||
ATF_CHECK_STREQ(buf, "20000000000000");
|
||||
assert_int_equal(n, 14);
|
||||
assert_string_equal(buf, "20000000000000");
|
||||
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%" PRIu64, zz);
|
||||
ATF_CHECK_EQ(n, 20);
|
||||
ATF_CHECK_STREQ(buf, "10000000000000000000");
|
||||
assert_int_equal(n, 20);
|
||||
assert_string_equal(buf, "10000000000000000000");
|
||||
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%" PRIu64, zz);
|
||||
ATF_CHECK_EQ(n, 20);
|
||||
ATF_CHECK_STREQ(buf, "10000000000000000000");
|
||||
assert_int_equal(n, 20);
|
||||
assert_string_equal(buf, "10000000000000000000");
|
||||
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%" PRId64, nn);
|
||||
ATF_CHECK_EQ(n, 14);
|
||||
ATF_CHECK_STREQ(buf, "20000000000000");
|
||||
assert_int_equal(n, 14);
|
||||
assert_string_equal(buf, "20000000000000");
|
||||
|
||||
size = 1000;
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%zu", size);
|
||||
ATF_CHECK_EQ(n, 4);
|
||||
ATF_CHECK_STREQ(buf, "1000");
|
||||
assert_int_equal(n, 4);
|
||||
assert_string_equal(buf, "1000");
|
||||
|
||||
size = 1000;
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%zx", size);
|
||||
ATF_CHECK_EQ(n, 3);
|
||||
ATF_CHECK_STREQ(buf, "3e8");
|
||||
assert_int_equal(n, 3);
|
||||
assert_string_equal(buf, "3e8");
|
||||
|
||||
size = 1000;
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%zo", size);
|
||||
ATF_CHECK_EQ(n, 4);
|
||||
ATF_CHECK_STREQ(buf, "1750");
|
||||
assert_int_equal(n, 4);
|
||||
assert_string_equal(buf, "1750");
|
||||
|
||||
zz = 0xf5f5f5f5f5f5f5f5ULL;
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "0x%" PRIx64, zz);
|
||||
ATF_CHECK_EQ(n, 18);
|
||||
ATF_CHECK_STREQ(buf, "0xf5f5f5f5f5f5f5f5");
|
||||
assert_int_equal(n, 18);
|
||||
assert_string_equal(buf, "0xf5f5f5f5f5f5f5f5");
|
||||
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%.2f", pi);
|
||||
ATF_CHECK_EQ(n, 4);
|
||||
ATF_CHECK_STREQ(buf, "3.14");
|
||||
assert_int_equal(n, 4);
|
||||
assert_string_equal(buf, "3.14");
|
||||
|
||||
/* Similar to the above, but additional characters follows */
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%.2f1592", pi);
|
||||
ATF_CHECK_EQ(n, 8);
|
||||
ATF_CHECK_STREQ(buf, "3.141592");
|
||||
assert_int_equal(n, 8);
|
||||
assert_string_equal(buf, "3.141592");
|
||||
|
||||
/* Similar to the above, but with leading spaces */
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "% 8.2f1592", pi);
|
||||
ATF_CHECK_EQ(n, 12);
|
||||
ATF_CHECK_STREQ(buf, " 3.141592");
|
||||
assert_int_equal(n, 12);
|
||||
assert_string_equal(buf, " 3.141592");
|
||||
|
||||
/* Similar to the above, but with trail spaces after the 4 */
|
||||
n = isc_print_snprintf(buf, sizeof(buf), "%-8.2f1592", pi);
|
||||
ATF_CHECK_EQ(n, 12);
|
||||
ATF_CHECK_STREQ(buf, "3.14 1592");
|
||||
assert_int_equal(n, 12);
|
||||
assert_string_equal(buf, "3.14 1592");
|
||||
}
|
||||
|
||||
ATF_TC(fprintf);
|
||||
ATF_TC_HEAD(fprintf, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "fprintf implementation");
|
||||
}
|
||||
ATF_TC_BODY(fprintf, tc) {
|
||||
/* Test fprintf implementation */
|
||||
static void
|
||||
fprintf_test(void **state) {
|
||||
FILE *f;
|
||||
int n;
|
||||
size_t size;
|
||||
char buf[10000];
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
f = fopen("fprintf.test", "w+");
|
||||
ATF_REQUIRE(f != NULL);
|
||||
assert_non_null(f);
|
||||
|
||||
size = 1000;
|
||||
n = isc_print_fprintf(f, "%zu", size);
|
||||
ATF_CHECK_EQ(n, 4);
|
||||
assert_int_equal(n, 4);
|
||||
|
||||
rewind(f);
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
n = fread(buf, 1, sizeof(buf), f);
|
||||
ATF_CHECK_EQ(n, 4);
|
||||
assert_int_equal(n, 4);
|
||||
|
||||
fclose(f);
|
||||
|
||||
ATF_CHECK_STREQ(buf, "1000");
|
||||
assert_string_equal(buf, "1000");
|
||||
|
||||
if ((n > 0) && (!strcmp(buf, "1000")))
|
||||
if ((n > 0) && (!strcmp(buf, "1000"))) {
|
||||
unlink("fprintf.test");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, snprintf);
|
||||
ATF_TP_ADD_TC(tp, fprintf);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(snprintf_test),
|
||||
cmocka_unit_test(fprintf_test),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,19 +9,49 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/queue.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
typedef struct item item_t;
|
||||
struct item {
|
||||
int value;
|
||||
|
|
@ -36,22 +66,14 @@ item_init(item_t *item, int value) {
|
|||
ISC_QLINK_INIT(item, qlink);
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
/* Test UDP sendto/recv (IPv4) */
|
||||
ATF_TC(queue_valid);
|
||||
ATF_TC_HEAD(queue_valid, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Check queue validity");
|
||||
}
|
||||
ATF_TC_BODY(queue_valid, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
queue_valid(void **state) {
|
||||
item_queue_t queue;
|
||||
item_t one, two, three, four, five;
|
||||
item_t *p;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
ISC_QUEUE_INIT(queue, qlink);
|
||||
|
||||
|
|
@ -61,77 +83,85 @@ ATF_TC_BODY(queue_valid, tc) {
|
|||
item_init(&four, 4);
|
||||
item_init(&five, 5);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK(ISC_QUEUE_EMPTY(queue));
|
||||
assert_true(ISC_QUEUE_EMPTY(queue));
|
||||
|
||||
ISC_QUEUE_POP(queue, qlink, p);
|
||||
ATF_CHECK(p == NULL);
|
||||
assert_null(p);
|
||||
|
||||
ATF_CHECK(! ISC_QLINK_LINKED(&one, qlink));
|
||||
assert_false(ISC_QLINK_LINKED(&one, qlink));
|
||||
ISC_QUEUE_PUSH(queue, &one, qlink);
|
||||
ATF_CHECK(ISC_QLINK_LINKED(&one, qlink));
|
||||
assert_true(ISC_QLINK_LINKED(&one, qlink));
|
||||
|
||||
ATF_CHECK(! ISC_QUEUE_EMPTY(queue));
|
||||
assert_false(ISC_QUEUE_EMPTY(queue));
|
||||
|
||||
ISC_QUEUE_POP(queue, qlink, p);
|
||||
ATF_REQUIRE(p != NULL);
|
||||
ATF_CHECK_EQ(p->value, 1);
|
||||
ATF_CHECK(ISC_QUEUE_EMPTY(queue));
|
||||
ATF_CHECK(! ISC_QLINK_LINKED(p, qlink));
|
||||
assert_non_null(p);
|
||||
assert_int_equal(p->value, 1);
|
||||
assert_true(ISC_QUEUE_EMPTY(queue));
|
||||
assert_false(ISC_QLINK_LINKED(p, qlink));
|
||||
|
||||
ISC_QUEUE_PUSH(queue, p, qlink);
|
||||
ATF_CHECK(! ISC_QUEUE_EMPTY(queue));
|
||||
ATF_CHECK(ISC_QLINK_LINKED(p, qlink));
|
||||
assert_false(ISC_QUEUE_EMPTY(queue));
|
||||
assert_true(ISC_QLINK_LINKED(p, qlink));
|
||||
|
||||
ATF_CHECK(! ISC_QLINK_LINKED(&two, qlink));
|
||||
assert_false(ISC_QLINK_LINKED(&two, qlink));
|
||||
ISC_QUEUE_PUSH(queue, &two, qlink);
|
||||
ATF_CHECK(ISC_QLINK_LINKED(&two, qlink));
|
||||
assert_true(ISC_QLINK_LINKED(&two, qlink));
|
||||
|
||||
ATF_CHECK(! ISC_QLINK_LINKED(&three, qlink));
|
||||
assert_false(ISC_QLINK_LINKED(&three, qlink));
|
||||
ISC_QUEUE_PUSH(queue, &three, qlink);
|
||||
ATF_CHECK(ISC_QLINK_LINKED(&three, qlink));
|
||||
assert_true(ISC_QLINK_LINKED(&three, qlink));
|
||||
|
||||
ATF_CHECK(! ISC_QLINK_LINKED(&four, qlink));
|
||||
assert_false(ISC_QLINK_LINKED(&four, qlink));
|
||||
ISC_QUEUE_PUSH(queue, &four, qlink);
|
||||
ATF_CHECK(ISC_QLINK_LINKED(&four, qlink));
|
||||
assert_true(ISC_QLINK_LINKED(&four, qlink));
|
||||
|
||||
ATF_CHECK(! ISC_QLINK_LINKED(&five, qlink));
|
||||
assert_false(ISC_QLINK_LINKED(&five, qlink));
|
||||
ISC_QUEUE_PUSH(queue, &five, qlink);
|
||||
ATF_CHECK(ISC_QLINK_LINKED(&five, qlink));
|
||||
assert_true(ISC_QLINK_LINKED(&five, qlink));
|
||||
|
||||
/* Test unlink by removing one item from the middle */
|
||||
ISC_QUEUE_UNLINK(queue, &three, qlink);
|
||||
|
||||
ISC_QUEUE_POP(queue, qlink, p);
|
||||
ATF_REQUIRE(p != NULL);
|
||||
ATF_CHECK_EQ(p->value, 1);
|
||||
assert_non_null(p);
|
||||
assert_int_equal(p->value, 1);
|
||||
|
||||
ISC_QUEUE_POP(queue, qlink, p);
|
||||
ATF_REQUIRE(p != NULL);
|
||||
ATF_CHECK_EQ(p->value, 2);
|
||||
assert_non_null(p);
|
||||
assert_int_equal(p->value, 2);
|
||||
|
||||
ISC_QUEUE_POP(queue, qlink, p);
|
||||
ATF_REQUIRE(p != NULL);
|
||||
ATF_CHECK_EQ(p->value, 4);
|
||||
assert_non_null(p);
|
||||
assert_int_equal(p->value, 4);
|
||||
|
||||
ISC_QUEUE_POP(queue, qlink, p);
|
||||
ATF_REQUIRE(p != NULL);
|
||||
ATF_CHECK_EQ(p->value, 5);
|
||||
assert_non_null(p);
|
||||
assert_int_equal(p->value, 5);
|
||||
|
||||
ATF_CHECK(ISC_QUEUE_EMPTY(queue));
|
||||
assert_true(ISC_QUEUE_EMPTY(queue));
|
||||
|
||||
ISC_QUEUE_DESTROY(queue);
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, queue_valid);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(queue_valid,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,23 +11,51 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/mem.h>
|
||||
#include <isc/netaddr.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/radix.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
ATF_TC(isc_radix_search);
|
||||
ATF_TC_HEAD(isc_radix_search, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test radix seaching");
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
ATF_TC_BODY(isc_radix_search, tc) {
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* test radix searching */
|
||||
static void
|
||||
isc_radix_search_test(void **state) {
|
||||
isc_radix_tree_t *radix = NULL;
|
||||
isc_radix_node_t *node;
|
||||
isc_prefix_t prefix;
|
||||
|
|
@ -35,13 +63,10 @@ ATF_TC_BODY(isc_radix_search, tc) {
|
|||
struct in_addr in_addr;
|
||||
isc_netaddr_t netaddr;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_radix_create(mctx, &radix, 32);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
in_addr.s_addr = inet_addr("3.3.3.0");
|
||||
isc_netaddr_fromin(&netaddr, &in_addr);
|
||||
|
|
@ -49,7 +74,7 @@ ATF_TC_BODY(isc_radix_search, tc) {
|
|||
|
||||
node = NULL;
|
||||
result = isc_radix_insert(radix, &node, NULL, &prefix);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
node->data[0] = (void *)1;
|
||||
isc_refcount_destroy(&prefix.refcount);
|
||||
|
||||
|
|
@ -59,7 +84,7 @@ ATF_TC_BODY(isc_radix_search, tc) {
|
|||
|
||||
node = NULL;
|
||||
result = isc_radix_insert(radix, &node, NULL, &prefix);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
node->data[0] = (void *)2;
|
||||
isc_refcount_destroy(&prefix.refcount);
|
||||
|
||||
|
|
@ -69,21 +94,32 @@ ATF_TC_BODY(isc_radix_search, tc) {
|
|||
|
||||
node = NULL;
|
||||
result = isc_radix_search(radix, &node, &prefix);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(node->data[0], (void *)2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(node->data[0], (void *)2);
|
||||
|
||||
isc_refcount_destroy(&prefix.refcount);
|
||||
|
||||
isc_radix_destroy(radix, NULL);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_radix_search);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(isc_radix_search_test,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -18,20 +18,28 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <isc/random.h>
|
||||
#include <isc/result.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/commandline.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#define REPS 25000
|
||||
|
||||
typedef double (pvalue_func_t)(isc_mem_t *mctx,
|
||||
|
|
@ -55,6 +63,17 @@ static double biginv = 2.22044604925031308085e-16;
|
|||
static double igamc(double a, double x);
|
||||
static double igam(double a, double x);
|
||||
|
||||
static bool verbose = false;
|
||||
|
||||
typedef enum {
|
||||
ISC_RANDOM8,
|
||||
ISC_RANDOM16,
|
||||
ISC_RANDOM32,
|
||||
ISC_RANDOM_BYTES,
|
||||
ISC_RANDOM_UNIFORM,
|
||||
ISC_NONCE_BYTES
|
||||
} isc_random_func;
|
||||
|
||||
static double
|
||||
igamc(double a, double x) {
|
||||
double ans, ax, c, yc, r, t, y, z;
|
||||
|
|
@ -68,7 +87,7 @@ igamc(double a, double x) {
|
|||
|
||||
ax = a * log(x) - x - lgamma(a);
|
||||
if (ax < -MAXLOG) {
|
||||
fprintf(stderr, "igamc: UNDERFLOW, ax=%f\n", ax);
|
||||
print_error("# igamc: UNDERFLOW, ax=%f\n", ax);
|
||||
return (0.0);
|
||||
}
|
||||
ax = exp(ax);
|
||||
|
|
@ -125,8 +144,8 @@ igam(double a, double x) {
|
|||
|
||||
/* Compute x**a * exp(-x) / md_gamma(a) */
|
||||
ax = a * log(x) - x - lgamma(a);
|
||||
if( ax < -MAXLOG ) {
|
||||
fprintf(stderr, "igam: UNDERFLOW, ax=%f\n", ax);
|
||||
if (ax < -MAXLOG ) {
|
||||
print_error("# igam: UNDERFLOW, ax=%f\n", ax);
|
||||
return (0.0);
|
||||
}
|
||||
ax = exp(ax);
|
||||
|
|
@ -270,11 +289,11 @@ random_test(pvalue_func_t *func) {
|
|||
tables_init();
|
||||
|
||||
result = isc_mem_create(0, 0, &mctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
rng = NULL;
|
||||
result = isc_rng_create(mctx, NULL, &rng);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
m = 1000;
|
||||
passed = 0;
|
||||
|
|
@ -292,8 +311,7 @@ random_test(pvalue_func_t *func) {
|
|||
passed++;
|
||||
}
|
||||
|
||||
ATF_REQUIRE(p_value >= 0.0);
|
||||
ATF_REQUIRE(p_value <= 1.0);
|
||||
assert_in_range(p_value, 0.0, 1.0);
|
||||
|
||||
i = (int) floor(p_value * 10);
|
||||
histogram[i]++;
|
||||
|
|
@ -311,13 +329,14 @@ random_test(pvalue_func_t *func) {
|
|||
lower_confidence = p_hat - (3.0 * sqrt((p_hat * (1.0 - p_hat)) / m));
|
||||
higher_confidence = p_hat + (3.0 * sqrt((p_hat * (1.0 - p_hat)) / m));
|
||||
|
||||
/* Debug message, not displayed when running via atf-run */
|
||||
printf("passed=%u/1000\n", passed);
|
||||
printf("higher_confidence=%f, lower_confidence=%f, proportion=%f\n",
|
||||
higher_confidence, lower_confidence, proportion);
|
||||
if (verbose) {
|
||||
print_message("# passed=%u/1000\n", passed);
|
||||
print_message("# higher_confidence=%f, lower_confidence=%f, "
|
||||
"proportion=%f\n",
|
||||
higher_confidence, lower_confidence, proportion);
|
||||
}
|
||||
|
||||
ATF_REQUIRE(proportion >= lower_confidence);
|
||||
ATF_REQUIRE(proportion <= higher_confidence);
|
||||
assert_in_range(proportion, lower_confidence, higher_confidence);
|
||||
|
||||
/*
|
||||
* Check uniform distribution of p-values (see section 4.2.2 in
|
||||
|
|
@ -331,15 +350,20 @@ random_test(pvalue_func_t *func) {
|
|||
histogram[10] = 0;
|
||||
|
||||
/* Pre-requisite that at least 55 sequences are processed. */
|
||||
ATF_REQUIRE(m >= 55);
|
||||
assert_true(m >= 55);
|
||||
|
||||
if (verbose) {
|
||||
print_message("# ");
|
||||
}
|
||||
|
||||
chi_square = 0.0;
|
||||
for (j = 0; j < 10; j++) {
|
||||
double numer;
|
||||
double denom;
|
||||
|
||||
/* Debug message, not displayed when running via atf-run */
|
||||
printf("hist%u=%u ", j, histogram[j]);
|
||||
if (verbose) {
|
||||
print_message("hist%u=%u ", j, histogram[j]);
|
||||
}
|
||||
|
||||
numer = (histogram[j] - (m / 10.0)) *
|
||||
(histogram[j] - (m / 10.0));
|
||||
|
|
@ -347,11 +371,13 @@ random_test(pvalue_func_t *func) {
|
|||
chi_square += numer / denom;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
if (verbose) {
|
||||
print_message("\n");
|
||||
}
|
||||
|
||||
p_value_t = igamc(9 / 2.0, chi_square / 2.0);
|
||||
|
||||
ATF_REQUIRE(p_value_t >= 0.0001);
|
||||
assert_true(p_value_t >= 0.0001);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -375,10 +401,11 @@ monobit(isc_mem_t *mctx, uint16_t *values, size_t length) {
|
|||
scount += scounts_table[values[i]];
|
||||
|
||||
/* Preconditions (section 2.1.7 in NIST SP 800-22) */
|
||||
ATF_REQUIRE(numbits >= 100);
|
||||
assert_true(numbits >= 100);
|
||||
|
||||
/* Debug message, not displayed when running via atf-run */
|
||||
printf("numbits=%u, scount=%d\n", numbits, scount);
|
||||
if (verbose) {
|
||||
print_message("# numbits=%u, scount=%d\n", numbits, scount);
|
||||
}
|
||||
|
||||
s_obs = abs(scount) / sqrt(numbits);
|
||||
p_value = erfc(s_obs / sqrt(2.0));
|
||||
|
|
@ -413,14 +440,15 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) {
|
|||
for (i = 0; i < REPS; i++)
|
||||
bcount += bitcounts_table[values[i]];
|
||||
|
||||
/* Debug message, not displayed when running via atf-run */
|
||||
printf("numbits=%u, bcount=%u\n", numbits, bcount);
|
||||
if (verbose) {
|
||||
print_message("# numbits=%u, bcount=%u\n", numbits, bcount);
|
||||
}
|
||||
|
||||
pi = (double) bcount / (double) numbits;
|
||||
tau = 2.0 / sqrt(numbits);
|
||||
|
||||
/* Preconditions (section 2.3.7 in NIST SP 800-22) */
|
||||
ATF_REQUIRE(numbits >= 100);
|
||||
assert_true(numbits >= 100);
|
||||
|
||||
/*
|
||||
* Pre-condition implied from the monobit test. This can fail
|
||||
|
|
@ -481,18 +509,19 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) {
|
|||
mwords = mbits / 16;
|
||||
numblocks = numbits / mbits;
|
||||
|
||||
/* Debug message, not displayed when running via atf-run */
|
||||
printf("numblocks=%u\n", numblocks);
|
||||
if (verbose) {
|
||||
print_message("# numblocks=%u\n", numblocks);
|
||||
}
|
||||
|
||||
/* Preconditions (section 2.2.7 in NIST SP 800-22) */
|
||||
ATF_REQUIRE(numbits >= 100);
|
||||
ATF_REQUIRE(mbits >= 20);
|
||||
ATF_REQUIRE((double) mbits > (0.01 * numbits));
|
||||
ATF_REQUIRE(numblocks < 100);
|
||||
ATF_REQUIRE(numbits >= (mbits * numblocks));
|
||||
assert_true(numbits >= 100);
|
||||
assert_true(mbits >= 20);
|
||||
assert_true((double) mbits > (0.01 * numbits));
|
||||
assert_true(numblocks < 100);
|
||||
assert_true(numbits >= (mbits * numblocks));
|
||||
|
||||
pi = isc_mem_get(mctx, numblocks * sizeof(double));
|
||||
ATF_REQUIRE(pi != NULL);
|
||||
assert_non_null(pi);
|
||||
|
||||
for (i = 0; i < numblocks; i++) {
|
||||
uint32_t j;
|
||||
|
|
@ -515,8 +544,9 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) {
|
|||
|
||||
isc_mem_put(mctx, pi, numblocks * sizeof(double));
|
||||
|
||||
/* Debug message, not displayed when running via atf-run */
|
||||
printf("chi_square=%f\n", chi_square);
|
||||
if (verbose) {
|
||||
print_message("# chi_square=%f\n", chi_square);
|
||||
}
|
||||
|
||||
p_value = igamc(numblocks * 0.5, chi_square * 0.5);
|
||||
|
||||
|
|
@ -551,9 +581,9 @@ binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) {
|
|||
numbits = num_matrices * matrix_m * matrix_q;
|
||||
|
||||
/* Preconditions (section 2.5.7 in NIST SP 800-22) */
|
||||
ATF_REQUIRE(matrix_m == 32);
|
||||
ATF_REQUIRE(matrix_q == 32);
|
||||
ATF_REQUIRE(numbits >= (38 * matrix_m * matrix_q));
|
||||
assert_int_equal(matrix_m, 32);
|
||||
assert_int_equal(matrix_q, 32);
|
||||
assert_true(numbits >= (38 * matrix_m * matrix_q));
|
||||
|
||||
fm_0 = 0;
|
||||
fm_1 = 0;
|
||||
|
|
@ -600,71 +630,83 @@ binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) {
|
|||
|
||||
chi_square = term1 + term2 + term3;
|
||||
|
||||
/* Debug message, not displayed when running via atf-run */
|
||||
printf("fm_0=%u, fm_1=%u, fm_rest=%u, chi_square=%f\n",
|
||||
fm_0, fm_1, fm_rest, chi_square);
|
||||
if (verbose) {
|
||||
print_message("# fm_0=%u, fm_1=%u, fm_rest=%u, chi_square=%f\n",
|
||||
fm_0, fm_1, fm_rest, chi_square);
|
||||
}
|
||||
|
||||
p_value = exp(-chi_square * 0.5);
|
||||
|
||||
return (p_value);
|
||||
}
|
||||
|
||||
ATF_TC(isc_rng_monobit);
|
||||
ATF_TC_HEAD(isc_rng_monobit, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Monobit test for the RNG");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_rng_monobit, tc) {
|
||||
UNUSED(tc);
|
||||
/* Monobit test for the RNG */
|
||||
static void
|
||||
isc_rng_monobit_bytes(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
random_test(monobit);
|
||||
}
|
||||
|
||||
ATF_TC(isc_rng_runs);
|
||||
ATF_TC_HEAD(isc_rng_runs, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Runs test for the RNG");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_rng_runs, tc) {
|
||||
UNUSED(tc);
|
||||
/* Runs test for the RNG */
|
||||
static void
|
||||
isc_rng_runs_bytes(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
random_test(runs);
|
||||
}
|
||||
|
||||
ATF_TC(isc_rng_blockfrequency);
|
||||
ATF_TC_HEAD(isc_rng_blockfrequency, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Block frequency test for the RNG");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(isc_rng_blockfrequency, tc) {
|
||||
UNUSED(tc);
|
||||
/* Block frequncy test for the RNG */
|
||||
static void
|
||||
isc_rng_blockfrequency_bytes(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
random_test(blockfrequency);
|
||||
}
|
||||
|
||||
ATF_TC(isc_rng_binarymatrixrank);
|
||||
ATF_TC_HEAD(isc_rng_binarymatrixrank, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "Binary matrix rank test for the RNG");
|
||||
}
|
||||
|
||||
/*
|
||||
* Binary matrix rank test for the RNG
|
||||
* This is the binary matrix rank test taken from the NIST SP 800-22 RNG
|
||||
* test suite.
|
||||
*/
|
||||
ATF_TC_BODY(isc_rng_binarymatrixrank, tc) {
|
||||
UNUSED(tc);
|
||||
static void
|
||||
isc_rng_binarymatrixrank_bytes(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
random_test(binarymatrixrank);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_rng_monobit);
|
||||
ATF_TP_ADD_TC(tp, isc_rng_runs);
|
||||
ATF_TP_ADD_TC(tp, isc_rng_blockfrequency);
|
||||
ATF_TP_ADD_TC(tp, isc_rng_binarymatrixrank);
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(isc_rng_monobit_bytes),
|
||||
cmocka_unit_test(isc_rng_runs_bytes),
|
||||
cmocka_unit_test(isc_rng_blockfrequency_bytes),
|
||||
cmocka_unit_test(isc_rng_binarymatrixrank_bytes),
|
||||
};
|
||||
int c;
|
||||
|
||||
return (atf_no_error());
|
||||
while ((c = isc_commandline_parse(argc, argv, "v")) != -1) {
|
||||
switch (c) {
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,31 +11,41 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#ifdef HAVE_REGEX_H
|
||||
#include <regex.h>
|
||||
#endif
|
||||
|
||||
#include <isc/commandline.h>
|
||||
#include <isc/regex.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
ATF_TC(regex_validate);
|
||||
ATF_TC_HEAD(regex_validate, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "check isc_regex_validate()");
|
||||
}
|
||||
ATF_TC_BODY(regex_validate, tc) {
|
||||
/* Set to true for verbose output */
|
||||
static bool verbose = false;
|
||||
|
||||
/* test isc_regex_validate() */
|
||||
static void
|
||||
regex_validate(void **state) {
|
||||
/*
|
||||
* test regex were generated using http://code.google.com/p/regfuzz/
|
||||
* modified to use only printable characters
|
||||
*/
|
||||
struct {
|
||||
const char * expression;
|
||||
const char *expression;
|
||||
int expect;
|
||||
int exception; /* regcomp accepts but is disallowed. */
|
||||
} tests[] = {
|
||||
|
|
@ -1070,7 +1080,7 @@ ATF_TC_BODY(regex_validate, tc) {
|
|||
unsigned int i;
|
||||
int r;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
#ifdef HAVE_REGEX_H
|
||||
/*
|
||||
|
|
@ -1083,19 +1093,29 @@ ATF_TC_BODY(regex_validate, tc) {
|
|||
r = regcomp(&preg, tests[i].expression, REG_EXTENDED);
|
||||
if (((r != 0 && tests[i].expect != -1) ||
|
||||
(r == 0 && tests[i].expect == -1)) && !tests[i].exception)
|
||||
fprintf(stderr, "regcomp(%s) -> %s expected %s\n",
|
||||
tests[i].expression, r != 0 ? "bad" : "good",
|
||||
tests[i].expect == -1 ? "bad" : "good");
|
||||
else if (r == 0 &&
|
||||
preg.re_nsub != (unsigned int)tests[i].expect &&
|
||||
!tests[i].exception) {
|
||||
fprintf(stderr, "%s preg.re_nsub %lu expected %d\n",
|
||||
tests[i].expression,
|
||||
(unsigned long)preg.re_nsub, tests[i].expect);
|
||||
tests[i].expect = preg.re_nsub;
|
||||
{
|
||||
if (verbose) {
|
||||
print_error("regcomp(%s) -> %s expected %s\n",
|
||||
tests[i].expression,
|
||||
r != 0 ? "bad" : "good",
|
||||
tests[i].expect == -1
|
||||
? "bad" : "good");
|
||||
}
|
||||
} else if (r == 0 &&
|
||||
preg.re_nsub != (unsigned int)tests[i].expect &&
|
||||
!tests[i].exception)
|
||||
{
|
||||
if (verbose) {
|
||||
print_error("%s preg.re_nsub %lu expected %d\n",
|
||||
tests[i].expression,
|
||||
(unsigned long)preg.re_nsub,
|
||||
tests[i].expect);
|
||||
}
|
||||
tests[i].expect = preg.re_nsub;
|
||||
}
|
||||
if (r == 0)
|
||||
if (r == 0) {
|
||||
regfree(&preg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1104,18 +1124,42 @@ ATF_TC_BODY(regex_validate, tc) {
|
|||
*/
|
||||
for (i = 0; i < sizeof(tests)/sizeof(*tests); i++) {
|
||||
r = isc_regex_validate(tests[i].expression);
|
||||
if (r != tests[i].expect)
|
||||
fprintf(stderr, "%s -> %d expected %d\n",
|
||||
tests[i].expression, r, tests[i].expect);
|
||||
ATF_CHECK_EQ(r, tests[i].expect);
|
||||
if (r != tests[i].expect) {
|
||||
print_error("# %s -> %d expected %d\n",
|
||||
tests[i].expression, r, tests[i].expect);
|
||||
}
|
||||
assert_int_equal(r, tests[i].expect);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, regex_validate);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(regex_validate),
|
||||
};
|
||||
int c;
|
||||
|
||||
while ((c = isc_commandline_parse(argc, argv, "v")) != -1) {
|
||||
switch (c) {
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,60 +9,61 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/safe.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
ATF_TC(isc_safe_memequal);
|
||||
ATF_TC_HEAD(isc_safe_memequal, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "safe memequal()");
|
||||
}
|
||||
ATF_TC_BODY(isc_safe_memequal, tc) {
|
||||
UNUSED(tc);
|
||||
/* test isc_safe_memequal() */
|
||||
static void
|
||||
isc_safe_memequal_test(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
ATF_CHECK(isc_safe_memequal("test", "test", 4));
|
||||
ATF_CHECK(!isc_safe_memequal("test", "tesc", 4));
|
||||
ATF_CHECK(isc_safe_memequal("\x00\x00\x00\x00",
|
||||
"\x00\x00\x00\x00", 4));
|
||||
ATF_CHECK(!isc_safe_memequal("\x00\x00\x00\x00",
|
||||
"\x00\x00\x00\x01", 4));
|
||||
ATF_CHECK(!isc_safe_memequal("\x00\x00\x00\x02",
|
||||
"\x00\x00\x00\x00", 4));
|
||||
assert_true(isc_safe_memequal("test", "test", 4));
|
||||
assert_true(!isc_safe_memequal("test", "tesc", 4));
|
||||
assert_true(isc_safe_memequal("\x00\x00\x00\x00",
|
||||
"\x00\x00\x00\x00", 4));
|
||||
assert_true(!isc_safe_memequal("\x00\x00\x00\x00",
|
||||
"\x00\x00\x00\x01", 4));
|
||||
assert_true(!isc_safe_memequal("\x00\x00\x00\x02",
|
||||
"\x00\x00\x00\x00", 4));
|
||||
}
|
||||
|
||||
ATF_TC(isc_safe_memcompare);
|
||||
ATF_TC_HEAD(isc_safe_memcompare, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "safe memcompare()");
|
||||
}
|
||||
ATF_TC_BODY(isc_safe_memcompare, tc) {
|
||||
UNUSED(tc);
|
||||
/* test isc_safe_memcompare() */
|
||||
static void
|
||||
isc_safe_memcompare_test(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
ATF_CHECK(isc_safe_memcompare("test", "test", 4) == 0);
|
||||
ATF_CHECK(isc_safe_memcompare("test", "tesc", 4) > 0);
|
||||
ATF_CHECK(isc_safe_memcompare("test", "tesy", 4) < 0);
|
||||
ATF_CHECK(isc_safe_memcompare("\x00\x00\x00\x00",
|
||||
"\x00\x00\x00\x00", 4) == 0);
|
||||
ATF_CHECK(isc_safe_memcompare("\x00\x00\x00\x00",
|
||||
"\x00\x00\x00\x01", 4) < 0);
|
||||
ATF_CHECK(isc_safe_memcompare("\x00\x00\x00\x02",
|
||||
"\x00\x00\x00\x00", 4) > 0);
|
||||
assert_int_equal(isc_safe_memcompare("test", "test", 4), 0);
|
||||
assert_true(isc_safe_memcompare("test", "tesc", 4) > 0);
|
||||
assert_true(isc_safe_memcompare("test", "tesy", 4) < 0);
|
||||
assert_int_equal(isc_safe_memcompare("\x00\x00\x00\x00",
|
||||
"\x00\x00\x00\x00", 4), 0);
|
||||
assert_true(isc_safe_memcompare("\x00\x00\x00\x00",
|
||||
"\x00\x00\x00\x01", 4) < 0);
|
||||
assert_true(isc_safe_memcompare("\x00\x00\x00\x02",
|
||||
"\x00\x00\x00\x00", 4) > 0);
|
||||
}
|
||||
|
||||
ATF_TC(isc_safe_memwipe);
|
||||
ATF_TC_HEAD(isc_safe_memwipe, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "isc_safe_memwipe()");
|
||||
}
|
||||
ATF_TC_BODY(isc_safe_memwipe, tc) {
|
||||
UNUSED(tc);
|
||||
/* test isc_safe_memwipe() */
|
||||
static void
|
||||
isc_safe_memwipe_test(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
/* These should pass. */
|
||||
isc_safe_memwipe(NULL, 0);
|
||||
|
|
@ -80,7 +81,7 @@ ATF_TC_BODY(isc_safe_memwipe, tc) {
|
|||
isc_safe_memwipe(buf1, sizeof(buf1));
|
||||
memset(buf2, 0, sizeof(buf2));
|
||||
|
||||
ATF_CHECK(memcmp(buf1, buf2, sizeof(buf1)) == 0);
|
||||
assert_int_equal(memcmp(buf1, buf2, sizeof(buf1)), 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -97,16 +98,29 @@ ATF_TC_BODY(isc_safe_memwipe, tc) {
|
|||
isc_safe_memwipe(buf1, 3);
|
||||
memset(buf2, 0, 3);
|
||||
|
||||
ATF_CHECK(memcmp(buf1, buf2, sizeof(buf1)) == 0);
|
||||
assert_int_equal(memcmp(buf1, buf2, sizeof(buf1)), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_safe_memequal);
|
||||
ATF_TP_ADD_TC(tp, isc_safe_memcompare);
|
||||
ATF_TP_ADD_TC(tp, isc_safe_memwipe);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(isc_safe_memequal_test),
|
||||
cmocka_unit_test(isc_safe_memwipe_test),
|
||||
cmocka_unit_test(isc_safe_memcompare_test),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,64 +9,79 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/netaddr.h>
|
||||
#include <isc/sockaddr.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
ATF_TC(sockaddr_hash);
|
||||
ATF_TC_HEAD(sockaddr_hash, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "sockaddr hash");
|
||||
}
|
||||
ATF_TC_BODY(sockaddr_hash, tc) {
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* test sockaddr hash */
|
||||
static void
|
||||
sockaddr_hash(void **state) {
|
||||
isc_sockaddr_t addr;
|
||||
struct in_addr in;
|
||||
struct in6_addr in6;
|
||||
unsigned int h1, h2, h3, h4;
|
||||
int ret;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
in.s_addr = inet_addr("127.0.0.1");
|
||||
isc_sockaddr_fromin(&addr, &in, 1);
|
||||
h1 = isc_sockaddr_hash(&addr, true);
|
||||
h2 = isc_sockaddr_hash(&addr, false);
|
||||
ATF_CHECK(h1 != h2);
|
||||
assert_int_not_equal(h1, h2);
|
||||
|
||||
ret = inet_pton(AF_INET6, "::ffff:127.0.0.1", &in6);
|
||||
ATF_CHECK(ret == 1);
|
||||
assert_int_equal(ret, 1);
|
||||
isc_sockaddr_fromin6(&addr, &in6, 1);
|
||||
h3 = isc_sockaddr_hash(&addr, true);
|
||||
h4 = isc_sockaddr_hash(&addr, false);
|
||||
ATF_CHECK(h1 == h3);
|
||||
ATF_CHECK(h2 == h4);
|
||||
|
||||
isc_test_end();
|
||||
assert_int_equal(h1, h3);
|
||||
assert_int_equal(h2, h4);
|
||||
}
|
||||
|
||||
ATF_TC(sockaddr_isnetzero);
|
||||
ATF_TC_HEAD(sockaddr_isnetzero, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "sockaddr is net zero");
|
||||
}
|
||||
ATF_TC_BODY(sockaddr_isnetzero, tc) {
|
||||
/* test isc_sockaddr_isnetzero() */
|
||||
static void
|
||||
sockaddr_isnetzero(void **state) {
|
||||
isc_sockaddr_t addr;
|
||||
struct in_addr in;
|
||||
struct in6_addr in6;
|
||||
|
|
@ -102,32 +117,30 @@ ATF_TC_BODY(sockaddr_isnetzero, tc) {
|
|||
{ "::ffff:255.255.255.255", false },
|
||||
};
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
for (i = 0; i < sizeof(data4)/sizeof(data4[0]); i++) {
|
||||
in.s_addr = inet_addr(data4[i].string);
|
||||
isc_sockaddr_fromin(&addr, &in, 1);
|
||||
r = isc_sockaddr_isnetzero(&addr);
|
||||
ATF_CHECK_EQ_MSG(r, data4[i].expect, "%s", data4[i].string);
|
||||
assert_int_equal(r, data4[i].expect);
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(data6)/sizeof(data6[0]); i++) {
|
||||
ret = inet_pton(AF_INET6, data6[i].string, &in6);
|
||||
ATF_CHECK_EQ(ret, 1);
|
||||
assert_int_equal(ret, 1);
|
||||
isc_sockaddr_fromin6(&addr, &in6, 1);
|
||||
r = isc_sockaddr_isnetzero(&addr);
|
||||
ATF_CHECK_EQ_MSG(r, data6[i].expect, "%s", data6[i].string);
|
||||
assert_int_equal(r, data6[i].expect);
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC(sockaddr_eqaddrprefix);
|
||||
ATF_TC_HEAD(sockaddr_eqaddrprefix, tc) {
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"isc_sockaddr_eqaddrprefix() returns true when "
|
||||
"prefixes of a and b are equal, and false when "
|
||||
"they are not equal");
|
||||
}
|
||||
ATF_TC_BODY(sockaddr_eqaddrprefix, tc) {
|
||||
/*
|
||||
* test that isc_sockaddr_eqaddrprefix() returns true when prefixes of a
|
||||
* and b are equal, and false when they are not equal
|
||||
*/
|
||||
static void
|
||||
sockaddr_eqaddrprefix(void **state) {
|
||||
struct in_addr ina_a;
|
||||
struct in_addr ina_b;
|
||||
struct in_addr ina_c;
|
||||
|
|
@ -135,32 +148,45 @@ ATF_TC_BODY(sockaddr_eqaddrprefix, tc) {
|
|||
isc_sockaddr_t isa_b;
|
||||
isc_sockaddr_t isa_c;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
ATF_CHECK(inet_pton(AF_INET, "194.100.32.87", &ina_a) >= 0);
|
||||
ATF_CHECK(inet_pton(AF_INET, "194.100.32.80", &ina_b) >= 0);
|
||||
ATF_CHECK(inet_pton(AF_INET, "194.101.32.87", &ina_c) >= 0);
|
||||
assert_true(inet_pton(AF_INET, "194.100.32.87", &ina_a) >= 0);
|
||||
assert_true(inet_pton(AF_INET, "194.100.32.80", &ina_b) >= 0);
|
||||
assert_true(inet_pton(AF_INET, "194.101.32.87", &ina_c) >= 0);
|
||||
|
||||
isc_sockaddr_fromin(&isa_a, &ina_a, 0);
|
||||
isc_sockaddr_fromin(&isa_b, &ina_b, 42);
|
||||
isc_sockaddr_fromin(&isa_c, &ina_c, 0);
|
||||
|
||||
ATF_CHECK(isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 0));
|
||||
ATF_CHECK(isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 29));
|
||||
ATF_CHECK(isc_sockaddr_eqaddrprefix(&isa_a, &isa_c, 8));
|
||||
assert_true(isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 0));
|
||||
assert_true(isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 29));
|
||||
assert_true(isc_sockaddr_eqaddrprefix(&isa_a, &isa_c, 8));
|
||||
|
||||
ATF_CHECK(! isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 30));
|
||||
ATF_CHECK(! isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 32));
|
||||
ATF_CHECK(! isc_sockaddr_eqaddrprefix(&isa_a, &isa_c, 16));
|
||||
assert_false(isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 30));
|
||||
assert_false(isc_sockaddr_eqaddrprefix(&isa_a, &isa_b, 32));
|
||||
assert_false(isc_sockaddr_eqaddrprefix(&isa_a, &isa_c, 16));
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, sockaddr_hash);
|
||||
ATF_TP_ADD_TC(tp, sockaddr_isnetzero);
|
||||
ATF_TP_ADD_TC(tp, sockaddr_eqaddrprefix);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(sockaddr_hash,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test(sockaddr_isnetzero),
|
||||
cmocka_unit_test(sockaddr_eqaddrprefix),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -9,51 +9,71 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/symtab.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
undefine(char *key, unsigned int type, isc_symvalue_t value, void *arg) {
|
||||
UNUSED(arg);
|
||||
|
||||
ATF_REQUIRE_EQ(type, 1);
|
||||
assert_int_equal(type, 1);
|
||||
isc_mem_free(mctx, key);
|
||||
isc_mem_free(mctx, value.as_pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
ATF_TC(symtab_grow);
|
||||
ATF_TC_HEAD(symtab_grow, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "symbol table growth");
|
||||
}
|
||||
ATF_TC_BODY(symtab_grow, tc) {
|
||||
/* test symbol table growth */
|
||||
static void
|
||||
symtab_grow(void **state) {
|
||||
isc_result_t result;
|
||||
isc_symtab_t *st = NULL;
|
||||
isc_symvalue_t value;
|
||||
isc_symexists_t policy = isc_symexists_reject;
|
||||
int i;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_symtab_create(mctx, 3, undefine, NULL, false, &st);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE(st != NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(st);
|
||||
|
||||
/* Nothing should be in the table yet */
|
||||
|
||||
|
|
@ -66,11 +86,11 @@ ATF_TC_BODY(symtab_grow, tc) {
|
|||
|
||||
snprintf(str, sizeof(str), "%04x", i);
|
||||
key = isc_mem_strdup(mctx, str);
|
||||
ATF_REQUIRE(key != NULL);
|
||||
assert_non_null(key);
|
||||
value.as_pointer = isc_mem_strdup(mctx, str);
|
||||
ATF_REQUIRE(value.as_pointer != NULL);
|
||||
assert_non_null(value.as_pointer);
|
||||
result = isc_symtab_define(st, key, 1, value, policy);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
undefine(key, 1, value, NULL);
|
||||
}
|
||||
|
|
@ -83,11 +103,11 @@ ATF_TC_BODY(symtab_grow, tc) {
|
|||
|
||||
snprintf(str, sizeof(str), "%04x", i);
|
||||
key = isc_mem_strdup(mctx, str);
|
||||
ATF_REQUIRE(key != NULL);
|
||||
assert_non_null(key);
|
||||
value.as_pointer = isc_mem_strdup(mctx, str);
|
||||
ATF_REQUIRE(value.as_pointer != NULL);
|
||||
assert_non_null(value.as_pointer);
|
||||
result = isc_symtab_define(st, key, 1, value, policy);
|
||||
ATF_CHECK_EQ(result, ISC_R_EXISTS);
|
||||
assert_int_equal(result, ISC_R_EXISTS);
|
||||
undefine(key, 1, value, NULL);
|
||||
}
|
||||
|
||||
|
|
@ -99,8 +119,8 @@ ATF_TC_BODY(symtab_grow, tc) {
|
|||
|
||||
snprintf(str, sizeof(str), "%04x", i);
|
||||
result = isc_symtab_lookup(st, str, 0, &value);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_CHECK_STREQ(str, (char *)value.as_pointer);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_string_equal(str, (char *)value.as_pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -111,7 +131,7 @@ ATF_TC_BODY(symtab_grow, tc) {
|
|||
|
||||
snprintf(str, sizeof(str), "%04x", i);
|
||||
result = isc_symtab_undefine(st, str, 1);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -122,19 +142,30 @@ ATF_TC_BODY(symtab_grow, tc) {
|
|||
|
||||
snprintf(str, sizeof(str), "%04x", i);
|
||||
result = isc_symtab_lookup(st, str, 0, &value);
|
||||
ATF_CHECK_EQ(result, ISC_R_NOTFOUND);
|
||||
assert_int_equal(result, ISC_R_NOTFOUND);
|
||||
}
|
||||
|
||||
isc_symtab_destroy(&st);
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, symtab_grow);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(symtab_grow,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -9,156 +9,152 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/taskpool.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Create a taskpool */
|
||||
ATF_TC(create_pool);
|
||||
ATF_TC_HEAD(create_pool, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create a taskpool");
|
||||
}
|
||||
ATF_TC_BODY(create_pool, tc) {
|
||||
static void
|
||||
create_pool(void **state) {
|
||||
isc_result_t result;
|
||||
isc_taskpool_t *pool = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_taskpool_create(taskmgr, mctx, 8, 2, &pool);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool), 8);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool), 8);
|
||||
|
||||
isc_taskpool_destroy(&pool);
|
||||
ATF_REQUIRE_EQ(pool, NULL);
|
||||
|
||||
isc_test_end();
|
||||
assert_null(pool);
|
||||
}
|
||||
|
||||
/* Resize a taskpool */
|
||||
ATF_TC(expand_pool);
|
||||
ATF_TC_HEAD(expand_pool, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "expand a taskpool");
|
||||
}
|
||||
ATF_TC_BODY(expand_pool, tc) {
|
||||
static void
|
||||
expand_pool(void **state) {
|
||||
isc_result_t result;
|
||||
isc_taskpool_t *pool1 = NULL, *pool2 = NULL, *hold = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_taskpool_create(taskmgr, mctx, 10, 2, &pool1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool1), 10);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool1), 10);
|
||||
|
||||
/* resizing to a smaller size should have no effect */
|
||||
hold = pool1;
|
||||
result = isc_taskpool_expand(&pool1, 5, &pool2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool2), 10);
|
||||
ATF_REQUIRE_EQ(pool2, hold);
|
||||
ATF_REQUIRE_EQ(pool1, NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool2), 10);
|
||||
assert_ptr_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
pool1 = pool2;
|
||||
pool2 = NULL;
|
||||
|
||||
/* resizing to the same size should have no effect */
|
||||
hold = pool1;
|
||||
result = isc_taskpool_expand(&pool1, 10, &pool2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool2), 10);
|
||||
ATF_REQUIRE_EQ(pool2, hold);
|
||||
ATF_REQUIRE_EQ(pool1, NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool2), 10);
|
||||
assert_ptr_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
pool1 = pool2;
|
||||
pool2 = NULL;
|
||||
|
||||
/* resizing to larger size should make a new pool */
|
||||
hold = pool1;
|
||||
result = isc_taskpool_expand(&pool1, 20, &pool2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool2), 20);
|
||||
ATF_REQUIRE(pool2 != hold);
|
||||
ATF_REQUIRE_EQ(pool1, NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool2), 20);
|
||||
assert_ptr_not_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
|
||||
isc_taskpool_destroy(&pool2);
|
||||
ATF_REQUIRE_EQ(pool2, NULL);
|
||||
|
||||
isc_test_end();
|
||||
assert_null(pool2);
|
||||
}
|
||||
|
||||
/* Get tasks */
|
||||
ATF_TC(get_tasks);
|
||||
ATF_TC_HEAD(get_tasks, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create a taskpool");
|
||||
}
|
||||
ATF_TC_BODY(get_tasks, tc) {
|
||||
static void
|
||||
get_tasks(void **state) {
|
||||
isc_result_t result;
|
||||
isc_taskpool_t *pool = NULL;
|
||||
isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_taskpool_create(taskmgr, mctx, 2, 2, &pool);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool), 2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool), 2);
|
||||
|
||||
/* two tasks in pool; make sure we can access them more than twice */
|
||||
isc_taskpool_gettask(pool, &task1);
|
||||
ATF_REQUIRE(ISCAPI_TASK_VALID(task1));
|
||||
assert_true(ISCAPI_TASK_VALID(task1));
|
||||
|
||||
isc_taskpool_gettask(pool, &task2);
|
||||
ATF_REQUIRE(ISCAPI_TASK_VALID(task2));
|
||||
assert_true(ISCAPI_TASK_VALID(task2));
|
||||
|
||||
isc_taskpool_gettask(pool, &task3);
|
||||
ATF_REQUIRE(ISCAPI_TASK_VALID(task3));
|
||||
assert_true(ISCAPI_TASK_VALID(task3));
|
||||
|
||||
isc_task_destroy(&task1);
|
||||
isc_task_destroy(&task2);
|
||||
isc_task_destroy(&task3);
|
||||
|
||||
isc_taskpool_destroy(&pool);
|
||||
ATF_REQUIRE_EQ(pool, NULL);
|
||||
|
||||
isc_test_end();
|
||||
assert_null(pool);
|
||||
}
|
||||
|
||||
/* Get tasks */
|
||||
ATF_TC(set_privilege);
|
||||
ATF_TC_HEAD(set_privilege, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "create a taskpool");
|
||||
}
|
||||
ATF_TC_BODY(set_privilege, tc) {
|
||||
/* Set privileges */
|
||||
static void
|
||||
set_privilege(void **state) {
|
||||
isc_result_t result;
|
||||
isc_taskpool_t *pool = NULL;
|
||||
isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_taskpool_create(taskmgr, mctx, 2, 2, &pool);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_taskpool_size(pool), 2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool), 2);
|
||||
|
||||
isc_taskpool_setprivilege(pool, true);
|
||||
|
||||
|
|
@ -166,39 +162,52 @@ ATF_TC_BODY(set_privilege, tc) {
|
|||
isc_taskpool_gettask(pool, &task2);
|
||||
isc_taskpool_gettask(pool, &task3);
|
||||
|
||||
ATF_CHECK(ISCAPI_TASK_VALID(task1));
|
||||
ATF_CHECK(ISCAPI_TASK_VALID(task2));
|
||||
ATF_CHECK(ISCAPI_TASK_VALID(task3));
|
||||
assert_true(ISCAPI_TASK_VALID(task1));
|
||||
assert_true(ISCAPI_TASK_VALID(task2));
|
||||
assert_true(ISCAPI_TASK_VALID(task3));
|
||||
|
||||
ATF_CHECK(isc_task_privilege(task1));
|
||||
ATF_CHECK(isc_task_privilege(task2));
|
||||
ATF_CHECK(isc_task_privilege(task3));
|
||||
assert_true(isc_task_privilege(task1));
|
||||
assert_true(isc_task_privilege(task2));
|
||||
assert_true(isc_task_privilege(task3));
|
||||
|
||||
isc_taskpool_setprivilege(pool, false);
|
||||
|
||||
ATF_CHECK(!isc_task_privilege(task1));
|
||||
ATF_CHECK(!isc_task_privilege(task2));
|
||||
ATF_CHECK(!isc_task_privilege(task3));
|
||||
assert_false(isc_task_privilege(task1));
|
||||
assert_false(isc_task_privilege(task2));
|
||||
assert_false(isc_task_privilege(task3));
|
||||
|
||||
isc_task_destroy(&task1);
|
||||
isc_task_destroy(&task2);
|
||||
isc_task_destroy(&task3);
|
||||
|
||||
isc_taskpool_destroy(&pool);
|
||||
ATF_REQUIRE_EQ(pool, NULL);
|
||||
|
||||
isc_test_end();
|
||||
assert_null(pool);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, create_pool);
|
||||
ATF_TP_ADD_TC(tp, expand_pool);
|
||||
ATF_TP_ADD_TC(tp, get_tasks);
|
||||
ATF_TP_ADD_TC(tp, set_privilege);
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(create_pool,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(expand_pool,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(get_tasks,
|
||||
_setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(set_privilege,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (atf_no_error());
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,37 +10,61 @@
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/time.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/time.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
ATF_TC(isc_time_parsehttptimestamp);
|
||||
ATF_TC_HEAD(isc_time_parsehttptimestamp, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "parse http time stamp");
|
||||
}
|
||||
ATF_TC_BODY(isc_time_parsehttptimestamp, tc) {
|
||||
/* parse http time stamp */
|
||||
static void
|
||||
isc_time_parsehttptimestamp_test(void **state) {
|
||||
isc_result_t result;
|
||||
isc_time_t t, x;
|
||||
char buf[ISC_FORMATHTTPTIMESTAMP_SIZE];
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
setenv("TZ", "PST8PDT", 1);
|
||||
result = isc_time_now(&t);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_time_formathttptimestamp(&t, buf, sizeof(buf));
|
||||
result = isc_time_parsehttptimestamp(buf, &x);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(isc_time_seconds(&t), isc_time_seconds(&x));
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_time_seconds(&t), isc_time_seconds(&x));
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_time_parsehttptimestamp);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(isc_time_parsehttptimestamp_test),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,15 +9,23 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/condition.h>
|
||||
#include <isc/commandline.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/platform.h>
|
||||
#include <isc/print.h>
|
||||
|
|
@ -25,7 +33,6 @@
|
|||
#include <isc/time.h>
|
||||
#include <isc/timer.h>
|
||||
#include <isc/util.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
|
|
@ -34,21 +41,43 @@
|
|||
*/
|
||||
#ifdef ISC_PLATFORM_USETHREADS
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
/* Set to true for verbose output */
|
||||
static bool verbose = false;
|
||||
|
||||
#define FUDGE_SECONDS 0 /* in absence of clock_getres() */
|
||||
#define FUDGE_NANOSECONDS 500000000 /* in absence of clock_getres() */
|
||||
|
||||
static isc_timer_t *timer = NULL;
|
||||
static isc_condition_t cv;
|
||||
static isc_mutex_t mx;
|
||||
static isc_time_t endtime;
|
||||
static isc_time_t lasttime;
|
||||
static int seconds;
|
||||
static int nanoseconds;
|
||||
static int eventcnt;
|
||||
static int nevents;
|
||||
static isc_timer_t *timer = NULL;
|
||||
static isc_condition_t cv;
|
||||
static isc_mutex_t mx;
|
||||
static isc_time_t endtime;
|
||||
static isc_time_t lasttime;
|
||||
static int seconds;
|
||||
static int nanoseconds;
|
||||
static int eventcnt;
|
||||
static int nevents;
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
/* Timer tests require two worker threads */
|
||||
result = isc_test_begin(NULL, true, 2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
shutdown(isc_task_t *task, isc_event_t *event) {
|
||||
|
|
@ -60,13 +89,13 @@ shutdown(isc_task_t *task, isc_event_t *event) {
|
|||
* Signal shutdown processing complete.
|
||||
*/
|
||||
result = isc_mutex_lock(&mx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_condition_signal(&cv);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_mutex_unlock(&mx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_event_free(&event);
|
||||
}
|
||||
|
|
@ -82,33 +111,33 @@ setup_test(isc_timertype_t timertype, isc_time_t *expires,
|
|||
eventcnt = 0;
|
||||
|
||||
result = isc_mutex_init(&mx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_condition_init(&cv);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
LOCK(&mx);
|
||||
|
||||
result = isc_task_create(taskmgr, 0, &task);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_task_onshutdown(task, shutdown, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_time_now(&lasttime);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_timer_create(timermgr, timertype, expires, interval,
|
||||
task, action, (void *)timertype,
|
||||
&timer);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Wait for shutdown processing to complete.
|
||||
*/
|
||||
while (eventcnt != nevents) {
|
||||
result = isc_condition_wait(&cv, &mx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
UNLOCK(&mx);
|
||||
|
|
@ -130,7 +159,9 @@ ticktock(isc_task_t *task, isc_event_t *event) {
|
|||
|
||||
++eventcnt;
|
||||
|
||||
printf("tick %d\n", eventcnt);
|
||||
if (verbose) {
|
||||
print_message("# tick %d\n", eventcnt);
|
||||
}
|
||||
|
||||
expected_event_type = ISC_TIMEREVENT_LIFE;
|
||||
if ((isc_timertype_t) event->ev_arg == isc_timertype_ticker) {
|
||||
|
|
@ -138,31 +169,31 @@ ticktock(isc_task_t *task, isc_event_t *event) {
|
|||
}
|
||||
|
||||
if (event->ev_type != expected_event_type) {
|
||||
printf("expected event type %u, got %u\n",
|
||||
expected_event_type, event->ev_type);
|
||||
print_error("# expected event type %u, got %u\n",
|
||||
expected_event_type, event->ev_type);
|
||||
}
|
||||
|
||||
result = isc_time_now(&now);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, seconds, nanoseconds);
|
||||
result = isc_time_add(&lasttime, &interval, &base);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, FUDGE_SECONDS, FUDGE_NANOSECONDS);
|
||||
result = isc_time_add(&base, &interval, &ulim);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_time_subtract(&base, &interval, &llim);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK(isc_time_compare(&llim, &now) <= 0);
|
||||
ATF_CHECK(isc_time_compare(&ulim, &now) >= 0);
|
||||
assert_true(isc_time_compare(&llim, &now) <= 0);
|
||||
assert_true(isc_time_compare(&ulim, &now) >= 0);
|
||||
lasttime = now;
|
||||
|
||||
if (eventcnt == nevents) {
|
||||
result = isc_time_now(&endtime);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_timer_detach(&timer);
|
||||
isc_task_shutdown(task);
|
||||
}
|
||||
|
|
@ -174,62 +205,46 @@ ticktock(isc_task_t *task, isc_event_t *event) {
|
|||
* Individual unit tests
|
||||
*/
|
||||
|
||||
ATF_TC(ticker);
|
||||
ATF_TC_HEAD(ticker, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "timer type ticker");
|
||||
}
|
||||
ATF_TC_BODY(ticker, tc) {
|
||||
isc_result_t result;
|
||||
/* timer type ticker */
|
||||
static void
|
||||
ticker(void **state) {
|
||||
isc_time_t expires;
|
||||
isc_interval_t interval;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
nevents = 12;
|
||||
seconds = 0;
|
||||
nanoseconds = 500000000;
|
||||
|
||||
result = isc_test_begin(NULL, true, 2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, seconds, nanoseconds);
|
||||
isc_time_settoepoch(&expires);
|
||||
|
||||
setup_test(isc_timertype_ticker, &expires, &interval, ticktock);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
ATF_TC(once_life);
|
||||
ATF_TC_HEAD(once_life, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "timer type once reaches lifetime");
|
||||
}
|
||||
ATF_TC_BODY(once_life, tc) {
|
||||
/* timer type once reaches lifetime */
|
||||
static void
|
||||
once_life(void **state) {
|
||||
isc_result_t result;
|
||||
isc_time_t expires;
|
||||
isc_interval_t interval;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
nevents = 1;
|
||||
seconds = 1;
|
||||
nanoseconds = 100000000;
|
||||
|
||||
result = isc_test_begin(NULL, true, 2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, seconds, nanoseconds);
|
||||
result = isc_time_nowplusinterval(&expires, &interval);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, 0, 0);
|
||||
|
||||
setup_test(isc_timertype_once, &expires, &interval, ticktock);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_idle(isc_task_t *task, isc_event_t *event) {
|
||||
isc_result_t result;
|
||||
|
|
@ -241,62 +256,58 @@ test_idle(isc_task_t *task, isc_event_t *event) {
|
|||
|
||||
++eventcnt;
|
||||
|
||||
printf("tick %d\n", eventcnt);
|
||||
if (verbose) {
|
||||
print_message("# tick %d\n", eventcnt);
|
||||
}
|
||||
|
||||
result = isc_time_now(&now);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, seconds, nanoseconds);
|
||||
result = isc_time_add(&lasttime, &interval, &base);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, FUDGE_SECONDS, FUDGE_NANOSECONDS);
|
||||
result = isc_time_add(&base, &interval, &ulim);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_time_subtract(&base, &interval, &llim);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK(isc_time_compare(&llim, &now) <= 0);
|
||||
ATF_CHECK(isc_time_compare(&ulim, &now) >= 0);
|
||||
assert_true(isc_time_compare(&llim, &now) <= 0);
|
||||
assert_true(isc_time_compare(&ulim, &now) >= 0);
|
||||
lasttime = now;
|
||||
|
||||
ATF_CHECK_EQ(event->ev_type, ISC_TIMEREVENT_IDLE);
|
||||
assert_int_equal(event->ev_type, ISC_TIMEREVENT_IDLE);
|
||||
|
||||
isc_timer_detach(&timer);
|
||||
isc_task_shutdown(task);
|
||||
isc_event_free(&event);
|
||||
}
|
||||
|
||||
ATF_TC(once_idle);
|
||||
ATF_TC_HEAD(once_idle, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "timer type once idles out");
|
||||
}
|
||||
ATF_TC_BODY(once_idle, tc) {
|
||||
/* timer type once idles out */
|
||||
static void
|
||||
once_idle(void **state) {
|
||||
isc_result_t result;
|
||||
isc_time_t expires;
|
||||
isc_interval_t interval;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
nevents = 1;
|
||||
seconds = 1;
|
||||
nanoseconds = 200000000;
|
||||
|
||||
result = isc_test_begin(NULL, true, 2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, seconds + 1, nanoseconds);
|
||||
result = isc_time_nowplusinterval(&expires, &interval);
|
||||
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, seconds, nanoseconds);
|
||||
|
||||
setup_test(isc_timertype_once, &expires, &interval, test_idle);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
/* timer reset */
|
||||
static void
|
||||
test_reset(isc_task_t *task, isc_event_t *event) {
|
||||
isc_result_t result;
|
||||
|
|
@ -309,46 +320,48 @@ test_reset(isc_task_t *task, isc_event_t *event) {
|
|||
|
||||
++eventcnt;
|
||||
|
||||
printf("tick %d\n", eventcnt);
|
||||
if (verbose) {
|
||||
print_message("# tick %d\n", eventcnt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check expired time.
|
||||
*/
|
||||
|
||||
result = isc_time_now(&now);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, seconds, nanoseconds);
|
||||
result = isc_time_add(&lasttime, &interval, &base);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, FUDGE_SECONDS, FUDGE_NANOSECONDS);
|
||||
result = isc_time_add(&base, &interval, &ulim);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_time_subtract(&base, &interval, &llim);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK(isc_time_compare(&llim, &now) <= 0);
|
||||
ATF_CHECK(isc_time_compare(&ulim, &now) >= 0);
|
||||
assert_true(isc_time_compare(&llim, &now) <= 0);
|
||||
assert_true(isc_time_compare(&ulim, &now) >= 0);
|
||||
lasttime = now;
|
||||
|
||||
if (eventcnt < 3) {
|
||||
ATF_CHECK_EQ(event->ev_type, ISC_TIMEREVENT_TICK);
|
||||
assert_int_equal(event->ev_type, ISC_TIMEREVENT_TICK);
|
||||
|
||||
if (eventcnt == 2) {
|
||||
isc_interval_set(&interval, seconds, nanoseconds);
|
||||
result = isc_time_nowplusinterval(&expires, &interval);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, 0, 0);
|
||||
result = isc_timer_reset(timer, isc_timertype_once,
|
||||
&expires, &interval,
|
||||
false);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
} else {
|
||||
ATF_CHECK_EQ(event->ev_type, ISC_TIMEREVENT_LIFE);
|
||||
assert_int_equal(event->ev_type, ISC_TIMEREVENT_LIFE);
|
||||
|
||||
isc_timer_detach(&timer);
|
||||
isc_task_shutdown(task);
|
||||
|
|
@ -357,19 +370,12 @@ test_reset(isc_task_t *task, isc_event_t *event) {
|
|||
isc_event_free(&event);
|
||||
}
|
||||
|
||||
ATF_TC(reset);
|
||||
ATF_TC_HEAD(reset, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "timer reset");
|
||||
}
|
||||
ATF_TC_BODY(reset, tc) {
|
||||
isc_result_t result;
|
||||
static void
|
||||
reset(void **state) {
|
||||
isc_time_t expires;
|
||||
isc_interval_t interval;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
nevents = 3;
|
||||
seconds = 0;
|
||||
|
|
@ -379,8 +385,6 @@ ATF_TC_BODY(reset, tc) {
|
|||
isc_time_settoepoch(&expires);
|
||||
|
||||
setup_test(isc_timertype_ticker, &expires, &interval, test_reset);
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
|
||||
static int startflag;
|
||||
|
|
@ -399,7 +403,9 @@ static void
|
|||
start_event(isc_task_t *task, isc_event_t *event) {
|
||||
UNUSED(task);
|
||||
|
||||
printf("start_event\n");
|
||||
if (verbose) {
|
||||
print_message("# start_event\n");
|
||||
}
|
||||
|
||||
LOCK(&mx);
|
||||
while (! startflag) {
|
||||
|
|
@ -419,7 +425,9 @@ tick_event(isc_task_t *task, isc_event_t *event) {
|
|||
UNUSED(task);
|
||||
|
||||
++eventcnt;
|
||||
printf("tick_event %d\n", eventcnt);
|
||||
if (verbose) {
|
||||
print_message("# tick_event %d\n", eventcnt);
|
||||
}
|
||||
|
||||
/*
|
||||
* On the first tick, purge all remaining tick events
|
||||
|
|
@ -430,7 +438,7 @@ tick_event(isc_task_t *task, isc_event_t *event) {
|
|||
isc_interval_set(&interval, seconds, 0);
|
||||
result = isc_timer_reset(tickertimer, isc_timertype_ticker,
|
||||
&expires, &interval, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_task_shutdown(task);
|
||||
}
|
||||
|
|
@ -442,7 +450,9 @@ static void
|
|||
once_event(isc_task_t *task, isc_event_t *event) {
|
||||
isc_result_t result;
|
||||
|
||||
printf("once_event\n");
|
||||
if (verbose) {
|
||||
print_message("# once_event\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Allow task1 to start processing events.
|
||||
|
|
@ -451,7 +461,7 @@ once_event(isc_task_t *task, isc_event_t *event) {
|
|||
startflag = 1;
|
||||
|
||||
result = isc_condition_broadcast(&cv);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
UNLOCK(&mx);
|
||||
|
||||
isc_event_free(&event);
|
||||
|
|
@ -465,7 +475,9 @@ shutdown_purge(isc_task_t *task, isc_event_t *event) {
|
|||
UNUSED(task);
|
||||
UNUSED(event);
|
||||
|
||||
printf("shutdown_event\n");
|
||||
if (verbose) {
|
||||
print_message("# shutdown_event\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Signal shutdown processing complete.
|
||||
|
|
@ -474,26 +486,21 @@ shutdown_purge(isc_task_t *task, isc_event_t *event) {
|
|||
shutdownflag = 1;
|
||||
|
||||
result = isc_condition_signal(&cv);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
UNLOCK(&mx);
|
||||
|
||||
isc_event_free(&event);
|
||||
}
|
||||
|
||||
ATF_TC(purge);
|
||||
ATF_TC_HEAD(purge, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "timer events purged");
|
||||
}
|
||||
ATF_TC_BODY(purge, tc) {
|
||||
/* timer events purged */
|
||||
static void
|
||||
purge(void **state) {
|
||||
isc_result_t result;
|
||||
isc_event_t *event = NULL;
|
||||
isc_time_t expires;
|
||||
isc_interval_t interval;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_test_begin(NULL, true, 2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
startflag = 0;
|
||||
shutdownflag = 0;
|
||||
|
|
@ -502,25 +509,25 @@ ATF_TC_BODY(purge, tc) {
|
|||
nanoseconds = 0;
|
||||
|
||||
result = isc_mutex_init(&mx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_condition_init(&cv);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_task_create(taskmgr, 0, &task1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_task_onshutdown(task1, shutdown_purge, NULL);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_task_create(taskmgr, 0, &task2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
LOCK(&mx);
|
||||
|
||||
event = isc_event_allocate(mctx, (void *)1 , (isc_eventtype_t)1,
|
||||
start_event, NULL, sizeof(*event));
|
||||
ATF_REQUIRE(event != NULL);
|
||||
assert_non_null(event);
|
||||
isc_task_send(task1, &event);
|
||||
|
||||
isc_time_settoepoch(&expires);
|
||||
|
|
@ -530,64 +537,74 @@ ATF_TC_BODY(purge, tc) {
|
|||
result = isc_timer_create(timermgr, isc_timertype_ticker,
|
||||
&expires, &interval, task1,
|
||||
tick_event, NULL, &tickertimer);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
oncetimer = NULL;
|
||||
|
||||
isc_interval_set(&interval, (seconds * 2) + 1, 0);
|
||||
result = isc_time_nowplusinterval(&expires, &interval);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_interval_set(&interval, 0, 0);
|
||||
result = isc_timer_create(timermgr, isc_timertype_once,
|
||||
&expires, &interval, task2,
|
||||
once_event, NULL, &oncetimer);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Wait for shutdown processing to complete.
|
||||
*/
|
||||
while (! shutdownflag) {
|
||||
result = isc_condition_wait(&cv, &mx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
UNLOCK(&mx);
|
||||
|
||||
ATF_CHECK_EQ(eventcnt, 1);
|
||||
assert_int_equal(eventcnt, 1);
|
||||
|
||||
isc_timer_detach(&tickertimer);
|
||||
isc_timer_detach(&oncetimer);
|
||||
isc_task_destroy(&task1);
|
||||
isc_task_destroy(&task2);
|
||||
DESTROYLOCK(&mx);
|
||||
}
|
||||
|
||||
isc_test_end();
|
||||
}
|
||||
#else
|
||||
ATF_TC(untested);
|
||||
ATF_TC_HEAD(untested, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "skipping nsec3 test");
|
||||
}
|
||||
ATF_TC_BODY(untested, tc) {
|
||||
UNUSED(tc);
|
||||
atf_tc_skip("DNSSEC not available");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
#ifdef ISC_PLATFORM_USETHREADS
|
||||
ATF_TP_ADD_TC(tp, ticker);
|
||||
ATF_TP_ADD_TC(tp, once_life);
|
||||
ATF_TP_ADD_TC(tp, once_idle);
|
||||
ATF_TP_ADD_TC(tp, reset);
|
||||
ATF_TP_ADD_TC(tp, purge);
|
||||
#else
|
||||
ATF_TP_ADD_TC(tp, untested);
|
||||
cmocka_unit_test_setup_teardown(ticker, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(once_life, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(once_idle, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(reset, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(purge, _setup, _teardown),
|
||||
#endif
|
||||
};
|
||||
int c;
|
||||
|
||||
while ((c = isc_commandline_parse(argc, argv, "v")) != -1) {
|
||||
switch (c) {
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
#endif
|
||||
|
||||
return (atf_no_error());
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -27,10 +27,8 @@ ISCDEPLIBS = ../../isc/libisc.@A@
|
|||
ISCCCLIBS = ../libisccc.@A@
|
||||
ISCCCDEPLIBS = ../libisccc.@A@
|
||||
|
||||
LIBS = @LIBS@ @ATFLIBS@
|
||||
|
||||
CMOCKA_CFLAGS = @CMOCKA_CFLAGS@
|
||||
CMOCKA_LIBS = @CMOCKA_LIBS@
|
||||
CFLAGS = @CFLAGS@ @CMOCKA_CFLAGS@
|
||||
LIBS = @LIBS@ @CMOCKA_LIBS@
|
||||
|
||||
OBJS =
|
||||
SRCS = result_test.c
|
||||
|
|
@ -40,9 +38,9 @@ TARGETS = result_test@EXEEXT@
|
|||
@BIND9_MAKE_RULES@
|
||||
|
||||
result_test@EXEEXT@: result_test.@O@ ${ISCDEPLIBS} ${ISCCCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_FLAGS} \
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ result_test.@O@ \
|
||||
${ISCCCLIBS} ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
|
||||
${ISCCCLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
unit::
|
||||
sh ${top_builddir}/unit/unittest.sh
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: tests
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: parser_test
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
syntax(2)
|
||||
test_suite('bind9')
|
||||
|
||||
atf_test_program{name='parser_test'}
|
||||
tap_test_program{name='parser_test'}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ srcdir = @srcdir@
|
|||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
# Attempt to disable parallel processing.
|
||||
.NOTPARALLEL:
|
||||
.NO_PARALLEL:
|
||||
|
||||
VERSION=@BIND9_VERSION@
|
||||
|
||||
@BIND9_MAKE_INCLUDES@
|
||||
|
|
@ -31,7 +27,8 @@ DNSDEPLIBS = ../../dns/libdns.@A@
|
|||
ISCCFGLIBS = ../libisccfg.@A@
|
||||
ISCCFGDEPLIBS = ../libisccfg.@A@
|
||||
|
||||
LIBS = @LIBS@ @ATFLIBS@
|
||||
CFLAGS = @CFLAGS@ @CMOCKA_CFLAGS@
|
||||
LIBS = @LIBS@ @CMOCKA_LIBS@
|
||||
|
||||
OBJS =
|
||||
SRCS = parser_test.c
|
||||
|
|
@ -42,9 +39,9 @@ TARGETS = parser_test@EXEEXT@
|
|||
@BIND9_MAKE_RULES@
|
||||
|
||||
parser_test@EXEEXT@: parser_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} ${ISCCFGDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
parser_test.@O@ ${ISCCFGLIBS} ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
|
||||
${LDFLAGS} -o $@ parser_test.@O@ \
|
||||
${ISCCFGLIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS}
|
||||
|
||||
unit::
|
||||
sh ${top_builddir}/unit/unittest.sh
|
||||
|
|
|
|||
|
|
@ -11,17 +11,25 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/lex.h>
|
||||
#include <isc/log.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/types.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
|
|
@ -52,10 +60,12 @@ static isc_logcategory_t categories[] = {
|
|||
|
||||
static void
|
||||
cleanup() {
|
||||
if (lctx != NULL)
|
||||
if (lctx != NULL) {
|
||||
isc_log_destroy(&lctx);
|
||||
if (mctx != NULL)
|
||||
}
|
||||
if (mctx != NULL) {
|
||||
isc_mem_destroy(&mctx);
|
||||
}
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
|
|
@ -89,18 +99,16 @@ setup() {
|
|||
return (result);
|
||||
}
|
||||
|
||||
ATF_TC(parse_buffer);
|
||||
ATF_TC_HEAD(parse_buffer, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "cfg_parse_buffer");
|
||||
}
|
||||
ATF_TC_BODY(parse_buffer, tc) {
|
||||
/* test cfg_parse_buffer() */
|
||||
static void
|
||||
parse_buffer_test(void **state) {
|
||||
isc_result_t result;
|
||||
unsigned char text[] = "options\n{\nrecursion yes;\n};\n";
|
||||
isc_buffer_t buf1, buf2;
|
||||
cfg_parser_t *p1 = NULL, *p2 = NULL;
|
||||
cfg_obj_t *c1 = NULL, *c2 = NULL;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
setup();
|
||||
|
||||
|
|
@ -109,24 +117,24 @@ ATF_TC_BODY(parse_buffer, tc) {
|
|||
|
||||
/* Parse with default line numbering */
|
||||
result = cfg_parser_create(mctx, lctx, &p1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = cfg_parse_buffer3(p1, &buf1, "text1", 0,
|
||||
&cfg_type_namedconf, &c1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(p1->line, 5);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(p1->line, 5);
|
||||
|
||||
isc_buffer_init(&buf2, &text[0], sizeof(text) - 1);
|
||||
isc_buffer_add(&buf2, sizeof(text) - 1);
|
||||
|
||||
/* Parse with changed line number */
|
||||
result = cfg_parser_create(mctx, lctx, &p2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = cfg_parse_buffer3(p2, &buf2, "text2", 100,
|
||||
&cfg_type_namedconf, &c2);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(p2->line, 104);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(p2->line, 104);
|
||||
|
||||
cfg_obj_destroy(p1, &c1);
|
||||
cfg_obj_destroy(p2, &c2);
|
||||
|
|
@ -137,56 +145,65 @@ ATF_TC_BODY(parse_buffer, tc) {
|
|||
cleanup();
|
||||
}
|
||||
|
||||
ATF_TC(cfg_map_firstclause);
|
||||
ATF_TC_HEAD(cfg_map_firstclause, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "cfg_map_firstclause");
|
||||
}
|
||||
ATF_TC_BODY(cfg_map_firstclause, tc) {
|
||||
/* test cfg_map_firstclause() */
|
||||
static void
|
||||
cfg_map_firstclause_test(void **state) {
|
||||
const char *name = NULL;
|
||||
const void *clauses = NULL;
|
||||
unsigned int idx;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
name = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx);
|
||||
ATF_CHECK(name != NULL);
|
||||
ATF_CHECK(clauses != NULL);
|
||||
ATF_CHECK_EQ(idx, 0);
|
||||
assert_non_null(name);
|
||||
assert_non_null(clauses);
|
||||
assert_int_equal(idx, 0);
|
||||
}
|
||||
|
||||
ATF_TC(cfg_map_nextclause);
|
||||
ATF_TC_HEAD(cfg_map_nextclause, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "cfg_map_firstclause");
|
||||
}
|
||||
ATF_TC_BODY(cfg_map_nextclause, tc) {
|
||||
/* test cfg_map_nextclause() */
|
||||
static void
|
||||
cfg_map_nextclause_test(void **state) {
|
||||
const char *name = NULL;
|
||||
const void *clauses = NULL;
|
||||
unsigned int idx;
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
name = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx);
|
||||
ATF_REQUIRE(name != NULL);
|
||||
ATF_REQUIRE(clauses != NULL);
|
||||
ATF_REQUIRE_EQ(idx, ISC_R_SUCCESS);
|
||||
assert_non_null(name);
|
||||
assert_non_null(clauses);
|
||||
assert_int_equal(idx, ISC_R_SUCCESS);
|
||||
|
||||
do {
|
||||
name = cfg_map_nextclause(&cfg_type_zoneopts, &clauses, &idx);
|
||||
if (name != NULL) {
|
||||
ATF_CHECK(clauses != NULL);
|
||||
assert_non_null(clauses);
|
||||
} else {
|
||||
ATF_CHECK_EQ(clauses, NULL);
|
||||
ATF_CHECK_EQ(idx, 0);
|
||||
assert_null(clauses);
|
||||
assert_int_equal(idx, 0);
|
||||
}
|
||||
} while (name != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, parse_buffer);
|
||||
ATF_TP_ADD_TC(tp, cfg_map_firstclause);
|
||||
ATF_TP_ADD_TC(tp, cfg_map_nextclause);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(parse_buffer_test),
|
||||
cmocka_unit_test(cfg_map_firstclause_test),
|
||||
cmocka_unit_test(cfg_map_nextclause_test),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: tests
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp: config_test
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
syntax(2)
|
||||
test_suite('bind9')
|
||||
|
||||
atf_test_program{name='config_test'}
|
||||
tap_test_program{name='config_test'}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@
|
|||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
# $Id$
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
|
@ -21,13 +19,14 @@ VERSION=@BIND9_VERSION@
|
|||
|
||||
@BIND9_MAKE_INCLUDES@
|
||||
|
||||
CINCLUDES = -I. -Iinclude -I../include ${LWRES_INCLUDES}
|
||||
CINCLUDES = -I. -Iinclude -I../include ${LWRES_INCLUDES} ${ISC_INCLUDES}
|
||||
CDEFINES = -DTESTS="\"${top_builddir}/lib/lwres/tests/\""
|
||||
|
||||
LWRESLIBS = ../liblwres.@A@
|
||||
LWRESDEPLIBS = ../liblwres.@A@
|
||||
|
||||
LIBS = @LIBS@ @ATFLIBS@
|
||||
CFLAGS = @CFLAGS@ @CMOCKA_CFLAGS@
|
||||
LIBS = @LIBS@ @CMOCKA_LIBS@
|
||||
|
||||
OBJS =
|
||||
SRCS = config_test.c
|
||||
|
|
|
|||
|
|
@ -11,30 +11,37 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
|
||||
#include "../lwconfig.c"
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
static void
|
||||
setup_test() {
|
||||
/*
|
||||
* atf-run changes us to a /tmp directory, so tests
|
||||
* The caller might run from another directory, so tests
|
||||
* that access test data files must first chdir to the proper
|
||||
* location.
|
||||
*/
|
||||
ATF_CHECK(chdir(TESTS) != -1);
|
||||
assert_int_not_equal(chdir(TESTS), -1);
|
||||
}
|
||||
|
||||
ATF_TC(parse_linklocal);
|
||||
ATF_TC_HEAD(parse_linklocal, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "lwres_conf_parse link-local nameserver");
|
||||
}
|
||||
ATF_TC_BODY(parse_linklocal, tc) {
|
||||
/* lwres_conf_parse link-local nameserver */
|
||||
static void
|
||||
parse_linklocal(void **state) {
|
||||
lwres_result_t result;
|
||||
lwres_context_t *ctx = NULL;
|
||||
unsigned char addr[16] = { 0xfe, 0x80, 0x00, 0x00,
|
||||
|
|
@ -42,27 +49,40 @@ ATF_TC_BODY(parse_linklocal, tc) {
|
|||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01 };
|
||||
|
||||
UNUSED(tc);
|
||||
UNUSED(state);
|
||||
|
||||
setup_test();
|
||||
|
||||
lwres_context_create(&ctx, NULL, NULL, NULL,
|
||||
LWRES_CONTEXT_USEIPV4 | LWRES_CONTEXT_USEIPV6);
|
||||
ATF_CHECK_EQ(ctx->confdata.nsnext, 0);
|
||||
ATF_CHECK_EQ(ctx->confdata.nameservers[0].zone, 0);
|
||||
assert_int_equal(ctx->confdata.nsnext, 0);
|
||||
assert_int_equal(ctx->confdata.nameservers[0].zone, 0);
|
||||
|
||||
result = lwres_conf_parse(ctx, "testdata/link-local.conf");
|
||||
ATF_CHECK_EQ(result, LWRES_R_SUCCESS);
|
||||
ATF_CHECK_EQ(ctx->confdata.nsnext, 1);
|
||||
ATF_CHECK_EQ(ctx->confdata.nameservers[0].zone, 1);
|
||||
ATF_CHECK_EQ(memcmp(ctx->confdata.nameservers[0].address, addr, 16), 0);
|
||||
assert_int_equal(result, LWRES_R_SUCCESS);
|
||||
assert_int_equal(ctx->confdata.nsnext, 1);
|
||||
assert_int_equal(ctx->confdata.nameservers[0].zone, 1);
|
||||
assert_memory_equal(ctx->confdata.nameservers[0].address, addr, 16);
|
||||
lwres_context_destroy(&ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, parse_linklocal);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(parse_linklocal),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
|
||||
# Attempt to disable parallel processing.
|
||||
.NOTPARALLEL:
|
||||
.NO_PARALLEL:
|
||||
SUBDIRS = @ATFBUILD@
|
||||
TARGETS = atf
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
||||
#
|
||||
# install ATF libraries, if configured with --with-atf
|
||||
#
|
||||
atf:
|
||||
@for i in ${ALL_SUBDIRS}; do \
|
||||
if [ "$$i" != "nulldir" -a -d $$i ]; then \
|
||||
(cd $$i; ${MAKE} ${MAKEDEFS} install) || exit 1; \
|
||||
fi; \
|
||||
done
|
||||
|
||||
clean distclean::
|
||||
rm -rf ./atf
|
||||
|
||||
distclean::
|
||||
rm unittest.sh
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
language: cpp
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
before_install:
|
||||
- ./admin/travis-install-deps.sh
|
||||
|
||||
env:
|
||||
- AS_ROOT=no
|
||||
- AS_ROOT=yes
|
||||
|
||||
script:
|
||||
- ./admin/travis-build.sh
|
||||
|
||||
notifications:
|
||||
email:
|
||||
- atf-log@googlegroups.com
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
Authors and contributors Automated Testing Framework
|
||||
===========================================================================
|
||||
|
||||
|
||||
* Julio Merino <jmmv@NetBSD.org>
|
||||
|
||||
Main developer. He started the work on this project when he took part in
|
||||
the Google Summer of Code 2007 program as a student.
|
||||
|
||||
* Martin Husemann <martin@NetBSD.org>
|
||||
|
||||
Mentored this project during its development as part of the Google Summer
|
||||
of Code 2007 program.
|
||||
|
||||
* Lukasz Strzygowski <qx89l4@gmail.com>
|
||||
|
||||
Participant of the Google Summer of Code 2008 program. Mentored by The
|
||||
NetBSD Foundation, he worked on the atfify NetBSD-SoC project and, as a
|
||||
side-effect, he contributed to the ATF source code. He developed the
|
||||
initial version of the atf-check utility and started the addition of the
|
||||
ATF_REQUIRE family of macros in the C interface.
|
||||
|
||||
* Paul Goyette <pgoyette@NetBSD.org>
|
||||
|
||||
Implemented timestamping of test programs and test cases so that
|
||||
atf-report can provide timings for their execution.
|
||||
|
||||
|
||||
===========================================================================
|
||||
vim: filetype=text:textwidth=75:expandtab:shiftwidth=2:softtabstop=2
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = atf
|
||||
|
||||
tp: atf-c
|
||||
tp: atf-c++
|
||||
tp: atf-sh
|
||||
tp: test-programs
|
||||
|
||||
tp-glob: tools*
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
Redistribution terms Automated Testing Framework
|
||||
===========================================================================
|
||||
|
||||
|
||||
License
|
||||
*******
|
||||
|
||||
Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012 The NetBSD Foundation, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Copyright 2011, 2012 Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of Google Inc. nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Relicensed code
|
||||
***************
|
||||
|
||||
The following code snippets have been taken from other projects. Even
|
||||
though they were not originally licensed under the terms above, the
|
||||
original authors have agreed to relicense their work so that this project
|
||||
can be distributed under a single license. This section is put here just to
|
||||
clarify this fact.
|
||||
|
||||
* configure.ac, Makefile.am: The original versions were derived from the
|
||||
ones in the XML Catalog Manager project, version 2.2.
|
||||
|
||||
Author: Julio Merino <jmmv@users.sourceforge.net>
|
||||
|
||||
* atf-c/ui.c: The format_paragraph and format_text functions were
|
||||
derived form the ones in the Monotone project, revision
|
||||
3a0982da308228d796df35f98d787c5cff2bb5b6.
|
||||
|
||||
Author: Julio Merino <jmmv@NetBSD.org>
|
||||
|
||||
* atf-c++/detail/io.hpp, atf-c++/detail/io.cpp, atf-c++/detail/io_test.cpp:
|
||||
These files were derived from the file_handle, systembuf, pipe and pistream
|
||||
classes and tests found in the Boost.Process library.
|
||||
|
||||
Author: Julio Merino <jmmv84@gmail.com>
|
||||
|
||||
* admin/check-style.sh, admin/check-style-common.awk,
|
||||
admin/check-style-cpp.awk, admin/check-style-shell.awk: These files,
|
||||
except the first one, were first implemented in the Buildtool project.
|
||||
They were later adapted to be part of Boost.Process and, during that
|
||||
process, the shell script was created.
|
||||
|
||||
Author: Julio Merino <jmmv84@gmail.com>
|
||||
|
||||
|
||||
===========================================================================
|
||||
vim: filetype=text:textwidth=75:expandtab:shiftwidth=2:softtabstop=2
|
||||
|
|
@ -1,223 +0,0 @@
|
|||
Installation instructions Automated Testing Framework
|
||||
===========================================================================
|
||||
|
||||
|
||||
Introduction
|
||||
************
|
||||
|
||||
ATF uses the GNU Automake, GNU Autoconf and GNU Libtool utilities as its
|
||||
build system. These are used only when compiling the application from the
|
||||
source code package. If you want to install ATF from a binary package, you
|
||||
do not need to read this document.
|
||||
|
||||
For the impatient:
|
||||
|
||||
$ ./configure
|
||||
$ make
|
||||
Gain root privileges
|
||||
# make install
|
||||
Drop root privileges
|
||||
$ make installcheck
|
||||
|
||||
Or alternatively, install as a regular user into your home directory:
|
||||
|
||||
$ ./configure --prefix ~/local
|
||||
$ make
|
||||
$ make install
|
||||
$ make installcheck
|
||||
|
||||
|
||||
Dependencies
|
||||
************
|
||||
|
||||
To build and use ATF successfully you need:
|
||||
|
||||
* A standards-compliant C/C++ complier. For example, GNU GCC 2.95 will not
|
||||
work.
|
||||
|
||||
* A POSIX shell interpreter.
|
||||
|
||||
* A make(1) utility.
|
||||
|
||||
If you are building ATF from the code on the repository, you will also need
|
||||
to have GNU autoconf, automake and libtool installed.
|
||||
|
||||
|
||||
Regenerating the build system
|
||||
*****************************
|
||||
|
||||
If you are building ATF from code extracted from the repository, you must
|
||||
first regenerate the files used by the build system. You will also need to
|
||||
do this if you modify configure.ac, Makefile.am or any of the other build
|
||||
system files. To do this, simply run:
|
||||
|
||||
$ autoreconf -i -s
|
||||
|
||||
For formal releases, no extra steps are needed.
|
||||
|
||||
|
||||
General build procedure
|
||||
***********************
|
||||
|
||||
To build and install the source package, you must follow these steps:
|
||||
|
||||
1. Configure the sources to adapt to your operating system. This is done
|
||||
using the 'configure' script located on the sources' top directory,
|
||||
and it is usually invoked without arguments unless you want to change
|
||||
the installation prefix. More details on this procedure are given on a
|
||||
later section.
|
||||
|
||||
2. Build the sources to generate the binaries and scripts. Simply run
|
||||
'make' on the sources' top directory after configuring them. No
|
||||
problems should arise.
|
||||
|
||||
3. Install the program by running 'make install'. You may need to become
|
||||
root to issue this step.
|
||||
|
||||
4. Issue any manual installation steps that may be required. These are
|
||||
described later in their own section.
|
||||
|
||||
5. Check that the installed programs work by running 'make installcheck'.
|
||||
You do not need to be root to do this, even though some checks will not
|
||||
be run otherwise.
|
||||
|
||||
|
||||
Configuration flags
|
||||
*******************
|
||||
|
||||
The most common, standard flags given to 'configure' are:
|
||||
|
||||
* --prefix=directory
|
||||
Possible values: Any path
|
||||
Default: /usr/local
|
||||
|
||||
Specifies where the program (binaries and all associated files) will
|
||||
be installed.
|
||||
|
||||
* --sysconfdir=directory
|
||||
Possible values: Any path
|
||||
Default: /usr/local/etc
|
||||
|
||||
Specifies where the installed programs will look for configuration files.
|
||||
'/atf' will be appended to the given path unless ATF_CONFSUBDIR is
|
||||
redefined as explained later on.
|
||||
|
||||
* --help
|
||||
Shows information about all available flags and exits immediately,
|
||||
without running any configuration tasks.
|
||||
|
||||
The following environment variables are specific to ATF's 'configure'
|
||||
script:
|
||||
|
||||
* ATF_BUILD_CC
|
||||
Possible values: empty, a absolute or relative path to a C compiler.
|
||||
Default: the value of CC as detected by the configure script.
|
||||
|
||||
Specifies the C compiler that ATF will use at run time whenever the
|
||||
build-time-specific checks are used.
|
||||
|
||||
* ATF_BUILD_CFLAGS
|
||||
Possible values: empty, a list of valid C compiler flags.
|
||||
Default: the value of CFLAGS as detected by the configure script.
|
||||
|
||||
Specifies the C compiler flags that ATF will use at run time whenever the
|
||||
build-time-specific checks are used.
|
||||
|
||||
* ATF_BUILD_CPP
|
||||
Possible values: empty, a absolute or relative path to a C/C++
|
||||
preprocessor.
|
||||
Default: the value of CPP as detected by the configure script.
|
||||
|
||||
Specifies the C/C++ preprocessor that ATF will use at run time whenever
|
||||
the build-time-specific checks are used.
|
||||
|
||||
* ATF_BUILD_CPPFLAGS
|
||||
Possible values: empty, a list of valid C/C++ preprocessor flags.
|
||||
Default: the value of CPPFLAGS as detected by the configure script.
|
||||
|
||||
Specifies the C/C++ preprocessor flags that ATF will use at run time
|
||||
whenever the build-time-specific checks are used.
|
||||
|
||||
* ATF_BUILD_CXX
|
||||
Possible values: empty, a absolute or relative path to a C++ compiler.
|
||||
Default: the value of CXX as detected by the configure script.
|
||||
|
||||
Specifies the C++ compiler that ATF will use at run time whenever the
|
||||
build-time-specific checks are used.
|
||||
|
||||
* ATF_BUILD_CXXFLAGS
|
||||
Possible values: empty, a list of valid C++ compiler flags.
|
||||
Default: the value of CXXFLAGS as detected by the configure script.
|
||||
|
||||
Specifies the C++ compiler flags that ATF will use at run time whenever
|
||||
the build-time-specific checks are used.
|
||||
|
||||
* ATF_CONFSUBDIR
|
||||
Possible values: empty, a relative path.
|
||||
Default: atf.
|
||||
|
||||
Specifies the subdirectory of the configuration directory (given by the
|
||||
--sysconfdir argument) under which ATF will search for its configuration
|
||||
files.
|
||||
|
||||
* ATF_SHELL
|
||||
Possible values: empty, absolute path to a POSIX shell interpreter.
|
||||
Default: empty.
|
||||
|
||||
Specifies the POSIX shell interpreter that ATF will use at run time to
|
||||
execute its scripts and the test programs written using the atf-sh
|
||||
library. If empty, the configure script will try to find a suitable
|
||||
interpreter for you.
|
||||
|
||||
* ATF_WORKDIR
|
||||
Possible values: empty, an absolute path.
|
||||
Default: /tmp or /var/tmp, depending on availability.
|
||||
|
||||
Specifies the directory that ATF will use to place its temporary files
|
||||
and work directories for test cases. This is just a default and can be
|
||||
overriden at run time.
|
||||
|
||||
* GDB
|
||||
Possible values: empty, absolute path to GNU GDB.
|
||||
Default: empty.
|
||||
|
||||
Specifies the path to the GNU GDB binary that atf-run will use to gather
|
||||
a stack trace of a crashing test program. If empty, the configure script
|
||||
will try to find a suitable binary for you.
|
||||
|
||||
The following flags are specific to ATF's 'configure' script:
|
||||
|
||||
* --enable-developer
|
||||
Possible values: yes, no
|
||||
Default: 'yes' in Git HEAD builds; 'no' in formal releases.
|
||||
|
||||
Enables several features useful for development, such as the inclusion
|
||||
of debugging symbols in all objects or the enforcement of compilation
|
||||
warnings.
|
||||
|
||||
The compiler will be executed with an exhaustive collection of warning
|
||||
detection features regardless of the value of this flag. However, such
|
||||
warnings are only fatal when --enable-developer is 'yes'.
|
||||
|
||||
* --enable-tools
|
||||
Possible values: yes, no
|
||||
Default: no.
|
||||
|
||||
Enables the build of the deprecated atf-config, atf-report, atf-run
|
||||
and atf-version tools. atf-report and atf-run have been superseded by
|
||||
Kyua, and atf-config and atf-version are unnecessary.
|
||||
|
||||
|
||||
Post-installation steps
|
||||
***********************
|
||||
|
||||
After installing ATF, you have to register the DTDs it provides into the
|
||||
system-wide XML catalog. See the comments at the top of the files in
|
||||
${datadir}/share/xml/atf to see the correct public identifiers. This
|
||||
directory will typically be /usr/local/share/xml/atf or /usr/share/xml/atf.
|
||||
Failure to do so will lead to further errors when processing the XML files
|
||||
generated by atf-report.
|
||||
|
||||
|
||||
===========================================================================
|
||||
vim: filetype=text:textwidth=75:expandtab:shiftwidth=2:softtabstop=2
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
syntax("kyuafile", 1)
|
||||
|
||||
test_suite("atf")
|
||||
|
||||
include("atf-c/Kyuafile")
|
||||
include("atf-c++/Kyuafile")
|
||||
include("atf-sh/Kyuafile")
|
||||
include("test-programs/Kyuafile")
|
||||
|
||||
if fs.exists("tools/Kyuafile") then
|
||||
include("tools/Kyuafile")
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue