[Git][NTPsec/ntpsec][pep8fix] 4 commits: tests: add test for libparse.ieee754io. Just a skeleton.

Eric S. Raymond gitlab at mg.gitlab.com
Tue Apr 4 10:55:19 UTC 2017


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


Commits:
6077bf19 by Gary E. Miller at 2017-04-03T22:51:11-07:00
tests: add test for libparse.ieee754io.  Just a skeleton.

- - - - -
60b517f7 by Hal Murray at 2017-04-04T02:15:17-07:00
Add comments to decode dates as magic numbers

- - - - -
2cc696ff by Hal Murray at 2017-04-04T02:15:17-07:00
Fix 2x if DEBUG => ifdef DEBUG (in refclocks)

- - - - -
6494681a by Ian Bruene at 2017-04-04T10:54:57+00:00
Fixed pep8 issues.

- - - - -


7 changed files:

- contrib/make-leap-seconds.py
- ntpd/refclock_jjy.c
- ntpd/refclock_jupiter.c
- tests/common/tests_main.c
- + tests/libparse/ieee754io.c
- tests/pylib/test_util.py
- tests/wscript


Changes:

=====================================
contrib/make-leap-seconds.py
=====================================
--- a/contrib/make-leap-seconds.py
+++ b/contrib/make-leap-seconds.py
@@ -83,7 +83,7 @@ args = sys.argv[1:]
 
 leap = time.time()
 days = int(leap/86400)
-leap = days*86400
+leap = (days+1)*86400
 
 if len(args) > 0:
   leapdate = datetime.datetime.strptime(args[0], "%Y-%m-%d")
@@ -97,13 +97,16 @@ if len(args) > 0:
   expire = (expiredate - epoch).total_seconds()
   expire = int(expire)
   args = args[1:]
+leap_txt = time.asctime(time.gmtime(leap))
 leap = str(leap+JAN_1970)
+expire_txt = time.asctime(time.gmtime(expire))
 expire=str(expire+JAN_1970)
 
-update = time.time()
-days = int(update/86400)
-update = days*86400
+update = int(time.time())
+update_txt = time.asctime(time.gmtime(update))
 update = str(update+JAN_1970)
+
+
 tai = "40"          # hardwired
 
 # File format
@@ -121,13 +124,13 @@ tai = "40"          # hardwired
 #  All dates use NTP epoch of 1900-01-01
 
 sha1 = sha.new()
-print("%s %s" % (leap, tai))
+print("%s %s  # %s" % (leap, tai, leap_txt))
 sha1.update(leap)
 sha1.update(tai)
-print("#$ %s" % update)
-sha1.update(update)
-print("#@ %s" % expire)
+print("#@ %s  # %s" % (expire, expire_txt))
 sha1.update(expire)
+print("#$ %s  # %s" % (update, update_txt))
+sha1.update(update)
 digest = sha1.hexdigest()
 print("#h %s %s %s %s %s" % \
  (digest[0:8], digest[8:16], digest[16:24], digest[24:32], digest[32:40]))


=====================================
ntpd/refclock_jjy.c
=====================================
--- a/ntpd/refclock_jjy.c
+++ b/ntpd/refclock_jjy.c
@@ -3492,7 +3492,7 @@ teljjy_conn_data ( struct peer *peer, struct refclockproc *pp, struct jjyunit *u
 		up->iTimestampCount++ ;
 
 		if ( up->iTimestampCount == 6 && ! up->bLineError ) {
-#if DEBUG
+#ifdef DEBUG
 			printf( "refclock_jjy.c : teljjy_conn_data : bLineError=%d iTimestamp=%d, %d, %d\n",
 				up->bLineError,
 				up->iTimestamp[3], up->iTimestamp[4], up->iTimestamp[5] ) ;


=====================================
ntpd/refclock_jupiter.c
=====================================
--- a/ntpd/refclock_jupiter.c
+++ b/ntpd/refclock_jupiter.c
@@ -589,7 +589,7 @@ jupiter_ppsapi(
 	}
 /*	instance->peer->precision = PPS_PRECISION; */
 
-#if DEBUG
+#ifdef DEBUG
 	if (debug) {
 		time_pps_getparams(instance->pps_handle, &instance->pps_params);
 		jupiter_debug(instance->peer, __func__,


=====================================
tests/common/tests_main.c
=====================================
--- a/tests/common/tests_main.c
+++ b/tests/common/tests_main.c
@@ -62,6 +62,10 @@ static void RunAllTests(void)
 	RUN_TEST_GROUP(ymd2yd);
 #endif
 
+#ifdef TEST_LIBPARSE
+	RUN_TEST_GROUP(ieee754io);
+#endif
+
 #ifdef TEST_NTPD
 	RUN_TEST_GROUP(leapsec);
 	RUN_TEST_GROUP(hackrestrict);


=====================================
tests/libparse/ieee754io.c
=====================================
--- /dev/null
+++ b/tests/libparse/ieee754io.c
@@ -0,0 +1,37 @@
+#include "config.h"
+#include "ntp_stdlib.h"
+#include "ntp_fp.h"
+#include "ieee754io.h"
+#include "timespecops.h"
+
+#include "unity.h"
+#include "unity_fixture.h"
+
+TEST_GROUP(ieee754io);
+
+TEST_SETUP(ieee754io) {}
+
+TEST_TEAR_DOWN(ieee754io) {}
+
+static offsets_t native_off = { 0, 1, 2, 3, 4, 5, 6, 7 };
+
+TEST(ieee754io, test_one) {
+        int ret;
+        unsigned char one[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+	unsigned char *bp = &one[0];
+        l_fp fp;
+
+        printf("hello\n");
+	ret = fetch_ieee754( &bp, IEEE_DOUBLE, &fp,
+            native_off);
+
+        printf("hello\n");
+        printf("%ld\n", (long)fp);
+
+	TEST_ASSERT( IEEE_OK == ret);
+	TEST_ASSERT_EQUAL_INT64( 0, (long)fp );
+}
+
+TEST_GROUP_RUNNER(ieee754io) {
+	RUN_TEST_CASE(ieee754io, test_one);
+}


=====================================
tests/pylib/test_util.py
=====================================
--- a/tests/pylib/test_util.py
+++ b/tests/pylib/test_util.py
@@ -68,9 +68,9 @@ class TestPylibUtilMethods(unittest.TestCase):
         self.assertEqual(ntp.util.scaleforunit(-0.00000042, 9),
                          (-420.0, -3))
         self.assertEqual(ntp.util.scaleforunit(1.0000004, 6),
-                          (1.0, 0))
+                         (1.0, 0))
         self.assertEqual(ntp.util.scaleforunit(1.0000005, 6),
-                          (1.000001, 0))
+                         (1.000001, 0))
 
     def test_oomsbetweenunits(self):
         self.assertEqual(ntp.util.oomsbetweenunits(3, 2),


=====================================
tests/wscript
=====================================
--- a/tests/wscript
+++ b/tests/wscript
@@ -63,6 +63,26 @@ def build(ctx):
         source=libntp_source,
     )
 
+    # libparse/
+    libparse_source = [
+        "libparse/ieee754io.c",
+    ] + common_source
+
+    ctx.ntp_test(
+        defines=unity_config + ["TEST_LIBPARSE=1"],
+        features="c cprogram bld_include src_include test",
+        includes=["%s/tests/unity/" % srcnode,
+                  "%s/tests/libparse/" % srcnode,
+                  "%s/tests/common/" % srcnode
+                  ] + ctx.env.PLATFORM_INCLUDES,
+        install_path=None,
+        lib=["parse"],
+        libpath=["libparse"],
+        source=libparse_source,
+        target="test_libparse",
+        use="unity ntp isc parse M PTHREAD CRYPTO RT SOCKET NSL",
+    )
+
     ntpd_source = [
 #        "ntpd/filegen.c",
         "ntpd/leapsec.c",



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/da4354c1fa87910106745d07f6e1637a02a654be...6494681afc1781a73ed8cf9451d7f30a25034e6b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170404/36d38d7d/attachment.html>


More information about the vc mailing list