[Git][NTPsec/ntpsec][working] 24 commits: Remove unused cruft from peer structure - was for asymmetry corrections??

Ian Bruene gitlab at mg.gitlab.com
Tue Jul 10 19:24:17 UTC 2018


Ian Bruene pushed to branch working at NTPsec / ntpsec


Commits:
4fa0e409 by Hal Murray at 2018-07-06T05:57:13Z
Remove unused cruft from peer structure - was for asymmetry corrections??

- - - - -
d3b93d7d by Hal Murray at 2018-07-06T06:04:54Z
Remove RES_ALLFLAGS, update MAC_LEN comments

- - - - -
ff4dde80 by Hal Murray at 2018-07-07T22:24:17Z
Cleanup ntp_random()
	drop use of ntp_be32dec
	check return code - crash if didn't work

- - - - -
693211aa by Hal Murray at 2018-07-07T22:39:56Z
Add crude test for ntp_random

- - - - -
1b3f83d9 by Hal Murray at 2018-07-07T22:48:41Z
Move ntp_random to shared, drop dummy ntp_random() from pymodule.c

- - - - -
520337d2 by Hal Murray at 2018-07-08T04:31:26Z
remove unused unmarshall_pkt from libntp/recvbuff.c
  and extract_32bits_from_stream too

- - - - -
e62391bf by Dan McGee at 2018-07-08T19:52:59Z
Add geteuid32 to list of permitted syscalls

`geteuid` is already in the list, but on Arch Linux ARM (for instance,
on a Raspberry Pi), this additional call is needed.

- - - - -
4633a9b4 by Ian Bruene at 2018-07-10T19:18:00Z
Added test for ntpcal_ntp_to_ntp.

- - - - -
385ab7af by Ian Bruene at 2018-07-10T19:18:00Z
Added test for ntpcal_daysec_to_date.

- - - - -
8b5084ae by Ian Bruene at 2018-07-10T19:18:00Z
Added test for ntpcal_split_eradays.

- - - - -
f0f01740 by Ian Bruene at 2018-07-10T19:18:00Z
Added test for ntpcal_time_to_date.

- - - - -
71b4f27e by Ian Bruene at 2018-07-10T19:18:00Z
Added test for ntpcal_days_in_years.

- - - - -
892112cc by Ian Bruene at 2018-07-10T19:18:00Z
Added test for ntpcal_edate_to_eradays.

- - - - -
58fbeef9 by Ian Bruene at 2018-07-10T19:18:00Z
Added test for ntpcal_etime_to_seconds.

- - - - -
9b09967b by Ian Bruene at 2018-07-10T19:18:00Z
Added test for ntpcal_tm_to_rd.

- - - - -
fc19fb93 by Ian Bruene at 2018-07-10T19:18:00Z
Added tests for ntpcal_date_to_daysec and ntpcal_tm_to_daysec.

- - - - -
3d185556 by Ian Bruene at 2018-07-10T19:18:00Z
Added test for ntpcal_date_to_time.

- - - - -
0b334f66 by Ian Bruene at 2018-07-10T19:18:00Z
Added tests for ntpcal_ntp64_to_date, ntpcal_ntp_to_date.

- - - - -
243f5e2f by Ian Bruene at 2018-07-10T19:18:00Z
Added test for ntpcal_periodic_event.

- - - - -
23968330 by Ian Bruene at 2018-07-10T19:18:00Z
Fix for 32-bit error in ntpcal_date_to_time test.

- - - - -
050e7497 by Ian Bruene at 2018-07-10T19:18:00Z
Added tests for functions in prettydate.c

- - - - -
810a51b4 by Ian Bruene at 2018-07-10T19:19:47Z
Merge.

- - - - -
cdb2c74e by Ian Bruene at 2018-07-10T19:21:29Z
Fixed indentation.

- - - - -
56154f24 by Ian Bruene at 2018-07-10T19:21:30Z
Whitespace fixes.

- - - - -


14 changed files:

- include/ntp.h
- include/recvbuff.h
- libntp/ntp_random.c
- libntp/pymodule.c
- libntp/recvbuff.c
- libntp/wscript
- ntpd/ntp_control.c
- ntpd/ntp_proto.c
- ntpd/ntp_sandbox.c
- tests/common/tests_main.c
- tests/libntp/ntp_calendar.c
- + tests/libntp/ntp_random.c
- tests/libntp/prettydate.c
- tests/wscript


Changes:

=====================================
include/ntp.h
=====================================
@@ -284,17 +284,6 @@ struct peer {
 	double	jitter;		/* peer jitter (squares) */
 	double	disp;		/* peer dispersion */
 
-	/*
-	 * Variables used to correct for packet length and asymmetry.
-	 */
-	double	t21;		/* outbound packet delay */
-	int	t21_bytes;	/* outbound packet length */
-	int	t21_last;	/* last outbound packet length */
-	double	r21;		/* outbound data rate */
-	double	t34;		/* inbound packet delay */
-	int	t34_bytes;	/* inbound packet length */
-	double	r34;		/* inbound data rate */
-
 	/*
 	 * End of clear-to-zero area
 	 */
@@ -435,9 +424,13 @@ struct pkt {
 	l_fp_w	rec;		/* receive time stamp */
 	l_fp_w	xmt;		/* transmit time stamp */
 
+/* Old style authentication was just appended
+ * without the type/length of an extension header. */
+/* Length includes 1 word of keyID */
+/* MD5 length is 16 bytes => 4+1 */
+/* SHA length is 20 bytes => 5+1 */
 #define MIN_MAC_LEN	(1 * sizeof(uint32_t))	/* crypto_NAK */
-#define MAX_MD5_LEN	(5 * sizeof(uint32_t))	/* MD5 */
-#define	MAX_MAC_LEN	(6 * sizeof(uint32_t))	/* SHA */
+#define	MAX_MAC_LEN	(6 * sizeof(uint32_t))	/* MAX of old style */
 
 	uint32_t	exten[(MAX_MAC_LEN) / sizeof(uint32_t)];
 } __attribute__ ((aligned));
@@ -689,11 +682,6 @@ struct restrict_u_tag {
 #define	RES_FLAKE		0x1000	/* flakeway - drop 10% */
 #define	RES_NOMRULIST		0x2000	/* mode 6 mrulist denied */
 
-#define	RES_ALLFLAGS		(RES_FLAGS | RES_NOQUERY |	\
-				 RES_NOMODIFY | RES_KOD |	\
-				 RES_MSSNTP | RES_FLAKE |	\
-				 RES_NOMRULIST)
-
 /* pythonize-header: start ignoring */
 
 /*


=====================================
include/recvbuff.h
=====================================
@@ -58,8 +58,6 @@ struct recvbuf {
 #endif /* REFCLOCK */
 };
 
-extern void unmarshall_pkt(struct pkt *, struct recvbuf *);
-
 extern	void	init_recvbuff(unsigned int); /* not really pure */
 
 /* freerecvbuf - make a single recvbuf available for reuse


=====================================
libntp/ntp_random.c
=====================================
@@ -11,12 +11,21 @@
 
 #include "config.h"
 #include "ntp.h"
-#include "ntp_endian.h"
+
+/* NB: RAND_bytes comes from OpenSSL
+ * Starting in version 1.1.1, it reseeds itself occasionally.
+ * That needs access to /dev/urandom which may be blocked by chroot jails.
+ */
 
 int32_t
 ntp_random(void)
 {
-	unsigned char rnd[sizeof(uint32_t)];
-	RAND_bytes(rnd, sizeof(rnd));
-	return (int32_t)ntp_be32dec(rnd);
+	int err;
+	uint32_t rnd;
+	err = RAND_bytes((unsigned char *)&rnd, sizeof(rnd));
+	if (1 != err) {
+		msyslog(LOG_ERR, "ERR: ntp_random - RAND_bytes failed");
+	  exit(1);
+	}
+	return rnd;
 }


=====================================
libntp/pymodule.c
=====================================
@@ -142,12 +142,6 @@ ntpc_step_systime(PyObject *self, PyObject *args)
     return Py_BuildValue("d", step_systime(full_adjustment, ntp_set_tod));
 }
 
-int32_t ntp_random(void)
-/* stub random function for get_systime() */
-{
-    return 0;
-}
-
 /* List of functions defined in the module */
 
 static PyMethodDef ntpc_methods[] = {


=====================================
libntp/recvbuff.c
=====================================
@@ -18,11 +18,6 @@ static unsigned long total_recvbufs;	/* total recvbufs currently in use */
 static unsigned long lowater_adds;	/* # of times we have added memory */
 static unsigned long buffer_shortfall;	/* # of missed free receive buffers
 					   between replenishments */
-/*
- * Unmarshalling helper
- */
-extern uint32_t extract_32bits_from_stream(uint8_t *);
-
 static DECL_FIFO_ANCHOR(recvbuf_t) full_recv_fifo;
 static recvbuf_t *		   free_recv_list;
 	
@@ -261,41 +256,3 @@ check_gen_fifo_consistency(void *fifo)
 }
 #endif	/* NTP_DEBUG_LISTS */
 
-void
-unmarshall_pkt(struct pkt *rpkt, struct recvbuf *rbufp)
-{
-    rpkt->li_vn_mode = (uint8_t)rbufp->recv_buffer[0];
-    rpkt->stratum = (uint8_t)rbufp->recv_buffer[1];
-    rpkt->ppoll = (uint8_t)rbufp->recv_buffer[2];
-    rpkt->precision = (int8_t)rbufp->recv_buffer[3];
-	// rootdelay
-	rpkt->rootdelay = extract_32bits_from_stream(&rbufp->recv_buffer[4]);
-	// rootdisp
-	rpkt->rootdisp = extract_32bits_from_stream(&rbufp->recv_buffer[8]);
-	// refid
-	rpkt->refid = extract_32bits_from_stream(&rbufp->recv_buffer[12]);
-	// reftime
-	rpkt->reftime.l_ui = extract_32bits_from_stream(&rbufp->recv_buffer[16]);
-	rpkt->reftime.l_uf = extract_32bits_from_stream(&rbufp->recv_buffer[20]);
-	// org
-	rpkt->org.l_ui = extract_32bits_from_stream(&rbufp->recv_buffer[24]);
-	rpkt->org.l_uf = extract_32bits_from_stream(&rbufp->recv_buffer[28]);
-	// rec
-	rpkt->rec.l_ui = extract_32bits_from_stream(&rbufp->recv_buffer[32]);
-	rpkt->rec.l_uf = extract_32bits_from_stream(&rbufp->recv_buffer[36]);
-	// xmt
-	rpkt->xmt.l_ui = extract_32bits_from_stream(&rbufp->recv_buffer[40]);
-	rpkt->xmt.l_uf = extract_32bits_from_stream(&rbufp->recv_buffer[44]);
-}
-
-uint32_t
-extract_32bits_from_stream(uint8_t *addr)
-{
-    uint32_t var = 0;
-	var = (uint32_t)*addr << 24;
-	var |= (uint32_t)*(addr + 1) << 16;
-	var |= (uint32_t)*(addr + 2) << 8;
-	var |= (uint32_t)*(addr + 3);
-	var = ntohl(var);
-	return var;
-}


=====================================
libntp/wscript
=====================================
@@ -15,7 +15,6 @@ def build(ctx):
         "macencrypt.c",
         "netof.c",
         "ntp_endian.c",
-        "ntp_random.c",
         "ntp_dns.c",
         "numtoa.c",
         "recvbuff.c",
@@ -33,6 +32,7 @@ def build(ctx):
         "lib_strbuf.c",
         "msyslog.c",
         "ntp_calendar.c",
+        "ntp_random.c",
         "prettydate.c",
         "statestr.c",
         "systime.c",


=====================================
ntpd/ntp_control.c
=====================================
@@ -272,19 +272,17 @@ static const struct ctl_proc control_codes[] = {
 #define	CP_FLASH		35
 #define	CP_MODE			36
 #define	CP_VARLIST		37
-#define	CP_IN			38
-#define	CP_OUT			39
-#define	CP_RATE			40
-#define	CP_BIAS			41
-#define	CP_SRCHOST		42
-#define	CP_TIMEREC		43
-#define	CP_TIMEREACH		44
-#define	CP_BADAUTH		45
-#define	CP_BOGUSORG		46
-#define	CP_OLDPKT		47
-#define	CP_SELDISP		48
-#define	CP_SELBROKEN		49
-#define	CP_CANDIDATE		50
+#define	CP_RATE			38
+#define	CP_BIAS			39
+#define	CP_SRCHOST		40
+#define	CP_TIMEREC		41
+#define	CP_TIMEREACH		42
+#define	CP_BADAUTH		43
+#define	CP_BOGUSORG		44
+#define	CP_OLDPKT		45
+#define	CP_SELDISP		46
+#define	CP_SELBROKEN		47
+#define	CP_CANDIDATE		48
 #define	CP_MAXCODE		CP_CANDIDATE
 
 /*
@@ -500,20 +498,18 @@ static const struct ctl_var peer_var[] = {
 	{ CP_FLASH,	RO, "flash" },		/* 35 */
 	{ CP_MODE,	RO, "mode" },		/* 36 */
 	{ CP_VARLIST,	RO, "peer_var_list" },	/* 37 */
-	{ CP_IN,	RO, "in" },		/* 38 */
-	{ CP_OUT,	RO, "out" },		/* 39 */
-	{ CP_RATE,	RO, "headway" },	/* 40 */
-	{ CP_BIAS,	RO, "bias" },		/* 41 */
-	{ CP_SRCHOST,	RO, "srchost" },	/* 42 */
-	{ CP_TIMEREC,	RO, "timerec" },	/* 43 */
-	{ CP_TIMEREACH,	RO, "timereach" },	/* 44 */
-	{ CP_BADAUTH,	RO, "badauth" },	/* 45 */
-	{ CP_BOGUSORG,	RO, "bogusorg" },	/* 46 */
-	{ CP_OLDPKT,	RO, "oldpkt" },		/* 47 */
-	{ CP_SELDISP,	RO, "seldisp" },	/* 48 */
-	{ CP_SELBROKEN,	RO, "selbroken" },	/* 49 */
-	{ CP_CANDIDATE, RO, "candidate" },	/* 50 */
-	{ 0,		EOV, "" }		/* 50/58 */
+	{ CP_RATE,	RO, "headway" },	/* 38 */
+	{ CP_BIAS,	RO, "bias" },		/* 39 */
+	{ CP_SRCHOST,	RO, "srchost" },	/* 40 */
+	{ CP_TIMEREC,	RO, "timerec" },	/* 41 */
+	{ CP_TIMEREACH,	RO, "timereach" },	/* 42 */
+	{ CP_BADAUTH,	RO, "badauth" },	/* 43 */
+	{ CP_BOGUSORG,	RO, "bogusorg" },	/* 44 */
+	{ CP_OLDPKT,	RO, "oldpkt" },		/* 45 */
+	{ CP_SELDISP,	RO, "seldisp" },	/* 46 */
+	{ CP_SELBROKEN,	RO, "selbroken" },	/* 47 */
+	{ CP_CANDIDATE, RO, "candidate" },	/* 48 */
+	{ 0,		EOV, "" }
 };
 
 
@@ -526,8 +522,6 @@ static const uint8_t def_peer_var[] = {
 	CP_SRCHOST,
 	CP_DSTADR,
 	CP_DSTPORT,
-	CP_OUT,
-	CP_IN,
 	CP_LEAP,
 	CP_STRATUM,
 	CP_PRECISION,
@@ -2131,16 +2125,6 @@ ctl_putpeer(
 				: 0);
 		break;
 
-	case CP_IN:
-		if (p->r21 > 0.)
-			ctl_putdbl(peer_var[id].text, p->r21 / MS_PER_S);
-		break;
-
-	case CP_OUT:
-		if (p->r34 > 0.)
-			ctl_putdbl(peer_var[id].text, p->r34 / MS_PER_S);
-		break;
-
 	case CP_RATE:
 		ctl_putuint(peer_var[id].text, p->throttle);
 		break;


=====================================
ntpd/ntp_proto.c
=====================================
@@ -2089,7 +2089,6 @@ peer_xmit(
 		get_systime(&xmt_tx);
 		peer->org = xmt_tx;
 		xpkt.xmt = htonl_fp(xmt_tx);
-		peer->t21_bytes = (int)sendlen;
 		sendpkt(&peer->srcadr, peer->dstadr, &xpkt, (int)sendlen);
 		peer->sent++;
 		peer->outcount++;
@@ -2126,7 +2125,6 @@ peer_xmit(
 		msyslog(LOG_ERR, "PROTO: buffer overflow %zu", sendlen);
 		exit(1);
 	}
-	peer->t21_bytes = (int)sendlen;
 	sendpkt(&peer->srcadr, peer->dstadr, &xpkt, (int)sendlen);
 	peer->sent++;
         peer->outcount++;


=====================================
ntpd/ntp_sandbox.c
=====================================
@@ -411,6 +411,9 @@ int scmp_sc[] = {
 	SCMP_SYS(geteuid),
 	SCMP_SYS(ppoll),
 	SCMP_SYS(sendmsg),
+#ifdef __NR_geteuid32
+	SCMP_SYS(geteuid32),
+#endif
 
 #ifdef __NR_mmap
 	/* gentoo 64-bit and 32-bit, Intel and Arm use mmap */


=====================================
tests/common/tests_main.c
=====================================
@@ -51,6 +51,7 @@ static void RunAllTests(void)
 	RUN_TEST_GROUP(netof6);
 	RUN_TEST_GROUP(numtoa);
 	RUN_TEST_GROUP(prettydate);
+	RUN_TEST_GROUP(random);
 	RUN_TEST_GROUP(recvbuff);
 	RUN_TEST_GROUP(refidsmear);
 	RUN_TEST_GROUP(socktoa);


=====================================
tests/libntp/ntp_calendar.c
=====================================
@@ -128,11 +128,27 @@ TEST(calendar, parse_to_unixtime) {
 }
 #endif
 
-// test the NTP to Unix time conversion
+TEST(calendar, PeriodicExtend1) {
+    // Test positive cycle, pivot > value
+    TEST_ASSERT_EQUAL(1001, ntpcal_periodic_extend(1000, 5, 2));
+    // Test positive cycle, pivot < value
+    TEST_ASSERT_EQUAL(6, ntpcal_periodic_extend(5, 1000, 2));
+    // Test negative cycle, pivot > value
+    TEST_ASSERT_EQUAL(999, ntpcal_periodic_extend(1000, 5, -2));
+    // Test negative cycle, pivot < value
+    TEST_ASSERT_EQUAL(4, ntpcal_periodic_extend(5, 1000, -2));
+}
+
+// test the NTP to 64-bit Unix scale time conversion
 TEST(calendar, NtpToTime1) {
   TEST_ASSERT_EQUAL(2085978538, ntpcal_ntp_to_time(42, 23));
 }
 
+// test the NTP to 64-bit NTP scale time conversion
+TEST(calendar, NtpToNtp1) {
+  TEST_ASSERT_EQUAL(4294967338, ntpcal_ntp_to_ntp(42, 23));
+}
+
 // test the day/sec join & split ops, making sure that 32bit
 // intermediate results would definitely overflow and the hi DWORD of
 // the 'time64_t' is definitely needed.
@@ -162,6 +178,37 @@ TEST(calendar, DaySplitMerge) {
 	}
 }
 
+TEST(calendar, SplitEraDays1) {
+    ntpcal_split res;
+	int32_t isleapyear = 42;
+
+	// Test no flag, no-leap, positive
+	res = ntpcal_split_eradays(4, NULL);
+	TEST_ASSERT_EQUAL(0, res.hi);
+	TEST_ASSERT_EQUAL(4, res.lo);
+	TEST_ASSERT_EQUAL(42, isleapyear);
+
+	// Test flag, no-leap, positive
+	res = ntpcal_split_eradays(4, &isleapyear);
+	TEST_ASSERT_EQUAL(0, res.hi);
+	TEST_ASSERT_EQUAL(4, res.lo);
+	TEST_ASSERT_EQUAL(0, isleapyear);
+
+	// Test flag, leap, positive
+	res = ntpcal_split_eradays(1400, &isleapyear);
+	TEST_ASSERT_EQUAL(3, res.hi);
+	TEST_ASSERT_EQUAL(305, res.lo);
+	TEST_ASSERT_EQUAL(1, isleapyear);
+
+	isleapyear = 0;
+
+	// Test flag, leap, negative
+	res = ntpcal_split_eradays(-100, &isleapyear);
+	TEST_ASSERT_EQUAL(-1, res.hi);
+	TEST_ASSERT_EQUAL(266, res.lo);
+	TEST_ASSERT_EQUAL(1, isleapyear);
+}
+
 TEST(calendar, SplitYearDays1) {
 	int32_t eyd;
 
@@ -201,6 +248,84 @@ TEST(calendar, RataDie1) {
 	TEST_ASSERT_TRUE(IsEqualDate(&expected, &actual));
 }
 
+TEST(calendar, DaysecToDate1) {
+    struct calendar cal;
+	int32_t days;
+
+	// Test normal date
+	days = ntpcal_daysec_to_date(&cal, 100000);
+	TEST_ASSERT_EQUAL(days, 1);
+	TEST_ASSERT_EQUAL(cal.hour, 3);
+	TEST_ASSERT_EQUAL(cal.minute, 46);
+	TEST_ASSERT_EQUAL(cal.second, 40);
+
+	// Test negative date
+	days = ntpcal_daysec_to_date(&cal, -100000);
+	TEST_ASSERT_EQUAL(-2, days);
+	TEST_ASSERT_EQUAL(20, cal.hour);
+	TEST_ASSERT_EQUAL(13, cal.minute);
+	TEST_ASSERT_EQUAL(20, cal.second);
+}
+
+TEST(calendar, TimeToDate1) {
+    struct calendar jd = {0, 0, 0, 0, 0, 0, 0, 0};
+	int res;
+
+	res = ntpcal_time_to_date(&jd, 1000000);
+	TEST_ASSERT_EQUAL(0, res);
+	TEST_ASSERT_EQUAL(1970, jd.year);
+	TEST_ASSERT_EQUAL(12, jd.yearday);
+	TEST_ASSERT_EQUAL(1, jd.month);
+	TEST_ASSERT_EQUAL(12, jd.monthday);
+	TEST_ASSERT_EQUAL(13, jd.hour);
+	TEST_ASSERT_EQUAL(46, jd.minute);
+	TEST_ASSERT_EQUAL(40, jd.second);
+	TEST_ASSERT_EQUAL(1, jd.weekday);
+}
+
+TEST(calendar, DayJoin1) {
+	TEST_ASSERT_EQUAL(4323600, ntpcal_dayjoin(50, 3600));
+}
+
+TEST(calendar, DaysInYears1) {
+    // Test positive less than one gregorian cycle of years
+    TEST_ASSERT_EQUAL(109572, ntpcal_days_in_years(300));
+    // Test positive one gregorian cycle of years
+    TEST_ASSERT_EQUAL(146097, ntpcal_days_in_years(400));
+    // Test positive greater than one gregorian cycle of years
+    TEST_ASSERT_EQUAL(182621, ntpcal_days_in_years(500));
+    // Test negative less than one gregorian cycle of years
+    TEST_ASSERT_EQUAL(-109573, ntpcal_days_in_years(-300));
+    // Test negative one gregorian cycle of years
+    TEST_ASSERT_EQUAL(-146097, ntpcal_days_in_years(-400));
+    // Test negative greater than one gregorian cycle of years
+    TEST_ASSERT_EQUAL(-182622, ntpcal_days_in_years(-500));
+}
+
+TEST(calendar, EdateToEradays1) {
+    // Test positive, no months
+    TEST_ASSERT_EQUAL(1827, ntpcal_edate_to_eradays(5, 0, 1));
+    // Test positive, with months
+    TEST_ASSERT_EQUAL(1917, ntpcal_edate_to_eradays(5, 3, 1));
+    // Test negative, no months
+    TEST_ASSERT_EQUAL(-1828, ntpcal_edate_to_eradays(-5, 0, -1));
+    // Test negative, with months
+    TEST_ASSERT_EQUAL(-1920, ntpcal_edate_to_eradays(-5, -3, -1));
+}
+
+TEST(calendar, EtimeToSeconds1) {
+    TEST_ASSERT_EQUAL(18181, ntpcal_etime_to_seconds(5, 3, 1));
+}
+
+TEST(calendar, TmToRd1) {
+    struct tm utm;
+
+    utm.tm_year = 10;
+    utm.tm_mon = 5;
+    utm.tm_mday = 1;
+    TEST_ASSERT_EQUAL(697399, ntpcal_tm_to_rd(&utm));
+}
+
 // check last day of february for first 10000 years
 TEST(calendar, LeapYears1) {
 	struct calendar dateIn, dateOut;
@@ -263,6 +388,60 @@ TEST(calendar, RoundTripDate) {
 	}
 }
 
+TEST(calendar, DateToDaysec1) {
+    struct calendar jd;
+
+	jd.hour = 18;
+	jd.minute = 45;
+	jd.second = 15;
+	TEST_ASSERT_EQUAL(67515, ntpcal_date_to_daysec(&jd));
+}
+
+TEST(calendar, TmToDaysec1) {
+    struct tm utm;
+
+	utm.tm_hour = 18;
+	utm.tm_min = 45;
+	utm.tm_sec = 15;
+	TEST_ASSERT_EQUAL(67515, ntpcal_tm_to_daysec(&utm));
+}
+
+TEST(calendar, DateToTime1) {
+    struct calendar jd;
+
+	jd.year = 2000;
+	jd.month = 2;
+	jd.monthday = 4;
+	jd.hour = 8;
+	jd.minute = 16;
+	jd.second = 32;
+	TEST_ASSERT_EQUAL(949652192, ntpcal_date_to_time(&jd));
+}
+
+TEST(calendar, Ntp64ToDate1) {
+    struct calendar jd;
+
+	TEST_ASSERT_EQUAL(0, ntpcal_ntp64_to_date(&jd, 10000000));
+	TEST_ASSERT_EQUAL(1900, jd.year);
+	TEST_ASSERT_EQUAL(4, jd.month);
+	TEST_ASSERT_EQUAL(26, jd.monthday);
+	TEST_ASSERT_EQUAL(17, jd.hour);
+	TEST_ASSERT_EQUAL(46, jd.minute);
+	TEST_ASSERT_EQUAL(40, jd.second);
+}
+
+TEST(calendar, NtpToDate1) {
+    struct calendar jd;
+
+	TEST_ASSERT_EQUAL(1, ntpcal_ntp_to_date(&jd, 86400, 1000000));
+	TEST_ASSERT_EQUAL(2036, jd.year);
+	TEST_ASSERT_EQUAL(2, jd.month);
+	TEST_ASSERT_EQUAL(8, jd.monthday);
+	TEST_ASSERT_EQUAL(6, jd.hour);
+	TEST_ASSERT_EQUAL(28, jd.minute);
+	TEST_ASSERT_EQUAL(16, jd.second);
+}
+
 
 TEST_GROUP_RUNNER(calendar) {
 	RUN_TEST_CASE(calendar, is_leapyear);
@@ -271,12 +450,27 @@ TEST_GROUP_RUNNER(calendar) {
 #ifdef CLOCK_GENERIC
 	RUN_TEST_CASE(calendar, parse_to_unixtime);
 #endif
+	RUN_TEST_CASE(calendar, PeriodicExtend1);
 	RUN_TEST_CASE(calendar, NtpToTime1);
+	RUN_TEST_CASE(calendar, NtpToNtp1);
 	RUN_TEST_CASE(calendar, DaySplitMerge);
+	RUN_TEST_CASE(calendar, DaysecToDate1);
+	RUN_TEST_CASE(calendar, SplitEraDays1);
 	RUN_TEST_CASE(calendar, SplitYearDays1);
 	RUN_TEST_CASE(calendar, SplitYearDays2);
 	RUN_TEST_CASE(calendar, RataDie1);
+	RUN_TEST_CASE(calendar, TimeToDate1);
+	RUN_TEST_CASE(calendar, DayJoin1);
+	RUN_TEST_CASE(calendar, DaysInYears1);
+	RUN_TEST_CASE(calendar, EdateToEradays1);
+	RUN_TEST_CASE(calendar, EtimeToSeconds1);
+	RUN_TEST_CASE(calendar, TmToRd1);
 	RUN_TEST_CASE(calendar, LeapYears1);
 	RUN_TEST_CASE(calendar, LeapYears2);
 	RUN_TEST_CASE(calendar, RoundTripDate);
+	RUN_TEST_CASE(calendar, DateToDaysec1);
+	RUN_TEST_CASE(calendar, TmToDaysec1);
+	RUN_TEST_CASE(calendar, DateToTime1);
+	RUN_TEST_CASE(calendar, Ntp64ToDate1);
+	RUN_TEST_CASE(calendar, NtpToDate1);
 }


=====================================
tests/libntp/ntp_random.c
=====================================
@@ -0,0 +1,37 @@
+#include "config.h"
+#include "ntp.h"
+
+#include "unity.h"
+#include "unity_fixture.h"
+
+TEST_GROUP(random);
+
+TEST_SETUP(random) {}
+
+TEST_TEAR_DOWN(random) {}
+
+
+TEST(random, random32) {
+	int i;
+	uint32_t ones = 0;
+	uint32_t zeros = ~0;
+
+	/* This is just a crude sanity check.
+	 * It could fail when working correctly,
+	 * but the chances are pretty small.
+	 * It won't be reproducable.  ;)
+	 * You can test this code by making the loop count smaller.
+	 */
+	for (i=0; i<99; i++) {
+		uint32_t sample = ntp_random();
+		ones |= sample;
+		zeros &= sample; 
+	}
+
+	TEST_ASSERT_EQUAL_INT32(~0, ones);
+	TEST_ASSERT_EQUAL_INT32(0, zeros);
+}
+
+TEST_GROUP_RUNNER(random) {
+	RUN_TEST_CASE(random, random32);
+}


=====================================
tests/libntp/prettydate.c
=====================================
@@ -19,6 +19,14 @@ TEST_TEAR_DOWN(prettydate) {}
 
 static const uint32_t HALF = 2147483648UL;
 
+TEST(prettydate, Rfc3339Date1) {
+    TEST_ASSERT_EQUAL_STRING("2036-02-07T06:28:16.000Z", rfc3339date(0));
+}
+
+TEST(prettydate, Rfc3339Time1) {
+    TEST_ASSERT_EQUAL_STRING("2036-02-07T06:28:16.000Z", rfc3339date(0));
+}
+
 TEST(prettydate, ConstantDate) {
     l_fp t = lfpinit((int32_t)3485080800LL, HALF); // 2010-06-09 14:00:00.5
 
@@ -27,4 +35,6 @@ TEST(prettydate, ConstantDate) {
 
 TEST_GROUP_RUNNER(prettydate) {
 	RUN_TEST_CASE(prettydate, ConstantDate);
+	RUN_TEST_CASE(prettydate, Rfc3339Date1);
+	RUN_TEST_CASE(prettydate, Rfc3339Time1);
 }


=====================================
tests/wscript
=====================================
@@ -35,6 +35,7 @@ def build(ctx):
     libntp_source = [
         "libntp/authkeys.c",
         "libntp/ntp_calendar.c",
+        "libntp/ntp_random.c",
         "libntp/clocktime.c",
         "libntp/decodenetnum.c",
         "libntp/hextolfp.c",



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/f1e14748ef0dce08b698a91528634d15adc2e8bc...56154f2447356d6613d40e524ebb85bc0ac3c532

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/f1e14748ef0dce08b698a91528634d15adc2e8bc...56154f2447356d6613d40e524ebb85bc0ac3c532
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180710/2d1b30e8/attachment.html>


More information about the vc mailing list