webrtc_m130/rtc_base/experiments/cpu_speed_experiment_unittest.cc
Åsa Persson 869e9fb4f3 Use field trial list in CpuSpeedExperiment.
Removes the need for specifying a fixed number of parameters.

Bug: none
Change-Id: I1324861807cb4929963aedccb6c2755b9c6ea3fc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/180421
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Commit-Queue: Åsa Persson <asapersson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32055}
2020-09-08 06:56:49 +00:00

83 lines
2.8 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.
*/
#include "rtc_base/experiments/cpu_speed_experiment.h"
#include "rtc_base/gunit.h"
#include "test/field_trial.h"
#include "test/gmock.h"
namespace webrtc {
TEST(CpuSpeedExperimentTest, NoValueIfNotEnabled) {
CpuSpeedExperiment cpu_speed_config;
EXPECT_FALSE(cpu_speed_config.GetValue(1));
}
TEST(CpuSpeedExperimentTest, GetValue) {
webrtc::test::ScopedFieldTrials field_trials(
"WebRTC-VP8-CpuSpeed-Arm/pixels:1000,cpu_speed:-12/");
CpuSpeedExperiment cpu_speed_config;
EXPECT_EQ(-12, cpu_speed_config.GetValue(1));
EXPECT_EQ(-12, cpu_speed_config.GetValue(1000));
EXPECT_EQ(-16, cpu_speed_config.GetValue(1001));
}
TEST(CpuSpeedExperimentTest, GetValueWithList) {
webrtc::test::ScopedFieldTrials field_trials(
"WebRTC-VP8-CpuSpeed-Arm/pixels:1000|2000|3000,cpu_speed:-1|-10|-16/");
CpuSpeedExperiment cpu_speed_config;
EXPECT_EQ(-1, cpu_speed_config.GetValue(1));
EXPECT_EQ(-1, cpu_speed_config.GetValue(1000));
EXPECT_EQ(-10, cpu_speed_config.GetValue(1001));
EXPECT_EQ(-10, cpu_speed_config.GetValue(2000));
EXPECT_EQ(-16, cpu_speed_config.GetValue(2001));
EXPECT_EQ(-16, cpu_speed_config.GetValue(3000));
EXPECT_EQ(-16, cpu_speed_config.GetValue(3001));
}
TEST(CpuSpeedExperimentTest, GetValueFailsForTooSmallValue) {
// Supported range: [-16, -1].
webrtc::test::ScopedFieldTrials field_trials(
"WebRTC-VP8-CpuSpeed-Arm/pixels:1000|2000|3000,cpu_speed:-1|-10|-17/");
CpuSpeedExperiment cpu_speed_config;
EXPECT_FALSE(cpu_speed_config.GetValue(1));
}
TEST(CpuSpeedExperimentTest, GetValueFailsForTooLargeValue) {
// Supported range: [-16, -1].
webrtc::test::ScopedFieldTrials field_trials(
"WebRTC-VP8-CpuSpeed-Arm/pixels:1000|2000|3000,cpu_speed:0|-10|-16/");
CpuSpeedExperiment cpu_speed_config;
EXPECT_FALSE(cpu_speed_config.GetValue(1));
}
TEST(CpuSpeedExperimentTest, GetValueFailsIfPixelsDecreases) {
webrtc::test::ScopedFieldTrials field_trials(
"WebRTC-VP8-CpuSpeed-Arm/pixels:1000|999|3000,cpu_speed:-5|-10|-16/");
CpuSpeedExperiment cpu_speed_config;
EXPECT_FALSE(cpu_speed_config.GetValue(1));
}
TEST(CpuSpeedExperimentTest, GetValueFailsIfCpuSpeedIncreases) {
webrtc::test::ScopedFieldTrials field_trials(
"WebRTC-VP8-CpuSpeed-Arm/pixels:1000|2000|3000,cpu_speed:-5|-4|-16/");
CpuSpeedExperiment cpu_speed_config;
EXPECT_FALSE(cpu_speed_config.GetValue(1));
}
} // namespace webrtc