]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
smeartest.c - Harlan Stenn
authorHarlan Stenn <stenn@ntp.org>
Fri, 26 Jun 2015 10:58:41 +0000 (10:58 +0000)
committerHarlan Stenn <stenn@ntp.org>
Fri, 26 Jun 2015 10:58:41 +0000 (10:58 +0000)
bk: 558d30618t4VTBexShgf1TJ_DWg67Q

tests/sandbox/Makefile.am
tests/sandbox/smeartest.c [new file with mode: 0644]

index c79e5be48f4118cd857d0389740ccc8964675f62..489ceab57d0d61f0741130f563ee2dab6a1e24cb 100644 (file)
@@ -5,7 +5,7 @@ CLEANFILES =
 
 run_unity =    cd $(srcdir) && ruby ../../sntp/unity/auto/generate_test_runner.rb
 
-check_PROGRAMS = bug-2803 first-test second-test
+check_PROGRAMS = bug-2803 first-test second-test smeartest
 
 # HMS: we may not need some of these:
 LDADD =                                        \
diff --git a/tests/sandbox/smeartest.c b/tests/sandbox/smeartest.c
new file mode 100644 (file)
index 0000000..9b07581
--- /dev/null
@@ -0,0 +1,104 @@
+#include <config.h>
+
+#include <ntp.h>
+#include <ntp_fp.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
+ */
+
+char *progname = "";
+
+l_fp convertRefIDToLFP(uint32_t r);
+uint32_t convertLFPToRefID(l_fp num);
+
+
+/*
+ * The smear data in the refid is the bottom 3 bytes of the refid,
+ * 2 bits of integer
+ * 22 bits of fraction
+ */
+l_fp
+convertRefIDToLFP(uint32_t r)
+{
+       l_fp temp;
+
+       printf("%02x %02x %02x %x: ",
+               (r >> 22) & 0x3,
+               (r >> 14) & 0xff,
+               (r >>  6) & 0xff,
+               (r & 0x0f)
+               );
+
+       temp.l_ui = (r >> 22) & 0x3;
+       temp.l_uf = ((uint32_t) ((r >> 14) & 0xFF) << 26)
+                 | ((uint32_t) ((r >>  6) & 0xFF) << 18)
+                 | ((uint32_t) ((r >>  0) & 0x0F) << 10);
+
+       if (temp.l_ui & 2)
+               temp.l_ui |= 0xFFFFFFFEu;
+
+       return temp;
+}
+
+
+uint32_t
+convertLFPToRefID(l_fp num)
+{
+       uint32_t temp;
+
+       temp  = (uint8_t) (num.l_ui << 6) | (num.l_uf >> 26);
+       temp |= (uint8_t) (num.l_uf >> 18);
+       temp |= (uint8_t) (num.l_uf >> 10);
+
+       return temp;
+}
+
+
+void rtol(uint32_t r);
+
+void
+rtol(uint32_t r)
+{
+       l_fp l;
+
+       // l = convertRefIDToLFP(htonl(r));
+       l = convertRefIDToLFP(r);
+       printf("refid %#x, smear %s\n", r, lfptoa(&l, 8));
+
+       return;
+}
+
+
+main()
+{
+
+       rtol(0xfe800000);
+       rtol(0xfe800001);
+       rtol(0xfe8ffffe);
+       rtol(0xfe8fffff);
+       rtol(0xfefffffe);
+       rtol(0xfeffffff);
+
+       rtol(0xfe000000);
+       rtol(0xfe000001);
+       rtol(0xfe3ffffe);
+       rtol(0xfe3fffff);
+       rtol(0xfe7ffffe);
+       rtol(0xfe7fffff);
+
+       return 0;
+}