[Git][NTPsec/ntpsec][master] TESTFRAME: Remove some auxiliary code only used by TESTFRAME
Eric S. Raymond
gitlab at mg.gitlab.com
Fri Sep 30 11:40:54 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
d2d5278a by Eric S. Raymond at 2016-09-30T07:39:46-04:00
TESTFRAME: Remove some auxiliary code only used by TESTFRAME
- - - - -
5 changed files:
- − libntp/pktvis.c
- libntp/wscript
- tests/common/tests_main.c
- − tests/libntp/ntpvis.c
- tests/wscript
Changes:
=====================================
libntp/pktvis.c deleted
=====================================
--- a/libntp/pktvis.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * pktvis.c - display format for NTP packets, and inverting it.
- */
-#include <config.h>
-
-#include <stdio.h>
-#include <inttypes.h>
-
-#include "ntpd.h"
-#include "ntp_assert.h"
-#include "ntp_fp.h"
-#include "lib_strbuf.h"
-
-#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))
-
-static const int LFP_MAX_PRECISION = 10;
-
-void packet_dump(char *buf, size_t buflen, struct pkt *pkt, size_t len)
-{
- size_t i;
- snprintf(buf, buflen, "%d:%d:%d:%d:%u:%u:%08x:%s:%s:%s:%s:",
- pkt->li_vn_mode, pkt->stratum, pkt->ppoll, pkt->precision,
- pkt->rootdelay, pkt->rootdisp,
- pkt->refid,
- lfptoa(&pkt->reftime, LFP_MAX_PRECISION),
- lfptoa(&pkt->org, LFP_MAX_PRECISION),
- lfptoa(&pkt->rec, LFP_MAX_PRECISION),
- lfptoa(&pkt->xmt, LFP_MAX_PRECISION));
-
- if (len == LEN_PKT_NOMAC)
- strlcat(buf, "nomac", buflen);
- else
- /* dump MAC as len - LEN_PKT_NOMAC chars in hex */
- for (i = 0; i + LEN_PKT_NOMAC < len; i++) {
- snprintf(buf + strlen(buf), buflen - strlen(buf),
- "%02x", BIGEND_GETBYTE(pkt->exten[i / sizeof(uint32_t)], i));
- }
-}
-
-static int packet_parse(char *pktbuf, struct pkt *pkt)
-{
- char refbuf[32], orgbuf[32], recbuf[32], xmtbuf[32], macbuf[BUFSIZ];
- int li_vn_mode = 0, stratum = 0, ppoll = 0, precision = 0;
- size_t pktlen;
-
- if (sscanf(pktbuf, "%d:%d:%d:%d:%u:%u:%08x:%[^:]:%[^:]:%[^:]:%[^:]:%s",
- &li_vn_mode, &stratum,
- &ppoll, &precision,
- &pkt->rootdelay, &pkt->rootdisp,
- &pkt->refid,
- refbuf, orgbuf, recbuf, xmtbuf, macbuf) != 12)
- return -1;
-
- /* extra transfers required because the struct members are int8_t */
- pkt->li_vn_mode = (uint8_t)li_vn_mode;
- pkt->stratum = (uint8_t)stratum;
- pkt->ppoll = (uint8_t)ppoll;
- pkt->precision = (int8_t)precision;
- atolfp(refbuf, &pkt->reftime);
- atolfp(orgbuf, &pkt->org);
- atolfp(recbuf, &pkt->rec);
- atolfp(xmtbuf, &pkt->xmt);
-
- pktlen = LEN_PKT_NOMAC;
- memset(pkt->exten, '\0', sizeof(pkt->exten));
- if (strcmp(macbuf, "nomac") != 0) {
- size_t i;
- for (i = 0; i < strlen(macbuf)/2; i++) {
- int hexval;
- if (sscanf(macbuf + 2*i, "%02x", &hexval) != 1) {
- return -1;
- }
- pkt->exten[i / sizeof(uint32_t)] |= BIGEND_PUTBYTE(hexval, i);
- }
-
- pktlen += i;
- }
- return pktlen;
-}
-
-size_t packet_undump(char *bin, int len, char *pktbuf)
-{
- struct pkt pkt;
- int pktlen = packet_parse(pktbuf, &pkt);
- INSIST((pktlen != -1) && len >= pktlen);
- /* works because pkt fields and extension are in network byte order */
- memcpy(bin, (char *)&pkt, pktlen);
- return pktlen;
-}
-
-/* end */
=====================================
libntp/wscript
=====================================
--- a/libntp/wscript
+++ b/libntp/wscript
@@ -30,7 +30,6 @@ def build(ctx):
"ntp_worker.c",
"numtoa.c",
"numtohost.c",
- "pktvis.c",
"prettydate.c",
"recvbuff.c",
"refidsmear.c",
=====================================
tests/common/tests_main.c
=====================================
--- a/tests/common/tests_main.c
+++ b/tests/common/tests_main.c
@@ -51,7 +51,6 @@ static void RunAllTests(void)
RUN_TEST_GROUP(modetoa);
RUN_TEST_GROUP(msyslog);
RUN_TEST_GROUP(netof);
- RUN_TEST_GROUP(ntpvis);
RUN_TEST_GROUP(numtoa);
RUN_TEST_GROUP(numtohost);
RUN_TEST_GROUP(prettydate);
=====================================
tests/libntp/ntpvis.c deleted
=====================================
--- a/tests/libntp/ntpvis.c
+++ /dev/null
@@ -1,92 +0,0 @@
-#include "config.h"
-#include "ntp_stdlib.h"
-
-#include "unity.h"
-#include "unity_fixture.h"
-
-TEST_GROUP(ntpvis);
-
-#include "ntpd.h"
-#include "timevalops.h"
-
-/* second/usec pair to unsigned lfp */
-#define SECUSECTOTS(sec, usec, ts) \
- do { \
- (ts)->l_ui = (u_long)sec; \
- TVUTOTSF(usec, (ts)->l_uf); \
- } while (false)
-
-
-static struct pkt ExamplePacket1 = {
- .li_vn_mode = 6,
- .stratum = 2,
- .ppoll = 3,
- .precision = -21,
- .rootdelay = 0,
- .rootdisp = 0,
- .refid = 0x47505300, /* big-endian 'GPS\0' */
- .exten = {0},
-};
-static char *ExampleDump1 = "6:2:3:-21:0:0:47505300:1474021718.5261510001:0.0000000000:0.0000000000:0.0000000000:nomac";
-
-/* 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' */
- .exten = {0x01020304},
-};
-static char *ExampleDump2 = "6:2:3:-21:0:0:47505300:1474021718.5261510001:0.0000000000:0.0000000000:0.0000000000:01020304";
-
-TEST_SETUP(ntpvis) {
- /* becomes lfp 1474021718.5261510001 */
- SECUSECTOTS(1474021718, 526151, &ExamplePacket1.reftime);
- SECUSECTOTS(1474021718, 526151, &ExamplePacket2.reftime);
-}
-
-TEST_TEAR_DOWN(ntpvis) {}
-
-TEST(ntpvis, PacketDump1) {
- char buf[BUFSIZ];
-
- packet_dump(buf, sizeof(buf), &ExamplePacket1, LEN_PKT_NOMAC);
- 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(ntpvis, Roundtrip1) {
- char buf1[BUFSIZ], buf2[BUFSIZ], bin[BUFSIZ];
- size_t binlen;
-
- packet_dump(buf1, sizeof(buf1), &ExamplePacket1, LEN_PKT_NOMAC);
- binlen = packet_undump(bin, sizeof(bin), buf1);
- packet_dump(buf2, sizeof(buf2), (struct pkt *)bin, binlen);
- TEST_ASSERT_EQUAL_STRING(buf1, buf2);
-}
-
-TEST(ntpvis, Roundtrip2) {
- char buf1[BUFSIZ], buf2[BUFSIZ], bin[BUFSIZ];
- size_t binlen;
-
- packet_dump(buf1, sizeof(buf1), &ExamplePacket2, LEN_PKT_NOMAC);
- binlen = packet_undump(bin, sizeof(bin), buf1);
- packet_dump(buf2, sizeof(buf2), (struct pkt *)bin, binlen);
- TEST_ASSERT_EQUAL_STRING(buf1, buf2);
-}
-
-TEST_GROUP_RUNNER(ntpvis) {
- RUN_TEST_CASE(ntpvis, PacketDump1);
- RUN_TEST_CASE(ntpvis, PacketDump2);
- RUN_TEST_CASE(ntpvis, Roundtrip1);
- RUN_TEST_CASE(ntpvis, Roundtrip2);
-}
=====================================
tests/wscript
=====================================
--- a/tests/wscript
+++ b/tests/wscript
@@ -65,7 +65,6 @@ def build(ctx):
"libntp/modetoa.c",
"libntp/msyslog.c",
"libntp/netof.c",
- "libntp/ntpvis.c",
"libntp/numtoa.c",
"libntp/numtohost.c",
"libntp/prettydate.c",
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/d2d5278a7aa5acc8d995399e883208cdc5789520
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160930/1b872086/attachment.html>
More information about the vc
mailing list