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

Side by Side Diff: base/sequence_checker_unittest.cc

Issue 2869893003: New Sequence/Thread checking API. (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/sequence_checker.h"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 8
7 #include <memory> 9 #include <memory>
8 #include <string> 10 #include <string>
9 11
10 #include "base/bind.h" 12 #include "base/bind.h"
11 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
12 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
13 #include "base/macros.h" 15 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
15 #include "base/sequence_checker_impl.h"
16 #include "base/sequence_token.h" 17 #include "base/sequence_token.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/test/gtest_util.h"
18 #include "base/test/sequenced_worker_pool_owner.h" 20 #include "base/test/sequenced_worker_pool_owner.h"
19 #include "base/threading/simple_thread.h" 21 #include "base/threading/simple_thread.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 23
22 namespace base { 24 namespace base {
23 25
24 namespace { 26 namespace {
25 27
26 constexpr size_t kNumWorkerThreads = 3; 28 constexpr size_t kNumWorkerThreads = 3;
27 29
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 FlushSequencedWorkerPoolForTesting(); 251 FlushSequencedWorkerPoolForTesting();
250 252
251 SequencedWorkerPoolOwner second_pool_owner(kNumWorkerThreads, "test2"); 253 SequencedWorkerPoolOwner second_pool_owner(kNumWorkerThreads, "test2");
252 second_pool_owner.pool()->PostNamedSequencedWorkerTask( 254 second_pool_owner.pool()->PostNamedSequencedWorkerTask(
253 "A", FROM_HERE, 255 "A", FROM_HERE,
254 base::BindOnce(&ExpectNotCalledOnValidSequence, 256 base::BindOnce(&ExpectNotCalledOnValidSequence,
255 base::Unretained(&sequence_checker))); 257 base::Unretained(&sequence_checker)));
256 second_pool_owner.pool()->FlushForTesting(); 258 second_pool_owner.pool()->FlushForTesting();
257 } 259 }
258 260
261 TEST_F(SequenceCheckerTest, Macros) {
262 SEQUENCE_CHECKER(my_sequence_checker);
263
264 PostToSequencedWorkerPool(
265 Bind([](SequenceChecker* sequence_checker) {
266 #if DCHECK_IS_ON()
267 EXPECT_DCHECK_DEATH({ DCHECK_CALLED_ON_VALID_SEQUENCE(*sequence_checker); }) ;
268 #else
269 // Happily no-ops on non-dcheck builds.
270 DCHECK_CALLED_ON_VALID_SEQUENCE(*sequence_checker);
271 #endif
272 }, Unretained(&my_sequence_checker)), "A");
273 FlushSequencedWorkerPoolForTesting();
274
275 DETACH_FROM_SEQUENCE(my_sequence_checker);
276
277 PostToSequencedWorkerPool(
278 Bind([](SequenceChecker* sequence_checker) {
279 // Happily passes after detaching from original sequence.
280 DCHECK_CALLED_ON_VALID_SEQUENCE(*sequence_checker);
281 }, Unretained(&my_sequence_checker)), "A");
282 FlushSequencedWorkerPoolForTesting();
283 }
284
259 } // namespace base 285 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698