Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 PlatformThread::Create(0, d1, &a); | 240 PlatformThread::Create(0, d1, &a); |
| 241 PlatformThread::Create(0, d2, &b); | 241 PlatformThread::Create(0, d2, &b); |
| 242 PlatformThread::Join(a); | 242 PlatformThread::Join(a); |
| 243 PlatformThread::Join(b); | 243 PlatformThread::Join(b); |
| 244 } | 244 } |
| 245 | 245 |
| 246 } // namespace | 246 } // namespace |
| 247 | 247 |
| 248 // A data race detector should report an error in this test. | 248 // A data race detector should report an error in this test. |
| 249 TEST(ToolsSanityTest, DataRace) { | 249 TEST(ToolsSanityTest, DataRace) { |
| 250 bool shared = false; | 250 bool *shared = new bool(false); |
|
Lei Zhang
2013/03/23 15:33:14
small nit: bool*
| |
| 251 TOOLS_SANITY_TEST_CONCURRENT_THREAD thread1(&shared), thread2(&shared); | 251 TOOLS_SANITY_TEST_CONCURRENT_THREAD thread1(shared), thread2(shared); |
| 252 RunInParallel(&thread1, &thread2); | 252 RunInParallel(&thread1, &thread2); |
| 253 EXPECT_TRUE(shared); | 253 EXPECT_TRUE(*shared); |
| 254 delete shared; | |
| 254 } | 255 } |
| 255 | 256 |
| 256 TEST(ToolsSanityTest, AnnotateBenignRace) { | 257 TEST(ToolsSanityTest, AnnotateBenignRace) { |
| 257 bool shared = false; | 258 bool shared = false; |
| 258 ANNOTATE_BENIGN_RACE(&shared, "Intentional race - make sure doesn't show up"); | 259 ANNOTATE_BENIGN_RACE(&shared, "Intentional race - make sure doesn't show up"); |
| 259 TOOLS_SANITY_TEST_CONCURRENT_THREAD thread1(&shared), thread2(&shared); | 260 TOOLS_SANITY_TEST_CONCURRENT_THREAD thread1(&shared), thread2(&shared); |
| 260 RunInParallel(&thread1, &thread2); | 261 RunInParallel(&thread1, &thread2); |
| 261 EXPECT_TRUE(shared); | 262 EXPECT_TRUE(shared); |
| 262 } | 263 } |
| 263 | 264 |
| 264 TEST(ToolsSanityTest, AtomicsAreIgnored) { | 265 TEST(ToolsSanityTest, AtomicsAreIgnored) { |
| 265 base::subtle::Atomic32 shared = 0; | 266 base::subtle::Atomic32 shared = 0; |
| 266 ReleaseStoreThread thread1(&shared); | 267 ReleaseStoreThread thread1(&shared); |
| 267 AcquireLoadThread thread2(&shared); | 268 AcquireLoadThread thread2(&shared); |
| 268 RunInParallel(&thread1, &thread2); | 269 RunInParallel(&thread1, &thread2); |
| 269 EXPECT_EQ(kMagicValue, shared); | 270 EXPECT_EQ(kMagicValue, shared); |
| 270 } | 271 } |
| 271 | 272 |
| 272 } // namespace base | 273 } // namespace base |
| OLD | NEW |