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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« 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