webrtc/test/scenario/scenario.h
Artem Titov 6cae2d5513 Reland "Remove RTC_DISALLOW_COPY_AND_ASSIGN usages completely"
This reverts commit 3f87250a4f.

Reason for revert: Downstream is fixed

Original change's description:
> Revert "Remove RTC_DISALLOW_COPY_AND_ASSIGN usages completely"
>
> This reverts commit 5f0eb93d2a.
>
> Reason for revert: Breaks downstream project. I'm going to fix that one and create a reland of this CL after.
>
> Original change's description:
> > Remove RTC_DISALLOW_COPY_AND_ASSIGN usages completely
> >
> > Bug: webrtc:13555, webrtc:13082
> > Change-Id: Iff2cda6f516739419e97e975e03f77a98f74be03
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249260
> > Reviewed-by: Harald Alvestrand <hta@webrtc.org>
> > Reviewed-by: Artem Titov <titovartem@webrtc.org>
> > Commit-Queue: (Daniel.L) Byoungchan Lee <daniel.l@hpcnt.com>
> > Cr-Commit-Position: refs/heads/main@{#35805}
>
> TBR=hta@webrtc.org,titovartem@webrtc.org,daniel.l@hpcnt.com,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com
>
> Change-Id: I33d497f1132adfe6d151023195a388d9b7d548f9
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:13555, webrtc:13082
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249364
> Reviewed-by: Artem Titov <titovartem@webrtc.org>
> Owners-Override: Artem Titov <titovartem@webrtc.org>
> Reviewed-by: Andrey Logvin <landrey@webrtc.org>
> Reviewed-by: Björn Terelius <terelius@webrtc.org>
> Commit-Queue: Artem Titov <titovartem@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#35807}

# Not skipping CQ checks because this is a reland.

Bug: webrtc:13555, webrtc:13082
Change-Id: I7ef1ef3b6e3c41b1a96014aa75f003c0fcf33949
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249365
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35814}
2022-01-27 12:55:44 +00:00

187 lines
7.4 KiB
C++

/*
* Copyright 2018 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_SCENARIO_SCENARIO_H_
#define TEST_SCENARIO_SCENARIO_H_
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "api/test/time_controller.h"
#include "rtc_base/fake_clock.h"
#include "rtc_base/task_queue.h"
#include "rtc_base/task_utils/repeating_task.h"
#include "test/gtest.h"
#include "test/logging/log_writer.h"
#include "test/network/network_emulation_manager.h"
#include "test/scenario/audio_stream.h"
#include "test/scenario/call_client.h"
#include "test/scenario/column_printer.h"
#include "test/scenario/network_node.h"
#include "test/scenario/scenario_config.h"
#include "test/scenario/video_stream.h"
namespace webrtc {
namespace test {
// Scenario is a class owning everything for a test scenario. It creates and
// holds network nodes, call clients and media streams. It also provides methods
// for changing behavior at runtime. Since it always keeps ownership of the
// created components, it generally returns non-owning pointers. It maintains
// the life of its objects until it is destroyed.
// For methods accepting configuration structs, a modifier function interface is
// generally provided. This allows simple partial overriding of the default
// configuration.
class Scenario {
public:
Scenario();
explicit Scenario(const testing::TestInfo* test_info);
explicit Scenario(std::string file_name);
Scenario(std::string file_name, bool real_time);
Scenario(std::unique_ptr<LogWriterFactoryInterface> log_writer_manager,
bool real_time);
~Scenario();
Scenario(const Scenario&) = delete;
Scenario& operator=(const Scenario&) = delete;
NetworkEmulationManagerImpl* net() { return &network_manager_; }
EmulatedNetworkNode* CreateSimulationNode(NetworkSimulationConfig config);
EmulatedNetworkNode* CreateSimulationNode(
std::function<void(NetworkSimulationConfig*)> config_modifier);
SimulationNode* CreateMutableSimulationNode(NetworkSimulationConfig config);
SimulationNode* CreateMutableSimulationNode(
std::function<void(NetworkSimulationConfig*)> config_modifier);
CallClient* CreateClient(std::string name, CallClientConfig config);
CallClient* CreateClient(
std::string name,
std::function<void(CallClientConfig*)> config_modifier);
CallClientPair* CreateRoutes(CallClient* first,
std::vector<EmulatedNetworkNode*> send_link,
CallClient* second,
std::vector<EmulatedNetworkNode*> return_link);
CallClientPair* CreateRoutes(CallClient* first,
std::vector<EmulatedNetworkNode*> send_link,
DataSize first_overhead,
CallClient* second,
std::vector<EmulatedNetworkNode*> return_link,
DataSize second_overhead);
void ChangeRoute(std::pair<CallClient*, CallClient*> clients,
std::vector<EmulatedNetworkNode*> over_nodes);
void ChangeRoute(std::pair<CallClient*, CallClient*> clients,
std::vector<EmulatedNetworkNode*> over_nodes,
DataSize overhead);
VideoStreamPair* CreateVideoStream(
std::pair<CallClient*, CallClient*> clients,
std::function<void(VideoStreamConfig*)> config_modifier);
VideoStreamPair* CreateVideoStream(
std::pair<CallClient*, CallClient*> clients,
VideoStreamConfig config);
AudioStreamPair* CreateAudioStream(
std::pair<CallClient*, CallClient*> clients,
std::function<void(AudioStreamConfig*)> config_modifier);
AudioStreamPair* CreateAudioStream(
std::pair<CallClient*, CallClient*> clients,
AudioStreamConfig config);
// Runs the provided function with a fixed interval. For real time tests,
// `function` starts being called after `interval` from the call to Every().
void Every(TimeDelta interval, std::function<void(TimeDelta)> function);
void Every(TimeDelta interval, std::function<void()> function);
// Runs the provided function on the internal task queue. This ensure that
// it's run on the main thread for simulated time tests.
void Post(std::function<void()> function);
// Runs the provided function after given duration has passed. For real time
// tests, `function` is called after `target_time_since_start` from the call
// to Every().
void At(TimeDelta offset, std::function<void()> function);
// Sends a packet over the nodes and runs `action` when it has been delivered.
void NetworkDelayedAction(std::vector<EmulatedNetworkNode*> over_nodes,
size_t packet_size,
std::function<void()> action);
// Runs the scenario for the given time.
void RunFor(TimeDelta duration);
// Runs the scenario until `target_time_since_start`.
void RunUntil(TimeDelta target_time_since_start);
// Runs the scenario until `target_time_since_start` or `exit_function`
// returns true. `exit_function` is polled after each `check_interval` has
// passed.
void RunUntil(TimeDelta target_time_since_start,
TimeDelta check_interval,
std::function<bool()> exit_function);
void Start();
void Stop();
// Triggers sending of dummy packets over the given nodes.
void TriggerPacketBurst(std::vector<EmulatedNetworkNode*> over_nodes,
size_t num_packets,
size_t packet_size);
ColumnPrinter TimePrinter();
StatesPrinter* CreatePrinter(std::string name,
TimeDelta interval,
std::vector<ColumnPrinter> printers);
// Returns the current time.
Timestamp Now();
// Return the duration of the current session so far.
TimeDelta TimeSinceStart();
std::unique_ptr<RtcEventLogOutput> GetLogWriter(std::string name) {
if (!log_writer_factory_ || name.empty())
return nullptr;
return log_writer_factory_->Create(name);
}
std::unique_ptr<LogWriterFactoryInterface> GetLogWriterFactory(
std::string name) {
if (!log_writer_factory_ || name.empty())
return nullptr;
return std::make_unique<LogWriterFactoryAddPrefix>(
log_writer_factory_.get(), name);
}
private:
TimeDelta TimeUntilTarget(TimeDelta target_time_offset);
const std::unique_ptr<LogWriterFactoryInterface> log_writer_factory_;
NetworkEmulationManagerImpl network_manager_;
Clock* clock_;
std::vector<std::unique_ptr<CallClient>> clients_;
std::vector<std::unique_ptr<CallClientPair>> client_pairs_;
std::vector<std::unique_ptr<VideoStreamPair>> video_streams_;
std::vector<std::unique_ptr<AudioStreamPair>> audio_streams_;
std::vector<std::unique_ptr<SimulationNode>> simulation_nodes_;
std::vector<std::unique_ptr<StatesPrinter>> printers_;
rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory_;
rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory_;
Timestamp start_time_ = Timestamp::PlusInfinity();
// Defined last so it's destroyed first.
rtc::TaskQueue task_queue_;
};
} // namespace test
} // namespace webrtc
#endif // TEST_SCENARIO_SCENARIO_H_