Commit a7bb323b authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[Atomics.waitAsync] Rewrite a test

This test should've been rewritten in the last
batch rewrite but wasn't.

Bug: v8:10239
Change-Id: Ic2949e6282f72975898ab7e9aefe3210bba71fbf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2319988
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69072}
parent 2264b3b0
......@@ -2,74 +2,67 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --harmony-sharedarraybuffer --harmony-atomics-waitasync
// Flags: --harmony-sharedarraybuffer --harmony-atomics-waitasync
(function test() {
const N = 10;
const script = `
const sab = new SharedArrayBuffer(16);
const i32a = new Int32Array(sab);
const location = 0;
const expected_value = 0;
const N = 10;
let log = [];
const N = ${N};
// Create N async waiters; the even ones without timeout and the odd ones
// with timeout.
for (let i = 0; i < N; ++i) {
let result;
if (i % 2 == 0) {
result = Atomics.waitAsync(i32a, 0, 0);
} else {
result = Atomics.waitAsync(i32a, 0, 0, i);
}
assertEquals(true, result.async);
result.value.then(
(value) => { log.push(value + " " + i); },
() => { assertUnreachable(); });
}
assertEquals(N, %AtomicsNumWaitersForTesting(i32a, 0));
assertEquals(0, %AtomicsNumUnresolvedAsyncPromisesForTesting(i32a, 0));
// Wait until the timed out waiters time out.
let rounds = 10000;
let previous_length = 0;
function wait() {
--rounds;
assertTrue(rounds > 0);
if (log.length > previous_length) {
// Made progress. Give the test more time.
previous_length = log.length;
rounds = 10000;
}
if (log.length < N / 2) {
setTimeout(wait, 0);
} else {
continuation1();
function start() {
// Create N async waiters; the even ones without timeout and the odd ones
// with timeout.
for (let i = 0; i < N; ++i) {
let result;
if (i % 2 == 0) {
result = Atomics.waitAsync(i32a, location, expected_value);
} else {
result = Atomics.waitAsync(i32a, location, expected_value, i);
}
result.value.then(
(value) => { postMessage(value + " " + i); },
() => { postMessage("unexpected"); });
}
}
setTimeout(wait, 0);
function continuation1() {
// Verify that all timed out waiters timed out in FIFO order.
assertEquals(N / 2, log.length);
let waiter_no = 1;
for (let i = 0; i < N / 2; ++i) {
assertEquals("timed-out " + waiter_no, log[i]);
waiter_no += 2;
}
function wakeUpRemainingWaiters() {
// Wake up all waiters
let notify_return_value = Atomics.notify(i32a, 0);
assertEquals(N / 2, notify_return_value);
assertEquals(0, %AtomicsNumWaitersForTesting(i32a, 0));
assertEquals(N / 2, %AtomicsNumUnresolvedAsyncPromisesForTesting(i32a, 0));
setTimeout(continuation2, 0);
let notify_return_value = Atomics.notify(i32a, location);
postMessage("notify return value " + notify_return_value);
}
function continuation2() {
// Verify that the waiters woke up in FIFO order.
assertEquals(N, log.length);
let waiter_no = 0;
for (let i = N / 2; i < N; ++i) {
assertEquals("ok " + waiter_no, log[i]);
waiter_no += 2;
function onmessage(param) {
if (param == "start") {
start();
} else if (param == "wakeUpRemainingWaiters") {
wakeUpRemainingWaiters();
}
}
})();
}`
const w = new Worker(script, {type : 'string'});
w.postMessage("start");
// Verify that all timed out waiters timed out in timeout order.
let waiter_no = 1;
for (let i = 0; i < N / 2; ++i) {
const m = w.getMessage();
assertEquals("timed-out " + waiter_no, m);
waiter_no += 2;
}
w.postMessage("wakeUpRemainingWaiters");
const m = w.getMessage();
assertEquals("notify return value " + N / 2, m);
// Verify that the waiters woke up in FIFO order.
waiter_no = 0;
for (let i = 0; i < N / 2; ++i) {
const m = w.getMessage();
assertEquals("ok " + waiter_no, m);
waiter_no += 2;
}
w.terminate();
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