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

Unified Diff: test/unittests/heap/spaces-unittest.cc

Issue 2796033002: [heap] Fix CompactionSpace test and move to unittests (Closed)
Patch Set: Win compile failures 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/unittests/BUILD.gn ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/heap/spaces-unittest.cc
diff --git a/test/unittests/heap/spaces-unittest.cc b/test/unittests/heap/spaces-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bdd993339845bffc41592bec372c9d3e5d84c74d
--- /dev/null
+++ b/test/unittests/heap/spaces-unittest.cc
@@ -0,0 +1,50 @@
+// Copyright 2017 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/heap/heap-inl.h"
+#include "src/heap/spaces-inl.h"
+#include "src/isolate.h"
+#include "test/unittests/test-utils.h"
+
+namespace v8 {
+namespace internal {
+
+typedef TestWithIsolate SpacesTest;
+
+TEST_F(SpacesTest, CompactionSpaceMerge) {
+ Heap* heap = i_isolate()->heap();
+ OldSpace* old_space = heap->old_space();
+ EXPECT_TRUE(old_space != NULL);
+
+ CompactionSpace* compaction_space =
+ new CompactionSpace(heap, OLD_SPACE, NOT_EXECUTABLE);
+ EXPECT_TRUE(compaction_space != NULL);
+ EXPECT_TRUE(compaction_space->SetUp());
+
+ // Cannot loop until "Available()" since we initially have 0 bytes available
+ // and would thus neither grow, nor be able to allocate an object.
+ const int kNumObjects = 10;
+ const int kNumObjectsPerPage =
+ compaction_space->AreaSize() / kMaxRegularHeapObjectSize;
+ const int kExpectedPages =
+ (kNumObjects + kNumObjectsPerPage - 1) / kNumObjectsPerPage;
+ for (int i = 0; i < kNumObjects; i++) {
+ HeapObject* object =
+ compaction_space->AllocateRawUnaligned(kMaxRegularHeapObjectSize)
+ .ToObjectChecked();
+ heap->CreateFillerObjectAt(object->address(), kMaxRegularHeapObjectSize,
+ ClearRecordedSlots::kNo);
+ }
+ int pages_in_old_space = old_space->CountTotalPages();
+ int pages_in_compaction_space = compaction_space->CountTotalPages();
+ EXPECT_EQ(kExpectedPages, pages_in_compaction_space);
+ old_space->MergeCompactionSpace(compaction_space);
+ EXPECT_EQ(pages_in_old_space + pages_in_compaction_space,
+ old_space->CountTotalPages());
+
+ delete compaction_space;
+}
+
+} // namespace internal
+} // namespace v8
« no previous file with comments | « test/unittests/BUILD.gn ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698