Commit 30c3ea66 authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

[wasm] Speed up some tests in grow-memory

Rework the testMemoryGrowReadWrite and testMemoryGrowZeroInitialSize
tests. Combine the different sized tests (32, 16, 8 bit integers) into a
single base tests, taking in function arguments to specify which
load/store function to call from the module exports.

Also reduced the number of checks made in each test. Previously the test
was asserting on every single valid offset. Now it checks the first 5
and the last 5 of each page of memory. From a quick local test using
`time`, it speeds up this test on x64 from ~40s to ~20s.

There is more work to be done: there are other tests below that also
assert on each offset, we can change those in a future patch.

The goal is to be able to run this on arm simulators
sufficiently quickly, and not require to mark this test as slow.

Bug: v8:7783
Change-Id: I2b17cf1811de6c26332d7e8f91efbbac3e89f6e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2116601Reviewed-by: 's avatarDeepti Gandluri <gdeepti@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66848}
parent 4132d725
...@@ -40,148 +40,83 @@ function genMemoryGrowBuilder() { ...@@ -40,148 +40,83 @@ function genMemoryGrowBuilder() {
var kV8MaxPages = 65536; var kV8MaxPages = 65536;
// TODO(gdeepti): Generate tests programatically for all the sizes instead of function testMemoryGrowReadWriteBase(size, load_fn, store_fn) {
// current implementation. // size is the number of bytes for load and stores.
function testMemoryGrowReadWrite32() {
var builder = genMemoryGrowBuilder(); var builder = genMemoryGrowBuilder();
builder.addMemory(1, undefined, false); builder.addMemory(1, undefined, false);
var module = builder.instantiate(); var module = builder.instantiate();
var offset; var offset;
function peek() { return module.exports.load(offset); } var load = module.exports[load_fn];
function poke(value) { return module.exports.store(offset, value); } var store = module.exports[store_fn];
function peek() { return load(offset); }
function poke(value) { return store(offset, value); }
function growMem(pages) { return module.exports.grow_memory(pages); } function growMem(pages) { return module.exports.grow_memory(pages); }
for(offset = 0; offset <= (kPageSize - 4); offset+=4) { // Instead of checking every n-th offset, check the first 5.
for(offset = 0; offset <= (4*size); offset+=size) {
poke(20); poke(20);
assertEquals(20, peek()); assertEquals(20, peek());
} }
for (offset = kPageSize - 3; offset < kPageSize + 4; offset++) { for (offset = kPageSize - (size - 1); offset < kPageSize + size; offset++) {
assertTraps(kTrapMemOutOfBounds, poke); assertTraps(kTrapMemOutOfBounds, poke);
assertTraps(kTrapMemOutOfBounds, peek); assertTraps(kTrapMemOutOfBounds, peek);
} }
assertEquals(1, growMem(3)); assertEquals(1, growMem(3));
for (offset = kPageSize; offset <= 4*kPageSize -4; offset+=4) { for (let n = 1; n <= 3; n++) {
poke(20); for (offset = n * kPageSize - 5 * size; offset <= n * kPageSize + 4 * size;
assertEquals(20, peek()); offset += size) {
} // Check the 5 offsets to the before and after the n-th page.
for (offset = 4*kPageSize - 3; offset < 4*kPageSize + 4; offset++) { // page n-1 page n page n+1
assertTraps(kTrapMemOutOfBounds, poke); // +---- ... ------------+---------- ... +------ ...
assertTraps(kTrapMemOutOfBounds, peek); // | | | ... | | | | | | | | | | | | ... | | | | ...
} // <+> ^ ^
// | first offset last offset
assertEquals(4, growMem(15)); // +-> size bytes
poke(20);
for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset+=4) { assertEquals(20, peek());
poke(20); }
assertEquals(20, peek());
}
for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 4; offset+=4) {
poke(20);
assertEquals(20, peek());
}
for (offset = 19*kPageSize - 3; offset < 19*kPageSize + 5; offset++) {
assertTraps(kTrapMemOutOfBounds, poke);
assertTraps(kTrapMemOutOfBounds, peek);
} }
}
testMemoryGrowReadWrite32();
function testMemoryGrowReadWrite16() {
var builder = genMemoryGrowBuilder();
builder.addMemory(1, undefined, false);
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); }
for(offset = 0; offset <= (kPageSize - 2); offset+=2) { // Check the last 5 valid offsets of the last page.
for (offset = 4*kPageSize-size-(4*size); offset <= 4*kPageSize -size; offset+=size) {
poke(20); poke(20);
assertEquals(20, peek()); assertEquals(20, peek());
} }
for (offset = kPageSize - 1; offset < kPageSize + 4; offset++) {
assertTraps(kTrapMemOutOfBounds, poke);
assertTraps(kTrapMemOutOfBounds, peek);
}
assertEquals(1, growMem(3)); for (offset = 4*kPageSize - (size-1); offset < 4*kPageSize + size; offset++) {
for (offset = kPageSize; offset <= 4*kPageSize -2; offset+=2) {
poke(20);
assertEquals(20, peek());
}
for (offset = 4*kPageSize - 1; offset < 4*kPageSize + 4; offset++) {
assertTraps(kTrapMemOutOfBounds, poke); assertTraps(kTrapMemOutOfBounds, poke);
assertTraps(kTrapMemOutOfBounds, peek); assertTraps(kTrapMemOutOfBounds, peek);
} }
assertEquals(4, growMem(15)); assertEquals(4, growMem(15));
for (offset = 4*kPageSize - 2; offset <= 4*kPageSize + 4; offset+=2) { for (offset = 4*kPageSize - (size-1); offset <= 4*kPageSize + size; offset+=size) {
poke(20); poke(20);
assertEquals(20, peek()); assertEquals(20, peek());
} }
for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 2; offset+=2) { for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - size; offset+=size) {
poke(20); poke(20);
assertEquals(20, peek()); assertEquals(20, peek());
} }
for (offset = 19*kPageSize - 1; offset < 19*kPageSize + 5; offset++) { for (offset = 19*kPageSize - (size-1); offset < 19*kPageSize + 5; offset++) {
assertTraps(kTrapMemOutOfBounds, poke); assertTraps(kTrapMemOutOfBounds, poke);
assertTraps(kTrapMemOutOfBounds, peek); assertTraps(kTrapMemOutOfBounds, peek);
} }
} }
testMemoryGrowReadWrite16(); (function testMemoryGrowReadWrite32() {
testMemoryGrowReadWriteBase(4, "load", "store");
function testMemoryGrowReadWrite8() { })();
var builder = genMemoryGrowBuilder();
builder.addMemory(1, undefined, false);
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); }
for(offset = 0; offset <= kPageSize - 1; offset++) {
poke(20);
assertEquals(20, peek());
}
for (offset = kPageSize; offset < kPageSize + 4; offset++) {
assertTraps(kTrapMemOutOfBounds, poke);
assertTraps(kTrapMemOutOfBounds, peek);
}
assertEquals(1, growMem(3));
for (offset = kPageSize; offset <= 4*kPageSize -1; offset++) {
poke(20);
assertEquals(20, peek());
}
for (offset = 4*kPageSize; offset < 4*kPageSize + 4; offset++) {
assertTraps(kTrapMemOutOfBounds, poke);
assertTraps(kTrapMemOutOfBounds, peek);
}
assertEquals(4, growMem(15));
for (offset = 4*kPageSize; offset <= 4*kPageSize + 4; offset++) { (function testMemoryGrowReadWrite16() {
poke(20); testMemoryGrowReadWriteBase(2, "load16", "store16");
assertEquals(20, peek()); })();
}
for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 1; offset++) {
poke(20);
assertEquals(20, peek());
}
for (offset = 19*kPageSize; offset < 19*kPageSize + 5; offset++) {
assertTraps(kTrapMemOutOfBounds, poke);
assertTraps(kTrapMemOutOfBounds, peek);
}
}
testMemoryGrowReadWrite8(); (function testMemoryGrowReadWrite8() {
testMemoryGrowReadWriteBase(1, "load8", "store8");
})();
function testMemoryGrowZeroInitialSize() { function testMemoryGrowZeroInitialSize() {
var builder = genMemoryGrowBuilder(); var builder = genMemoryGrowBuilder();
...@@ -217,13 +152,15 @@ function testMemoryGrowZeroInitialSize() { ...@@ -217,13 +152,15 @@ function testMemoryGrowZeroInitialSize() {
testMemoryGrowZeroInitialSize(); testMemoryGrowZeroInitialSize();
function testMemoryGrowZeroInitialSize32() { function testMemoryGrowZeroInitialSizeBase(size, load_fn, store_fn) {
var builder = genMemoryGrowBuilder(); var builder = genMemoryGrowBuilder();
builder.addMemory(0, undefined, false); builder.addMemory(0, undefined, false);
var module = builder.instantiate(); var module = builder.instantiate();
var offset; var offset;
function peek() { return module.exports.load(offset); } var load = module.exports[load_fn];
function poke(value) { return module.exports.store(offset, value); } var store = module.exports[store_fn];
function peek() { return load(offset); }
function poke(value) { return store(offset, value); }
function growMem(pages) { return module.exports.grow_memory(pages); } function growMem(pages) { return module.exports.grow_memory(pages); }
assertTraps(kTrapMemOutOfBounds, peek); assertTraps(kTrapMemOutOfBounds, peek);
...@@ -231,69 +168,34 @@ function testMemoryGrowZeroInitialSize32() { ...@@ -231,69 +168,34 @@ function testMemoryGrowZeroInitialSize32() {
assertEquals(0, growMem(1)); assertEquals(0, growMem(1));
for(offset = 0; offset <= kPageSize - 4; offset++) { // Instead of checking every offset, check the first 5.
for(offset = 0; offset <= 4; offset++) {
poke(20); poke(20);
assertEquals(20, peek()); assertEquals(20, peek());
} }
for(offset = kPageSize - 3; offset <= kPageSize + 5; offset++) { // Check the last 5 valid ones.
assertTraps(kTrapMemOutOfBounds, peek); for(offset = kPageSize - (size * 4); offset <= kPageSize - size; offset++) {
}
}
testMemoryGrowZeroInitialSize32();
function testMemoryGrowZeroInitialSize16() {
var builder = genMemoryGrowBuilder();
builder.addMemory(0, undefined, false);
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); poke(20);
assertEquals(20, peek()); assertEquals(20, peek());
} }
for(offset = kPageSize - 1; offset <= kPageSize + 5; offset++) { for(offset = kPageSize - (size - 1); offset <= kPageSize + 5; offset++) {
assertTraps(kTrapMemOutOfBounds, peek); assertTraps(kTrapMemOutOfBounds, peek);
} }
} }
testMemoryGrowZeroInitialSize16(); (function testMemoryGrowZeroInitialSize32() {
testMemoryGrowZeroInitialSizeBase(4, "load", "store");
function testMemoryGrowZeroInitialSize8() { })();
var builder = genMemoryGrowBuilder();
builder.addMemory(0, undefined, false);
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++) { (function testMemoryGrowZeroInitialSize16() {
assertTraps(kTrapMemOutOfBounds, peek); testMemoryGrowZeroInitialSizeBase(2, "load16", "store16");
} })();
}
testMemoryGrowZeroInitialSize8(); (function testMemoryGrowZeroInitialSize8() {
testMemoryGrowZeroInitialSizeBase(1, "load8", "store8");
})();
function testMemoryGrowTrapMaxPagesZeroInitialMemory() { function testMemoryGrowTrapMaxPagesZeroInitialMemory() {
var builder = genMemoryGrowBuilder(); var builder = genMemoryGrowBuilder();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment