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

Side by Side Diff: base/threading/platform_thread_unittest.cc

Issue 1051863003: Turn ThreadPriority enum into an enum class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@setthreadpri
Patch Set: nits Created 5 years, 8 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
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | base/threading/platform_thread_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "base/threading/platform_thread.h" 8 #include "base/threading/platform_thread.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 168 }
169 169
170 namespace { 170 namespace {
171 171
172 const ThreadPriority kThreadPriorityTestValues[] = { 172 const ThreadPriority kThreadPriorityTestValues[] = {
173 // Disable non-normal priority toggling on POSIX as it appears to be broken 173 // Disable non-normal priority toggling on POSIX as it appears to be broken
174 // (http://crbug.com/468793). This is prefered to disabling the tests altogether 174 // (http://crbug.com/468793). This is prefered to disabling the tests altogether
175 // on POSIX as it at least provides coverage for running this code under 175 // on POSIX as it at least provides coverage for running this code under
176 // "normal" priority. 176 // "normal" priority.
177 #if !defined(OS_POSIX) 177 #if !defined(OS_POSIX)
178 kThreadPriority_RealtimeAudio, 178 ThreadPriority::DISPLAY,
179 kThreadPriority_Display, 179 ThreadPriority::REALTIME_AUDIO,
180 kThreadPriority_Background, 180 // Keep BACKGROUND second to last to test backgrounding from other
181 // priorities.
182 ThreadPriority::BACKGROUND,
181 #endif // !defined(OS_POSIX) 183 #endif // !defined(OS_POSIX)
182 // Keep normal last to test unbackgrounding. 184 // Keep NORMAL last to test unbackgrounding.
183 kThreadPriority_Normal 185 ThreadPriority::NORMAL
184 }; 186 };
185 187
186 } // namespace 188 } // namespace
187 189
188 // Test changing another thread's priority. 190 // Test changing another thread's priority.
189 // NOTE: This test is partially disabled on POSIX, see note above and 191 // NOTE: This test is partially disabled on POSIX, see note above and
190 // http://crbug.com/468793. 192 // http://crbug.com/468793.
191 TEST(PlatformThreadTest, ThreadPriorityOtherThread) { 193 TEST(PlatformThreadTest, ThreadPriorityOtherThread) {
192 PlatformThreadHandle current_handle(PlatformThread::CurrentHandle()); 194 PlatformThreadHandle current_handle(PlatformThread::CurrentHandle());
193 195
194 // Confirm that the current thread's priority is as expected. 196 // Confirm that the current thread's priority is as expected.
195 EXPECT_EQ(kThreadPriority_Normal, 197 EXPECT_EQ(ThreadPriority::NORMAL,
196 PlatformThread::GetThreadPriority(current_handle)); 198 PlatformThread::GetThreadPriority(current_handle));
197 199
198 // Create a test thread. 200 // Create a test thread.
199 FunctionTestThread thread; 201 FunctionTestThread thread;
200 PlatformThreadHandle handle; 202 PlatformThreadHandle handle;
201 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); 203 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle));
202 thread.WaitForThreadStart(); 204 thread.WaitForThreadStart();
203 EXPECT_NE(thread.thread_id(), kInvalidThreadId); 205 EXPECT_NE(thread.thread_id(), kInvalidThreadId);
204 EXPECT_NE(thread.thread_id(), PlatformThread::CurrentId()); 206 EXPECT_NE(thread.thread_id(), PlatformThread::CurrentId());
205 207
206 // New threads should get normal priority by default. 208 // New threads should get normal priority by default.
207 EXPECT_EQ(kThreadPriority_Normal, PlatformThread::GetThreadPriority(handle)); 209 EXPECT_EQ(ThreadPriority::NORMAL, PlatformThread::GetThreadPriority(handle));
208 210
209 // Toggle each supported priority on the test thread and confirm it only 211 // Toggle each supported priority on the test thread and confirm it only
210 // affects it (and not the current thread). 212 // affects it (and not the current thread).
211 for (size_t i = 0; i < arraysize(kThreadPriorityTestValues); ++i) { 213 for (size_t i = 0; i < arraysize(kThreadPriorityTestValues); ++i) {
212 SCOPED_TRACE(i); 214 SCOPED_TRACE(i);
213 215
214 // Alter and verify the test thread's priority. 216 // Alter and verify the test thread's priority.
215 PlatformThread::SetThreadPriority(handle, kThreadPriorityTestValues[i]); 217 PlatformThread::SetThreadPriority(handle, kThreadPriorityTestValues[i]);
216 EXPECT_EQ(kThreadPriorityTestValues[i], 218 EXPECT_EQ(kThreadPriorityTestValues[i],
217 PlatformThread::GetThreadPriority(handle)); 219 PlatformThread::GetThreadPriority(handle));
218 220
219 // Make sure the current thread was otherwise unaffected. 221 // Make sure the current thread was otherwise unaffected.
220 EXPECT_EQ(kThreadPriority_Normal, 222 EXPECT_EQ(ThreadPriority::NORMAL,
221 PlatformThread::GetThreadPriority(current_handle)); 223 PlatformThread::GetThreadPriority(current_handle));
222 } 224 }
223 225
224 thread.MarkForTermination(); 226 thread.MarkForTermination();
225 PlatformThread::Join(handle); 227 PlatformThread::Join(handle);
226 } 228 }
227 229
228 // Test changing the current thread's priority (which has different semantics on 230 // Test changing the current thread's priority (which has different semantics on
229 // some platforms). 231 // some platforms).
230 // NOTE: This test is partially disabled on POSIX, see note above and 232 // NOTE: This test is partially disabled on POSIX, see note above and
231 // http://crbug.com/468793. 233 // http://crbug.com/468793.
232 TEST(PlatformThreadTest, ThreadPriorityCurrentThread) { 234 TEST(PlatformThreadTest, ThreadPriorityCurrentThread) {
233 PlatformThreadHandle current_handle(PlatformThread::CurrentHandle()); 235 PlatformThreadHandle current_handle(PlatformThread::CurrentHandle());
234 236
235 // Confirm that the current thread's priority is as expected. 237 // Confirm that the current thread's priority is as expected.
236 EXPECT_EQ(kThreadPriority_Normal, 238 EXPECT_EQ(ThreadPriority::NORMAL,
237 PlatformThread::GetThreadPriority(current_handle)); 239 PlatformThread::GetThreadPriority(current_handle));
238 240
239 // Create a test thread for verification purposes only. 241 // Create a test thread for verification purposes only.
240 FunctionTestThread thread; 242 FunctionTestThread thread;
241 PlatformThreadHandle handle; 243 PlatformThreadHandle handle;
242 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); 244 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle));
243 thread.WaitForThreadStart(); 245 thread.WaitForThreadStart();
244 EXPECT_NE(thread.thread_id(), kInvalidThreadId); 246 EXPECT_NE(thread.thread_id(), kInvalidThreadId);
245 EXPECT_NE(thread.thread_id(), PlatformThread::CurrentId()); 247 EXPECT_NE(thread.thread_id(), PlatformThread::CurrentId());
246 248
247 // Confirm that the new thread's priority is as expected. 249 // Confirm that the new thread's priority is as expected.
248 EXPECT_EQ(kThreadPriority_Normal, PlatformThread::GetThreadPriority(handle)); 250 EXPECT_EQ(ThreadPriority::NORMAL, PlatformThread::GetThreadPriority(handle));
249 251
250 // Toggle each supported priority on the current thread and confirm it only 252 // Toggle each supported priority on the current thread and confirm it only
251 // affects it (and not the test thread). 253 // affects it (and not the test thread).
252 for (size_t i = 0; i < arraysize(kThreadPriorityTestValues); ++i) { 254 for (size_t i = 0; i < arraysize(kThreadPriorityTestValues); ++i) {
253 SCOPED_TRACE(i); 255 SCOPED_TRACE(i);
254 256
255 // Alter and verify the current thread's priority. 257 // Alter and verify the current thread's priority.
256 PlatformThread::SetThreadPriority(current_handle, 258 PlatformThread::SetThreadPriority(current_handle,
257 kThreadPriorityTestValues[i]); 259 kThreadPriorityTestValues[i]);
258 EXPECT_EQ(kThreadPriorityTestValues[i], 260 EXPECT_EQ(kThreadPriorityTestValues[i],
259 PlatformThread::GetThreadPriority(current_handle)); 261 PlatformThread::GetThreadPriority(current_handle));
260 262
261 // Make sure the test thread was otherwise unaffected. 263 // Make sure the test thread was otherwise unaffected.
262 EXPECT_EQ(kThreadPriority_Normal, 264 EXPECT_EQ(ThreadPriority::NORMAL,
263 PlatformThread::GetThreadPriority(handle)); 265 PlatformThread::GetThreadPriority(handle));
264 } 266 }
265 267
266 // Restore current thread priority for follow-up tests. 268 // Restore current thread priority for follow-up tests.
267 PlatformThread::SetThreadPriority(current_handle, kThreadPriority_Normal); 269 PlatformThread::SetThreadPriority(current_handle, ThreadPriority::NORMAL);
268 270
269 thread.MarkForTermination(); 271 thread.MarkForTermination();
270 PlatformThread::Join(handle); 272 PlatformThread::Join(handle);
271 } 273 }
272 274
273 } // namespace base 275 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | base/threading/platform_thread_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698