Index: test/mjsunit/wasm/grow-memory.js |
diff --git a/test/mjsunit/wasm/grow-memory.js b/test/mjsunit/wasm/grow-memory.js |
index ecc105ee0d1d589f85f08689446c8791a5b8cfe9..d15cd935df03ac4e3090e78e1fe65e24d4f8f23a 100644 |
--- a/test/mjsunit/wasm/grow-memory.js |
+++ b/test/mjsunit/wasm/grow-memory.js |
@@ -38,6 +38,8 @@ function genGrowMemoryBuilder() { |
return builder; |
} |
+// TODO(gdeepti): Generate tests programatically for all the sizes instead of |
+// current implementation. |
function testGrowMemoryReadWrite32() { |
var builder = genGrowMemoryBuilder(); |
builder.addMemory(1, 1, false); |
@@ -197,15 +199,96 @@ function testGrowMemoryZeroInitialSize() { |
assertEquals(20, peek()); |
} |
- //TODO(gdeepti): Fix tests with correct write boundaries |
- //when runtime function is fixed. |
- for(offset = kPageSize; offset <= kPageSize + 5; offset++) { |
+ for(offset = kPageSize - 3; offset <= kPageSize + 5; offset++) { |
assertTraps(kTrapMemOutOfBounds, peek); |
} |
+ |
+ offset = 3*kPageSize; |
+ for (var i = 1; i < 4; i++) { |
+ assertTraps(kTrapMemOutOfBounds, poke); |
+ assertEquals(i, growMem(1)); |
+ } |
+ poke(20); |
+ assertEquals(20, peek()); |
} |
testGrowMemoryZeroInitialSize(); |
+function testGrowMemoryZeroInitialSize32() { |
+ var builder = genGrowMemoryBuilder(); |
+ var module = builder.instantiate(); |
+ var offset; |
+ function peek() { return module.exports.load(offset); } |
+ function poke(value) { return module.exports.store(offset, value); } |
+ function growMem(pages) { return module.exports.grow_memory(pages); } |
+ |
+ assertTraps(kTrapMemOutOfBounds, peek); |
+ assertTraps(kTrapMemOutOfBounds, poke); |
+ |
+ assertEquals(0, growMem(1)); |
+ |
+ for(offset = 0; offset <= kPageSize - 4; offset++) { |
+ poke(20); |
+ assertEquals(20, peek()); |
+ } |
+ |
+ for(offset = kPageSize - 3; offset <= kPageSize + 5; offset++) { |
+ assertTraps(kTrapMemOutOfBounds, peek); |
+ } |
+} |
+ |
+testGrowMemoryZeroInitialSize32(); |
+ |
+function testGrowMemoryZeroInitialSize16() { |
+ var builder = genGrowMemoryBuilder(); |
+ var module = builder.instantiate(); |
+ var offset; |
+ function peek() { return module.exports.load16(offset); } |
+ function poke(value) { return module.exports.store16(offset, value); } |
+ function growMem(pages) { return module.exports.grow_memory(pages); } |
+ |
+ assertTraps(kTrapMemOutOfBounds, peek); |
+ assertTraps(kTrapMemOutOfBounds, poke); |
+ |
+ assertEquals(0, growMem(1)); |
+ |
+ for(offset = 0; offset <= kPageSize - 2; offset++) { |
+ poke(20); |
+ assertEquals(20, peek()); |
+ } |
+ |
+ for(offset = kPageSize - 1; offset <= kPageSize + 5; offset++) { |
+ assertTraps(kTrapMemOutOfBounds, peek); |
+ } |
+} |
+ |
+testGrowMemoryZeroInitialSize16(); |
+ |
+function testGrowMemoryZeroInitialSize8() { |
+ var builder = genGrowMemoryBuilder(); |
+ var module = builder.instantiate(); |
+ var offset; |
+ function peek() { return module.exports.load8(offset); } |
+ function poke(value) { return module.exports.store8(offset, value); } |
+ function growMem(pages) { return module.exports.grow_memory(pages); } |
+ |
+ assertTraps(kTrapMemOutOfBounds, peek); |
+ assertTraps(kTrapMemOutOfBounds, poke); |
+ |
+ assertEquals(0, growMem(1)); |
+ |
+ for(offset = 0; offset <= kPageSize - 1; offset++) { |
+ poke(20); |
+ assertEquals(20, peek()); |
+ } |
+ |
+ for(offset = kPageSize; offset <= kPageSize + 5; offset++) { |
+ assertTraps(kTrapMemOutOfBounds, peek); |
+ } |
+} |
+ |
+testGrowMemoryZeroInitialSize8(); |
+ |
function testGrowMemoryTrapMaxPagesZeroInitialMemory() { |
var builder = genGrowMemoryBuilder(); |
var module = builder.instantiate(); |