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

Side by Side Diff: test/unittests/wasm/ast-decoder-unittest.cc

Issue 1847543002: Expose a lower bound of malloc'd memory via heap statistics (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 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 unified diff | Download patch
« no previous file with comments | « test/unittests/test-utils.h ('k') | test/unittests/wasm/encoder-unittest.cc » ('j') | 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 V8 project authors. All rights reserved. 1 // Copyright 2015 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 "test/unittests/test-utils.h" 5 #include "test/unittests/test-utils.h"
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "test/cctest/wasm/test-signatures.h" 9 #include "test/cctest/wasm/test-signatures.h"
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void AddLocals(LocalType type, uint32_t count) { 73 void AddLocals(LocalType type, uint32_t count) {
74 local_decls.AddLocals(count, type); 74 local_decls.AddLocals(count, type);
75 } 75 }
76 76
77 // Preprends local variable declarations and renders nice error messages for 77 // Preprends local variable declarations and renders nice error messages for
78 // verification failures. 78 // verification failures.
79 void Verify(ErrorCode expected, FunctionSig* sig, const byte* start, 79 void Verify(ErrorCode expected, FunctionSig* sig, const byte* start,
80 const byte* end) { 80 const byte* end) {
81 local_decls.Prepend(&start, &end); 81 local_decls.Prepend(&start, &end);
82 // Verify the code. 82 // Verify the code.
83 TreeResult result = VerifyWasmCode(module, sig, start, end); 83 TreeResult result =
84 VerifyWasmCode(zone()->allocator(), module, sig, start, end);
84 85
85 if (result.error_code != expected) { 86 if (result.error_code != expected) {
86 ptrdiff_t pc = result.error_pc - result.start; 87 ptrdiff_t pc = result.error_pc - result.start;
87 ptrdiff_t pt = result.error_pt - result.start; 88 ptrdiff_t pt = result.error_pt - result.start;
88 std::ostringstream str; 89 std::ostringstream str;
89 if (expected == kSuccess) { 90 if (expected == kSuccess) {
90 str << "Verification failed: " << result.error_code << " pc = +" << pc; 91 str << "Verification failed: " << result.error_code << " pc = +" << pc;
91 if (result.error_pt) str << ", pt = +" << pt; 92 if (result.error_pt) str << ", pt = +" << pt;
92 str << ", msg = " << result.error_msg.get(); 93 str << ", msg = " << result.error_msg.get();
93 } else { 94 } else {
(...skipping 2110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 size_t count) { 2205 size_t count) {
2205 for (size_t i = 0; i < count; i++) { 2206 for (size_t i = 0; i < count; i++) {
2206 EXPECT_EQ(expected, map->at(pos++)); 2207 EXPECT_EQ(expected, map->at(pos++));
2207 } 2208 }
2208 return pos; 2209 return pos;
2209 } 2210 }
2210 }; 2211 };
2211 2212
2212 TEST_F(LocalDeclDecoderTest, NoLocals) { 2213 TEST_F(LocalDeclDecoderTest, NoLocals) {
2213 static const byte data[] = {0}; 2214 static const byte data[] = {0};
2214 LocalTypeMap map = DecodeLocalDeclsForTesting(data, data + sizeof(data)); 2215 base::AccountingAllocator allocator;
2216 LocalTypeMap map =
2217 DecodeLocalDeclsForTesting(&allocator, data, data + sizeof(data));
2215 EXPECT_EQ(0, map->size()); 2218 EXPECT_EQ(0, map->size());
2216 if (map) delete map; 2219 if (map) delete map;
2217 } 2220 }
2218 2221
2219 TEST_F(LocalDeclDecoderTest, OneLocal) { 2222 TEST_F(LocalDeclDecoderTest, OneLocal) {
2220 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 2223 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
2221 LocalType type = kLocalTypes[i]; 2224 LocalType type = kLocalTypes[i];
2222 const byte data[] = { 2225 const byte data[] = {
2223 1, 1, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))}; 2226 1, 1, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))};
2224 LocalTypeMap map = DecodeLocalDeclsForTesting(data, data + sizeof(data)); 2227 base::AccountingAllocator allocator;
2228 LocalTypeMap map =
2229 DecodeLocalDeclsForTesting(&allocator, data, data + sizeof(data));
2225 EXPECT_EQ(1, map->size()); 2230 EXPECT_EQ(1, map->size());
2226 EXPECT_EQ(type, map->at(0)); 2231 EXPECT_EQ(type, map->at(0));
2227 if (map) delete map; 2232 if (map) delete map;
2228 } 2233 }
2229 } 2234 }
2230 2235
2231 TEST_F(LocalDeclDecoderTest, FiveLocals) { 2236 TEST_F(LocalDeclDecoderTest, FiveLocals) {
2232 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 2237 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
2233 LocalType type = kLocalTypes[i]; 2238 LocalType type = kLocalTypes[i];
2234 const byte data[] = { 2239 const byte data[] = {
2235 1, 5, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))}; 2240 1, 5, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))};
2236 LocalTypeMap map = DecodeLocalDeclsForTesting(data, data + sizeof(data)); 2241 base::AccountingAllocator allocator;
2242 LocalTypeMap map =
2243 DecodeLocalDeclsForTesting(&allocator, data, data + sizeof(data));
2237 EXPECT_EQ(5, map->size()); 2244 EXPECT_EQ(5, map->size());
2238 ExpectRun(map, 0, type, 5); 2245 ExpectRun(map, 0, type, 5);
2239 if (map) delete map; 2246 if (map) delete map;
2240 } 2247 }
2241 } 2248 }
2242 2249
2243 TEST_F(LocalDeclDecoderTest, MixedLocals) { 2250 TEST_F(LocalDeclDecoderTest, MixedLocals) {
2244 for (byte a = 0; a < 3; a++) { 2251 for (byte a = 0; a < 3; a++) {
2245 for (byte b = 0; b < 3; b++) { 2252 for (byte b = 0; b < 3; b++) {
2246 for (byte c = 0; c < 3; c++) { 2253 for (byte c = 0; c < 3; c++) {
2247 for (byte d = 0; d < 3; d++) { 2254 for (byte d = 0; d < 3; d++) {
2248 const byte data[] = {4, a, kLocalI32, b, kLocalI64, 2255 const byte data[] = {4, a, kLocalI32, b, kLocalI64,
2249 c, kLocalF32, d, kLocalF64}; 2256 c, kLocalF32, d, kLocalF64};
2257 base::AccountingAllocator allocator;
2250 LocalTypeMap map = 2258 LocalTypeMap map =
2251 DecodeLocalDeclsForTesting(data, data + sizeof(data)); 2259 DecodeLocalDeclsForTesting(&allocator, data, data + sizeof(data));
2252 EXPECT_EQ(a + b + c + d, map->size()); 2260 EXPECT_EQ(a + b + c + d, map->size());
2253 2261
2254 size_t pos = 0; 2262 size_t pos = 0;
2255 pos = ExpectRun(map, pos, kAstI32, a); 2263 pos = ExpectRun(map, pos, kAstI32, a);
2256 pos = ExpectRun(map, pos, kAstI64, b); 2264 pos = ExpectRun(map, pos, kAstI64, b);
2257 pos = ExpectRun(map, pos, kAstF32, c); 2265 pos = ExpectRun(map, pos, kAstF32, c);
2258 pos = ExpectRun(map, pos, kAstF64, d); 2266 pos = ExpectRun(map, pos, kAstF64, d);
2259 2267
2260 if (map) delete map; 2268 if (map) delete map;
2261 } 2269 }
2262 } 2270 }
2263 } 2271 }
2264 } 2272 }
2265 } 2273 }
2266 2274
2267 TEST_F(LocalDeclDecoderTest, UseEncoder) { 2275 TEST_F(LocalDeclDecoderTest, UseEncoder) {
2268 const byte* data = nullptr; 2276 const byte* data = nullptr;
2269 const byte* end = nullptr; 2277 const byte* end = nullptr;
2270 LocalDeclEncoder local_decls; 2278 LocalDeclEncoder local_decls;
2271 2279
2272 local_decls.AddLocals(5, kAstF32); 2280 local_decls.AddLocals(5, kAstF32);
2273 local_decls.AddLocals(1337, kAstI32); 2281 local_decls.AddLocals(1337, kAstI32);
2274 local_decls.AddLocals(212, kAstI64); 2282 local_decls.AddLocals(212, kAstI64);
2275 local_decls.Prepend(&data, &end); 2283 local_decls.Prepend(&data, &end);
2276 2284
2277 LocalTypeMap map = DecodeLocalDeclsForTesting(data, end); 2285 base::AccountingAllocator allocator;
2286 LocalTypeMap map = DecodeLocalDeclsForTesting(&allocator, data, end);
2278 size_t pos = 0; 2287 size_t pos = 0;
2279 pos = ExpectRun(map, pos, kAstF32, 5); 2288 pos = ExpectRun(map, pos, kAstF32, 5);
2280 pos = ExpectRun(map, pos, kAstI32, 1337); 2289 pos = ExpectRun(map, pos, kAstI32, 1337);
2281 pos = ExpectRun(map, pos, kAstI64, 212); 2290 pos = ExpectRun(map, pos, kAstI64, 212);
2282 2291
2283 if (map) delete map; 2292 if (map) delete map;
2284 delete[] data; 2293 delete[] data;
2285 } 2294 }
2286 2295
2287 } // namespace wasm 2296 } // namespace wasm
2288 } // namespace internal 2297 } // namespace internal
2289 } // namespace v8 2298 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/test-utils.h ('k') | test/unittests/wasm/encoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698