Add and use CreateTestFieldTrialsPtr function for convinience and clarity
Though many tests use FieldTrials by value or const reference, some tests need FieldTrials wrapped into unique_ptr, for example, to pass it to Environment. To better support 2nd set of tests, this patch suggest a new simple wrapper for the common need to create unique_ptr<FieldTrials>. Bug: webrtc:419453427 Change-Id: Icff3e69d858642f43ad79cea5016a5d850616146 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/397162 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#44991}
This commit is contained in:
parent
4a5a5a3e06
commit
d1475bdd72
@ -17,7 +17,6 @@
|
||||
#include "api/audio_codecs/audio_format.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/field_trials.h"
|
||||
#include "test/create_test_field_trials.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
@ -88,9 +87,8 @@ TEST(AudioDecoderOpusTest, MakeAudioDecoderCannotForceDefaultNumChannels) {
|
||||
}
|
||||
|
||||
TEST(AudioDecoderOpusTest, MakeAudioDecoderForcesStereo) {
|
||||
const Environment env =
|
||||
CreateEnvironment(std::make_unique<FieldTrials>(CreateTestFieldTrials(
|
||||
"WebRTC-Audio-OpusDecodeStereoByDefault/Enabled/")));
|
||||
const Environment env = CreateEnvironment(CreateTestFieldTrialsPtr(
|
||||
"WebRTC-Audio-OpusDecodeStereoByDefault/Enabled/"));
|
||||
auto decoder = AudioDecoderOpus::MakeAudioDecoder(
|
||||
env,
|
||||
/*config=*/{.num_channels = std::nullopt});
|
||||
@ -99,9 +97,8 @@ TEST(AudioDecoderOpusTest, MakeAudioDecoderForcesStereo) {
|
||||
}
|
||||
|
||||
TEST(AudioDecoderOpusTest, MakeAudioDecoderCannotForceStereo) {
|
||||
const Environment env =
|
||||
CreateEnvironment(std::make_unique<FieldTrials>(CreateTestFieldTrials(
|
||||
"WebRTC-Audio-OpusDecodeStereoByDefault/Enabled/")));
|
||||
const Environment env = CreateEnvironment(CreateTestFieldTrialsPtr(
|
||||
"WebRTC-Audio-OpusDecodeStereoByDefault/Enabled/"));
|
||||
auto decoder =
|
||||
AudioDecoderOpus::MakeAudioDecoder(env, /*config=*/{.num_channels = 1});
|
||||
|
||||
|
||||
@ -55,8 +55,7 @@ PeerConfigurer::PeerConfigurer(PeerNetworkDependencies& network)
|
||||
network.socket_factory())),
|
||||
params_(std::make_unique<Params>()),
|
||||
configurable_params_(std::make_unique<ConfigurableParams>()) {
|
||||
components_->pcf_dependencies->field_trials =
|
||||
std::make_unique<FieldTrials>(CreateTestFieldTrials());
|
||||
components_->pcf_dependencies->field_trials = CreateTestFieldTrialsPtr();
|
||||
}
|
||||
|
||||
PeerConfigurer* PeerConfigurer::SetName(absl::string_view name) {
|
||||
|
||||
@ -33,7 +33,6 @@
|
||||
#include "api/audio_codecs/opus/audio_decoder_opus.h"
|
||||
#include "api/audio_codecs/opus/audio_encoder_opus.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/field_trials.h"
|
||||
#include "api/neteq/default_neteq_factory.h"
|
||||
#include "api/neteq/neteq.h"
|
||||
#include "common_audio/vad/include/vad.h"
|
||||
@ -49,8 +48,7 @@
|
||||
namespace webrtc {
|
||||
|
||||
TestRedFec::TestRedFec()
|
||||
: env_(CreateEnvironment(
|
||||
std::make_unique<FieldTrials>(CreateTestFieldTrials()))),
|
||||
: env_(CreateEnvironment(CreateTestFieldTrialsPtr())),
|
||||
encoder_factory_(CreateAudioEncoderFactory<AudioEncoderG711,
|
||||
AudioEncoderG722,
|
||||
AudioEncoderL16,
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
#include "api/array_view.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/field_trials.h"
|
||||
#include "api/video/encoded_image.h"
|
||||
#include "api/video/video_frame.h"
|
||||
#include "api/video_codecs/video_decoder.h"
|
||||
@ -97,9 +96,8 @@ TEST(Dav1dDecoderTest, KeepsDecodedResolutionByDefault) {
|
||||
}
|
||||
|
||||
TEST(Dav1dDecoderTest, CropsToRenderResolutionWhenCropIsEnabled) {
|
||||
TestAv1Decoder decoder(
|
||||
CreateEnvironment(std::make_unique<FieldTrials>(CreateTestFieldTrials(
|
||||
"WebRTC-Dav1dDecoder-CropToRenderResolution/Enabled/"))));
|
||||
TestAv1Decoder decoder(CreateEnvironment(CreateTestFieldTrialsPtr(
|
||||
"WebRTC-Dav1dDecoder-CropToRenderResolution/Enabled/")));
|
||||
decoder.Decode(
|
||||
CreateEncodedImage(kAv1FrameWith36x20EncodededAnd32x16RenderResolution));
|
||||
EXPECT_EQ(decoder.decoded_frame().width(), 32);
|
||||
@ -107,9 +105,8 @@ TEST(Dav1dDecoderTest, CropsToRenderResolutionWhenCropIsEnabled) {
|
||||
}
|
||||
|
||||
TEST(Dav1dDecoderTest, DoesNotCropToRenderResolutionWhenCropIsDisabled) {
|
||||
TestAv1Decoder decoder(
|
||||
CreateEnvironment(std::make_unique<FieldTrials>(CreateTestFieldTrials(
|
||||
"WebRTC-Dav1dDecoder-CropToRenderResolution/Disabled/"))));
|
||||
TestAv1Decoder decoder(CreateEnvironment(CreateTestFieldTrialsPtr(
|
||||
"WebRTC-Dav1dDecoder-CropToRenderResolution/Disabled/")));
|
||||
decoder.Decode(
|
||||
CreateEncodedImage(kAv1FrameWith36x20EncodededAnd32x16RenderResolution));
|
||||
EXPECT_EQ(decoder.decoded_frame().width(), 36);
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
#include "absl/flags/flag.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/field_trials.h"
|
||||
#include "api/test/metrics/global_metrics_logger_and_exporter.h"
|
||||
#include "api/units/data_rate.h"
|
||||
#include "api/units/frequency.h"
|
||||
@ -575,8 +574,7 @@ INSTANTIATE_TEST_SUITE_P(All,
|
||||
FramerateAdaptationTest::TestParamsToString);
|
||||
|
||||
TEST(VideoCodecTest, DISABLED_EncodeDecode) {
|
||||
const Environment env =
|
||||
CreateEnvironment(std::make_unique<FieldTrials>(CreateTestFieldTrials()));
|
||||
const Environment env = CreateEnvironment(CreateTestFieldTrialsPtr());
|
||||
|
||||
VideoSourceSettings source_settings{
|
||||
.file_path = absl::GetFlag(FLAGS_input_path),
|
||||
|
||||
@ -21,7 +21,6 @@
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
|
||||
#include "api/data_channel_interface.h"
|
||||
#include "api/field_trials.h"
|
||||
#include "api/jsep.h"
|
||||
#include "api/make_ref_counted.h"
|
||||
#include "api/rtc_error.h"
|
||||
@ -72,10 +71,9 @@ class PeerConnectionDataChannelOpenTest
|
||||
absl::string_view field_trials = "") {
|
||||
auto pc_wrapper = make_ref_counted<PeerConnectionTestWrapper>(
|
||||
"pc", &vss_, background_thread_.get(), background_thread_.get());
|
||||
pc_wrapper->CreatePc(
|
||||
{}, CreateBuiltinAudioEncoderFactory(),
|
||||
CreateBuiltinAudioDecoderFactory(),
|
||||
std::make_unique<FieldTrials>(CreateTestFieldTrials(field_trials)));
|
||||
pc_wrapper->CreatePc({}, CreateBuiltinAudioEncoderFactory(),
|
||||
CreateBuiltinAudioDecoderFactory(),
|
||||
CreateTestFieldTrialsPtr(field_trials));
|
||||
return pc_wrapper;
|
||||
}
|
||||
|
||||
|
||||
@ -26,7 +26,6 @@
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
|
||||
#include "api/audio_options.h"
|
||||
#include "api/field_trials.h"
|
||||
#include "api/field_trials_view.h"
|
||||
#include "api/jsep.h"
|
||||
#include "api/make_ref_counted.h"
|
||||
@ -235,10 +234,9 @@ class PeerConnectionEncodingsIntegrationTest : public ::testing::Test {
|
||||
absl::string_view field_trials = "") {
|
||||
auto pc_wrapper = make_ref_counted<PeerConnectionTestWrapper>(
|
||||
"pc", &pss_, background_thread_.get(), background_thread_.get());
|
||||
pc_wrapper->CreatePc(
|
||||
{}, CreateBuiltinAudioEncoderFactory(),
|
||||
CreateBuiltinAudioDecoderFactory(),
|
||||
std::make_unique<FieldTrials>(CreateTestFieldTrials(field_trials)));
|
||||
pc_wrapper->CreatePc({}, CreateBuiltinAudioEncoderFactory(),
|
||||
CreateBuiltinAudioDecoderFactory(),
|
||||
CreateTestFieldTrialsPtr(field_trials));
|
||||
return pc_wrapper;
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/enable_media_with_defaults.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/field_trials.h"
|
||||
#include "api/media_types.h"
|
||||
#include "api/peer_connection_interface.h"
|
||||
#include "api/rtp_parameters.h"
|
||||
@ -66,8 +65,7 @@ class PeerConnectionFieldTrialTest : public ::testing::Test {
|
||||
void CreatePCFactory(absl::string_view field_trials) {
|
||||
PeerConnectionFactoryDependencies pcf_deps;
|
||||
pcf_deps.signaling_thread = Thread::Current();
|
||||
pcf_deps.env = CreateEnvironment(
|
||||
std::make_unique<FieldTrials>(CreateTestFieldTrials(field_trials)));
|
||||
pcf_deps.env = CreateEnvironment(CreateTestFieldTrialsPtr(field_trials));
|
||||
pcf_deps.adm = FakeAudioCaptureModule::Create();
|
||||
EnableMediaWithDefaults(pcf_deps);
|
||||
pc_factory_ = CreateModularPeerConnectionFactory(std::move(pcf_deps));
|
||||
|
||||
@ -128,8 +128,7 @@ class SdpMungingTest : public ::testing::Test {
|
||||
absl::string_view field_trials) {
|
||||
auto observer = std::make_unique<MockPeerConnectionObserver>();
|
||||
PeerConnectionDependencies pc_deps(observer.get());
|
||||
pc_deps.trials =
|
||||
std::make_unique<FieldTrials>(CreateTestFieldTrials(field_trials));
|
||||
pc_deps.trials = CreateTestFieldTrialsPtr(field_trials);
|
||||
auto result =
|
||||
pc_factory_->CreatePeerConnectionOrError(config, std::move(pc_deps));
|
||||
EXPECT_TRUE(result.ok());
|
||||
|
||||
@ -24,7 +24,6 @@
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
|
||||
#include "api/create_peerconnection_factory.h"
|
||||
#include "api/field_trials.h"
|
||||
#include "api/jsep.h"
|
||||
#include "api/media_types.h"
|
||||
#include "api/peer_connection_interface.h"
|
||||
@ -123,8 +122,7 @@ class SdpOfferAnswerTest : public ::testing::Test {
|
||||
absl::string_view field_trials) {
|
||||
auto observer = std::make_unique<MockPeerConnectionObserver>();
|
||||
PeerConnectionDependencies pc_deps(observer.get());
|
||||
pc_deps.trials =
|
||||
std::make_unique<FieldTrials>(CreateTestFieldTrials(field_trials));
|
||||
pc_deps.trials = CreateTestFieldTrialsPtr(field_trials);
|
||||
auto result =
|
||||
pc_factory_->CreatePeerConnectionOrError(config, std::move(pc_deps));
|
||||
EXPECT_TRUE(result.ok());
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
#include "api/crypto/crypto_options.h"
|
||||
#include "api/data_channel_interface.h"
|
||||
#include "api/dtls_transport_interface.h"
|
||||
#include "api/field_trials.h"
|
||||
#include "api/field_trials_view.h"
|
||||
#include "api/ice_transport_interface.h"
|
||||
#include "api/jsep.h"
|
||||
@ -1469,12 +1468,11 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test {
|
||||
if (it != field_trials_overrides_.end()) {
|
||||
field_trials = it->second;
|
||||
}
|
||||
if (!client->Init(
|
||||
options, &modified_config, std::move(dependencies), fss_.get(),
|
||||
network_thread_.get(), worker_thread_.get(),
|
||||
std::make_unique<FieldTrials>(CreateTestFieldTrials(field_trials)),
|
||||
std::move(event_log_factory), reset_encoder_factory,
|
||||
reset_decoder_factory, create_media_engine)) {
|
||||
if (!client->Init(options, &modified_config, std::move(dependencies),
|
||||
fss_.get(), network_thread_.get(), worker_thread_.get(),
|
||||
CreateTestFieldTrialsPtr(field_trials),
|
||||
std::move(event_log_factory), reset_encoder_factory,
|
||||
reset_decoder_factory, create_media_engine)) {
|
||||
return nullptr;
|
||||
}
|
||||
return client;
|
||||
|
||||
@ -154,6 +154,7 @@ rtc_library("create_test_field_trials") {
|
||||
sources = [ "create_test_field_trials.h" ]
|
||||
deps = [
|
||||
"../api:field_trials",
|
||||
"//third_party/abseil-cpp/absl/base:nullability",
|
||||
"//third_party/abseil-cpp/absl/strings:string_view",
|
||||
]
|
||||
|
||||
|
||||
@ -10,6 +10,9 @@
|
||||
#ifndef TEST_CREATE_TEST_FIELD_TRIALS_H_
|
||||
#define TEST_CREATE_TEST_FIELD_TRIALS_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/field_trials.h"
|
||||
|
||||
@ -20,9 +23,15 @@ namespace webrtc {
|
||||
// the command line flag.
|
||||
// Crashes if command line flag or the `s` are not a valid field trial string.
|
||||
//
|
||||
// The intention of this function is to be the default source of field trials
|
||||
// The intention of these functions is to be the default source of field trials
|
||||
// in tests so that tests always use the command line flag.
|
||||
// The behavior of these two functions is identical, they differ only in the
|
||||
// return types for convenience.
|
||||
FieldTrials CreateTestFieldTrials(absl::string_view s = "");
|
||||
inline absl_nonnull std::unique_ptr<FieldTrials> CreateTestFieldTrialsPtr(
|
||||
absl::string_view s = "") {
|
||||
return std::make_unique<FieldTrials>(CreateTestFieldTrials(s));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user