-AUTOMAKE_OPTIONS = foreign 1.9 subdir-objects
+#AUTOMAKE_OPTIONS = foreign 1.9 subdir-objects
NULL =
BUILT_SOURCES =
CLEANFILES =
# HMS: we may not need some of these:
LDADD = \
+ $(top_builddir)/sntp/unity/libunity.a \
$(top_builddir)/libntp/libntp.a \
$(LDADD_LIBNTP) \
$(PTHREAD_LIBS) \
# 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 \
## 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 > $@
../../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
+#include <config.h>
#include <stdio.h>
#include <sys/time.h>
+#include <ntp_fp.h>
+#include <timevalops.h>
+
/* microseconds per second */
#define MICROSECONDS 1000000
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