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

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: CR gab #20 Created 4 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
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 26 matching lines...) Expand all
37 worker_thread_ = SchedulerWorkerThread::Create( 37 worker_thread_ = SchedulerWorkerThread::Create(
38 ThreadPriority::NORMAL, 38 ThreadPriority::NORMAL,
39 WrapUnique(new TestSchedulerWorkerThreadDelegate(this)), 39 WrapUnique(new TestSchedulerWorkerThreadDelegate(this)),
40 &task_tracker_); 40 &task_tracker_);
41 ASSERT_TRUE(worker_thread_); 41 ASSERT_TRUE(worker_thread_);
42 main_entry_called_.Wait(); 42 main_entry_called_.Wait();
43 } 43 }
44 44
45 void TearDown() override { 45 void TearDown() override {
46 worker_thread_->JoinForTesting(); 46 worker_thread_->JoinForTesting();
47
48 {
49 AutoSchedulerLock auto_lock(main_entry_worker_thread_lock_);
50 EXPECT_EQ(worker_thread_.get(), main_entry_worker_thread_);
51 }
47 } 52 }
48 53
49 size_t TasksPerSequence() const { return GetParam(); } 54 size_t TasksPerSequence() const { return GetParam(); }
50 55
51 // Wait until GetWork() has been called |num_get_work| times. 56 // Wait until GetWork() has been called |num_get_work| times.
52 void WaitForNumGetWork(size_t num_get_work) { 57 void WaitForNumGetWork(size_t num_get_work) {
53 AutoSchedulerLock auto_lock(lock_); 58 AutoSchedulerLock auto_lock(lock_);
54 while (num_get_work_ < num_get_work) 59 while (num_get_work_ < num_get_work)
55 num_get_work_cv_->Wait(); 60 num_get_work_cv_->Wait();
56 } 61 }
(...skipping 27 matching lines...) Expand all
84 std::unique_ptr<SchedulerWorkerThread> worker_thread_; 89 std::unique_ptr<SchedulerWorkerThread> worker_thread_;
85 90
86 private: 91 private:
87 class TestSchedulerWorkerThreadDelegate 92 class TestSchedulerWorkerThreadDelegate
88 : public SchedulerWorkerThread::Delegate { 93 : public SchedulerWorkerThread::Delegate {
89 public: 94 public:
90 TestSchedulerWorkerThreadDelegate(TaskSchedulerWorkerThreadTest* outer) 95 TestSchedulerWorkerThreadDelegate(TaskSchedulerWorkerThreadTest* outer)
91 : outer_(outer) {} 96 : outer_(outer) {}
92 97
93 // SchedulerWorkerThread::Delegate: 98 // SchedulerWorkerThread::Delegate:
94 void OnMainEntry() override { 99 void OnMainEntry(SchedulerWorkerThread* worker_thread) override {
100 {
101 AutoSchedulerLock auto_lock(outer_->main_entry_worker_thread_lock_);
102 outer_->main_entry_worker_thread_ = worker_thread;
gab 2016/04/26 11:46:27 Why can't this directly compare to |worker_thread_
fdoray 2016/04/26 14:56:47 OnMainEntry() may be called before |worker_thread_
103 }
104
95 // Without synchronization, OnMainEntry() could be called twice without 105 // Without synchronization, OnMainEntry() could be called twice without
96 // generating an error. 106 // generating an error.
97 AutoSchedulerLock auto_lock(outer_->lock_); 107 AutoSchedulerLock auto_lock(outer_->lock_);
98 EXPECT_FALSE(outer_->main_entry_called_.IsSignaled()); 108 EXPECT_FALSE(outer_->main_entry_called_.IsSignaled());
99 outer_->main_entry_called_.Signal(); 109 outer_->main_entry_called_.Signal();
100 } 110 }
101 111
102 scoped_refptr<Sequence> GetWork( 112 scoped_refptr<Sequence> GetWork(
103 SchedulerWorkerThread* worker_thread) override { 113 SchedulerWorkerThread* worker_thread) override {
104 EXPECT_EQ(outer_->worker_thread_.get(), worker_thread); 114 EXPECT_EQ(outer_->worker_thread_.get(), worker_thread);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 203
194 // Sequences created by GetWork(). 204 // Sequences created by GetWork().
195 std::vector<scoped_refptr<Sequence>> created_sequences_; 205 std::vector<scoped_refptr<Sequence>> created_sequences_;
196 206
197 // Sequences passed to EnqueueSequence(). 207 // Sequences passed to EnqueueSequence().
198 std::vector<scoped_refptr<Sequence>> re_enqueued_sequences_; 208 std::vector<scoped_refptr<Sequence>> re_enqueued_sequences_;
199 209
200 // Number of times that RunTaskCallback() has been called. 210 // Number of times that RunTaskCallback() has been called.
201 size_t num_run_tasks_ = 0; 211 size_t num_run_tasks_ = 0;
202 212
213 // Synchronizes access to |main_entry_worker_thread_|.
214 SchedulerLock main_entry_worker_thread_lock_;
215
216 // The worker thread argument passed to OnMainEntry().
217 SchedulerWorkerThread* main_entry_worker_thread_ = nullptr;
218
203 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerThreadTest); 219 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerThreadTest);
204 }; 220 };
205 221
206 // Verify that when GetWork() continuously returns Sequences, all Tasks in these 222 // Verify that when GetWork() continuously returns Sequences, all Tasks in these
207 // Sequences run successfully. The test wakes up the SchedulerWorkerThread once. 223 // Sequences run successfully. The test wakes up the SchedulerWorkerThread once.
208 TEST_P(TaskSchedulerWorkerThreadTest, ContinuousWork) { 224 TEST_P(TaskSchedulerWorkerThreadTest, ContinuousWork) {
209 // Set GetWork() to return |kNumSequencesPerTest| Sequences before starting to 225 // Set GetWork() to return |kNumSequencesPerTest| Sequences before starting to
210 // return nullptr. 226 // return nullptr.
211 SetNumSequencesToCreate(kNumSequencesPerTest); 227 SetNumSequencesToCreate(kNumSequencesPerTest);
212 228
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 INSTANTIATE_TEST_CASE_P(OneTaskPerSequence, 283 INSTANTIATE_TEST_CASE_P(OneTaskPerSequence,
268 TaskSchedulerWorkerThreadTest, 284 TaskSchedulerWorkerThreadTest,
269 ::testing::Values(1)); 285 ::testing::Values(1));
270 INSTANTIATE_TEST_CASE_P(TwoTasksPerSequence, 286 INSTANTIATE_TEST_CASE_P(TwoTasksPerSequence,
271 TaskSchedulerWorkerThreadTest, 287 TaskSchedulerWorkerThreadTest,
272 ::testing::Values(2)); 288 ::testing::Values(2));
273 289
274 } // namespace 290 } // namespace
275 } // namespace internal 291 } // namespace internal
276 } // namespace base 292 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698