| 692 | |
| 693 | #[test] |
| 694 | fn theta() { |
| 695 | // Less naive test case, estimate and local periods are 10 PPM off |
| 696 | // estimate clock rates 1GHz |
| 697 | // epoch is 1 day after 1970 new years |
| 698 | |
| 699 | let uncorrected_clock = UncorrectedClock { |
| 700 | k: Instant::from_days(1), |
| 701 | p_estimate: Period::from_seconds(1e-9), |
| 702 | }; |
| 703 | let local_period = Period::from_seconds(uncorrected_clock.p_estimate.get() * 1.000_010); |
| 704 | |
| 705 | let mut local = Local::new(NonZeroUsize::new(2).unwrap()); |
| 706 | let event1 = event::Phc::builder() |
| 707 | .tsc_pre(TscCount::new(1_000_000_000)) |
| 708 | .tsc_post(TscCount::new(1_000_001_000)) |
| 709 | .data(event::PhcData { |
| 710 | time: Instant::from_days(1) + Duration::from_secs(1) + Duration::from_nanos(500), |
| 711 | clock_error_bound: Duration::from_micros(42), |
| 712 | }) |
| 713 | .build() |
| 714 | .unwrap(); |
| 715 | |
| 716 | let event2 = event::Phc::builder() |
| 717 | .tsc_pre(TscCount::new(2_000_000_000)) |
| 718 | .tsc_post(TscCount::new(2_000_001_000)) |
| 719 | .data(event::PhcData { |
| 720 | time: Instant::from_days(1) + Duration::from_secs(2) + Duration::from_nanos(500), |
| 721 | clock_error_bound: Duration::from_micros(32), |
| 722 | }) |
| 723 | .build() |
| 724 | .unwrap(); |
| 725 | |
| 726 | local.feed(event1.clone()).unwrap(); |
| 727 | local.feed(event2.clone()).unwrap(); |
| 728 | |
| 729 | let CalculateThetaOutput { |
| 730 | theta, |
| 731 | clock_error_bound, |
| 732 | } = Phc::calculate_theta(&local, local_period, uncorrected_clock); |
| 733 | |
| 734 | assert_eq!(theta, Duration::from_micros(-5)); |
| 735 | assert_eq!( |
| 736 | clock_error_bound, |
| 737 | event1.calculate_clock_error_bound(local_period) |
| 738 | ); |
| 739 | } |
| 740 | |
| 741 | #[test] |
| 742 | fn feed_two_events() { |