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 <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 | 336 |
| 337 TEST(ToolsSanityTest, AtomicsAreIgnored) { | 337 TEST(ToolsSanityTest, AtomicsAreIgnored) { |
| 338 base::subtle::Atomic32 shared = 0; | 338 base::subtle::Atomic32 shared = 0; |
| 339 ReleaseStoreThread thread1(&shared); | 339 ReleaseStoreThread thread1(&shared); |
| 340 AcquireLoadThread thread2(&shared); | 340 AcquireLoadThread thread2(&shared); |
| 341 RunInParallel(&thread1, &thread2); | 341 RunInParallel(&thread1, &thread2); |
| 342 EXPECT_EQ(kMagicValue, shared); | 342 EXPECT_EQ(kMagicValue, shared); |
| 343 } | 343 } |
| 344 | 344 |
| 345 #if defined(CFI_ENFORCEMENT) | 345 #if defined(CFI_ENFORCEMENT) |
| 346 // TODO(krasin): remove CFI_CAST_CHECK, see https://crbug.com/626794. | |
| 347 #if defined(CFI_CAST_CHECK) | |
| 346 TEST(ToolsSanityTest, BadCast) { | 348 TEST(ToolsSanityTest, BadCast) { |
| 347 class A { | 349 class A { |
| 348 virtual void f() {} | 350 virtual void f() {} |
| 349 }; | 351 }; |
| 350 | 352 |
| 351 class B { | 353 class B { |
| 352 virtual void f() {} | 354 virtual void f() {} |
| 353 }; | 355 }; |
| 354 | 356 |
| 355 A a; | 357 A a; |
| 356 EXPECT_DEATH((void)(B*)&a, "ILL_ILLOPN"); | 358 EXPECT_DEATH((void)(B*)&a, "ILL_ILLOPN"); |
| 357 } | 359 } |
| 358 #endif | 360 #endif // CFI_CAST_CHECK |
| 361 | |
| 362 TEST(ToolsSanityTest, BadVirtualCall) { | |
| 363 class A { | |
| 364 public: | |
| 365 virtual void f() {} | |
| 366 }; | |
| 367 | |
| 368 class B { | |
| 369 public: | |
| 370 virtual void f() {} | |
| 371 }; | |
| 372 | |
| 373 A a; | |
| 374 B b; | |
| 375 A *a_ptr = &a; | |
| 376 // Make a_ptr to point to b instead. | |
| 377 *reinterpret_cast<void**>(a_ptr) = *reinterpret_cast<void**>(&b); | |
| 378 EXPECT_DEATH(a_ptr->f(), "ILL_ILLOPN"); | |
|
pcc1
2016/07/11 21:56:47
I'm not sure if this is quite the test we need her
krasin1
2016/07/12 03:33:55
I've played a bit with the code, and the compiler
| |
| 379 } | |
| 380 | |
| 381 #endif // CFI_ENFORCEMENT | |
| 359 | 382 |
| 360 } // namespace base | 383 } // namespace base |
| OLD | NEW |