Skip to content
Snippets Groups Projects
Commit 5d689952 authored by Amal Hussein's avatar Amal Hussein Committed by Leo Balter
Browse files

additional test coverage for atomics.wait (#1497)

parent 478f5b4c
No related branches found
No related tags found
No related merge requests found
Showing
with 164 additions and 177 deletions
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description: >
Test range checking of Atomics.wait on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
features: [SharedArrayBuffer, ArrayBuffer, DataView, Atomics, TypedArray, arrow-function, let, for-of]
---*/
var sab = new SharedArrayBuffer(8);
var views = [Int32Array];
if (typeof BigInt !== "undefined") {
views.push(BigInt64Array);
}
testWithTypedArrayConstructors(function(View) {
let view = new View(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.wait(view, Idx, 10, 0)); // Even with zero timeout
});
}, views);
...@@ -27,6 +27,7 @@ $262.agent.broadcast(ia.buffer); ...@@ -27,6 +27,7 @@ $262.agent.broadcast(ia.buffer);
assert.sameValue(getReport(), "timed-out"); assert.sameValue(getReport(), "timed-out");
assert.sameValue((getReport() | 0) >= 500 - $ATOMICS_MAX_TIME_EPSILON, true); assert.sameValue((getReport() | 0) >= 500 - $ATOMICS_MAX_TIME_EPSILON, true);
function getReport() { function getReport() {
var r; var r;
while ((r = $262.agent.getReport()) == null) while ((r = $262.agent.getReport()) == null)
......
...@@ -12,7 +12,7 @@ info: | ...@@ -12,7 +12,7 @@ info: |
... ...
Null Return +0. Null Return +0.
Boolean If argument is true, return 1. If argument is false, return +0. Boolean If argument is true, return 1. If argument is false, return +0.
features: [ Atomics ] features: [ Atomics, SharedArrayBuffer, TypedArray ]
includes: [ atomicsHelper.js ] includes: [ atomicsHelper.js ]
---*/ ---*/
......
// Copyright (C) 2018 Amal Hussein. All rights reserved. // Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-atomics.wait esid: sec-atomics.wait
description: > description: >
......
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description:
Throws a TypeError if typedArray arg is not an Int32Array
info: |
Atomics.wait( typedArray, index, value, timeout )
1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
...
5.If onlyInt32 is true, then
If typeName is not "Int32Array", throw a TypeError exception.
features: [ Atomics, TypedArray ]
---*/
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
assert.throws(TypeError, function() {
Atomics.wait(new Float64Array(), poisoned, poisoned, poisoned);
}, 'Float64Array');
assert.throws(TypeError, function() {
Atomics.wait(new Float32Array(), poisoned, poisoned, poisoned);
}, 'Float32Array');
assert.throws(TypeError, function() {
Atomics.wait(new Int16Array(), poisoned, poisoned, poisoned);
}, 'Int16Array');
assert.throws(TypeError, function() {
Atomics.wait(new Int8Array(), poisoned, poisoned, poisoned);
}, 'Int8Array');
assert.throws(TypeError, function() {
Atomics.wait(new Uint32Array(), poisoned, poisoned, poisoned);
}, 'Uint32Array');
assert.throws(TypeError, function() {
Atomics.wait(new Uint16Array(), poisoned, poisoned, poisoned);
}, 'Uint16Array');
assert.throws(TypeError, function() {
Atomics.wait(new Uint8Array(), poisoned, poisoned, poisoned);
}, 'Uint8Array');
assert.throws(TypeError, function() {
Atomics.wait(new Uint8ClampedArray(), poisoned, poisoned, poisoned);
}, 'Uint8ClampedArray');
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description: >
Test Atomics.wait on view values other than TypedArrays
includes: [testAtomics.js]
features: [SharedArrayBuffer, ArrayBuffer, DataView, Atomics, arrow-function, let, for-of]
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.wait(view, 0, 0, 0))); // Even with zero timeout
});
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description: >
Test Atomics.wait on non-shared integer TypedArrays
includes: [testTypedArray.js]
features: [Atomics, TypedArray]
---*/
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
if (typeof BigInt !== "undefined") {
int_views.push(BigInt64Array);
int_views.push(BigUint64Array);
}
testWithTypedArrayConstructors(function(View) {
var view = new View(ab);
assert.throws(TypeError, (() => Atomics.wait(view, 0, 0, 0))); // Should fail even if waiting 0ms
}, int_views);
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description: >
Throws a RangeError if value of index arg is out of range
info: |
Atomics.wait( typedArray, index, value, timeout )
2.Let i be ? ValidateAtomicAccess(typedArray, index).
...
2.Let accessIndex be ? ToIndex(requestIndex).
...
5. If accessIndex ≥ length, throw a RangeError exception.
features: [ Atomics, SharedArrayBuffer, TypedArray ]
---*/
var int32Array = new Int32Array(new SharedArrayBuffer(4));
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
assert.throws(RangeError, () => Atomics.wait(int32Array, Infinity, poisoned, poisoned));
assert.throws(RangeError, () => Atomics.wait(int32Array, 2, poisoned, poisoned));
assert.throws(RangeError, () => Atomics.wait(int32Array, 200, poisoned, poisoned));
...@@ -20,9 +20,6 @@ info: | ...@@ -20,9 +20,6 @@ info: |
features: [ Atomics ] features: [ Atomics ]
---*/ ---*/
var sab = new SharedArrayBuffer(4);
var int32Array = new Int32Array(sab);
function getReport() { function getReport() {
var r; var r;
while ((r = $262.agent.getReport()) == null) { while ((r = $262.agent.getReport()) == null) {
...@@ -34,28 +31,30 @@ function getReport() { ...@@ -34,28 +31,30 @@ function getReport() {
$262.agent.start( $262.agent.start(
` `
$262.agent.receiveBroadcast(function (sab) { $262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
var poisoned = { var poisoned = {
valueOf: false, valueOf: false,
toString: false toString: false
}; };
var err; var err;
try { try {
Atomics.wait(int32Array, 0, 0, poisoned); Atomics.wait(int32Array, 0, 0, poisoned);
} catch(e) { } catch(e) {
err = e.constructor; err = e.name;
} }
$262.agent.report(err); $262.agent.report(err);
$262.agent.leaving(); $262.agent.leaving();
}) })
`); `);
var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); var sab = new SharedArrayBuffer(4);
var int32Array = new Int32Array(sab);
$262.agent.broadcast(int32Array.buffer); $262.agent.broadcast(int32Array.buffer);
$262.agent.sleep(150); assert.sameValue(getReport(), 'TypeError');
assert.sameValue(getReport(), TypeError); assert.sameValue(Atomics.wake(int32Array, 0), 0);
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description: >
Test Atomics.wait on shared non-integer TypedArrays
includes: [testTypedArray.js]
features: [Atomics, TypedArray]
---*/
var sab = new SharedArrayBuffer(1024);
var other_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Uint32Array,
Uint8ClampedArray, Float32Array, Float64Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(sab);
// Even with timout zero this should fail
assert.throws(TypeError, (() => Atomics.wait(view, 0, 0, 0)));
}, other_views);
// Copyright (C) 2018 Amal Hussein. All rights reserved. // Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-atomics.wait esid: sec-atomics.wait
description: > description: >
......
...@@ -9,12 +9,11 @@ info: | ...@@ -9,12 +9,11 @@ info: |
Atomics.wait( typedArray, index, value, timeout ) Atomics.wait( typedArray, index, value, timeout )
4.Let q be ? ToNumber(timeout). 4.Let q be ? ToNumber(timeout).
features: [Atomics, Symbol] ...
Symbol Throw a TypeError exception.
features: [Atomics, SharedArrayBuffer, TypedArray, Symbol]
---*/ ---*/
var sab = new SharedArrayBuffer(4);
var int32Array = new Int32Array(sab);
function getReport() { function getReport() {
var r; var r;
while ((r = $262.agent.getReport()) == null) { while ((r = $262.agent.getReport()) == null) {
...@@ -25,23 +24,25 @@ function getReport() { ...@@ -25,23 +24,25 @@ function getReport() {
$262.agent.start( $262.agent.start(
` `
$262.agent.receiveBroadcast(function (sab) { $262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
var err; var err;
var s = Symbol();
try { try {
Atomics.wait(int32Array, 0, 0, s); Atomics.wait(int32Array, 0, 0, Symbol('foo'));
} catch(e) { } catch(e) {
err = e.constructor; err = e.name;
} }
$262.agent.report(err); $262.agent.report(err);
$262.agent.leaving(); $262.agent.leaving();
}) })
`); `);
var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); var sab = new SharedArrayBuffer(4);
var int32Array = new Int32Array(sab);
$262.agent.broadcast(int32Array.buffer); $262.agent.broadcast(int32Array.buffer);
assert.sameValue(getReport(), TypeError); assert.sameValue(getReport(), 'TypeError');
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description: >
Null or false timeout arg should result in an +0 timeout
info: |
Atomics.wait( typedArray, index, value, timeout )
4.Let q be ? ToNumber(timeout).
...
Null Return +0.
Boolean If argument is true, return 1. If argument is false, return +0.
features: [Atomics]
includes: [atomicsHelper.js]
---*/
var NUMREPORTS = 4; // Expected reports output from running agents
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null)
$262.agent.sleep(100);
return r;
}
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
var start = Date.now();
$262.agent.report("A " + Atomics.wait(int32Array, 0, 0, null)); // null => +0
$262.agent.report(Date.now() - start);
$262.agent.leaving();
})
`);
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
var start = Date.now();
$262.agent.report("B " + Atomics.wait(int32Array, 0, 0, false)); // false => +0
$262.agent.report(Date.now() - start);
$262.agent.leaving();
})
`);
var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
$262.agent.broadcast(int32Array.buffer);
$262.agent.sleep(150);
var sortedReports = [];
for (var i = 0; i < NUMREPORTS; i++) {
sortedReports.push(getReport());
}
sortedReports.sort();
assert.sameValue(sortedReports[2], 'A timed-out');
assert.sameValue(sortedReports[3], 'B timed-out');
assert(sortedReports[0] >= 0 && sortedReports[0] <= $ATOMICS_MAX_TIME_EPSILON, "timeout should be a min of 0ms and max of $ATOMICS_MAX_TIME_EPSILON");
assert(sortedReports[1] >= 0 && sortedReports[1] <= $ATOMICS_MAX_TIME_EPSILON, "timeout should be a min of 0ms and max of $ATOMICS_MAX_TIME_EPSILON");
assert.sameValue(Atomics.wake(int32Array, 0), 0);
...@@ -11,7 +11,7 @@ info: | ...@@ -11,7 +11,7 @@ info: |
4.Let q be ? ToNumber(timeout). 4.Let q be ? ToNumber(timeout).
... ...
Boolean If argument is true, return 1. If argument is false, return +0. Boolean If argument is true, return 1. If argument is false, return +0.
features: [ Atomics ] features: [ Atomics, SharedArrayBuffer, TypedArray ]
includes: [atomicsHelper.js] includes: [atomicsHelper.js]
---*/ ---*/
...@@ -41,5 +41,8 @@ $262.agent.broadcast(int32Array.buffer); ...@@ -41,5 +41,8 @@ $262.agent.broadcast(int32Array.buffer);
$262.agent.sleep(2); $262.agent.sleep(2);
var r1 = getReport(); var r1 = getReport();
var r2 = getReport();
assert.sameValue(r1, "timed-out"); assert.sameValue(r1, "timed-out");
assert(r2 >= 1, "timeout should be a min of 1ms");
assert(r2 <= $ATOMICS_MAX_TIME_EPSILON + 1, "timeout should be a max of $ATOMICS_MAX_TIME_EPSILON + 1ms");
...@@ -33,7 +33,8 @@ var sab = new SharedArrayBuffer(1024); ...@@ -33,7 +33,8 @@ var sab = new SharedArrayBuffer(1024);
var int32Array = new Int32Array(sab); var int32Array = new Int32Array(sab);
$262.agent.broadcast(int32Array.buffer); $262.agent.broadcast(int32Array.buffer);
$262.agent.sleep(5);
$262.agent.sleep(150);
assert.sameValue(Atomics.wake(int32Array, 0), 1); // wake at index 0 assert.sameValue(Atomics.wake(int32Array, 0), 1); // wake at index 0
assert.sameValue(Atomics.wake(int32Array, 0), 0); // wake again at index 0, and 0 agents should be woken assert.sameValue(Atomics.wake(int32Array, 0), 0); // wake again at index 0, and 0 agents should be woken
......
...@@ -4,59 +4,49 @@ ...@@ -4,59 +4,49 @@
/*--- /*---
esid: sec-atomics.wait esid: sec-atomics.wait
description: > description: >
NaN timeout arg should result in an infinite timeout Returns "not-equal" when value of index is not equal
info: | info: |
Atomics.wait( typedArray, index, value, timeout ) Atomics.wait( typedArray, index, value, timeout )
4.Let q be ? ToNumber(timeout). 14.If v is not equal to w, then
... a.Perform LeaveCriticalSection(WL).
Undefined Return NaN. b. Return the String "not-equal".
5.If q is NaN, let t be +∞, else let t be max(q, 0)
features: [ Atomics, SharedArrayBuffer, TypedArray ] features: [ Atomics, SharedArrayBuffer, TypedArray ]
---*/ ---*/
var NUMAGENT = 2; // Total number of agents started
var WAKEUP = 0; // Index all agents are waiting on
var WAKECOUNT = 2; // Total number of agents to wake up
function getReport() { function getReport() {
var r; var r;
while ((r = $262.agent.getReport()) == null) while ((r = $262.agent.getReport()) == null) {
$262.agent.sleep(100); $262.agent.sleep(100);
}
return r; return r;
} }
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("A " + Atomics.wait(int32Array, 0, 0, NaN)); // NaN => +Infinity
$262.agent.leaving();
})
`);
$262.agent.start( $262.agent.start(
` `
$262.agent.receiveBroadcast(function (sab) { $262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab); var int32Array = new Int32Array(sab);
$262.agent.report("B " + Atomics.wait(int32Array, 0, 0)); // undefined => NaN => +Infinity
$262.agent.report(Atomics.wait(int32Array, 0, 44, 100));
$262.agent.report(Atomics.wait(int32Array, 0, 251.4, 1000));
$262.agent.report(Atomics.wait(int32Array, 0, Infinity, 1000));
$262.agent.leaving(); $262.agent.leaving();
}) })
`); `);
var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); var int32Array = new Int32Array(new SharedArrayBuffer(1024));
$262.agent.broadcast(int32Array.buffer); $262.agent.broadcast(int32Array.buffer);
$262.agent.sleep(500); // Ample time $262.agent.sleep(200);
assert.sameValue(Atomics.wake(int32Array, WAKEUP, WAKECOUNT), WAKECOUNT);
var sortedReports = []; assert.sameValue(getReport(), "not-equal");
for (var i = 0; i < NUMAGENT; i++) { assert.sameValue(getReport(), "not-equal");
sortedReports.push(getReport()); assert.sameValue(getReport(), "not-equal");
}
sortedReports.sort();
assert.sameValue(sortedReports[0], "A ok"); assert.sameValue(Atomics.wake(int32Array, 0), 0);
assert.sameValue(sortedReports[1], "B ok");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment