Skip to content

Commit bbc1879

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[wasm] Do not treat wasm throw exceptions inside LiveTests as failures
The test case testWasmCodeGenerationAndCompilationAndExecution treats a wasm program that throws an exception as a failure and expects this failure rate to remain below a certain threshold. With the exception- handling proposal (https://github.com/WebAssembly/exception-handling) wasm adds support for deliberately throwing exceptions. As these should also be fuzzed, generating a throw should not be treated as a failure by this test case. This change handles this by wrapping the call to the exported wasm function like this: try { instance.exports.w0(); } catch (e) { if (!(e instance of WebAssembly.Exception)) rethrow e; } Still, this highlights the issue of many wasm programs throwing an unconditional exception, so the weight to generate a throw inside wasm is now significantly lowered as well. (The same does not apply to a rethrow as a rethrow is only reachable when such a "low chance" throw was already emitted, so keeping that higher prevents us from making it exceedingly rare to cover rethrow edges.) Change-Id: I17c270edd87aa7d8af97efa1eb6eaded420e9a8f Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/7963393 Auto-Submit: Matthias Liedtke <[email protected]> Reviewed-by: Carl Smith <[email protected]> Commit-Queue: Matthias Liedtke <[email protected]>
1 parent cf4badc commit bbc1879

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ public let codeGeneratorWeights = [
275275
"WasmLegacyTryGenerator": 8,
276276
"WasmLegacyCatchGenerator": 8,
277277
"WasmLegacyTryDelegateGenerator": 8,
278-
"WasmThrowGenerator": 8,
279-
"WasmRethrowGenerator": 8,
278+
"WasmThrowGenerator": 2,
279+
"WasmRethrowGenerator": 10,
280280
"WasmBranchGenerator": 10,
281281
"WasmBranchIfGenerator": 10,
282282
"WasmJsCallGenerator": 30,

Tests/FuzzilliTests/LiveTests.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LiveTests: XCTestCase {
4545
}
4646
// Make at least one Wasm global available
4747
b.createWasmGlobal(value: .wasmi32(1337), isMutable: true)
48-
// Make at laest one Wasm tag of each kind available.
48+
// Make at least one Wasm tag of each kind available.
4949
b.createWasmJSTag()
5050
b.createWasmTag(parameterTypes: [.wasmi32, .wasmf64])
5151

@@ -72,7 +72,7 @@ class LiveTests: XCTestCase {
7272
}
7373
// Make at least one Wasm global available
7474
b.createWasmGlobal(value: .wasmi32(1337), isMutable: true)
75-
// Make at laest one Wasm tag of each kind available.
75+
// Make at least one Wasm tag of each kind available.
7676
b.createWasmJSTag()
7777
b.createWasmTag(parameterTypes: [.wasmi32, .wasmf64])
7878

@@ -84,18 +84,28 @@ class LiveTests: XCTestCase {
8484
}
8585
}
8686

87-
b.callMethod(m.getExportedMethod(at: 0), on: m.loadExports())
87+
// The wasm exception handling proposal contains instructions to deliberately trigger
88+
// exceptions. Catch these exceptions here to not treat them as test failures.
89+
b.buildTryCatchFinally {
90+
b.callMethod(m.getExportedMethod(at: 0), on: m.loadExports())
91+
} catchBody: { exception in
92+
let wasmGlobal = b.createNamedVariable(forBuiltin: "WebAssembly")
93+
let wasmException = b.getProperty("Exception", of: wasmGlobal)
94+
b.buildIf(b.unary(.LogicalNot, b.testInstanceOf(exception, wasmException))) {
95+
b.throwException(exception)
96+
}
97+
}
8898
}
8999

90100
// TODO(cffsmith): Try to lower this
91-
// We expect a maximum of 50% of Wasm execution attempts to fail
92-
checkFailureRate(testResults: results, maxFailureRate: 0.50)
101+
// We expect a maximum of 25% of Wasm execution attempts to fail.
102+
checkFailureRate(testResults: results, maxFailureRate: 0.25)
93103
}
94104

95105
// The closure can use the ProgramBuilder to emit a program of a specific
96106
// shape that is then executed with the given runner. We then check that
97107
// we stay below the maximum failure rate over the given number of iterations.
98-
static func runLiveTest(iterations n: Int = 250, withRunner runner: JavaScriptExecutor, body: (inout ProgramBuilder) -> Void) throws -> (failureRate: Double, failureMessages: [String: Int]) {
108+
static func runLiveTest(iterations n: Int = 250, withRunner runner: JavaScriptExecutor, body: (ProgramBuilder) -> Void) throws -> (failureRate: Double, failureMessages: [String: Int]) {
99109
let liveTestConfig = Configuration(logLevel: .error, enableInspection: true)
100110

101111
// We have to use the proper JavaScriptEnvironment here.
@@ -120,9 +130,9 @@ class LiveTests: XCTestCase {
120130
var results = [ExecutionResult?](repeating: nil, count: n)
121131

122132
for _ in 0..<n {
123-
var b = fuzzer.makeBuilder()
133+
let b = fuzzer.makeBuilder()
124134

125-
body(&b)
135+
body(b)
126136

127137
let program = b.finalize()
128138
let jsProgram = fuzzer.lifter.lift(program)

0 commit comments

Comments
 (0)