Moves ownership of time controller into NetworkEmulationManager.
This makes it easier to maintain consistency between real time and simulated time modes. The RealTimeController is updated to use an explicit main thread, this ensures that pending destruction tasks are run as the network emulator goes out of scope. Bug: webrtc:11255 Change-Id: Ie73ab778c78a68d7c58c0f857f14a8d8ac027c67 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166164 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Reviewed-by: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30342}
This commit is contained in:
parent
402379f1f3
commit
6ce033a863
42
api/BUILD.gn
42
api/BUILD.gn
@ -538,6 +538,7 @@ rtc_source_set("network_emulation_manager_api") {
|
|||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
":simulated_network_api",
|
":simulated_network_api",
|
||||||
|
":time_controller",
|
||||||
"../call:simulated_network",
|
"../call:simulated_network",
|
||||||
"../rtc_base",
|
"../rtc_base",
|
||||||
"test/network_emulation",
|
"test/network_emulation",
|
||||||
@ -547,6 +548,24 @@ rtc_source_set("network_emulation_manager_api") {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rtc_source_set("time_controller") {
|
||||||
|
visibility = [ "*" ]
|
||||||
|
sources = [
|
||||||
|
"test/time_controller.cc",
|
||||||
|
"test/time_controller.h",
|
||||||
|
]
|
||||||
|
|
||||||
|
deps = [
|
||||||
|
"../modules/utility",
|
||||||
|
"../rtc_base",
|
||||||
|
"../rtc_base/synchronization:yield_policy",
|
||||||
|
"../system_wrappers",
|
||||||
|
"task_queue",
|
||||||
|
"units:time_delta",
|
||||||
|
"units:timestamp",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
rtc_source_set("fec_controller_api") {
|
rtc_source_set("fec_controller_api") {
|
||||||
visibility = [ "*" ]
|
visibility = [ "*" ]
|
||||||
sources = [
|
sources = [
|
||||||
@ -913,29 +932,6 @@ if (rtc_include_tests) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc_library("time_controller") {
|
|
||||||
visibility = [ "*" ]
|
|
||||||
testonly = true
|
|
||||||
sources = [ "test/time_controller.h" ]
|
|
||||||
|
|
||||||
deps = [
|
|
||||||
"../modules:module_api",
|
|
||||||
"../modules/utility:utility",
|
|
||||||
"../rtc_base",
|
|
||||||
"../rtc_base:rtc_base_tests_utils",
|
|
||||||
"../rtc_base:rtc_event",
|
|
||||||
"../rtc_base/synchronization:sequence_checker",
|
|
||||||
"../rtc_base/synchronization:yield_policy",
|
|
||||||
"../rtc_base/task_utils:to_queued_task",
|
|
||||||
"../system_wrappers",
|
|
||||||
"task_queue",
|
|
||||||
"task_queue:default_task_queue_factory",
|
|
||||||
"units:time_delta",
|
|
||||||
"units:timestamp",
|
|
||||||
"//third_party/abseil-cpp/absl/strings",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
rtc_library("create_time_controller") {
|
rtc_library("create_time_controller") {
|
||||||
visibility = [ "*" ]
|
visibility = [ "*" ]
|
||||||
testonly = true
|
testonly = true
|
||||||
|
|||||||
@ -17,8 +17,9 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
std::unique_ptr<NetworkEmulationManager> CreateNetworkEmulationManager() {
|
std::unique_ptr<NetworkEmulationManager> CreateNetworkEmulationManager(
|
||||||
return std::make_unique<test::NetworkEmulationManagerImpl>();
|
TimeMode mode) {
|
||||||
|
return std::make_unique<test::NetworkEmulationManagerImpl>(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
std::unique_ptr<NetworkEmulationManager> CreateNetworkEmulationManager();
|
std::unique_ptr<NetworkEmulationManager> CreateNetworkEmulationManager(
|
||||||
|
TimeMode mode = TimeMode::kRealTime);
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "api/test/network_emulation/network_emulation_interfaces.h"
|
#include "api/test/network_emulation/network_emulation_interfaces.h"
|
||||||
#include "api/test/simulated_network.h"
|
#include "api/test/simulated_network.h"
|
||||||
|
#include "api/test/time_controller.h"
|
||||||
|
|
||||||
#include "api/units/timestamp.h"
|
#include "api/units/timestamp.h"
|
||||||
#include "rtc_base/network.h"
|
#include "rtc_base/network.h"
|
||||||
@ -69,6 +70,8 @@ class EmulatedNetworkManagerInterface {
|
|||||||
std::function<void(EmulatedNetworkStats)> stats_callback) const = 0;
|
std::function<void(EmulatedNetworkStats)> stats_callback) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class TimeMode { kRealTime, kSimulated };
|
||||||
|
|
||||||
// Provides an API for creating and configuring emulated network layer.
|
// Provides an API for creating and configuring emulated network layer.
|
||||||
// All objects returned by this API are owned by NetworkEmulationManager itself
|
// All objects returned by this API are owned by NetworkEmulationManager itself
|
||||||
// and will be deleted when manager will be deleted.
|
// and will be deleted when manager will be deleted.
|
||||||
@ -103,6 +106,8 @@ class NetworkEmulationManager {
|
|||||||
};
|
};
|
||||||
virtual ~NetworkEmulationManager() = default;
|
virtual ~NetworkEmulationManager() = default;
|
||||||
|
|
||||||
|
virtual TimeController* time_controller() = 0;
|
||||||
|
|
||||||
// Creates an emulated network node, which represents single network in
|
// Creates an emulated network node, which represents single network in
|
||||||
// the emulated network layer.
|
// the emulated network layer.
|
||||||
virtual EmulatedNetworkNode* CreateEmulatedNode(
|
virtual EmulatedNetworkNode* CreateEmulatedNode(
|
||||||
|
|||||||
27
api/test/time_controller.cc
Normal file
27
api/test/time_controller.cc
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 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/time_controller.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
bool TimeController::Wait(const std::function<bool()>& done,
|
||||||
|
TimeDelta max_duration) {
|
||||||
|
// Step size is chosen to be short enough to not significantly affect latency
|
||||||
|
// in real time tests while being long enough to avoid adding too much load to
|
||||||
|
// the system.
|
||||||
|
const auto kStep = TimeDelta::ms(5);
|
||||||
|
for (auto elapsed = TimeDelta::Zero(); elapsed < max_duration;
|
||||||
|
elapsed += kStep) {
|
||||||
|
if (done())
|
||||||
|
return true;
|
||||||
|
AdvanceTime(kStep);
|
||||||
|
}
|
||||||
|
return done();
|
||||||
|
}
|
||||||
|
} // namespace webrtc
|
||||||
@ -23,7 +23,6 @@
|
|||||||
#include "system_wrappers/include/clock.h"
|
#include "system_wrappers/include/clock.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
// Interface for controlling time progress. This allows us to execute test code
|
// Interface for controlling time progress. This allows us to execute test code
|
||||||
// in either real time or simulated time by using different implementation of
|
// in either real time or simulated time by using different implementation of
|
||||||
// this interface.
|
// this interface.
|
||||||
@ -51,6 +50,10 @@ class TimeController {
|
|||||||
// Allow task queues and process threads created by this instance to execute
|
// Allow task queues and process threads created by this instance to execute
|
||||||
// for the given |duration|.
|
// for the given |duration|.
|
||||||
virtual void AdvanceTime(TimeDelta duration) = 0;
|
virtual void AdvanceTime(TimeDelta duration) = 0;
|
||||||
|
|
||||||
|
// Waits until done() == true, polling done() in small time intervals.
|
||||||
|
bool Wait(const std::function<bool()>& done,
|
||||||
|
TimeDelta max_duration = TimeDelta::seconds(5));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Interface for telling time, scheduling an event to fire at a particular time,
|
// Interface for telling time, scheduling an event to fire at a particular time,
|
||||||
|
|||||||
@ -425,6 +425,21 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
class CurrentThreadSetter : CurrentTaskQueueSetter {
|
||||||
|
public:
|
||||||
|
explicit CurrentThreadSetter(Thread* thread)
|
||||||
|
: CurrentTaskQueueSetter(thread),
|
||||||
|
manager_(rtc::ThreadManager::Instance()),
|
||||||
|
previous_(manager_->CurrentThread()) {
|
||||||
|
manager_->ChangeCurrentThreadForTest(thread);
|
||||||
|
}
|
||||||
|
~CurrentThreadSetter() { manager_->ChangeCurrentThreadForTest(previous_); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
rtc::ThreadManager* const manager_;
|
||||||
|
rtc::Thread* const previous_;
|
||||||
|
};
|
||||||
|
|
||||||
// DelayedMessage goes into a priority queue, sorted by trigger time. Messages
|
// DelayedMessage goes into a priority queue, sorted by trigger time. Messages
|
||||||
// with the same trigger time are processed in num_ (FIFO) order.
|
// with the same trigger time are processed in num_ (FIFO) order.
|
||||||
class DelayedMessage {
|
class DelayedMessage {
|
||||||
|
|||||||
@ -113,8 +113,7 @@ TEST(CrossTrafficTest, RandomWalkCrossTraffic) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TcpMessageRouteTest, DeliveredOnLossyNetwork) {
|
TEST(TcpMessageRouteTest, DeliveredOnLossyNetwork) {
|
||||||
GlobalSimulatedTimeController time(Timestamp::seconds(0));
|
NetworkEmulationManagerImpl net(TimeMode::kSimulated);
|
||||||
NetworkEmulationManagerImpl net(&time);
|
|
||||||
BuiltInNetworkBehaviorConfig send;
|
BuiltInNetworkBehaviorConfig send;
|
||||||
// 800 kbps means that the 100 kB message would be delivered in ca 1 second
|
// 800 kbps means that the 100 kB message would be delivered in ca 1 second
|
||||||
// under ideal conditions and no overhead.
|
// under ideal conditions and no overhead.
|
||||||
@ -134,17 +133,16 @@ TEST(TcpMessageRouteTest, DeliveredOnLossyNetwork) {
|
|||||||
constexpr size_t kMessageSize = 100000;
|
constexpr size_t kMessageSize = 100000;
|
||||||
|
|
||||||
tcp_route->SendMessage(kMessageSize, [&] {
|
tcp_route->SendMessage(kMessageSize, [&] {
|
||||||
RTC_LOG(LS_INFO) << "Received at "
|
RTC_LOG(LS_INFO) << "Received at " << ToString(net.Now());
|
||||||
<< ToString(time.GetClock()->CurrentTime());
|
|
||||||
deliver_count++;
|
deliver_count++;
|
||||||
});
|
});
|
||||||
|
|
||||||
// If there was no loss, we would have delivered the message in ca 1 second,
|
// If there was no loss, we would have delivered the message in ca 1 second,
|
||||||
// with 50% it should take much longer.
|
// with 50% it should take much longer.
|
||||||
time.AdvanceTime(TimeDelta::seconds(5));
|
net.time_controller()->AdvanceTime(TimeDelta::seconds(5));
|
||||||
ASSERT_EQ(deliver_count, 0);
|
ASSERT_EQ(deliver_count, 0);
|
||||||
// But given enough time the messsage will be delivered, but only once.
|
// But given enough time the messsage will be delivered, but only once.
|
||||||
time.AdvanceTime(TimeDelta::seconds(60));
|
net.time_controller()->AdvanceTime(TimeDelta::seconds(60));
|
||||||
EXPECT_EQ(deliver_count, 1);
|
EXPECT_EQ(deliver_count, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,8 +17,7 @@ namespace webrtc {
|
|||||||
FeedbackGeneratorImpl::FeedbackGeneratorImpl(
|
FeedbackGeneratorImpl::FeedbackGeneratorImpl(
|
||||||
FeedbackGeneratorImpl::Config config)
|
FeedbackGeneratorImpl::Config config)
|
||||||
: conf_(config),
|
: conf_(config),
|
||||||
time_controller_{Timestamp::seconds(100000)},
|
net_(TimeMode::kSimulated),
|
||||||
net_{&time_controller_},
|
|
||||||
send_link_{new SimulatedNetwork(conf_.send_link)},
|
send_link_{new SimulatedNetwork(conf_.send_link)},
|
||||||
ret_link_{new SimulatedNetwork(conf_.return_link)},
|
ret_link_{new SimulatedNetwork(conf_.return_link)},
|
||||||
route_(this,
|
route_(this,
|
||||||
@ -28,11 +27,11 @@ FeedbackGeneratorImpl::FeedbackGeneratorImpl(
|
|||||||
{net_.CreateEmulatedNode(absl::WrapUnique(ret_link_))})) {}
|
{net_.CreateEmulatedNode(absl::WrapUnique(ret_link_))})) {}
|
||||||
|
|
||||||
Timestamp FeedbackGeneratorImpl::Now() {
|
Timestamp FeedbackGeneratorImpl::Now() {
|
||||||
return time_controller_.GetClock()->CurrentTime();
|
return net_.Now();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedbackGeneratorImpl::Sleep(TimeDelta duration) {
|
void FeedbackGeneratorImpl::Sleep(TimeDelta duration) {
|
||||||
time_controller_.AdvanceTime(duration);
|
net_.time_controller()->AdvanceTime(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedbackGeneratorImpl::SendPacket(size_t size) {
|
void FeedbackGeneratorImpl::SendPacket(size_t size) {
|
||||||
|
|||||||
@ -44,7 +44,6 @@ class FeedbackGeneratorImpl
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Config conf_;
|
Config conf_;
|
||||||
GlobalSimulatedTimeController time_controller_;
|
|
||||||
::webrtc::test::NetworkEmulationManagerImpl net_;
|
::webrtc::test::NetworkEmulationManagerImpl net_;
|
||||||
SimulatedNetwork* const send_link_;
|
SimulatedNetwork* const send_link_;
|
||||||
SimulatedNetwork* const ret_link_;
|
SimulatedNetwork* const ret_link_;
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
#include "call/simulated_network.h"
|
#include "call/simulated_network.h"
|
||||||
#include "rtc_base/fake_network.h"
|
#include "rtc_base/fake_network.h"
|
||||||
#include "test/time_controller/real_time_controller.h"
|
#include "test/time_controller/real_time_controller.h"
|
||||||
|
#include "test/time_controller/simulated_time_controller.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace test {
|
namespace test {
|
||||||
@ -27,18 +28,27 @@ namespace {
|
|||||||
constexpr uint32_t kMinIPv4Address = 0xC0A80000;
|
constexpr uint32_t kMinIPv4Address = 0xC0A80000;
|
||||||
// uint32_t representation of 192.168.255.255 address
|
// uint32_t representation of 192.168.255.255 address
|
||||||
constexpr uint32_t kMaxIPv4Address = 0xC0A8FFFF;
|
constexpr uint32_t kMaxIPv4Address = 0xC0A8FFFF;
|
||||||
|
|
||||||
|
std::unique_ptr<TimeController> CreateTimeController(TimeMode mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case TimeMode::kRealTime:
|
||||||
|
return std::make_unique<RealTimeController>();
|
||||||
|
case TimeMode::kSimulated:
|
||||||
|
// Using an offset of 100000 to get nice fixed width and readable
|
||||||
|
// timestamps in typical test scenarios.
|
||||||
|
const Timestamp kSimulatedStartTime = Timestamp::seconds(100000);
|
||||||
|
return std::make_unique<GlobalSimulatedTimeController>(
|
||||||
|
kSimulatedStartTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
NetworkEmulationManagerImpl::NetworkEmulationManagerImpl()
|
NetworkEmulationManagerImpl::NetworkEmulationManagerImpl(TimeMode mode)
|
||||||
: NetworkEmulationManagerImpl(GlobalRealTimeController()) {}
|
: time_controller_(CreateTimeController(mode)),
|
||||||
|
clock_(time_controller_->GetClock()),
|
||||||
NetworkEmulationManagerImpl::NetworkEmulationManagerImpl(
|
|
||||||
TimeController* time_controller)
|
|
||||||
: time_controller_(time_controller),
|
|
||||||
clock_(time_controller->GetClock()),
|
|
||||||
next_node_id_(1),
|
next_node_id_(1),
|
||||||
next_ip4_address_(kMinIPv4Address),
|
next_ip4_address_(kMinIPv4Address),
|
||||||
task_queue_(time_controller->GetTaskQueueFactory()->CreateTaskQueue(
|
task_queue_(time_controller_->GetTaskQueueFactory()->CreateTaskQueue(
|
||||||
"NetworkEmulation",
|
"NetworkEmulation",
|
||||||
TaskQueueFactory::Priority::NORMAL)) {}
|
TaskQueueFactory::Priority::NORMAL)) {}
|
||||||
|
|
||||||
@ -266,7 +276,7 @@ NetworkEmulationManagerImpl::CreateEmulatedNetworkManagerInterface(
|
|||||||
auto endpoints_container =
|
auto endpoints_container =
|
||||||
std::make_unique<EndpointsContainer>(endpoint_impls);
|
std::make_unique<EndpointsContainer>(endpoint_impls);
|
||||||
auto network_manager = std::make_unique<EmulatedNetworkManager>(
|
auto network_manager = std::make_unique<EmulatedNetworkManager>(
|
||||||
time_controller_, &task_queue_, endpoints_container.get());
|
time_controller_.get(), &task_queue_, endpoints_container.get());
|
||||||
for (auto* endpoint : endpoints) {
|
for (auto* endpoint : endpoints) {
|
||||||
// Associate endpoint with network manager.
|
// Associate endpoint with network manager.
|
||||||
bool insertion_result =
|
bool insertion_result =
|
||||||
|
|||||||
@ -39,8 +39,7 @@ namespace test {
|
|||||||
|
|
||||||
class NetworkEmulationManagerImpl : public NetworkEmulationManager {
|
class NetworkEmulationManagerImpl : public NetworkEmulationManager {
|
||||||
public:
|
public:
|
||||||
NetworkEmulationManagerImpl();
|
explicit NetworkEmulationManagerImpl(TimeMode mode);
|
||||||
explicit NetworkEmulationManagerImpl(TimeController* time_controller);
|
|
||||||
~NetworkEmulationManagerImpl();
|
~NetworkEmulationManagerImpl();
|
||||||
|
|
||||||
EmulatedNetworkNode* CreateEmulatedNode(
|
EmulatedNetworkNode* CreateEmulatedNode(
|
||||||
@ -84,11 +83,13 @@ class NetworkEmulationManagerImpl : public NetworkEmulationManager {
|
|||||||
EmulatedNetworkManagerInterface* CreateEmulatedNetworkManagerInterface(
|
EmulatedNetworkManagerInterface* CreateEmulatedNetworkManagerInterface(
|
||||||
const std::vector<EmulatedEndpoint*>& endpoints) override;
|
const std::vector<EmulatedEndpoint*>& endpoints) override;
|
||||||
|
|
||||||
private:
|
TimeController* time_controller() override { return time_controller_.get(); }
|
||||||
absl::optional<rtc::IPAddress> GetNextIPv4Address();
|
|
||||||
Timestamp Now() const;
|
Timestamp Now() const;
|
||||||
|
|
||||||
TimeController* const time_controller_;
|
private:
|
||||||
|
absl::optional<rtc::IPAddress> GetNextIPv4Address();
|
||||||
|
const std::unique_ptr<TimeController> time_controller_;
|
||||||
Clock* const clock_;
|
Clock* const clock_;
|
||||||
int next_node_id_;
|
int next_node_id_;
|
||||||
|
|
||||||
|
|||||||
@ -99,7 +99,7 @@ TEST(NetworkEmulationManagerPCTest, Run) {
|
|||||||
signaling_thread->Start();
|
signaling_thread->Start();
|
||||||
|
|
||||||
// Setup emulated network
|
// Setup emulated network
|
||||||
NetworkEmulationManagerImpl emulation;
|
NetworkEmulationManagerImpl emulation(TimeMode::kRealTime);
|
||||||
|
|
||||||
EmulatedNetworkNode* alice_node = emulation.CreateEmulatedNode(
|
EmulatedNetworkNode* alice_node = emulation.CreateEmulatedNode(
|
||||||
std::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
std::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
||||||
|
|||||||
@ -28,8 +28,8 @@ namespace webrtc {
|
|||||||
namespace test {
|
namespace test {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr int kNetworkPacketWaitTimeoutMs = 100;
|
constexpr TimeDelta kNetworkPacketWaitTimeout = TimeDelta::Millis<100>();
|
||||||
constexpr int kStatsWaitTimeoutMs = 1000;
|
constexpr TimeDelta kStatsWaitTimeout = TimeDelta::Seconds<1>();
|
||||||
constexpr int kOverheadIpv4Udp = 20 + 8;
|
constexpr int kOverheadIpv4Udp = 20 + 8;
|
||||||
|
|
||||||
class SocketReader : public sigslot::has_slots<> {
|
class SocketReader : public sigslot::has_slots<> {
|
||||||
@ -128,7 +128,7 @@ class NetworkEmulationManagerThreeNodesRoutingTest : public ::testing::Test {
|
|||||||
rtc::CopyOnWriteBuffer(10));
|
rtc::CopyOnWriteBuffer(10));
|
||||||
|
|
||||||
// Sleep at the end to wait for async packets delivery.
|
// Sleep at the end to wait for async packets delivery.
|
||||||
SleepMs(kNetworkPacketWaitTimeoutMs);
|
emulation_.time_controller()->AdvanceTime(kNetworkPacketWaitTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -139,7 +139,7 @@ class NetworkEmulationManagerThreeNodesRoutingTest : public ::testing::Test {
|
|||||||
MockReceiver r_e1_e3_;
|
MockReceiver r_e1_e3_;
|
||||||
MockReceiver r_e3_e1_;
|
MockReceiver r_e3_e1_;
|
||||||
|
|
||||||
NetworkEmulationManagerImpl emulation_;
|
NetworkEmulationManagerImpl emulation_{TimeMode::kRealTime};
|
||||||
EmulatedEndpoint* e1_;
|
EmulatedEndpoint* e1_;
|
||||||
EmulatedEndpoint* e2_;
|
EmulatedEndpoint* e2_;
|
||||||
EmulatedEndpoint* e3_;
|
EmulatedEndpoint* e3_;
|
||||||
@ -156,7 +156,7 @@ EmulatedNetworkNode* CreateEmulatedNodeWithDefaultBuiltInConfig(
|
|||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
|
|
||||||
TEST(NetworkEmulationManagerTest, GeneratedIpv4AddressDoesNotCollide) {
|
TEST(NetworkEmulationManagerTest, GeneratedIpv4AddressDoesNotCollide) {
|
||||||
NetworkEmulationManagerImpl network_manager;
|
NetworkEmulationManagerImpl network_manager(TimeMode::kRealTime);
|
||||||
std::set<rtc::IPAddress> ips;
|
std::set<rtc::IPAddress> ips;
|
||||||
EmulatedEndpointConfig config;
|
EmulatedEndpointConfig config;
|
||||||
config.generated_ip_family = EmulatedEndpointConfig::IpAddressFamily::kIpv4;
|
config.generated_ip_family = EmulatedEndpointConfig::IpAddressFamily::kIpv4;
|
||||||
@ -169,7 +169,7 @@ TEST(NetworkEmulationManagerTest, GeneratedIpv4AddressDoesNotCollide) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(NetworkEmulationManagerTest, GeneratedIpv6AddressDoesNotCollide) {
|
TEST(NetworkEmulationManagerTest, GeneratedIpv6AddressDoesNotCollide) {
|
||||||
NetworkEmulationManagerImpl network_manager;
|
NetworkEmulationManagerImpl network_manager(TimeMode::kRealTime);
|
||||||
std::set<rtc::IPAddress> ips;
|
std::set<rtc::IPAddress> ips;
|
||||||
EmulatedEndpointConfig config;
|
EmulatedEndpointConfig config;
|
||||||
config.generated_ip_family = EmulatedEndpointConfig::IpAddressFamily::kIpv6;
|
config.generated_ip_family = EmulatedEndpointConfig::IpAddressFamily::kIpv6;
|
||||||
@ -182,7 +182,7 @@ TEST(NetworkEmulationManagerTest, GeneratedIpv6AddressDoesNotCollide) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(NetworkEmulationManagerTest, Run) {
|
TEST(NetworkEmulationManagerTest, Run) {
|
||||||
NetworkEmulationManagerImpl network_manager;
|
NetworkEmulationManagerImpl network_manager(TimeMode::kRealTime);
|
||||||
|
|
||||||
EmulatedNetworkNode* alice_node = network_manager.CreateEmulatedNode(
|
EmulatedNetworkNode* alice_node = network_manager.CreateEmulatedNode(
|
||||||
std::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
std::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
||||||
@ -233,8 +233,8 @@ TEST(NetworkEmulationManagerTest, Run) {
|
|||||||
[&]() { s2->Send(data.data(), data.size()); });
|
[&]() { s2->Send(data.data(), data.size()); });
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::Event wait;
|
network_manager.time_controller()->AdvanceTime(TimeDelta::seconds(1));
|
||||||
wait.Wait(1000);
|
|
||||||
EXPECT_EQ(r1.ReceivedCount(), 1000);
|
EXPECT_EQ(r1.ReceivedCount(), 1000);
|
||||||
EXPECT_EQ(r2.ReceivedCount(), 1000);
|
EXPECT_EQ(r2.ReceivedCount(), 1000);
|
||||||
|
|
||||||
@ -262,11 +262,13 @@ TEST(NetworkEmulationManagerTest, Run) {
|
|||||||
EXPECT_EQ(st.bytes_dropped.bytes(), 0l);
|
EXPECT_EQ(st.bytes_dropped.bytes(), 0l);
|
||||||
received_stats_count++;
|
received_stats_count++;
|
||||||
});
|
});
|
||||||
ASSERT_EQ_WAIT(received_stats_count.load(), 2, kStatsWaitTimeoutMs);
|
ASSERT_EQ_SIMULATED_WAIT(received_stats_count.load(), 2,
|
||||||
|
kStatsWaitTimeout.ms(),
|
||||||
|
*network_manager.time_controller());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NetworkEmulationManagerTest, ThroughputStats) {
|
TEST(NetworkEmulationManagerTest, ThroughputStats) {
|
||||||
NetworkEmulationManagerImpl network_manager;
|
NetworkEmulationManagerImpl network_manager(TimeMode::kRealTime);
|
||||||
|
|
||||||
EmulatedNetworkNode* alice_node = network_manager.CreateEmulatedNode(
|
EmulatedNetworkNode* alice_node = network_manager.CreateEmulatedNode(
|
||||||
std::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
std::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
||||||
@ -313,12 +315,11 @@ TEST(NetworkEmulationManagerTest, ThroughputStats) {
|
|||||||
|
|
||||||
// Send 11 packets, totalizing 1 second between the first and the last.
|
// Send 11 packets, totalizing 1 second between the first and the last.
|
||||||
const int kNumPacketsSent = 11;
|
const int kNumPacketsSent = 11;
|
||||||
const int kDelayMs = 100;
|
const TimeDelta kDelay = TimeDelta::ms(100);
|
||||||
rtc::Event wait;
|
|
||||||
for (int i = 0; i < kNumPacketsSent; i++) {
|
for (int i = 0; i < kNumPacketsSent; i++) {
|
||||||
t1->PostTask(RTC_FROM_HERE, [&]() { s1->Send(data.data(), data.size()); });
|
t1->PostTask(RTC_FROM_HERE, [&]() { s1->Send(data.data(), data.size()); });
|
||||||
t2->PostTask(RTC_FROM_HERE, [&]() { s2->Send(data.data(), data.size()); });
|
t2->PostTask(RTC_FROM_HERE, [&]() { s2->Send(data.data(), data.size()); });
|
||||||
wait.Wait(kDelayMs);
|
network_manager.time_controller()->AdvanceTime(kDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::atomic<int> received_stats_count{0};
|
std::atomic<int> received_stats_count{0};
|
||||||
@ -328,11 +329,15 @@ TEST(NetworkEmulationManagerTest, ThroughputStats) {
|
|||||||
|
|
||||||
const double tolerance = 0.95; // Accept 5% tolerance for timing.
|
const double tolerance = 0.95; // Accept 5% tolerance for timing.
|
||||||
EXPECT_GE(st.last_packet_sent_time - st.first_packet_sent_time,
|
EXPECT_GE(st.last_packet_sent_time - st.first_packet_sent_time,
|
||||||
TimeDelta::ms((kNumPacketsSent - 1) * kDelayMs * tolerance));
|
(kNumPacketsSent - 1) * kDelay * tolerance);
|
||||||
EXPECT_GT(st.AverageSendRate().bps(), 0);
|
EXPECT_GT(st.AverageSendRate().bps(), 0);
|
||||||
received_stats_count++;
|
received_stats_count++;
|
||||||
});
|
});
|
||||||
ASSERT_EQ_WAIT(received_stats_count.load(), 1, kStatsWaitTimeoutMs);
|
|
||||||
|
ASSERT_EQ_SIMULATED_WAIT(received_stats_count.load(), 1,
|
||||||
|
kStatsWaitTimeout.ms(),
|
||||||
|
*network_manager.time_controller());
|
||||||
|
|
||||||
EXPECT_EQ(r1.ReceivedCount(), 11);
|
EXPECT_EQ(r1.ReceivedCount(), 11);
|
||||||
EXPECT_EQ(r2.ReceivedCount(), 11);
|
EXPECT_EQ(r2.ReceivedCount(), 11);
|
||||||
|
|
||||||
|
|||||||
@ -41,34 +41,22 @@ std::unique_ptr<FileLogWriterFactory> GetPeerScenarioLogManager(
|
|||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<TimeController> CreateTimeController(bool real_time) {
|
|
||||||
if (real_time) {
|
|
||||||
return std::make_unique<RealTimeController>();
|
|
||||||
} else {
|
|
||||||
// Using an offset of 100000 to get nice fixed width and readable timestamps
|
|
||||||
// in typical test scenarios.
|
|
||||||
const Timestamp kSimulatedStartTime = Timestamp::seconds(100000);
|
|
||||||
return std::make_unique<GlobalSimulatedTimeController>(kSimulatedStartTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
PeerScenario::PeerScenario(const testing::TestInfo& test_info, bool real_time)
|
PeerScenario::PeerScenario(const testing::TestInfo& test_info, TimeMode mode)
|
||||||
: PeerScenario(
|
: PeerScenario(
|
||||||
std::string(test_info.test_suite_name()) + "/" + test_info.name(),
|
std::string(test_info.test_suite_name()) + "/" + test_info.name(),
|
||||||
real_time) {}
|
mode) {}
|
||||||
|
|
||||||
PeerScenario::PeerScenario(std::string file_name, bool real_time)
|
PeerScenario::PeerScenario(std::string file_name, TimeMode mode)
|
||||||
: PeerScenario(GetPeerScenarioLogManager(file_name), real_time) {}
|
: PeerScenario(GetPeerScenarioLogManager(file_name), mode) {}
|
||||||
|
|
||||||
PeerScenario::PeerScenario(
|
PeerScenario::PeerScenario(
|
||||||
std::unique_ptr<LogWriterFactoryInterface> log_writer_manager,
|
std::unique_ptr<LogWriterFactoryInterface> log_writer_manager,
|
||||||
bool real_time)
|
TimeMode mode)
|
||||||
: log_writer_manager_(std::move(log_writer_manager)),
|
: log_writer_manager_(std::move(log_writer_manager)),
|
||||||
time_controller_(CreateTimeController(real_time)),
|
net_(mode),
|
||||||
signaling_thread_(time_controller_->GetMainThread()),
|
signaling_thread_(net_.time_controller()->GetMainThread()) {}
|
||||||
net_(time_controller_.get()) {}
|
|
||||||
|
|
||||||
PeerScenarioClient* PeerScenario::CreateClient(
|
PeerScenarioClient* PeerScenario::CreateClient(
|
||||||
PeerScenarioClient::Config config) {
|
PeerScenarioClient::Config config) {
|
||||||
@ -79,7 +67,7 @@ PeerScenarioClient* PeerScenario::CreateClient(
|
|||||||
PeerScenarioClient* PeerScenario::CreateClient(
|
PeerScenarioClient* PeerScenario::CreateClient(
|
||||||
std::string name,
|
std::string name,
|
||||||
PeerScenarioClient::Config config) {
|
PeerScenarioClient::Config config) {
|
||||||
peer_clients_.emplace_back(net(), time_controller_.get(), thread(),
|
peer_clients_.emplace_back(net(), signaling_thread_,
|
||||||
GetLogWriterFactory(name), config);
|
GetLogWriterFactory(name), config);
|
||||||
return &peer_clients_.back();
|
return &peer_clients_.back();
|
||||||
}
|
}
|
||||||
@ -119,20 +107,12 @@ void PeerScenario::AttachVideoQualityAnalyzer(VideoQualityAnalyzer* analyzer,
|
|||||||
|
|
||||||
bool PeerScenario::WaitAndProcess(std::atomic<bool>* event,
|
bool PeerScenario::WaitAndProcess(std::atomic<bool>* event,
|
||||||
TimeDelta max_duration) {
|
TimeDelta max_duration) {
|
||||||
const auto kStep = TimeDelta::ms(5);
|
return net_.time_controller()->Wait([event] { return event->load(); },
|
||||||
if (*event)
|
max_duration);
|
||||||
return true;
|
|
||||||
for (auto elapsed = TimeDelta::Zero(); elapsed < max_duration;
|
|
||||||
elapsed += kStep) {
|
|
||||||
time_controller_->AdvanceTime(kStep);
|
|
||||||
if (*event)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerScenario::ProcessMessages(TimeDelta duration) {
|
void PeerScenario::ProcessMessages(TimeDelta duration) {
|
||||||
time_controller_->AdvanceTime(duration);
|
net_.time_controller()->AdvanceTime(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<LogWriterFactoryInterface> PeerScenario::GetLogWriterFactory(
|
std::unique_ptr<LogWriterFactoryInterface> PeerScenario::GetLogWriterFactory(
|
||||||
|
|||||||
@ -47,14 +47,14 @@ class PeerScenario {
|
|||||||
// command line flag. Optionally, the TestInfo struct available in gtest can
|
// command line flag. Optionally, the TestInfo struct available in gtest can
|
||||||
// be used to automatically generate a path based on the test name.
|
// be used to automatically generate a path based on the test name.
|
||||||
explicit PeerScenario(const testing::TestInfo& test_info,
|
explicit PeerScenario(const testing::TestInfo& test_info,
|
||||||
bool real_time = false);
|
TimeMode mode = TimeMode::kSimulated);
|
||||||
explicit PeerScenario(std::string file_name, bool real_time = false);
|
explicit PeerScenario(std::string file_name,
|
||||||
|
TimeMode mode = TimeMode::kSimulated);
|
||||||
explicit PeerScenario(
|
explicit PeerScenario(
|
||||||
std::unique_ptr<LogWriterFactoryInterface> log_writer_manager,
|
std::unique_ptr<LogWriterFactoryInterface> log_writer_manager,
|
||||||
bool real_time = false);
|
TimeMode mode = TimeMode::kSimulated);
|
||||||
|
|
||||||
NetworkEmulationManagerImpl* net() { return &net_; }
|
NetworkEmulationManagerImpl* net() { return &net_; }
|
||||||
rtc::Thread* thread() { return signaling_thread_; }
|
|
||||||
|
|
||||||
// Creates a client wrapping a peer connection conforming to the given config.
|
// Creates a client wrapping a peer connection conforming to the given config.
|
||||||
// The client will share the signaling thread with the scenario. To maintain
|
// The client will share the signaling thread with the scenario. To maintain
|
||||||
@ -111,10 +111,9 @@ class PeerScenario {
|
|||||||
std::string name);
|
std::string name);
|
||||||
|
|
||||||
const std::unique_ptr<LogWriterFactoryInterface> log_writer_manager_;
|
const std::unique_ptr<LogWriterFactoryInterface> log_writer_manager_;
|
||||||
const std::unique_ptr<TimeController> time_controller_;
|
NetworkEmulationManagerImpl net_;
|
||||||
rtc::Thread* const signaling_thread_;
|
rtc::Thread* const signaling_thread_;
|
||||||
std::list<PeerVideoQualityPair> video_quality_pairs_;
|
std::list<PeerVideoQualityPair> video_quality_pairs_;
|
||||||
NetworkEmulationManagerImpl net_;
|
|
||||||
std::list<PeerScenarioClient> peer_clients_;
|
std::list<PeerScenarioClient> peer_clients_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -147,15 +147,14 @@ class TimeControllerBasedCallFactory : public CallFactoryInterface {
|
|||||||
|
|
||||||
PeerScenarioClient::PeerScenarioClient(
|
PeerScenarioClient::PeerScenarioClient(
|
||||||
NetworkEmulationManager* net,
|
NetworkEmulationManager* net,
|
||||||
TimeController* time_controller,
|
|
||||||
rtc::Thread* signaling_thread,
|
rtc::Thread* signaling_thread,
|
||||||
std::unique_ptr<LogWriterFactoryInterface> log_writer_factory,
|
std::unique_ptr<LogWriterFactoryInterface> log_writer_factory,
|
||||||
PeerScenarioClient::Config config)
|
PeerScenarioClient::Config config)
|
||||||
: endpoints_(CreateEndpoints(net, config.endpoints)),
|
: endpoints_(CreateEndpoints(net, config.endpoints)),
|
||||||
task_queue_factory_(time_controller->GetTaskQueueFactory()),
|
task_queue_factory_(net->time_controller()->GetTaskQueueFactory()),
|
||||||
signaling_thread_(signaling_thread),
|
signaling_thread_(signaling_thread),
|
||||||
log_writer_factory_(std::move(log_writer_factory)),
|
log_writer_factory_(std::move(log_writer_factory)),
|
||||||
worker_thread_(time_controller->CreateThread("worker")),
|
worker_thread_(net->time_controller()->CreateThread("worker")),
|
||||||
handlers_(config.handlers),
|
handlers_(config.handlers),
|
||||||
observer_(new LambdaPeerConnectionObserver(&handlers_)) {
|
observer_(new LambdaPeerConnectionObserver(&handlers_)) {
|
||||||
handlers_.on_track.push_back(
|
handlers_.on_track.push_back(
|
||||||
@ -191,7 +190,7 @@ PeerScenarioClient::PeerScenarioClient(
|
|||||||
pcf_deps.signaling_thread = signaling_thread_;
|
pcf_deps.signaling_thread = signaling_thread_;
|
||||||
pcf_deps.worker_thread = worker_thread_.get();
|
pcf_deps.worker_thread = worker_thread_.get();
|
||||||
pcf_deps.call_factory =
|
pcf_deps.call_factory =
|
||||||
std::make_unique<TimeControllerBasedCallFactory>(time_controller);
|
std::make_unique<TimeControllerBasedCallFactory>(net->time_controller());
|
||||||
pcf_deps.task_queue_factory =
|
pcf_deps.task_queue_factory =
|
||||||
std::make_unique<TaskQueueFactoryWrapper>(task_queue_factory_);
|
std::make_unique<TaskQueueFactoryWrapper>(task_queue_factory_);
|
||||||
pcf_deps.event_log_factory =
|
pcf_deps.event_log_factory =
|
||||||
|
|||||||
@ -108,7 +108,6 @@ class PeerScenarioClient {
|
|||||||
|
|
||||||
PeerScenarioClient(
|
PeerScenarioClient(
|
||||||
NetworkEmulationManager* net,
|
NetworkEmulationManager* net,
|
||||||
TimeController* time_controller,
|
|
||||||
rtc::Thread* signaling_thread,
|
rtc::Thread* signaling_thread,
|
||||||
std::unique_ptr<LogWriterFactoryInterface> log_writer_factory,
|
std::unique_ptr<LogWriterFactoryInterface> log_writer_factory,
|
||||||
Config config);
|
Config config);
|
||||||
|
|||||||
@ -20,8 +20,6 @@
|
|||||||
#include "test/logging/file_log_writer.h"
|
#include "test/logging/file_log_writer.h"
|
||||||
#include "test/network/network_emulation.h"
|
#include "test/network/network_emulation.h"
|
||||||
#include "test/testsupport/file_utils.h"
|
#include "test/testsupport/file_utils.h"
|
||||||
#include "test/time_controller/real_time_controller.h"
|
|
||||||
#include "test/time_controller/simulated_time_controller.h"
|
|
||||||
|
|
||||||
ABSL_FLAG(bool, scenario_logs, false, "Save logs from scenario framework.");
|
ABSL_FLAG(bool, scenario_logs, false, "Save logs from scenario framework.");
|
||||||
ABSL_FLAG(std::string,
|
ABSL_FLAG(std::string,
|
||||||
@ -47,13 +45,6 @@ std::unique_ptr<FileLogWriterFactory> GetScenarioLogManager(
|
|||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
std::unique_ptr<TimeController> CreateTimeController(bool real_time) {
|
|
||||||
if (real_time) {
|
|
||||||
return std::make_unique<RealTimeController>();
|
|
||||||
} else {
|
|
||||||
return std::make_unique<GlobalSimulatedTimeController>(kSimulatedStartTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Scenario::Scenario()
|
Scenario::Scenario()
|
||||||
@ -74,13 +65,13 @@ Scenario::Scenario(
|
|||||||
std::unique_ptr<LogWriterFactoryInterface> log_writer_factory,
|
std::unique_ptr<LogWriterFactoryInterface> log_writer_factory,
|
||||||
bool real_time)
|
bool real_time)
|
||||||
: log_writer_factory_(std::move(log_writer_factory)),
|
: log_writer_factory_(std::move(log_writer_factory)),
|
||||||
time_controller_(CreateTimeController(real_time)),
|
network_manager_(real_time ? TimeMode::kRealTime : TimeMode::kSimulated),
|
||||||
network_manager_(time_controller_.get()),
|
clock_(network_manager_.time_controller()->GetClock()),
|
||||||
clock_(time_controller_->GetClock()),
|
|
||||||
audio_decoder_factory_(CreateBuiltinAudioDecoderFactory()),
|
audio_decoder_factory_(CreateBuiltinAudioDecoderFactory()),
|
||||||
audio_encoder_factory_(CreateBuiltinAudioEncoderFactory()),
|
audio_encoder_factory_(CreateBuiltinAudioEncoderFactory()),
|
||||||
task_queue_(time_controller_->GetTaskQueueFactory()->CreateTaskQueue(
|
task_queue_(network_manager_.time_controller()
|
||||||
"Scenario",
|
->GetTaskQueueFactory()
|
||||||
|
->CreateTaskQueue("Scenario",
|
||||||
TaskQueueFactory::Priority::NORMAL)) {}
|
TaskQueueFactory::Priority::NORMAL)) {}
|
||||||
|
|
||||||
Scenario::~Scenario() {
|
Scenario::~Scenario() {
|
||||||
@ -116,8 +107,8 @@ StatesPrinter* Scenario::CreatePrinter(std::string name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
CallClient* Scenario::CreateClient(std::string name, CallClientConfig config) {
|
CallClient* Scenario::CreateClient(std::string name, CallClientConfig config) {
|
||||||
CallClient* client =
|
CallClient* client = new CallClient(network_manager_.time_controller(),
|
||||||
new CallClient(time_controller_.get(), GetLogWriterFactory(name), config);
|
GetLogWriterFactory(name), config);
|
||||||
if (config.transport.state_log_interval.IsFinite()) {
|
if (config.transport.state_log_interval.IsFinite()) {
|
||||||
Every(config.transport.state_log_interval, [this, client]() {
|
Every(config.transport.state_log_interval, [this, client]() {
|
||||||
client->network_controller_factory_.LogCongestionControllerStats(Now());
|
client->network_controller_factory_.LogCongestionControllerStats(Now());
|
||||||
@ -282,7 +273,7 @@ void Scenario::At(TimeDelta offset, std::function<void()> function) {
|
|||||||
void Scenario::RunFor(TimeDelta duration) {
|
void Scenario::RunFor(TimeDelta duration) {
|
||||||
if (start_time_.IsInfinite())
|
if (start_time_.IsInfinite())
|
||||||
Start();
|
Start();
|
||||||
time_controller_->AdvanceTime(duration);
|
network_manager_.time_controller()->AdvanceTime(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scenario::RunUntil(TimeDelta target_time_since_start) {
|
void Scenario::RunUntil(TimeDelta target_time_since_start) {
|
||||||
@ -295,11 +286,12 @@ void Scenario::RunUntil(TimeDelta target_time_since_start,
|
|||||||
if (start_time_.IsInfinite())
|
if (start_time_.IsInfinite())
|
||||||
Start();
|
Start();
|
||||||
while (check_interval >= TimeUntilTarget(target_time_since_start)) {
|
while (check_interval >= TimeUntilTarget(target_time_since_start)) {
|
||||||
time_controller_->AdvanceTime(check_interval);
|
network_manager_.time_controller()->AdvanceTime(check_interval);
|
||||||
if (exit_function())
|
if (exit_function())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
time_controller_->AdvanceTime(TimeUntilTarget(target_time_since_start));
|
network_manager_.time_controller()->AdvanceTime(
|
||||||
|
TimeUntilTarget(target_time_since_start));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scenario::Start() {
|
void Scenario::Start() {
|
||||||
|
|||||||
@ -161,7 +161,6 @@ class Scenario {
|
|||||||
TimeDelta TimeUntilTarget(TimeDelta target_time_offset);
|
TimeDelta TimeUntilTarget(TimeDelta target_time_offset);
|
||||||
|
|
||||||
const std::unique_ptr<LogWriterFactoryInterface> log_writer_factory_;
|
const std::unique_ptr<LogWriterFactoryInterface> log_writer_factory_;
|
||||||
std::unique_ptr<TimeController> time_controller_;
|
|
||||||
NetworkEmulationManagerImpl network_manager_;
|
NetworkEmulationManagerImpl network_manager_;
|
||||||
Clock* clock_;
|
Clock* clock_;
|
||||||
|
|
||||||
|
|||||||
@ -14,8 +14,28 @@
|
|||||||
#include "system_wrappers/include/sleep.h"
|
#include "system_wrappers/include/sleep.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
namespace {
|
||||||
|
class MainThread : public rtc::Thread {
|
||||||
|
public:
|
||||||
|
MainThread()
|
||||||
|
: Thread(std::make_unique<rtc::NullSocketServer>(), false),
|
||||||
|
current_setter_(this) {
|
||||||
|
DoInit();
|
||||||
|
}
|
||||||
|
~MainThread() {
|
||||||
|
Stop();
|
||||||
|
DoDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
CurrentThreadSetter current_setter_;
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
RealTimeController::RealTimeController()
|
RealTimeController::RealTimeController()
|
||||||
: task_queue_factory_(CreateDefaultTaskQueueFactory()) {}
|
: task_queue_factory_(CreateDefaultTaskQueueFactory()),
|
||||||
|
main_thread_(std::make_unique<MainThread>()) {
|
||||||
|
main_thread_->SetName("Main", this);
|
||||||
|
}
|
||||||
|
|
||||||
Clock* RealTimeController::GetClock() {
|
Clock* RealTimeController::GetClock() {
|
||||||
return Clock::GetRealTimeClock();
|
return Clock::GetRealTimeClock();
|
||||||
@ -42,16 +62,11 @@ std::unique_ptr<rtc::Thread> RealTimeController::CreateThread(
|
|||||||
}
|
}
|
||||||
|
|
||||||
rtc::Thread* RealTimeController::GetMainThread() {
|
rtc::Thread* RealTimeController::GetMainThread() {
|
||||||
return rtc::Thread::Current();
|
return main_thread_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RealTimeController::AdvanceTime(TimeDelta duration) {
|
void RealTimeController::AdvanceTime(TimeDelta duration) {
|
||||||
GetMainThread()->ProcessMessages(duration.ms());
|
main_thread_->ProcessMessages(duration.ms());
|
||||||
}
|
|
||||||
|
|
||||||
RealTimeController* GlobalRealTimeController() {
|
|
||||||
static RealTimeController* time_controller = new RealTimeController();
|
|
||||||
return time_controller;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
@ -36,10 +36,9 @@ class RealTimeController : public TimeController {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
|
const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
|
||||||
|
const std::unique_ptr<rtc::Thread> main_thread_;
|
||||||
};
|
};
|
||||||
|
|
||||||
RealTimeController* GlobalRealTimeController();
|
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif // TEST_TIME_CONTROLLER_REAL_TIME_CONTROLLER_H_
|
#endif // TEST_TIME_CONTROLLER_REAL_TIME_CONTROLLER_H_
|
||||||
|
|||||||
@ -19,20 +19,7 @@ namespace webrtc {
|
|||||||
class SimulatedThread : public rtc::Thread,
|
class SimulatedThread : public rtc::Thread,
|
||||||
public sim_time_impl::SimulatedSequenceRunner {
|
public sim_time_impl::SimulatedSequenceRunner {
|
||||||
public:
|
public:
|
||||||
class CurrentThreadSetter : CurrentTaskQueueSetter {
|
using CurrentThreadSetter = CurrentThreadSetter;
|
||||||
public:
|
|
||||||
explicit CurrentThreadSetter(Thread* thread)
|
|
||||||
: CurrentTaskQueueSetter(thread),
|
|
||||||
manager_(rtc::ThreadManager::Instance()),
|
|
||||||
previous_(manager_->CurrentThread()) {
|
|
||||||
manager_->ChangeCurrentThreadForTest(thread);
|
|
||||||
}
|
|
||||||
~CurrentThreadSetter() { manager_->ChangeCurrentThreadForTest(previous_); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
rtc::ThreadManager* const manager_;
|
|
||||||
rtc::Thread* const previous_;
|
|
||||||
};
|
|
||||||
SimulatedThread(sim_time_impl::SimulatedTimeControllerImpl* handler,
|
SimulatedThread(sim_time_impl::SimulatedTimeControllerImpl* handler,
|
||||||
absl::string_view name,
|
absl::string_view name,
|
||||||
std::unique_ptr<rtc::SocketServer> socket_server);
|
std::unique_ptr<rtc::SocketServer> socket_server);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user