Atomics.wake: additional coverage. ()

Completes gh-1472
This commit is contained in:
Rick Waldron 2018-04-25 10:00:35 -04:00 committed by Leo Balter
parent 0b36f27000
commit d12d7d270e
19 changed files with 297 additions and 73 deletions

View File

@ -87,4 +87,4 @@ assert.sameValue(Atomics.wake(int32Array, 0, 1), 1);
orderAgentsWereWoken += getReport();
assert.sameValue(orderWhichAgentsWereStarted ,orderAgentsWereWoken); // agents should wake in the same order as they were started FIFO
assert.sameValue(orderWhichAgentsWereStarted, orderAgentsWereWoken); // agents should wake in the same order as they were started FIFO

View File

@ -5,6 +5,12 @@
esid: sec-atomics.wake
description: >
Test range checking of Atomics.wake on arrays that allow atomic operations
info: |
Atomics.wake( typedArray, index, count )
1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
..
includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/
@ -14,12 +20,12 @@ var views = [Int32Array];
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
views.push(BigUint64Array);
}
testWithTypedArrayConstructors(function(TA) {
let view = new TA(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.wake(view, Idx, 0)); // Even with waking zero
assert.throws(RangeError, () => Atomics.wake(view, IdxGen(view), 0)); // Even with waking zero
});
}, views);

View File

@ -4,7 +4,24 @@
/*---
esid: sec-atomics.wake
description: >
Allowed boundary cases of the third 'count' argument to Atomics.wake
Allowed boundary cases for 'count' argument to Atomics.wake
info: |
Atomics.wake( typedArray, index, count )
...
3. If count is undefined, let c be +.
4. Else,
a. Let intCount be ? ToInteger(count).
...
ToInteger ( argument )
1. Let number be ? ToNumber(argument).
2. If number is NaN, return +0.
3. If number is +0, -0, +, or -, return number.
4. Return the number value that is the same sign as number
and whose magnitude is floor(abs(number)).
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/

View File

@ -4,11 +4,13 @@
/*---
esid: sec-atomics.wake
description: >
Undefined count arg should result in an infinite count
Default to +Infinity when missing 'count' argument to Atomics.wake
info: |
Atomics.wake( typedArray, index, count )
3.If count is undefined, let c be +.
...
3. If count is undefined, let c be +.
...
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
@ -18,58 +20,51 @@ var WAKEUP = 0; // Index all agents are waiting on
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null)
$262.agent.sleep(100);
while ((r = $262.agent.getReport()) == null) {
$262.agent.sleep(10);
}
return r;
}
$262.agent.start(
`
$262.agent.start(`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("A " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.report("A " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50));
$262.agent.leaving();
})
});
`);
$262.agent.start(
`
$262.agent.start(`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("B " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.report("B " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50));
$262.agent.leaving();
})
});
`);
$262.agent.start(
`
$262.agent.start(`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("C " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.report("C " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50));
$262.agent.leaving();
})
});
`);
$262.agent.start(
`
$262.agent.start(`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("D " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.report("D " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50));
$262.agent.leaving();
})
});
`);
var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
$262.agent.broadcast(int32Array.buffer);
$262.agent.sleep(200); // half of timeout
$262.agent.sleep(20);
assert.sameValue($262.agent.getReport(), null);
assert.sameValue(Atomics.wake(int32Array, WAKEUP), NUMAGENT);
assert.sameValue(Atomics.wake(int32Array, WAKEUP /*, count missing */), NUMAGENT);
var sortedReports = [];
for (var i = 0; i < NUMAGENT; i++) {

View File

@ -19,55 +19,49 @@ var WAKEUP = 0; // Index all agents are waiting on
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null)
$262.agent.sleep(100);
$262.agent.sleep(10);
return r;
}
$262.agent.start(
`
$262.agent.start(`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("A " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.report("A " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50));
$262.agent.leaving();
})
});
`);
$262.agent.start(
`
$262.agent.start(`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("B " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.report("B " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50));
$262.agent.leaving();
})
});
`);
$262.agent.start(
`
$262.agent.start(`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("C " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.report("C " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50));
$262.agent.leaving();
})
});
`);
$262.agent.start(
`
$262.agent.start(`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("D " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.report("D " + Atomics.wait(int32Array, ${WAKEUP}, 0, 50));
$262.agent.leaving();
})
});
`);
var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
$262.agent.broadcast(int32Array.buffer);
$262.agent.sleep(200); // half of timeout
assert.sameValue($262.agent.getReport(), null);
$262.agent.sleep(20); // half of timeout
assert.sameValue(Atomics.wake(int32Array, WAKEUP, undefined), NUMAGENT);

View File

@ -0,0 +1,32 @@
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
NaNs are converted to 0 for 'count' argument to Atomics.wake
info: |
Atomics.wake( typedArray, index, count )
...
3. If count is undefined, let c be +.
4. Else,
a. Let intCount be ? ToInteger(count).
...
ToInteger ( argument )
...
2. If number is NaN, return +0.
...
features: [Atomics, SharedArrayBuffer, TypedArray]
includes: [nans.js]
---*/
var sab = new SharedArrayBuffer(4);
var view = new Int32Array(sab);
NaNs.forEach(nan => {
assert.sameValue(Atomics.wake(view, 0, nan), 0);
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
Return abrupt when symbol passed for 'count' argument to Atomics.wake
info: |
Atomics.wake( typedArray, index, count )
...
3. If count is undefined, let c be +.
4. Else,
a. Let intCount be ? ToInteger(count).
...
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
var sab = new SharedArrayBuffer(4);
var view = new Int32Array(sab);
assert.throws(TypeError, function() {
Atomics.wake(view, 0, Symbol());
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
Return abrupt when ToInteger throws an exception on 'count' argument to Atomics.wake
info: |
Atomics.wake( typedArray, index, count )
...
3. If count is undefined, let c be +.
4. Else,
a. Let intCount be ? ToInteger(count).
...
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
var sab = new SharedArrayBuffer(4);
var view = new Int32Array(sab);
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
assert.throws(Test262Error, function() {
Atomics.wake(view, 0, poisoned);
});

View File

@ -11,8 +11,6 @@ features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedAr
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var views = [Int32Array];
var view = new Int32Array(sab, 32, 20);
view[0] = 0;

View File

@ -5,7 +5,7 @@
esid: sec-atomics.wake
description: >
Throws a RangeError if value of index arg is out of range
info: |
info: |
Atomics.wake( typedArray, index, count )
2.Let i be ? ValidateAtomicAccess(typedArray, index).

View File

@ -4,7 +4,7 @@
/*---
esid: sec-atomics.wake
description: >
Throws a TypeError if index arg can not be converted to an Integer
Return abrupt when ToInteger throws for 'index' argument to Atomics.wake
info: |
Atomics.wake( typedArray, index, value, timeout )

View File

@ -34,7 +34,7 @@ $262.agent.receiveBroadcast(function (sab) {
var ia = new Int32Array(sab);
Atomics.add(ia, ${RUNNING}, 1);
// This will always time out.
$262.agent.report("B " + Atomics.wait(ia, ${DUMMY}, 0, 1000));
$262.agent.report("B " + Atomics.wait(ia, ${DUMMY}, 0, 10));
$262.agent.leaving();
})
`);
@ -47,7 +47,7 @@ waitUntil(ia, RUNNING, NUMAGENT + 1);
// Then wait some more to give the agents a fair chance to wait. If we don't,
// we risk sending the wakeup before agents are sleeping, and we hang.
$262.agent.sleep(500);
$262.agent.sleep(50);
// Wake all waiting on WAKEUP, should be 3 always, they won't time out.
assert.sameValue(Atomics.wake(ia, WAKEUP), NUMAGENT);
@ -66,7 +66,7 @@ assert.sameValue(rs[NUMAGENT], "B timed-out");
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null) {
$262.agent.sleep(100);
$262.agent.sleep(10);
}
return r;
}
@ -74,7 +74,7 @@ function getReport() {
function waitUntil(ia, k, value) {
var i = 0;
while (Atomics.load(ia, k) !== value && i < 15) {
$262.agent.sleep(100);
$262.agent.sleep(10);
i++;
}
assert.sameValue(Atomics.load(ia, k), value, "All agents are running");

View File

@ -33,7 +33,7 @@ $262.agent.receiveBroadcast(function (sab) {
var ia = new Int32Array(sab);
Atomics.add(ia, ${RUNNING}, 1);
// This will always time out.
$262.agent.report("B " + Atomics.wait(ia, ${DUMMY}, 0, 1000));
$262.agent.report("B " + Atomics.wait(ia, ${DUMMY}, 0, 10));
$262.agent.leaving();
})
`);
@ -46,7 +46,7 @@ waitUntil(ia, RUNNING, NUMAGENT + 1);
// Then wait some more to give the agents a fair chance to wait. If we don't,
// we risk sending the wakeup before agents are sleeping, and we hang.
$262.agent.sleep(500);
$262.agent.sleep(50);
// Wake all waiting on WAKEUP, should be 3 always, they won't time out.
assert.sameValue(Atomics.wake(ia, WAKEUP), NUMAGENT);
@ -65,7 +65,7 @@ assert.sameValue(rs[NUMAGENT], "B timed-out");
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null) {
$262.agent.sleep(100);
$262.agent.sleep(10);
}
return r;
}
@ -73,7 +73,7 @@ function getReport() {
function waitUntil(ia, k, value) {
var i = 0;
while (Atomics.load(ia, k) !== value && i < 15) {
$262.agent.sleep(100);
$262.agent.sleep(10);
i++;
}
assert.sameValue(Atomics.load(ia, k), value, "All agents are running");

View File

@ -41,12 +41,12 @@ waitUntil(ia, RUNNING, NUMAGENT);
// Then wait some more to give the agents a fair chance to wait. If we don't,
// we risk sending the wakeup before agents are sleeping, and we hang.
$262.agent.sleep(500);
$262.agent.sleep(50);
// Make them sleep in order 0 1 2 on ia[0]
for (var i = 0; i < NUMAGENT; i++) {
Atomics.store(ia, SPIN + i, 1);
$262.agent.sleep(500);
$262.agent.sleep(50);
}
// Wake them up one at a time and check the order is 0 1 2
@ -58,7 +58,7 @@ for (var i = 0; i < NUMAGENT; i++) {
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null) {
$262.agent.sleep(100);
$262.agent.sleep(10);
}
return r;
}
@ -66,7 +66,7 @@ function getReport() {
function waitUntil(ia, k, value) {
var i = 0;
while (Atomics.load(ia, k) !== value && i < 15) {
$262.agent.sleep(100);
$262.agent.sleep(10);
i++;
}
assert.sameValue(Atomics.load(ia, k), value, "All agents are running");

View File

@ -37,7 +37,7 @@ waitUntil(ia, RUNNING, NUMAGENT);
// Then wait some more to give the agents a fair chance to wait. If we don't,
// we risk sending the wakeup before agents are sleeping, and we hang.
$262.agent.sleep(500);
$262.agent.sleep(50);
// There's a slight risk we'll fail to wake the desired count, if the preceding
// sleep() took much longer than anticipated and workers have started timing
@ -61,7 +61,7 @@ for (var i = WAKECOUNT; i < NUMAGENT; i++) {
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null) {
$262.agent.sleep(100);
$262.agent.sleep(10);
}
return r;
}
@ -69,7 +69,7 @@ function getReport() {
function waitUntil(ia, k, value) {
var i = 0;
while (Atomics.load(ia, k) !== value && i < 15) {
$262.agent.sleep(100);
$262.agent.sleep(10);
i++;
}
assert.sameValue(Atomics.load(ia, k), value, "All agents are running");

View File

@ -0,0 +1,54 @@
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
Test that Atomics.wake on awoken waiter is a noop.
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null) {
$262.agent.sleep(10);
}
return r;
}
function waitUntil(ia, k, value) {
var i = 0;
while (Atomics.load(ia, k) !== value && i < 15) {
$262.agent.sleep(10);
i++;
}
assert.sameValue(Atomics.load(ia, k), value, "All agents are running");
}
$262.agent.start(
`
$262.agent.receiveBroadcast(function(sab) {
var ia = new Int32Array(sab);
Atomics.add(ia, 1, 1);
$262.agent.report(Atomics.wait(ia, 0, 0, 2000));
$262.agent.leaving();
})
`);
var ia = new Int32Array(new SharedArrayBuffer(2 * Int32Array.BYTES_PER_ELEMENT));
$262.agent.broadcast(ia.buffer);
waitUntil(ia, 1, 1);
assert.sameValue(Atomics.wake(ia, 0, 1), 1);
$262.agent.sleep(10);
// Collect and check results
var report = getReport();
assert.sameValue(report, "ok");
// Already awake, this should be a noop
assert.sameValue(Atomics.wake(ia, 0, 1), 0);

View File

@ -0,0 +1,36 @@
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
Test that Atomics.wake wakes zero waiters if there are no agents waiting.
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var ia = new Int32Array(sab);
Atomics.add(ia, 1, 1);
$262.agent.leaving();
})
`);
var ia = new Int32Array(new SharedArrayBuffer(2 * Int32Array.BYTES_PER_ELEMENT));
$262.agent.broadcast(ia.buffer);
waitUntil(ia, 1);
// There are ZERO agents waiting to wake...
assert.sameValue(Atomics.wake(ia, 0, 1), 0);
function waitUntil(ia, k) {
var i = 0;
while (Atomics.load(ia, k) !== 1 && i < 15) {
$262.agent.sleep(100);
i++;
}
assert.sameValue(Atomics.load(ia, k), 1, "All agents are running");
}

View File

@ -0,0 +1,37 @@
// Copyright (C) 2018 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
Test that Atomics.wake wakes zero waiters if there are no agents that match
its arguments waiting.
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var ia = new Int32Array(sab);
Atomics.add(ia, 1, 1);
$262.agent.leaving();
})
`);
var ia = new Int32Array(new SharedArrayBuffer(2 * Int32Array.BYTES_PER_ELEMENT));
$262.agent.broadcast(ia.buffer);
waitUntil(ia, 1);
// There are ZERO matching agents...
assert.sameValue(Atomics.wake(ia, 1, 1), 0);
function waitUntil(ia, k) {
var i = 0;
while (Atomics.load(ia, k) !== 1 && i < 15) {
$262.agent.sleep(100);
i++;
}
assert.sameValue(Atomics.load(ia, k), 1, "All agents are running");
}

View File

@ -22,7 +22,7 @@ $262.agent.receiveBroadcast(function (sab) {
var ia = new Int32Array(sab);
Atomics.add(ia, ${RUNNING}, 1);
// Waiters that are not woken will time out eventually.
$262.agent.report(Atomics.wait(ia, ${WAKEUP}, 0, 2000));
$262.agent.report(Atomics.wait(ia, ${WAKEUP}, 0, 200));
$262.agent.leaving();
})
`);
@ -36,7 +36,7 @@ waitUntil(ia, RUNNING, NUMAGENT);
// Then wait some more to give the agents a fair chance to wait. If we don't,
// we risk sending the wakeup before agents are sleeping, and we hang.
$262.agent.sleep(500);
$262.agent.sleep(50);
// There's a slight risk we'll fail to wake the desired count, if the preceding
// sleep() took much longer than anticipated and workers have started timing
@ -60,14 +60,14 @@ for (var i = WAKECOUNT; i < NUMAGENT; i++) {
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null)
$262.agent.sleep(100);
$262.agent.sleep(10);
return r;
}
function waitUntil(ia, k, value) {
var i = 0;
while (Atomics.load(ia, k) !== value && i < 15) {
$262.agent.sleep(100);
$262.agent.sleep(10);
i++;
}
assert.sameValue(Atomics.load(ia, k), value, "Atomics.load(ia, k) returns value (All agents are running)");