OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "base/metrics/persistent_memory_allocator.h" | 5 #include "base/metrics/persistent_memory_allocator.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 // simply by chance but it is useful during development to ensure that the | 465 // simply by chance but it is useful during development to ensure that the |
466 // test is working correctly. | 466 // test is working correctly. |
467 EXPECT_NE(iterable_count, t1.count()); | 467 EXPECT_NE(iterable_count, t1.count()); |
468 EXPECT_NE(iterable_count, t2.count()); | 468 EXPECT_NE(iterable_count, t2.count()); |
469 EXPECT_NE(iterable_count, t3.count()); | 469 EXPECT_NE(iterable_count, t3.count()); |
470 EXPECT_NE(iterable_count, t4.count()); | 470 EXPECT_NE(iterable_count, t4.count()); |
471 EXPECT_NE(iterable_count, t5.count()); | 471 EXPECT_NE(iterable_count, t5.count()); |
472 #endif | 472 #endif |
473 } | 473 } |
474 | 474 |
| 475 TEST_F(PersistentMemoryAllocatorTest, DelayedAllocationTest) { |
| 476 std::atomic<Reference> ref1, ref2; |
| 477 ref1.store(0, std::memory_order_relaxed); |
| 478 ref2.store(0, std::memory_order_relaxed); |
| 479 DelayedPersistentAllocation da1(allocator_.get(), &ref1, 1001, 100, true); |
| 480 DelayedPersistentAllocation da2a(allocator_.get(), &ref2, 2002, 200, 0, true); |
| 481 DelayedPersistentAllocation da2b(allocator_.get(), &ref2, 2002, 200, 5, true); |
| 482 |
| 483 // Nothing should yet have been allocated. |
| 484 uint32_t type; |
| 485 PersistentMemoryAllocator::Iterator iter(allocator_.get()); |
| 486 EXPECT_EQ(0U, iter.GetNext(&type)); |
| 487 |
| 488 // Do first delayed allocation and check that a new persistent object exists. |
| 489 EXPECT_EQ(0U, da1.reference()); |
| 490 void* mem1 = da1.Get(); |
| 491 ASSERT_TRUE(mem1); |
| 492 EXPECT_NE(0U, da1.reference()); |
| 493 EXPECT_EQ(allocator_->GetAsReference(mem1, 1001), |
| 494 ref1.load(std::memory_order_relaxed)); |
| 495 EXPECT_NE(0U, iter.GetNext(&type)); |
| 496 EXPECT_EQ(1001U, type); |
| 497 EXPECT_EQ(0U, iter.GetNext(&type)); |
| 498 |
| 499 // Do second delayed allocation and check. |
| 500 void* mem2a = da2a.Get(); |
| 501 ASSERT_TRUE(mem2a); |
| 502 EXPECT_EQ(allocator_->GetAsReference(mem2a, 2002), |
| 503 ref2.load(std::memory_order_relaxed)); |
| 504 EXPECT_NE(0U, iter.GetNext(&type)); |
| 505 EXPECT_EQ(2002U, type); |
| 506 EXPECT_EQ(0U, iter.GetNext(&type)); |
| 507 |
| 508 // Third allocation should just return offset into second allocation. |
| 509 void* mem2b = da2b.Get(); |
| 510 ASSERT_TRUE(mem2b); |
| 511 EXPECT_EQ(0U, iter.GetNext(&type)); |
| 512 EXPECT_EQ(reinterpret_cast<uintptr_t>(mem2a) + 5, |
| 513 reinterpret_cast<uintptr_t>(mem2b)); |
| 514 } |
| 515 |
475 // This test doesn't verify anything other than it doesn't crash. Its goal | 516 // This test doesn't verify anything other than it doesn't crash. Its goal |
476 // is to find coding errors that aren't otherwise tested for, much like a | 517 // is to find coding errors that aren't otherwise tested for, much like a |
477 // "fuzzer" would. | 518 // "fuzzer" would. |
478 // This test is suppsoed to fail on TSAN bot (crbug.com/579867). | 519 // This test is suppsoed to fail on TSAN bot (crbug.com/579867). |
479 #if defined(THREAD_SANITIZER) | 520 #if defined(THREAD_SANITIZER) |
480 #define MAYBE_CorruptionTest DISABLED_CorruptionTest | 521 #define MAYBE_CorruptionTest DISABLED_CorruptionTest |
481 #else | 522 #else |
482 #define MAYBE_CorruptionTest CorruptionTest | 523 #define MAYBE_CorruptionTest CorruptionTest |
483 #endif | 524 #endif |
484 TEST_F(PersistentMemoryAllocatorTest, MAYBE_CorruptionTest) { | 525 TEST_F(PersistentMemoryAllocatorTest, MAYBE_CorruptionTest) { |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 // For filesize >= minsize, the file must be acceptable. This | 910 // For filesize >= minsize, the file must be acceptable. This |
870 // else clause (file-not-acceptable) should be reached only if | 911 // else clause (file-not-acceptable) should be reached only if |
871 // filesize < minsize. | 912 // filesize < minsize. |
872 EXPECT_GT(minsize, filesize); | 913 EXPECT_GT(minsize, filesize); |
873 } | 914 } |
874 } | 915 } |
875 } | 916 } |
876 #endif // !defined(OS_NACL) | 917 #endif // !defined(OS_NACL) |
877 | 918 |
878 } // namespace base | 919 } // namespace base |
OLD | NEW |