From: Harlan Stenn Date: Sun, 3 May 2015 03:41:35 +0000 (+0000) Subject: bug-2803 framework X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=082671b5a80c7e35a3eb8d463080a5700071a380;p=thirdparty%2Fntp.git bug-2803 framework bk: 554598efYEs_BhVURa35AIsc-T6EFA --- diff --git a/sntp/configure.ac b/sntp/configure.ac index 172c6b1a1..1b0e1e877 100644 --- a/sntp/configure.ac +++ b/sntp/configure.ac @@ -150,5 +150,6 @@ AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([include/Makefile]) AC_CONFIG_FILES([scripts/Makefile]) AC_CONFIG_FILES([tests/Makefile]) +AC_CONFIG_FILES([unity/Makefile]) AC_OUTPUT diff --git a/sntp/unity/Makefile.am b/sntp/unity/Makefile.am new file mode 100644 index 000000000..e5b36b4e2 --- /dev/null +++ b/sntp/unity/Makefile.am @@ -0,0 +1,15 @@ +AUTOMAKE_OPTIONS = foreign 1.9 subdir-objects +NULL = +BUILT_SOURCES = +CLEANFILES = + +noinst_LIBRARIES = libunity.a + +libunity_a_SOURCES = \ + unity.c \ + unity.h \ + unity_internals.h \ + $(NULL) + +include $(top_srcdir)/depsver.mf +include $(top_srcdir)/includes.mf diff --git a/tests/bug-2803/Makefile.am b/tests/bug-2803/Makefile.am index d0ad58feb..d8caadf77 100644 --- a/tests/bug-2803/Makefile.am +++ b/tests/bug-2803/Makefile.am @@ -1,4 +1,4 @@ -AUTOMAKE_OPTIONS = foreign 1.9 subdir-objects +#AUTOMAKE_OPTIONS = foreign 1.9 subdir-objects NULL = BUILT_SOURCES = CLEANFILES = @@ -7,6 +7,7 @@ check_PROGRAMS = bug-2803 # HMS: we may not need some of these: LDADD = \ + $(top_builddir)/sntp/unity/libunity.a \ $(top_builddir)/libntp/libntp.a \ $(LDADD_LIBNTP) \ $(PTHREAD_LIBS) \ @@ -17,16 +18,15 @@ AM_CFLAGS = $(CFLAGS_NTP) # HMS: we may not need some of these: AM_CPPFLAGS = $(NTP_INCS) -AM_CPPFLAGS += -I$(top_srcdir)/sntp AM_CPPFLAGS += -I$(top_srcdir)/sntp/unity -AM_CPPFLAGS += -I$(top_srcdir)/ntpd +AM_CPPFLAGS += -I$(top_srcdir)/include AM_CPPFLAGS += $(CPPFLAGS_NTP) AM_LDFLAGS = $(LDFLAGS_NTP) -tests_SOURCES = $(top_srcdir)/sntp/unity/unity.c \ - bug-2803.c \ - $(NULL) +bug_2803_SOURCES = \ + bug-2803.c \ + $(NULL) # HMS: we may not need some of these: #noinst_HEADERS = ntpdtest.h \ @@ -41,8 +41,8 @@ endif ## check-libntp.mf - automake fragment ## slightly adapted for deeper directory -BUILT_SOURCES += check-libntp -CLEANFILES += check-libntp +BUILT_SOURCES += check-libntp check-libunity +CLEANFILES += check-libntp check-libunity check-libntp: ../../libntp/libntp.a @echo stamp > $@ @@ -50,5 +50,11 @@ check-libntp: ../../libntp/libntp.a ../../libntp/libntp.a: cd ../../libntp && $(MAKE) $(AM_MAKEFLAGS) libntp.a +check-libunity: ../../sntp/unity/libunity.a + @echo stamp > $@ + +../../sntp/unity/libunity.a: + cd ../../libunity && $(MAKE) $(AM_MAKEFLAGS) libunity.a + include $(top_srcdir)/depsver.mf include $(top_srcdir)/includes.mf diff --git a/tests/bug-2803/bug-2803.c b/tests/bug-2803/bug-2803.c index b474bd992..a31fccfdd 100644 --- a/tests/bug-2803/bug-2803.c +++ b/tests/bug-2803/bug-2803.c @@ -1,7 +1,11 @@ +#include #include #include +#include +#include + /* microseconds per second */ #define MICROSECONDS 1000000 @@ -10,140 +14,6 @@ static int verbose = 1; // if not 0, also print results if test passed static int exit_on_err = 0; // if not 0, exit if test failed -/* - * Inline functions below copied from NTP 4.source code, - -/* make sure microseconds are in nominal range */ -static inline struct timeval -normalize_tval( - struct timeval x - ) -{ - long z; - - /* - * If the fraction becomes excessive denormal, we use division - * to do first partial normalisation. The normalisation loops - * following will do the remaining cleanup. Since the size of - * tv_usec has a peculiar definition by the standard the range - * check is coded manually. And labs() is intentionally not used - * here: it has implementation-defined behaviour when applied - * to LONG_MIN. - */ - if (x.tv_usec < -3l * MICROSECONDS || - x.tv_usec > 3l * MICROSECONDS ) { - z = x.tv_usec / MICROSECONDS; - x.tv_usec -= z * MICROSECONDS; - x.tv_sec += z; - } - - /* - * Do any remaining normalisation steps in loops. This takes 3 - * steps max, and should outperform a division even if the - * mul-by-inverse trick is employed. (It also does the floor - * division adjustment if the above division was executed.) - */ - if (x.tv_usec < 0) - do { - x.tv_usec += MICROSECONDS; - x.tv_sec--; - } while (x.tv_usec < 0); - else if (x.tv_usec >= MICROSECONDS) - do { - x.tv_usec -= MICROSECONDS; - x.tv_sec++; - } while (x.tv_usec >= MICROSECONDS); - - return x; -} - - - -/* x = a + b */ -static inline struct timeval -add_tval( - struct timeval a, - struct timeval b - ) -{ - struct timeval x; - - x = a; - x.tv_sec += b.tv_sec; - x.tv_usec += b.tv_usec; - - return normalize_tval(x); -} - -/* x = a + b, b is fraction only */ -static inline struct timeval -add_tval_us( - struct timeval a, - long b - ) -{ - struct timeval x; - - x = a; - x.tv_usec += b; - - return normalize_tval(x); -} - -/* x = a - b */ -static inline struct timeval -sub_tval( - struct timeval a, - struct timeval b - ) -{ - struct timeval x; - - x = a; - x.tv_sec -= b.tv_sec; - x.tv_usec -= b.tv_usec; - - return normalize_tval(x); -} - -/* x = a - b, b is fraction only */ -static inline struct timeval -sub_tval_us( - struct timeval a, - long b - ) -{ - struct timeval x; - - x = a; - x.tv_usec -= b; - - return normalize_tval(x); -} - -/* x = abs(a) */ -static inline struct timeval -abs_tval( - struct timeval a - ) -{ - struct timeval c; - - c = normalize_tval(a); - if (c.tv_sec < 0) { - if (c.tv_usec != 0) { - c.tv_sec = -c.tv_sec - 1; - c.tv_usec = MICROSECONDS - c.tv_usec; - } else { - c.tv_sec = -c.tv_sec; - } - } - - return c; -} - - - /* * Test function calling the old and new code mentioned in * http://bugs.ntp.org/show_bug.cgi?id=2803#c22