| OLD | NEW |
| 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 "base/task_scheduler/scheduler_thread_pool_impl.h" | 5 #include "base/task_scheduler/scheduler_thread_pool_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <unordered_set> | 10 #include <unordered_set> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 DISALLOW_COPY_AND_ASSIGN(TestDelayedTaskManager); | 56 DISALLOW_COPY_AND_ASSIGN(TestDelayedTaskManager); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 class TaskSchedulerThreadPoolImplTest | 59 class TaskSchedulerThreadPoolImplTest |
| 60 : public testing::TestWithParam<ExecutionMode> { | 60 : public testing::TestWithParam<ExecutionMode> { |
| 61 protected: | 61 protected: |
| 62 TaskSchedulerThreadPoolImplTest() = default; | 62 TaskSchedulerThreadPoolImplTest() = default; |
| 63 | 63 |
| 64 void SetUp() override { | 64 void SetUp() override { |
| 65 thread_pool_ = SchedulerThreadPoolImpl::Create( | 65 thread_pool_ = SchedulerThreadPoolImpl::Create( |
| 66 ThreadPriority::NORMAL, kNumThreadsInThreadPool, IORestriction::ALLOWED, | 66 "TestThreadPoolWithFileIO", ThreadPriority::NORMAL, |
| 67 kNumThreadsInThreadPool, IORestriction::ALLOWED, |
| 67 Bind(&TaskSchedulerThreadPoolImplTest::ReEnqueueSequenceCallback, | 68 Bind(&TaskSchedulerThreadPoolImplTest::ReEnqueueSequenceCallback, |
| 68 Unretained(this)), | 69 Unretained(this)), |
| 69 &task_tracker_, &delayed_task_manager_); | 70 &task_tracker_, &delayed_task_manager_); |
| 70 ASSERT_TRUE(thread_pool_); | 71 ASSERT_TRUE(thread_pool_); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void TearDown() override { | 74 void TearDown() override { |
| 74 thread_pool_->WaitForAllWorkerThreadsIdleForTesting(); | 75 thread_pool_->WaitForAllWorkerThreadsIdleForTesting(); |
| 75 thread_pool_->JoinForTesting(); | 76 thread_pool_->JoinForTesting(); |
| 76 } | 77 } |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerThreadPoolImplIORestrictionTest); | 353 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerThreadPoolImplIORestrictionTest); |
| 353 }; | 354 }; |
| 354 | 355 |
| 355 } // namespace | 356 } // namespace |
| 356 | 357 |
| 357 TEST_P(TaskSchedulerThreadPoolImplIORestrictionTest, IORestriction) { | 358 TEST_P(TaskSchedulerThreadPoolImplIORestrictionTest, IORestriction) { |
| 358 TaskTracker task_tracker; | 359 TaskTracker task_tracker; |
| 359 DelayedTaskManager delayed_task_manager(Bind(&DoNothing)); | 360 DelayedTaskManager delayed_task_manager(Bind(&DoNothing)); |
| 360 | 361 |
| 361 auto thread_pool = SchedulerThreadPoolImpl::Create( | 362 auto thread_pool = SchedulerThreadPoolImpl::Create( |
| 362 ThreadPriority::NORMAL, 1U, GetParam(), | 363 "TestThreadPoolWithParam", ThreadPriority::NORMAL, 1U, GetParam(), |
| 363 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker, | 364 Bind(&NotReachedReEnqueueSequenceCallback), &task_tracker, |
| 364 &delayed_task_manager); | 365 &delayed_task_manager); |
| 365 ASSERT_TRUE(thread_pool); | 366 ASSERT_TRUE(thread_pool); |
| 366 | 367 |
| 367 WaitableEvent task_ran(true, false); | 368 WaitableEvent task_ran(true, false); |
| 368 thread_pool->CreateTaskRunnerWithTraits(TaskTraits(), ExecutionMode::PARALLEL) | 369 thread_pool->CreateTaskRunnerWithTraits(TaskTraits(), ExecutionMode::PARALLEL) |
| 369 ->PostTask(FROM_HERE, Bind(&ExpectIORestriction, GetParam(), &task_ran)); | 370 ->PostTask(FROM_HERE, Bind(&ExpectIORestriction, GetParam(), &task_ran)); |
| 370 task_ran.Wait(); | 371 task_ran.Wait(); |
| 371 | 372 |
| 372 thread_pool->JoinForTesting(); | 373 thread_pool->JoinForTesting(); |
| 373 } | 374 } |
| 374 | 375 |
| 375 INSTANTIATE_TEST_CASE_P(IOAllowed, | 376 INSTANTIATE_TEST_CASE_P(IOAllowed, |
| 376 TaskSchedulerThreadPoolImplIORestrictionTest, | 377 TaskSchedulerThreadPoolImplIORestrictionTest, |
| 377 ::testing::Values(IORestriction::ALLOWED)); | 378 ::testing::Values(IORestriction::ALLOWED)); |
| 378 INSTANTIATE_TEST_CASE_P(IODisallowed, | 379 INSTANTIATE_TEST_CASE_P(IODisallowed, |
| 379 TaskSchedulerThreadPoolImplIORestrictionTest, | 380 TaskSchedulerThreadPoolImplIORestrictionTest, |
| 380 ::testing::Values(IORestriction::DISALLOWED)); | 381 ::testing::Values(IORestriction::DISALLOWED)); |
| 381 | 382 |
| 382 } // namespace internal | 383 } // namespace internal |
| 383 } // namespace base | 384 } // namespace base |
| OLD | NEW |