| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/scheduler/base/work_queue.h" | 5 #include "platform/scheduler/base/work_queue.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | |
| 10 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 11 #include "platform/scheduler/base/real_time_domain.h" | 10 #include "platform/scheduler/base/real_time_domain.h" |
| 12 #include "platform/scheduler/base/task_queue_impl.h" | 11 #include "platform/scheduler/base/task_queue_impl.h" |
| 13 #include "platform/scheduler/base/work_queue_sets.h" | 12 #include "platform/scheduler/base/work_queue_sets.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 15 | 14 |
| 16 namespace blink { | 15 namespace blink { |
| 17 namespace scheduler { | 16 namespace scheduler { |
| 18 namespace internal { | 17 namespace internal { |
| 19 namespace { | |
| 20 void NopTask() {} | |
| 21 } | |
| 22 | 18 |
| 23 class WorkQueueTest : public testing::Test { | 19 class WorkQueueTest : public testing::Test { |
| 24 public: | 20 public: |
| 25 void SetUp() override { | 21 void SetUp() override { |
| 26 time_domain_.reset(new RealTimeDomain("")); | 22 time_domain_.reset(new RealTimeDomain("")); |
| 27 task_queue_ = make_scoped_refptr(new TaskQueueImpl( | 23 task_queue_ = make_scoped_refptr(new TaskQueueImpl( |
| 28 nullptr, time_domain_.get(), TaskQueue::Spec("fake"), "", "")); | 24 nullptr, time_domain_.get(), TaskQueue::Spec("fake"), "", "")); |
| 29 | 25 |
| 30 work_queue_.reset(new WorkQueue(task_queue_.get(), "test")); | 26 work_queue_.reset( |
| 27 new WorkQueue(task_queue_.get(), "test", |
| 28 TaskQueueImpl::Task::EnqueueOrderComparatorFn)); |
| 31 work_queue_sets_.reset(new WorkQueueSets(1, "test")); | 29 work_queue_sets_.reset(new WorkQueueSets(1, "test")); |
| 32 work_queue_sets_->AddQueue(work_queue_.get(), 0); | 30 work_queue_sets_->AddQueue(work_queue_.get(), 0); |
| 33 | 31 |
| 34 incoming_queue_.reset(new std::queue<TaskQueueImpl::Task>()); | 32 incoming_queue_.reset(new TaskQueueImpl::ComparatorQueue( |
| 33 TaskQueueImpl::Task::EnqueueOrderComparatorFn)); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void TearDown() override { work_queue_sets_->RemoveQueue(work_queue_.get()); } | 36 void TearDown() override { work_queue_sets_->RemoveQueue(work_queue_.get()); } |
| 38 | 37 |
| 39 protected: | 38 protected: |
| 40 TaskQueueImpl::Task FakeTaskWithEnqueueOrder(int enqueue_order) { | 39 TaskQueueImpl::Task FakeTaskWithEnqueueOrder(int enqueue_order) { |
| 41 TaskQueueImpl::Task fake_task(FROM_HERE, base::Bind(&NopTask), | 40 TaskQueueImpl::Task fake_task(FROM_HERE, base::Closure(), base::TimeTicks(), |
| 42 base::TimeTicks(), 0, true); | 41 0, true); |
| 43 fake_task.set_enqueue_order(enqueue_order); | 42 fake_task.set_enqueue_order(enqueue_order); |
| 44 return fake_task; | 43 return fake_task; |
| 45 } | 44 } |
| 46 | 45 |
| 47 std::unique_ptr<RealTimeDomain> time_domain_; | 46 std::unique_ptr<RealTimeDomain> time_domain_; |
| 48 scoped_refptr<TaskQueueImpl> task_queue_; | 47 scoped_refptr<TaskQueueImpl> task_queue_; |
| 49 std::unique_ptr<WorkQueue> work_queue_; | 48 std::unique_ptr<WorkQueue> work_queue_; |
| 50 std::unique_ptr<WorkQueueSets> work_queue_sets_; | 49 std::unique_ptr<WorkQueueSets> work_queue_sets_; |
| 51 std::unique_ptr<std::queue<TaskQueueImpl::Task>> incoming_queue_; | 50 std::unique_ptr<TaskQueueImpl::ComparatorQueue> incoming_queue_; |
| 52 }; | 51 }; |
| 53 | 52 |
| 54 TEST_F(WorkQueueTest, Empty) { | 53 TEST_F(WorkQueueTest, Empty) { |
| 55 EXPECT_TRUE(work_queue_->Empty()); | 54 EXPECT_TRUE(work_queue_->Empty()); |
| 56 work_queue_->Push(FakeTaskWithEnqueueOrder(1)); | 55 work_queue_->Push(FakeTaskWithEnqueueOrder(1)); |
| 57 EXPECT_FALSE(work_queue_->Empty()); | 56 EXPECT_FALSE(work_queue_->Empty()); |
| 58 } | 57 } |
| 59 | 58 |
| 60 TEST_F(WorkQueueTest, Empty_IgnoresFences) { | 59 TEST_F(WorkQueueTest, Empty_IgnoresFences) { |
| 61 work_queue_->Push(FakeTaskWithEnqueueOrder(1)); | 60 work_queue_->Push(FakeTaskWithEnqueueOrder(1)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 TEST_F(WorkQueueTest, PushAfterFenceHit) { | 115 TEST_F(WorkQueueTest, PushAfterFenceHit) { |
| 117 work_queue_->InsertFence(1); | 116 work_queue_->InsertFence(1); |
| 118 WorkQueue* work_queue; | 117 WorkQueue* work_queue; |
| 119 EXPECT_FALSE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); | 118 EXPECT_FALSE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); |
| 120 | 119 |
| 121 work_queue_->Push(FakeTaskWithEnqueueOrder(2)); | 120 work_queue_->Push(FakeTaskWithEnqueueOrder(2)); |
| 122 EXPECT_FALSE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); | 121 EXPECT_FALSE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); |
| 123 } | 122 } |
| 124 | 123 |
| 125 TEST_F(WorkQueueTest, SwapLocked) { | 124 TEST_F(WorkQueueTest, SwapLocked) { |
| 126 incoming_queue_->push(FakeTaskWithEnqueueOrder(2)); | 125 incoming_queue_->insert(FakeTaskWithEnqueueOrder(2)); |
| 127 incoming_queue_->push(FakeTaskWithEnqueueOrder(3)); | 126 incoming_queue_->insert(FakeTaskWithEnqueueOrder(3)); |
| 128 incoming_queue_->push(FakeTaskWithEnqueueOrder(4)); | 127 incoming_queue_->insert(FakeTaskWithEnqueueOrder(4)); |
| 129 | 128 |
| 130 WorkQueue* work_queue; | 129 WorkQueue* work_queue; |
| 131 EXPECT_FALSE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); | 130 EXPECT_FALSE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); |
| 132 EXPECT_TRUE(work_queue_->Empty()); | 131 EXPECT_TRUE(work_queue_->Empty()); |
| 133 work_queue_->SwapLocked(*incoming_queue_.get()); | 132 work_queue_->SwapLocked(*incoming_queue_.get()); |
| 134 | 133 |
| 135 EXPECT_TRUE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); | 134 EXPECT_TRUE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); |
| 136 EXPECT_FALSE(work_queue_->Empty()); | 135 EXPECT_FALSE(work_queue_->Empty()); |
| 137 EXPECT_TRUE(incoming_queue_->empty()); | 136 EXPECT_TRUE(incoming_queue_->empty()); |
| 138 | 137 |
| 139 ASSERT_NE(nullptr, work_queue_->GetFrontTask()); | 138 ASSERT_NE(nullptr, work_queue_->GetFrontTask()); |
| 140 EXPECT_EQ(2ull, work_queue_->GetFrontTask()->enqueue_order()); | 139 EXPECT_EQ(2ull, work_queue_->GetFrontTask()->enqueue_order()); |
| 141 | 140 |
| 142 ASSERT_NE(nullptr, work_queue_->GetBackTask()); | 141 ASSERT_NE(nullptr, work_queue_->GetBackTask()); |
| 143 EXPECT_EQ(4ull, work_queue_->GetBackTask()->enqueue_order()); | 142 EXPECT_EQ(4ull, work_queue_->GetBackTask()->enqueue_order()); |
| 144 } | 143 } |
| 145 | 144 |
| 146 TEST_F(WorkQueueTest, SwapLockedAfterFenceHit) { | 145 TEST_F(WorkQueueTest, SwapLockedAfterFenceHit) { |
| 147 work_queue_->InsertFence(1); | 146 work_queue_->InsertFence(1); |
| 148 incoming_queue_->push(FakeTaskWithEnqueueOrder(2)); | 147 incoming_queue_->insert(FakeTaskWithEnqueueOrder(2)); |
| 149 incoming_queue_->push(FakeTaskWithEnqueueOrder(3)); | 148 incoming_queue_->insert(FakeTaskWithEnqueueOrder(3)); |
| 150 incoming_queue_->push(FakeTaskWithEnqueueOrder(4)); | 149 incoming_queue_->insert(FakeTaskWithEnqueueOrder(4)); |
| 151 | 150 |
| 152 WorkQueue* work_queue; | 151 WorkQueue* work_queue; |
| 153 EXPECT_FALSE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); | 152 EXPECT_FALSE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); |
| 154 EXPECT_TRUE(work_queue_->Empty()); | 153 EXPECT_TRUE(work_queue_->Empty()); |
| 155 work_queue_->SwapLocked(*incoming_queue_.get()); | 154 work_queue_->SwapLocked(*incoming_queue_.get()); |
| 156 | 155 |
| 157 EXPECT_FALSE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); | 156 EXPECT_FALSE(work_queue_sets_->GetOldestQueueInSet(0, &work_queue)); |
| 158 EXPECT_FALSE(work_queue_->Empty()); | 157 EXPECT_FALSE(work_queue_->Empty()); |
| 159 EXPECT_TRUE(incoming_queue_->empty()); | 158 EXPECT_TRUE(incoming_queue_->empty()); |
| 160 | 159 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 EXPECT_EQ(1ull, work_queue_->TakeTaskFromWorkQueue().enqueue_order()); | 353 EXPECT_EQ(1ull, work_queue_->TakeTaskFromWorkQueue().enqueue_order()); |
| 355 EXPECT_TRUE(work_queue_->BlockedByFence()); | 354 EXPECT_TRUE(work_queue_->BlockedByFence()); |
| 356 | 355 |
| 357 EXPECT_TRUE(work_queue_->InsertFence(4)); | 356 EXPECT_TRUE(work_queue_->InsertFence(4)); |
| 358 EXPECT_FALSE(work_queue_->BlockedByFence()); | 357 EXPECT_FALSE(work_queue_->BlockedByFence()); |
| 359 } | 358 } |
| 360 | 359 |
| 361 } // namespace internal | 360 } // namespace internal |
| 362 } // namespace scheduler | 361 } // namespace scheduler |
| 363 } // namespace blink | 362 } // namespace blink |
| OLD | NEW |