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

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

Issue 2034813003: Make changing a record's type an atomic operation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « base/metrics/persistent_memory_allocator.cc ('k') | 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 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 EXPECT_EQ(1, allocs_samples->GetCount(sizeof(TestObject2))); 174 EXPECT_EQ(1, allocs_samples->GetCount(sizeof(TestObject2)));
175 #if !DCHECK_IS_ON() // DCHECK builds will die at a NOTREACHED(). 175 #if !DCHECK_IS_ON() // DCHECK builds will die at a NOTREACHED().
176 EXPECT_EQ(0U, allocator_->Allocate(TEST_MEMORY_SIZE + 1, 0)); 176 EXPECT_EQ(0U, allocator_->Allocate(TEST_MEMORY_SIZE + 1, 0));
177 allocs_samples = allocator_->allocs_histogram_->SnapshotSamples(); 177 allocs_samples = allocator_->allocs_histogram_->SnapshotSamples();
178 EXPECT_EQ(3, allocs_samples->TotalCount()); 178 EXPECT_EQ(3, allocs_samples->TotalCount());
179 EXPECT_EQ(1, allocs_samples->GetCount(0)); 179 EXPECT_EQ(1, allocs_samples->GetCount(0));
180 #endif 180 #endif
181 181
182 // Check that an objcet's type can be changed. 182 // Check that an objcet's type can be changed.
183 EXPECT_EQ(2U, allocator_->GetType(block2)); 183 EXPECT_EQ(2U, allocator_->GetType(block2));
184 allocator_->SetType(block2, 3); 184 allocator_->ChangeType(block2, 3, 2);
185 EXPECT_EQ(3U, allocator_->GetType(block2)); 185 EXPECT_EQ(3U, allocator_->GetType(block2));
186 allocator_->SetType(block2, 2); 186 allocator_->ChangeType(block2, 2, 3);
187 EXPECT_EQ(2U, allocator_->GetType(block2)); 187 EXPECT_EQ(2U, allocator_->GetType(block2));
188 188
189 // Create second allocator (read/write) using the same memory segment. 189 // Create second allocator (read/write) using the same memory segment.
190 std::unique_ptr<PersistentMemoryAllocator> allocator2( 190 std::unique_ptr<PersistentMemoryAllocator> allocator2(
191 new PersistentMemoryAllocator(mem_segment_.get(), TEST_MEMORY_SIZE, 191 new PersistentMemoryAllocator(mem_segment_.get(), TEST_MEMORY_SIZE,
192 TEST_MEMORY_PAGE, 0, "", false)); 192 TEST_MEMORY_PAGE, 0, "", false));
193 EXPECT_EQ(TEST_ID, allocator2->Id()); 193 EXPECT_EQ(TEST_ID, allocator2->Id());
194 EXPECT_FALSE(allocator2->used_histogram_); 194 EXPECT_FALSE(allocator2->used_histogram_);
195 EXPECT_FALSE(allocator2->allocs_histogram_); 195 EXPECT_FALSE(allocator2->allocs_histogram_);
196 EXPECT_NE(allocator2->allocs_histogram_, allocator_->allocs_histogram_); 196 EXPECT_NE(allocator2->allocs_histogram_, allocator_->allocs_histogram_);
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 { 504 {
505 std::unique_ptr<SharedMemory> shmem1(new SharedMemory()); 505 std::unique_ptr<SharedMemory> shmem1(new SharedMemory());
506 ASSERT_TRUE(shmem1->CreateAndMapAnonymous(TEST_MEMORY_SIZE)); 506 ASSERT_TRUE(shmem1->CreateAndMapAnonymous(TEST_MEMORY_SIZE));
507 SharedPersistentMemoryAllocator local(std::move(shmem1), TEST_ID, "", 507 SharedPersistentMemoryAllocator local(std::move(shmem1), TEST_ID, "",
508 false); 508 false);
509 EXPECT_FALSE(local.IsReadonly()); 509 EXPECT_FALSE(local.IsReadonly());
510 r123 = local.Allocate(123, 123); 510 r123 = local.Allocate(123, 123);
511 r456 = local.Allocate(456, 456); 511 r456 = local.Allocate(456, 456);
512 r789 = local.Allocate(789, 789); 512 r789 = local.Allocate(789, 789);
513 local.MakeIterable(r123); 513 local.MakeIterable(r123);
514 local.SetType(r456, 654); 514 local.ChangeType(r456, 654, 456);
515 local.MakeIterable(r789); 515 local.MakeIterable(r789);
516 local.GetMemoryInfo(&meminfo1); 516 local.GetMemoryInfo(&meminfo1);
517 EXPECT_FALSE(local.IsFull()); 517 EXPECT_FALSE(local.IsFull());
518 EXPECT_FALSE(local.IsCorrupt()); 518 EXPECT_FALSE(local.IsCorrupt());
519 519
520 ASSERT_TRUE(local.shared_memory()->ShareToProcess( 520 ASSERT_TRUE(local.shared_memory()->ShareToProcess(
521 GetCurrentProcessHandle(), 521 GetCurrentProcessHandle(),
522 &shared_handle)); 522 &shared_handle));
523 } 523 }
524 524
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 591
592 PersistentMemoryAllocator::MemoryInfo meminfo1; 592 PersistentMemoryAllocator::MemoryInfo meminfo1;
593 Reference r123, r456, r789; 593 Reference r123, r456, r789;
594 { 594 {
595 LocalPersistentMemoryAllocator local(TEST_MEMORY_SIZE, TEST_ID, ""); 595 LocalPersistentMemoryAllocator local(TEST_MEMORY_SIZE, TEST_ID, "");
596 EXPECT_FALSE(local.IsReadonly()); 596 EXPECT_FALSE(local.IsReadonly());
597 r123 = local.Allocate(123, 123); 597 r123 = local.Allocate(123, 123);
598 r456 = local.Allocate(456, 456); 598 r456 = local.Allocate(456, 456);
599 r789 = local.Allocate(789, 789); 599 r789 = local.Allocate(789, 789);
600 local.MakeIterable(r123); 600 local.MakeIterable(r123);
601 local.SetType(r456, 654); 601 local.ChangeType(r456, 654, 456);
602 local.MakeIterable(r789); 602 local.MakeIterable(r789);
603 local.GetMemoryInfo(&meminfo1); 603 local.GetMemoryInfo(&meminfo1);
604 EXPECT_FALSE(local.IsFull()); 604 EXPECT_FALSE(local.IsFull());
605 EXPECT_FALSE(local.IsCorrupt()); 605 EXPECT_FALSE(local.IsCorrupt());
606 606
607 File writer(file_path, File::FLAG_CREATE | File::FLAG_WRITE); 607 File writer(file_path, File::FLAG_CREATE | File::FLAG_WRITE);
608 ASSERT_TRUE(writer.IsValid()); 608 ASSERT_TRUE(writer.IsValid());
609 writer.Write(0, (const char*)local.data(), local.used()); 609 writer.Write(0, (const char*)local.data(), local.used());
610 } 610 }
611 611
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 } else { 779 } else {
780 // For filesize >= minsize, the file must be acceptable. This 780 // For filesize >= minsize, the file must be acceptable. This
781 // else clause (file-not-acceptable) should be reached only if 781 // else clause (file-not-acceptable) should be reached only if
782 // filesize < minsize. 782 // filesize < minsize.
783 EXPECT_GT(minsize, filesize); 783 EXPECT_GT(minsize, filesize);
784 } 784 }
785 } 785 }
786 } 786 }
787 787
788 } // namespace base 788 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/persistent_memory_allocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698