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

Side by Side Diff: base/tools_sanity_unittest.cc

Issue 9055001: Change code in base (primarily unit tests) to use Sleep(TimeDelta). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Qualify windows Sleep calls to go through PlatformThread. Created 8 years, 11 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/timer_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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file contains intentional memory errors, some of which may lead to 5 // This file contains intentional memory errors, some of which may lead to
6 // crashes if the test is ran without special memory testing tools. We use these 6 // crashes if the test is ran without special memory testing tools. We use these
7 // errors to verify the sanity of the tools. 7 // errors to verify the sanity of the tools.
8 8
9 #include "base/atomicops.h" 9 #include "base/atomicops.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 class TOOLS_SANITY_TEST_CONCURRENT_THREAD : public PlatformThread::Delegate { 163 class TOOLS_SANITY_TEST_CONCURRENT_THREAD : public PlatformThread::Delegate {
164 public: 164 public:
165 explicit TOOLS_SANITY_TEST_CONCURRENT_THREAD(bool *value) : value_(value) {} 165 explicit TOOLS_SANITY_TEST_CONCURRENT_THREAD(bool *value) : value_(value) {}
166 ~TOOLS_SANITY_TEST_CONCURRENT_THREAD() {} 166 ~TOOLS_SANITY_TEST_CONCURRENT_THREAD() {}
167 void ThreadMain() { 167 void ThreadMain() {
168 *value_ = true; 168 *value_ = true;
169 169
170 // Sleep for a few milliseconds so the two threads are more likely to live 170 // Sleep for a few milliseconds so the two threads are more likely to live
171 // simultaneously. Otherwise we may miss the report due to mutex 171 // simultaneously. Otherwise we may miss the report due to mutex
172 // lock/unlock's inside thread creation code in pure-happens-before mode... 172 // lock/unlock's inside thread creation code in pure-happens-before mode...
173 PlatformThread::Sleep(100); 173 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100));
174 } 174 }
175 private: 175 private:
176 bool *value_; 176 bool *value_;
177 }; 177 };
178 178
179 class ReleaseStoreThread : public PlatformThread::Delegate { 179 class ReleaseStoreThread : public PlatformThread::Delegate {
180 public: 180 public:
181 explicit ReleaseStoreThread(base::subtle::Atomic32 *value) : value_(value) {} 181 explicit ReleaseStoreThread(base::subtle::Atomic32 *value) : value_(value) {}
182 ~ReleaseStoreThread() {} 182 ~ReleaseStoreThread() {}
183 void ThreadMain() { 183 void ThreadMain() {
184 base::subtle::Release_Store(value_, kMagicValue); 184 base::subtle::Release_Store(value_, kMagicValue);
185 185
186 // Sleep for a few milliseconds so the two threads are more likely to live 186 // Sleep for a few milliseconds so the two threads are more likely to live
187 // simultaneously. Otherwise we may miss the report due to mutex 187 // simultaneously. Otherwise we may miss the report due to mutex
188 // lock/unlock's inside thread creation code in pure-happens-before mode... 188 // lock/unlock's inside thread creation code in pure-happens-before mode...
189 PlatformThread::Sleep(100); 189 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100));
190 } 190 }
191 private: 191 private:
192 base::subtle::Atomic32 *value_; 192 base::subtle::Atomic32 *value_;
193 }; 193 };
194 194
195 class AcquireLoadThread : public PlatformThread::Delegate { 195 class AcquireLoadThread : public PlatformThread::Delegate {
196 public: 196 public:
197 explicit AcquireLoadThread(base::subtle::Atomic32 *value) : value_(value) {} 197 explicit AcquireLoadThread(base::subtle::Atomic32 *value) : value_(value) {}
198 ~AcquireLoadThread() {} 198 ~AcquireLoadThread() {}
199 void ThreadMain() { 199 void ThreadMain() {
200 // Wait for the other thread to make Release_Store 200 // Wait for the other thread to make Release_Store
201 PlatformThread::Sleep(100); 201 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100));
202 base::subtle::Acquire_Load(value_); 202 base::subtle::Acquire_Load(value_);
203 } 203 }
204 private: 204 private:
205 base::subtle::Atomic32 *value_; 205 base::subtle::Atomic32 *value_;
206 }; 206 };
207 207
208 void RunInParallel(PlatformThread::Delegate *d1, PlatformThread::Delegate *d2) { 208 void RunInParallel(PlatformThread::Delegate *d1, PlatformThread::Delegate *d2) {
209 PlatformThreadHandle a; 209 PlatformThreadHandle a;
210 PlatformThreadHandle b; 210 PlatformThreadHandle b;
211 PlatformThread::Create(0, d1, &a); 211 PlatformThread::Create(0, d1, &a);
(...skipping 22 matching lines...) Expand all
234 234
235 TEST(ToolsSanityTest, AtomicsAreIgnored) { 235 TEST(ToolsSanityTest, AtomicsAreIgnored) {
236 base::subtle::Atomic32 shared = 0; 236 base::subtle::Atomic32 shared = 0;
237 ReleaseStoreThread thread1(&shared); 237 ReleaseStoreThread thread1(&shared);
238 AcquireLoadThread thread2(&shared); 238 AcquireLoadThread thread2(&shared);
239 RunInParallel(&thread1, &thread2); 239 RunInParallel(&thread1, &thread2);
240 EXPECT_EQ(kMagicValue, shared); 240 EXPECT_EQ(kMagicValue, shared);
241 } 241 }
242 242
243 } // namespace base 243 } // namespace base
OLDNEW
« no previous file with comments | « base/timer_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698