]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Makefile.am:
authorDamir Tomic <viperus@ntp.org>
Tue, 16 Jun 2015 10:46:58 +0000 (12:46 +0200)
committerDamir Tomic <viperus@ntp.org>
Tue, 16 Jun 2015 10:46:58 +0000 (12:46 +0200)
  added building timevalops.c
run-test-timevalops.c, timevalops.c:
  new file
lfpfunc.c:
  removed sstream
g_timevalops.cpp:
  Rename: tests/libntp/timevalops.cpp -> tests/libntp/g_timevalops.cpp

bk: 557ffea26lVb6U_LjwrU5aob6UQp0g

tests/libntp/Makefile.am
tests/libntp/g_timevalops.cpp [moved from tests/libntp/timevalops.cpp with 100% similarity]
tests/libntp/lfpfunc.c
tests/libntp/run-test-lfpfunc.c
tests/libntp/run-test-timevalops.c [new file with mode: 0644]
tests/libntp/timevalops.c [new file with mode: 0644]

index 926e446fc89378225f78a71ca9c7f810ed9aa9ff..33a5a9ec8336684c738dd531c54bc1f8f2b449de 100644 (file)
@@ -29,6 +29,7 @@ check_PROGRAMS =              \
        test-netof              \
        test-socktoa            \
        test-decodenetnum       \
+       test-timevalops         \
        $(NULL)
 
 if GTEST_AVAILABLE
@@ -101,7 +102,7 @@ tests_SOURCES =                                     \
                strtolfp.cpp            \
                timespecops.cpp         \
                timestructs.cpp         \
-               timevalops.cpp          \
+               g_timevalops.cpp        \
                tstotv.cpp              \
                tvtots.cpp              \
                g_uglydate.cpp          \
@@ -327,6 +328,15 @@ test_calendar_LDADD =                              \
        $(top_builddir)/sntp/unity/libunity.a   \
        $(NULL)
 
+test_timevalops_CFLAGS =                       \
+       -I$(top_srcdir)/sntp/unity              \
+       $(NULL)
+
+test_timevalops_LDADD =                                \
+       $(LDADD)                                \
+       $(top_builddir)/sntp/unity/libunity.a   \
+       $(NULL)
+
 
 test_modetoa_SOURCES =                 \
        modetoa.c                       \
@@ -447,6 +457,11 @@ test_calendar_SOURCES =                    \
        test-libntp.c                   \
        $(NULL)
 
+test_timevalops_SOURCES =                      \
+       timevalops.c                    \
+       run-test-timevalops.c           \
+       $(NULL)
+
 
 BUILT_SOURCES +=                               \
        $(srcdir)/run-test-a_md5encrypt.c       \
@@ -472,6 +487,7 @@ BUILT_SOURCES +=                            \
        $(srcdir)/run-test-vi64ops.c            \
        $(srcdir)/run-test-ymd2yd.c             \
        $(srcdir)/run-test-calendar.c           \
+       $(srcdir)/run-test-timevalops.c         \
        $(NULL)
 
 $(srcdir)/run-test-modetoa.c: $(srcdir)/modetoa.c $(std_unity_list)
@@ -543,6 +559,9 @@ $(srcdir)/run-test-caljulian.c: $(srcdir)/caljulian.c $(std_unity_list)
 $(srcdir)/run-test-calendar.c: $(srcdir)/calendar.c $(std_unity_list)
        $(run_unity) calendar.c run-test-calendar.c
 
+$(srcdir)/run-test-timevalops.c: $(srcdir)/timevalops.c $(std_unity_list)
+       $(run_unity) timevalops.c run-test-timevalops.c
+
 
 TESTS =
 
index 6248eb7faf3acb044352bf55fe8b41a2dd3158eb..e38104f8fee0a3bd15e2c1a57cc9ab6c81e45615 100644 (file)
@@ -9,8 +9,7 @@
 #include <float.h>
 #include <math.h>
 
-#include <string.h> //
-//#include <sstream>
+#include <string.h>
 
 
 typedef struct  {
index 62a7a902d8c18897d592c71ae7c88331cc11f2f3..84f99f50827558235f14555abd6ce2f9a1df16b9 100644 (file)
@@ -53,15 +53,15 @@ int main(int argc, char *argv[])
   progname = argv[0];
   Unity.TestFile = "lfpfunc.c";
   UnityBegin("lfpfunc.c");
-  RUN_TEST(test_AdditionLR, 318);
-  RUN_TEST(test_AdditionRL, 336);
-  RUN_TEST(test_SubtractionLR, 354);
-  RUN_TEST(test_SubtractionRL, 368);
-  RUN_TEST(test_Negation, 385);
-  RUN_TEST(test_Absolute, 404);
-  RUN_TEST(test_FDF_RoundTrip, 435);
-  RUN_TEST(test_SignedRelOps, 466);
-  RUN_TEST(test_UnsignedRelOps, 509);
+  RUN_TEST(test_AdditionLR, 317);
+  RUN_TEST(test_AdditionRL, 335);
+  RUN_TEST(test_SubtractionLR, 353);
+  RUN_TEST(test_SubtractionRL, 367);
+  RUN_TEST(test_Negation, 384);
+  RUN_TEST(test_Absolute, 403);
+  RUN_TEST(test_FDF_RoundTrip, 434);
+  RUN_TEST(test_SignedRelOps, 465);
+  RUN_TEST(test_UnsignedRelOps, 508);
 
   return (UnityEnd());
 }
diff --git a/tests/libntp/run-test-timevalops.c b/tests/libntp/run-test-timevalops.c
new file mode 100644 (file)
index 0000000..9732672
--- /dev/null
@@ -0,0 +1,89 @@
+/* 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 <setjmp.h>
+#include <stdio.h>
+
+//=======External Functions This Runner Calls=====
+extern void setUp(void);
+extern void tearDown(void);
+extern void test_Helpers1();
+extern void test_Normalise();
+extern void test_SignNoFrac();
+extern void test_SignWithFrac();
+extern void test_CmpFracEQ();
+extern void test_CmpFracGT();
+extern void test_CmpFracLT();
+extern void test_AddFullNorm();
+extern void test_AddFullOflow1();
+extern void test_AddUsecNorm();
+extern void test_AddUsecOflow1();
+extern void test_SubFullNorm();
+extern void test_SubFullOflow();
+extern void test_SubUsecNorm();
+extern void test_SubUsecOflow();
+extern void test_Neg();
+extern void test_AbsNoFrac();
+extern void test_AbsWithFrac();
+extern void test_LFProundtrip();
+extern void test_ToString();
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "timevalops.c";
+  UnityBegin("timevalops.c");
+  RUN_TEST(test_Helpers1, 126);
+  RUN_TEST(test_Normalise, 153);
+  RUN_TEST(test_SignNoFrac, 167);
+  RUN_TEST(test_SignWithFrac, 179);
+  RUN_TEST(test_CmpFracEQ, 194);
+  RUN_TEST(test_CmpFracGT, 208);
+  RUN_TEST(test_CmpFracLT, 222);
+  RUN_TEST(test_AddFullNorm, 240);
+  RUN_TEST(test_AddFullOflow1, 255);
+  RUN_TEST(test_AddUsecNorm, 269);
+  RUN_TEST(test_AddUsecOflow1, 281);
+  RUN_TEST(test_SubFullNorm, 297);
+  RUN_TEST(test_SubFullOflow, 311);
+  RUN_TEST(test_SubUsecNorm, 325);
+  RUN_TEST(test_SubUsecOflow, 337);
+  RUN_TEST(test_Neg, 353);
+  RUN_TEST(test_AbsNoFrac, 370);
+  RUN_TEST(test_AbsWithFrac, 381);
+  RUN_TEST(test_LFProundtrip, 520);
+  RUN_TEST(test_ToString, 539);
+
+  return (UnityEnd());
+}
diff --git a/tests/libntp/timevalops.c b/tests/libntp/timevalops.c
new file mode 100644 (file)
index 0000000..d9754fc
--- /dev/null
@@ -0,0 +1,564 @@
+#include "config.h"
+//#include "libntptest.h"
+//#include "c_timestructs.h"
+
+#include "unity.h"
+
+#include "ntp_types.h"
+#include "ntp_fp.h"
+
+#include <math.h>
+#include "timevalops.h"
+
+#include <string.h>
+
+//in unity_helper.h :
+#define TEST_ASSERT_EQUAL_timeval(a, b) { \
+    TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec"); \
+    TEST_ASSERT_EQUAL_INT64_MESSAGE(a.tv_usec, b.tv_usec, "Field tv_usec");    \
+}
+
+//timeval has time_t, long, and time_t is basically uint
+
+static u_int32 my_tick_to_tsf(u_int32 ticks);
+static u_int32 my_tsf_to_tick(u_int32 tsf);
+
+// that's it...
+typedef struct {
+       long    usec;
+       u_int32 frac;
+} lfpfracdata ;
+
+
+//******************************************MY CUSTOM FUNCTIONS*******************************
+
+typedef int bool; //TRUE and FALSE are already defined somewhere, so I can't do typedef enum { FALSE, TRUE } boolean;
+
+const bool timeval_isValid(struct timeval V)
+       { return V.tv_usec >= 0 && V.tv_usec < 1000000; }
+
+//taken from lfpfunc.c -> maybe remove this from timevalops.c and lfpfunc. and put in c_timstructs.h ????!!!!!
+l_fp l_fp_init(int32 i, u_int32 f)
+{
+       l_fp temp;
+       temp.l_i  = i;
+       temp.l_uf = f;
+
+       return temp;
+}
+
+/*
+struct timeval limit;
+AssertTimevalClose::AssertTimevalClose(
+       time_t hi,
+       int32  lo
+       )
+{
+       limit.tv_sec = hi;
+       limit.tv_usec = lo;
+}
+
+AssertTimecalClose AssertTimevalClose_init(time_t hi, int32  lo)
+{
+       AssertTimevalClose temp ;
+       limit.tv_sec = hi;
+       limit.tv_usec = lo;
+}
+
+AssertTimevalClose temp ;
+       temp.tv_sec = hi;
+       temp.tv_usec = lo;
+       return temp;
+*/
+
+static const lfpfracdata fdata[] = {
+       {      0, 0x00000000 }, {   7478, 0x01ea1405 },
+       {  22077, 0x05a6d699 }, { 125000, 0x20000000 },
+       { 180326, 0x2e29d841 }, { 207979, 0x353e1c9b },
+       { 250000, 0x40000000 }, { 269509, 0x44fe8ab5 },
+       { 330441, 0x5497c808 }, { 333038, 0x5541fa76 },
+       { 375000, 0x60000000 }, { 394734, 0x650d4995 },
+       { 446327, 0x72427c7c }, { 500000, 0x80000000 },
+       { 517139, 0x846338b4 }, { 571953, 0x926b8306 },
+       { 587353, 0x965cc426 }, { 625000, 0xa0000000 },
+       { 692136, 0xb12fd32c }, { 750000, 0xc0000000 },
+       { 834068, 0xd5857aff }, { 848454, 0xd9344806 },
+       { 854222, 0xdaae4b02 }, { 861465, 0xdc88f862 },
+       { 875000, 0xe0000000 }, { 910661, 0xe921144d },
+       { 922162, 0xec12cf10 }, { 942190, 0xf1335d25 }
+};
+
+
+u_int32 my_tick_to_tsf(u_int32 ticks)
+{
+       // convert microseconds to l_fp fractional units, using double
+       // precision float calculations or, if available, 64bit integer
+       // arithmetic. This should give the precise fraction, rounded to
+       // the nearest representation.
+#ifdef HAVE_U_INT64
+       return (u_int32)((( ((u_int64)(ticks)) << 32) + 500000) / 1000000); //not sure if I neailed the ()()()() and casting!!!!
+#else
+       return (u_int32)( ((double)(ticks)) * 4294.967296 + 0.5); //this double - u_int32 cast wories me, needs dhecking!
+#endif
+       // And before you ask: if ticks >= 1000000, the result is
+       // truncated nonsense, so don't use it out-of-bounds.
+}
+
+u_int32 my_tsf_to_tick(u_int32 tsf)
+{
+       // Inverse operation: converts fraction to microseconds.
+#ifdef HAVE_U_INT64
+       return (u_int32)( ((u_int64)(tsf) * 1000000 + 0x80000000) >> 32); //CHECK ME!!!
+#else
+       return (u_int32)(double(tsf) / 4294.967296 + 0.5);
+#endif
+       // Beware: The result might be 10^6 due to rounding!
+}
+
+
+//***************************************END OF CUSTOM FUNCTIONS*****************************
+
+
+// ---------------------------------------------------------------------
+// test support stuff - part1
+// ---------------------------------------------------------------------
+
+void test_Helpers1() {
+       struct timeval x;
+
+       for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) {
+               x.tv_usec = -1;
+               TEST_ASSERT_FALSE(timeval_isValid(x));
+               x.tv_usec = 0;
+               TEST_ASSERT_TRUE(timeval_isValid(x));
+               x.tv_usec = 999999;
+               TEST_ASSERT_TRUE(timeval_isValid(x));
+               x.tv_usec = 1000000;
+               TEST_ASSERT_FALSE(timeval_isValid(x));
+       }
+}
+
+
+struct timeval timeval_init( time_t hi, long lo){
+       struct timeval V; 
+       V.tv_sec = hi; 
+       V.tv_usec = lo;
+       return V;
+}
+
+//----------------------------------------------------------------------
+// test normalisation
+//----------------------------------------------------------------------
+
+void test_Normalise() {
+       long ns;
+       for (ns = -2000000000; ns <= 2000000000; ns += 10000000) {
+               struct timeval x = timeval_init(0, ns);
+               
+               x = normalize_tval(x);
+               TEST_ASSERT_TRUE(timeval_isValid(x));
+       }
+}
+
+//----------------------------------------------------------------------
+// test classification
+//----------------------------------------------------------------------
+
+void test_SignNoFrac() {
+       int i;
+       // sign test, no fraction
+       for (i = -4; i <= 4; ++i) {
+               struct timeval a = timeval_init(i, 0);
+               int          E = (i > 0) - (i < 0);
+               int          r = test_tval(a);
+
+               TEST_ASSERT_EQUAL(E, r);
+       }
+}
+
+void test_SignWithFrac() {
+       // sign test, with fraction
+       int i;
+       for (i = -4; i <= 4; ++i) {
+               struct timeval a = timeval_init(i, 10);
+               int          E = (i >= 0) - (i < 0);
+               int          r = test_tval(a);
+
+               TEST_ASSERT_EQUAL(E, r);
+       }
+}
+
+//----------------------------------------------------------------------
+// test compare
+//----------------------------------------------------------------------
+void test_CmpFracEQ() {
+       int i,j;
+       // fractions are equal
+       for (i = -4; i <= 4; ++i)
+               for (j = -4; j <= 4; ++j) {
+                       struct timeval a = timeval_init(i, 200);
+                       struct timeval b = timeval_init(j, 200);
+                       int          E = (i > j) - (i < j);
+                       int          r = cmp_tval_denorm(a, b);
+
+                       TEST_ASSERT_EQUAL(E, r);
+               }
+}
+
+void test_CmpFracGT() {
+       // fraction a bigger fraction b
+       int i,j;
+       for (i = -4; i <= 4; ++i)
+               for (j = -4; j <= 4; ++j) {
+                       struct timeval a = timeval_init( i , 999800);
+                       struct timeval b = timeval_init( j , 200);
+                       int          E = (i >= j) - (i < j);
+                       int          r = cmp_tval_denorm(a, b);
+
+                       TEST_ASSERT_EQUAL(E, r);
+               }
+}
+
+void test_CmpFracLT() {
+       // fraction a less fraction b
+       int i,j;
+       for (i = -4; i <= 4; ++i)
+               for (j = -4; j <= 4; ++j) {
+                       struct timeval a = timeval_init(i, 200);
+                       struct timeval b = timeval_init(j, 999800);
+                       int          E = (i > j) - (i <= j);
+                       int          r = cmp_tval_denorm(a, b);
+
+                       TEST_ASSERT_EQUAL(E, r);
+               }
+}
+
+//----------------------------------------------------------------------
+// Test addition (sum)
+//----------------------------------------------------------------------
+
+void test_AddFullNorm() {
+       int i,j;
+       for (i = -4; i <= 4; ++i)
+               for (j = -4; j <= 4; ++j) {
+                       struct timeval a = timeval_init(i, 200);
+                       struct timeval b = timeval_init(j, 400);
+                       struct timeval E = timeval_init(i + j, 200 + 400);
+                       struct timeval c;
+
+                       c = add_tval(a, b);
+                       TEST_ASSERT_EQUAL_timeval(E, c); //added &,E&c ??? -> that was wrong!
+                       //TEST_ASSERT_EQUAL(E, c);
+               }
+}
+
+void test_AddFullOflow1() {
+       int i,j;
+       for (i = -4; i <= 4; ++i)
+               for (j = -4; j <= 4; ++j) {
+                       struct timeval a = timeval_init(i, 200);
+                       struct timeval b = timeval_init(j, 999900);
+                       struct timeval E = timeval_init(i + j + 1, 100);
+                       struct timeval c;
+
+                       c = add_tval(a, b);
+                       TEST_ASSERT_EQUAL_timeval(E, c);
+               }
+}
+
+void test_AddUsecNorm() {
+       int i;
+       for (i = -4; i <= 4; ++i) {
+               struct timeval a = timeval_init(i, 200);
+               struct timeval E = timeval_init(i, 600);
+               struct timeval c;
+
+               c = add_tval_us(a, 600 - 200);
+               TEST_ASSERT_EQUAL_timeval(E, c);
+       }
+}
+
+void test_AddUsecOflow1() {
+       int i;
+       for (i = -4; i <= 4; ++i) {
+               struct timeval a = timeval_init(i, 200);
+               struct timeval E = timeval_init(i + 1, 100);
+               struct timeval c;
+
+               c = add_tval_us(a, MICROSECONDS - 100);
+               TEST_ASSERT_EQUAL_timeval(E, c);
+       }
+}
+
+//----------------------------------------------------------------------
+// test subtraction (difference)
+//----------------------------------------------------------------------
+
+void test_SubFullNorm() {
+       int i,j;
+       for (i = -4; i <= 4; ++i)
+               for (j = -4; j <= 4; ++j) {
+                       struct timeval a = timeval_init(i, 600);
+                       struct timeval b = timeval_init(j, 400);
+                       struct timeval E = timeval_init(i - j, 600 - 400);
+                       struct timeval c;
+
+                       c = sub_tval(a, b);
+                       TEST_ASSERT_EQUAL_timeval(E, c);
+               }
+}
+
+void test_SubFullOflow() {
+       int i,j;
+       for (i = -4; i <= 4; ++i)
+               for (j = -4; j <= 4; ++j) {
+                       struct timeval a = timeval_init(i, 100);
+                       struct timeval b = timeval_init(j, 999900);
+                       struct timeval E = timeval_init(i - j - 1, 200);
+                       struct timeval c;
+
+                       c = sub_tval(a, b);
+                       TEST_ASSERT_EQUAL_timeval(E, c);
+               }
+}
+
+void test_SubUsecNorm() {
+       int i = -4;
+       for (i = -4; i <= 4; ++i) {
+               struct timeval a = timeval_init(i, 600);
+               struct timeval E = timeval_init(i, 200);
+               struct timeval c;
+
+               c = sub_tval_us(a, 600 - 200);
+               TEST_ASSERT_EQUAL_timeval(E, c);
+       }
+}
+
+void test_SubUsecOflow() {
+       int i = -4;
+       for (i = -4; i <= 4; ++i) {
+               struct timeval a = timeval_init(i, 100);
+               struct timeval E = timeval_init(i - 1, 200);
+               struct timeval c;
+
+               c = sub_tval_us(a, MICROSECONDS - 100);
+               TEST_ASSERT_EQUAL_timeval(E, c);
+       }
+}
+
+//----------------------------------------------------------------------
+// test negation
+//----------------------------------------------------------------------
+
+void test_Neg() {
+       int i = -4;
+       for (i = -4; i <= 4; ++i) {
+               struct timeval a = timeval_init(i, 100);
+               struct timeval b;
+               struct timeval c;
+
+               b = neg_tval(a);
+               c = add_tval(a, b);
+               TEST_ASSERT_EQUAL(0, test_tval(c));
+       }
+}
+
+//----------------------------------------------------------------------
+// test abs value
+//----------------------------------------------------------------------
+
+void test_AbsNoFrac() {
+       int i = -4;
+       for (i = -4; i <= 4; ++i) {
+               struct timeval a = timeval_init(i, 0);
+               struct timeval b;
+
+               b = abs_tval(a);
+               TEST_ASSERT_EQUAL((i != 0), test_tval(b));
+       }
+}
+
+void test_AbsWithFrac() {
+       int i = -4;
+       for (i = -4; i <= 4; ++i) {
+               struct timeval a = timeval_init(i, 100);
+               struct timeval b;
+
+               b = abs_tval(a);
+               TEST_ASSERT_EQUAL(1, test_tval(b));
+       }
+}
+
+// ---------------------------------------------------------------------
+// test support stuff -- part 2
+// ---------------------------------------------------------------------
+
+/*
+
+void test_Helpers2() {
+       struct AssertTimevalClose isClose = AssertTimevalClose_init(0, 2);
+       struct timeval x, y;
+       long i; 
+
+       for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++)
+               for (x.tv_usec = 1;
+                    x.tv_usec < 1000000;
+                    x.tv_usec += 499999) {
+                       for (i = -4; i < 5; i++) {
+                               y = x;
+                               y.tv_usec += i;
+                               if (i >= -2 && i <= 2)
+                                       ASSERT_PRED_FORMAT2(isClose, x, y);
+                               else
+                                       ASSERT_PRED_FORMAT2(!isClose, x, y);
+                       }
+               }
+}
+
+// and the global predicate instances we're using here
+static AssertFpClose FpClose(0, 1);
+static AssertTimevalClose TimevalClose(0, 1);
+
+//----------------------------------------------------------------------
+// conversion to l_fp
+//----------------------------------------------------------------------
+
+void test_ToLFPbittest() {
+       u_int32 i = 0;
+       for (i = 0; i < 1000000; i++) {
+               struct timeval a = timeval_init(1, i);
+               l_fp E = l_fp_init(1,my_tick_to_tsf(i));
+               l_fp    r;
+
+               r = tval_intv_to_lfp(a);
+               ASSERT_PRED_FORMAT2(FpClose, E, r);
+       }
+}
+
+void test_ToLFPrelPos() {
+       int i = 0;
+       for (i = 0; i < COUNTOF(fdata); i++) {
+               struct timeval a = timeval_init(1, fdata[i].usec);
+               l_fp E = l_fp_init(1, fdata[i].frac);
+               l_fp    r;
+
+               r = tval_intv_to_lfp(a);
+               ASSERT_PRED_FORMAT2(FpClose, E, r);
+       }
+}
+
+void test_ToLFPrelNeg() {
+       int i = 0;
+       for (i = 0; i < COUNTOF(fdata); i++) {
+               struct timeval a = timeval_init(-1, fdata[i].usec);
+               l_fp E = l_fp_init(~0, fdata[i].frac);
+               l_fp    r;
+
+               r = tval_intv_to_lfp(a);
+               ASSERT_PRED_FORMAT2(FpClose, E, r);
+       }
+}
+
+void test_ToLFPabs() {
+       int i = 0;
+       for (i = 0; i < COUNTOF(fdata); i++) {
+               struct timeval a = timeval_init(1, fdata[i].usec);
+               l_fp E = l_fp_init(1 + JAN_1970, fdata[i].frac);
+               l_fp    r;
+
+               r = tval_stamp_to_lfp(a);
+               ASSERT_PRED_FORMAT2(FpClose, E, r);
+       }
+}
+
+//----------------------------------------------------------------------
+// conversion from l_fp
+//----------------------------------------------------------------------
+
+void test_FromLFPbittest() {
+       // Not *exactly* a bittest, because 2**32 tests would take a
+       // really long time even on very fast machines! So we do test
+       // every 1000 fractional units.
+       u_int32 tsf = 0;
+       for (tsf = 0; tsf < ~u_int32(1000); tsf += 1000) {
+               struct timeval E = timeval_init(1, my_tsf_to_tick(tsf));
+               l_fp a = l_fp_init(1, tsf);
+               struct timeval r;
+
+               r = lfp_intv_to_tval(a);
+               // The conversion might be off by one microsecond when
+               // comparing to calculated value.
+               ASSERT_PRED_FORMAT2(TimevalClose, E, r);
+       }
+}
+
+void test_FromLFPrelPos() {
+       int i = 0;      
+       for (i = 0; i < COUNTOF(fdata); i++) {
+               l_fp a = l_fp_init(1, fdata[i].frac);
+               struct timeval E = timeval_init(1, fdata[i].usec);
+               struct timeval r;
+
+               r = lfp_intv_to_tval(a);
+               ASSERT_PRED_FORMAT2(TimevalClose, E, r);
+       }
+}
+
+void test_FromLFPrelNeg() {
+       int i = 0;
+       for (i = 0; i < COUNTOF(fdata); i++) {
+               l_fp a = l_fp_init(~0, fdata[i].frac);
+               struct timeval E = timeval_init(-1, fdata[i].usec);
+               struct timeval r;
+
+               r = lfp_intv_to_tval(a);
+               ASSERT_PRED_FORMAT2(TimevalClose, E, r);
+       }
+}
+*/
+// usec -> frac -> usec roundtrip, using a prime start and increment
+void test_LFProundtrip() {
+       int32_t t = -1;
+       u_int32 i = 5;
+       for (t = -1; t < 2; ++t)
+               for (i = 5; i < 1000000; i+=11) {
+                       struct timeval E = timeval_init(t, i);
+                       l_fp a;
+                       struct timeval r;
+
+                       a = tval_intv_to_lfp(E);
+                       r = lfp_intv_to_tval(a);
+                       TEST_ASSERT_EQUAL_timeval(E, r);
+               }
+}
+
+//----------------------------------------------------------------------
+// string formatting
+//----------------------------------------------------------------------
+
+void test_ToString() {
+       static const struct {
+               time_t       sec;
+               long         usec;
+               const char * repr;
+       } data [] = {
+               { 0, 0,  "0.000000" },
+               { 2, 0,  "2.000000" },
+               {-2, 0, "-2.000000" },
+               { 0, 1,  "0.000001" },
+               { 0,-1, "-0.000001" },
+               { 1,-1,  "0.999999" },
+               {-1, 1, "-0.999999" },
+               {-1,-1, "-1.000001" },
+       };
+       int i;
+       for (i = 0; i < COUNTOF(data); ++i) {
+               struct timeval a = timeval_init(data[i].sec, data[i].usec);
+               const char *  E = data[i].repr; //??
+               const char *  r = tvaltoa(a);
+
+               TEST_ASSERT_EQUAL_STRING(E, r);
+       }
+}
+
+// -*- EOF -*-