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