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

Side by Side Diff: base/metrics/persistent_memory_allocator_unittest.cc

Issue 2806403002: Support delayed allocations from persistent memory. (Closed)
Patch Set: fixed build problems Created 3 years, 8 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
OLDNEW
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
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);
480 DelayedPersistentAllocation da2a(allocator_.get(), &ref2, 2002, 200, 0);
481 DelayedPersistentAllocation da2b(allocator_.get(), &ref2, 2002, 200, 10);
482 da1.MakeIterable();
483 da2a.MakeIterable();
484 da2b.MakeIterable();
485
486 // Nothing should yet have been allocated.
487 uint32_t type;
488 PersistentMemoryAllocator::Iterator iter(allocator_.get());
489 EXPECT_EQ(0U, iter.GetNext(&type));
490
491 // Do first delayed allocation and check that a new persistent object exists.
492 EXPECT_EQ(0U, da1.reference());
493 void* mem1 = da1.Get();
494 ASSERT_TRUE(mem1);
495 EXPECT_NE(0U, da1.reference());
496 EXPECT_EQ(allocator_->GetAsReference(mem1, 1001),
497 ref1.load(std::memory_order_relaxed));
498 EXPECT_NE(0U, iter.GetNext(&type));
499 EXPECT_EQ(1001U, type);
500 EXPECT_EQ(0U, iter.GetNext(&type));
501
502 // Do second delayed allocation and check.
503 void* mem2a = da2a.Get();
504 ASSERT_TRUE(mem2a);
505 EXPECT_EQ(allocator_->GetAsReference(mem2a, 2002),
506 ref2.load(std::memory_order_relaxed));
507 EXPECT_NE(0U, iter.GetNext(&type));
508 EXPECT_EQ(2002U, type);
509 EXPECT_EQ(0U, iter.GetNext(&type));
510
511 // Third allocation should just return offset into second allocation.
512 void* mem2b = da2b.Get();
513 ASSERT_TRUE(mem2b);
514 EXPECT_EQ(0U, iter.GetNext(&type));
515 EXPECT_EQ(reinterpret_cast<uintptr_t>(mem2a) + 10,
516 reinterpret_cast<uintptr_t>(mem2b));
517 }
518
475 // This test doesn't verify anything other than it doesn't crash. Its goal 519 // 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 520 // is to find coding errors that aren't otherwise tested for, much like a
477 // "fuzzer" would. 521 // "fuzzer" would.
478 // This test is suppsoed to fail on TSAN bot (crbug.com/579867). 522 // This test is suppsoed to fail on TSAN bot (crbug.com/579867).
479 #if defined(THREAD_SANITIZER) 523 #if defined(THREAD_SANITIZER)
480 #define MAYBE_CorruptionTest DISABLED_CorruptionTest 524 #define MAYBE_CorruptionTest DISABLED_CorruptionTest
481 #else 525 #else
482 #define MAYBE_CorruptionTest CorruptionTest 526 #define MAYBE_CorruptionTest CorruptionTest
483 #endif 527 #endif
484 TEST_F(PersistentMemoryAllocatorTest, MAYBE_CorruptionTest) { 528 TEST_F(PersistentMemoryAllocatorTest, MAYBE_CorruptionTest) {
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 // For filesize >= minsize, the file must be acceptable. This 913 // For filesize >= minsize, the file must be acceptable. This
870 // else clause (file-not-acceptable) should be reached only if 914 // else clause (file-not-acceptable) should be reached only if
871 // filesize < minsize. 915 // filesize < minsize.
872 EXPECT_GT(minsize, filesize); 916 EXPECT_GT(minsize, filesize);
873 } 917 }
874 } 918 }
875 } 919 }
876 #endif // !defined(OS_NACL) 920 #endif // !defined(OS_NACL)
877 921
878 } // namespace base 922 } // namespace base
OLDNEW
« base/metrics/persistent_memory_allocator.cc ('K') | « base/metrics/persistent_memory_allocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698