Commit 40df6ed8 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Test worker termination while compiling

If a worker terminates while a wasm finisher task is scheduled, we try
to cancel that task even though the platform already deleted it. This
results in UBSan failures, ASan failures or crashes.
The bug itself is fixed on the v8 side in https://crrev.com/c/1209344,
but the test needs to be a layout test, thus on the chromium side.

R=ahaas@chromium.org

Bug: chromium:875579
Change-Id: I98f19869044299801eb521d97f417b403ca356c0
Reviewed-on: https://chromium-review.googlesource.com/1209602Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589459}
parent 65e2f0f3
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="resources/wasm-constants.js"></script>
<script src="resources/wasm-module-builder.js"></script>
<script>
const test = async_test("TestWasmWorkerTerminationWhileCompiling");
const kNumWorkers = 8;
const kNumFunctions = 5000;
// This function is executed by each worker.
function workerFunction() {
onmessage = function(event) {
// Start asynchronous compilation, then notify the main thread about that.
WebAssembly.compile(event.data)
.catch(e => postMessage("compilation error: " + e));
postMessage("compiling");
};
}
// Build a wasm module with a number of function, such that the workers need
// some time compiling it.
const builder = new WasmModuleBuilder();
for (var i = 0; i < kNumFunctions; ++i) {
builder.addFunction('func' + i, kSig_v_v).addBody([kExprCallFunction, 0]);
}
const module_bytes = builder.toBuffer();
const blobURL =
URL.createObjectURL(new Blob(['(' + workerFunction.toString() + ')()']));
// Counter to wait for all workers to start compilation.
var outstanding_worker_events = kNumWorkers;
const workers = [];
function workerEvent(event) {
// If the event data is not "compiling", this is an error in the worker.
assert_equals(event.data, "compiling");
// Decrement counter of workers that did not start compiling yet.
// Do nothing if there are still outstanding workers.
assert_greater_than(outstanding_worker_events, 0);
if (--outstanding_worker_events > 0) return;
// All workers started compiling! Now terminate them all. This should not
// crash.
for (let i = 0; i < kNumWorkers; ++i) {
workers[i].terminate();
}
test.done();
}
for (let i = 0; i < kNumWorkers; ++i) {
const worker = new Worker(blobURL);
worker.onmessage = test.step_func(workerEvent);
worker.postMessage(module_bytes);
workers.push(worker);
}
</script>
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