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

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

Issue 2416393002: Revert of [wasm] Fix bounds check for zero initial memory. (Closed)
Patch Set: Created 4 years, 2 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 | « src/wasm/wasm-module.cc ('k') | test/mjsunit/wasm/import-memory.js » ('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 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 // 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 kPageSize = 0x10000; 10 var kPageSize = 0x10000;
(...skipping 20 matching lines...) Expand all
31 builder.addFunction("load8", kSig_i_i) 31 builder.addFunction("load8", kSig_i_i)
32 .addBody([kExprGetLocal, 0, kExprI32LoadMem8U, 0, 0]) 32 .addBody([kExprGetLocal, 0, kExprI32LoadMem8U, 0, 0])
33 .exportFunc(); 33 .exportFunc();
34 builder.addFunction("store8", kSig_i_ii) 34 builder.addFunction("store8", kSig_i_ii)
35 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem8, 0, 0, 35 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem8, 0, 0,
36 kExprGetLocal, 1]) 36 kExprGetLocal, 1])
37 .exportFunc(); 37 .exportFunc();
38 return builder; 38 return builder;
39 } 39 }
40 40
41 // TODO(gdeepti): Generate tests programatically for all the sizes instead of
42 // current implementation.
43 function testGrowMemoryReadWrite32() { 41 function testGrowMemoryReadWrite32() {
44 var builder = genGrowMemoryBuilder(); 42 var builder = genGrowMemoryBuilder();
45 builder.addMemory(1, 1, false); 43 builder.addMemory(1, 1, false);
46 var module = builder.instantiate(); 44 var module = builder.instantiate();
47 var offset; 45 var offset;
48 function peek() { return module.exports.load(offset); } 46 function peek() { return module.exports.load(offset); }
49 function poke(value) { return module.exports.store(offset, value); } 47 function poke(value) { return module.exports.store(offset, value); }
50 function growMem(pages) { return module.exports.grow_memory(pages); } 48 function growMem(pages) { return module.exports.grow_memory(pages); }
51 49
52 for(offset = 0; offset <= (kPageSize - 4); offset+=4) { 50 for(offset = 0; offset <= (kPageSize - 4); offset+=4) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 assertTraps(kTrapMemOutOfBounds, peek); 190 assertTraps(kTrapMemOutOfBounds, peek);
193 assertTraps(kTrapMemOutOfBounds, poke); 191 assertTraps(kTrapMemOutOfBounds, poke);
194 192
195 assertEquals(0, growMem(1)); 193 assertEquals(0, growMem(1));
196 194
197 for(offset = 0; offset <= kPageSize - 4; offset++) { 195 for(offset = 0; offset <= kPageSize - 4; offset++) {
198 poke(20); 196 poke(20);
199 assertEquals(20, peek()); 197 assertEquals(20, peek());
200 } 198 }
201 199
202 for(offset = kPageSize - 3; offset <= kPageSize + 5; offset++) { 200 //TODO(gdeepti): Fix tests with correct write boundaries
203 assertTraps(kTrapMemOutOfBounds, peek); 201 //when runtime function is fixed.
204 }
205
206 offset = 3*kPageSize;
207 for (var i = 1; i < 4; i++) {
208 assertTraps(kTrapMemOutOfBounds, poke);
209 assertEquals(i, growMem(1));
210 }
211 poke(20);
212 assertEquals(20, peek());
213 }
214
215 testGrowMemoryZeroInitialSize();
216
217 function testGrowMemoryZeroInitialSize32() {
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(0, growMem(1));
229
230 for(offset = 0; offset <= kPageSize - 4; offset++) {
231 poke(20);
232 assertEquals(20, peek());
233 }
234
235 for(offset = kPageSize - 3; offset <= kPageSize + 5; offset++) {
236 assertTraps(kTrapMemOutOfBounds, peek);
237 }
238 }
239
240 testGrowMemoryZeroInitialSize32();
241
242 function testGrowMemoryZeroInitialSize16() {
243 var builder = genGrowMemoryBuilder();
244 var module = builder.instantiate();
245 var offset;
246 function peek() { return module.exports.load16(offset); }
247 function poke(value) { return module.exports.store16(offset, value); }
248 function growMem(pages) { return module.exports.grow_memory(pages); }
249
250 assertTraps(kTrapMemOutOfBounds, peek);
251 assertTraps(kTrapMemOutOfBounds, poke);
252
253 assertEquals(0, growMem(1));
254
255 for(offset = 0; offset <= kPageSize - 2; offset++) {
256 poke(20);
257 assertEquals(20, peek());
258 }
259
260 for(offset = kPageSize - 1; offset <= kPageSize + 5; offset++) {
261 assertTraps(kTrapMemOutOfBounds, peek);
262 }
263 }
264
265 testGrowMemoryZeroInitialSize16();
266
267 function testGrowMemoryZeroInitialSize8() {
268 var builder = genGrowMemoryBuilder();
269 var module = builder.instantiate();
270 var offset;
271 function peek() { return module.exports.load8(offset); }
272 function poke(value) { return module.exports.store8(offset, value); }
273 function growMem(pages) { return module.exports.grow_memory(pages); }
274
275 assertTraps(kTrapMemOutOfBounds, peek);
276 assertTraps(kTrapMemOutOfBounds, poke);
277
278 assertEquals(0, growMem(1));
279
280 for(offset = 0; offset <= kPageSize - 1; offset++) {
281 poke(20);
282 assertEquals(20, peek());
283 }
284
285 for(offset = kPageSize; offset <= kPageSize + 5; offset++) { 202 for(offset = kPageSize; offset <= kPageSize + 5; offset++) {
286 assertTraps(kTrapMemOutOfBounds, peek); 203 assertTraps(kTrapMemOutOfBounds, peek);
287 } 204 }
288 } 205 }
289 206
290 testGrowMemoryZeroInitialSize8(); 207 testGrowMemoryZeroInitialSize();
291 208
292 function testGrowMemoryTrapMaxPagesZeroInitialMemory() { 209 function testGrowMemoryTrapMaxPagesZeroInitialMemory() {
293 var builder = genGrowMemoryBuilder(); 210 var builder = genGrowMemoryBuilder();
294 var module = builder.instantiate(); 211 var module = builder.instantiate();
295 var maxPages = 16385; 212 var maxPages = 16385;
296 function growMem(pages) { return module.exports.grow_memory(pages); } 213 function growMem(pages) { return module.exports.grow_memory(pages); }
297 assertEquals(-1, growMem(maxPages)); 214 assertEquals(-1, growMem(maxPages));
298 } 215 }
299 216
300 testGrowMemoryTrapMaxPagesZeroInitialMemory(); 217 testGrowMemoryTrapMaxPagesZeroInitialMemory();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 poke(0xaced); 351 poke(0xaced);
435 assertEquals(0xaced, peek()); 352 assertEquals(0xaced, peek());
436 } 353 }
437 354
438 for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset++) { 355 for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset++) {
439 assertTraps(kTrapMemOutOfBounds, poke); 356 assertTraps(kTrapMemOutOfBounds, poke);
440 } 357 }
441 } 358 }
442 359
443 testGrowMemoryOutOfBoundsOffset(); 360 testGrowMemoryOutOfBoundsOffset();
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/mjsunit/wasm/import-memory.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698