Cleanup of scenario test framework.
* Removing unused return values. * Using TaskQueueForTest to do blocking calls. * Improving naming. This prepares for future work to run scenario tests in simulated time. Bug: webrtc:10365 Change-Id: I2c100e9c20f4b85e85d7b455ea01944f6a14e08f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/127561 Reviewed-by: Artem Titov <titovartem@webrtc.org> Commit-Queue: Sebastian Jansson <srte@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27105}
This commit is contained in:

committed by
Commit Bot

parent
9a66d5ed65
commit
123f3453e2
@ -55,7 +55,6 @@ if (rtc_include_tests) {
|
||||
"audio_stream.h",
|
||||
"call_client.cc",
|
||||
"call_client.h",
|
||||
"call_client.h",
|
||||
"hardware_codecs.cc",
|
||||
"hardware_codecs.h",
|
||||
"network_node.cc",
|
||||
@ -128,6 +127,7 @@ if (rtc_include_tests) {
|
||||
"../../rtc_base:rtc_base_approved",
|
||||
"../../rtc_base:rtc_base_tests_utils",
|
||||
"../../rtc_base:rtc_task_queue",
|
||||
"../../rtc_base:rtc_task_queue_for_test",
|
||||
"../../rtc_base:safe_minmax",
|
||||
"../../rtc_base:sequenced_task_checker",
|
||||
"../../system_wrappers",
|
||||
|
@ -32,9 +32,7 @@ VideoQualityAnalyzer::VideoQualityAnalyzer(
|
||||
}
|
||||
|
||||
VideoQualityAnalyzer::~VideoQualityAnalyzer() {
|
||||
rtc::Event event;
|
||||
task_queue_.PostTask([&event] { event.Set(); });
|
||||
event.Wait(rtc::Event::kForever);
|
||||
task_queue_.SendTask([] {});
|
||||
}
|
||||
|
||||
void VideoQualityAnalyzer::OnCapturedFrame(const VideoFrame& frame) {
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "api/video/video_frame.h"
|
||||
#include "api/video/video_sink_interface.h"
|
||||
#include "api/video/video_source_interface.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "rtc_base/task_queue_for_test.h"
|
||||
#include "rtc_base/time_utils.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
#include "test/logging/log_writer.h"
|
||||
@ -50,7 +50,7 @@ class VideoQualityAnalyzer {
|
||||
std::vector<std::function<void(const VideoFrameQualityInfo&)>>
|
||||
frame_info_handlers_;
|
||||
std::deque<VideoFrame> captured_frames_;
|
||||
rtc::TaskQueue task_queue_;
|
||||
rtc::test::TaskQueueForTest task_queue_;
|
||||
};
|
||||
|
||||
struct VideoQualityStats {
|
||||
|
@ -224,12 +224,11 @@ SimulationNode* Scenario::CreateSimulationNode(NetworkNodeConfig config) {
|
||||
}
|
||||
|
||||
EmulatedNetworkNode* Scenario::CreateNetworkNode(
|
||||
NetworkNodeConfig config,
|
||||
std::unique_ptr<NetworkBehaviorInterface> behavior) {
|
||||
RTC_DCHECK(config.mode == NetworkNodeConfig::TrafficMode::kCustom);
|
||||
network_nodes_.emplace_back(new EmulatedNetworkNode(std::move(behavior)));
|
||||
EmulatedNetworkNode* network_node = network_nodes_.back().get();
|
||||
Every(config.update_frequency,
|
||||
// TODO(srte): Use the update interval as provided by |behavior|.
|
||||
Every(TimeDelta::ms(5),
|
||||
[this, network_node] { network_node->Process(Now()); });
|
||||
return network_node;
|
||||
}
|
||||
@ -315,24 +314,21 @@ AudioStreamPair* Scenario::CreateAudioStream(
|
||||
return audio_streams_.back().get();
|
||||
}
|
||||
|
||||
RepeatedActivity* Scenario::Every(TimeDelta interval,
|
||||
std::function<void(TimeDelta)> function) {
|
||||
void Scenario::Every(TimeDelta interval,
|
||||
std::function<void(TimeDelta)> function) {
|
||||
repeated_activities_.emplace_back(new RepeatedActivity(interval, function));
|
||||
if (start_time_.IsFinite()) {
|
||||
repeated_activities_.back()->SetStartTime(Now());
|
||||
}
|
||||
return repeated_activities_.back().get();
|
||||
}
|
||||
|
||||
RepeatedActivity* Scenario::Every(TimeDelta interval,
|
||||
std::function<void()> function) {
|
||||
void Scenario::Every(TimeDelta interval, std::function<void()> function) {
|
||||
auto function_with_argument = [function](TimeDelta) { function(); };
|
||||
repeated_activities_.emplace_back(
|
||||
new RepeatedActivity(interval, function_with_argument));
|
||||
if (start_time_.IsFinite()) {
|
||||
repeated_activities_.back()->SetStartTime(Now());
|
||||
}
|
||||
return repeated_activities_.back().get();
|
||||
}
|
||||
|
||||
void Scenario::At(TimeDelta offset, std::function<void()> function) {
|
||||
@ -340,24 +336,25 @@ void Scenario::At(TimeDelta offset, std::function<void()> function) {
|
||||
}
|
||||
|
||||
void Scenario::RunFor(TimeDelta duration) {
|
||||
RunUntil(Duration() + duration);
|
||||
RunUntil(TimeSinceStart() + duration);
|
||||
}
|
||||
|
||||
void Scenario::RunUntil(TimeDelta max_duration) {
|
||||
RunUntil(max_duration, TimeDelta::PlusInfinity(), []() { return false; });
|
||||
void Scenario::RunUntil(TimeDelta target_time_since_start) {
|
||||
RunUntil(target_time_since_start, TimeDelta::PlusInfinity(),
|
||||
[]() { return false; });
|
||||
}
|
||||
|
||||
void Scenario::RunUntil(TimeDelta max_duration,
|
||||
TimeDelta poll_interval,
|
||||
void Scenario::RunUntil(TimeDelta target_time_since_start,
|
||||
TimeDelta check_interval,
|
||||
std::function<bool()> exit_function) {
|
||||
if (start_time_.IsInfinite())
|
||||
Start();
|
||||
|
||||
rtc::Event done_;
|
||||
while (!exit_function() && Duration() < max_duration) {
|
||||
while (!exit_function() && TimeSinceStart() < target_time_since_start) {
|
||||
Timestamp current_time = Now();
|
||||
TimeDelta duration = current_time - start_time_;
|
||||
Timestamp next_time = current_time + poll_interval;
|
||||
Timestamp next_time = current_time + check_interval;
|
||||
for (auto& activity : repeated_activities_) {
|
||||
activity->Poll(current_time);
|
||||
next_time = std::min(next_time, activity->NextTime());
|
||||
@ -423,7 +420,7 @@ Timestamp Scenario::Now() {
|
||||
return Timestamp::us(clock_->TimeInMicroseconds());
|
||||
}
|
||||
|
||||
TimeDelta Scenario::Duration() {
|
||||
TimeDelta Scenario::TimeSinceStart() {
|
||||
if (start_time_.IsInfinite())
|
||||
return TimeDelta::Zero();
|
||||
return Now() - start_time_;
|
||||
|
@ -74,7 +74,6 @@ class Scenario {
|
||||
SimulationNode* CreateSimulationNode(
|
||||
std::function<void(NetworkNodeConfig*)> config_modifier);
|
||||
EmulatedNetworkNode* CreateNetworkNode(
|
||||
NetworkNodeConfig config,
|
||||
std::unique_ptr<NetworkBehaviorInterface> behavior);
|
||||
|
||||
CallClient* CreateClient(std::string name, CallClientConfig config);
|
||||
@ -130,9 +129,8 @@ class Scenario {
|
||||
CrossTrafficConfig config);
|
||||
|
||||
// Runs the provided function with a fixed interval.
|
||||
RepeatedActivity* Every(TimeDelta interval,
|
||||
std::function<void(TimeDelta)> function);
|
||||
RepeatedActivity* Every(TimeDelta interval, std::function<void()> function);
|
||||
void Every(TimeDelta interval, std::function<void(TimeDelta)> function);
|
||||
void Every(TimeDelta interval, std::function<void()> function);
|
||||
|
||||
// Runs the provided function after given duration has passed in a session.
|
||||
void At(TimeDelta offset, std::function<void()> function);
|
||||
@ -145,9 +143,12 @@ class Scenario {
|
||||
// Runs the scenario for the given time or until the exit function returns
|
||||
// true.
|
||||
void RunFor(TimeDelta duration);
|
||||
void RunUntil(TimeDelta max_duration);
|
||||
void RunUntil(TimeDelta max_duration,
|
||||
TimeDelta probe_interval,
|
||||
void RunUntil(TimeDelta target_time_since_start);
|
||||
// Will check |exit_function| every |check_interval|. It stops after a check
|
||||
// if either |target_time_since_start| has passed or if |exit_function|
|
||||
// returns true.
|
||||
void RunUntil(TimeDelta target_time_since_start,
|
||||
TimeDelta check_interval,
|
||||
std::function<bool()> exit_function);
|
||||
void Start();
|
||||
void Stop();
|
||||
@ -165,7 +166,7 @@ class Scenario {
|
||||
// Returns the current time.
|
||||
Timestamp Now();
|
||||
// Return the duration of the current session so far.
|
||||
TimeDelta Duration();
|
||||
TimeDelta TimeSinceStart();
|
||||
|
||||
std::unique_ptr<RtcEventLogOutput> GetLogWriter(std::string name) {
|
||||
if (!log_writer_factory_ || name.empty())
|
||||
|
Reference in New Issue
Block a user