test262/test/built-ins/Atomics/wake/count-defaults-to-infinity-...

76 lines
2.1 KiB
JavaScript

// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
Undefined count arg should result in an infinite count
info: |
Atomics.wake( typedArray, index, count )
3.If count is undefined, let c be +∞.
includes: [atomicsHelper.js]
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
const NUMAGENT = 4; // Total number of agents started
const WAKEUP = 0; // Index all agents are waiting on
$262.agent.start(`
$262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab);
$262.agent.report("A " + Atomics.wait(i32a, ${WAKEUP}, 0, 50));
$262.agent.leaving();
});
`);
$262.agent.start(`
$262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab);
$262.agent.report("B " + Atomics.wait(i32a, ${WAKEUP}, 0, 50));
$262.agent.leaving();
});
`);
$262.agent.start(`
$262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab);
$262.agent.report("C " + Atomics.wait(i32a, ${WAKEUP}, 0, 50));
$262.agent.leaving();
});
`);
$262.agent.start(`
$262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab);
$262.agent.report("D " + Atomics.wait(i32a, ${WAKEUP}, 0, 50));
$262.agent.leaving();
});
`);
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
$262.agent.broadcast(i32a.buffer);
$262.agent.sleep(20); // half of timeout
assert.sameValue(
Atomics.wake(i32a, WAKEUP, undefined),
NUMAGENT,
'Atomics.wake(i32a, WAKEUP, undefined) equals the value of `NUMAGENT` (4)'
);
const sortedReports = [];
for (var i = 0; i < NUMAGENT; i++) {
sortedReports.push(getReport());
}
sortedReports.sort();
assert.sameValue(sortedReports[0], 'A ok', 'The value of sortedReports[0] is "A ok"');
assert.sameValue(sortedReports[1], 'B ok', 'The value of sortedReports[1] is "B ok"');
assert.sameValue(sortedReports[2], 'C ok', 'The value of sortedReports[2] is "C ok"');
assert.sameValue(sortedReports[3], 'D ok', 'The value of sortedReports[3] is "D ok"');