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

Side by Side Diff: test/mjsunit/wasm/module-memory.js

Issue 2051043002: Implement Wasm GrowMemory opcode as a wasm runtime call (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Ben's review, fix includes Created 4 years, 6 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
« src/compiler/wasm-compiler.cc ('K') | « src/x64/assembler-x64.cc ('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 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 // Flags: --expose-wasm --expose-gc --stress-compaction 5 // Flags: --expose-wasm --expose-gc --stress-compaction
6 6
7 load("test/mjsunit/wasm/wasm-constants.js"); 7 load("test/mjsunit/wasm/wasm-constants.js");
8 load("test/mjsunit/wasm/wasm-module-builder.js"); 8 load("test/mjsunit/wasm/wasm-module-builder.js");
9 9
10 var kMemSize = 65536; 10 var kMemSize = 65536;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 149 }
150 150
151 151
152 for (offset = 65534; offset < 66536; offset++) { 152 for (offset = 65534; offset < 66536; offset++) {
153 assertTraps(kTrapMemOutOfBounds, read); 153 assertTraps(kTrapMemOutOfBounds, read);
154 assertTraps(kTrapMemOutOfBounds, write); 154 assertTraps(kTrapMemOutOfBounds, write);
155 } 155 }
156 } 156 }
157 157
158 testOOBThrows(); 158 testOOBThrows();
159
160 function genGrowMemoryBuilder() {
161 var builder = new WasmModuleBuilder();
162 builder.addFunction("grow_memory", kSig_i_i)
163 .addBody([kExprGetLocal, 0, kExprGrowMemory])
164 .exportFunc();
165 builder.addFunction("load", kSig_i_i)
166 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
167 .exportFunc();
168 builder.addFunction("store", kSig_i_ii)
169 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0])
170 .exportFunc();
171 return builder;
172 }
173
174 function testGrowMemoryReadWrite() {
175 var builder = genGrowMemoryBuilder();
176 builder.addMemory(1, 1, false);
177 var module = builder.instantiate();
178 var offset;
179 function peek() { return module.exports.load(offset); }
180 function poke(value) { return module.exports.store(offset, value); }
181 function growMem(pages) { return module.exports.grow_memory(pages); }
182
183 for(offset = 0; offset < 65533; offset++) {
184 poke(20);
185 assertEquals(peek(), 20);
186 }
187 for (offset = 65534; offset < 66538; offset++) {
188 assertTraps(kTrapMemOutOfBounds, poke);
189 assertTraps(kTrapMemOutOfBounds, peek);
190 }
191
192 assertEquals(growMem(3), 1);
193
194 for (offset = 65534; offset < 262141; offset++) {
195 poke(20);
196 assertEquals(peek(), 20);
197 }
198 for (offset = 262142; offset < 262145; offset++) {
199 assertTraps(kTrapMemOutOfBounds, poke);
200 assertTraps(kTrapMemOutOfBounds, peek);
201 }
202
203 assertEquals(growMem(15), 4);
204
205 for (offset = 262142; offset < 262148; offset++) {
206 poke(20);
207 assertEquals(peek(), 20);
208 }
209 for (offset = 1245184; offset < 1245188; offset++) {
210 assertTraps(kTrapMemOutOfBounds, poke);
211 assertTraps(kTrapMemOutOfBounds, peek);
212 }
213 }
214
215 testGrowMemoryReadWrite();
216
217 function testGrowMemoryZeroInitialSize() {
218 var builder = genGrowMemoryBuilder();
219 var module = builder.instantiate();
220 var offset;
221 function peek() { return module.exports.load(offset); }
222 function poke(value) { return module.exports.store(offset, value); }
223 function growMem(pages) { return module.exports.grow_memory(pages); }
224
225 assertTraps(kTrapMemOutOfBounds, peek);
226 assertTraps(kTrapMemOutOfBounds, poke);
227
228 assertEquals(growMem(1), 0);
229
230 for(offset = 0; offset <=65533; offset++) {
231 poke(20);
232 assertEquals(peek(), 20);
233 }
234
235 //TODO(gdeepti): Fix tests with correct write boundaries
236 //when runtime function is fixed.
237 for(offset = 65536; offset <= 65539; offset++) {
238 assertTraps(kTrapMemOutOfBounds, peek);
239 }
240 }
241
242 testGrowMemoryZeroInitialSize();
243
244 function testGrowMemoryTrapMaxPagesZeroInitialMemory() {
245 var builder = genGrowMemoryBuilder();
246 var module = builder.instantiate();
247 var maxPages = 16385;
248 function growMem() { return module.exports.grow_memory(maxPages); }
249 assertTraps(kTrapMemOutOfBounds, growMem);
250 }
251
252 testGrowMemoryTrapMaxPagesZeroInitialMemory();
253
254 function testGrowMemoryTrapMaxPages() {
255 var builder = genGrowMemoryBuilder();
256 builder.addMemory(1, 1, false);
257 var module = builder.instantiate();
258 var maxPages = 16384;
259 function growMem() { return module.exports.grow_memory(maxPages); }
260 assertTraps(kTrapMemOutOfBounds, growMem);
261 }
262
263 testGrowMemoryTrapMaxPages();
264
265
266 function testGrowMemoryOobThrows() {
267 var builder = genGrowMemoryBuilder();
268 builder.addMemory(1, 1, false);
269 builder.addFunction("geti", kSig_i_ii)
270 .addBody([
271 kExprGetLocal, 0,
272 kExprGetLocal, 1,
273 kExprI32LoadMem, 0, 0,
274 kExprI32StoreMem, 0, 0
275 ])
276 .exportFunc();
277
278 var module = builder.instantiate();
279 var offset;
280
281 function read() { return module.exports.geti(0, offset); }
282 function write() { return module.exports.geti(offset, 0); }
283
284 for (offset = 0; offset < 65533; offset++) {
285 assertEquals(0, read());
286 assertEquals(0, write());
287 }
288
289 for (offset = 65534; offset < 66536; offset++) {
290 assertTraps(kTrapMemOutOfBounds, read);
291 assertTraps(kTrapMemOutOfBounds, write);
292 }
293
294 function resizeMem() { return module.exports.grow_memory(2); }
295 assertEquals(1, resizeMem());
296
297 for (offset = 0; offset < 196605; offset++) {
298 assertEquals(0, read());
299 assertEquals(0, write());
300 }
301
302 for (offset = 196605; offset < 196610; offset++) {
303 assertTraps(kTrapMemOutOfBounds, read);
304 assertTraps(kTrapMemOutOfBounds, write);
305 }
306
307 }
308
309 testGrowMemoryOobThrows();
OLDNEW
« src/compiler/wasm-compiler.cc ('K') | « src/x64/assembler-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698