src/media/audio/drivers/test/admin_test.cc
// Wait for the specified number of position notifications.
Wait for the specified number of position notifications.
Wait for the specified number of position notifications .
void AdminTest::ExpectPositionNotifyCount(uint32_t count) {
  if (device_access_denied()) {
    return;
  }
  RunLoopUntil(
      [this, count]() { return position_notification_count_ >= count || device_access_denied(); });
  ClearPositionNotification();
  auto timestamp_duration = position_info_.timestamp - start_time_;
  auto observed_duration = zx::clock::get_monotonic().get() - start_time_;
  ASSERT_GT(position_notification_count_, 0u) << "No position notifications received";
  ASSERT_GE(position_notification_count_, count) << "Too few position notifications received";
  ASSERT_NE(pcm_format_.frame_rate * notifications_per_ring_, 0u);
  auto ns_per_notification =
      (zx::sec(1) * ring_buffer_frames_) / (pcm_format_.frame_rate * notifications_per_ring_);
  double average_num_notif_periods_elapsed = position_notification_count_ - 0.5;
  auto min_allowed_time = ns_per_notification.get() * (average_num_notif_periods_elapsed - 0.75);
  auto expected_time = ns_per_notification.get() * average_num_notif_periods_elapsed;
  auto max_allowed_time = ns_per_notification.get() * (average_num_notif_periods_elapsed + 0.75);
  FX_LOGS(DEBUG) << "Timestamp delta from min/ideal/max: " << std::setw(10)
                 << (min_allowed_time - timestamp_duration) << " : " << std::setw(10)
                 << (expected_time - timestamp_duration) << " : " << std::setw(10)
                 << (max_allowed_time - timestamp_duration);
  EXPECT_GE(timestamp_duration, min_allowed_time)
      << "Notification rate too high. Device clock rate too fast?";
  EXPECT_LE(timestamp_duration, max_allowed_time)
      << "Notification rate too low. Device clock rate too slow?";
  FX_LOGS(DEBUG) << "Expected " << average_num_notif_periods_elapsed << " intervals, was "
                 << static_cast<double>(timestamp_duration) / ns_per_notification.get();
  FX_LOGS(DEBUG) << "Observed delta from min/ideal/max : " << std::setw(10)
                 << (min_allowed_time - observed_duration) << " : " << std::setw(10)
                 << (expected_time - observed_duration) << " : " << std::setw(10)
                 << (max_allowed_time - observed_duration);
  EXPECT_GT(observed_duration, min_allowed_time);
  uint64_t expected_bytes = (timestamp_duration * pcm_format_.frame_rate * frame_size_) / ZX_SEC(1);
  FX_LOGS(DEBUG) << "Running byte position: expected " << expected_bytes << ", actual "
                 << running_position_ << ", "
                 << static_cast<double>(expected_bytes) / running_position_;
}
void AdminTest :: ExpectPositionNotifyCount ( uint32_t count ) { if ( device_access_denied ( ) ) { return ; } RunLoopUntil ( [ this , count ] ( ) { return position_notification_count_ >= count || device_access_denied ( ) ; } ) ; ClearPositionNotification ( ) ; auto timestamp_duration = position_info_ . timestamp - start_time_ ; auto observed_duration = zx :: clock :: get_monotonic ( ) . get ( ) - start_time_ ; ASSERT_GT ( position_notification_count_ , 0u ) << " " ; ASSERT_GE ( position_notification_count_ , count ) << " " ; ASSERT_NE ( pcm_format_ . frame_rate * notifications_per_ring_ , 0u ) ; auto ns_per_notification = ( zx :: sec ( 1 ) * ring_buffer_frames_ ) / ( pcm_format_ . frame_rate * notifications_per_ring_ ) ; double average_num_notif_periods_elapsed = position_notification_count_ - 0.5 ; auto min_allowed_time = ns_per_notification . get ( ) * ( average_num_notif_periods_elapsed - 0.75 ) ; auto expected_time = ns_per_notification . get ( ) * average_num_notif_periods_elapsed ; auto max_allowed_time = ns_per_notification . get ( ) * ( average_num_notif_periods_elapsed + 0.75 ) ; FX_LOGS ( DEBUG ) << " " << std :: setw ( 10 ) << ( min_allowed_time - timestamp_duration ) << " " << std :: setw ( 10 ) << ( expected_time - timestamp_duration ) << " " << std :: setw ( 10 ) << ( max_allowed_time - timestamp_duration ) ; EXPECT_GE ( timestamp_duration , min_allowed_time ) << " " ; EXPECT_LE ( timestamp_duration , max_allowed_time ) << " " ; FX_LOGS ( DEBUG ) << " " << average_num_notif_periods_elapsed << " " << static_cast < double > ( timestamp_duration ) / ns_per_notification . get ( ) ; FX_LOGS ( DEBUG ) << " " << std :: setw ( 10 ) << ( min_allowed_time - observed_duration ) << " " << std :: setw ( 10 ) << ( expected_time - observed_duration ) << " " << std :: setw ( 10 ) << ( max_allowed_time - observed_duration ) ; EXPECT_GT ( observed_duration , min_allowed_time ) ; uint64_t expected_bytes = ( timestamp_duration * pcm_format_ . frame_rate * frame_size_ ) / ZX_SEC ( 1 ) ; FX_LOGS ( DEBUG ) << " " << expected_bytes << " " << running_position_ << " " << static_cast < double > ( expected_bytes ) / running_position_ ; }
Wait for the specified number of position notifications.
Wait for the specified number of position notifications .
// What timestamp do we expect, for the final notification received? We know how many // notifications we've received; we'll multiply this by the per-notification time duration. // However, upon enabling notifications, our first notification might arrive immediately. Thus, // the average number of notification periods elapsed is (position_notification_count_ - 0.5). // Furthermore, notification timing requirements for drivers are somewhat loose, so we include a // tolerance range of +/- 0.75 notification periods. // Also validate when the notification was actually received (not just the timestamp).