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

Side by Side Diff: base/task_scheduler/scheduler_worker_thread_unittest.cc

Issue 1876363004: TaskScheduler [11] Support ExecutionMode::SINGLE_THREADED. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@8_delayed
Patch Set: add #include <algorithm> Created 4 years, 7 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/task_scheduler/scheduler_worker_thread_stack_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/task_scheduler/scheduler_worker_thread.h" 5 #include "base/task_scheduler/scheduler_worker_thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 13 matching lines...) Expand all
24 namespace internal { 24 namespace internal {
25 namespace { 25 namespace {
26 26
27 const size_t kNumSequencesPerTest = 150; 27 const size_t kNumSequencesPerTest = 150;
28 28
29 // The test parameter is the number of Tasks per Sequence returned by GetWork(). 29 // The test parameter is the number of Tasks per Sequence returned by GetWork().
30 class TaskSchedulerWorkerThreadTest : public testing::TestWithParam<size_t> { 30 class TaskSchedulerWorkerThreadTest : public testing::TestWithParam<size_t> {
31 protected: 31 protected:
32 TaskSchedulerWorkerThreadTest() 32 TaskSchedulerWorkerThreadTest()
33 : main_entry_called_(true, false), 33 : main_entry_called_(true, false),
34 num_get_work_cv_(lock_.CreateConditionVariable()) {} 34 num_get_work_cv_(lock_.CreateConditionVariable()),
35 worker_thread_set_(true, false) {}
35 36
36 void SetUp() override { 37 void SetUp() override {
37 worker_thread_ = SchedulerWorkerThread::Create( 38 worker_thread_ = SchedulerWorkerThread::Create(
38 ThreadPriority::NORMAL, 39 ThreadPriority::NORMAL,
39 WrapUnique(new TestSchedulerWorkerThreadDelegate(this)), 40 WrapUnique(new TestSchedulerWorkerThreadDelegate(this)),
40 &task_tracker_); 41 &task_tracker_);
41 ASSERT_TRUE(worker_thread_); 42 ASSERT_TRUE(worker_thread_);
43 worker_thread_set_.Signal();
42 main_entry_called_.Wait(); 44 main_entry_called_.Wait();
43 } 45 }
44 46
45 void TearDown() override { 47 void TearDown() override {
46 worker_thread_->JoinForTesting(); 48 worker_thread_->JoinForTesting();
47 } 49 }
48 50
49 size_t TasksPerSequence() const { return GetParam(); } 51 size_t TasksPerSequence() const { return GetParam(); }
50 52
51 // Wait until GetWork() has been called |num_get_work| times. 53 // Wait until GetWork() has been called |num_get_work| times.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 std::unique_ptr<SchedulerWorkerThread> worker_thread_; 86 std::unique_ptr<SchedulerWorkerThread> worker_thread_;
85 87
86 private: 88 private:
87 class TestSchedulerWorkerThreadDelegate 89 class TestSchedulerWorkerThreadDelegate
88 : public SchedulerWorkerThread::Delegate { 90 : public SchedulerWorkerThread::Delegate {
89 public: 91 public:
90 TestSchedulerWorkerThreadDelegate(TaskSchedulerWorkerThreadTest* outer) 92 TestSchedulerWorkerThreadDelegate(TaskSchedulerWorkerThreadTest* outer)
91 : outer_(outer) {} 93 : outer_(outer) {}
92 94
93 // SchedulerWorkerThread::Delegate: 95 // SchedulerWorkerThread::Delegate:
94 void OnMainEntry() override { 96 void OnMainEntry(SchedulerWorkerThread* worker_thread) override {
97 outer_->worker_thread_set_.Wait();
98 EXPECT_EQ(outer_->worker_thread_.get(), worker_thread);
99
95 // Without synchronization, OnMainEntry() could be called twice without 100 // Without synchronization, OnMainEntry() could be called twice without
96 // generating an error. 101 // generating an error.
97 AutoSchedulerLock auto_lock(outer_->lock_); 102 AutoSchedulerLock auto_lock(outer_->lock_);
98 EXPECT_FALSE(outer_->main_entry_called_.IsSignaled()); 103 EXPECT_FALSE(outer_->main_entry_called_.IsSignaled());
99 outer_->main_entry_called_.Signal(); 104 outer_->main_entry_called_.Signal();
100 } 105 }
101 106
102 scoped_refptr<Sequence> GetWork( 107 scoped_refptr<Sequence> GetWork(
103 SchedulerWorkerThread* worker_thread) override { 108 SchedulerWorkerThread* worker_thread) override {
104 EXPECT_EQ(outer_->worker_thread_.get(), worker_thread); 109 EXPECT_EQ(outer_->worker_thread_.get(), worker_thread);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 198
194 // Sequences created by GetWork(). 199 // Sequences created by GetWork().
195 std::vector<scoped_refptr<Sequence>> created_sequences_; 200 std::vector<scoped_refptr<Sequence>> created_sequences_;
196 201
197 // Sequences passed to EnqueueSequence(). 202 // Sequences passed to EnqueueSequence().
198 std::vector<scoped_refptr<Sequence>> re_enqueued_sequences_; 203 std::vector<scoped_refptr<Sequence>> re_enqueued_sequences_;
199 204
200 // Number of times that RunTaskCallback() has been called. 205 // Number of times that RunTaskCallback() has been called.
201 size_t num_run_tasks_ = 0; 206 size_t num_run_tasks_ = 0;
202 207
208 // Signaled after |worker_thread_| is set.
209 WaitableEvent worker_thread_set_;
210
203 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerThreadTest); 211 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerThreadTest);
204 }; 212 };
205 213
206 // Verify that when GetWork() continuously returns Sequences, all Tasks in these 214 // Verify that when GetWork() continuously returns Sequences, all Tasks in these
207 // Sequences run successfully. The test wakes up the SchedulerWorkerThread once. 215 // Sequences run successfully. The test wakes up the SchedulerWorkerThread once.
208 TEST_P(TaskSchedulerWorkerThreadTest, ContinuousWork) { 216 TEST_P(TaskSchedulerWorkerThreadTest, ContinuousWork) {
209 // Set GetWork() to return |kNumSequencesPerTest| Sequences before starting to 217 // Set GetWork() to return |kNumSequencesPerTest| Sequences before starting to
210 // return nullptr. 218 // return nullptr.
211 SetNumSequencesToCreate(kNumSequencesPerTest); 219 SetNumSequencesToCreate(kNumSequencesPerTest);
212 220
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 INSTANTIATE_TEST_CASE_P(OneTaskPerSequence, 275 INSTANTIATE_TEST_CASE_P(OneTaskPerSequence,
268 TaskSchedulerWorkerThreadTest, 276 TaskSchedulerWorkerThreadTest,
269 ::testing::Values(1)); 277 ::testing::Values(1));
270 INSTANTIATE_TEST_CASE_P(TwoTasksPerSequence, 278 INSTANTIATE_TEST_CASE_P(TwoTasksPerSequence,
271 TaskSchedulerWorkerThreadTest, 279 TaskSchedulerWorkerThreadTest,
272 ::testing::Values(2)); 280 ::testing::Values(2));
273 281
274 } // namespace 282 } // namespace
275 } // namespace internal 283 } // namespace internal
276 } // namespace base 284 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker_thread_stack_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698