1 /*
2 * Copyright 2018 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "rtc_base/experiments/cpu_speed_experiment.h"
12
13 #include "rtc_base/gunit.h"
14 #include "test/field_trial.h"
15 #include "test/gmock.h"
16
17 namespace webrtc {
18
TEST(CpuSpeedExperimentTest,GetConfigsFailsIfNotEnabled)19 TEST(CpuSpeedExperimentTest, GetConfigsFailsIfNotEnabled) {
20 EXPECT_FALSE(CpuSpeedExperiment::GetConfigs());
21 }
22
TEST(CpuSpeedExperimentTest,GetConfigsFailsForTooFewParameters)23 TEST(CpuSpeedExperimentTest, GetConfigsFailsForTooFewParameters) {
24 webrtc::test::ScopedFieldTrials field_trials(
25 "WebRTC-VP8-CpuSpeed-Arm/Enabled-1000,-1,2000,-10,3000/");
26 EXPECT_FALSE(CpuSpeedExperiment::GetConfigs());
27 }
28
TEST(CpuSpeedExperimentTest,GetConfigs)29 TEST(CpuSpeedExperimentTest, GetConfigs) {
30 webrtc::test::ScopedFieldTrials field_trials(
31 "WebRTC-VP8-CpuSpeed-Arm/Enabled-1000,-1,2000,-10,3000,-16/");
32
33 const absl::optional<std::vector<CpuSpeedExperiment::Config>> kConfigs =
34 CpuSpeedExperiment::GetConfigs();
35 ASSERT_TRUE(kConfigs);
36 EXPECT_THAT(*kConfigs,
37 ::testing::ElementsAre(CpuSpeedExperiment::Config{1000, -1},
38 CpuSpeedExperiment::Config{2000, -10},
39 CpuSpeedExperiment::Config{3000, -16}));
40 }
41
TEST(CpuSpeedExperimentTest,GetValue)42 TEST(CpuSpeedExperimentTest, GetValue) {
43 webrtc::test::ScopedFieldTrials field_trials(
44 "WebRTC-VP8-CpuSpeed-Arm/Enabled-1000,-5,2000,-10,3000,-12/");
45
46 const absl::optional<std::vector<CpuSpeedExperiment::Config>> kConfigs =
47 CpuSpeedExperiment::GetConfigs();
48 ASSERT_TRUE(kConfigs);
49 ASSERT_EQ(3u, (*kConfigs).size());
50 EXPECT_EQ(-5, CpuSpeedExperiment::GetValue(1, *kConfigs));
51 EXPECT_EQ(-5, CpuSpeedExperiment::GetValue(1000, *kConfigs));
52 EXPECT_EQ(-10, CpuSpeedExperiment::GetValue(1000 + 1, *kConfigs));
53 EXPECT_EQ(-10, CpuSpeedExperiment::GetValue(2000, *kConfigs));
54 EXPECT_EQ(-12, CpuSpeedExperiment::GetValue(2000 + 1, *kConfigs));
55 EXPECT_EQ(-12, CpuSpeedExperiment::GetValue(3000, *kConfigs));
56 EXPECT_EQ(-16, CpuSpeedExperiment::GetValue(3000 + 1, *kConfigs));
57 }
58
TEST(CpuSpeedExperimentTest,GetConfigsFailsForTooSmallValue)59 TEST(CpuSpeedExperimentTest, GetConfigsFailsForTooSmallValue) {
60 // Supported range: [-16, -1].
61 webrtc::test::ScopedFieldTrials field_trials(
62 "WebRTC-VP8-CpuSpeed-Arm/Enabled-1000,-1,2000,-10,3000,-17/");
63 EXPECT_FALSE(CpuSpeedExperiment::GetConfigs());
64 }
65
TEST(CpuSpeedExperimentTest,GetConfigsFailsForTooLargeValue)66 TEST(CpuSpeedExperimentTest, GetConfigsFailsForTooLargeValue) {
67 // Supported range: [-16, -1].
68 webrtc::test::ScopedFieldTrials field_trials(
69 "WebRTC-VP8-CpuSpeed-Arm/Enabled-1000,0,2000,-10,3000,-16/");
70 EXPECT_FALSE(CpuSpeedExperiment::GetConfigs());
71 }
72
TEST(CpuSpeedExperimentTest,GetConfigsFailsIfPixelsDecreasing)73 TEST(CpuSpeedExperimentTest, GetConfigsFailsIfPixelsDecreasing) {
74 webrtc::test::ScopedFieldTrials field_trials(
75 "WebRTC-VP8-CpuSpeed-Arm/Enabled-1000,-5,999,-10,3000,-16/");
76 EXPECT_FALSE(CpuSpeedExperiment::GetConfigs());
77 }
78
TEST(CpuSpeedExperimentTest,GetConfigsFailsIfCpuSpeedIncreasing)79 TEST(CpuSpeedExperimentTest, GetConfigsFailsIfCpuSpeedIncreasing) {
80 webrtc::test::ScopedFieldTrials field_trials(
81 "WebRTC-VP8-CpuSpeed-Arm/Enabled-1000,-5,2000,-4,3000,-16/");
82 EXPECT_FALSE(CpuSpeedExperiment::GetConfigs());
83 }
84
85 } // namespace webrtc
86