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 class A { |
| 363 public: |
| 364 A(): n_(0) {} |
| 365 virtual void f() { n_++; } |
| 366 protected: |
| 367 int n_; |
| 368 }; |
| 369 |
| 370 class B: public A { |
| 371 public: |
| 372 void f() override { n_--; } |
| 373 }; |
| 374 |
| 375 NOINLINE void KillVptrAndCall(A *obj) { |
| 376 *reinterpret_cast<void **>(obj) = 0; |
| 377 obj->f(); |
| 378 } |
| 379 |
| 380 TEST(ToolsSanityTest, BadVirtualCall) { |
| 381 A a; |
| 382 B b; |
| 383 EXPECT_DEATH({ KillVptrAndCall(&a); KillVptrAndCall(&b); }, "ILL_ILLOPN"); |
| 384 } |
| 385 |
| 386 #endif // CFI_ENFORCEMENT |
359 | 387 |
360 } // namespace base | 388 } // namespace base |
OLD | NEW |