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

Side by Side Diff: test/unittests/wasm/encoder-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
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 "src/wasm/ast-decoder.h" 9 #include "src/wasm/ast-decoder.h"
10 #include "src/wasm/encoder.h" 10 #include "src/wasm/encoder.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 const std::vector<uint8_t> result = UnsignedLEB128From(input); 45 const std::vector<uint8_t> result = UnsignedLEB128From(input);
46 CHECK_EQ(result.size(), length); 46 CHECK_EQ(result.size(), length);
47 for (int i = 0; i < length; i++) { 47 for (int i = 0; i < length; i++) {
48 CHECK_EQ(result.at(i), vals[i]); 48 CHECK_EQ(result.at(i), vals[i]);
49 } 49 }
50 } 50 }
51 }; 51 };
52 52
53 53
54 TEST_F(EncoderTest, Function_Builder_Variable_Indexing) { 54 TEST_F(EncoderTest, Function_Builder_Variable_Indexing) {
55 Zone zone; 55 ZoneForTesting zone;
56 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 56 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
57 uint16_t f_index = builder->AddFunction(); 57 uint16_t f_index = builder->AddFunction();
58 WasmFunctionBuilder* function = builder->FunctionAt(f_index); 58 WasmFunctionBuilder* function = builder->FunctionAt(f_index);
59 uint16_t local_f32 = function->AddLocal(kAstF32); 59 uint16_t local_f32 = function->AddLocal(kAstF32);
60 uint16_t param_float32 = function->AddParam(kAstF32); 60 uint16_t param_float32 = function->AddParam(kAstF32);
61 uint16_t local_i32 = function->AddLocal(kAstI32); 61 uint16_t local_i32 = function->AddLocal(kAstI32);
62 uint16_t local_f64 = function->AddLocal(kAstF64); 62 uint16_t local_f64 = function->AddLocal(kAstF64);
63 uint16_t local_i64 = function->AddLocal(kAstI64); 63 uint16_t local_i64 = function->AddLocal(kAstI64);
64 uint16_t param_int32 = function->AddParam(kAstI32); 64 uint16_t param_int32 = function->AddParam(kAstI32);
65 uint16_t local_i32_2 = function->AddLocal(kAstI32); 65 uint16_t local_i32_2 = function->AddLocal(kAstI32);
(...skipping 17 matching lines...) Expand all
83 WasmFunctionEncoder* f = function->Build(&zone, builder); 83 WasmFunctionEncoder* f = function->Build(&zone, builder);
84 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone); 84 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone);
85 byte* buffer = &buffer_vector[0]; 85 byte* buffer = &buffer_vector[0];
86 byte* header = buffer; 86 byte* header = buffer;
87 byte* body = buffer + f->HeaderSize(); 87 byte* body = buffer + f->HeaderSize();
88 f->Serialize(buffer, &header, &body); 88 f->Serialize(buffer, &header, &body);
89 } 89 }
90 90
91 91
92 TEST_F(EncoderTest, Function_Builder_Indexing_Variable_Width) { 92 TEST_F(EncoderTest, Function_Builder_Indexing_Variable_Width) {
93 Zone zone; 93 ZoneForTesting zone;
94 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 94 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
95 uint16_t f_index = builder->AddFunction(); 95 uint16_t f_index = builder->AddFunction();
96 WasmFunctionBuilder* function = builder->FunctionAt(f_index); 96 WasmFunctionBuilder* function = builder->FunctionAt(f_index);
97 for (size_t i = 0; i < 128; i++) { 97 for (size_t i = 0; i < 128; i++) {
98 AddLocal(function, kAstF32); 98 AddLocal(function, kAstF32);
99 } 99 }
100 AddLocal(function, kAstI32); 100 AddLocal(function, kAstI32);
101 101
102 WasmFunctionEncoder* f = function->Build(&zone, builder); 102 WasmFunctionEncoder* f = function->Build(&zone, builder);
103 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone); 103 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone);
104 byte* buffer = &buffer_vector[0]; 104 byte* buffer = &buffer_vector[0];
105 byte* header = buffer; 105 byte* header = buffer;
106 byte* body = buffer + f->HeaderSize(); 106 byte* body = buffer + f->HeaderSize();
107 f->Serialize(buffer, &header, &body); 107 f->Serialize(buffer, &header, &body);
108 body = buffer + f->HeaderSize(); 108 body = buffer + f->HeaderSize();
109 } 109 }
110 110
111 TEST_F(EncoderTest, Function_Builder_Block_Variable_Width) { 111 TEST_F(EncoderTest, Function_Builder_Block_Variable_Width) {
112 Zone zone; 112 ZoneForTesting zone;
113 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 113 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
114 uint16_t f_index = builder->AddFunction(); 114 uint16_t f_index = builder->AddFunction();
115 WasmFunctionBuilder* function = builder->FunctionAt(f_index); 115 WasmFunctionBuilder* function = builder->FunctionAt(f_index);
116 function->EmitWithVarInt(kExprBlock, 200); 116 function->EmitWithVarInt(kExprBlock, 200);
117 for (int i = 0; i < 200; ++i) { 117 for (int i = 0; i < 200; ++i) {
118 function->Emit(kExprNop); 118 function->Emit(kExprNop);
119 } 119 }
120 120
121 WasmFunctionEncoder* f = function->Build(&zone, builder); 121 WasmFunctionEncoder* f = function->Build(&zone, builder);
122 CHECK_EQ(f->BodySize(), 204); 122 CHECK_EQ(f->BodySize(), 204);
123 } 123 }
124 124
125 TEST_F(EncoderTest, Function_Builder_EmitEditableVarIntImmediate) { 125 TEST_F(EncoderTest, Function_Builder_EmitEditableVarIntImmediate) {
126 Zone zone; 126 ZoneForTesting zone;
127 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 127 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
128 uint16_t f_index = builder->AddFunction(); 128 uint16_t f_index = builder->AddFunction();
129 WasmFunctionBuilder* function = builder->FunctionAt(f_index); 129 WasmFunctionBuilder* function = builder->FunctionAt(f_index);
130 function->Emit(kExprLoop); 130 function->Emit(kExprLoop);
131 uint32_t offset = function->EmitEditableVarIntImmediate(); 131 uint32_t offset = function->EmitEditableVarIntImmediate();
132 for (int i = 0; i < 200; ++i) { 132 for (int i = 0; i < 200; ++i) {
133 function->Emit(kExprNop); 133 function->Emit(kExprNop);
134 } 134 }
135 function->EditVarIntImmediate(offset, 200); 135 function->EditVarIntImmediate(offset, 200);
136 136
137 WasmFunctionEncoder* f = function->Build(&zone, builder); 137 WasmFunctionEncoder* f = function->Build(&zone, builder);
138 CHECK_EQ(f->BodySize(), 204); 138 CHECK_EQ(f->BodySize(), 204);
139 } 139 }
140 140
141 TEST_F(EncoderTest, Function_Builder_EmitEditableVarIntImmediate_Locals) { 141 TEST_F(EncoderTest, Function_Builder_EmitEditableVarIntImmediate_Locals) {
142 Zone zone; 142 ZoneForTesting zone;
143 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); 143 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
144 uint16_t f_index = builder->AddFunction(); 144 uint16_t f_index = builder->AddFunction();
145 WasmFunctionBuilder* function = builder->FunctionAt(f_index); 145 WasmFunctionBuilder* function = builder->FunctionAt(f_index);
146 function->Emit(kExprBlock); 146 function->Emit(kExprBlock);
147 uint32_t offset = function->EmitEditableVarIntImmediate(); 147 uint32_t offset = function->EmitEditableVarIntImmediate();
148 for (int i = 0; i < 200; ++i) { 148 for (int i = 0; i < 200; ++i) {
149 AddLocal(function, kAstI32); 149 AddLocal(function, kAstI32);
150 } 150 }
151 function->EditVarIntImmediate(offset, 200); 151 function->EditVarIntImmediate(offset, 200);
152 152
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 leb_value[0] = 0x80; 204 leb_value[0] = 0x80;
205 leb_value[1] = 0x80; 205 leb_value[1] = 0x80;
206 leb_value[2] = 0x80; 206 leb_value[2] = 0x80;
207 leb_value[3] = 0x80; 207 leb_value[3] = 0x80;
208 leb_value[4] = 0x80; 208 leb_value[4] = 0x80;
209 CheckReadValue(leb_value, -1, -1, kInvalidLEB128); 209 CheckReadValue(leb_value, -1, -1, kInvalidLEB128);
210 } 210 }
211 } // namespace wasm 211 } // namespace wasm
212 } // namespace internal 212 } // namespace internal
213 } // namespace v8 213 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698