Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: components/task_scheduler_util/common/variations_util_unittest.cc

Issue 2749303002: [reference - do not submit] Always create four pools in TaskSchedulerImpl. (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/task_scheduler_util/common/variations_util.h" 5 #include "components/task_scheduler_util/common/variations_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/task_scheduler/scheduler_worker_params.h" 15 #include "base/task_scheduler/scheduler_worker_params.h"
16 #include "base/task_scheduler/scheduler_worker_pool_params.h" 16 #include "base/task_scheduler/scheduler_worker_pool_params.h"
17 #include "base/threading/platform_thread.h"
18 #include "components/variations/variations_associated_data.h" 17 #include "components/variations/variations_associated_data.h"
19 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
20 19
21 namespace task_scheduler_util { 20 namespace task_scheduler_util {
22 21
23 namespace { 22 namespace {
24 23
25 using StandbyThreadPolicy = 24 using StandbyThreadPolicy =
26 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; 25 base::SchedulerWorkerPoolParams::StandbyThreadPolicy;
27 using ThreadPriority = base::ThreadPriority; 26 using SchedulerBackwardCompatibility = base::SchedulerBackwardCompatibility;
28 27
29 #if !defined(OS_IOS) 28 #if !defined(OS_IOS)
30 constexpr char kFieldTrialName[] = "BrowserScheduler"; 29 constexpr char kFieldTrialName[] = "BrowserScheduler";
31 constexpr char kFieldTrialTestGroup[] = "Test"; 30 constexpr char kFieldTrialTestGroup[] = "Test";
32 constexpr char kTaskSchedulerVariationParamsSwitch[] = 31 constexpr char kTaskSchedulerVariationParamsSwitch[] =
33 "task-scheduler-variation-params"; 32 "task-scheduler-variation-params";
34 #endif // !defined(OS_IOS) 33 #endif // !defined(OS_IOS)
35 34
36 std::vector<SchedulerImmutableWorkerPoolParams> GetImmutableWorkerPoolParams() {
37 std::vector<SchedulerImmutableWorkerPoolParams> constant_worker_pool_params;
38 constant_worker_pool_params.emplace_back("Background",
39 ThreadPriority::BACKGROUND);
40 constant_worker_pool_params.emplace_back("BackgroundFileIO",
41 ThreadPriority::BACKGROUND);
42 constant_worker_pool_params.emplace_back("Foreground",
43 ThreadPriority::NORMAL);
44 constant_worker_pool_params.emplace_back(
45 "ForegroundFileIO", ThreadPriority::NORMAL,
46 base::SchedulerBackwardCompatibility::INIT_COM_STA);
47 return constant_worker_pool_params;
48 }
49
50 class TaskSchedulerUtilVariationsUtilTest : public testing::Test { 35 class TaskSchedulerUtilVariationsUtilTest : public testing::Test {
51 public: 36 public:
52 TaskSchedulerUtilVariationsUtilTest() : field_trial_list_(nullptr) {} 37 TaskSchedulerUtilVariationsUtilTest() : field_trial_list_(nullptr) {}
53 ~TaskSchedulerUtilVariationsUtilTest() override { 38 ~TaskSchedulerUtilVariationsUtilTest() override {
54 // Ensure that the maps are cleared between tests, since they are stored as 39 // Ensure that the maps are cleared between tests, since they are stored as
55 // process singletons. 40 // process singletons.
56 variations::testing::ClearAllVariationIDs(); 41 variations::testing::ClearAllVariationIDs();
57 variations::testing::ClearAllVariationParams(); 42 variations::testing::ClearAllVariationParams();
58 } 43 }
59 44
60 private: 45 private:
61 base::FieldTrialList field_trial_list_; 46 base::FieldTrialList field_trial_list_;
62 47
63 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerUtilVariationsUtilTest); 48 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerUtilVariationsUtilTest);
64 }; 49 };
65 50
66 } // namespace 51 } // namespace
67 52
68 TEST_F(TaskSchedulerUtilVariationsUtilTest, OrderingParams5) { 53 TEST_F(TaskSchedulerUtilVariationsUtilTest, OrderingParams5) {
69 std::map<std::string, std::string> variation_params; 54 const auto worker_pool_params_a = StringToWorkerPoolParams(
70 variation_params["Background"] = "1;1;1;0;42"; 55 "1;1;1;0;42", SchedulerBackwardCompatibility::DISABLED);
71 variation_params["BackgroundFileIO"] = "2;2;1;0;52"; 56 EXPECT_EQ(StandbyThreadPolicy::ONE,
72 variation_params["Foreground"] = "4;4;1;0;62"; 57 worker_pool_params_a.standby_thread_policy());
73 variation_params["ForegroundFileIO"] = "8;8;1;0;72"; 58 EXPECT_EQ(1U, worker_pool_params_a.max_threads());
59 EXPECT_EQ(base::TimeDelta::FromMilliseconds(42),
60 worker_pool_params_a.suggested_reclaim_time());
61 EXPECT_EQ(base::SchedulerBackwardCompatibility::DISABLED,
62 worker_pool_params_a.backward_compatibility());
74 63
75 auto params_vector = 64 const auto worker_pool_params_b = StringToWorkerPoolParams(
76 GetWorkerPoolParams(GetImmutableWorkerPoolParams(), variation_params); 65 "8;8;1;0;72", SchedulerBackwardCompatibility::ENABLED);
77 ASSERT_EQ(4U, params_vector.size()); 66 EXPECT_EQ(StandbyThreadPolicy::ONE,
78 67 worker_pool_params_b.standby_thread_policy());
79 EXPECT_EQ("Background", params_vector[0].name()); 68 EXPECT_EQ(8U, worker_pool_params_b.max_threads());
80 EXPECT_EQ(ThreadPriority::BACKGROUND, params_vector[0].priority_hint());
81 EXPECT_EQ(StandbyThreadPolicy::ONE, params_vector[0].standby_thread_policy());
82 EXPECT_EQ(1U, params_vector[0].max_threads());
83 EXPECT_EQ(base::TimeDelta::FromMilliseconds(42),
84 params_vector[0].suggested_reclaim_time());
85 EXPECT_EQ(base::SchedulerBackwardCompatibility::DISABLED,
86 params_vector[0].backward_compatibility());
87
88 EXPECT_EQ("BackgroundFileIO", params_vector[1].name());
89 EXPECT_EQ(ThreadPriority::BACKGROUND, params_vector[1].priority_hint());
90 EXPECT_EQ(StandbyThreadPolicy::ONE, params_vector[1].standby_thread_policy());
91 EXPECT_EQ(2U, params_vector[1].max_threads());
92 EXPECT_EQ(base::TimeDelta::FromMilliseconds(52),
93 params_vector[1].suggested_reclaim_time());
94 EXPECT_EQ(base::SchedulerBackwardCompatibility::DISABLED,
95 params_vector[1].backward_compatibility());
96
97 EXPECT_EQ("Foreground", params_vector[2].name());
98 EXPECT_EQ(ThreadPriority::NORMAL, params_vector[2].priority_hint());
99 EXPECT_EQ(StandbyThreadPolicy::ONE, params_vector[2].standby_thread_policy());
100 EXPECT_EQ(4U, params_vector[2].max_threads());
101 EXPECT_EQ(base::TimeDelta::FromMilliseconds(62),
102 params_vector[2].suggested_reclaim_time());
103 EXPECT_EQ(base::SchedulerBackwardCompatibility::DISABLED,
104 params_vector[2].backward_compatibility());
105
106 EXPECT_EQ("ForegroundFileIO", params_vector[3].name());
107 EXPECT_EQ(ThreadPriority::NORMAL, params_vector[3].priority_hint());
108 EXPECT_EQ(StandbyThreadPolicy::ONE, params_vector[3].standby_thread_policy());
109 EXPECT_EQ(8U, params_vector[3].max_threads());
110 EXPECT_EQ(base::TimeDelta::FromMilliseconds(72), 69 EXPECT_EQ(base::TimeDelta::FromMilliseconds(72),
111 params_vector[3].suggested_reclaim_time()); 70 worker_pool_params_b.suggested_reclaim_time());
112 EXPECT_EQ(base::SchedulerBackwardCompatibility::INIT_COM_STA, 71 EXPECT_EQ(base::SchedulerBackwardCompatibility::INIT_COM_STA,
113 params_vector[3].backward_compatibility()); 72 worker_pool_params_b.backward_compatibility());
114 } 73 }
115 74
116 TEST_F(TaskSchedulerUtilVariationsUtilTest, OrderingParams6) { 75 TEST_F(TaskSchedulerUtilVariationsUtilTest, OrderingParams6) {
117 std::map<std::string, std::string> variation_params; 76 const auto worker_pool_params_a = StringToWorkerPoolParams(
118 variation_params["Background"] = "1;1;1;0;42;lazy"; 77 "1;1;1;0;42;lazy", SchedulerBackwardCompatibility::DISABLED);
119 variation_params["BackgroundFileIO"] = "2;2;1;0;52;one"; 78 EXPECT_EQ(StandbyThreadPolicy::LAZY,
120 variation_params["Foreground"] = "4;4;1;0;62;lazy"; 79 worker_pool_params_a.standby_thread_policy());
121 variation_params["ForegroundFileIO"] = "8;8;1;0;72;one"; 80 EXPECT_EQ(1U, worker_pool_params_a.max_threads());
81 EXPECT_EQ(base::TimeDelta::FromMilliseconds(42),
82 worker_pool_params_a.suggested_reclaim_time());
83 EXPECT_EQ(base::SchedulerBackwardCompatibility::DISABLED,
84 worker_pool_params_a.backward_compatibility());
122 85
123 auto params_vector = 86 const auto worker_pool_params_b = StringToWorkerPoolParams(
124 GetWorkerPoolParams(GetImmutableWorkerPoolParams(), variation_params); 87 "8;8;1;0;72;one", SchedulerBackwardCompatibility::ENABLED);
125 ASSERT_EQ(4U, params_vector.size()); 88 EXPECT_EQ(StandbyThreadPolicy::ONE,
126 89 worker_pool_params_b.standby_thread_policy());
127 EXPECT_EQ("Background", params_vector[0].name()); 90 EXPECT_EQ(8U, worker_pool_params_b.max_threads());
128 EXPECT_EQ(ThreadPriority::BACKGROUND, params_vector[0].priority_hint());
129 EXPECT_EQ(StandbyThreadPolicy::LAZY,
130 params_vector[0].standby_thread_policy());
131 EXPECT_EQ(1U, params_vector[0].max_threads());
132 EXPECT_EQ(base::TimeDelta::FromMilliseconds(42),
133 params_vector[0].suggested_reclaim_time());
134 EXPECT_EQ(base::SchedulerBackwardCompatibility::DISABLED,
135 params_vector[0].backward_compatibility());
136
137 EXPECT_EQ("BackgroundFileIO", params_vector[1].name());
138 EXPECT_EQ(ThreadPriority::BACKGROUND, params_vector[1].priority_hint());
139 EXPECT_EQ(StandbyThreadPolicy::ONE, params_vector[1].standby_thread_policy());
140 EXPECT_EQ(2U, params_vector[1].max_threads());
141 EXPECT_EQ(base::TimeDelta::FromMilliseconds(52),
142 params_vector[1].suggested_reclaim_time());
143 EXPECT_EQ(base::SchedulerBackwardCompatibility::DISABLED,
144 params_vector[1].backward_compatibility());
145
146 EXPECT_EQ("Foreground", params_vector[2].name());
147 EXPECT_EQ(ThreadPriority::NORMAL, params_vector[2].priority_hint());
148 EXPECT_EQ(StandbyThreadPolicy::LAZY,
149 params_vector[2].standby_thread_policy());
150 EXPECT_EQ(4U, params_vector[2].max_threads());
151 EXPECT_EQ(base::TimeDelta::FromMilliseconds(62),
152 params_vector[2].suggested_reclaim_time());
153 EXPECT_EQ(base::SchedulerBackwardCompatibility::DISABLED,
154 params_vector[2].backward_compatibility());
155
156 EXPECT_EQ("ForegroundFileIO", params_vector[3].name());
157 EXPECT_EQ(ThreadPriority::NORMAL, params_vector[3].priority_hint());
158 EXPECT_EQ(StandbyThreadPolicy::ONE, params_vector[3].standby_thread_policy());
159 EXPECT_EQ(8U, params_vector[3].max_threads());
160 EXPECT_EQ(base::TimeDelta::FromMilliseconds(72), 91 EXPECT_EQ(base::TimeDelta::FromMilliseconds(72),
161 params_vector[3].suggested_reclaim_time()); 92 worker_pool_params_b.suggested_reclaim_time());
162 EXPECT_EQ(base::SchedulerBackwardCompatibility::INIT_COM_STA, 93 EXPECT_EQ(base::SchedulerBackwardCompatibility::INIT_COM_STA,
163 params_vector[3].backward_compatibility()); 94 worker_pool_params_b.backward_compatibility());
164 }
165
166 TEST_F(TaskSchedulerUtilVariationsUtilTest, NoData) {
167 EXPECT_TRUE(GetWorkerPoolParams(GetImmutableWorkerPoolParams(),
168 std::map<std::string, std::string>())
169 .empty());
170 } 95 }
171 96
172 TEST_F(TaskSchedulerUtilVariationsUtilTest, IncompleteParameters) { 97 TEST_F(TaskSchedulerUtilVariationsUtilTest, IncompleteParameters) {
173 std::map<std::string, std::string> variation_params; 98 EXPECT_FALSE(StringToWorkerPoolParams("1;1;1;0").IsValid());
174 variation_params["Background"] = "1;1;1;0";
175 variation_params["BackgroundFileIO"] = "2;2;1;0";
176 variation_params["Foreground"] = "4;4;1;0";
177 variation_params["ForegroundFileIO"] = "8;8;1;0";
178 EXPECT_TRUE(
179 GetWorkerPoolParams(GetImmutableWorkerPoolParams(), variation_params)
180 .empty());
181 } 99 }
182 100
183 TEST_F(TaskSchedulerUtilVariationsUtilTest, InvalidParameters) { 101 TEST_F(TaskSchedulerUtilVariationsUtilTest, InvalidParameters) {
184 std::map<std::string, std::string> variation_params; 102 EXPECT_FALSE(StringToWorkerPoolParams("a;b;c;d;e").IsValid());
185 variation_params["Background"] = "a;b;c;d;e";
186 variation_params["BackgroundFileIO"] = "a;b;c;d;e";
187 variation_params["Foreground"] = "a;b;c;d;e";
188 variation_params["ForegroundFileIO"] = "a;b;c;d;e";
189 EXPECT_TRUE(
190 GetWorkerPoolParams(GetImmutableWorkerPoolParams(), variation_params)
191 .empty());
192 } 103 }
193 104
194 #if !defined(OS_IOS) 105 #if !defined(OS_IOS)
195 // Verify that AddVariationParamsToCommandLine() serializes BrowserScheduler 106 // Verify that AddVariationParamsToCommandLine() serializes BrowserScheduler
196 // variation params that start with the specified prefix to the command line and 107 // variation params that start with the specified prefix to the command line and
197 // that GetVariationParamsFromCommandLine() correctly deserializes them. 108 // that GetVariationParamsFromCommandLine() correctly deserializes them.
198 TEST_F(TaskSchedulerUtilVariationsUtilTest, CommandLine) { 109 TEST_F(TaskSchedulerUtilVariationsUtilTest, CommandLine) {
199 std::map<std::string, std::string> in_variation_params; 110 std::map<std::string, std::string> in_variation_params;
200 in_variation_params["PrefixFoo"] = "Foo"; 111 in_variation_params["PrefixFoo"] = "Foo";
201 in_variation_params["PrefixBar"] = "Bar"; 112 in_variation_params["PrefixBar"] = "Bar";
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 168
258 // Verify that GetVariationParamsFromCommandLine() returns an empty map when the 169 // Verify that GetVariationParamsFromCommandLine() returns an empty map when the
259 // command line doesn't have a --task-scheduler-variation-params switch. 170 // command line doesn't have a --task-scheduler-variation-params switch.
260 TEST_F(TaskSchedulerUtilVariationsUtilTest, CommandLineNoSwitch) { 171 TEST_F(TaskSchedulerUtilVariationsUtilTest, CommandLineNoSwitch) {
261 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 172 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
262 EXPECT_TRUE(GetVariationParamsFromCommandLine(command_line).empty()); 173 EXPECT_TRUE(GetVariationParamsFromCommandLine(command_line).empty());
263 } 174 }
264 #endif // !defined(OS_IOS) 175 #endif // !defined(OS_IOS)
265 176
266 } // namespace task_scheduler_util 177 } // namespace task_scheduler_util
OLDNEW
« no previous file with comments | « components/task_scheduler_util/common/variations_util.cc ('k') | components/task_scheduler_util/renderer/initialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698