diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-12 05:01:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-12 05:01:24 +0000 |
commit | 15d5aecc5b2123bab1a374d36420f5752096d081 (patch) | |
tree | 5300829fb1e869c2ace0b1b5b8bfc68faaa98472 /test | |
parent | Releasing progress-linux version 4.5-3~progress7.99u1. (diff) | |
download | chrony-15d5aecc5b2123bab1a374d36420f5752096d081.tar.xz chrony-15d5aecc5b2123bab1a374d36420f5752096d081.zip |
Merging upstream version 4.6.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | test/compilation/002-scanbuild | 1 | ||||
-rwxr-xr-x | test/simulation/008-ntpera | 1 | ||||
-rwxr-xr-x | test/simulation/106-refclock | 13 | ||||
-rwxr-xr-x | test/simulation/108-peer | 2 | ||||
-rwxr-xr-x | test/simulation/110-chronyc | 20 | ||||
-rwxr-xr-x | test/simulation/113-leapsecond | 88 | ||||
-rwxr-xr-x | test/simulation/118-maxdelay | 1 | ||||
-rwxr-xr-x | test/simulation/119-smoothtime | 2 | ||||
-rwxr-xr-x | test/simulation/121-local | 90 | ||||
-rwxr-xr-x | test/simulation/121-orphan | 26 | ||||
-rwxr-xr-x | test/simulation/122-xleave | 1 | ||||
-rwxr-xr-x | test/simulation/124-tai | 16 | ||||
-rwxr-xr-x | test/simulation/126-burst | 2 | ||||
-rwxr-xr-x | test/simulation/127-filter | 2 | ||||
-rwxr-xr-x | test/simulation/135-ratelimit | 11 | ||||
-rwxr-xr-x | test/simulation/142-ntpoverptp | 17 | ||||
-rwxr-xr-x | test/simulation/144-monoroot | 4 | ||||
-rwxr-xr-x | test/simulation/148-replacement | 24 | ||||
-rwxr-xr-x | test/simulation/203-initreload | 26 | ||||
-rwxr-xr-x | test/system/007-cmdmon | 9 | ||||
-rwxr-xr-x | test/system/008-confload | 25 | ||||
-rwxr-xr-x | test/system/010-nts | 5 | ||||
-rw-r--r-- | test/unit/clientlog.c | 60 | ||||
-rw-r--r-- | test/unit/leapdb.c | 106 | ||||
-rw-r--r-- | test/unit/leapdb.list | 22 | ||||
-rw-r--r-- | test/unit/ntp_sources.c | 10 |
26 files changed, 489 insertions, 95 deletions
diff --git a/test/compilation/002-scanbuild b/test/compilation/002-scanbuild index 0395df9..ff7e2aa 100755 --- a/test/compilation/002-scanbuild +++ b/test/compilation/002-scanbuild @@ -3,6 +3,7 @@ cd ../.. for opts in \ + "--enable-debug" \ "--host-system=Linux" \ "--host-system=NetBSD" \ "--host-system=FreeBSD" \ diff --git a/test/simulation/008-ntpera b/test/simulation/008-ntpera index 2eea63b..ab11819 100755 --- a/test/simulation/008-ntpera +++ b/test/simulation/008-ntpera @@ -41,7 +41,6 @@ for time_offset in -1e-1 1e-1; do export CLKNETSIM_START_DATE=$(awk "BEGIN {printf \"%.0f\", $ntp_start + $start_offset}") run_test || test_fail check_chronyd_exit || test_fail - check_source_selection || test_fail check_packet_interval || test_fail check_sync && test_fail done diff --git a/test/simulation/106-refclock b/test/simulation/106-refclock index ba7c482..dedab9b 100755 --- a/test/simulation/106-refclock +++ b/test/simulation/106-refclock @@ -36,7 +36,7 @@ Update interval : 16\.. seconds .*$" || test_fail if echo "$refclock" | grep -q 'PHC.*nocrossts'; then - check_file_messages "20.* GPS.*[0-9] N " 650 750 refclocks.log || test_fail + check_file_messages "20.* GPS.*[0-9] N " 620 750 refclocks.log || test_fail else check_file_messages "20.* GPS.*[0-9] N " 997 1001 refclocks.log || test_fail fi @@ -64,7 +64,7 @@ Stratum.*: 1 Root delay : 0\.000000001 seconds .*$" || test_fail - check_file_messages "20.* PPS1.*[0-9] N " 620 740 refclocks.log || test_fail + check_file_messages "20.* PPS1.*[0-9] N " 610 740 refclocks.log || test_fail check_file_messages "20.* PPS1.*- N " 60 63 refclocks.log || test_fail rm -f tmp/refclocks.log @@ -89,14 +89,15 @@ Root delay : 0\.000000001 seconds check_file_messages "20.* PPS1.*- N " 60 63 refclocks.log || test_fail rm -f tmp/refclocks.log - min_sync_time=100 - max_sync_time=220 + min_sync_time=80 + max_sync_time=180 chronyc_start=220 client_conf=" refclock SHM 0 refid NMEA offset 0.35 delay 0.1 refclock PPS /dev/pps0 logdir tmp -log refclocks" +log refclocks +maxupdateskew 10000" run_test || test_fail check_chronyd_exit || test_fail @@ -108,7 +109,7 @@ Stratum.*: 1 Root delay : 0\.000000001 seconds .*$" || test_fail - check_file_messages "20.* PPS1.*[0-9] N " 800 940 refclocks.log || test_fail + check_file_messages "20.* PPS1.*[0-9] N " 800 960 refclocks.log || test_fail check_file_messages "20.* PPS1.*- N " 50 63 refclocks.log || test_fail rm -f tmp/refclocks.log fi diff --git a/test/simulation/108-peer b/test/simulation/108-peer index 906de17..2c914e1 100755 --- a/test/simulation/108-peer +++ b/test/simulation/108-peer @@ -21,6 +21,7 @@ EOF clients=2 peers=2 +freq_max_limit=1e-3 max_sync_time=1000 client_server_options="minpoll 6 maxpoll 6" client_peer_options="minpoll 6 maxpoll 6" @@ -30,6 +31,7 @@ check_chronyd_exit || test_fail check_source_selection || test_fail check_sync || test_fail +freq_max_limit=$default_freq_max_limit base_delay="(+ 1e-4 (* -1 (equal 0.1 from 3) (equal 0.1 to 1)))" client_peer_options="" diff --git a/test/simulation/110-chronyc b/test/simulation/110-chronyc index 46b0a3f..5b32931 100755 --- a/test/simulation/110-chronyc +++ b/test/simulation/110-chronyc @@ -58,7 +58,7 @@ MS Name/IP address Stratum Poll Reach LastRx Last sample \^\? 192\.168\.123\.2 0 [0-9]+ 0 - \+0ns\[ \+0ns\] \+/- 0ns Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev ============================================================================== -SHM0 [0-9 ]+ [0-9 ]+ [0-9 ]+ [ +-][01]\.... [0-9 ]+\.... [0-9 +-]+[un]s [0-9 ]+[un]s +SHM0 [0-9 ]+ [0-9 ]+ [0-9 ]+ [ +-][012]\.... [0-9 ]+\.... [0-9 +-]+[un]s [0-9 ]+[un]s 192\.168\.123\.1 [0-9 ]+ [0-9 ]+ [0-9 ]+ [ +-][01]\.... [0-9 ]+\.... [0-9 +-]+[un]s [0-9 ]+[un]s 192\.168\.123\.2 0 0 0 \+0\.000 2000\.000 \+0ns 4000ms 210 n_samples = 0 @@ -114,7 +114,7 @@ limit=1 for chronyc_conf in \ "accheck 1.2.3.4" \ "add peer 10.0.0.0 minpoll 2 maxpoll 6" \ - "add server 10.0.0.0 minpoll 6 maxpoll 10 iburst burst key 1 certset 2 maxdelay 1e-3 maxdelayratio 10.0 maxdelaydevratio 10.0 maxdelayquant 0.5 mindelay 1e-4 asymmetry 0.5 offset 1e-5 minsamples 6 maxsamples 6 filter 3 offline auto_offline prefer noselect trust require xleave polltarget 20 port 123 presend 7 minstratum 3 version 4 nts ntsport 4460 copy extfield F323 extfield F324" \ + "add server 10.0.0.0 minpoll 6 maxpoll 10 iburst burst key 1 certset 2 maxdelay 1e-3 maxdelayratio 10.0 maxdelaydevratio 10.0 maxdelayquant 0.5 mindelay 1e-4 asymmetry 0.5 offset 1e-5 minsamples 6 maxsamples 6 filter 3 offline auto_offline prefer noselect trust require xleave polltarget 20 port 123 presend 7 minstratum 3 version 4 nts ntsport 4460 copy extfield F323 extfield F324 ipv6 ipv4" \ "add server node1.net1.clk" \ "allow 1.2.3.4" \ "allow 1.2" \ @@ -145,7 +145,7 @@ for chronyc_conf in \ "dfreq 1.0e-3" \ "doffset -1.0" \ "dump" \ - "local stratum 5 distance 1.0 orphan" \ + "local stratum 5 distance 1.0 activate 0.5 orphan" \ "local off" \ "makestep 10.0 3" \ "makestep" \ @@ -165,6 +165,7 @@ for chronyc_conf in \ "offline" \ "offline 255.255.255.0/1.2.3.0" \ "offline 1.2.3.0/24" \ + "offset 1.2.3.4 1.0" \ "online" \ "online 1.2.3.0/24" \ "onoffline" \ @@ -247,6 +248,10 @@ Total TX : 1 Total RX : 1 Total valid RX : 1 Total good RX : 0 +Total kernel TX : [01] +Total kernel RX : 1 +Total HW TX : 0 +Total HW RX : 0 S Name/IP Address Auth COpts EOpts Last Score Interval Leap ======================================================================= M node1\.net1\.clk N ----- ----- 0 1\.0 \+0ns \+0ns N @@ -347,6 +352,7 @@ maxpoll 192.168.123.1 5 maxupdateskew 192.168.123.1 10.0 minpoll 192.168.123.1 3 minstratum 192.168.123.1 1 +offset 192.168.123.1 -1.0 polltarget 192.168.123.1 10 selectopts 192.168.123.1 +trust +prefer -require selectdata @@ -371,6 +377,7 @@ check_chronyc_output "^200 OK 200 OK 200 OK 200 OK +200 OK S Name/IP Address Auth COpts EOpts Last Score Interval Leap ======================================================================= M node1\.net1\.clk N \-PT\-\- \-PT\-\- 0 1\.0 \+0ns \+0ns \? @@ -433,7 +440,12 @@ server_conf=" server 192.168.123.1 noclientlog" -commands=( +check_config_h 'FEAT_IPV6 1' && commands=( + "add server ::1 ipv4" "^515 Invalid address family$" + ) || commands=() + +commands+=( + "add server 192.168.123.1 ipv6" "^515 Invalid address family$" "add server nosuchnode.net1.clk" "^Invalid host/IP address$" "allow nosuchnode.net1.clk" "^Could not read address$" "allow 192.168.123.0/2 4" "^Could not read address$" diff --git a/test/simulation/113-leapsecond b/test/simulation/113-leapsecond index 394440b..63da734 100755 --- a/test/simulation/113-leapsecond +++ b/test/simulation/113-leapsecond @@ -8,54 +8,86 @@ check_config_h 'FEAT_REFCLOCK 1' || test_skip export CLKNETSIM_START_DATE=$(TZ=UTC date -d 'Dec 30 2008 0:00:00' +'%s') -leap=$[2 * 24 * 3600] limit=$[4 * 24 * 3600] client_start=$[2 * 3600] -server_conf="refclock SHM 0 dpoll 10 poll 10 -leapsectz right/UTC" refclock_jitter=1e-9 -refclock_offset="(* -1.0 (equal 0.1 (max (sum 1.0) $leap) $leap))" -for leapmode in system step slew; do - client_conf="leapsecmode $leapmode" - if [ $leapmode = slew ]; then - max_sync_time=$[$leap + 12] - else - max_sync_time=$[$leap] - fi +for dir in "+1" "-1"; do + leap=$[2 * 24 * 3600 + 1 + $dir] + server_conf="refclock SHM 0 dpoll 10 poll 10 + leapseclist tmp/leap.list" + refclock_offset="(* $dir (equal 0.1 (max (sum 1.0) $leap) $leap))" + + cat > tmp/leap.list <<-EOF + #$ 3676924800 + #@ 3928521600 + 3345062400 33 # 1 Jan 2006 + 3439756800 $[33 - $dir] # 1 Jan 2009 $( + [ "$dir" = "+1" ] && echo -e "\n3471292800 33\n3502828800 34") + 3550089600 35 # 1 Jul 2012 + EOF + + for leapmode in system step slew; do + client_conf="leapsecmode $leapmode" + if [ $leapmode = slew ]; then + max_sync_time=$[2 * 24 * 3600 + 13] + else + max_sync_time=$[2 * 24 * 3600 + 1] + fi + min_sync_time=$[$max_sync_time - 2] + + run_test || test_fail + check_chronyd_exit || test_fail + check_source_selection || test_fail + check_packet_interval || test_fail + check_sync || test_fail + check_file_messages "System clock TAI offset set to" 1 1 log.1 || test_fail + check_file_messages "System clock TAI offset set to 33" 1 1 log.1 || test_fail + done + + client_server_options="trust" + client_conf="refclock SHM 0 dpoll 10 poll 10 delay 1e-3" + min_sync_time=$[$leap - 2] + max_sync_time=$[$leap] run_test || test_fail check_chronyd_exit || test_fail check_source_selection || test_fail check_packet_interval || test_fail check_sync || test_fail -done -client_server_options="trust" -client_conf="refclock SHM 0 dpoll 10 poll 10 delay 1e-3" + client_server_options="" + client_conf="leapsecmode system" + min_sync_time=230000 + max_sync_time=240000 -run_test || test_fail -check_chronyd_exit || test_fail -check_source_selection || test_fail -check_packet_interval || test_fail -check_sync || test_fail + for smoothmode in "" "leaponly"; do + server_conf="refclock SHM 0 dpoll 10 poll 10 + leapseclist tmp/leap.list + leapsecmode slew + smoothtime 400 0.001 $smoothmode" -client_server_options="" -client_conf="leapsecmode system" -min_sync_time=230000 -max_sync_time=240000 + run_test || test_fail + check_chronyd_exit || test_fail + check_source_selection || test_fail + check_packet_interval || test_fail + check_sync || test_fail + done +done -for smoothmode in "" "leaponly"; do +if TZ=right/UTC date -d 'Dec 31 2008 23:59:60' 2> /dev/null | grep :60; then server_conf="refclock SHM 0 dpoll 10 poll 10 - leapsectz right/UTC - leapsecmode slew - smoothtime 400 0.001 $smoothmode" + leapsectz right/UTC" + refclock_offset="(* -1 (equal 0.1 (max (sum 1.0) $leap) $leap))" + client_conf="leapsecmode system" + min_sync_time=$[$leap - 2] + max_sync_time=$[$leap] run_test || test_fail check_chronyd_exit || test_fail check_source_selection || test_fail check_packet_interval || test_fail check_sync || test_fail -done +fi test_pass diff --git a/test/simulation/118-maxdelay b/test/simulation/118-maxdelay index 117b170..8ab0a62 100755 --- a/test/simulation/118-maxdelay +++ b/test/simulation/118-maxdelay @@ -14,7 +14,6 @@ client_server_options="maxpoll 6 maxdelay 3e-5 maxdelayratio 2.0 maxdelaydevrati run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail check_packet_interval || test_fail check_sync || test_fail diff --git a/test/simulation/119-smoothtime b/test/simulation/119-smoothtime index 7f5114c..fc2c6be 100755 --- a/test/simulation/119-smoothtime +++ b/test/simulation/119-smoothtime @@ -14,7 +14,7 @@ max_sync_time=800 run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail +check_source_selection && test_fail check_sync || test_fail limit=10000 diff --git a/test/simulation/121-local b/test/simulation/121-local new file mode 100755 index 0000000..ba99efc --- /dev/null +++ b/test/simulation/121-local @@ -0,0 +1,90 @@ +#!/usr/bin/env bash + +. ./test.common + +test_start "local options" + +check_config_h 'FEAT_CMDMON 1' || test_skip + +server_strata=3 +server_conf="local stratum 5 orphan +server 192.168.123.1 +server 192.168.123.2 +server 192.168.123.3" +max_sync_time=900 +client_start=140 +chronyc_start=700 +chronyc_conf="tracking" +time_rms_limit=5e-4 + +run_test || test_fail +check_chronyd_exit || test_fail +check_source_selection || test_fail +check_sync || test_fail +check_chronyc_output "^.*Stratum *: 7.*$" || test_fail + +limit=4000 +wander=0.0 +jitter=0.0 +server_strata=1 +server_conf="" +client_server_options="minpoll 6 maxpoll 6 minsamples 64" +chronyc_start=1 +chronyc_conf="timeout 1000000 +tracking +tracking +tracking +tracking" +base_delay=$(cat <<-EOF | tr -d '\n' + (+ 1e-4 + (* 990 + (equal 0.1 from 3)) + (* -1 + (equal 0.1 from 1) + (equal 0.1 (max (% time 2000) 1000) 1000))) +EOF +) + +client_conf="local +maxclockerror 1000" + +run_test || test_fail +check_chronyd_exit || test_fail +check_chronyc_output "^.*7F7F0101.*C0A87B01.*7F7F0101.*C0A87B01.*$" || test_fail + +client_conf="local distance 0.5 +maxclockerror 1000" + +run_test || test_fail +check_chronyd_exit || test_fail +check_chronyc_output "^.*7F7F0101.*C0A87B01.*7F7F0101.*C0A87B01.*$" || test_fail + +client_conf="local distance 2.0 +maxclockerror 1000" + +run_test || test_fail +check_chronyd_exit || test_fail +check_chronyc_output "^.*7F7F0101.*C0A87B01.*C0A87B01.*C0A87B01.*$" || test_fail + +client_conf="local activate 1e-4 +maxclockerror 1000" + +run_test || test_fail +check_chronyd_exit || test_fail +check_chronyc_output "^.* 00000000 .*C0A87B01.*C0A87B01.*C0A87B01.*$" || test_fail + +client_conf="local activate 1e-1 +maxclockerror 1000" + +run_test || test_fail +check_chronyd_exit || test_fail +check_chronyc_output "^.* 00000000 .*C0A87B01.*7F7F0101.*C0A87B01.*$" || test_fail + +client_conf="local activate 1e-1 distance 2.0 +maxclockerror 1000" + +run_test || test_fail +check_chronyd_exit || test_fail +check_chronyc_output "^.* 00000000 .*C0A87B01.*C0A87B01.*C0A87B01.*$" || test_fail + +test_pass diff --git a/test/simulation/121-orphan b/test/simulation/121-orphan deleted file mode 100755 index 7579997..0000000 --- a/test/simulation/121-orphan +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -. ./test.common - -test_start "orphan option" - -check_config_h 'FEAT_CMDMON 1' || test_skip - -server_strata=3 -server_conf="local stratum 5 orphan -server 192.168.123.1 -server 192.168.123.2 -server 192.168.123.3" -max_sync_time=900 -client_start=140 -chronyc_start=700 -chronyc_conf="tracking" -time_rms_limit=5e-4 - -run_test || test_fail -check_chronyd_exit || test_fail -check_source_selection || test_fail -check_sync || test_fail -check_chronyc_output "^.*Stratum *: 7.*$" || test_fail - -test_pass diff --git a/test/simulation/122-xleave b/test/simulation/122-xleave index c19063a..77059d8 100755 --- a/test/simulation/122-xleave +++ b/test/simulation/122-xleave @@ -53,7 +53,6 @@ for rpoll in 4 5 6; do run_test || test_fail check_chronyd_exit || test_fail - check_source_selection || test_fail check_sync || test_fail if [ $rpoll -le 5 ]; then diff --git a/test/simulation/124-tai b/test/simulation/124-tai index 97064f7..e8c909d 100755 --- a/test/simulation/124-tai +++ b/test/simulation/124-tai @@ -18,9 +18,17 @@ servers=0 refclock_offset="(+ -34 (equal 0.1 (max (sum 1.0) $leap) $leap))" client_conf=" refclock SHM 0 dpoll 0 poll 0 tai -leapsectz right/UTC +leapseclist tmp/leap.list leapsecmode ignore -maxchange 1e-3 1 0" +maxchange 1e-3 10 0" + +cat > tmp/leap.list <<-EOF + #$ 3676924800 + #@ 3928521600 + 3345062400 33 # 1 Jan 2006 + 3439756800 34 # 1 Jan 2009 + 3550089600 35 # 1 Jul 2012 +EOF run_test || test_fail check_chronyd_exit || test_fail @@ -33,9 +41,9 @@ time_offset=-1000 refclock_offset="(+ -34)" client_conf=" refclock SHM 0 dpoll 0 poll 0 tai -leapsectz right/UTC +leapseclist tmp/leap.list makestep 1 1 -maxchange 1e-3 1 0" +maxchange 1e-3 10 0" run_test || test_fail check_chronyd_exit || test_fail diff --git a/test/simulation/126-burst b/test/simulation/126-burst index 1cb6f9c..baae3d5 100755 --- a/test/simulation/126-burst +++ b/test/simulation/126-burst @@ -22,7 +22,7 @@ client_min_mean_out_interval=150.0 run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail +check_source_selection && test_fail check_packet_interval || test_fail check_sync || test_fail diff --git a/test/simulation/127-filter b/test/simulation/127-filter index 739dd91..68afec2 100755 --- a/test/simulation/127-filter +++ b/test/simulation/127-filter @@ -12,7 +12,7 @@ client_min_mean_out_interval=15.9 run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail +check_source_selection && test_fail check_packet_interval || test_fail check_sync || test_fail diff --git a/test/simulation/135-ratelimit b/test/simulation/135-ratelimit index 86c435d..0756f19 100755 --- a/test/simulation/135-ratelimit +++ b/test/simulation/135-ratelimit @@ -15,4 +15,15 @@ check_sync || test_fail check_file_messages " 2 1 " 1200 1300 log.packets || test_fail check_file_messages " 1 2 " 180 220 log.packets || test_fail +server_conf="ratelimit interval 6 burst 2 leak 4 kod 2" + +run_test || test_fail +check_chronyd_exit || test_fail +check_packet_interval || test_fail +check_sync || test_fail + +check_file_messages " 2 1 " 700 850 log.packets || test_fail +check_file_messages " 1 2 " 350 450 log.packets || test_fail +check_log_messages "Received KoD RATE.*\.123.1" 100 140 || test_fail + test_pass diff --git a/test/simulation/142-ntpoverptp b/test/simulation/142-ntpoverptp index 2996dc0..74cb8f7 100755 --- a/test/simulation/142-ntpoverptp +++ b/test/simulation/142-ntpoverptp @@ -16,6 +16,7 @@ peers=2 max_sync_time=420 server_conf=" +ptpdomain 123 ptpport 319" client_conf=" ptpport 319 @@ -103,4 +104,20 @@ if check_config_h 'FEAT_DEBUG 1'; then check_log_messages "apply_net_correction.*Applied" 0 0 || test_fail fi +freq_offset=-1e-4 +delay_correction="" +server_conf="ptpport 319" +client_conf="ptpport 319 +ptpdomain 124 +authselectmode ignore +keyfile tmp/peer.keys" +time_max_limit=$default_time_max_limit +time_rms_limit=$default_time_rms_limit +freq_max_limit=$default_freq_max_limit +freq_rms_limit=$default_freq_rms_limit + +run_test || test_fail +check_chronyd_exit || test_fail +check_sync && test_fail + test_pass diff --git a/test/simulation/144-monoroot b/test/simulation/144-monoroot index 20fae12..d97f30d 100755 --- a/test/simulation/144-monoroot +++ b/test/simulation/144-monoroot @@ -20,7 +20,7 @@ for options in "extfield F323" "xleave extfield F323"; do run_test || test_fail check_chronyd_exit || test_fail - check_source_selection || test_fail + check_source_selection && test_fail check_sync || test_fail done @@ -47,7 +47,7 @@ for lpoll in 5 6 7; do run_test || test_fail check_chronyd_exit || test_fail - check_source_selection || test_fail + check_source_selection && test_fail check_sync || test_fail done done diff --git a/test/simulation/148-replacement b/test/simulation/148-replacement index f15fc4d..d09fba6 100755 --- a/test/simulation/148-replacement +++ b/test/simulation/148-replacement @@ -53,4 +53,28 @@ check_log_messages "2010-01-01T0[5-9]:.*Source 192.168.123.. replaced with" 0 15 check_file_messages "20.*192.168.123.* 11.1 6 6 " 20 500 measurements.log || test_fail rm -f tmp/measurements.log +# 2 replaceable falsetickers and 1 replaceable unreachable server +servers=6 +falsetickers=2 +base_delay="(+ 1e-4 (* -1 (equal 0.1 to 3)))" +client_server_conf=" +server nodes-4-1.net1.clk +server nodes-5-2.net1.clk +server nodes-6-3.net1.clk" + +run_test || test_fail +check_chronyd_exit || test_fail +check_source_selection && test_fail +check_packet_interval || test_fail +check_sync || test_fail + +check_log_messages "Can't synchronise: no majority" 1 1 || test_fail +check_log_messages "Detected falseticker" 0 2 || test_fail +check_log_messages "Source 192.168.123.. replaced with" 3 60 || test_fail +check_log_messages "Source 192.168.123.1 replaced with" 1 25 || test_fail +check_log_messages "Source 192.168.123.2 replaced with" 1 25 || test_fail +check_log_messages "Source 192.168.123.3 replaced with" 1 25 || test_fail +check_file_messages "20.*192.168.123.* 11.1 6 6 " 50 800 measurements.log || test_fail +rm -f tmp/measurements.log + test_pass diff --git a/test/simulation/203-initreload b/test/simulation/203-initreload new file mode 100755 index 0000000..cf7924b --- /dev/null +++ b/test/simulation/203-initreload @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +. ./test.common + +check_config_h 'FEAT_CMDMON 1' || test_skip + +# Test fix "conf: don't load sourcedir during initstepslew and RTC init" + +test_start "reload during initstepslew" + +client_conf="initstepslew 5 192.168.123.1 +sourcedir tmp" +client_server_conf="#" +chronyc_conf="reload sources" +chronyc_start=4 + +echo 'server 192.168.123.1' > tmp/sources.sources + +run_test || test_fail +check_chronyd_exit || test_fail +check_source_selection || test_fail +check_sync || test_fail + +check_log_messages "Added source 192\.168\.123\.1" 1 1 || test_fail + +test_pass diff --git a/test/system/007-cmdmon b/test/system/007-cmdmon index f9541d3..954a15b 100755 --- a/test/system/007-cmdmon +++ b/test/system/007-cmdmon @@ -28,6 +28,7 @@ for command in \ "local" \ "online" \ "onoffline" \ + "offset $server 0.0" \ "maxdelay $server 1e-1" \ "maxdelaydevratio $server 5.0" \ "maxdelayratio $server 3.0" \ @@ -97,12 +98,16 @@ RX timestamping : (Daemon|Kernel) Total TX : [0-9]+ Total RX : [0-9]+ Total valid RX : [0-9]+ -Total good RX : [0-9]+$" || test_fail +Total good RX : [0-9]+ +Total kernel TX : [0-9]+ +Total kernel RX : [0-9]+ +Total HW TX : 0 +Total HW RX : 0$" || test_fail run_chronyc "selectdata" || test_fail check_chronyc_output "^S Name/IP Address Auth COpts EOpts Last Score Interval Leap ======================================================================= -s 127\.0\.0\.1 N -PTR- -PTR- 0 1\.0 \+0ns \+0ns \?$" || test_fail +M 127\.0\.0\.1 N -PTR- -PTR- 0 1\.0 \+0ns \+0ns \?$" || test_fail run_chronyc "serverstats" || test_fail check_chronyc_output "^NTP packets received : [0-9]+ diff --git a/test/system/008-confload b/test/system/008-confload index 7e80698..b107d70 100755 --- a/test/system/008-confload +++ b/test/system/008-confload @@ -77,7 +77,32 @@ check_chronyc_output "^[^=]* .. 127\.123\.5\.3 *[05] 7 [^^]* .. 127\.123\.5\.6 [^^]*$" || test_fail +run_chronyc "reload sources" || test_fail +run_chronyc "reload sources" || test_fail + +rm $TEST_DIR/conf5.d/{3,5,6}.sources +echo "server 127.123.5.7" > $TEST_DIR/conf5.d/7.sources + +run_chronyc "reload sources" || test_fail + +run_chronyc "sources" || test_fail +check_chronyc_output "^[^=]* +=* +.. 127\.123\.1\.1 [^^]* +.. 127\.123\.1\.3 [^^]* +.. 127\.123\.1\.4 [^^]* +.. 127\.123\.3\.1 [^^]* +.. 127\.123\.2\.2 [^^]* +.. 127\.123\.2\.3 [^^]* +.. 127\.123\.4\.4 [^^]* +.. 127\.123\.1\.2 *[05] 6 [^^]* +.. 127\.123\.5\.2 *[05] 5 [^^]* +.. 127\.123\.5\.7 [^^]*$" || test_fail + +run_chronyc "reload sources" || test_fail + stop_chronyd || test_fail +check_chronyd_message_count "Could not add source.*\.5\.5.*in use" 1 1 || test_fail check_chronyd_message_count "Could not add source" 1 1 || test_fail test_pass diff --git a/test/system/010-nts b/test/system/010-nts index 8d92bbc..b215efa 100755 --- a/test/system/010-nts +++ b/test/system/010-nts @@ -45,6 +45,11 @@ check_chronyc_output "^Name/IP address Mode KeyID Type KLen Last Atm ========================================================================= 127\.0\.0\.1 NTS 1 (30|15) (128|256) [0-9] 0 0 [78] ( 64|100)$" || test_fail +run_chronyc "serverstats" || test_fail +check_chronyc_output "NTS-KE connections accepted: 1 +NTS-KE connections dropped : 0 +Authenticated NTP packets : [1-9][0-9]*" || test_fail + stop_chronyd || test_fail check_chronyd_messages || test_fail check_chronyd_files || test_fail diff --git a/test/unit/clientlog.c b/test/unit/clientlog.c index e5bf1f4..96818b2 100644 --- a/test/unit/clientlog.c +++ b/test/unit/clientlog.c @@ -1,6 +1,6 @@ /* ********************************************************************** - * Copyright (C) Miroslav Lichvar 2016, 2021 + * Copyright (C) Miroslav Lichvar 2016, 2021, 2024 * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as @@ -35,18 +35,18 @@ void test_unit(void) { uint64_t ts64, prev_first_ts64, prev_last_ts64, max_step; + int i, j, k, kod, passes, kods, drops, index, shift; uint32_t index2, prev_first, prev_size; NTP_Timestamp_Source ts_src, ts_src2; struct timespec ts, ts2; - int i, j, k, index, shift; CLG_Service s; NTP_int64 ntp_ts; IPAddr ip; char conf[][100] = { "clientloglimit 20000", "ratelimit interval 3 burst 4 leak 3", - "cmdratelimit interval 3 burst 4 leak 3", - "ntsratelimit interval 6 burst 8 leak 3", + "ntsratelimit interval 4 burst 8 leak 3", + "cmdratelimit interval 6 burst 4 leak 3", }; CNF_Initialise(0, 0); @@ -80,19 +80,51 @@ test_unit(void) DEBUG_LOG("records %u", ARR_GetSize(records)); TEST_CHECK(ARR_GetSize(records) == 128); - s = CLG_NTP; + for (kod = 0; kod <= 2; kod += 2) { + for (s = CLG_NTP; s <= CLG_CMDMON; s++) { + for (i = passes = kods = drops = 0; i < 10000; i++) { + kod_rate[s] = kod; + ts.tv_sec += 1; + index = CLG_LogServiceAccess(s, &ip, &ts); + TEST_CHECK(index >= 0); + switch (CLG_LimitServiceRate(s, index)) { + case CLG_PASS: + passes += 1; + break; + case CLG_DROP: + drops += 1; + break; + case CLG_KOD: + kods += 1; + break; + default: + assert(0); + } + } - for (i = j = 0; i < 10000; i++) { - ts.tv_sec += 1; - index = CLG_LogServiceAccess(s, &ip, &ts); - TEST_CHECK(index >= 0); - if (!CLG_LimitServiceRate(s, index)) - j++; + DEBUG_LOG("service %d requests %d passes %d kods %d drops %d", + (int)s, i, passes, kods, drops); + if (kod) + TEST_CHECK(kods * 2.5 < drops && kods * 3.5 > drops); + else + TEST_CHECK(kods == 0); + + switch (s) { + case CLG_NTP: + TEST_CHECK(passes > 1750 && passes < 2050); + break; + case CLG_NTSKE: + TEST_CHECK(passes > 1300 && passes < 1600); + break; + case CLG_CMDMON: + TEST_CHECK(passes > 1100 && passes < 1400); + break; + default: + assert(0); + } + } } - DEBUG_LOG("requests %d responses %d", i, j); - TEST_CHECK(j * 4 < i && j * 6 > i); - TEST_CHECK(!ntp_ts_map.timestamps); UTI_ZeroNtp64(&ntp_ts); diff --git a/test/unit/leapdb.c b/test/unit/leapdb.c new file mode 100644 index 0000000..cb27387 --- /dev/null +++ b/test/unit/leapdb.c @@ -0,0 +1,106 @@ +/* + ********************************************************************** + * Copyright (C) Patrick Oppenlander 2024 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + ********************************************************************** + */ + +#include <leapdb.c> +#include "test.h" + +struct test_vector { + time_t when; + int tai_offset; + NTP_Leap leap; + int fake; +} tests[] = { + /* leapdb.list is a cut down version of leap-seconds.list */ + {3439756800, 34, LEAP_InsertSecond, 0}, /* 1 Jan 2009 */ + {3550089600, 35, LEAP_InsertSecond, 0}, /* 1 Jul 2012 */ + {3644697600, 36, LEAP_InsertSecond, 0}, /* 1 Jul 2015 */ + {3692217600, 37, LEAP_InsertSecond, 0}, /* 1 Jan 2017 */ + {3786825600, 36, LEAP_DeleteSecond, 1}, /* 1 Jan 2020 fake in leapdb.list */ +}; + +static void +test_leap_source(NTP_Leap (*fn)(time_t when, int *tai_offset), + int skip_fakes) +{ + int i, prev_tai_offset = 34; + + for (i = 0; i < sizeof tests / sizeof tests[0]; ++i) { + struct test_vector *t = tests + i; + + NTP_Leap leap; + int tai_offset = -1; + + /* Our unit test leapdb.list contains a fake entry removing a leap second. + * Skip this when testing with the right/UTC timezone using mktime(). */ + if (skip_fakes && t->fake) + continue; + + /* One second before leap second */ + leap = fn(t->when - LEAP_SEC_LIST_OFFSET - 1, &tai_offset); + TEST_CHECK(leap == t->leap); + TEST_CHECK(tai_offset = prev_tai_offset); + + /* Exactly on leap second */ + leap = fn(t->when - LEAP_SEC_LIST_OFFSET, &tai_offset); + TEST_CHECK(leap == LEAP_Normal); + TEST_CHECK(tai_offset == t->tai_offset); + + /* One second after leap second */ + leap = fn(t->when - LEAP_SEC_LIST_OFFSET + 1, &tai_offset); + TEST_CHECK(leap == LEAP_Normal); + TEST_CHECK(tai_offset == t->tai_offset); + + prev_tai_offset = t->tai_offset; + } +} + +void +test_unit(void) +{ + char conf[][100] = { + "leapsectz right/UTC", + "leapseclist leapdb.list" + }; + int i; + + CNF_Initialise(0, 0); + for (i = 0; i < sizeof conf / sizeof conf[0]; i++) + CNF_ParseLine(NULL, i + 1, conf[i]); + LDB_Initialise(); + + if (check_leap_source(get_tz_leap)) { + DEBUG_LOG("testing get_tz_leap"); + test_leap_source(get_tz_leap, 1); + } else { + DEBUG_LOG("Skipping get_tz_leap test. Either the right/UTC timezone is " + "missing, or mktime() doesn't support leap seconds."); + } + + DEBUG_LOG("testing get_list_leap"); + TEST_CHECK(check_leap_source(get_list_leap)); + test_leap_source(get_list_leap, 0); + + /* This exercises the twice-per-day logic */ + DEBUG_LOG("testing LDB_GetLeap"); + test_leap_source(LDB_GetLeap, 1); + + LDB_Finalise(); + CNF_Finalise(); +} diff --git a/test/unit/leapdb.list b/test/unit/leapdb.list new file mode 100644 index 0000000..5dc2188 --- /dev/null +++ b/test/unit/leapdb.list @@ -0,0 +1,22 @@ +# +# Cut down version of leap-seconds.list for unit test. +# +# Blank lines need to be ignored, so include a few for testing. +# Whitespace errors on non-blank lines below are copied from the original file. +# + +# Leap second data update time +#$ 3676924800 +# +# File update time +#@ 3928521600 + +3439756800 34 # 1 Jan 2009 +3550089600 35 # 1 Jul 2012 +3644697600 36 # 1 Jul 2015 +3692217600 37 # 1 Jan 2017 +3786825600 36 # 1 Jan 2020 (fake entry to test negative leap second) + +# FIPS 180-1 hash +# NOTE! this value has not been recomputed for this unit test file. +#h 16edd0f0 3666784f 37db6bdd e74ced87 59af48f1 diff --git a/test/unit/ntp_sources.c b/test/unit/ntp_sources.c index e3d7c4d..a9bdbad 100644 --- a/test/unit/ntp_sources.c +++ b/test/unit/ntp_sources.c @@ -125,7 +125,7 @@ void test_unit(void) { char source_line[] = "127.0.0.1 offline", conf[] = "port 0", name[64]; - int i, j, k, slot, found, pool, prev_n; + int i, j, k, family, slot, found, pool, prev_n; uint32_t hash = 0, conf_id; NTP_Remote_Address addrs[256], addr; NTP_Local_Address local_addr; @@ -216,7 +216,7 @@ test_unit(void) TEST_CHECK(n_sources == 0); - status = NSR_AddSourceByName("a b", 0, 0, 0, &source.params, &conf_id); + status = NSR_AddSourceByName("a b", IPADDR_UNSPEC, 0, 0, 0, &source.params, &conf_id); TEST_CHECK(status == NSR_InvalidName); local_addr.ip_addr.family = IPADDR_INET4; @@ -228,11 +228,13 @@ test_unit(void) for (i = 0; i < 500; i++) { for (j = 0; j < 20; j++) { snprintf(name, sizeof (name), "ntp%d.example.net", (int)(random() % 10)); + family = random() % 2 ? IPADDR_UNSPEC : random() % 2 ? IPADDR_INET4 : IPADDR_INET6; pool = random() % 2; prev_n = n_sources; DEBUG_LOG("%d/%d adding source %s pool=%d", i, j, name, pool); - status = NSR_AddSourceByName(name, 0, pool, random() % 2 ? NTP_SERVER : NTP_PEER, + status = NSR_AddSourceByName(name, family, 0, pool, + random() % 2 ? NTP_SERVER : NTP_PEER, &source.params, &conf_id); TEST_CHECK(status == NSR_UnresolvedName); @@ -242,11 +244,13 @@ test_unit(void) for (us = unresolved_sources; us->next; us = us->next) ; TEST_CHECK(strcmp(us->name, name) == 0); + TEST_CHECK(us->family == family); if (pool) { TEST_CHECK(us->address.ip_addr.family == IPADDR_UNSPEC && us->pool_id >= 0); } else { TEST_CHECK(strcmp(NSR_GetName(&us->address.ip_addr), name) == 0); TEST_CHECK(find_slot2(&us->address, &slot) == 2); + TEST_CHECK(get_record(slot)->family == family); } if (random() % 2) { |