Commit bd8fb77f authored by Frederik Gossen's avatar Frederik Gossen Committed by Commit Bot

[wasm-hints] Test Compilation With Hints

Extend test coverage for Wasm compilation with compilation hints. Tests
cover, in particular, error handling in streaming compilation and
asynchronous compilation.

Bug: v8:9003
Change-Id: Id46e02904a3a5df60c2617b11445bdc04c8b3b1d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1566520
Commit-Queue: Frederik Gossen <frgossen@google.com>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60876}
parent 3295fb73
This diff is collapsed.
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.
// Flags: --experimental-wasm-compilation-hints
load('test/mjsunit/wasm/wasm-module-builder.js');
(function testCompileWithBadLazyHint() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction('id', kSig_i_i)
.addBody([kExprGetLocal, 0])
.giveCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierOptimized,
kCompilationHintTierBaseline)
.exportFunc();
let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.compile(bytes)
.then(assertUnreachable,
error => assertEquals("WebAssembly.compile(): Invalid compilation " +
"hint 0x2d (forbidden downgrade) @+49", error.message)));
})();
(function testCompileWithBadLazyFunctionBody() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction('id', kSig_i_l)
.addBody([kExprGetLocal, 0])
.giveCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierDefault,
kCompilationHintTierDefault)
.exportFunc();
let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.compile(bytes)
.then(assertUnreachable,
error => assertEquals("WebAssembly.compile(): type error in " +
"merge[0] (expected i32, got i64) @+56", error.message)));
})();
(function testCompileEmptyModule() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.compile(bytes));
})();
(function testCompileLazyModule() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction('id', kSig_i_i)
.addBody([kExprGetLocal, 0])
.giveCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierDefault,
kCompilationHintTierDefault)
.exportFunc();
let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.instantiate(bytes)
.then(({module, instance}) => assertEquals(42, instance.exports.id(42))));
})();
...@@ -92,7 +92,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -92,7 +92,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
.giveCompilationHint(kCompilationHintStrategyEager, .giveCompilationHint(kCompilationHintStrategyEager,
kCompilationHintTierDefault, kCompilationHintTierDefault,
kCompilationHintTierOptimized) kCompilationHintTierOptimized)
let instance = builder.instantiate(); builder.instantiate();
})(); })();
(function testDecodeCompilationHintsSectionTopTierDefault() { (function testDecodeCompilationHintsSectionTopTierDefault() {
......
...@@ -23,11 +23,12 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -23,11 +23,12 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
kCompilationHintTierDefault) kCompilationHintTierDefault)
.exportFunc(); .exportFunc();
let bytes = builder.toBuffer(); let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes), {mod: {pow: Math.pow}}).then( assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes),
({module, instance}) => assertEquals(27, instance.exports.upow2(3)))); {mod: {pow: Math.pow}})
.then(({module, instance}) => assertEquals(27, instance.exports.upow2(3))));
})(); })();
(function testInstantiateStreamingWithBadHint() { (function testInstantiateStreamingWithBadLazyHint() {
print(arguments.callee.name); print(arguments.callee.name);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addImport('mod', 'pow', kSig_i_ii); builder.addImport('mod', 'pow', kSig_i_ii);
...@@ -44,14 +45,16 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -44,14 +45,16 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
kCompilationHintTierBaseline) kCompilationHintTierBaseline)
.exportFunc(); .exportFunc();
let bytes = builder.toBuffer(); let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes), {mod: {pow: Math.pow}}).then( assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes),
assertUnreachable, {mod: {pow: Math.pow}})
error => assertEquals("WebAssembly.compile(): Invalid compilation hint 0x2d (forbidden downgrade) @+78", error.message))); .then(assertUnreachable,
error => assertEquals("WebAssembly.compile(): Invalid compilation " +
"hint 0x2d (forbidden downgrade) @+78",
error.message)));
})(); })();
(function testInstantiateStreamingWithBadFunctionBody() { (function testInstantiateStreamingWithBadLazyFunctionBody() {
print(arguments.callee.name); print(arguments.callee.name);
let invalidFunctionCode = 0x65;
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addImport('mod', 'pow', kSig_f_ff); builder.addImport('mod', 'pow', kSig_f_ff);
builder.addFunction('upow', kSig_i_i) builder.addFunction('upow', kSig_i_i)
...@@ -67,9 +70,11 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -67,9 +70,11 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
kCompilationHintTierDefault) kCompilationHintTierDefault)
.exportFunc(); .exportFunc();
let bytes = builder.toBuffer(); let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes), {mod: {pow: Math.pow}}).then( assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes),
assertUnreachable, {mod: {pow: Math.pow}})
error => assertEquals("WebAssembly.compile(): call[1] expected type f32, found get_local of type i32 @+94", error.message))); .then(assertUnreachable,
error => assertEquals("WebAssembly.compile(): call[1] expected " +
"type f32, found get_local of type i32 @+94", error.message)));
})(); })();
(function testInstantiateStreamingEmptyModule() { (function testInstantiateStreamingEmptyModule() {
...@@ -77,10 +82,11 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -77,10 +82,11 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addImport('mod', 'pow', kSig_i_ii); builder.addImport('mod', 'pow', kSig_i_ii);
let bytes = builder.toBuffer(); let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes), {mod: {pow: Math.pow}})); assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes),
{mod: {pow: Math.pow}}));
})(); })();
(function testInstantiateStreamingAllHintsLazy() { (function testInstantiateStreamingLazyModule() {
print(arguments.callee.name); print(arguments.callee.name);
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addImport('mod', 'pow', kSig_i_ii); builder.addImport('mod', 'pow', kSig_i_ii);
...@@ -93,6 +99,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js'); ...@@ -93,6 +99,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
kCompilationHintTierDefault) kCompilationHintTierDefault)
.exportFunc(); .exportFunc();
let bytes = builder.toBuffer(); let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes), {mod: {pow: Math.pow}}).then( assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes),
({module, instance}) => assertEquals(27, instance.exports.upow(3)))); {mod: {pow: Math.pow}})
.then(({module, instance}) => assertEquals(27, instance.exports.upow(3))));
})(); })();
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.
// Flags: --experimental-wasm-compilation-hints
load('test/mjsunit/wasm/wasm-module-builder.js');
(function testCompileWithBadLazyHint() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction('id', kSig_i_i)
.addBody([kExprGetLocal, 0])
.giveCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierOptimized,
kCompilationHintTierBaseline)
.exportFunc();
assertThrows(() => builder.toModule(),
WebAssembly.CompileError,
"WebAssembly.Module(): Invalid compilation hint 0x2d " +
"(forbidden downgrade) @+49");
})();
(function testCompileWithBadLazyFunctionBody() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction('id', kSig_i_l)
.addBody([kExprGetLocal, 0])
.giveCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierDefault,
kCompilationHintTierDefault)
.exportFunc();
assertThrows(() => builder.toModule(),
WebAssembly.CompileError,
"WebAssembly.Module(): Compiling function #0:\"id\" failed: type error " +
"in merge[0] (expected i32, got i64) @+56");
})();
(function testCompileEmptyModule() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.toModule();
})();
(function testCompileLazyModule() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction('id', kSig_i_i)
.addBody([kExprGetLocal, 0])
.giveCompilationHint(kCompilationHintStrategyLazy,
kCompilationHintTierDefault,
kCompilationHintTierDefault)
.exportFunc();
assertEquals(42, builder.instantiate().exports.id(42));
})();
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