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

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

Issue 2449383002: New zone-backed list datastructure to replace ZoneList (Closed)
Patch Set: Reaction to comments Created 4 years, 1 month 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
« src/zone/zone-chunk-list.h ('K') | « test/unittests/unittests.gyp ('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
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <ctime>
Jakob Kummerow 2016/10/26 16:08:10 what's this needed for?
6
7 #include "src/zone/zone-chunk-list.h"
8
9 #include "src/list-inl.h"
10 #include "src/zone/accounting-allocator.h"
11 #include "src/zone/zone-containers.h"
12 #include "src/zone/zone.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace v8 {
16 namespace internal {
17
18 const size_t kItemCount = size_t(1) << 10;
19
20 TEST(ZoneChunkList, ForwardIterationTest) {
21 AccountingAllocator allocator;
22 Zone zone(&allocator, ZONE_NAME);
23
24 ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
25
26 for (size_t i = 0; i < kItemCount; ++i) {
27 zone_chunk_list.push_back(static_cast<uintptr_t>(i));
28 }
29
30 size_t count = 0;
31
32 for (uintptr_t item : zone_chunk_list) {
33 EXPECT_EQ(static_cast<size_t>(item), count);
34 count++;
35 }
36
37 EXPECT_EQ(count, kItemCount);
38 }
39
40 TEST(ZoneChunkList, ReverseIterationTest) {
41 AccountingAllocator allocator;
42 Zone zone(&allocator, ZONE_NAME);
43
44 ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
45
46 for (size_t i = 0; i < kItemCount; ++i) {
47 zone_chunk_list.push_back(static_cast<uintptr_t>(i));
48 }
49
50 size_t count = 0;
51
52 for (auto it = zone_chunk_list.rbegin(); it != zone_chunk_list.rend(); ++it) {
53 EXPECT_EQ(static_cast<size_t>(*it), kItemCount - count - 1);
54 count++;
55 }
56
57 EXPECT_EQ(count, kItemCount);
58 }
59
60 TEST(ZoneChunkList, PushFrontTest) {
61 AccountingAllocator allocator;
62 Zone zone(&allocator, ZONE_NAME);
63
64 ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
65
66 for (size_t i = 0; i < kItemCount; ++i) {
67 zone_chunk_list.push_front(static_cast<uintptr_t>(i));
68 }
69
70 size_t count = 0;
71
72 for (uintptr_t item : zone_chunk_list) {
73 EXPECT_EQ(static_cast<size_t>(item), kItemCount - count - 1);
74 count++;
75 }
76
77 EXPECT_EQ(count, kItemCount);
78 }
79
80 TEST(ZoneChunkList, RewindTest) {
81 AccountingAllocator allocator;
82 Zone zone(&allocator, ZONE_NAME);
83
84 ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
85
86 for (size_t i = 0; i < kItemCount; ++i) {
87 zone_chunk_list.push_back(static_cast<uintptr_t>(i));
88 }
89
90 zone_chunk_list.Rewind(42);
91
92 size_t count = 0;
93
94 for (uintptr_t item : zone_chunk_list) {
95 EXPECT_EQ(static_cast<size_t>(item), count);
96 count++;
97 }
98
99 EXPECT_EQ(count, 42);
100 EXPECT_EQ(count, zone_chunk_list.size());
101
102 zone_chunk_list.Rewind(0);
103
104 count = 0;
105
106 for (uintptr_t item : zone_chunk_list) {
107 USE(item);
108 count++;
109 }
110
111 EXPECT_EQ(count, 0);
112 EXPECT_EQ(count, zone_chunk_list.size());
113
114 zone_chunk_list.Rewind(100);
115
116 count = 0;
117
118 for (uintptr_t item : zone_chunk_list) {
119 EXPECT_EQ(static_cast<size_t>(item), count);
120 count++;
121 }
122
123 EXPECT_EQ(count, 0);
124 EXPECT_EQ(count, zone_chunk_list.size());
125 }
126
127 TEST(ZoneChunkList, FindTest) {
128 AccountingAllocator allocator;
129 Zone zone(&allocator, ZONE_NAME);
130
131 ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
132
133 for (size_t i = 0; i < kItemCount; ++i) {
134 zone_chunk_list.push_back(static_cast<uintptr_t>(i));
135 }
136
137 const size_t index = kItemCount / 2 + 42;
138
139 EXPECT_EQ(*zone_chunk_list.Find(index), static_cast<uintptr_t>(index));
140
141 *zone_chunk_list.Find(index) = 42;
142
143 EXPECT_EQ(*zone_chunk_list.Find(index), 42);
144 }
145
146 } // namespace internal
147 } // namespace v8
OLDNEW
« src/zone/zone-chunk-list.h ('K') | « test/unittests/unittests.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698