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

Side by Side Diff: base/threading/simple_thread_unittest.cc

Issue 2032603002: Migrate WaitableEvent to enum-based constructor in base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WEvent_enums
Patch Set: undo incorrect template change Created 4 years, 6 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/threading/simple_thread.cc ('k') | base/threading/thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/atomic_sequence_num.h" 5 #include "base/atomic_sequence_num.h"
6 #include "base/strings/string_number_conversions.h" 6 #include "base/strings/string_number_conversions.h"
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "base/threading/simple_thread.h" 8 #include "base/threading/simple_thread.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 EXPECT_FALSE(thread.HasBeenJoined()); 88 EXPECT_FALSE(thread.HasBeenJoined());
89 89
90 thread.Join(); 90 thread.Join();
91 EXPECT_TRUE(thread.HasBeenStarted()); 91 EXPECT_TRUE(thread.HasBeenStarted());
92 EXPECT_TRUE(thread.HasBeenJoined()); 92 EXPECT_TRUE(thread.HasBeenJoined());
93 EXPECT_EQ(7, stack_int); 93 EXPECT_EQ(7, stack_int);
94 } 94 }
95 95
96 TEST(SimpleThreadTest, WaitForEvent) { 96 TEST(SimpleThreadTest, WaitForEvent) {
97 // Create a thread, and wait for it to signal us. 97 // Create a thread, and wait for it to signal us.
98 WaitableEvent event(true, false); 98 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL,
99 WaitableEvent::InitialState::NOT_SIGNALED);
99 100
100 WaitEventRunner runner(&event); 101 WaitEventRunner runner(&event);
101 DelegateSimpleThread thread(&runner, "event_waiter"); 102 DelegateSimpleThread thread(&runner, "event_waiter");
102 103
103 EXPECT_FALSE(event.IsSignaled()); 104 EXPECT_FALSE(event.IsSignaled());
104 thread.Start(); 105 thread.Start();
105 event.Wait(); 106 event.Wait();
106 EXPECT_TRUE(event.IsSignaled()); 107 EXPECT_TRUE(event.IsSignaled());
107 thread.Join(); 108 thread.Join();
108 } 109 }
109 110
110 TEST(SimpleThreadTest, NamedWithOptions) { 111 TEST(SimpleThreadTest, NamedWithOptions) {
111 WaitableEvent event(true, false); 112 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL,
113 WaitableEvent::InitialState::NOT_SIGNALED);
112 114
113 WaitEventRunner runner(&event); 115 WaitEventRunner runner(&event);
114 SimpleThread::Options options; 116 SimpleThread::Options options;
115 DelegateSimpleThread thread(&runner, "event_waiter", options); 117 DelegateSimpleThread thread(&runner, "event_waiter", options);
116 EXPECT_EQ(thread.name_prefix(), "event_waiter"); 118 EXPECT_EQ(thread.name_prefix(), "event_waiter");
117 EXPECT_FALSE(event.IsSignaled()); 119 EXPECT_FALSE(event.IsSignaled());
118 120
119 thread.Start(); 121 thread.Start();
120 EXPECT_EQ(thread.name_prefix(), "event_waiter"); 122 EXPECT_EQ(thread.name_prefix(), "event_waiter");
121 EXPECT_EQ(thread.name(), 123 EXPECT_EQ(thread.name(),
(...skipping 23 matching lines...) Expand all
145 // Add work while we're running. 147 // Add work while we're running.
146 pool.AddWork(&runner, 300); 148 pool.AddWork(&runner, 300);
147 149
148 pool.JoinAll(); 150 pool.JoinAll();
149 151
150 EXPECT_EQ(seq.GetNext(), 601); 152 EXPECT_EQ(seq.GetNext(), 601);
151 153
152 // We can reuse our pool. Verify that all 10 threads can actually run in 154 // We can reuse our pool. Verify that all 10 threads can actually run in
153 // parallel, so this test will only pass if there are actually 10 threads. 155 // parallel, so this test will only pass if there are actually 10 threads.
154 AtomicSequenceNumber seq2; 156 AtomicSequenceNumber seq2;
155 WaitableEvent event(true, false); 157 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL,
158 WaitableEvent::InitialState::NOT_SIGNALED);
156 // Changing 9 to 10, for example, would cause us JoinAll() to never return. 159 // Changing 9 to 10, for example, would cause us JoinAll() to never return.
157 VerifyPoolRunner verifier(&seq2, 9, &event); 160 VerifyPoolRunner verifier(&seq2, 9, &event);
158 pool.Start(); 161 pool.Start();
159 162
160 pool.AddWork(&verifier, 10); 163 pool.AddWork(&verifier, 10);
161 164
162 pool.JoinAll(); 165 pool.JoinAll();
163 EXPECT_EQ(seq2.GetNext(), 10); 166 EXPECT_EQ(seq2.GetNext(), 10);
164 } 167 }
165 168
166 } // namespace base 169 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/simple_thread.cc ('k') | base/threading/thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698