Remove ExternalTimeController

It is not used so we don't need it.

Bug: webrtc:384483059
Change-Id: I99a4c3dca0881c56d5cd6eb41430505f2c9ccb03
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/371700
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43578}
This commit is contained in:
Evan Shrubsole 2024-12-16 15:44:45 +00:00 committed by WebRTC LUCI CQ
parent eb1d53fcda
commit c36f8dcd98
9 changed files with 0 additions and 498 deletions

View File

@ -1560,7 +1560,6 @@ if (rtc_include_tests) {
"rtp_parameters_unittest.cc", "rtp_parameters_unittest.cc",
"scoped_refptr_unittest.cc", "scoped_refptr_unittest.cc",
"sequence_checker_unittest.cc", "sequence_checker_unittest.cc",
"test/create_time_controller_unittest.cc",
"test/peerconnection_quality_test_fixture_unittest.cc", "test/peerconnection_quality_test_fixture_unittest.cc",
] ]

View File

@ -26,16 +26,10 @@
#include "pc/media_factory.h" #include "pc/media_factory.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "system_wrappers/include/clock.h" #include "system_wrappers/include/clock.h"
#include "test/time_controller/external_time_controller.h"
#include "test/time_controller/simulated_time_controller.h" #include "test/time_controller/simulated_time_controller.h"
namespace webrtc { namespace webrtc {
std::unique_ptr<TimeController> CreateTimeController(
ControlledAlarmClock* alarm) {
return std::make_unique<ExternalTimeController>(alarm);
}
std::unique_ptr<TimeController> CreateSimulatedTimeController() { std::unique_ptr<TimeController> CreateSimulatedTimeController() {
return std::make_unique<GlobalSimulatedTimeController>( return std::make_unique<GlobalSimulatedTimeController>(
Timestamp::Seconds(10000)); Timestamp::Seconds(10000));

View File

@ -17,10 +17,6 @@
namespace webrtc { namespace webrtc {
// Creates a time coltroller that wraps `alarm`.
std::unique_ptr<TimeController> CreateTimeController(
ControlledAlarmClock* alarm);
// Creates a time controller that runs in simulated time. // Creates a time controller that runs in simulated time.
std::unique_ptr<TimeController> CreateSimulatedTimeController(); std::unique_ptr<TimeController> CreateSimulatedTimeController();

View File

@ -1,78 +0,0 @@
/*
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "api/test/create_time_controller.h"
#include <functional>
#include "api/test/time_controller.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "system_wrappers/include/clock.h"
#include "test/gtest.h"
namespace webrtc {
namespace {
class FakeAlarm : public ControlledAlarmClock {
public:
explicit FakeAlarm(Timestamp start_time);
Clock* GetClock() override;
bool ScheduleAlarmAt(Timestamp deadline) override;
void SetCallback(std::function<void()> callback) override;
void Sleep(TimeDelta duration) override;
private:
SimulatedClock clock_;
Timestamp deadline_;
std::function<void()> callback_;
};
FakeAlarm::FakeAlarm(Timestamp start_time)
: clock_(start_time),
deadline_(Timestamp::PlusInfinity()),
callback_([] {}) {}
Clock* FakeAlarm::GetClock() {
return &clock_;
}
bool FakeAlarm::ScheduleAlarmAt(Timestamp deadline) {
if (deadline < deadline_) {
deadline_ = deadline;
return true;
}
return false;
}
void FakeAlarm::SetCallback(std::function<void()> callback) {
callback_ = callback;
}
void FakeAlarm::Sleep(TimeDelta duration) {
Timestamp end_time = clock_.CurrentTime() + duration;
while (deadline_ <= end_time) {
clock_.AdvanceTime(deadline_ - clock_.CurrentTime());
deadline_ = Timestamp::PlusInfinity();
callback_();
}
clock_.AdvanceTime(end_time - clock_.CurrentTime());
}
TEST(CreateTimeControllerTest, CreatesNonNullController) {
FakeAlarm alarm(Timestamp::Millis(100));
EXPECT_NE(CreateTimeController(&alarm), nullptr);
}
} // namespace
} // namespace webrtc

View File

@ -62,28 +62,5 @@ class TimeController {
TimeDelta max_duration = TimeDelta::Seconds(5)); TimeDelta max_duration = TimeDelta::Seconds(5));
}; };
// Interface for telling time, scheduling an event to fire at a particular time,
// and waiting for time to pass.
class ControlledAlarmClock {
public:
virtual ~ControlledAlarmClock() = default;
// Gets a clock that tells the alarm clock's notion of time.
virtual Clock* GetClock() = 0;
// Schedules the alarm to fire at `deadline`.
// An alarm clock only supports one deadline. Calls to `ScheduleAlarmAt` with
// an earlier deadline will reset the alarm to fire earlier.Calls to
// `ScheduleAlarmAt` with a later deadline are ignored. Returns true if the
// deadline changed, false otherwise.
virtual bool ScheduleAlarmAt(Timestamp deadline) = 0;
// Sets the callback that should be run when the alarm fires.
virtual void SetCallback(std::function<void()> callback) = 0;
// Waits for `duration` to pass, according to the alarm clock.
virtual void Sleep(TimeDelta duration) = 0;
};
} // namespace webrtc } // namespace webrtc
#endif // API_TEST_TIME_CONTROLLER_H_ #endif // API_TEST_TIME_CONTROLLER_H_

View File

@ -11,8 +11,6 @@ import("../../webrtc.gni")
rtc_library("time_controller") { rtc_library("time_controller") {
testonly = true testonly = true
sources = [ sources = [
"external_time_controller.cc",
"external_time_controller.h",
"real_time_controller.cc", "real_time_controller.cc",
"real_time_controller.h", "real_time_controller.h",
"simulated_task_queue.cc", "simulated_task_queue.cc",
@ -48,7 +46,6 @@ if (rtc_include_tests) {
rtc_library("time_controller_unittests") { rtc_library("time_controller_unittests") {
testonly = true testonly = true
sources = [ sources = [
"external_time_controller_unittest.cc",
"simulated_time_controller_unittest.cc", "simulated_time_controller_unittest.cc",
"time_controller_conformance_test.cc", "time_controller_conformance_test.cc",
] ]

View File

@ -1,135 +0,0 @@
/*
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "test/time_controller/external_time_controller.h"
#include <algorithm>
#include <map>
#include <memory>
#include <utility>
#include "absl/functional/any_invocable.h"
#include "api/task_queue/task_queue_base.h"
#include "api/task_queue/task_queue_factory.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "rtc_base/checks.h"
#include "rtc_base/synchronization/yield_policy.h"
#include "test/time_controller/simulated_time_controller.h"
namespace webrtc {
// Wraps a TaskQueue so that it can reschedule the time controller whenever
// an external call schedules a new task.
class ExternalTimeController::TaskQueueWrapper : public TaskQueueBase {
public:
TaskQueueWrapper(ExternalTimeController* parent,
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> base)
: parent_(parent), base_(std::move(base)) {}
void PostTaskImpl(absl::AnyInvocable<void() &&> task,
const PostTaskTraits& traits,
const Location& location) override {
parent_->UpdateTime();
base_->PostTask(TaskWrapper(std::move(task)));
parent_->ScheduleNext();
}
void PostDelayedTaskImpl(absl::AnyInvocable<void() &&> task,
TimeDelta delay,
const PostDelayedTaskTraits& traits,
const Location& location) override {
parent_->UpdateTime();
if (traits.high_precision) {
base_->PostDelayedHighPrecisionTask(TaskWrapper(std::move(task)), delay);
} else {
base_->PostDelayedTask(TaskWrapper(std::move(task)), delay);
}
parent_->ScheduleNext();
}
void Delete() override { delete this; }
private:
absl::AnyInvocable<void() &&> TaskWrapper(
absl::AnyInvocable<void() &&> task) {
return [task = std::move(task), this]() mutable {
CurrentTaskQueueSetter current(this);
std::move(task)();
};
}
ExternalTimeController* const parent_;
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> base_;
};
ExternalTimeController::ExternalTimeController(ControlledAlarmClock* alarm)
: alarm_(alarm),
impl_(alarm_->GetClock()->CurrentTime()),
yield_policy_(&impl_) {
global_clock_.SetTime(alarm_->GetClock()->CurrentTime());
alarm_->SetCallback([this] { Run(); });
}
Clock* ExternalTimeController::GetClock() {
return alarm_->GetClock();
}
TaskQueueFactory* ExternalTimeController::GetTaskQueueFactory() {
return this;
}
void ExternalTimeController::AdvanceTime(TimeDelta duration) {
alarm_->Sleep(duration);
}
std::unique_ptr<rtc::Thread> ExternalTimeController::CreateThread(
const std::string& name,
std::unique_ptr<rtc::SocketServer> socket_server) {
RTC_DCHECK_NOTREACHED();
return nullptr;
}
rtc::Thread* ExternalTimeController::GetMainThread() {
RTC_DCHECK_NOTREACHED();
return nullptr;
}
std::unique_ptr<TaskQueueBase, TaskQueueDeleter>
ExternalTimeController::CreateTaskQueue(
absl::string_view name,
TaskQueueFactory::Priority priority) const {
return std::unique_ptr<TaskQueueBase, TaskQueueDeleter>(
new TaskQueueWrapper(const_cast<ExternalTimeController*>(this),
impl_.CreateTaskQueue(name, priority)));
}
void ExternalTimeController::Run() {
rtc::ScopedYieldPolicy yield_policy(&impl_);
UpdateTime();
impl_.RunReadyRunners();
ScheduleNext();
}
void ExternalTimeController::UpdateTime() {
Timestamp now = alarm_->GetClock()->CurrentTime();
impl_.AdvanceTime(now);
global_clock_.SetTime(now);
}
void ExternalTimeController::ScheduleNext() {
RTC_DCHECK_EQ(impl_.CurrentTime(), alarm_->GetClock()->CurrentTime());
TimeDelta delay =
std::max(impl_.NextRunTime() - impl_.CurrentTime(), TimeDelta::Zero());
if (delay.IsFinite()) {
alarm_->ScheduleAlarmAt(alarm_->GetClock()->CurrentTime() + delay);
}
}
} // namespace webrtc

View File

@ -1,69 +0,0 @@
/*
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef TEST_TIME_CONTROLLER_EXTERNAL_TIME_CONTROLLER_H_
#define TEST_TIME_CONTROLLER_EXTERNAL_TIME_CONTROLLER_H_
#include <functional>
#include <memory>
#include "absl/strings/string_view.h"
#include "api/task_queue/task_queue_base.h"
#include "api/task_queue/task_queue_factory.h"
#include "api/test/time_controller.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "system_wrappers/include/clock.h"
#include "test/time_controller/simulated_time_controller.h"
namespace webrtc {
// TimeController implementation built on an external controlled alarm.
// This implementation is used to delegate scheduling and execution to an
// external run loop.
class ExternalTimeController : public TimeController, public TaskQueueFactory {
public:
explicit ExternalTimeController(ControlledAlarmClock* alarm);
// Implementation of TimeController.
Clock* GetClock() override;
TaskQueueFactory* GetTaskQueueFactory() override;
void AdvanceTime(TimeDelta duration) override;
std::unique_ptr<rtc::Thread> CreateThread(
const std::string& name,
std::unique_ptr<rtc::SocketServer> socket_server) override;
rtc::Thread* GetMainThread() override;
// Implementation of TaskQueueFactory.
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> CreateTaskQueue(
absl::string_view name,
TaskQueueFactory::Priority priority) const override;
private:
class TaskQueueWrapper;
// Executes any tasks scheduled at or before the current time. May call
// `ScheduleNext` to schedule the next call to `Run`.
void Run();
void UpdateTime();
void ScheduleNext();
ControlledAlarmClock* alarm_;
sim_time_impl::SimulatedTimeControllerImpl impl_;
rtc::ScopedYieldPolicy yield_policy_;
// Overrides the global rtc::Clock to ensure that it reports the same times as
// the time controller.
rtc::ScopedBaseFakeClock global_clock_;
};
} // namespace webrtc
#endif // TEST_TIME_CONTROLLER_EXTERNAL_TIME_CONTROLLER_H_

View File

@ -1,179 +0,0 @@
/*
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "test/time_controller/external_time_controller.h"
#include <atomic>
#include <memory>
#include <utility>
#include "api/task_queue/task_queue_base.h"
#include "rtc_base/event.h"
#include "rtc_base/task_utils/repeating_task.h"
#include "test/gmock.h"
#include "test/gtest.h"
// NOTE: Since these tests rely on real time behavior, they will be flaky
// if run on heavily loaded systems.
namespace webrtc {
namespace {
using ::testing::AtLeast;
using ::testing::Invoke;
using ::testing::MockFunction;
using ::testing::NiceMock;
using ::testing::Return;
constexpr Timestamp kStartTime = Timestamp::Seconds(1000);
class FakeAlarm : public ControlledAlarmClock {
public:
explicit FakeAlarm(Timestamp start_time);
Clock* GetClock() override;
bool ScheduleAlarmAt(Timestamp deadline) override;
void SetCallback(std::function<void()> callback) override;
void Sleep(TimeDelta duration) override;
private:
SimulatedClock clock_;
Timestamp deadline_;
std::function<void()> callback_;
};
FakeAlarm::FakeAlarm(Timestamp start_time)
: clock_(start_time),
deadline_(Timestamp::PlusInfinity()),
callback_([] {}) {}
Clock* FakeAlarm::GetClock() {
return &clock_;
}
bool FakeAlarm::ScheduleAlarmAt(Timestamp deadline) {
if (deadline < deadline_) {
deadline_ = deadline;
return true;
}
return false;
}
void FakeAlarm::SetCallback(std::function<void()> callback) {
callback_ = callback;
}
void FakeAlarm::Sleep(TimeDelta duration) {
Timestamp end_time = clock_.CurrentTime() + duration;
while (deadline_ <= end_time) {
clock_.AdvanceTime(deadline_ - clock_.CurrentTime());
deadline_ = Timestamp::PlusInfinity();
callback_();
}
clock_.AdvanceTime(end_time - clock_.CurrentTime());
}
} // namespace
TEST(ExternalTimeControllerTest, TaskIsStoppedOnStop) {
const TimeDelta kShortInterval = TimeDelta::Millis(5);
const TimeDelta kLongInterval = TimeDelta::Millis(20);
const int kShortIntervalCount = 4;
const int kMargin = 1;
FakeAlarm alarm(kStartTime);
ExternalTimeController time_simulation(&alarm);
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue =
time_simulation.GetTaskQueueFactory()->CreateTaskQueue(
"TestQueue", TaskQueueFactory::Priority::NORMAL);
std::atomic_int counter(0);
auto handle = RepeatingTaskHandle::Start(task_queue.get(), [&] {
if (++counter >= kShortIntervalCount)
return kLongInterval;
return kShortInterval;
});
// Sleep long enough to go through the initial phase.
time_simulation.AdvanceTime(kShortInterval * (kShortIntervalCount + kMargin));
EXPECT_EQ(counter.load(), kShortIntervalCount);
task_queue->PostTask(
[handle = std::move(handle)]() mutable { handle.Stop(); });
// Sleep long enough that the task would run at least once more if not
// stopped.
time_simulation.AdvanceTime(kLongInterval * 2);
EXPECT_EQ(counter.load(), kShortIntervalCount);
}
TEST(ExternalTimeControllerTest, TaskCanStopItself) {
std::atomic_int counter(0);
FakeAlarm alarm(kStartTime);
ExternalTimeController time_simulation(&alarm);
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue =
time_simulation.GetTaskQueueFactory()->CreateTaskQueue(
"TestQueue", TaskQueueFactory::Priority::NORMAL);
RepeatingTaskHandle handle;
task_queue->PostTask([&] {
handle = RepeatingTaskHandle::Start(task_queue.get(), [&] {
++counter;
handle.Stop();
return TimeDelta::Millis(2);
});
});
time_simulation.AdvanceTime(TimeDelta::Millis(10));
EXPECT_EQ(counter.load(), 1);
}
TEST(ExternalTimeControllerTest, YieldForTask) {
FakeAlarm alarm(kStartTime);
ExternalTimeController time_simulation(&alarm);
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue =
time_simulation.GetTaskQueueFactory()->CreateTaskQueue(
"TestQueue", TaskQueueFactory::Priority::NORMAL);
rtc::Event event;
task_queue->PostTask([&] { event.Set(); });
EXPECT_TRUE(event.Wait(TimeDelta::Millis(200)));
}
TEST(ExternalTimeControllerTest, TasksYieldToEachOther) {
FakeAlarm alarm(kStartTime);
ExternalTimeController time_simulation(&alarm);
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue =
time_simulation.GetTaskQueueFactory()->CreateTaskQueue(
"TestQueue", TaskQueueFactory::Priority::NORMAL);
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> other_queue =
time_simulation.GetTaskQueueFactory()->CreateTaskQueue(
"OtherQueue", TaskQueueFactory::Priority::NORMAL);
task_queue->PostTask([&] {
rtc::Event event;
other_queue->PostTask([&] { event.Set(); });
EXPECT_TRUE(event.Wait(TimeDelta::Millis(200)));
});
time_simulation.AdvanceTime(TimeDelta::Millis(300));
}
TEST(ExternalTimeControllerTest, CurrentTaskQueue) {
FakeAlarm alarm(kStartTime);
ExternalTimeController time_simulation(&alarm);
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue =
time_simulation.GetTaskQueueFactory()->CreateTaskQueue(
"TestQueue", TaskQueueFactory::Priority::NORMAL);
task_queue->PostTask([&] { EXPECT_TRUE(task_queue->IsCurrent()); });
time_simulation.AdvanceTime(TimeDelta::Millis(10));
}
} // namespace webrtc