mirror of https://github.com/tc39/test262.git
Harness: atomicsHelper.js tests
This commit is contained in:
parent
0e7319c015
commit
a0643d0bb6
|
@ -36,26 +36,20 @@ defines:
|
|||
return r;
|
||||
};
|
||||
|
||||
if (this.setTimeout === undefined) {
|
||||
(function(that) {
|
||||
that.setTimeout = function(callback, delay) {
|
||||
let p = Promise.resolve();
|
||||
let start = Date.now();
|
||||
let end = start + delay;
|
||||
function check() {
|
||||
if ((end - Date.now()) > 0) {
|
||||
p.then(check);
|
||||
}
|
||||
else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
$262.agent.setTimeout = function(callback, delay) {
|
||||
let p = Promise.resolve();
|
||||
let start = $262.agent.monotonicNow();
|
||||
let end = start + delay;
|
||||
function check() {
|
||||
if ($262.agent.monotonicNow() >= end) {
|
||||
p.then(check);
|
||||
}
|
||||
})(this);
|
||||
}
|
||||
|
||||
$262.agent.setTimeout = setTimeout;
|
||||
else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
p.then(check);
|
||||
};
|
||||
|
||||
$262.agent.getReportAsync = function() {
|
||||
return new Promise(function(resolve) {
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: >
|
||||
Testing $262.agent.* extensions
|
||||
info: |
|
||||
Including atomicsHelper.js will expose the functions:
|
||||
|
||||
- $262.agent.getReportAsync
|
||||
- $262.agent.getReport
|
||||
- $262.agent.safeBroadcastAsync
|
||||
- $262.agent.safeBroadcast
|
||||
- $262.agent.setTimeout
|
||||
- $262.agent.tryYield (wrapper for $262.agent.sleep)
|
||||
- $262.agent.trySleep (wrapper for $262.agent.sleep)
|
||||
|
||||
$262.agent.* relies on the presence of host defined agent capabilities
|
||||
|
||||
includes: [atomicsHelper.js]
|
||||
features: [Atomics, SharedArrayBuffer]
|
||||
---*/
|
||||
|
||||
const AGENT_READY_INDEX = 0;
|
||||
const AGENT_WAIT_INDEX = 1;
|
||||
|
||||
$262.agent.start(`
|
||||
$262.agent.receiveBroadcast((sab) => {
|
||||
const i32a = new Int32Array(sab);
|
||||
Atomics.add(i32a, ${AGENT_READY_INDEX}, 1);
|
||||
$262.agent.report(Atomics.wait(i32a, ${AGENT_WAIT_INDEX}, 0, Infinity));
|
||||
$262.agent.leaving();
|
||||
});
|
||||
`);
|
||||
|
||||
const i32a = new Int32Array(
|
||||
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
|
||||
);
|
||||
|
||||
$262.agent.safeBroadcast(i32a);
|
||||
$262.agent.waitUntil(i32a, AGENT_READY_INDEX, 1);
|
||||
|
||||
// An agent may have been interrupted between reporting its initial report
|
||||
// and the `Atomics.wait` call. Try to yield control to ensure the agent
|
||||
// actually started to wait.
|
||||
$262.agent.tryYield();
|
||||
|
||||
assert.sameValue(
|
||||
Atomics.notify(i32a, AGENT_WAIT_INDEX),
|
||||
1,
|
||||
'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)), AGENT_WAIT_INDEX) must return 1'
|
||||
);
|
||||
|
||||
assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() must return "ok"');
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: >
|
||||
Testing $262.agent.* extensions
|
||||
info: |
|
||||
Including atomicsHelper.js will expose the functions:
|
||||
|
||||
- $262.agent.getReportAsync
|
||||
- $262.agent.getReport
|
||||
- $262.agent.safeBroadcastAsync
|
||||
- $262.agent.safeBroadcast
|
||||
- $262.agent.setTimeout
|
||||
- $262.agent.tryYield (wrapper for $262.agent.sleep)
|
||||
- $262.agent.trySleep (wrapper for $262.agent.sleep)
|
||||
|
||||
$262.agent.* relies on the presence of host defined agent capabilities
|
||||
|
||||
includes: [atomicsHelper.js]
|
||||
features: [Atomics, Atomics.waitAsync, SharedArrayBuffer]
|
||||
flags: [async]
|
||||
---*/
|
||||
|
||||
const AGENT_READY_INDEX = 0;
|
||||
const AGENT_WAIT_INDEX = 1;
|
||||
|
||||
$262.agent.start(`
|
||||
$262.agent.receiveBroadcast(async (sab) => {
|
||||
const i32a = new Int32Array(sab);
|
||||
Atomics.add(i32a, ${AGENT_READY_INDEX}, 1);
|
||||
|
||||
$262.agent.report(await Atomics.waitAsync(i32a, ${AGENT_WAIT_INDEX}, 0, Infinity).value);
|
||||
$262.agent.leaving();
|
||||
});
|
||||
`);
|
||||
|
||||
const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4));
|
||||
|
||||
$262.agent.safeBroadcastAsync(i32a, AGENT_READY_INDEX, 1).then(async agentCount => {
|
||||
|
||||
assert.sameValue(
|
||||
Atomics.notify(i32a, AGENT_WAIT_INDEX),
|
||||
1,
|
||||
'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)), AGENT_WAIT_INDEX) must return 1'
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
await $262.agent.getReportAsync(),
|
||||
'ok',
|
||||
'(await $262.agent.getReportAsync()) resolves to the value "ok"'
|
||||
);
|
||||
}).then($DONE, $DONE);
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: >
|
||||
Testing $262.agent.* extensions
|
||||
info: |
|
||||
Including atomicsHelper.js will expose the functions:
|
||||
|
||||
- $262.agent.getReportAsync
|
||||
- $262.agent.getReport
|
||||
- $262.agent.safeBroadcastAsync
|
||||
- $262.agent.safeBroadcast
|
||||
- $262.agent.setTimeout
|
||||
- $262.agent.tryYield (wrapper for $262.agent.sleep)
|
||||
- $262.agent.trySleep (wrapper for $262.agent.sleep)
|
||||
|
||||
$262.agent.* relies on the presence of host defined agent capabilities
|
||||
|
||||
includes: [atomicsHelper.js]
|
||||
flags: [async]
|
||||
---*/
|
||||
|
||||
Promise.all([
|
||||
new Promise(resolve => $262.agent.setTimeout(() => resolve(2), 2)),
|
||||
new Promise(resolve => $262.agent.setTimeout(() => resolve(4), 4)),
|
||||
new Promise(resolve => $262.agent.setTimeout(() => resolve(6), 6)),
|
||||
]).then(results => {
|
||||
assert.sameValue(results[0], 2);
|
||||
assert.sameValue(results[1], 4);
|
||||
assert.sameValue(results[2], 6);
|
||||
}, $DONE).then($DONE, $DONE);
|
Loading…
Reference in New Issue