diff options
author | Cy Schubert <cy@FreeBSD.org> | 2015-03-30 13:30:15 +0000 |
---|---|---|
committer | Cy Schubert <cy@FreeBSD.org> | 2015-03-30 13:30:15 +0000 |
commit | 2b15cb3d0922bd70ea592f0da9b4a5b167f4d53f (patch) | |
tree | 388af01c574ac107295ae453bab1e272bbfcda27 /contrib/ntp/sntp/tests | |
parent | a83592093c063d2b02127a1de7c7c93d5f600bd2 (diff) | |
parent | f7cba3a80d9ebefc57776fffd17a4ae68f72e494 (diff) |
MFV ntp 4.2.8p1 (r258945, r275970, r276091, r276092, r276093, r278284)
Thanks to roberto for providing pointers to wedge this into HEAD.
Approved by: roberto
Notes
Notes:
svn path=/head/; revision=280849
Diffstat (limited to 'contrib/ntp/sntp/tests')
26 files changed, 2453 insertions, 0 deletions
diff --git a/contrib/ntp/sntp/tests/Makefile.am b/contrib/ntp/sntp/tests/Makefile.am new file mode 100644 index 000000000000..feb914276205 --- /dev/null +++ b/contrib/ntp/sntp/tests/Makefile.am @@ -0,0 +1,111 @@ +NULL = +BUILT_SOURCES = + +check_PROGRAMS = +if BUILD_SNTP +check_PROGRAMS += tests +endif + +base_SOURCES = \ + $(srcdir)/../tests_main.cpp \ + $(NULL) + +tests_SOURCES = \ + $(base_SOURCES) \ + crypto.cpp \ + keyFile.cpp \ + kodDatabase.cpp \ + kodFile.cpp \ + networking.cpp \ + packetHandling.cpp \ + packetProcessing.cpp \ + utilities.cpp \ + $(NULL) + +noinst_HEADERS = \ + sntptest.h \ + fileHandlingTest.h \ + $(NULL) + +dist_check_SCRIPTS = tests-runner + +EXTRA_DIST = \ + data/debug-input-lfp-bin \ + data/debug-input-lfp-dec \ + data/debug-input-pkt \ + data/key-test-ascii \ + data/key-test-comments \ + data/key-test-empty \ + data/key-test-hex \ + data/key-test-invalid-hex \ + data/kod-expected-multiple \ + data/kod-expected-single \ + data/kod-test-blanks \ + data/kod-test-correct \ + data/kod-test-empty \ + $(NULL) + +CLEANFILES = \ + data/kod-output-multiple \ + data/kod-output-single \ + data/debug-output-pkt \ + data/debug-output-lfp-dec \ + data/kod-output-blank \ + data/debug-output-lfp-bin \ + $(NULL) + +LDADD = \ + ../libsntp.a \ + $(LIBOPTS_LDADD) \ + $(LDADD_LIBEVENT) \ + $(top_builddir)/../libntp/libntp.a \ + $(LDADD_LIBNTP) \ + $(LDADD_NTP) \ + $(GTEST_LDFLAGS) \ + $(GTEST_LIBS) \ + $(NULL) + +AM_CFLAGS = $(CFLAGS_NTP) +AM_CXXFLAGS = $(GTEST_CXXFLAGS) + +AM_CPPFLAGS = $(SNTP_INCS) +AM_CPPFLAGS += -I$(srcdir)/.. +AM_CPPFLAGS += -I$(top_srcdir)/../tests +AM_CPPFLAGS += $(LIBOPTS_CFLAGS) +AM_CPPFLAGS += $(CPPFLAGS_LIBEVENT) +AM_CPPFLAGS += $(GTEST_CPPFLAGS) +AM_CPPFLAGS += $(CPPFLAGS_NTP) + +AM_LDFLAGS = $(LDFLAGS_NTP) + +TESTS = + +if !NTP_CROSSCOMPILE +TESTS += tests-runner +endif + +## ensure ../libsntp.a is built + +BUILT_SOURCES += check-libsntp +CLEANFILES += check-libsntp + +check-libsntp: ../libsntp.a + @echo stamp > $@ + +../libsntp.a: + cd .. && $(MAKE) $(AM_MAKEFLAGS) libsntp.a + +## check-libntp.mf - automake fragment +## slightly adapted for deeper directory + +BUILT_SOURCES += check-libntp +CLEANFILES += check-libntp + +check-libntp: ../../libntp/libntp.a + @echo stamp > $@ + +../../libntp/libntp.a: + cd ../../libntp && $(MAKE) $(AM_MAKEFLAGS) libntp.a + +include $(top_srcdir)/depsver.mf +include $(top_srcdir)/includes.mf diff --git a/contrib/ntp/sntp/tests/Makefile.in b/contrib/ntp/sntp/tests/Makefile.in new file mode 100644 index 000000000000..73b78daf6bb9 --- /dev/null +++ b/contrib/ntp/sntp/tests/Makefile.in @@ -0,0 +1,899 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +check_PROGRAMS = $(am__EXEEXT_1) +@BUILD_SNTP_TRUE@am__append_1 = tests +@NTP_CROSSCOMPILE_FALSE@am__append_2 = tests-runner +DIST_COMMON = $(dist_check_SCRIPTS) $(noinst_HEADERS) \ + $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(top_srcdir)/depsver.mf $(top_srcdir)/includes.mf +subdir = tests +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/libopts/m4/libopts.m4 \ + $(top_srcdir)/libopts/m4/stdnoreturn.m4 \ + $(top_srcdir)/libevent/m4/openldap-thread-check.m4 \ + $(top_srcdir)/libevent/m4/openldap.m4 \ + $(top_srcdir)/m4/hms_search_lib.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/m4/ntp_cacheversion.m4 \ + $(top_srcdir)/m4/ntp_compiler.m4 \ + $(top_srcdir)/m4/ntp_crosscompile.m4 \ + $(top_srcdir)/m4/ntp_debug.m4 $(top_srcdir)/m4/ntp_dir_sep.m4 \ + $(top_srcdir)/m4/ntp_facilitynames.m4 \ + $(top_srcdir)/m4/ntp_googletest.m4 \ + $(top_srcdir)/m4/ntp_ipv6.m4 $(top_srcdir)/m4/ntp_lib_m.m4 \ + $(top_srcdir)/m4/ntp_libevent.m4 \ + $(top_srcdir)/m4/ntp_libntp.m4 \ + $(top_srcdir)/m4/ntp_lineeditlibs.m4 \ + $(top_srcdir)/m4/ntp_locinfo.m4 \ + $(top_srcdir)/m4/ntp_openssl.m4 \ + $(top_srcdir)/m4/ntp_pkg_config.m4 \ + $(top_srcdir)/m4/ntp_prog_cc.m4 $(top_srcdir)/m4/ntp_sntp.m4 \ + $(top_srcdir)/m4/ntp_sysexits.m4 \ + $(top_srcdir)/m4/ntp_ver_suffix.m4 \ + $(top_srcdir)/m4/os_cflags.m4 $(top_srcdir)/m4/snprintf.m4 \ + $(top_srcdir)/m4/version.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +@BUILD_SNTP_TRUE@am__EXEEXT_1 = tests$(EXEEXT) +am__objects_1 = +am__objects_2 = tests_main.$(OBJEXT) $(am__objects_1) +am_tests_OBJECTS = $(am__objects_2) crypto.$(OBJEXT) keyFile.$(OBJEXT) \ + kodDatabase.$(OBJEXT) kodFile.$(OBJEXT) networking.$(OBJEXT) \ + packetHandling.$(OBJEXT) packetProcessing.$(OBJEXT) \ + utilities.$(OBJEXT) $(am__objects_1) +tests_OBJECTS = $(am_tests_OBJECTS) +tests_LDADD = $(LDADD) +am__DEPENDENCIES_1 = +tests_DEPENDENCIES = ../libsntp.a $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(top_builddir)/../libntp/libntp.a \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/libevent/build-aux/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +AM_V_CXX = $(am__v_CXX_$(V)) +am__v_CXX_ = $(am__v_CXX_$(AM_DEFAULT_VERBOSITY)) +am__v_CXX_0 = @echo " CXX " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CXXLD = $(am__v_CXXLD_$(V)) +am__v_CXXLD_ = $(am__v_CXXLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CXXLD_0 = @echo " CXXLD " $@; +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +SOURCES = $(tests_SOURCES) +DIST_SOURCES = $(tests_SOURCES) +HEADERS = $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags +am__tty_colors = \ +red=; grn=; lgn=; blu=; std= +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALLOCA = @ALLOCA@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CALC_TICKADJ_DB = @CALC_TICKADJ_DB@ +CALC_TICKADJ_DL = @CALC_TICKADJ_DL@ +CALC_TICKADJ_DS = @CALC_TICKADJ_DS@ +CALC_TICKADJ_MS = @CALC_TICKADJ_MS@ +CALC_TICKADJ_NI = @CALC_TICKADJ_NI@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CFLAGS_NTP = @CFLAGS_NTP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CPPFLAGS_LIBEVENT = @CPPFLAGS_LIBEVENT@ +CPPFLAGS_NTP = @CPPFLAGS_NTP@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EDITLINE_LIBS = @EDITLINE_LIBS@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +GTEST_CONFIG = @GTEST_CONFIG@ +GTEST_CPPFLAGS = @GTEST_CPPFLAGS@ +GTEST_CXXFLAGS = @GTEST_CXXFLAGS@ +GTEST_LDFLAGS = @GTEST_LDFLAGS@ +GTEST_LIBS = @GTEST_LIBS@ +HAVE_INLINE = @HAVE_INLINE@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDADD_LIBEVENT = @LDADD_LIBEVENT@ +LDADD_LIBNTP = @LDADD_LIBNTP@ +LDADD_LIBUTIL = @LDADD_LIBUTIL@ +LDADD_NTP = @LDADD_NTP@ +LDFLAGS = @LDFLAGS@ +LDFLAGS_NTP = @LDFLAGS_NTP@ +LIBISC_PTHREADS_NOTHREADS = @LIBISC_PTHREADS_NOTHREADS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBOPTS_CFLAGS = @LIBOPTS_CFLAGS@ +LIBOPTS_DIR = @LIBOPTS_DIR@ +LIBOPTS_LDADD = @LIBOPTS_LDADD@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIB_SYSLOG = @LIB_SYSLOG@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MANTAGFMT = @MANTAGFMT@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NTPDATE_DB = @NTPDATE_DB@ +NTPDATE_DL = @NTPDATE_DL@ +NTPDATE_DS = @NTPDATE_DS@ +NTPDATE_MS = @NTPDATE_MS@ +NTPDATE_NI = @NTPDATE_NI@ +NTPDC_DB = @NTPDC_DB@ +NTPDC_DL = @NTPDC_DL@ +NTPDC_DS = @NTPDC_DS@ +NTPDC_MS = @NTPDC_MS@ +NTPDC_NI = @NTPDC_NI@ +NTPDSIM_DB = @NTPDSIM_DB@ +NTPDSIM_DL = @NTPDSIM_DL@ +NTPDSIM_DS = @NTPDSIM_DS@ +NTPDSIM_MS = @NTPDSIM_MS@ +NTPDSIM_NI = @NTPDSIM_NI@ +NTPD_DB = @NTPD_DB@ +NTPD_DL = @NTPD_DL@ +NTPD_DS = @NTPD_DS@ +NTPD_MS = @NTPD_MS@ +NTPD_NI = @NTPD_NI@ +NTPQ_DB = @NTPQ_DB@ +NTPQ_DL = @NTPQ_DL@ +NTPQ_DS = @NTPQ_DS@ +NTPQ_MS = @NTPQ_MS@ +NTPQ_NI = @NTPQ_NI@ +NTPSNMPD_DB = @NTPSNMPD_DB@ +NTPSNMPD_DL = @NTPSNMPD_DL@ +NTPSNMPD_DS = @NTPSNMPD_DS@ +NTPSNMPD_MS = @NTPSNMPD_MS@ +NTPSNMPD_NI = @NTPSNMPD_NI@ +NTPSWEEP_DB = @NTPSWEEP_DB@ +NTPSWEEP_DL = @NTPSWEEP_DL@ +NTPSWEEP_DS = @NTPSWEEP_DS@ +NTPSWEEP_MS = @NTPSWEEP_MS@ +NTPSWEEP_NI = @NTPSWEEP_NI@ +NTPTIME_DB = @NTPTIME_DB@ +NTPTIME_DL = @NTPTIME_DL@ +NTPTIME_DS = @NTPTIME_DS@ +NTPTIME_MS = @NTPTIME_MS@ +NTPTIME_NI = @NTPTIME_NI@ +NTPTRACE_DB = @NTPTRACE_DB@ +NTPTRACE_DL = @NTPTRACE_DL@ +NTPTRACE_DS = @NTPTRACE_DS@ +NTPTRACE_MS = @NTPTRACE_MS@ +NTPTRACE_NI = @NTPTRACE_NI@ +NTP_FORCE_LIBEVENT_DIST = @NTP_FORCE_LIBEVENT_DIST@ +NTP_KEYGEN_DB = @NTP_KEYGEN_DB@ +NTP_KEYGEN_DL = @NTP_KEYGEN_DL@ +NTP_KEYGEN_DS = @NTP_KEYGEN_DS@ +NTP_KEYGEN_MS = @NTP_KEYGEN_MS@ +NTP_KEYGEN_NI = @NTP_KEYGEN_NI@ +NTP_WAIT_DB = @NTP_WAIT_DB@ +NTP_WAIT_DL = @NTP_WAIT_DL@ +NTP_WAIT_DS = @NTP_WAIT_DS@ +NTP_WAIT_MS = @NTP_WAIT_MS@ +NTP_WAIT_NI = @NTP_WAIT_NI@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +POSIX_SHELL = @POSIX_SHELL@ +PTHREAD_LIBS = @PTHREAD_LIBS@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SNTP = @SNTP@ +SNTP_DB = @SNTP_DB@ +SNTP_DL = @SNTP_DL@ +SNTP_DS = @SNTP_DS@ +SNTP_MS = @SNTP_MS@ +SNTP_NI = @SNTP_NI@ +STDNORETURN_H = @STDNORETURN_H@ +STRIP = @STRIP@ +TICKADJ_DB = @TICKADJ_DB@ +TICKADJ_DL = @TICKADJ_DL@ +TICKADJ_DS = @TICKADJ_DS@ +TICKADJ_MS = @TICKADJ_MS@ +TICKADJ_NI = @TICKADJ_NI@ +TIMETRIM_DB = @TIMETRIM_DB@ +TIMETRIM_DL = @TIMETRIM_DL@ +TIMETRIM_DS = @TIMETRIM_DS@ +TIMETRIM_MS = @TIMETRIM_MS@ +TIMETRIM_NI = @TIMETRIM_NI@ +VERSION = @VERSION@ +VER_SUFFIX = @VER_SUFFIX@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +subdirs = @subdirs@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +NULL = +BUILT_SOURCES = check-libsntp check-libntp .deps-ver +base_SOURCES = \ + $(srcdir)/../tests_main.cpp \ + $(NULL) + +tests_SOURCES = \ + $(base_SOURCES) \ + crypto.cpp \ + keyFile.cpp \ + kodDatabase.cpp \ + kodFile.cpp \ + networking.cpp \ + packetHandling.cpp \ + packetProcessing.cpp \ + utilities.cpp \ + $(NULL) + +noinst_HEADERS = \ + sntptest.h \ + fileHandlingTest.h \ + $(NULL) + +dist_check_SCRIPTS = tests-runner +EXTRA_DIST = \ + data/debug-input-lfp-bin \ + data/debug-input-lfp-dec \ + data/debug-input-pkt \ + data/key-test-ascii \ + data/key-test-comments \ + data/key-test-empty \ + data/key-test-hex \ + data/key-test-invalid-hex \ + data/kod-expected-multiple \ + data/kod-expected-single \ + data/kod-test-blanks \ + data/kod-test-correct \ + data/kod-test-empty \ + $(NULL) + +CLEANFILES = data/kod-output-multiple data/kod-output-single \ + data/debug-output-pkt data/debug-output-lfp-dec \ + data/kod-output-blank data/debug-output-lfp-bin $(NULL) \ + check-libsntp check-libntp .deps-ver +LDADD = \ + ../libsntp.a \ + $(LIBOPTS_LDADD) \ + $(LDADD_LIBEVENT) \ + $(top_builddir)/../libntp/libntp.a \ + $(LDADD_LIBNTP) \ + $(LDADD_NTP) \ + $(GTEST_LDFLAGS) \ + $(GTEST_LIBS) \ + $(NULL) + +AM_CFLAGS = $(CFLAGS_NTP) +AM_CXXFLAGS = $(GTEST_CXXFLAGS) +AM_CPPFLAGS = $(SNTP_INCS) -I$(srcdir)/.. -I$(top_srcdir)/../tests \ + $(LIBOPTS_CFLAGS) $(CPPFLAGS_LIBEVENT) $(GTEST_CPPFLAGS) \ + $(CPPFLAGS_NTP) +AM_LDFLAGS = $(LDFLAGS_NTP) +TESTS = $(am__append_2) +SNTP_INCS = -I$(top_srcdir)/../include \ + -I$(top_srcdir)/../lib/isc/include \ + -I$(top_srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/include \ + -I$(top_srcdir)/../lib/isc/unix/include +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .cpp .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/depsver.mf $(top_srcdir)/includes.mf $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign tests/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign tests/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +tests$(EXEEXT): $(tests_OBJECTS) $(tests_DEPENDENCIES) + @rm -f tests$(EXEEXT) + $(AM_V_CXXLD)$(CXXLINK) $(tests_OBJECTS) $(tests_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/crypto.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keyFile.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kodDatabase.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kodFile.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/networking.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/packetHandling.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/packetProcessing.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tests_main.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utilities.Po@am__quote@ + +.cpp.o: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< + +.cpp.obj: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cpp.lo: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< + +tests_main.o: $(srcdir)/../tests_main.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT tests_main.o -MD -MP -MF $(DEPDIR)/tests_main.Tpo -c -o tests_main.o `test -f '$(srcdir)/../tests_main.cpp' || echo '$(srcdir)/'`$(srcdir)/../tests_main.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tests_main.Tpo $(DEPDIR)/tests_main.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$(srcdir)/../tests_main.cpp' object='tests_main.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o tests_main.o `test -f '$(srcdir)/../tests_main.cpp' || echo '$(srcdir)/'`$(srcdir)/../tests_main.cpp + +tests_main.obj: $(srcdir)/../tests_main.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT tests_main.obj -MD -MP -MF $(DEPDIR)/tests_main.Tpo -c -o tests_main.obj `if test -f '$(srcdir)/../tests_main.cpp'; then $(CYGPATH_W) '$(srcdir)/../tests_main.cpp'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../tests_main.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tests_main.Tpo $(DEPDIR)/tests_main.Po +@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$(srcdir)/../tests_main.cpp' object='tests_main.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o tests_main.obj `if test -f '$(srcdir)/../tests_main.cpp'; then $(CYGPATH_W) '$(srcdir)/../tests_main.cpp'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../tests_main.cpp'; fi` + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list=' $(TESTS) '; \ + $(am__tty_colors); \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + col=$$red; res=XPASS; \ + ;; \ + *) \ + col=$$grn; res=PASS; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xfail=`expr $$xfail + 1`; \ + col=$$lgn; res=XFAIL; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + col=$$red; res=FAIL; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + col=$$blu; res=SKIP; \ + fi; \ + echo "$${col}$$res$${std}: $$tst"; \ + done; \ + if test "$$all" -eq 1; then \ + tests="test"; \ + All=""; \ + else \ + tests="tests"; \ + All="All "; \ + fi; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="$$All$$all $$tests passed"; \ + else \ + if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ + banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all $$tests failed"; \ + else \ + if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ + banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + if test "$$skip" -eq 1; then \ + skipped="($$skip test was not run)"; \ + else \ + skipped="($$skip tests were not run)"; \ + fi; \ + test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + if test "$$failed" -eq 0; then \ + echo "$$grn$$dashes"; \ + else \ + echo "$$red$$dashes"; \ + fi; \ + echo "$$banner"; \ + test -z "$$skipped" || echo "$$skipped"; \ + test -z "$$report" || echo "$$report"; \ + echo "$$dashes$$std"; \ + test "$$failed" -eq 0; \ + else :; fi + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) \ + $(dist_check_SCRIPTS) + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am +all-am: Makefile $(HEADERS) +installdirs: +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) +clean: clean-am + +clean-am: clean-checkPROGRAMS clean-generic clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: all check check-am install install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ + clean-checkPROGRAMS clean-generic clean-libtool ctags \ + distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am + + +check-libsntp: ../libsntp.a + @echo stamp > $@ + +../libsntp.a: + cd .. && $(MAKE) $(AM_MAKEFLAGS) libsntp.a + +check-libntp: ../../libntp/libntp.a + @echo stamp > $@ + +../../libntp/libntp.a: + cd ../../libntp && $(MAKE) $(AM_MAKEFLAGS) libntp.a +$(DEPDIR)/deps-ver: $(top_srcdir)/deps-ver + @[ -f $@ ] || \ + cp $(top_srcdir)/deps-ver $@ + @[ -w $@ ] || \ + chmod ug+w $@ + @cmp $(top_srcdir)/deps-ver $@ > /dev/null || ( \ + $(MAKE) $(AM_MAKEFLAGS) clean && \ + echo -n "Prior $(subdir)/$(DEPDIR) version " && \ + cat $@ && \ + rm -rf $(DEPDIR) && \ + mkdir $(DEPDIR) && \ + case "$(top_builddir)" in \ + .) \ + ./config.status Makefile depfiles \ + ;; \ + *) \ + cd "$(top_builddir)" && \ + ./config.status $(subdir)/Makefile depfiles && \ + cd $(subdir) \ + ;; \ + esac && \ + echo -n "Cleaned $(subdir)/$(DEPDIR) version " && \ + cat $(top_srcdir)/deps-ver \ + ) + cp $(top_srcdir)/deps-ver $@ + +.deps-ver: $(top_srcdir)/deps-ver + @[ ! -d $(DEPDIR) ] || $(MAKE) $(AM_MAKEFLAGS) $(DEPDIR)/deps-ver + @touch $@ + +# +# depsver.mf included in Makefile.am for directories with .deps +# +# When building in the same directory with sources that change over +# time, such as when tracking using bk, the .deps files can become +# stale with respect to moved, deleted, or superceded headers. Most +# commonly, this would exhibit as make reporting a failure to make a +# header file which is no longer in the location given. To address +# this issue, we use a deps-ver file which is updated with each change +# that breaks old .deps files. A copy of deps-ver is made into +# $(DEPDIR) if not already present. If $(DEPDIR)/deps-ver is present +# with different contents than deps-ver, we make clean to ensure all +# .o files built before the incompatible change are rebuilt along with +# their updated .deps files, then remove $(DEPDIR) and recreate it as +# empty stubs. +# +# It is normal when configured with --disable-dependency-tracking for +# the DEPDIR to not have been created. For this reason, we use the +# intermediate target .deps-ver, which invokes make recursively if +# DEPDIR exists. +# +# If you modify depsver.mf, please make the changes to the master +# copy, the one in sntp is copied by the bootstrap script from it. +# +# This comment block follows rather than leads the related code so that +# it stays with it in the generated Makefile.in and Makefile. +# + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/contrib/ntp/sntp/tests/crypto.cpp b/contrib/ntp/sntp/tests/crypto.cpp new file mode 100644 index 000000000000..a6f89f5aa842 --- /dev/null +++ b/contrib/ntp/sntp/tests/crypto.cpp @@ -0,0 +1,129 @@ +#include "sntptest.h" + +extern "C" { +#include "crypto.h" +}; + +class cryptoTest : public sntptest { +}; + +#define MD5_LENGTH 16 +#define SHA1_LENGTH 20 + +TEST_F(cryptoTest, MakeMd5Mac) { + + const char* PKT_DATA = "abcdefgh0123"; + const int PKT_LEN = strlen(PKT_DATA); + const char* EXPECTED_DIGEST = + "\x52\x6c\xb8\x38\xaf\x06\x5a\xfb\x6c\x98\xbb\xc0\x9b\x0a\x7a\x1b"; + char actual[MD5_LENGTH]; + + key md5; + md5.next = NULL; + md5.key_id = 10; + md5.key_len = 6; + memcpy(&md5.key_seq, "md5seq", md5.key_len); + memcpy(&md5.type, "MD5", 4); + + EXPECT_EQ(MD5_LENGTH, + make_mac((char*)PKT_DATA, PKT_LEN, MD5_LENGTH, &md5, actual)); + + EXPECT_TRUE(memcmp(EXPECTED_DIGEST, actual, MD5_LENGTH) == 0); +} + +#ifdef OPENSSL +TEST_F(cryptoTest, MakeSHA1Mac) { + const char* PKT_DATA = "abcdefgh0123"; + const int PKT_LEN = strlen(PKT_DATA); + const char* EXPECTED_DIGEST = + "\x17\xaa\x82\x97\xc7\x17\x13\x6a\x9b\xa9" + "\x63\x85\xb4\xce\xbe\x94\xa0\x97\x16\x1d"; + char actual[SHA1_LENGTH]; + + key sha1; + sha1.next = NULL; + sha1.key_id = 20; + sha1.key_len = 7; + memcpy(&sha1.key_seq, "sha1seq", sha1.key_len); + memcpy(&sha1.type, "SHA1", 5); + + EXPECT_EQ(SHA1_LENGTH, + make_mac((char*)PKT_DATA, PKT_LEN, SHA1_LENGTH, &sha1, actual)); + + EXPECT_TRUE(memcmp(EXPECTED_DIGEST, actual, SHA1_LENGTH) == 0); +} +#endif /* OPENSSL */ + +TEST_F(cryptoTest, VerifyCorrectMD5) { + const char* PKT_DATA = + "sometestdata" // Data + "\0\0\0\0" // Key-ID (unused) + "\xc7\x58\x99\xdd\x99\x32\x0f\x71" // MAC + "\x2b\x7b\xfe\x4f\xa2\x32\xcf\xac"; + const int PKT_LEN = 12; + + key md5; + md5.next = NULL; + md5.key_id = 0; + md5.key_len = 6; + memcpy(&md5.key_seq, "md5key", md5.key_len); + memcpy(&md5.type, "MD5", 4); + + EXPECT_TRUE(auth_md5((char*)PKT_DATA, PKT_LEN, MD5_LENGTH, &md5)); +} + +#ifdef OPENSSL +TEST_F(cryptoTest, VerifySHA1) { + const char* PKT_DATA = + "sometestdata" // Data + "\0\0\0\0" // Key-ID (unused) + "\xad\x07\xde\x36\x39\xa6\x77\xfa\x5b\xce" // MAC + "\x2d\x8a\x7d\x06\x96\xe6\x0c\xbc\xed\xe1"; + const int PKT_LEN = 12; + + key sha1; + sha1.next = NULL; + sha1.key_id = 0; + sha1.key_len = 7; + memcpy(&sha1.key_seq, "sha1key", sha1.key_len); + memcpy(&sha1.type, "SHA1", 5); + + EXPECT_TRUE(auth_md5((char*)PKT_DATA, PKT_LEN, SHA1_LENGTH, &sha1)); +} +#endif /* OPENSSL */ + +TEST_F(cryptoTest, VerifyFailure) { + /* We use a copy of the MD5 verification code, but modify + * the last bit to make sure verification fails. */ + const char* PKT_DATA = + "sometestdata" // Data + "\0\0\0\0" // Key-ID (unused) + "\xc7\x58\x99\xdd\x99\x32\x0f\x71" // MAC + "\x2b\x7b\xfe\x4f\xa2\x32\xcf\x00"; // Last byte is wrong! + const int PKT_LEN = 12; + + key md5; + md5.next = NULL; + md5.key_id = 0; + md5.key_len = 6; + memcpy(&md5.key_seq, "md5key", md5.key_len); + memcpy(&md5.type, "MD5", 4); + + EXPECT_FALSE(auth_md5((char*)PKT_DATA, PKT_LEN, MD5_LENGTH, &md5)); +} + +TEST_F(cryptoTest, PacketSizeNotMultipleOfFourBytes) { + const char* PKT_DATA = "123456"; + const int PKT_LEN = 6; + char actual[MD5_LENGTH]; + + key md5; + md5.next = NULL; + md5.key_id = 10; + md5.key_len = 6; + memcpy(&md5.key_seq, "md5seq", md5.key_len); + memcpy(&md5.type, "MD5", 4); + + EXPECT_EQ(0, make_mac((char*)PKT_DATA, PKT_LEN, MD5_LENGTH, &md5, actual)); +} + diff --git a/contrib/ntp/sntp/tests/data/debug-input-lfp-bin b/contrib/ntp/sntp/tests/data/debug-input-lfp-bin new file mode 100644 index 000000000000..99d559cc23d2 --- /dev/null +++ b/contrib/ntp/sntp/tests/data/debug-input-lfp-bin @@ -0,0 +1,3 @@ +-------------------------------------------------------------------------------- +0: 00000000 1: 00000000 2: 00000000 3: 00111111 4: 00000000 5: 00000000 6: 00000000 7: 01111111 +-------------------------------------------------------------------------------- diff --git a/contrib/ntp/sntp/tests/data/debug-input-lfp-dec b/contrib/ntp/sntp/tests/data/debug-input-lfp-dec new file mode 100644 index 000000000000..6e81c854347f --- /dev/null +++ b/contrib/ntp/sntp/tests/data/debug-input-lfp-dec @@ -0,0 +1,3 @@ +-------------------------------------------------------------------------------- +0: 0 1: 0 2: 24 3: 166 4: 0 5: 4 6: 181 7: 22 +-------------------------------------------------------------------------------- diff --git a/contrib/ntp/sntp/tests/data/debug-input-pkt b/contrib/ntp/sntp/tests/data/debug-input-pkt new file mode 100644 index 000000000000..ff61b75263cb --- /dev/null +++ b/contrib/ntp/sntp/tests/data/debug-input-pkt @@ -0,0 +1,8 @@ +-------------------------------------------------------------------------------- +0: 24 1: 0 2: 0 3: 0 4: 0 5: 0 6: 0 7: 0 +8: 0 9: 0 10: 0 11: 0 12: 0 13: 0 14: 0 15: 0 +16: 0 17: 0 18: 0 19: 0 20: 0 21: 0 22: 0 23: 0 +24: 0 25: 0 26: 0 27: 0 28: 0 29: 0 30: 0 31: 0 +32: 0 33: 0 34: 0 35: 0 36: 0 37: 0 38: 0 39: 0 +40: 0 41: 0 42: 0 43: 8 44: 7f 45: ff 46: ff 47: ff +-------------------------------------------------------------------------------- diff --git a/contrib/ntp/sntp/tests/data/key-test-ascii b/contrib/ntp/sntp/tests/data/key-test-ascii new file mode 100644 index 000000000000..9240c819462b --- /dev/null +++ b/contrib/ntp/sntp/tests/data/key-test-ascii @@ -0,0 +1,2 @@ +50 MD5 asciikeyOne +40 MD5 asciikeyTwo diff --git a/contrib/ntp/sntp/tests/data/key-test-comments b/contrib/ntp/sntp/tests/data/key-test-comments new file mode 100644 index 000000000000..437049effedc --- /dev/null +++ b/contrib/ntp/sntp/tests/data/key-test-comments @@ -0,0 +1,3 @@ +# This is an initial comment, this file should contain 2 keys. +34 MD5 xyz #This is a comment after an ASCII key. +10 MD5 010101010101010101010101010101 #Comment after hex key. diff --git a/contrib/ntp/sntp/tests/data/key-test-empty b/contrib/ntp/sntp/tests/data/key-test-empty new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/contrib/ntp/sntp/tests/data/key-test-empty diff --git a/contrib/ntp/sntp/tests/data/key-test-hex b/contrib/ntp/sntp/tests/data/key-test-hex new file mode 100644 index 000000000000..fb704c5fd94e --- /dev/null +++ b/contrib/ntp/sntp/tests/data/key-test-hex @@ -0,0 +1,3 @@ +10 MD5 0123456789abcdef0123456789 +20 MD5 111111111111111111111111111111 +30 MD5 01010101010101010101010101 diff --git a/contrib/ntp/sntp/tests/data/key-test-invalid-hex b/contrib/ntp/sntp/tests/data/key-test-invalid-hex new file mode 100644 index 000000000000..0933ed00bc7e --- /dev/null +++ b/contrib/ntp/sntp/tests/data/key-test-invalid-hex @@ -0,0 +1,2 @@ +30 MD5 0101010101010101010101010101gh +10 MD5 010101010101010101010101010101 diff --git a/contrib/ntp/sntp/tests/data/kod-expected-multiple b/contrib/ntp/sntp/tests/data/kod-expected-multiple new file mode 100644 index 000000000000..c6ba292779eb --- /dev/null +++ b/contrib/ntp/sntp/tests/data/kod-expected-multiple @@ -0,0 +1,3 @@ +000000000000abcd DENY 192.0.2.1 +000000000000abcd RSTR 192.0.2.5 +000000000000abcd RATE example.com diff --git a/contrib/ntp/sntp/tests/data/kod-expected-single b/contrib/ntp/sntp/tests/data/kod-expected-single new file mode 100644 index 000000000000..8ad3c7ccc17d --- /dev/null +++ b/contrib/ntp/sntp/tests/data/kod-expected-single @@ -0,0 +1 @@ +0000000000000001 DENY host1 diff --git a/contrib/ntp/sntp/tests/data/kod-test-blanks b/contrib/ntp/sntp/tests/data/kod-test-blanks new file mode 100644 index 000000000000..5c20e7271e57 --- /dev/null +++ b/contrib/ntp/sntp/tests/data/kod-test-blanks @@ -0,0 +1,6 @@ + +0000000012345678 DENY 192.0.2.5 + +0000000000000fff RSTR 192.0.2.100 +000000000000abcd DENY example.com + diff --git a/contrib/ntp/sntp/tests/data/kod-test-correct b/contrib/ntp/sntp/tests/data/kod-test-correct new file mode 100644 index 000000000000..8a3e230ea0f9 --- /dev/null +++ b/contrib/ntp/sntp/tests/data/kod-test-correct @@ -0,0 +1,2 @@ +0000000012345678 DENY 192.0.2.5 +0000000000000fff RSTR 192.0.2.100 diff --git a/contrib/ntp/sntp/tests/data/kod-test-empty b/contrib/ntp/sntp/tests/data/kod-test-empty new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/contrib/ntp/sntp/tests/data/kod-test-empty diff --git a/contrib/ntp/sntp/tests/fileHandlingTest.h b/contrib/ntp/sntp/tests/fileHandlingTest.h new file mode 100644 index 000000000000..502a248b9bd0 --- /dev/null +++ b/contrib/ntp/sntp/tests/fileHandlingTest.h @@ -0,0 +1,64 @@ +#ifndef FILE_HANDLING_TEST_H +#define FILE_HANDLING_TEST_H + +#include "sntptest.h" + +#include <fstream> +#include <string> + +using std::ifstream; +using std::string; +using std::ios; + +class fileHandlingTest : public sntptest { +protected: + enum DirectoryType { + INPUT_DIR = 0, + OUTPUT_DIR = 1 + }; + + std::string CreatePath(const char* filename, DirectoryType argument) { + std::string path; + + if (m_params.size() >= argument + 1) { + path = m_params[argument]; + } + + if (path[path.size()-1] != DIR_SEP && !path.empty()) { + path.append(1, DIR_SEP); + } + path.append(filename); + + return path; + } + + int GetFileSize(ifstream& file) { + int initial = file.tellg(); + + file.seekg(0, ios::end); + int length = file.tellg(); + file.seekg(initial); + + return length; + } + + void CompareFileContent(ifstream& expected, ifstream& actual) { + int currentLine = 1; + while (actual.good() && expected.good()) { + string actualLine, expectedLine; + getline(actual, actualLine); + getline(expected, expectedLine); + + EXPECT_EQ(expectedLine, actualLine) << "Comparision failed on line " << currentLine; + currentLine++; + } + } + + void ClearFile(const std::string& filename) { + std::ofstream clear(filename.c_str(), ios::trunc); + ASSERT_TRUE(clear.good()); + clear.close(); + } +}; + +#endif // FILE_HANDLING_TEST_H diff --git a/contrib/ntp/sntp/tests/keyFile.cpp b/contrib/ntp/sntp/tests/keyFile.cpp new file mode 100644 index 000000000000..3efbe8f8d8f6 --- /dev/null +++ b/contrib/ntp/sntp/tests/keyFile.cpp @@ -0,0 +1,131 @@ +#include "fileHandlingTest.h" + +extern "C" { +#include "crypto.h" +}; + +class keyFileTest : public fileHandlingTest { +protected: + ::testing::AssertionResult CompareKeys(key& expected, key& actual) { + if (expected.key_id != actual.key_id) + return ::testing::AssertionFailure() + << "Expected key_id: " << expected.key_id + << " but was: " << actual.key_id; + if (expected.key_len != actual.key_len) + return ::testing::AssertionFailure() + << "Expected key_len: " << expected.key_len + << " but was: " << actual.key_len; + if (strcmp(expected.type, actual.type) != 0) + return ::testing::AssertionFailure() + << "Expected key_type: " << expected.type + << " but was: " << actual.type; + if (memcmp(expected.key_seq, actual.key_seq, expected.key_len) != 0) + return ::testing::AssertionFailure() + << "Key mismatch!"; + return ::testing::AssertionSuccess(); + } + + ::testing::AssertionResult CompareKeys(int key_id, + int key_len, + const char* type, + const char* key_seq, + key& actual) { + key temp; + + temp.key_id = key_id; + temp.key_len = key_len; + strlcpy(temp.type, type, sizeof(temp.type)); + memcpy(temp.key_seq, key_seq, key_len); + + return CompareKeys(temp, actual); + } +}; + +TEST_F(keyFileTest, ReadEmptyKeyFile) { + key* keys = NULL; + + ASSERT_EQ(0, auth_init(CreatePath("key-test-empty", INPUT_DIR).c_str(), &keys)); + + EXPECT_TRUE(keys == NULL); +} + +TEST_F(keyFileTest, ReadASCIIKeys) { + key* keys = NULL; + + ASSERT_EQ(2, auth_init(CreatePath("key-test-ascii", INPUT_DIR).c_str(), &keys)); + + ASSERT_TRUE(keys != NULL); + + key* result = NULL; + get_key(40, &result); + ASSERT_TRUE(result != NULL); + EXPECT_TRUE(CompareKeys(40, 11, "MD5", "asciikeyTwo", *result)); + + result = NULL; + get_key(50, &result); + ASSERT_TRUE(result != NULL); + EXPECT_TRUE(CompareKeys(50, 11, "MD5", "asciikeyOne", *result)); +} + +TEST_F(keyFileTest, ReadHexKeys) { + key* keys = NULL; + + ASSERT_EQ(3, auth_init(CreatePath("key-test-hex", INPUT_DIR).c_str(), &keys)); + + ASSERT_TRUE(keys != NULL); + + key* result = NULL; + get_key(10, &result); + ASSERT_TRUE(result != NULL); + EXPECT_TRUE(CompareKeys(10, 13, "MD5", + "\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89", *result)); + + result = NULL; + get_key(20, &result); + ASSERT_TRUE(result != NULL); + char data1[15]; memset(data1, 0x11, 15); + EXPECT_TRUE(CompareKeys(20, 15, "MD5", data1, *result)); + + result = NULL; + get_key(30, &result); + ASSERT_TRUE(result != NULL); + char data2[13]; memset(data2, 0x01, 13); + EXPECT_TRUE(CompareKeys(30, 13, "MD5", data2, *result)); +} + +TEST_F(keyFileTest, ReadKeyFileWithComments) { + key* keys = NULL; + + ASSERT_EQ(2, auth_init(CreatePath("key-test-comments", INPUT_DIR).c_str(), &keys)); + + ASSERT_TRUE(keys != NULL); + + key* result = NULL; + get_key(10, &result); + ASSERT_TRUE(result != NULL); + char data[15]; memset(data, 0x01, 15); + EXPECT_TRUE(CompareKeys(10, 15, "MD5", data, *result)); + + result = NULL; + get_key(34, &result); + ASSERT_TRUE(result != NULL); + EXPECT_TRUE(CompareKeys(34, 3, "MD5", "xyz", *result)); +} + +TEST_F(keyFileTest, ReadKeyFileWithInvalidHex) { + key* keys = NULL; + + ASSERT_EQ(1, auth_init(CreatePath("key-test-invalid-hex", INPUT_DIR).c_str(), &keys)); + + ASSERT_TRUE(keys != NULL); + + key* result = NULL; + get_key(10, &result); + ASSERT_TRUE(result != NULL); + char data[15]; memset(data, 0x01, 15); + EXPECT_TRUE(CompareKeys(10, 15, "MD5", data, *result)); + + result = NULL; + get_key(30, &result); // Should not exist, and result should remain NULL. + ASSERT_TRUE(result == NULL); +} diff --git a/contrib/ntp/sntp/tests/kodDatabase.cpp b/contrib/ntp/sntp/tests/kodDatabase.cpp new file mode 100644 index 000000000000..515f4337a3e4 --- /dev/null +++ b/contrib/ntp/sntp/tests/kodDatabase.cpp @@ -0,0 +1,118 @@ +#include "sntptest.h" + +extern "C" { +#include "kod_management.h" +}; + +class kodDatabaseTest : public sntptest { +protected: + virtual void SetUp() { + kod_init_kod_db("/dev/null", TRUE); + } +}; + +TEST_F(kodDatabaseTest, SingleEntryHandling) { + char HOST[] = "192.0.2.5"; + char REASON[] = "DENY"; + + add_entry(HOST, REASON); + + kod_entry* result; + + EXPECT_EQ(1, search_entry(HOST, &result)); + EXPECT_STREQ(HOST, result->hostname); + EXPECT_STREQ(REASON, result->type); +} + +TEST_F(kodDatabaseTest, MultipleEntryHandling) { + char HOST1[] = "192.0.2.3"; + char REASON1[] = "DENY"; + + char HOST2[] = "192.0.5.5"; + char REASON2[] = "RATE"; + + char HOST3[] = "192.0.10.1"; + char REASON3[] = "DENY"; + + add_entry(HOST1, REASON1); + add_entry(HOST2, REASON2); + add_entry(HOST3, REASON3); + + kod_entry* result; + + EXPECT_EQ(1, search_entry(HOST1, &result)); + EXPECT_STREQ(HOST1, result->hostname); + EXPECT_STREQ(REASON1, result->type); + + EXPECT_EQ(1, search_entry(HOST2, &result)); + EXPECT_STREQ(HOST2, result->hostname); + EXPECT_STREQ(REASON2, result->type); + + EXPECT_EQ(1, search_entry(HOST3, &result)); + EXPECT_STREQ(HOST3, result->hostname); + EXPECT_STREQ(REASON3, result->type); + + free(result); +} + +TEST_F(kodDatabaseTest, NoMatchInSearch) { + char HOST_ADD[] = "192.0.2.6"; + char HOST_NOTADD[] = "192.0.6.1"; + char REASON[] = "DENY"; + + add_entry(HOST_ADD, REASON); + + kod_entry* result; + + EXPECT_EQ(0, search_entry(HOST_NOTADD, &result)); + EXPECT_TRUE(result == NULL); +} + +TEST_F(kodDatabaseTest, AddDuplicate) { + char HOST[] = "192.0.2.3"; + char REASON1[] = "RATE"; + char REASON2[] = "DENY"; + + add_entry(HOST, REASON1); + kod_entry* result1; + ASSERT_EQ(1, search_entry(HOST, &result1)); + + /* + * Sleeps for two seconds since we want to ensure that + * the timestamp is updated to a new value. + */ + sleep(2); + + add_entry(HOST, REASON2); + kod_entry* result2; + ASSERT_EQ(1, search_entry(HOST, &result2)); + + EXPECT_NE(result1->timestamp, result2->timestamp); + + free(result1); + free(result2); +} + +TEST_F(kodDatabaseTest, DeleteEntry) { + char HOST1[] = "192.0.2.1"; + char HOST2[] = "192.0.2.2"; + char HOST3[] = "192.0.2.3"; + char REASON[] = "DENY"; + + add_entry(HOST1, REASON); + add_entry(HOST2, REASON); + add_entry(HOST3, REASON); + + kod_entry* result; + + ASSERT_EQ(1, search_entry(HOST2, &result)); + free(result); + + delete_entry(HOST2, REASON); + + EXPECT_EQ(0, search_entry(HOST2, &result)); + + // Ensure that the other entry is still there. + EXPECT_EQ(1, search_entry(HOST1, &result)); + free(result); +} diff --git a/contrib/ntp/sntp/tests/kodFile.cpp b/contrib/ntp/sntp/tests/kodFile.cpp new file mode 100644 index 000000000000..e1775f6374fa --- /dev/null +++ b/contrib/ntp/sntp/tests/kodFile.cpp @@ -0,0 +1,138 @@ +#include "fileHandlingTest.h" + +extern "C" { +#include "kod_management.h" + +#include "ntp_stdlib.h" // For estrdup() +}; + +/* + * We access some parts of the kod database directly, without + * going through the public interface + */ +extern int kod_db_cnt; +extern kod_entry** kod_db; +extern char* kod_db_file; + +class kodFileTest : public fileHandlingTest { +protected: + virtual void SetUp() { + kod_db_cnt = 0; + kod_db = NULL; + } + + virtual void TearDown() { + } +}; + +TEST_F(kodFileTest, ReadEmptyFile) { + kod_init_kod_db(CreatePath("kod-test-empty", INPUT_DIR).c_str(), TRUE); + + EXPECT_EQ(0, kod_db_cnt); +} + +TEST_F(kodFileTest, ReadCorrectFile) { + kod_init_kod_db(CreatePath("kod-test-correct", INPUT_DIR).c_str(), TRUE); + + EXPECT_EQ(2, kod_db_cnt); + + kod_entry* res; + + ASSERT_EQ(1, search_entry("192.0.2.5", &res)); + EXPECT_STREQ("DENY", res->type); + EXPECT_STREQ("192.0.2.5", res->hostname); + EXPECT_EQ(0x12345678, res->timestamp); + + ASSERT_EQ(1, search_entry("192.0.2.100", &res)); + EXPECT_STREQ("RSTR", res->type); + EXPECT_STREQ("192.0.2.100", res->hostname); + EXPECT_EQ(0xfff, res->timestamp); +} + +TEST_F(kodFileTest, ReadFileWithBlankLines) { + kod_init_kod_db(CreatePath("kod-test-blanks", INPUT_DIR).c_str(), TRUE); + + EXPECT_EQ(3, kod_db_cnt); + + kod_entry* res; + + ASSERT_EQ(1, search_entry("192.0.2.5", &res)); + EXPECT_STREQ("DENY", res->type); + EXPECT_STREQ("192.0.2.5", res->hostname); + EXPECT_EQ(0x12345678, res->timestamp); + + ASSERT_EQ(1, search_entry("192.0.2.100", &res)); + EXPECT_STREQ("RSTR", res->type); + EXPECT_STREQ("192.0.2.100", res->hostname); + EXPECT_EQ(0xfff, res->timestamp); + + ASSERT_EQ(1, search_entry("example.com", &res)); + EXPECT_STREQ("DENY", res->type); + EXPECT_STREQ("example.com", res->hostname); + EXPECT_EQ(0xabcd, res->timestamp); +} + +TEST_F(kodFileTest, WriteEmptyFile) { + kod_db_file = estrdup(CreatePath("kod-output-blank", OUTPUT_DIR).c_str()); + + write_kod_db(); + + // Open file and ensure that the filesize is 0 bytes. + std::ifstream is(kod_db_file, std::ios::binary); + ASSERT_FALSE(is.fail()); + + EXPECT_EQ(0, GetFileSize(is)); + + is.close(); +} + +TEST_F(kodFileTest, WriteFileWithSingleEntry) { + kod_db_file = estrdup(CreatePath("kod-output-single", OUTPUT_DIR).c_str()); + + add_entry("host1", "DENY"); + + /* Here we must manipulate the timestamps, so they match the one in + * the expected file. + */ + kod_db[0]->timestamp = 1; + + write_kod_db(); + + // Open file and compare sizes. + ifstream actual(kod_db_file, ios::binary); + ifstream expected(CreatePath("kod-expected-single", INPUT_DIR).c_str()); + ASSERT_TRUE(actual.good()); + ASSERT_TRUE(expected.good()); + + ASSERT_EQ(GetFileSize(expected), GetFileSize(actual)); + + CompareFileContent(expected, actual); +} + +TEST_F(kodFileTest, WriteFileWithMultipleEntries) { + kod_db_file = estrdup(CreatePath("kod-output-multiple", OUTPUT_DIR).c_str()); + + add_entry("example.com", "RATE"); + add_entry("192.0.2.1", "DENY"); + add_entry("192.0.2.5", "RSTR"); + + /* + * Manipulate timestamps. This is a bit of a hack, ideally these + * tests should not care about the internal representation. + */ + kod_db[0]->timestamp = 0xabcd; + kod_db[1]->timestamp = 0xabcd; + kod_db[2]->timestamp = 0xabcd; + + write_kod_db(); + + // Open file and compare sizes and content. + ifstream actual(kod_db_file, ios::binary); + ifstream expected(CreatePath("kod-expected-multiple", INPUT_DIR).c_str()); + ASSERT_TRUE(actual.good()); + ASSERT_TRUE(expected.good()); + + ASSERT_EQ(GetFileSize(expected), GetFileSize(actual)); + + CompareFileContent(expected, actual); +} diff --git a/contrib/ntp/sntp/tests/networking.cpp b/contrib/ntp/sntp/tests/networking.cpp new file mode 100644 index 000000000000..1d6ad6c44065 --- /dev/null +++ b/contrib/ntp/sntp/tests/networking.cpp @@ -0,0 +1,5 @@ +#include "sntptest.h" + +extern "C" { +#include "networking.h" +}; diff --git a/contrib/ntp/sntp/tests/packetHandling.cpp b/contrib/ntp/sntp/tests/packetHandling.cpp new file mode 100644 index 000000000000..ef17489bd6b9 --- /dev/null +++ b/contrib/ntp/sntp/tests/packetHandling.cpp @@ -0,0 +1,264 @@ +#include "sntptest.h" + +extern "C" { +#include "kod_management.h" +#include "main.h" +#include "networking.h" +#include "ntp.h" +}; + +class mainTest : public sntptest { +protected: + ::testing::AssertionResult LfpEquality(const l_fp &expected, const l_fp &actual) { + if (L_ISEQU(&expected, &actual)) { + return ::testing::AssertionSuccess(); + } else { + return ::testing::AssertionFailure() + << " expected: " << lfptoa(&expected, FRACTION_PREC) + << " (" << expected.l_ui << "." << expected.l_uf << ")" + << " but was: " << lfptoa(&actual, FRACTION_PREC) + << " (" << actual.l_ui << "." << actual.l_uf << ")"; + } + } +}; + +TEST_F(mainTest, GenerateUnauthenticatedPacket) { + pkt testpkt; + + timeval xmt; + GETTIMEOFDAY(&xmt, NULL); + xmt.tv_sec += JAN_1970; + + EXPECT_EQ(LEN_PKT_NOMAC, + generate_pkt(&testpkt, &xmt, 0, NULL)); + + EXPECT_EQ(LEAP_NOTINSYNC, PKT_LEAP(testpkt.li_vn_mode)); + EXPECT_EQ(NTP_VERSION, PKT_VERSION(testpkt.li_vn_mode)); + EXPECT_EQ(MODE_CLIENT, PKT_MODE(testpkt.li_vn_mode)); + + EXPECT_EQ(STRATUM_UNSPEC, PKT_TO_STRATUM(testpkt.stratum)); + EXPECT_EQ(8, testpkt.ppoll); + + l_fp expected_xmt, actual_xmt; + TVTOTS(&xmt, &expected_xmt); + NTOHL_FP(&testpkt.xmt, &actual_xmt); + EXPECT_TRUE(LfpEquality(expected_xmt, actual_xmt)); +} + +TEST_F(mainTest, GenerateAuthenticatedPacket) { + key testkey; + testkey.next = NULL; + testkey.key_id = 30; + testkey.key_len = 9; + memcpy(testkey.key_seq, "123456789", testkey.key_len); + memcpy(testkey.type, "MD5", 3); + + pkt testpkt; + + timeval xmt; + GETTIMEOFDAY(&xmt, NULL); + xmt.tv_sec += JAN_1970; + + const int EXPECTED_PKTLEN = LEN_PKT_NOMAC + MAX_MD5_LEN; + + EXPECT_EQ(EXPECTED_PKTLEN, + generate_pkt(&testpkt, &xmt, testkey.key_id, &testkey)); + + EXPECT_EQ(LEAP_NOTINSYNC, PKT_LEAP(testpkt.li_vn_mode)); + EXPECT_EQ(NTP_VERSION, PKT_VERSION(testpkt.li_vn_mode)); + EXPECT_EQ(MODE_CLIENT, PKT_MODE(testpkt.li_vn_mode)); + + EXPECT_EQ(STRATUM_UNSPEC, PKT_TO_STRATUM(testpkt.stratum)); + EXPECT_EQ(8, testpkt.ppoll); + + l_fp expected_xmt, actual_xmt; + TVTOTS(&xmt, &expected_xmt); + NTOHL_FP(&testpkt.xmt, &actual_xmt); + EXPECT_TRUE(LfpEquality(expected_xmt, actual_xmt)); + + EXPECT_EQ(testkey.key_id, ntohl(testpkt.exten[0])); + + char expected_mac[MAX_MD5_LEN]; + ASSERT_EQ(MAX_MD5_LEN - 4, // Remove the key_id, only keep the mac. + make_mac((char*)&testpkt, LEN_PKT_NOMAC, MAX_MD5_LEN, &testkey, expected_mac)); + EXPECT_TRUE(memcmp(expected_mac, (char*)&testpkt.exten[1], MAX_MD5_LEN -4) == 0); +} + +TEST_F(mainTest, OffsetCalculationPositiveOffset) { + pkt rpkt; + + rpkt.precision = -16; // 0,000015259 + rpkt.rootdelay = HTONS_FP(DTOUFP(0.125)); + rpkt.rootdisp = HTONS_FP(DTOUFP(0.25)); + // Synch Distance: (0.125+0.25)/2.0 == 0.1875 + l_fp reftime; + get_systime(&reftime); + HTONL_FP(&reftime, &rpkt.reftime); + + l_fp tmp; + + // T1 - Originate timestamp + tmp.l_ui = 1000000000UL; + tmp.l_uf = 0UL; + HTONL_FP(&tmp, &rpkt.org); + + // T2 - Receive timestamp + tmp.l_ui = 1000000001UL; + tmp.l_uf = 2147483648UL; + HTONL_FP(&tmp, &rpkt.rec); + + // T3 - Transmit timestamp + tmp.l_ui = 1000000002UL; + tmp.l_uf = 0UL; + HTONL_FP(&tmp, &rpkt.xmt); + + // T4 - Destination timestamp as standard timeval + tmp.l_ui = 1000000001UL; + tmp.l_uf = 0UL; + timeval dst; + TSTOTV(&tmp, &dst); + dst.tv_sec -= JAN_1970; + + double offset, precision, synch_distance; + offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &synch_distance); + + EXPECT_DOUBLE_EQ(1.25, offset); + EXPECT_DOUBLE_EQ(1. / ULOGTOD(16), precision); + // 1.1250150000000001 ? + EXPECT_DOUBLE_EQ(1.125015, synch_distance); +} + +TEST_F(mainTest, OffsetCalculationNegativeOffset) { + pkt rpkt; + + rpkt.precision = -1; + rpkt.rootdelay = HTONS_FP(DTOUFP(0.5)); + rpkt.rootdisp = HTONS_FP(DTOUFP(0.5)); + // Synch Distance is (0.5+0.5)/2.0, or 0.5 + l_fp reftime; + get_systime(&reftime); + HTONL_FP(&reftime, &rpkt.reftime); + + l_fp tmp; + + // T1 - Originate timestamp + tmp.l_ui = 1000000001UL; + tmp.l_uf = 0UL; + HTONL_FP(&tmp, &rpkt.org); + + // T2 - Receive timestamp + tmp.l_ui = 1000000000UL; + tmp.l_uf = 2147483648UL; + HTONL_FP(&tmp, &rpkt.rec); + + // T3 - Transmit timestamp + tmp.l_ui = 1000000001UL; + tmp.l_uf = 2147483648UL; + HTONL_FP(&tmp, &rpkt.xmt); + + // T4 - Destination timestamp as standard timeval + tmp.l_ui = 1000000003UL; + tmp.l_uf = 0UL; + timeval dst; + TSTOTV(&tmp, &dst); + dst.tv_sec -= JAN_1970; + + double offset, precision, synch_distance; + offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &synch_distance); + + EXPECT_DOUBLE_EQ(-1, offset); + EXPECT_DOUBLE_EQ(1. / ULOGTOD(1), precision); + EXPECT_DOUBLE_EQ(1.3333483333333334, synch_distance); +} + +TEST_F(mainTest, HandleUnusableServer) { + pkt rpkt; + sockaddr_u host; + int rpktl; + + ZERO(rpkt); + ZERO(host); + rpktl = SERVER_UNUSEABLE; + EXPECT_EQ(-1, handle_pkt(rpktl, &rpkt, &host, "")); +} + +TEST_F(mainTest, HandleUnusablePacket) { + pkt rpkt; + sockaddr_u host; + int rpktl; + + ZERO(rpkt); + ZERO(host); + rpktl = PACKET_UNUSEABLE; + EXPECT_EQ(1, handle_pkt(rpktl, &rpkt, &host, "")); +} + +TEST_F(mainTest, HandleServerAuthenticationFailure) { + pkt rpkt; + sockaddr_u host; + int rpktl; + + ZERO(rpkt); + ZERO(host); + rpktl = SERVER_AUTH_FAIL; + EXPECT_EQ(1, handle_pkt(rpktl, &rpkt, &host, "")); +} + +TEST_F(mainTest, HandleKodDemobilize) { + const char * HOSTNAME = "192.0.2.1"; + const char * REASON = "DENY"; + pkt rpkt; + sockaddr_u host; + int rpktl; + kod_entry * entry; + + rpktl = KOD_DEMOBILIZE; + ZERO(rpkt); + memcpy(&rpkt.refid, REASON, 4); + ZERO(host); + host.sa4.sin_family = AF_INET; + host.sa4.sin_addr.s_addr = inet_addr(HOSTNAME); + + // Test that the KOD-entry is added to the database. + kod_init_kod_db("/dev/null", TRUE); + + EXPECT_EQ(1, handle_pkt(rpktl, &rpkt, &host, HOSTNAME)); + + ASSERT_EQ(1, search_entry(HOSTNAME, &entry)); + EXPECT_TRUE(memcmp(REASON, entry->type, 4) == 0); +} + +TEST_F(mainTest, HandleKodRate) { + pkt rpkt; + sockaddr_u host; + int rpktl; + + ZERO(rpkt); + ZERO(host); + rpktl = KOD_RATE; + EXPECT_EQ(1, handle_pkt(rpktl, &rpkt, &host, "")); +} + +TEST_F(mainTest, HandleCorrectPacket) { + pkt rpkt; + sockaddr_u host; + int rpktl; + l_fp now; + + // We don't want our testing code to actually change the system clock. + ASSERT_FALSE(ENABLED_OPT(STEP)); + ASSERT_FALSE(ENABLED_OPT(SLEW)); + + get_systime(&now); + HTONL_FP(&now, &rpkt.reftime); + HTONL_FP(&now, &rpkt.org); + HTONL_FP(&now, &rpkt.rec); + HTONL_FP(&now, &rpkt.xmt); + rpktl = LEN_PKT_NOMAC; + ZERO(host); + AF(&host) = AF_INET; + + EXPECT_EQ(0, handle_pkt(rpktl, &rpkt, &host, "")); +} + +/* packetHandling.cpp */ diff --git a/contrib/ntp/sntp/tests/packetProcessing.cpp b/contrib/ntp/sntp/tests/packetProcessing.cpp new file mode 100644 index 000000000000..322b8938ecc2 --- /dev/null +++ b/contrib/ntp/sntp/tests/packetProcessing.cpp @@ -0,0 +1,334 @@ +#include "sntptest.h" + +extern "C" { +#include "networking.h" +#include "ntp_stdlib.h" +}; + +#include <sstream> +#include <string> + +// Hacks into the key database. +extern key* key_ptr; +extern int key_cnt; + +class packetProcessingTest : public sntptest { +protected: + pkt testpkt; + pkt testspkt; + sockaddr_u testsock; + bool restoreKeyDb; + + void PrepareAuthenticationTest(int key_id, + int key_len, + const char* type, + const void* key_seq) { + std::stringstream ss; + ss << key_id; + + ActivateOption("-a", ss.str().c_str()); + + key_cnt = 1; + key_ptr = new key; + key_ptr->next = NULL; + key_ptr->key_id = key_id; + key_ptr->key_len = key_len; + memcpy(key_ptr->type, "MD5", 3); + + ASSERT_TRUE(key_len < sizeof(key_ptr->key_seq)); + + memcpy(key_ptr->key_seq, key_seq, key_ptr->key_len); + restoreKeyDb = true; + } + + void PrepareAuthenticationTest(int key_id, + int key_len, + const void* key_seq) { + PrepareAuthenticationTest(key_id, key_len, "MD5", key_seq); + } + + virtual void SetUp() { + restoreKeyDb = false; + + /* Initialize the test packet and socket, + * so they contain at least some valid data. */ + testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, NTP_VERSION, + MODE_SERVER); + testpkt.stratum = STRATUM_REFCLOCK; + memcpy(&testpkt.refid, "GPS\0", 4); + + /* Set the origin timestamp of the received packet to the + * same value as the transmit timestamp of the sent packet. */ + l_fp tmp; + tmp.l_ui = 1000UL; + tmp.l_uf = 0UL; + + HTONL_FP(&tmp, &testpkt.org); + HTONL_FP(&tmp, &testspkt.xmt); + } + + virtual void TearDown() { + if (restoreKeyDb) { + key_cnt = 0; + delete key_ptr; + key_ptr = NULL; + } + } +}; + +TEST_F(packetProcessingTest, TooShortLength) { + EXPECT_EQ(PACKET_UNUSEABLE, + process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC - 1, + MODE_SERVER, &testspkt, "UnitTest")); + EXPECT_EQ(PACKET_UNUSEABLE, + process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC - 1, + MODE_BROADCAST, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, LengthNotMultipleOfFour) { + EXPECT_EQ(PACKET_UNUSEABLE, + process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC + 6, + MODE_SERVER, &testspkt, "UnitTest")); + EXPECT_EQ(PACKET_UNUSEABLE, + process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC + 3, + MODE_BROADCAST, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, TooShortExtensionFieldLength) { + /* The lower 16-bits are the length of the extension field. + * This lengths must be multiples of 4 bytes, which gives + * a minimum of 4 byte extension field length. */ + testpkt.exten[7] = htonl(3); // 3 bytes is too short. + + /* We send in a pkt_len of header size + 4 byte extension + * header + 24 byte MAC, this prevents the length error to + * be caught at an earlier stage */ + int pkt_len = LEN_PKT_NOMAC + 4 + 24; + + EXPECT_EQ(PACKET_UNUSEABLE, + process_pkt(&testpkt, &testsock, pkt_len, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, UnauthenticatedPacketReject) { + // Activate authentication option + ActivateOption("-a", "123"); + ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); + + int pkt_len = LEN_PKT_NOMAC; + + // We demand authentication, but no MAC header is present. + EXPECT_EQ(SERVER_AUTH_FAIL, + process_pkt(&testpkt, &testsock, pkt_len, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, CryptoNAKPacketReject) { + // Activate authentication option + ActivateOption("-a", "123"); + ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); + + int pkt_len = LEN_PKT_NOMAC + 4; // + 4 byte MAC = Crypto-NAK + + EXPECT_EQ(SERVER_AUTH_FAIL, + process_pkt(&testpkt, &testsock, pkt_len, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, AuthenticatedPacketInvalid) { + // Activate authentication option + PrepareAuthenticationTest(50, 9, "123456789"); + ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); + + // Prepare the packet. + int pkt_len = LEN_PKT_NOMAC; + + testpkt.exten[0] = htonl(50); + int mac_len = make_mac((char*)&testpkt, pkt_len, + MAX_MD5_LEN, key_ptr, + (char*)&testpkt.exten[1]); + + pkt_len += 4 + mac_len; + + // Now, alter the MAC so it becomes invalid. + testpkt.exten[1] += 1; + + EXPECT_EQ(SERVER_AUTH_FAIL, + process_pkt(&testpkt, &testsock, pkt_len, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, AuthenticatedPacketUnknownKey) { + // Activate authentication option + PrepareAuthenticationTest(30, 9, "123456789"); + ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); + + // Prepare the packet. Observe that the Key-ID expected is 30, + // but the packet has a key id of 50. + int pkt_len = LEN_PKT_NOMAC; + + testpkt.exten[0] = htonl(50); + int mac_len = make_mac((char*)&testpkt, pkt_len, + MAX_MD5_LEN, key_ptr, + (char*)&testpkt.exten[1]); + pkt_len += 4 + mac_len; + + EXPECT_EQ(SERVER_AUTH_FAIL, + process_pkt(&testpkt, &testsock, pkt_len, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, ServerVersionTooOld) { + ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); + + testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, + NTP_OLDVERSION - 1, + MODE_CLIENT); + ASSERT_LT(PKT_VERSION(testpkt.li_vn_mode), NTP_OLDVERSION); + + int pkt_len = LEN_PKT_NOMAC; + + EXPECT_EQ(SERVER_UNUSEABLE, + process_pkt(&testpkt, &testsock, pkt_len, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, ServerVersionTooNew) { + ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); + + testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, + NTP_VERSION + 1, + MODE_CLIENT); + ASSERT_GT(PKT_VERSION(testpkt.li_vn_mode), NTP_VERSION); + + int pkt_len = LEN_PKT_NOMAC; + + EXPECT_EQ(SERVER_UNUSEABLE, + process_pkt(&testpkt, &testsock, pkt_len, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, NonWantedMode) { + ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); + + testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, + NTP_VERSION, + MODE_CLIENT); + + // The packet has a mode of MODE_CLIENT, but process_pkt expects MODE_SERVER + + EXPECT_EQ(SERVER_UNUSEABLE, + process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC, + MODE_SERVER, &testspkt, "UnitTest")); +} + +/* Tests bug 1597 */ +TEST_F(packetProcessingTest, KoDRate) { + ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); + + testpkt.stratum = STRATUM_PKT_UNSPEC; + memcpy(&testpkt.refid, "RATE", 4); + + EXPECT_EQ(KOD_RATE, + process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, KoDDeny) { + ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); + + testpkt.stratum = STRATUM_PKT_UNSPEC; + memcpy(&testpkt.refid, "DENY", 4); + + EXPECT_EQ(KOD_DEMOBILIZE, + process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, RejectUnsyncedServer) { + ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); + + testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC, + NTP_VERSION, + MODE_SERVER); + + EXPECT_EQ(SERVER_UNUSEABLE, + process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, RejectWrongResponseServerMode) { + ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); + + l_fp tmp; + tmp.l_ui = 1000UL; + tmp.l_uf = 0UL; + HTONL_FP(&tmp, &testpkt.org); + + tmp.l_ui = 2000UL; + tmp.l_uf = 0UL; + HTONL_FP(&tmp, &testspkt.xmt); + + EXPECT_EQ(PACKET_UNUSEABLE, + process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, AcceptNoSentPacketBroadcastMode) { + ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); + + testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, + NTP_VERSION, + MODE_BROADCAST); + + EXPECT_EQ(LEN_PKT_NOMAC, + process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC, + MODE_BROADCAST, NULL, "UnitTest")); +} + +TEST_F(packetProcessingTest, CorrectUnauthenticatedPacket) { + ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); + + EXPECT_EQ(LEN_PKT_NOMAC, + process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC, + MODE_SERVER, &testspkt, "UnitTest")); +} + +TEST_F(packetProcessingTest, CorrectAuthenticatedPacketMD5) { + PrepareAuthenticationTest(10, 15, "123456789abcdef"); + ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); + + int pkt_len = LEN_PKT_NOMAC; + + // Prepare the packet. + testpkt.exten[0] = htonl(10); + int mac_len = make_mac((char*)&testpkt, pkt_len, + MAX_MD5_LEN, key_ptr, + (char*)&testpkt.exten[1]); + + pkt_len += 4 + mac_len; + + EXPECT_EQ(pkt_len, + process_pkt(&testpkt, &testsock, pkt_len, + MODE_SERVER, &testspkt, "UnitTest")); + +} + +TEST_F(packetProcessingTest, CorrectAuthenticatedPacketSHA1) { + PrepareAuthenticationTest(20, 15, "SHA1", "abcdefghijklmno"); + ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); + + int pkt_len = LEN_PKT_NOMAC; + + // Prepare the packet. + testpkt.exten[0] = htonl(20); + int mac_len = make_mac((char*)&testpkt, pkt_len, + MAX_MAC_LEN, key_ptr, + (char*)&testpkt.exten[1]); + + pkt_len += 4 + mac_len; + + EXPECT_EQ(pkt_len, + process_pkt(&testpkt, &testsock, pkt_len, + MODE_SERVER, &testspkt, "UnitTest")); +} diff --git a/contrib/ntp/sntp/tests/sntptest.h b/contrib/ntp/sntp/tests/sntptest.h new file mode 100644 index 000000000000..d5add9cbf465 --- /dev/null +++ b/contrib/ntp/sntp/tests/sntptest.h @@ -0,0 +1,35 @@ +#ifndef SNTPTEST_H +#define SNTPTEST_H + +#include "tests_main.h" + +extern "C" { +#include "ntp_stdlib.h" +#include "sntp-opts.h" +}; + +class sntptest : public ntptest { +protected: + sntptest() { + optionSaveState(&sntpOptions); + } + + ~sntptest() { + optionRestore(&sntpOptions); + } + + void ActivateOption(const char* option, const char* argument) { + const int ARGV_SIZE = 4; + + char* opts[ARGV_SIZE]; + + opts[0] = estrdup("sntpopts"); + opts[1] = estrdup(option); + opts[2] = estrdup(argument); + opts[3] = estrdup("127.0.0.1"); + + optionProcess(&sntpOptions, ARGV_SIZE, opts); + } +}; + +#endif // SNTPTEST_H diff --git a/contrib/ntp/sntp/tests/tests-runner b/contrib/ntp/sntp/tests/tests-runner new file mode 100755 index 000000000000..412516ca6536 --- /dev/null +++ b/contrib/ntp/sntp/tests/tests-runner @@ -0,0 +1,13 @@ +#!/bin/sh + +# $builddir is always . +builddir=. +# $srcdir will be set to the correct directory when this script is called from +# the Makefiles generated by Automake. + +# Create output directory. +mkdir -p $builddir/data + +# Test executable expects two arguments: test_input_dir and test_output_dir. +./tests $srcdir/data $builddir/data + diff --git a/contrib/ntp/sntp/tests/utilities.cpp b/contrib/ntp/sntp/tests/utilities.cpp new file mode 100644 index 000000000000..4c8c30535064 --- /dev/null +++ b/contrib/ntp/sntp/tests/utilities.cpp @@ -0,0 +1,176 @@ +#include "sntptest.h" +#include "fileHandlingTest.h" + +extern "C" { +#include "main.h" +#include "utilities.h" +const char * Version = "stub unit test Version string"; +}; + +using std::string; + +class utilitiesTest : public sntptest { +protected: + sockaddr_u CreateSockaddr4(const char* address) { + sockaddr_u s; + s.sa4.sin_family = AF_INET; + s.sa4.sin_addr.s_addr = inet_addr(address); + SET_PORT(&s, 123); + + return s; + } + + addrinfo CreateAddrinfo(sockaddr_u* sock) { + addrinfo a; + a.ai_family = sock->sa.sa_family; + a.ai_addrlen = SIZEOF_SOCKADDR(a.ai_family); + a.ai_addr = &sock->sa; + return a; + } +}; + +class debugUtilitiesTest : public fileHandlingTest { +protected: + bool outputFileOpened; + FILE* outputFile; + + debugUtilitiesTest() : outputFileOpened(false) {} + + void InitDebugTest(const string& filename) { + // Clear the contents of the current file. + // Open the output file + outputFile = fopen(filename.c_str(), "w+"); + ASSERT_TRUE(outputFile != NULL); + outputFileOpened = true; + } + + // Closes outputFile, and compare contents. + void FinishDebugTest(const string& expected, + const string& actual) { + if (outputFileOpened) + fclose(outputFile); + + ifstream e(expected.c_str()); + ifstream a(actual.c_str()); + ASSERT_TRUE(e.good()); + ASSERT_TRUE(a.good()); + + CompareFileContent(e, a); + } +}; + +/* + * These tests are essentially a copy of the tests for socktoa() + * in libntp. If sntp switches to using that functions, these + * tests can be removed. + */ + +TEST_F(utilitiesTest, IPv4Address) { + const char* ADDR = "192.0.2.10"; + + sockaddr_u input = CreateSockaddr4(ADDR); + addrinfo inputA = CreateAddrinfo(&input); + + EXPECT_STREQ(ADDR, ss_to_str(&input)); + EXPECT_STREQ(ADDR, addrinfo_to_str(&inputA)); +} + +TEST_F(utilitiesTest, IPv6Address) { + const struct in6_addr address = { + 0x20, 0x01, 0x0d, 0xb8, + 0x85, 0xa3, 0x08, 0xd3, + 0x13, 0x19, 0x8a, 0x2e, + 0x03, 0x70, 0x73, 0x34 + }; + const char * expected = "2001:db8:85a3:8d3:1319:8a2e:370:7334"; + sockaddr_u input; + addrinfo inputA; + + memset(&input, 0, sizeof(input)); + input.sa6.sin6_family = AF_INET6; + input.sa6.sin6_addr = address; + EXPECT_STREQ(expected, ss_to_str(&input)); + + inputA = CreateAddrinfo(&input); + EXPECT_STREQ(expected, addrinfo_to_str(&inputA)); +} + +TEST_F(utilitiesTest, SetLiVnMode1) { + pkt expected; + expected.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, + NTP_VERSION, + MODE_SERVER); + + pkt actual; + set_li_vn_mode(&actual, LEAP_NOWARNING, NTP_VERSION, + MODE_SERVER); + + EXPECT_EQ(expected.li_vn_mode, actual.li_vn_mode); +} + +TEST_F(utilitiesTest, SetLiVnMode2) { + pkt expected; + expected.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC, + NTP_OLDVERSION, + MODE_BROADCAST); + + pkt actual; + set_li_vn_mode(&actual, LEAP_NOTINSYNC, NTP_OLDVERSION, + MODE_BROADCAST); + + EXPECT_EQ(expected.li_vn_mode, actual.li_vn_mode); +} + +/* Debug utilities tests */ + +TEST_F(debugUtilitiesTest, PktOutput) { + string filename = CreatePath("debug-output-pkt", OUTPUT_DIR); + InitDebugTest(filename); + + pkt testpkt; + memset(&testpkt, 0, sizeof(pkt)); + testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, + NTP_VERSION, + MODE_SERVER); + + l_fp test; + test.l_ui = 8; + test.l_uf = 2147483647; // Lots of ones. + HTONL_FP(&test, &testpkt.xmt); + + pkt_output(&testpkt, LEN_PKT_NOMAC, outputFile); + + FinishDebugTest(CreatePath("debug-input-pkt", INPUT_DIR), filename); +} + +TEST_F(debugUtilitiesTest, LfpOutputBinaryFormat) { + string filename = CreatePath("debug-output-lfp-bin", OUTPUT_DIR); + InitDebugTest(filename); + + l_fp test; + test.l_ui = 63; // 00000000 00000000 00000000 00111111 + test.l_uf = 127; // 00000000 00000000 00000000 01111111 + + l_fp network; + HTONL_FP(&test, &network); + + l_fp_output_bin(&network, outputFile); + + FinishDebugTest(CreatePath("debug-input-lfp-bin", INPUT_DIR), filename); +} + +TEST_F(debugUtilitiesTest, LfpOutputDecimalFormat) { + string filename = CreatePath("debug-output-lfp-dec", OUTPUT_DIR); + InitDebugTest(filename); + + l_fp test; + test.l_ui = 6310; // 0x000018A6 + test.l_uf = 308502; // 0x00004B516 + + l_fp network; + HTONL_FP(&test, &network); + + l_fp_output_dec(&network, outputFile); + + FinishDebugTest(CreatePath("debug-input-lfp-dec", INPUT_DIR), filename); +} |