[wasm] Extend streaming-error-position test coverage.
R=clemensb@chromium.org TEST=mjsunit/wasm/streaming-error-position Change-Id: Ia1e95f5c5b0f90a98848951333c4c4aa4ebafefe Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1889880 Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#64657}
This commit is contained in:
parent
5a0e3df6f3
commit
18afb44ff4
@ -8,10 +8,25 @@
|
||||
|
||||
load('test/mjsunit/wasm/wasm-module-builder.js');
|
||||
|
||||
function testErrorPosition(bytes, pos, test_name) {
|
||||
function testErrorPositionAsyncOnly(bytes, pos, message) {
|
||||
let buffer = bytes.trunc_buffer();
|
||||
// Only test the streaming decoder since this kind of error is out of sync
|
||||
// with the non-streaming decoder, hence errors cannot be compared.
|
||||
assertThrowsAsync(
|
||||
WebAssembly.compile(bytes.trunc_buffer()), WebAssembly.CompileError,
|
||||
new RegExp('@\\+' + pos));
|
||||
WebAssembly.compile(buffer), WebAssembly.CompileError,
|
||||
new RegExp(message + '.*@\\+' + pos));
|
||||
}
|
||||
|
||||
function testErrorPosition(bytes, pos, message) {
|
||||
let buffer = bytes.trunc_buffer();
|
||||
// First check the non-streaming decoder as a reference.
|
||||
assertThrows(
|
||||
() => new WebAssembly.Module(buffer), WebAssembly.CompileError,
|
||||
new RegExp(message + '.*@\\+' + pos));
|
||||
// Next test the actual streaming decoder.
|
||||
assertThrowsAsync(
|
||||
WebAssembly.compile(buffer), WebAssembly.CompileError,
|
||||
new RegExp(message + '.*@\\+' + pos));
|
||||
}
|
||||
|
||||
(function testInvalidMagic() {
|
||||
@ -20,7 +35,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
kWasmH0, kWasmH1 + 1, kWasmH2, kWasmH3, kWasmV0, kWasmV1, kWasmV2, kWasmV3
|
||||
]);
|
||||
// Error at pos==0 because that's where the magic word is.
|
||||
testErrorPosition(bytes, 0, 'testInvalidMagic');
|
||||
testErrorPosition(bytes, 0, 'expected magic word');
|
||||
})();
|
||||
|
||||
(function testInvalidVersion() {
|
||||
@ -29,7 +44,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
kWasmH0, kWasmH1, kWasmH2, kWasmH3, kWasmV0, kWasmV1 + 1, kWasmV2, kWasmV3
|
||||
]);
|
||||
// Error at pos==4 because that's where the version word is.
|
||||
testErrorPosition(bytes, 4, 'testInvalidVersion');
|
||||
testErrorPosition(bytes, 4, 'expected version');
|
||||
})();
|
||||
|
||||
(function testSectionLengthInvalidVarint() {
|
||||
@ -38,7 +53,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
bytes.emit_u8(kTypeSectionCode);
|
||||
bytes.emit_bytes([0x80, 0x80, 0x80, 0x80, 0x80, 0x00]);
|
||||
let pos = bytes.length - 1 - 1;
|
||||
testErrorPosition(bytes, pos, 'testSectionLengthInvalidVarint');
|
||||
testErrorPosition(bytes, pos, 'expected section length');
|
||||
})();
|
||||
|
||||
(function testSectionLengthTooBig() {
|
||||
@ -47,7 +62,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
bytes.emit_u8(kTypeSectionCode);
|
||||
bytes.emit_u32v(0xffffff23);
|
||||
let pos = bytes.length - 1;
|
||||
testErrorPosition(bytes, pos, 'testSectionLengthTooBig');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'maximum function size');
|
||||
})();
|
||||
|
||||
(function testFunctionsCountInvalidVarint() {
|
||||
@ -71,7 +86,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
bytes.emit_bytes([0x80, 0x80, 0x80, 0x80, 0x80, 0x00]);
|
||||
|
||||
let pos = bytes.length - 1 - 1;
|
||||
testErrorPosition(bytes, pos, 'testFunctionsCountInvalidVarint');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'expected functions count');
|
||||
})();
|
||||
|
||||
(function testFunctionsCountTooBig() {
|
||||
@ -95,7 +110,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
bytes.emit_u32v(0xffffff23);
|
||||
|
||||
let pos = bytes.length - 1;
|
||||
testErrorPosition(bytes, pos, 'testFunctionsCountTooBig');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'maximum function size');
|
||||
})();
|
||||
|
||||
(function testFunctionsCountDoesNotMatch() {
|
||||
@ -119,7 +134,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
bytes.emit_u32v(5);
|
||||
|
||||
let pos = bytes.length - 1;
|
||||
testErrorPosition(bytes, pos, 'testFunctionsCountDoesNotMatch');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'function body count 5 mismatch');
|
||||
})();
|
||||
|
||||
(function testBodySizeInvalidVarint() {
|
||||
@ -148,7 +163,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
bytes.emit_bytes([0x80, 0x80, 0x80, 0x80, 0x80, 0x00]);
|
||||
|
||||
let pos = bytes.length - 1 - 1;
|
||||
testErrorPosition(bytes, pos, 'testBodySizeInvalidVarint');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'expected body size');
|
||||
})();
|
||||
|
||||
(function testBodySizeTooBig() {
|
||||
@ -177,7 +192,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
bytes.emit_u32v(0xffffff23);
|
||||
|
||||
let pos = bytes.length - 1;
|
||||
testErrorPosition(bytes, pos, 'testBodySizeTooBig');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'maximum function size');
|
||||
})();
|
||||
|
||||
(function testBodySizeDoesNotFit() {
|
||||
@ -206,7 +221,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
bytes.emit_u32v(20);
|
||||
|
||||
let pos = bytes.length - 1;
|
||||
testErrorPosition(bytes, pos, 'testBodySizeDoesNotFit');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'not enough code section bytes');
|
||||
})();
|
||||
|
||||
(function testBodySizeIsZero() {
|
||||
@ -235,7 +250,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
bytes.emit_u32v(0);
|
||||
|
||||
let pos = bytes.length - 1;
|
||||
testErrorPosition(bytes, pos, 'testBodySizeIsZero');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'invalid function length');
|
||||
})();
|
||||
|
||||
(function testStaleCodeSectionBytes() {
|
||||
@ -265,7 +280,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
]);
|
||||
|
||||
let pos = bytes.length - 1;
|
||||
testErrorPosition(bytes, pos, 'testStaleCodeSectionBytes');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'not all code section bytes were used');
|
||||
})();
|
||||
|
||||
(function testInvalidCode() {
|
||||
@ -297,7 +312,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
|
||||
// Find error at the index of kExprLocalGet.
|
||||
let pos = bytes.length - 1 - 1;
|
||||
testErrorPosition(bytes, pos, 'testInvalidCode');
|
||||
testErrorPosition(bytes, pos, 'invalid local index');
|
||||
})();
|
||||
|
||||
(function testCodeSectionRepeats() {
|
||||
@ -336,7 +351,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
]);
|
||||
|
||||
// Find error at the second kCodeSectionCode.
|
||||
testErrorPosition(bytes, pos, 'testCodeSectionRepeats');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'code section can only appear once');
|
||||
})();
|
||||
|
||||
(function testCodeSectionSizeZero() {
|
||||
@ -363,7 +378,7 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
|
||||
// Find error at the code section length.
|
||||
let pos = bytes.length - 1;
|
||||
testErrorPosition(bytes, pos, 'testCodeSectionSizeZero');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'code section cannot have size 0');
|
||||
})();
|
||||
|
||||
(function testInvalidSection() {
|
||||
@ -380,5 +395,5 @@ function testErrorPosition(bytes, pos, test_name) {
|
||||
]);
|
||||
|
||||
let pos = bytes.length - 1 - 1;
|
||||
testErrorPosition(bytes, pos, 'testInvalidSection');
|
||||
testErrorPositionAsyncOnly(bytes, pos, 'invalid local type');
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user