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

Unified Diff: test/unittests/zone/zone-chunk-list-unittest.cc

Issue 2449383002: New zone-backed list datastructure to replace ZoneList (Closed)
Patch Set: Added some debug checks Created 4 years, 2 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/unittests.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/zone/zone-chunk-list-unittest.cc
diff --git a/test/unittests/zone/zone-chunk-list-unittest.cc b/test/unittests/zone/zone-chunk-list-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..13ff2cf04b43b0e518dedf08788e77084aeb672d
--- /dev/null
+++ b/test/unittests/zone/zone-chunk-list-unittest.cc
@@ -0,0 +1,144 @@
+// Copyright 2016 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/zone/zone-chunk-list.h"
+
+#include "src/list-inl.h"
+#include "src/zone/accounting-allocator.h"
+#include "src/zone/zone.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace internal {
+
+const size_t kItemCount = size_t(1) << 10;
+
+TEST(ZoneChunkList, ForwardIterationTest) {
+ AccountingAllocator allocator;
+ Zone zone(&allocator, ZONE_NAME);
+
+ ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
+
+ for (size_t i = 0; i < kItemCount; ++i) {
+ zone_chunk_list.push_back(static_cast<uintptr_t>(i));
+ }
+
+ size_t count = 0;
+
+ for (uintptr_t item : zone_chunk_list) {
+ EXPECT_EQ(static_cast<size_t>(item), count);
+ count++;
+ }
+
+ EXPECT_EQ(count, kItemCount);
+}
+
+TEST(ZoneChunkList, ReverseIterationTest) {
+ AccountingAllocator allocator;
+ Zone zone(&allocator, ZONE_NAME);
+
+ ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
+
+ for (size_t i = 0; i < kItemCount; ++i) {
+ zone_chunk_list.push_back(static_cast<uintptr_t>(i));
+ }
+
+ size_t count = 0;
+
+ for (auto it = zone_chunk_list.rbegin(); it != zone_chunk_list.rend(); ++it) {
+ EXPECT_EQ(static_cast<size_t>(*it), kItemCount - count - 1);
+ count++;
+ }
+
+ EXPECT_EQ(count, kItemCount);
+}
+
+TEST(ZoneChunkList, PushFrontTest) {
+ AccountingAllocator allocator;
+ Zone zone(&allocator, ZONE_NAME);
+
+ ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
+
+ for (size_t i = 0; i < kItemCount; ++i) {
+ zone_chunk_list.push_front(static_cast<uintptr_t>(i));
+ }
+
+ size_t count = 0;
+
+ for (uintptr_t item : zone_chunk_list) {
+ EXPECT_EQ(static_cast<size_t>(item), kItemCount - count - 1);
+ count++;
+ }
+
+ EXPECT_EQ(count, kItemCount);
+}
+
+TEST(ZoneChunkList, RewindTest) {
+ AccountingAllocator allocator;
+ Zone zone(&allocator, ZONE_NAME);
+
+ ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
+
+ for (size_t i = 0; i < kItemCount; ++i) {
+ zone_chunk_list.push_back(static_cast<uintptr_t>(i));
+ }
+
+ zone_chunk_list.Rewind(42);
+
+ size_t count = 0;
+
+ for (uintptr_t item : zone_chunk_list) {
+ EXPECT_EQ(static_cast<size_t>(item), count);
+ count++;
+ }
+
+ EXPECT_EQ(count, 42);
+ EXPECT_EQ(count, zone_chunk_list.size());
+
+ zone_chunk_list.Rewind(0);
+
+ count = 0;
+
+ for (uintptr_t item : zone_chunk_list) {
+ USE(item);
+ count++;
+ }
+
+ EXPECT_EQ(count, 0);
+ EXPECT_EQ(count, zone_chunk_list.size());
+
+ zone_chunk_list.Rewind(100);
+
+ count = 0;
+
+ for (uintptr_t item : zone_chunk_list) {
+ EXPECT_EQ(static_cast<size_t>(item), count);
+ count++;
+ }
+
+ EXPECT_EQ(count, 0);
+ EXPECT_EQ(count, zone_chunk_list.size());
+}
+
+TEST(ZoneChunkList, FindTest) {
+ AccountingAllocator allocator;
+ Zone zone(&allocator, ZONE_NAME);
+
+ ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
+
+ for (size_t i = 0; i < kItemCount; ++i) {
+ zone_chunk_list.push_back(static_cast<uintptr_t>(i));
+ }
+
+ const size_t index = kItemCount / 2 + 42;
+
+ EXPECT_EQ(*zone_chunk_list.Find(index), static_cast<uintptr_t>(index));
+
+ *zone_chunk_list.Find(index) = 42;
+
+ EXPECT_EQ(*zone_chunk_list.Find(index), 42);
+}
+
+} // namespace internal
+} // namespace v8
« no previous file with comments | « test/unittests/unittests.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698