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,NoValueIfNotEnabled)19 TEST(CpuSpeedExperimentTest, NoValueIfNotEnabled) {
20 CpuSpeedExperiment cpu_speed_config;
21 EXPECT_FALSE(cpu_speed_config.GetValue(1, /*num_cores=*/1));
22 }
23
TEST(CpuSpeedExperimentTest,GetValue)24 TEST(CpuSpeedExperimentTest, GetValue) {
25 webrtc::test::ScopedFieldTrials field_trials(
26 "WebRTC-VP8-CpuSpeed-Arm/pixels:1000,cpu_speed:-12,cores:4/");
27
28 CpuSpeedExperiment cpu_speed_config;
29 EXPECT_EQ(-12, cpu_speed_config.GetValue(1, /*num_cores=*/1));
30 EXPECT_EQ(-12, cpu_speed_config.GetValue(1000, /*num_cores=*/1));
31 EXPECT_EQ(-16, cpu_speed_config.GetValue(1001, /*num_cores=*/1));
32 }
33
TEST(CpuSpeedExperimentTest,GetValueWithList)34 TEST(CpuSpeedExperimentTest, GetValueWithList) {
35 webrtc::test::ScopedFieldTrials field_trials(
36 "WebRTC-VP8-CpuSpeed-Arm/pixels:1000|2000|3000,cpu_speed:-1|-10|-16/");
37
38 CpuSpeedExperiment cpu_speed_config;
39 EXPECT_EQ(-1, cpu_speed_config.GetValue(1, /*num_cores=*/1));
40 EXPECT_EQ(-1, cpu_speed_config.GetValue(1000, /*num_cores=*/1));
41 EXPECT_EQ(-10, cpu_speed_config.GetValue(1001, /*num_cores=*/1));
42 EXPECT_EQ(-10, cpu_speed_config.GetValue(2000, /*num_cores=*/1));
43 EXPECT_EQ(-16, cpu_speed_config.GetValue(2001, /*num_cores=*/1));
44 EXPECT_EQ(-16, cpu_speed_config.GetValue(3000, /*num_cores=*/1));
45 EXPECT_EQ(-16, cpu_speed_config.GetValue(3001, /*num_cores=*/1));
46 }
47
TEST(CpuSpeedExperimentTest,GetValueWithCores)48 TEST(CpuSpeedExperimentTest, GetValueWithCores) {
49 webrtc::test::ScopedFieldTrials field_trials(
50 "WebRTC-VP8-CpuSpeed-Arm/"
51 "pixels:1000|2000|3000,cpu_speed:-1|-10|-16,"
52 "cpu_speed_le_cores:-5|-11|-16,cores:2/");
53
54 CpuSpeedExperiment cpu_speed_config;
55 EXPECT_EQ(-5, cpu_speed_config.GetValue(1000, /*num_cores=*/1));
56 EXPECT_EQ(-11, cpu_speed_config.GetValue(2000, /*num_cores=*/2));
57 EXPECT_EQ(-1, cpu_speed_config.GetValue(1000, /*num_cores=*/3));
58 EXPECT_EQ(-10, cpu_speed_config.GetValue(2000, /*num_cores=*/4));
59 }
60
TEST(CpuSpeedExperimentTest,GetValueWithCoresUnconfigured)61 TEST(CpuSpeedExperimentTest, GetValueWithCoresUnconfigured) {
62 webrtc::test::ScopedFieldTrials field_trials(
63 "WebRTC-VP8-CpuSpeed-Arm/"
64 "pixels:1000|2000|3000,cpu_speed:-1|-10|-16,"
65 "cpu_speed_le_cores:-5|-11|-16/");
66
67 CpuSpeedExperiment cpu_speed_config;
68 EXPECT_EQ(-1, cpu_speed_config.GetValue(1000, /*num_cores=*/1));
69 EXPECT_EQ(-10, cpu_speed_config.GetValue(2000, /*num_cores=*/2));
70 }
71
TEST(CpuSpeedExperimentTest,GetValueFailsForTooSmallValue)72 TEST(CpuSpeedExperimentTest, GetValueFailsForTooSmallValue) {
73 // Supported range: [-16, -1].
74 webrtc::test::ScopedFieldTrials field_trials(
75 "WebRTC-VP8-CpuSpeed-Arm/pixels:1000|2000|3000,cpu_speed:-1|-10|-17/");
76
77 CpuSpeedExperiment cpu_speed_config;
78 EXPECT_FALSE(cpu_speed_config.GetValue(1, /*num_cores=*/1));
79 }
80
TEST(CpuSpeedExperimentTest,GetValueFailsForTooLargeValue)81 TEST(CpuSpeedExperimentTest, GetValueFailsForTooLargeValue) {
82 // Supported range: [-16, -1].
83 webrtc::test::ScopedFieldTrials field_trials(
84 "WebRTC-VP8-CpuSpeed-Arm/pixels:1000|2000|3000,cpu_speed:0|-10|-16/");
85
86 CpuSpeedExperiment cpu_speed_config;
87 EXPECT_FALSE(cpu_speed_config.GetValue(1, /*num_cores=*/1));
88 }
89
TEST(CpuSpeedExperimentTest,GetValueFailsIfPixelsDecreases)90 TEST(CpuSpeedExperimentTest, GetValueFailsIfPixelsDecreases) {
91 webrtc::test::ScopedFieldTrials field_trials(
92 "WebRTC-VP8-CpuSpeed-Arm/pixels:1000|999|3000,cpu_speed:-5|-10|-16/");
93
94 CpuSpeedExperiment cpu_speed_config;
95 EXPECT_FALSE(cpu_speed_config.GetValue(1, /*num_cores=*/1));
96 }
97
TEST(CpuSpeedExperimentTest,GetValueFailsIfCpuSpeedIncreases)98 TEST(CpuSpeedExperimentTest, GetValueFailsIfCpuSpeedIncreases) {
99 webrtc::test::ScopedFieldTrials field_trials(
100 "WebRTC-VP8-CpuSpeed-Arm/pixels:1000|2000|3000,cpu_speed:-5|-4|-16/");
101
102 CpuSpeedExperiment cpu_speed_config;
103 EXPECT_FALSE(cpu_speed_config.GetValue(1, /*num_cores=*/1));
104 }
105
106 } // namespace webrtc
107