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

83 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-03-20 15:40:33 +01:00
// 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]
2018-04-19 16:11:50 +02:00
features: [Atomics, SharedArrayBuffer, TypedArray]
2018-03-20 15:40:33 +01:00
---*/
const RUNNING = 0
const WAIT_INDEX = 1; // Index all agents are waiting on
const NUMAGENT = 4; // Total number of agents started
const BUFFER_SIZE = 5; // Index all agents are waiting on
2018-03-20 15:40:33 +01:00
$262.agent.start(`
$262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
$262.agent.report("A " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50));
$262.agent.leaving();
});
2018-03-20 15:40:33 +01:00
`);
$262.agent.start(`
$262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
$262.agent.report("B " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50));
$262.agent.leaving();
});
2018-03-20 15:40:33 +01:00
`);
$262.agent.start(`
$262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
$262.agent.report("C " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50));
$262.agent.leaving();
});
2018-03-20 15:40:33 +01:00
`);
$262.agent.start(`
$262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
$262.agent.report("D " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50));
$262.agent.leaving();
});
2018-03-20 15:40:33 +01:00
`);
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * BUFFER_SIZE)
);
2018-03-20 15:40:33 +01:00
$262.agent.broadcast(i32a.buffer);
2018-03-20 15:40:33 +01:00
// Wait for agents to be running.
$262.agent.waitUntil(i32a, RUNNING, NUMAGENT);
2018-03-20 15:40:33 +01:00
assert.sameValue(
Atomics.wake(i32a, WAIT_INDEX, undefined),
NUMAGENT,
'Atomics.wake(i32a, WAIT_INDEX, undefined) returns the value of `NUMAGENT` (4)'
);
2018-03-20 15:40:33 +01:00
const reports = [];
2018-03-20 15:40:33 +01:00
for (var i = 0; i < NUMAGENT; i++) {
reports.push($262.agent.getReport());
2018-03-20 15:40:33 +01:00
}
reports.sort();
2018-03-20 15:40:33 +01:00
assert.sameValue(reports[0], 'A ok', 'The value of reports[0] is "A ok"');
assert.sameValue(reports[1], 'B ok', 'The value of reports[1] is "B ok"');
assert.sameValue(reports[2], 'C ok', 'The value of reports[2] is "C ok"');
assert.sameValue(reports[3], 'D ok', 'The value of reports[3] is "D ok"');