From: Harlan Stenn Date: Sat, 27 Jun 2015 01:16:47 +0000 (+0000) Subject: refidsmear function support and tests. Harlan Stenn. X-Git-Tag: NTP_4_2_8P3_RC3~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2591f9792c3a1e5e73b7e968ca75812344972d1d;p=thirdparty%2Fntp.git refidsmear function support and tests. Harlan Stenn. bk: 558df97fQksMl7AJ39G38VYhIg4AnA --- diff --git a/ChangeLog b/ChangeLog index 79b54b0a8..11f07f876 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ --- * [Bug 2855] Parser fix for conditional leap smear code. Harlan Stenn. +* refidsmear function support and tests. Harlan Stenn. * sntp/tests/Makefile.am: remove g_nameresolution.cpp as it tested something that was only in the 4.2.6 sntp. Harlan Stenn. * Modified tests/bug-2803/Makefile.am so it builds Unity framework tests. diff --git a/include/Makefile.am b/include/Makefile.am index 5ab3e6e9d..8b063c3c6 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -64,6 +64,7 @@ noinst_HEADERS = \ parse_conf.h \ recvbuff.h \ refclock_atom.h \ + refidsmear.h \ ssl_applink.c \ timepps-SCO.h \ timepps-Solaris.h \ diff --git a/include/refidsmear.h b/include/refidsmear.h new file mode 100644 index 000000000..9c0f24529 --- /dev/null +++ b/include/refidsmear.h @@ -0,0 +1,3 @@ + +extern l_fp convertRefIDToLFP(uint32_t r); +extern uint32_t convertLFPToRefID(l_fp num); diff --git a/libntp/Makefile.am b/libntp/Makefile.am index c12658f5a..914badb5f 100644 --- a/libntp/Makefile.am +++ b/libntp/Makefile.am @@ -89,6 +89,7 @@ libntp_a_SRCS = \ numtohost.c \ octtoint.c \ prettydate.c \ + refidsmear.c \ recvbuff.c \ refnumtoa.c \ snprintf.c \ diff --git a/libntp/refidsmear.c b/libntp/refidsmear.c new file mode 100644 index 000000000..fef428e8a --- /dev/null +++ b/libntp/refidsmear.c @@ -0,0 +1,58 @@ +#include + +#include +#include +#include + +/* + * we want to test a refid format of: + * 254.x.y.x + * + * where x.y.z are 24 bits containing 2 (signed) integer bits + * and 22 fractional bits. + * + */ + + +l_fp +convertRefIDToLFP(uint32_t r) +{ + l_fp temp; + + r = ntohl(r); + + // printf("%03d %08x: ", (r >> 24) & 0xFF, (r & 0x00FFFFFF) ); + + temp.l_uf = (r << 10); /* 22 fractional bits */ + + temp.l_ui = (r >> 22) & 0x3; + temp.l_ui |= ~(temp.l_ui & 2) + 1; + + return temp; +} + + +uint32_t +convertLFPToRefID(l_fp num) +{ + uint32_t temp; + + /* round the input with the highest bit to shift out from the + * fraction, then keep just two bits from the integral part. + * + * TODO: check for overflows; should we clamp/saturate or just + * complain? + */ + L_ADDUF(&num, 0x200); + num.l_ui &= 3; + + /* combine integral and fractional part to 24 bits */ + temp = (num.l_ui << 22) | (num.l_uf >> 10); + + /* put in the leading 254.0.0.0 */ + temp |= UINT32_C(0xFE000000); + + // printf("%03d %08x: ", (temp >> 24) & 0xFF, (temp & 0x00FFFFFF) ); + + return htonl(temp); +} diff --git a/tests/libntp/Makefile.am b/tests/libntp/Makefile.am index 1887b25dd..288d38c79 100644 --- a/tests/libntp/Makefile.am +++ b/tests/libntp/Makefile.am @@ -30,6 +30,7 @@ check_PROGRAMS = \ test-octtoint \ test-prettydate \ test-recvbuff \ + test-refidsmear \ test-refnumtoa \ test-sfptostr \ test-socktoa \ @@ -148,6 +149,7 @@ BUILT_SOURCES += \ $(srcdir)/run-octtoint.c \ $(srcdir)/run-prettydate.c \ $(srcdir)/run-recvbuff.c \ + $(srcdir)/run-refidsmear.c \ $(srcdir)/run-refnumtoa.c \ $(srcdir)/run-sfptostr.c \ $(srcdir)/run-socktoa.c \ @@ -173,367 +175,383 @@ noinst_HEADERS = \ test-libntp.h \ $(NULL) -#$(srcdir)/run-libntp.c: $(srcdir)/test-libntp.c $(std_unity_list) -# $(run_unity) test-libntp.c run-libntp.c +### -#test_libntp_CFLAGS = \ -# -I$(top_srcdir)/sntp/unity \ -# $(NULL) - -#test_libntp_LDADD = \ -# $(LDADD) \ -# $(top_builddir)/sntp/unity/libunity.a \ -# $(NULL) - -test_modetoa_CFLAGS = \ +test_a_md5encrypt_CFLAGS = \ -I$(top_srcdir)/sntp/unity \ $(NULL) -test_modetoa_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +test_a_md5encrypt_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_uglydate_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_a_md5encrypt_SOURCES = \ + a_md5encrypt.c \ + run-a_md5encrypt.c \ $(NULL) -test_uglydate_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ - $(NULL) +$(srcdir)/run-a_md5encrypt.c: $(srcdir)/a_md5encrypt.c $(std_unity_list) + $(run_unity) a_md5encrypt.c run-a_md5encrypt.c -test_ymd2yd_CFLAGS = \ +### + +test_atoint_CFLAGS = \ -I$(top_srcdir)/sntp/unity \ $(NULL) -test_ymd2yd_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +test_atoint_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_statestr_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_atoint_SOURCES = \ + atoint.c \ + run-atoint.c \ $(NULL) -test_statestr_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ - $(NULL) +$(srcdir)/run-atoint.c: $(srcdir)/atoint.c $(std_unity_list) + $(run_unity) atoint.c run-atoint.c -test_numtoa_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +### + +test_atouint_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_numtoa_LDADD = \ - $(unity_tests_LDADD) \ +test_atouint_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_numtohost_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_atouint_SOURCES = \ + atouint.c \ + run-atouint.c \ $(NULL) -test_numtohost_LDADD = \ - $(unity_tests_LDADD) \ +$(srcdir)/run-atouint.c: $(srcdir)/atouint.c $(std_unity_list) + $(run_unity) atouint.c run-atouint.c + +### + +test_authkeys_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_hextoint_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_authkeys_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_hextoint_LDADD = \ - $(unity_tests_LDADD) \ +test_authkeys_SOURCES = \ + authkeys.c \ + run-authkeys.c \ $(NULL) -test_atoint_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +$(srcdir)/run-authkeys.c: $(srcdir)/authkeys.c $(std_unity_list) + $(run_unity) authkeys.c run-authkeys.c + +### + +test_buftvtots_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_atoint_LDADD = \ - $(unity_tests_LDADD) \ +test_buftvtots_SOURCES = \ + buftvtots.c \ + run-buftvtots.c \ $(NULL) -test_octtoint_CFLAGS = \ +test_buftvtots_CFLAGS = \ -I$(top_srcdir)/sntp/unity \ + -DUNITY_INCLUDE_DOUBLE \ $(NULL) -test_octtoint_LDADD = \ - $(unity_tests_LDADD) \ - $(NULL) +$(srcdir)/run-buftvtots.c: $(srcdir)/buftvtots.c $(std_unity_list) + $(run_unity) buftvtots.c run-buftvtots.c -test_hextolfp_CFLAGS = \ +### + +test_calendar_CFLAGS = \ -I$(top_srcdir)/sntp/unity \ $(NULL) -test_hextolfp_LDADD = \ +test_calendar_LDADD = \ $(unity_tests_LDADD) \ $(NULL) -test_netof_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_calendar_SOURCES = \ + calendar.c \ + run-calendar.c \ + test-libntp.c \ $(NULL) -test_netof_LDADD = \ - $(unity_tests_LDADD) \ - $(NULL) +$(srcdir)/run-calendar.c: $(srcdir)/calendar.c $(std_unity_list) + $(run_unity) calendar.c run-calendar.c -test_decodenetnum_CFLAGS = \ +### + +test_caltontp_CFLAGS = \ -I$(top_srcdir)/sntp/unity \ $(NULL) -test_decodenetnum_LDADD = \ +test_caltontp_LDADD = \ $(unity_tests_LDADD) \ -lpthread \ $(NULL) -test_socktoa_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_caltontp_SOURCES = \ + caltontp.c \ + run-caltontp.c \ $(NULL) -test_socktoa_LDADD = \ - $(unity_tests_LDADD) \ - $(NULL) +$(srcdir)/run-caltontp.c: $(srcdir)/caltontp.c $(std_unity_list) + $(run_unity) caltontp.c run-caltontp.c -test_strtolfp_CFLAGS = \ +### + +test_caljulian_CFLAGS = \ -I$(top_srcdir)/sntp/unity \ $(NULL) -test_strtolfp_LDADD = \ +test_caljulian_LDADD = \ $(unity_tests_LDADD) \ -lpthread \ $(NULL) -test_lfptostr_CFLAGS = \ +test_caljulian_SOURCES = \ + caljulian.c \ + run-caljulian.c \ + test-libntp.c \ + $(NULL) + +$(srcdir)/run-caljulian.c: $(srcdir)/caljulian.c $(std_unity_list) + $(run_unity) caljulian.c run-caljulian.c + +### + +test_calyearstart_CFLAGS = \ -I$(top_srcdir)/sntp/unity \ $(NULL) -test_lfptostr_LDADD = \ +test_calyearstart_LDADD = \ $(unity_tests_LDADD) \ $(NULL) -test_a_md5encrypt_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_calyearstart_SOURCES = \ + calyearstart.c \ + run-calyearstart.c \ + test-libntp.c \ $(NULL) -test_a_md5encrypt_LDADD = \ - $(unity_tests_LDADD) \ - $(NULL) +$(srcdir)/run-calyearstart.c: $(srcdir)/calyearstart.c $(std_unity_list) + $(run_unity) calyearstart.c run-calyearstart.c -test_atouint_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ - $(NULL) +### -test_atouint_LDADD = \ - $(unity_tests_LDADD) \ +test_clocktime_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_authkeys_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_clocktime_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_authkeys_LDADD = \ - $(unity_tests_LDADD) \ +test_clocktime_SOURCES = \ + clocktime.c \ + run-clocktime.c \ + test-libntp.c \ $(NULL) -test_lfpfunc_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ - -DUNITY_INCLUDE_DOUBLE \ - $(NULL) +$(srcdir)/run-clocktime.c: $(srcdir)/clocktime.c $(std_unity_list) + $(run_unity) clocktime.c run-clocktime.c -test_lfpfunc_LDADD = \ - $(unity_tests_LDADD) \ - $(NULL) +### -test_vi64ops_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_decodenetnum_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_vi64ops_LDADD = \ - $(unity_tests_LDADD) \ +test_decodenetnum_LDADD = \ + $(unity_tests_LDADD) \ + -lpthread \ $(NULL) -test_refnumtoa_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_decodenetnum_SOURCES = \ + decodenetnum.c \ + run-decodenetnum.c \ $(NULL) -test_refnumtoa_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ - $(NULL) +$(srcdir)/run-decodenetnum.c: $(srcdir)/decodenetnum.c $(std_unity_list) + $(run_unity) decodenetnum.c run-decodenetnum.c -test_calyearstart_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ - $(NULL) +### -test_calyearstart_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +test_hextoint_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_clocktime_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_hextoint_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_clocktime_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +test_hextoint_SOURCES = \ + hextoint.c \ + run-hextoint.c \ $(NULL) -test_caljulian_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ - $(NULL) +$(srcdir)/run-hextoint.c: $(srcdir)/hextoint.c $(std_unity_list) + $(run_unity) hextoint.c run-hextoint.c -test_caljulian_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ - -lpthread \ - $(NULL) +### -test_calendar_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_hextolfp_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_calendar_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +test_hextolfp_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_timevalops_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_hextolfp_SOURCES = \ + hextolfp.c \ + run-hextolfp.c \ $(NULL) -test_timevalops_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ - $(NULL) +$(srcdir)/run-hextolfp.c: $(srcdir)/hextolfp.c $(std_unity_list) + $(run_unity) hextolfp.c run-hextolfp.c -test_timespecops_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +### + +test_humandate_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_timespecops_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +test_humandate_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_ssl_init_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_humandate_SOURCES = \ + humandate.c \ + run-humandate.c \ $(NULL) -test_ssl_init_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +$(srcdir)/run-humandate.c: $(srcdir)/humandate.c $(std_unity_list) + $(run_unity) humandate.c run-humandate.c + +### + +test_lfpfunc_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + -DUNITY_INCLUDE_DOUBLE \ $(NULL) -test_tvtots_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ - -DUNITY_INCLUDE_DOUBLE \ +test_lfpfunc_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_tvtots_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +test_lfpfunc_SOURCES = \ + lfpfunc.c \ + run-lfpfunc.c \ $(NULL) -test_sfptostr_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ - -DUNITY_INCLUDE_DOUBLE \ +$(srcdir)/run-lfpfunc.c: $(srcdir)/lfpfunc.c $(std_unity_list) + $(run_unity) lfpfunc.c run-lfpfunc.c + +### + +test_lfptostr_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_sfptostr_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +test_lfptostr_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_humandate_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_lfptostr_SOURCES = \ + lfptostr.c \ + run-lfptostr.c \ $(NULL) -test_humandate_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +$(srcdir)/run-lfptostr.c: $(srcdir)/lfptostr.c $(std_unity_list) + $(run_unity) lfptostr.c run-lfptostr.c + +### + +test_modetoa_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_caltontp_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_modetoa_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_caltontp_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ - -lpthread \ +test_modetoa_SOURCES = \ + modetoa.c \ + run-modetoa.c \ $(NULL) +$(srcdir)/run-modetoa.c: $(srcdir)/modetoa.c $(std_unity_list) + $(run_unity) modetoa.c run-modetoa.c + +### + test_msyslog_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ + -I$(top_srcdir)/sntp/unity \ $(NULL) test_msyslog_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ + $(unity_tests_LDADD) \ $(NULL) -test_prettydate_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_msyslog_SOURCES = \ + msyslog.c \ + run-msyslog.c \ $(NULL) -test_prettydate_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ - $(NULL) +$(srcdir)/run-msyslog.c: $(srcdir)/msyslog.c $(std_unity_list) + $(run_unity) msyslog.c run-msyslog.c -test_recvbuff_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ - $(NULL) +### -test_recvbuff_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +test_netof_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_tstotv_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_netof_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_tstotv_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +test_netof_SOURCES = \ + netof.c \ + run-netof.c \ $(NULL) -test_buftvtots_CFLAGS = \ +$(srcdir)/run-netof.c: $(srcdir)/netof.c $(std_unity_list) + $(run_unity) netof.c run-netof.c + +### + +test_numtoa_CFLAGS = \ -I$(top_srcdir)/sntp/unity \ - -DUNITY_INCLUDE_DOUBLE \ $(NULL) -test_buftvtots_LDADD = \ - $(LDADD) \ - $(top_builddir)/sntp/unity/libunity.a \ +test_numtoa_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) - -test_modetoa_SOURCES = \ - modetoa.c \ - run-modetoa.c \ +test_numtoa_SOURCES = \ + numtoa.c \ + run-numtoa.c \ $(NULL) -test_uglydate_SOURCES = \ - uglydate.c \ - run-uglydate.c \ - $(NULL) +$(srcdir)/run-numtoa.c: $(srcdir)/numtoa.c $(std_unity_list) + $(run_unity) numtoa.c run-numtoa.c -test_ymd2yd_SOURCES = \ - ymd2yd.c \ - run-ymd2yd.c \ - $(NULL) +### -test_statestr_SOURCES = \ - statestr.c \ - run-statestr.c \ +test_numtohost_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_numtoa_SOURCES = \ - numtoa.c \ - run-numtoa.c \ +test_numtohost_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) test_numtohost_SOURCES = \ @@ -541,19 +559,17 @@ test_numtohost_SOURCES = \ run-numtohost.c \ $(NULL) -test_hextoint_SOURCES = \ - hextoint.c \ - run-hextoint.c \ - $(NULL) +$(srcdir)/run-numtohost.c: $(srcdir)/numtohost.c $(std_unity_list) + $(run_unity) numtohost.c run-numtohost.c -test_atoint_SOURCES = \ - atoint.c \ - run-atoint.c \ +### + +test_octtoint_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_a_md5encrypt_SOURCES = \ - a_md5encrypt.c \ - run-a_md5encrypt.c \ +test_octtoint_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) test_octtoint_SOURCES = \ @@ -561,54 +577,71 @@ test_octtoint_SOURCES = \ run-octtoint.c \ $(NULL) -test_hextolfp_SOURCES = \ - hextolfp.c \ - run-hextolfp.c \ +$(srcdir)/run-octtoint.c: $(srcdir)/octtoint.c $(std_unity_list) + $(run_unity) octtoint.c run-octtoint.c + +### + +test_prettydate_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_netof_SOURCES = \ - netof.c \ - run-netof.c \ +test_prettydate_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_decodenetnum_SOURCES = \ - decodenetnum.c \ - run-decodenetnum.c \ +test_prettydate_SOURCES = \ + prettydate.c \ + run-prettydate.c \ $(NULL) -test_socktoa_SOURCES = \ - socktoa.c \ - run-socktoa.c \ +$(srcdir)/run-prettydate.c: $(srcdir)/prettydate.c $(std_unity_list) + $(run_unity) prettydate.c run-prettydate.c + +### + +test_recvbuff_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_strtolfp_SOURCES = \ - strtolfp.c \ - run-strtolfp.c \ +test_recvbuff_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_lfptostr_SOURCES = \ - lfptostr.c \ - run-lfptostr.c \ +test_recvbuff_SOURCES = \ + recvbuff.c \ + run-recvbuff.c \ $(NULL) -test_atouint_SOURCES = \ - atouint.c \ - run-atouint.c \ +$(srcdir)/run-recvbuff.c: $(srcdir)/recvbuff.c $(std_unity_list) + $(run_unity) recvbuff.c run-recvbuff.c + +### + +test_refidsmear_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_authkeys_SOURCES = \ - authkeys.c \ - run-authkeys.c \ +test_refidsmear_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_lfpfunc_SOURCES = \ - lfpfunc.c \ - run-lfpfunc.c \ +test_refidsmear_SOURCES = \ + refidsmear.c \ + run-refidsmear.c \ $(NULL) -test_vi64ops_SOURCES = \ - vi64ops.c \ - run-vi64ops.c \ +$(srcdir)/run-refidsmear.c: $(srcdir)/refidsmear.c $(std_unity_list) + $(run_unity) refidsmear.c run-refidsmear.c + +### + +test_refnumtoa_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) + +test_refnumtoa_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) test_refnumtoa_SOURCES = \ @@ -616,38 +649,54 @@ test_refnumtoa_SOURCES = \ run-refnumtoa.c \ $(NULL) -test_calyearstart_SOURCES = \ - calyearstart.c \ - run-calyearstart.c \ - test-libntp.c \ +$(srcdir)/run-refnumtoa.c: $(srcdir)/refnumtoa.c $(std_unity_list) + $(run_unity) refnumtoa.c run-refnumtoa.c + +### + +test_sfptostr_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + -DUNITY_INCLUDE_DOUBLE \ $(NULL) -test_clocktime_SOURCES = \ - clocktime.c \ - run-clocktime.c \ - test-libntp.c \ +test_sfptostr_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_caljulian_SOURCES = \ - caljulian.c \ - run-caljulian.c \ - test-libntp.c \ +test_sfptostr_SOURCES = \ + sfptostr.c \ + run-sfptostr.c \ $(NULL) -test_calendar_SOURCES = \ - calendar.c \ - run-calendar.c \ - test-libntp.c \ +$(srcdir)/run-sfptostr.c: $(srcdir)/sfptostr.c $(std_unity_list) + $(run_unity) sfptostr.c run-sfptostr.c + +### + +test_socktoa_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_timevalops_SOURCES = \ - timevalops.c \ - run-timevalops.c \ +test_socktoa_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_timespecops_SOURCES = \ - timespecops.c \ - run-timespecops.c \ +test_socktoa_SOURCES = \ + socktoa.c \ + run-socktoa.c \ + $(NULL) + +$(srcdir)/run-socktoa.c: $(srcdir)/socktoa.c $(std_unity_list) + $(run_unity) socktoa.c run-socktoa.c + +### + +test_ssl_init_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) + +test_ssl_init_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) test_ssl_init_SOURCES = \ @@ -655,162 +704,174 @@ test_ssl_init_SOURCES = \ run-ssl_init.c \ $(NULL) -test_tvtots_SOURCES = \ - tvtots.c \ - run-tvtots.c \ - $(NULL) +$(srcdir)/run-ssl_init.c: $(srcdir)/ssl_init.c $(std_unity_list) + $(run_unity) ssl_init.c run-ssl_init.c -test_sfptostr_SOURCES = \ - sfptostr.c \ - run-sfptostr.c \ - $(NULL) +### -test_humandate_SOURCES = \ - humandate.c \ - run-humandate.c \ +test_statestr_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_caltontp_SOURCES = \ - caltontp.c \ - run-caltontp.c \ +test_statestr_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_msyslog_SOURCES = \ - msyslog.c \ - run-msyslog.c \ +test_statestr_SOURCES = \ + statestr.c \ + run-statestr.c \ $(NULL) -test_prettydate_SOURCES = \ - prettydate.c \ - run-prettydate.c \ - $(NULL) +$(srcdir)/run-statestr.c: $(srcdir)/statestr.c $(std_unity_list) + $(run_unity) statestr.c run-statestr.c -test_recvbuff_SOURCES = \ - recvbuff.c \ - run-recvbuff.c \ - $(NULL) +### -test_tstotv_SOURCES = \ - tstotv.c \ - run-tstotv.c \ +test_strtolfp_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_buftvtots_SOURCES = \ - buftvtots.c \ - run-buftvtots.c \ +test_strtolfp_LDADD = \ + $(unity_tests_LDADD) \ + -lpthread \ $(NULL) +test_strtolfp_SOURCES = \ + strtolfp.c \ + run-strtolfp.c \ + $(NULL) -$(srcdir)/run-modetoa.c: $(srcdir)/modetoa.c $(std_unity_list) - $(run_unity) modetoa.c run-modetoa.c +$(srcdir)/run-strtolfp.c: $(srcdir)/strtolfp.c $(std_unity_list) + $(run_unity) strtolfp.c run-strtolfp.c -$(srcdir)/run-uglydate.c: $(srcdir)/uglydate.c $(std_unity_list) - $(run_unity) uglydate.c run-uglydate.c +### -$(srcdir)/run-ymd2yd.c: $(srcdir)/ymd2yd.c $(std_unity_list) - $(run_unity) ymd2yd.c run-ymd2yd.c +test_timespecops_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) -$(srcdir)/run-statestr.c: $(srcdir)/statestr.c $(std_unity_list) - $(run_unity) statestr.c run-statestr.c +test_timespecops_LDADD = \ + $(unity_tests_LDADD) \ + $(NULL) -$(srcdir)/run-numtoa.c: $(srcdir)/numtoa.c $(std_unity_list) - $(run_unity) numtoa.c run-numtoa.c +test_timespecops_SOURCES = \ + timespecops.c \ + run-timespecops.c \ + $(NULL) -$(srcdir)/run-numtohost.c: $(srcdir)/numtohost.c $(std_unity_list) - $(run_unity) numtohost.c run-numtohost.c +$(srcdir)/run-timespecops.c: $(srcdir)/timespecops.c $(std_unity_list) + $(run_unity) timespecops.c run-timespecops.c -$(srcdir)/run-hextoint.c: $(srcdir)/hextoint.c $(std_unity_list) - $(run_unity) hextoint.c run-hextoint.c +### -$(srcdir)/run-atoint.c: $(srcdir)/atoint.c $(std_unity_list) - $(run_unity) atoint.c run-atoint.c +test_timevalops_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) -$(srcdir)/run-octtoint.c: $(srcdir)/octtoint.c $(std_unity_list) - $(run_unity) octtoint.c run-octtoint.c +test_timevalops_LDADD = \ + $(unity_tests_LDADD) \ + $(NULL) -$(srcdir)/run-hextolfp.c: $(srcdir)/hextolfp.c $(std_unity_list) - $(run_unity) hextolfp.c run-hextolfp.c +test_timevalops_SOURCES = \ + timevalops.c \ + run-timevalops.c \ + $(NULL) -$(srcdir)/run-netof.c: $(srcdir)/netof.c $(std_unity_list) - $(run_unity) netof.c run-netof.c +$(srcdir)/run-timevalops.c: $(srcdir)/timevalops.c $(std_unity_list) + $(run_unity) timevalops.c run-timevalops.c -$(srcdir)/run-decodenetnum.c: $(srcdir)/decodenetnum.c $(std_unity_list) - $(run_unity) decodenetnum.c run-decodenetnum.c +### -$(srcdir)/run-socktoa.c: $(srcdir)/socktoa.c $(std_unity_list) - $(run_unity) socktoa.c run-socktoa.c +test_tstotv_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) -$(srcdir)/run-strtolfp.c: $(srcdir)/strtolfp.c $(std_unity_list) - $(run_unity) strtolfp.c run-strtolfp.c +test_tstotv_LDADD = \ + $(unity_tests_LDADD) \ + $(NULL) -$(srcdir)/run-lfptostr.c: $(srcdir)/lfptostr.c $(std_unity_list) - $(run_unity) lfptostr.c run-lfptostr.c +test_tstotv_SOURCES = \ + tstotv.c \ + run-tstotv.c \ + $(NULL) -$(srcdir)/run-a_md5encrypt.c: $(srcdir)/a_md5encrypt.c $(std_unity_list) - $(run_unity) a_md5encrypt.c run-a_md5encrypt.c +$(srcdir)/run-tstotv.c: $(srcdir)/tstotv.c $(std_unity_list) + $(run_unity) tstotv.c run-tstotv.c -$(srcdir)/run-atouint.c: $(srcdir)/atouint.c $(std_unity_list) - $(run_unity) atouint.c run-atouint.c +### -$(srcdir)/run-authkeys.c: $(srcdir)/authkeys.c $(std_unity_list) - $(run_unity) authkeys.c run-authkeys.c +test_tvtots_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + -DUNITY_INCLUDE_DOUBLE \ + $(NULL) -$(srcdir)/run-lfpfunc.c: $(srcdir)/lfpfunc.c $(std_unity_list) - $(run_unity) lfpfunc.c run-lfpfunc.c +test_tvtots_LDADD = \ + $(unity_tests_LDADD) \ + $(NULL) -$(srcdir)/run-vi64ops.c: $(srcdir)/vi64ops.c $(std_unity_list) - $(run_unity) vi64ops.c run-vi64ops.c +test_tvtots_SOURCES = \ + tvtots.c \ + run-tvtots.c \ + $(NULL) -$(srcdir)/run-refnumtoa.c: $(srcdir)/refnumtoa.c $(std_unity_list) - $(run_unity) refnumtoa.c run-refnumtoa.c +$(srcdir)/run-tvtots.c: $(srcdir)/tvtots.c $(std_unity_list) + $(run_unity) tvtots.c run-tvtots.c -$(srcdir)/run-calyearstart.c: $(srcdir)/calyearstart.c $(std_unity_list) - $(run_unity) calyearstart.c run-calyearstart.c +### -$(srcdir)/run-clocktime.c: $(srcdir)/clocktime.c $(std_unity_list) - $(run_unity) clocktime.c run-clocktime.c +test_uglydate_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) -$(srcdir)/run-caljulian.c: $(srcdir)/caljulian.c $(std_unity_list) - $(run_unity) caljulian.c run-caljulian.c +test_uglydate_LDADD = \ + $(unity_tests_LDADD) \ + $(NULL) -$(srcdir)/run-calendar.c: $(srcdir)/calendar.c $(std_unity_list) - $(run_unity) calendar.c run-calendar.c +test_uglydate_SOURCES = \ + uglydate.c \ + run-uglydate.c \ + $(NULL) -$(srcdir)/run-timevalops.c: $(srcdir)/timevalops.c $(std_unity_list) - $(run_unity) timevalops.c run-timevalops.c +$(srcdir)/run-uglydate.c: $(srcdir)/uglydate.c $(std_unity_list) + $(run_unity) uglydate.c run-uglydate.c -$(srcdir)/run-timespecops.c: $(srcdir)/timespecops.c $(std_unity_list) - $(run_unity) timespecops.c run-timespecops.c +### -$(srcdir)/run-ssl_init.c: $(srcdir)/ssl_init.c $(std_unity_list) - $(run_unity) ssl_init.c run-ssl_init.c +test_vi64ops_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) -$(srcdir)/run-tvtots.c: $(srcdir)/tvtots.c $(std_unity_list) - $(run_unity) tvtots.c run-tvtots.c +test_vi64ops_LDADD = \ + $(unity_tests_LDADD) \ + $(NULL) -$(srcdir)/run-sfptostr.c: $(srcdir)/sfptostr.c $(std_unity_list) - $(run_unity) sfptostr.c run-sfptostr.c +test_vi64ops_SOURCES = \ + vi64ops.c \ + run-vi64ops.c \ + $(NULL) -$(srcdir)/run-humandate.c: $(srcdir)/humandate.c $(std_unity_list) - $(run_unity) humandate.c run-humandate.c +$(srcdir)/run-vi64ops.c: $(srcdir)/vi64ops.c $(std_unity_list) + $(run_unity) vi64ops.c run-vi64ops.c -$(srcdir)/run-caltontp.c: $(srcdir)/caltontp.c $(std_unity_list) - $(run_unity) caltontp.c run-caltontp.c +### -$(srcdir)/run-msyslog.c: $(srcdir)/msyslog.c $(std_unity_list) - $(run_unity) msyslog.c run-msyslog.c +test_ymd2yd_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) -$(srcdir)/run-prettydate.c: $(srcdir)/prettydate.c $(std_unity_list) - $(run_unity) prettydate.c run-prettydate.c +test_ymd2yd_LDADD = \ + $(unity_tests_LDADD) \ + $(NULL) -$(srcdir)/run-recvbuff.c: $(srcdir)/recvbuff.c $(std_unity_list) - $(run_unity) recvbuff.c run-recvbuff.c +test_ymd2yd_SOURCES = \ + ymd2yd.c \ + run-ymd2yd.c \ + $(NULL) -$(srcdir)/run-tstotv.c: $(srcdir)/tstotv.c $(std_unity_list) - $(run_unity) tstotv.c run-tstotv.c +$(srcdir)/run-ymd2yd.c: $(srcdir)/ymd2yd.c $(std_unity_list) + $(run_unity) ymd2yd.c run-ymd2yd.c -$(srcdir)/run-buftvtots.c: $(srcdir)/buftvtots.c $(std_unity_list) - $(run_unity) buftvtots.c run-buftvtots.c +### TESTS = diff --git a/tests/libntp/refidsmear.c b/tests/libntp/refidsmear.c new file mode 100644 index 000000000..7f2adcc8d --- /dev/null +++ b/tests/libntp/refidsmear.c @@ -0,0 +1,127 @@ +#include "config.h" + +#include +#include +#include + +//#include "ntp_stdlib.h" +//#include "ntp_calendar.h" + +#include "unity.h" + +/* + * we want to test a refid format of: + * 254.x.y.x + * + * where x.y.z are 24 bits containing 2 (signed) integer bits + * and 22 fractional bits. + * + * we want functions to convert to/from this format, with unit tests. + * + * Interesting test cases include: + * 254.0.0.0 + * 254.0.0.1 + * 254.127.255.255 + * 254.128.0.0 + * 254.255.255.255 + */ + +void rtol(uint32_t r, char *es); + +void +rtol(uint32_t r, char *es) +{ + l_fp l; + char *as; + + printf("rtol: "); + + l = convertRefIDToLFP(htonl(r)); + as = lfptoa(&l, 8); + printf("refid %#x, smear %s\n", r, as); + // ASSERT: as and es are equal + + return; +} + + +void rtoltor(uint32_t er, char *es); + +void +rtoltor(uint32_t er, char *es) +{ + l_fp l; + char *as; + uint32_t ar; + + printf("rtoltor: "); + l = convertRefIDToLFP(htonl(er)); + as = lfptoa(&l, 8); + + ar = convertLFPToRefID(l); + printf("smear %s, refid %#.8x\n", lfptoa(&l, 8), ntohl(ar)); + + //ASSERT es == as + //ASSERT er == ar + + return; +} + + +void ltor(l_fp l, char *er); + +void +ltor(l_fp l, char *er) +{ + uint32_t r; + + printf("ltor: "); + + r = convertLFPToRefID(l); + printf("smear %s, refid %#.8x\n", lfptoa(&l, 8), ntohl(r)); + + return; +} + + +void test_refidsmear(void) +{ + + rtol(0xfe800000, "-2.00000000"); + rtol(0xfe800001, "-1.99999976"); + rtol(0xfe8ffffe, "-1.75000048"); + rtol(0xfe8fffff, "-1.75000024"); + rtol(0xfef00000, "-0.25000000"); + rtol(0xfef00001, "-0.24999976"); + rtol(0xfefffffe, "-0.00000048"); + rtol(0xfeffffff, "-0.00000024"); + + rtol(0xfe000000, "0.00000000"); + rtol(0xfe000001, "0.00000024"); + rtol(0xfe6ffffe, "1.74999952"); + rtol(0xfe6fffff, "1.74999976"); + rtol(0xfe700000, "1.75000000"); + rtol(0xfe700001, "1.75000024"); + rtol(0xfe7ffffe, "1.99999952"); + rtol(0xfe7fffff, "1.99999976"); + + rtoltor(0xfe800000, "-2.00000000"); + rtoltor(0xfe800001, "-1.99999976"); + rtoltor(0xfe8ffffe, "-1.75000048"); + rtoltor(0xfe8fffff, "-1.75000024"); + rtoltor(0xfef00000, "-0.25000000"); + rtoltor(0xfef00001, "-0.24999976"); + rtoltor(0xfefffffe, "-0.00000048"); + rtoltor(0xfeffffff, "-0.00000024"); + + rtoltor(0xfe000000, "0.00000000"); + rtoltor(0xfe000001, "0.00000024"); + rtoltor(0xfe6ffffe, "1.74999952"); + rtoltor(0xfe6fffff, "1.74999976"); + rtoltor(0xfe700000, "1.75000000"); + rtoltor(0xfe700001, "1.75000024"); + rtoltor(0xfe7ffffe, "1.99999952"); + rtoltor(0xfe7fffff, "1.99999976"); + + return; +} diff --git a/tests/libntp/run-refidsmear.c b/tests/libntp/run-refidsmear.c new file mode 100644 index 000000000..7cbb83fe6 --- /dev/null +++ b/tests/libntp/run-refidsmear.c @@ -0,0 +1,52 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +//=======Test Runner Used To Run Each Test Below===== +#define RUN_TEST(TestFunc, TestLineNum) \ +{ \ + Unity.CurrentTestName = #TestFunc; \ + Unity.CurrentTestLineNumber = TestLineNum; \ + Unity.NumberOfTests++; \ + if (TEST_PROTECT()) \ + { \ + setUp(); \ + TestFunc(); \ + } \ + if (TEST_PROTECT() && !TEST_IS_IGNORED) \ + { \ + tearDown(); \ + } \ + UnityConcludeTest(); \ +} + +//=======Automagically Detected Files To Include===== +#include "unity.h" +#include +#include + +//=======External Functions This Runner Calls===== +extern void setUp(void); +extern void tearDown(void); +void resetTest(void); +extern void test_refidsmear(void); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + +char *progname; + + +//=======MAIN===== +int main(int argc, char *argv[]) +{ + progname = argv[0]; + Unity.TestFile = "refidsmear.c"; + UnityBegin("refidsmear.c"); + RUN_TEST(test_refidsmear, 87); + + return (UnityEnd()); +}