During this season of giving, you can show your support for the NTP Project by making a donation to Network Time Foundation.

Leap Second Testing

This page is a simple description of testing the leap-second implementation in NTP, this is part of my GSoC project as suggested by Harlan and I got many help from Martin.

This page is not completed yet and may contains incorrect information, I'll update it in few more days and any comment about mistakes are welcomed.

Setting up a Test Server

This part is pretty much a tutorial than a documentation, I'll list all the necessary steps of setting up a test server with fake time for the following tests, all the commands are based on Ubuntu 12.04 LTS system and may differ from other distributions and/or systems.

A test server can be simply simulated by setting up a NTP server and a file from NIST that describes all leap seconds. I use a pre-build ntpd from Ubuntu's repo to simplify the commands, if a ntp-dev is needed, you have to compile it by own.

The NTP Public Services Project operates an autobuilder which creates Debian packages (both i386 binary for the current Debian Stable Release and source) for each NTP-Dev snapshot release. The binary packages may be installable on OSes such as Ubuntu which are derived from Debian. The source packages may be used to compile binary packages for non-i386 architectures and when customizations are required.

-- SteveKostecke - 2013-09-26

Firstly, we install a ntp daemon. To install the pre-packaged version NTP shipped with Ubuntu:
sudo apt-get install ntp
To install the NTP Public Service Project's pre-packaged version of NTP-dev:
sudo apt-get install ntp-dev

And we get file from a NIST ftp server. This file is available on all the NIST servers, I just used a random one, for more infomation on this file, check Support.ConfiguringNTP#Section_6.14.
sudo mkdir /var/ntp && cd /var/ntp
sudo wget ftp://nist1-ny2.ustiming.org/pub/leap-seconds.list

Then we need to change settings of ntpd so that it can announce a fake time.
sudo vi /etc/ntp.conf

We just comment all the `server` lines out, and set the server itself as refclock as described in Support.UndisciplinedLocalClock:

fudge stratum 10
leapfile "/var/ntp/leap-seconds.list"

Now we set the system time to somewhere a little before a leap second took place, e.g, Jun 30, 2012, and then restart the ntpd daemon.
sudo date -s "2012-06-30 23:30"
sudo service ntp restart

Now we just got back to 30 minutes earlier than a leap-second in the past.

The test I write for leap second is very simple, a 50-times loop is executed and check current system time every 100ms (using nanosleep() to set the time step), then out put the data of all the 5 seconds to a file. The test is writen under NTP's unit test framework and can be executed with 'make check' as well as all the other tests, the test code is located at ~zhong/gsoc13/ntp-unit-test/tests/libntp/systime.cpp and the output file is within the same directory at /the/full/path/tests/libntp/data/leap.test.

-- AllenZhong - 2013-09-26
Topic revision: r8 - 10 Oct 2022, DruLavigne
Copyright © by the contributing authors.Use of this website indicates your agreement with, and acceptance of, the PrivacyPolicy, the WikiDisclaimer, and the PrivateWebPolicy.