[Git][NTPsec/ntpsec][master] 2 commits: tests: add missing casts.
Gary E. Miller
gitlab at mg.gitlab.com
Fri Mar 31 03:06:24 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
ded17ce1 by Gary E. Miller at 2017-03-30T18:55:15-07:00
tests: add missing casts.
- - - - -
3f0ed989 by Gary E. Miller at 2017-03-30T20:05:37-07:00
ntploggps: use Logger modules, get log file rotation.
My /var/log/ntpstats/gpsd was getting huge.
- - - - -
2 changed files:
- ntpclients/ntploggps
- tests/libntp/timespecops.c
Changes:
=====================================
ntpclients/ntploggps
=====================================
--- a/ntpclients/ntploggps
+++ b/ntpclients/ntploggps
@@ -20,6 +20,8 @@ See the manual page for details.
from __future__ import print_function
import io
+import logging
+import logging.handlers
import sys
import threading
import time
@@ -44,6 +46,31 @@ ntpologgps: can't find the Python argparse module
sys.exit(1)
+def logging_setup():
+ "Create logging object"
+ logFormat = logging.Formatter('%(message)s')
+ # Create logger for gpsd
+ Logger = logging.getLogger()
+ Logger.setLevel(logging.INFO)
+ # Create file handler
+ if args.logfile:
+ # log to logfile
+ file = logging.handlers.TimedRotatingFileHandler(
+ args.logfile[0],
+ when='midnight',
+ interval=1)
+ else:
+ # log to stdout
+ file = logging.StreamHandler(sys.stdout)
+
+ file.setLevel(logging.INFO)
+ # Create the formatter and add it to the handler
+ file.setFormatter(logFormat)
+ # Add the handler to the logger
+ Logger.addHandler(file)
+ return Logger
+
+
parser = argparse.ArgumentParser(description="gpsd log file generator",
epilog="""
See the manual page for details.
@@ -124,12 +151,13 @@ class GpsPoller(threading.Thread):
"Return the gpsd time fix"
return self.gpsd.fix.time
- def display(self):
+ def log_line(self):
"Displays the time, device, TDOP, and nSat data collected"
- out.write('%s %s %f %d\n' % (gps.isotime(self.get_time()),
- self.gpsd.device,
- self.gpsd.tdop,
- self.gpsd.satellites_used))
+ s = '%s %s %f %d' % (gps.isotime(self.get_time()),
+ self.gpsd.device,
+ self.gpsd.tdop,
+ self.gpsd.satellites_used)
+ return s
if __name__ == '__main__':
# this is the main thread
@@ -138,18 +166,21 @@ if __name__ == '__main__':
gpsp = GpsPoller() # create the thread
try:
+ # Create the logger instance
+ Logger = logging_setup()
+
+ # Create data layout
+ Logger.info("# Time Device TDOP nSat")
+
gpsp.start() # start it up
last_time = 0
- out.write("\n") # print blank line to prevent log corruption
- out.write("# Time Device TDOP nSat\n")
while gpsp.running:
# It may take a second or two to get good data
try:
if 'nan' != gpsp.get_time() and not gps.isnan(gpsp.get_time()):
if last_time != gpsp.get_time():
- gpsp.display()
- out.flush()
+ Logger.info(gpsp.log_line())
last_time = gpsp.get_time()
if args.once:
# just once
@@ -179,7 +210,3 @@ if __name__ == '__main__':
if args.verbose:
print("ntploggps: Done -- Exiting.")
-
- # mom says: be nice and flush
- out.flush()
- out.close()
=====================================
tests/libntp/timespecops.c
=====================================
--- a/tests/libntp/timespecops.c
+++ b/tests/libntp/timespecops.c
@@ -59,11 +59,12 @@ static struct timespec timespec_init(time_t hi, long lo)
static bool AssertFpClose(const l_fp m, const l_fp n, const l_fp limit)
{
- int64_t diff = m - n;
+ int64_t diff = (int64_t)(m - n);
if ((l_fp)llabs(diff) <= limit)
return true;
else {
- printf("m_expr which is %s \nand\nn_expr which is %s\nare not close; diff=%susec\n", lfptoa(m, 10), lfptoa(n, 10), lfptoa(diff, 10));
+ printf("m_expr which is %s \nand\nn_expr which is %s\nare not close; diff=%susec\n",
+ lfptoa(m, 10), lfptoa(n, 10), lfptoa((l_fp)diff, 10));
return false;
}
}
@@ -539,7 +540,7 @@ TEST(timespecops, test_ToLFPabs) {
for (i = 0; i < (int)COUNTOF(fdata); ++i) {
struct timespec a = timespec_init(1, fdata[i].nsec);
- l_fp E = lfpinit(1 + JAN_1970, fdata[i].frac);
+ l_fp E = lfpinit((int)(1 + JAN_1970), fdata[i].frac);
l_fp r;
r = tspec_stamp_to_lfp(a);
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/0e9a9305ea6331085dd9b5ad4cef3cb87874bb15...3f0ed9899e2b7770e55812feafe88b83f075c098
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170331/d408e8ec/attachment.html>
More information about the vc
mailing list