[Git][NTPsec/ntpsec][master] TESTFRAME: packet_dump unit test with MAC successful.

Eric S. Raymond gitlab at mg.gitlab.com
Thu Sep 15 19:53:01 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
0863405f by Eric S. Raymond at 2016-09-15T15:52:16-04:00
TESTFRAME: packet_dump unit test with MAC successful.

- - - - -


2 changed files:

- libntp/pktvis.c
- tests/libntp/ntpvis.c


Changes:

=====================================
libntp/pktvis.c
=====================================
--- a/libntp/pktvis.c
+++ b/libntp/pktvis.c
@@ -11,7 +11,7 @@
 #include "ntp_fp.h"
 #include "lib_strbuf.h"
 
-#define BIGEND_BYTESHIFT(i, m)	(8 * ((m) - (i % (m))))
+#define BIGEND_BYTESHIFT(i, m)	(8 * ((m - 1) - (i % (m))))
 #define BIGEND_GETBYTE(u32, i)	(((u32) >> BIGEND_BYTESHIFT(i, 4)) & 0xff)
 #define BIGEND_PUTBYTE(b, i)	(((b) & 0xff) << BIGEND_BYTESHIFT(i, 4))
 


=====================================
tests/libntp/ntpvis.c
=====================================
--- a/tests/libntp/ntpvis.c
+++ b/tests/libntp/ntpvis.c
@@ -19,7 +19,7 @@ static struct pkt ExamplePacket1 = {
     .precision = -21,
     .rootdelay = 0,
     .rootdisp = 0,
-    .refid = 0x47506300,	/* big-endian 'GPS' */
+    .refid = 0x47505300,	/* big-endian 'GPS\0' */
 #ifdef __unused__
     .reftime = 0,
     .org = 0,
@@ -28,15 +28,43 @@ static struct pkt ExamplePacket1 = {
 #endif
     .exten = {0},
 };
-static char *ExampleDump1 = "6:2:3:-21:0:0:1196450560:0:0:0:0:nomac";
+static char *ExampleDump1 = "6:2:3:-21:0:0:1196446464:0:0:0:0:nomac";
 
-TEST(ntpvis, PacketDump) {
+/* same as ExamplePacket1 but with 4 extension bytes */
+static struct pkt ExamplePacket2 = {
+    .li_vn_mode = 6,
+    .stratum = 2,
+    .ppoll = 3,
+    .precision = -21,
+    .rootdelay = 0,
+    .rootdisp = 0,
+    .refid = 0x47505300,	/* big-endian 'GPS\0' */
+#ifdef __unused__
+    .reftime = 0,
+    .org = 0,
+    .rec = 0,
+    .xmt = 0,
+#endif
+    .exten = {0x01020304},
+};
+static char *ExampleDump2 = "6:2:3:-21:0:0:1196446464:0:0:0:0:01020304";
+
+
+TEST(ntpvis, PacketDump1) {
     char buf[BUFSIZ];
 
     packet_dump(buf, sizeof(buf), &ExamplePacket1, LEN_PKT_NOMAC);
-    TEST_ASSERT_TRUE(strcmp(buf, ExampleDump1) == 0);
+    TEST_ASSERT_EQUAL_STRING(ExampleDump1, buf);
+}
+
+TEST(ntpvis, PacketDump2) {
+    char buf[BUFSIZ];
+
+    packet_dump(buf, sizeof(buf), &ExamplePacket2, LEN_PKT_NOMAC + 4);
+    TEST_ASSERT_EQUAL_STRING(ExampleDump2, buf);
 }
 
 TEST_GROUP_RUNNER(ntpvis) {
-    RUN_TEST_CASE(ntpvis, PacketDump);
+    RUN_TEST_CASE(ntpvis, PacketDump1);
+    RUN_TEST_CASE(ntpvis, PacketDump2);
 }



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/0863405f0e358fe602cf721ecd69bf543a1d4289
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160915/c51e7a44/attachment.html>


More information about the vc mailing list