| 743 | theta, |
| 744 | clock_error_bound, |
| 745 | } = Ntp::calculate_theta(&local, local_period, uncorrected_clock); |
| 746 | |
| 747 | assert_eq!(theta, Duration::from_secs(0)); |
| 748 | assert_eq!( |
| 749 | clock_error_bound, |
| 750 | event1.calculate_clock_error_bound(local_period) |
| 751 | ); |
| 752 | } |
| 753 | |
| 754 | #[test] |
| 755 | fn theta() { |
| 756 | // Less naive test case, estimate and local periods are 10 PPM off |
| 757 | // estimate clock rates 1GHz |
| 758 | // epoch is 1 day after 1970 new years |
| 759 | |
| 760 | let uncorrected_clock = UncorrectedClock { |
| 761 | k: Instant::from_days(1), |
| 762 | p_estimate: Period::from_seconds(1e-9), |
| 763 | }; |
| 764 | let local_period = Period::from_seconds(uncorrected_clock.p_estimate.get() * 1.000_010); |
| 765 | |
| 766 | let mut local = Local::new(NonZeroUsize::new(2).unwrap()); |
| 767 | let event1 = event::Ntp::builder() |
| 768 | .counter_pre(TscCount::new(1_000_000_000)) |
| 769 | .counter_post(TscCount::new(1_000_001_000)) |
| 770 | .ntp_data(event::NtpData { |
| 771 | server_recv_time: Instant::from_days(1) |
| 772 | + Duration::from_secs(1) |
| 773 | + Duration::from_nanos(100), |
| 774 | server_send_time: Instant::from_days(1) |
| 775 | + Duration::from_secs(1) |
| 776 | + Duration::from_nanos(900), |
| 777 | root_delay: Duration::from_micros(15), |
| 778 | root_dispersion: Duration::from_micros(27), |
| 779 | stratum: Stratum::TWO, |
| 780 | }) |
| 781 | .build() |
| 782 | .unwrap(); |
| 783 | |
| 784 | let event2 = event::Ntp::builder() |
| 785 | .counter_pre(TscCount::new(2_000_000_000)) |
| 786 | .counter_post(TscCount::new(2_000_001_000)) |
| 787 | .ntp_data(event::NtpData { |
| 788 | server_recv_time: Instant::from_days(1) |
| 789 | + Duration::from_secs(2) |
| 790 | + Duration::from_nanos(100), |
| 791 | server_send_time: Instant::from_days(1) |
| 792 | + Duration::from_secs(2) |
| 793 | + Duration::from_nanos(900), |
| 794 | root_delay: Duration::from_micros(15), |
| 795 | root_dispersion: Duration::from_micros(17), |
| 796 | stratum: Stratum::TWO, |
| 797 | }) |
| 798 | .build() |
| 799 | .unwrap(); |
| 800 | |
| 801 | local.feed(event1.clone()).unwrap(); |
| 802 | local.feed(event2.clone()).unwrap(); |