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

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

Issue 2416543002: [wasm] Fix bounds check for zero initial memory. (Closed)
Patch Set: Fix bot failure 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.
41 function testGrowMemoryReadWrite32() { 43 function testGrowMemoryReadWrite32() {
42 var builder = genGrowMemoryBuilder(); 44 var builder = genGrowMemoryBuilder();
43 builder.addMemory(1, 1, false); 45 builder.addMemory(1, 1, false);
44 var module = builder.instantiate(); 46 var module = builder.instantiate();
45 var offset; 47 var offset;
46 function peek() { return module.exports.load(offset); } 48 function peek() { return module.exports.load(offset); }
47 function poke(value) { return module.exports.store(offset, value); } 49 function poke(value) { return module.exports.store(offset, value); }
48 function growMem(pages) { return module.exports.grow_memory(pages); } 50 function growMem(pages) { return module.exports.grow_memory(pages); }
49 51
50 for(offset = 0; offset <= (kPageSize - 4); offset+=4) { 52 for(offset = 0; offset <= (kPageSize - 4); offset+=4) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 assertTraps(kTrapMemOutOfBounds, peek); 192 assertTraps(kTrapMemOutOfBounds, peek);
191 assertTraps(kTrapMemOutOfBounds, poke); 193 assertTraps(kTrapMemOutOfBounds, poke);
192 194
193 assertEquals(0, growMem(1)); 195 assertEquals(0, growMem(1));
194 196
195 for(offset = 0; offset <= kPageSize - 4; offset++) { 197 for(offset = 0; offset <= kPageSize - 4; offset++) {
196 poke(20); 198 poke(20);
197 assertEquals(20, peek()); 199 assertEquals(20, peek());
198 } 200 }
199 201
200 //TODO(gdeepti): Fix tests with correct write boundaries 202 for(offset = kPageSize - 3; offset <= kPageSize + 5; offset++) {
201 //when runtime function is fixed. 203 assertTraps(kTrapMemOutOfBounds, peek);
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
202 for(offset = kPageSize; offset <= kPageSize + 5; offset++) { 285 for(offset = kPageSize; offset <= kPageSize + 5; offset++) {
203 assertTraps(kTrapMemOutOfBounds, peek); 286 assertTraps(kTrapMemOutOfBounds, peek);
204 } 287 }
205 } 288 }
206 289
207 testGrowMemoryZeroInitialSize(); 290 testGrowMemoryZeroInitialSize8();
208 291
209 function testGrowMemoryTrapMaxPagesZeroInitialMemory() { 292 function testGrowMemoryTrapMaxPagesZeroInitialMemory() {
210 var builder = genGrowMemoryBuilder(); 293 var builder = genGrowMemoryBuilder();
211 var module = builder.instantiate(); 294 var module = builder.instantiate();
212 var maxPages = 16385; 295 var maxPages = 16385;
213 function growMem(pages) { return module.exports.grow_memory(pages); } 296 function growMem(pages) { return module.exports.grow_memory(pages); }
214 assertEquals(-1, growMem(maxPages)); 297 assertEquals(-1, growMem(maxPages));
215 } 298 }
216 299
217 testGrowMemoryTrapMaxPagesZeroInitialMemory(); 300 testGrowMemoryTrapMaxPagesZeroInitialMemory();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 poke(0xaced); 434 poke(0xaced);
352 assertEquals(0xaced, peek()); 435 assertEquals(0xaced, peek());
353 } 436 }
354 437
355 for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset++) { 438 for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset++) {
356 assertTraps(kTrapMemOutOfBounds, poke); 439 assertTraps(kTrapMemOutOfBounds, poke);
357 } 440 }
358 } 441 }
359 442
360 testGrowMemoryOutOfBoundsOffset(); 443 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