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

Side by Side Diff: base/tools_sanity_unittest.cc

Issue 339893002: Make sure ThreadSanitizer v2 reports a data race in ToolsSanityTest.DataRace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix the ifdefs Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 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/debug/asan_invalid_access.h" 10 #include "base/debug/asan_invalid_access.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 280
281 void RunInParallel(PlatformThread::Delegate *d1, PlatformThread::Delegate *d2) { 281 void RunInParallel(PlatformThread::Delegate *d1, PlatformThread::Delegate *d2) {
282 PlatformThreadHandle a; 282 PlatformThreadHandle a;
283 PlatformThreadHandle b; 283 PlatformThreadHandle b;
284 PlatformThread::Create(0, d1, &a); 284 PlatformThread::Create(0, d1, &a);
285 PlatformThread::Create(0, d2, &b); 285 PlatformThread::Create(0, d2, &b);
286 PlatformThread::Join(a); 286 PlatformThread::Join(a);
287 PlatformThread::Join(b); 287 PlatformThread::Join(b);
288 } 288 }
289 289
290 } // namespace 290 #if defined(THREAD_SANITIZER)
291 291 void DataRace() {
292 // A data race detector should report an error in this test.
293 TEST(ToolsSanityTest, DataRace) {
294 bool *shared = new bool(false); 292 bool *shared = new bool(false);
295 TOOLS_SANITY_TEST_CONCURRENT_THREAD thread1(shared), thread2(shared); 293 TOOLS_SANITY_TEST_CONCURRENT_THREAD thread1(shared), thread2(shared);
296 RunInParallel(&thread1, &thread2); 294 RunInParallel(&thread1, &thread2);
297 EXPECT_TRUE(*shared); 295 EXPECT_TRUE(*shared);
298 delete shared; 296 delete shared;
297 // We're in a death test - crash.
298 CHECK(0);
299 } 299 }
300 #endif
301
302 } // namespace
303
304 #if defined(THREAD_SANITIZER)
305 // A data race detector should report an error in this test.
306 TEST(ToolsSanityTest, DataRace) {
307 // The suppression regexp must match that in base/debug/tsan_suppressions.cc.
308 EXPECT_DEATH(DataRace(), "1 race:base/tools_sanity_unittest.cc");
309 }
310 #endif
300 311
301 TEST(ToolsSanityTest, AnnotateBenignRace) { 312 TEST(ToolsSanityTest, AnnotateBenignRace) {
302 bool shared = false; 313 bool shared = false;
303 ANNOTATE_BENIGN_RACE(&shared, "Intentional race - make sure doesn't show up"); 314 ANNOTATE_BENIGN_RACE(&shared, "Intentional race - make sure doesn't show up");
304 TOOLS_SANITY_TEST_CONCURRENT_THREAD thread1(&shared), thread2(&shared); 315 TOOLS_SANITY_TEST_CONCURRENT_THREAD thread1(&shared), thread2(&shared);
305 RunInParallel(&thread1, &thread2); 316 RunInParallel(&thread1, &thread2);
306 EXPECT_TRUE(shared); 317 EXPECT_TRUE(shared);
307 } 318 }
308 319
309 TEST(ToolsSanityTest, AtomicsAreIgnored) { 320 TEST(ToolsSanityTest, AtomicsAreIgnored) {
310 base::subtle::Atomic32 shared = 0; 321 base::subtle::Atomic32 shared = 0;
311 ReleaseStoreThread thread1(&shared); 322 ReleaseStoreThread thread1(&shared);
312 AcquireLoadThread thread2(&shared); 323 AcquireLoadThread thread2(&shared);
313 RunInParallel(&thread1, &thread2); 324 RunInParallel(&thread1, &thread2);
314 EXPECT_EQ(kMagicValue, shared); 325 EXPECT_EQ(kMagicValue, shared);
315 } 326 }
316 327
317 } // namespace base 328 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698