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

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

Issue 2468183004: Used ZoneChunkList in deoptimizer (Closed)
Patch Set: Added unittests to ensure correct copyto 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
« no previous file with comments | « src/zone/zone-chunk-list.h ('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 2016 the V8 project authors. All rights reserved. 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 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 "src/zone/zone-chunk-list.h" 5 #include "src/zone/zone-chunk-list.h"
6 6
7 #include "src/list-inl.h" 7 #include "src/list-inl.h"
8 #include "src/zone/accounting-allocator.h" 8 #include "src/zone/accounting-allocator.h"
9 #include "src/zone/zone.h" 9 #include "src/zone/zone.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 const size_t index = kItemCount / 2 + 42; 134 const size_t index = kItemCount / 2 + 42;
135 135
136 EXPECT_EQ(*zone_chunk_list.Find(index), static_cast<uintptr_t>(index)); 136 EXPECT_EQ(*zone_chunk_list.Find(index), static_cast<uintptr_t>(index));
137 137
138 *zone_chunk_list.Find(index) = 42; 138 *zone_chunk_list.Find(index) = 42;
139 139
140 EXPECT_EQ(*zone_chunk_list.Find(index), 42); 140 EXPECT_EQ(*zone_chunk_list.Find(index), 42);
141 } 141 }
142 142
143 TEST(ZoneChunkList, CopyToTest) {
144 AccountingAllocator allocator;
145 Zone zone(&allocator, ZONE_NAME);
146
147 ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
148
149 for (size_t i = 0; i < kItemCount; ++i) {
150 zone_chunk_list.push_back(static_cast<uintptr_t>(i));
151 }
152
153 uintptr_t* array = zone.NewArray<uintptr_t>(kItemCount);
154
155 zone_chunk_list.CopyTo(array);
156
157 for (size_t i = 0; i < kItemCount; ++i) {
158 EXPECT_EQ(array[i], static_cast<uintptr_t>(i));
159 }
160 }
161
162 TEST(ZoneChunkList, SmallCopyToTest) {
163 AccountingAllocator allocator;
164 Zone zone(&allocator, ZONE_NAME);
165
166 ZoneChunkList<uint8_t> zone_chunk_list(&zone);
167
168 for (size_t i = 0; i < kItemCount; ++i) {
169 zone_chunk_list.push_back(static_cast<uint8_t>(i & 0xFF));
170 }
171
172 uint8_t* array = zone.NewArray<uint8_t>(kItemCount);
173
174 zone_chunk_list.CopyTo(array);
175
176 for (size_t i = 0; i < kItemCount; ++i) {
177 EXPECT_EQ(array[i], static_cast<uint8_t>(i & 0xFF));
178 }
179 }
180
181 struct Fubar {
182 size_t a_;
183 size_t b_;
184 };
185
186 TEST(ZoneChunkList, BigCopyToTest) {
187 AccountingAllocator allocator;
188 Zone zone(&allocator, ZONE_NAME);
189
190 ZoneChunkList<Fubar> zone_chunk_list(&zone);
191
192 for (size_t i = 0; i < kItemCount; ++i) {
193 zone_chunk_list.push_back({i, i + 5});
194 }
195
196 Fubar* array = zone.NewArray<Fubar>(kItemCount);
197
198 zone_chunk_list.CopyTo(array);
199
200 for (size_t i = 0; i < kItemCount; ++i) {
201 EXPECT_EQ(array[i].a_, i);
202 EXPECT_EQ(array[i].b_, i + 5);
203 }
204 }
205
143 } // namespace internal 206 } // namespace internal
144 } // namespace v8 207 } // namespace v8
OLDNEW
« no previous file with comments | « src/zone/zone-chunk-list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698