mirror of
https://github.com/tc39/test262.git
synced 2025-07-28 00:14:35 +02:00
additional test coverage for atomics.wait (#1497)
This commit is contained in:
parent
478f5b4c0c
commit
5d6899522a
@ -1,25 +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 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);
|
||||
assert.sameValue(getReport(), "timed-out");
|
||||
assert.sameValue((getReport() | 0) >= 500 - $ATOMICS_MAX_TIME_EPSILON, true);
|
||||
|
||||
|
||||
function getReport() {
|
||||
var r;
|
||||
while ((r = $262.agent.getReport()) == null)
|
||||
|
@ -12,7 +12,7 @@ info: |
|
||||
...
|
||||
Null Return +0.
|
||||
Boolean If argument is true, return 1. If argument is false, return +0.
|
||||
features: [ Atomics ]
|
||||
features: [ Atomics, SharedArrayBuffer, TypedArray ]
|
||||
includes: [ atomicsHelper.js ]
|
||||
---*/
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
// 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: >
|
||||
|
54
test/built-ins/Atomics/wait/non-int32-typedarray-throws.js
Normal file
54
test/built-ins/Atomics/wait/non-int32-typedarray-throws.js
Normal file
@ -0,0 +1,54 @@
|
||||
// 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');
|
@ -1,14 +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 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
|
||||
});
|
@ -1,25 +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 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);
|
28
test/built-ins/Atomics/wait/out-of-range-index-throws.js
Normal file
28
test/built-ins/Atomics/wait/out-of-range-index-throws.js
Normal file
@ -0,0 +1,28 @@
|
||||
// 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: |
|
||||
features: [ Atomics ]
|
||||
---*/
|
||||
|
||||
var sab = new SharedArrayBuffer(4);
|
||||
var int32Array = new Int32Array(sab);
|
||||
|
||||
function getReport() {
|
||||
var r;
|
||||
while ((r = $262.agent.getReport()) == null) {
|
||||
@ -34,17 +31,18 @@ function getReport() {
|
||||
$262.agent.start(
|
||||
`
|
||||
$262.agent.receiveBroadcast(function (sab) {
|
||||
|
||||
var int32Array = new Int32Array(sab);
|
||||
var poisoned = {
|
||||
valueOf: false,
|
||||
toString: false
|
||||
};
|
||||
|
||||
var err;
|
||||
|
||||
try {
|
||||
Atomics.wait(int32Array, 0, 0, poisoned);
|
||||
} catch(e) {
|
||||
err = e.constructor;
|
||||
err = e.name;
|
||||
}
|
||||
|
||||
$262.agent.report(err);
|
||||
@ -52,10 +50,11 @@ $262.agent.receiveBroadcast(function (sab) {
|
||||
})
|
||||
`);
|
||||
|
||||
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.sleep(150);
|
||||
assert.sameValue(getReport(), 'TypeError');
|
||||
|
||||
assert.sameValue(getReport(), TypeError);
|
||||
assert.sameValue(Atomics.wake(int32Array, 0), 0);
|
||||
|
@ -1,22 +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);
|
@ -1,5 +1,6 @@
|
||||
// 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: >
|
@ -9,12 +9,11 @@ info: |
|
||||
Atomics.wait( typedArray, index, value, 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() {
|
||||
var r;
|
||||
while ((r = $262.agent.getReport()) == null) {
|
||||
@ -26,13 +25,14 @@ function getReport() {
|
||||
$262.agent.start(
|
||||
`
|
||||
$262.agent.receiveBroadcast(function (sab) {
|
||||
|
||||
var int32Array = new Int32Array(sab);
|
||||
var err;
|
||||
var s = Symbol();
|
||||
|
||||
try {
|
||||
Atomics.wait(int32Array, 0, 0, s);
|
||||
Atomics.wait(int32Array, 0, 0, Symbol('foo'));
|
||||
} catch(e) {
|
||||
err = e.constructor;
|
||||
err = e.name;
|
||||
}
|
||||
|
||||
$262.agent.report(err);
|
||||
@ -40,8 +40,9 @@ $262.agent.receiveBroadcast(function (sab) {
|
||||
})
|
||||
`);
|
||||
|
||||
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);
|
||||
|
||||
assert.sameValue(getReport(), TypeError);
|
||||
assert.sameValue(getReport(), 'TypeError');
|
@ -1,62 +0,0 @@
|
||||
// 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: >
|
||||
NaN timeout arg should result in an infinite timeout
|
||||
info: |
|
||||
Atomics.wait( typedArray, index, value, timeout )
|
||||
|
||||
4.Let q be ? ToNumber(timeout).
|
||||
...
|
||||
Undefined Return NaN.
|
||||
5.If q is NaN, let t be +∞, else let t be max(q, 0)
|
||||
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() {
|
||||
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);
|
||||
$262.agent.report("A " + Atomics.wait(int32Array, 0, 0, NaN)); // NaN => +Infinity
|
||||
$262.agent.leaving();
|
||||
})
|
||||
`);
|
||||
|
||||
$262.agent.start(
|
||||
`
|
||||
$262.agent.receiveBroadcast(function (sab) {
|
||||
var int32Array = new Int32Array(sab);
|
||||
$262.agent.report("B " + Atomics.wait(int32Array, 0, 0)); // undefined => NaN => +Infinity
|
||||
$262.agent.leaving();
|
||||
})
|
||||
`);
|
||||
|
||||
var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
|
||||
|
||||
$262.agent.broadcast(int32Array.buffer);
|
||||
|
||||
$262.agent.sleep(500); // Ample time
|
||||
|
||||
assert.sameValue(Atomics.wake(int32Array, WAKEUP, WAKECOUNT), WAKECOUNT);
|
||||
|
||||
var sortedReports = [];
|
||||
for (var i = 0; i < NUMAGENT; i++) {
|
||||
sortedReports.push(getReport());
|
||||
}
|
||||
sortedReports.sort();
|
||||
|
||||
assert.sameValue(sortedReports[0], "A ok");
|
||||
assert.sameValue(sortedReports[1], "B ok");
|
@ -1,68 +0,0 @@
|
||||
// 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: |
|
||||
4.Let q be ? ToNumber(timeout).
|
||||
...
|
||||
Boolean If argument is true, return 1. If argument is false, return +0.
|
||||
features: [ Atomics ]
|
||||
features: [ Atomics, SharedArrayBuffer, TypedArray ]
|
||||
includes: [atomicsHelper.js]
|
||||
---*/
|
||||
|
||||
@ -41,5 +41,8 @@ $262.agent.broadcast(int32Array.buffer);
|
||||
$262.agent.sleep(2);
|
||||
|
||||
var r1 = getReport();
|
||||
var r2 = getReport();
|
||||
|
||||
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);
|
||||
var int32Array = new Int32Array(sab);
|
||||
|
||||
$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), 0); // wake again at index 0, and 0 agents should be woken
|
||||
|
52
test/built-ins/Atomics/wait/wait-index-value-not-equal.js
Normal file
52
test/built-ins/Atomics/wait/wait-index-value-not-equal.js
Normal file
@ -0,0 +1,52 @@
|
||||
// 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: >
|
||||
Returns "not-equal" when value of index is not equal
|
||||
info: |
|
||||
Atomics.wait( typedArray, index, value, timeout )
|
||||
|
||||
14.If v is not equal to w, then
|
||||
a.Perform LeaveCriticalSection(WL).
|
||||
b. Return the String "not-equal".
|
||||
|
||||
features: [ Atomics, SharedArrayBuffer, TypedArray ]
|
||||
---*/
|
||||
|
||||
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);
|
||||
|
||||
$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();
|
||||
})
|
||||
`);
|
||||
|
||||
var int32Array = new Int32Array(new SharedArrayBuffer(1024));
|
||||
|
||||
$262.agent.broadcast(int32Array.buffer);
|
||||
|
||||
$262.agent.sleep(200);
|
||||
|
||||
|
||||
assert.sameValue(getReport(), "not-equal");
|
||||
assert.sameValue(getReport(), "not-equal");
|
||||
assert.sameValue(getReport(), "not-equal");
|
||||
|
||||
assert.sameValue(Atomics.wake(int32Array, 0), 0);
|
Loading…
x
Reference in New Issue
Block a user