v8/test/mjsunit/wasm/shared-arraybuffer-worker-simple-gc.js
Marja Hölttä 73d401b9d1 [test] Make worker related tests more fuzzable
Details: https://docs.google.com/document/d/1-Gi37Ks7rXMVVRkC_HkwGxenP7T1huQUOMrYOtkUCFk/edit?usp=sharing

Bug: v8:11340
Change-Id: Ia1d75270373a7ef2307e7ee0fd24da9ecfa27d18
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2643381
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72315}
2021-01-26 12:09:59 +00:00

86 lines
2.1 KiB
JavaScript

// 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: --expose-gc
const kNumIterations = 10;
function NewWorker() {
function workerCode() {
onmessage = (msg) => {
if (msg.memory) postMessage("ack");
if (msg.quit) postMessage("bye");
gc();
}
}
return new Worker(workerCode, {type: 'function'});
}
function PingWorker(worker, memory) {
worker.postMessage({memory: memory});
assertEquals("ack", worker.getMessage());
worker.postMessage({quit: true});
assertEquals("bye", worker.getMessage());
}
function AllocMemory() {
return new SharedArrayBuffer(1024);
}
function RunSingleWorkerSingleMemoryTest() {
print(arguments.callee.name);
let worker = NewWorker();
let first = AllocMemory();
for (let i = 0; i < kNumIterations; i++) {
print(`iteration ${i}`);
PingWorker(worker, first);
gc();
}
worker.terminate();
}
function RunSingleWorkerTwoMemoryTest() {
print(arguments.callee.name);
let worker = NewWorker();
let first = AllocMemory(), second = AllocMemory();
for (let i = 0; i < kNumIterations; i++) {
print(`iteration ${i}`);
PingWorker(worker, first);
PingWorker(worker, second);
gc();
}
worker.terminate();
}
function RunSingleWorkerMultipleMemoryTest() {
print(arguments.callee.name);
let worker = NewWorker();
let first = AllocMemory();
for (let i = 0; i < kNumIterations; i++) {
print(`iteration ${i}`);
PingWorker(worker, first);
PingWorker(worker, AllocMemory());
gc();
}
worker.terminate();
}
function RunMultipleWorkerMultipleMemoryTest() {
print(arguments.callee.name);
let first = AllocMemory();
for (let i = 0; i < kNumIterations; i++) {
print(`iteration ${i}`);
let worker = NewWorker();
PingWorker(worker, first);
PingWorker(worker, AllocMemory());
worker.terminate();
gc();
}
}
RunSingleWorkerSingleMemoryTest();
RunSingleWorkerTwoMemoryTest();
RunSingleWorkerMultipleMemoryTest();
RunMultipleWorkerMultipleMemoryTest();