diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Atomics/wait/bigint')
27 files changed, 1310 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/bad-range.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/bad-range.js new file mode 100644 index 0000000000..ad3310e9a0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/bad-range.js @@ -0,0 +1,29 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. 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 +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + ... + +includes: [testAtomics.js] +features: [ArrayBuffer, Atomics, BigInt, DataView, SharedArrayBuffer, Symbol, TypedArray] +---*/ + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 8) +); + +testWithAtomicsOutOfBoundsIndices(function(IdxGen) { + assert.throws(RangeError, function() { + Atomics.wait(i64a, IdxGen(i64a), 0n, 0); + }, '`Atomics.wait(i64a, IdxGen(i64a), 0n, 0)` throws RangeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/browser.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/browser.js diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/cannot-suspend-throws.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/cannot-suspend-throws.js new file mode 100644 index 0000000000..5b54c68914 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/cannot-suspend-throws.js @@ -0,0 +1,27 @@ +// |reftest| skip-if(xulRuntime.shell||!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- shell can block main thread, Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// 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: > + Atomics.wait throws if agent cannot be suspended, CanBlock is false +info: | + Assuming [[CanBlock]] is false for the main host. + + Atomics.wait( typedArray, index, value, timeout ) + + ... (after args validation) + 6. Let B be AgentCanSuspend(). + 7. If B is false, throw a TypeError exception. + ... +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +flags: [CanBlockIsFalse] +---*/ + +const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + +assert.throws(TypeError, function() { + Atomics.wait(i64a, 0, 0n, 0); +}, '`Atomics.wait(i64a, 0, 0n, 0)` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/false-for-timeout-agent.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/false-for-timeout-agent.js new file mode 100644 index 0000000000..1b401417e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/false-for-timeout-agent.js @@ -0,0 +1,78 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// 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: > + False timeout arg should result in an +0 timeout +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 4. Let q be ? ToNumber(timeout). + + Boolean -> If argument is true, return 1. If argument is false, return +0. + +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +const RUNNING = 1; + +$262.agent.start(` + const valueOf = { + valueOf: function() { + return false; + } + }; + + const toPrimitive = { + [Symbol.toPrimitive]: function() { + return false; + } + }; + + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const status1 = Atomics.wait(i64a, 0, 0n, false); + const status2 = Atomics.wait(i64a, 0, 0n, valueOf); + const status3 = Atomics.wait(i64a, 0, 0n, toPrimitive); + + $262.agent.report(status1); + $262.agent.report(status2); + $262.agent.report(status3); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); + +assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/false-for-timeout.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/false-for-timeout.js new file mode 100644 index 0000000000..b58907c223 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/false-for-timeout.js @@ -0,0 +1,52 @@ +// |reftest| skip-if(!xulRuntime.shell||!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- browser cannot block main thread, Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// 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: > + False timeout arg should result in an +0 timeout +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 4. Let q be ? ToNumber(timeout). + + Boolean -> If argument is true, return 1. If argument is false, return +0. + +features: [Atomics, BigInt, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray] +flags: [CanBlockIsTrue] +---*/ + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +const valueOf = { + valueOf: function() { + return false; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]: function() { + return false; + } +}; + +assert.sameValue( + Atomics.wait(i64a, 0, 0n, false), + "timed-out", + 'Atomics.wait(i64a, 0, 0n, false) returns "timed-out"' +); +assert.sameValue( + Atomics.wait(i64a, 0, 0n, valueOf), + "timed-out", + 'Atomics.wait(i64a, 0, 0n, valueOf) returns "timed-out"' +); +assert.sameValue( + Atomics.wait(i64a, 0, 0n, toPrimitive), + "timed-out", + 'Atomics.wait(i64a, 0, 0n, toPrimitive) returns "timed-out"' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/nan-for-timeout.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/nan-for-timeout.js new file mode 100644 index 0000000000..00ae824330 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/nan-for-timeout.js @@ -0,0 +1,46 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// 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) + +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +const RUNNING = 1; + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + $262.agent.report(Atomics.wait(i64a, 0, 0n, NaN)); // NaN => +Infinity + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +assert.sameValue(Atomics.notify(i64a, 0), 1, 'Atomics.notify(i64a, 0) returns 1'); +assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/negative-index-throws.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/negative-index-throws.js new file mode 100644 index 0000000000..ce31bf301e --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/negative-index-throws.js @@ -0,0 +1,42 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// 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 is index < 0 +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 2.Let i be ? ValidateAtomicAccess(typedArray, index). + ... + 2.Let accessIndex be ? ToIndex(requestIndex). + ... + 2.b If integerIndex < 0, throw a RangeError exception +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 8) +); +const poisoned = { + valueOf: function() { + throw new Test262Error('should not evaluate this code'); + } +}; + +assert.throws(RangeError, function() { + Atomics.wait(i64a, -Infinity, poisoned, poisoned); +}, '`Atomics.wait(i64a, -Infinity, poisoned, poisoned)` throws RangeError'); +assert.throws(RangeError, function() { + Atomics.wait(i64a, -7.999, poisoned, poisoned); +}, '`Atomics.wait(i64a, -7.999, poisoned, poisoned)` throws RangeError'); +assert.throws(RangeError, function() { + Atomics.wait(i64a, -1, poisoned, poisoned); +}, '`Atomics.wait(i64a, -1, poisoned, poisoned)` throws RangeError'); +assert.throws(RangeError, function() { + Atomics.wait(i64a, -300, poisoned, poisoned); +}, '`Atomics.wait(i64a, -300, poisoned, poisoned)` throws RangeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/negative-timeout-agent.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/negative-timeout-agent.js new file mode 100644 index 0000000000..752fc7f8fc --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/negative-timeout-agent.js @@ -0,0 +1,42 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Test that Atomics.wait times out with a negative timeout +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +const RUNNING = 1; + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + $262.agent.report(Atomics.wait(i64a, 0, 0n, -5)); // -5 => 0 + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/negative-timeout.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/negative-timeout.js new file mode 100644 index 0000000000..e38b9381cc --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/negative-timeout.js @@ -0,0 +1,23 @@ +// |reftest| skip-if(!xulRuntime.shell||!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- browser cannot block main thread, Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Test that Atomics.wait times out with a negative timeout +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +flags: [CanBlockIsTrue] +---*/ + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +assert.sameValue( + Atomics.wait(i64a, 0, 0n, -1), + "timed-out", + 'Atomics.wait(i64a, 0, 0n, -1) returns "timed-out"' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-no-operation.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-no-operation.js new file mode 100644 index 0000000000..01202a1efe --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-no-operation.js @@ -0,0 +1,62 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// 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 that Atomics.wait returns the right result when it timed out and that + the time to time out is reasonable. + info: | + 17. Let awoken be Suspend(WL, W, t). + 18. If awoken is true, then + a. Assert: W is not on the list of waiters in WL. + 19. Else, + a.Perform RemoveWaiter(WL, W). +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT}); + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +// NO OPERATION OCCURS HERE! + +const lapse = $262.agent.getReport(); +assert( + lapse >= TIMEOUT, + 'The result of `(lapse >= TIMEOUT)` is true' +); +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-add.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-add.js new file mode 100644 index 0000000000..b822c523d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-add.js @@ -0,0 +1,57 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Waiter does not spuriously notify on index which is subject to Add operation +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT}); + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +Atomics.add(i64a, 0, 1n); + +const lapse = $262.agent.getReport(); +assert( + lapse >= TIMEOUT, + 'The result of `(lapse >= TIMEOUT)` is true' +); +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); + + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-and.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-and.js new file mode 100644 index 0000000000..e3d168a11b --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-and.js @@ -0,0 +1,57 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Waiter does not spuriously nofity on index which is subject to And operation +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT}); + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +Atomics.and(i64a, 0, 1n); + +const lapse = $262.agent.getReport(); +assert( + lapse >= TIMEOUT, + 'The result of `(lapse >= TIMEOUT)` is true' +); +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); + + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-compareExchange.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-compareExchange.js new file mode 100644 index 0000000000..0ebe25cd3d --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-compareExchange.js @@ -0,0 +1,55 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Waiter does not spuriously notify on index which is subject to compareExchange operation +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT}); + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +Atomics.compareExchange(i64a, 0, 0n, 1n); + +const lapse = $262.agent.getReport(); +assert( + lapse >= TIMEOUT, + 'The result of `(lapse >= TIMEOUT)` is true' +); +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-exchange.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-exchange.js new file mode 100644 index 0000000000..f668ee3611 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-exchange.js @@ -0,0 +1,55 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Waiter does not spuriously notify on index which is subject to exchange operation +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT}); + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +Atomics.exchange(i64a, 0, 1n); + +const lapse = $262.agent.getReport(); +assert( + lapse >= TIMEOUT, + 'The result of `(lapse >= TIMEOUT)` is true' +); +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-or.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-or.js new file mode 100644 index 0000000000..6eebfce7c1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-or.js @@ -0,0 +1,55 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Waiter does not spuriously notify on index which is subject to Or operation +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT}); + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +Atomics.or(i64a, 0, 1n); + +const lapse = $262.agent.getReport(); +assert( + lapse >= TIMEOUT, + 'The result of `(lapse >= TIMEOUT)` is true' +); +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store.js new file mode 100644 index 0000000000..3b3630f721 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store.js @@ -0,0 +1,55 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Demonstrates that Atomics.store(...) is causing a waiting +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT}); + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +Atomics.store(i64a, 0, 0x111111n); + +const lapse = $262.agent.getReport(); +assert( + lapse >= TIMEOUT, + 'The result of `(lapse >= TIMEOUT)` is true' +); +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-sub.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-sub.js new file mode 100644 index 0000000000..0703e2e57e --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-sub.js @@ -0,0 +1,55 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Waiter does not spuriously notify on index which is subject to Sub operation +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT}); + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +Atomics.sub(i64a, 0, 1n); + +const lapse = $262.agent.getReport(); +assert( + lapse >= TIMEOUT, + 'The result of `(lapse >= TIMEOUT)` is true' +); +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-xor.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-xor.js new file mode 100644 index 0000000000..1d6f636d65 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-xor.js @@ -0,0 +1,55 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Waiter does not spuriously notify on index which is subject to xor operation +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.small; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT}); + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +Atomics.xor(i64a, 0, 1n); + +const lapse = $262.agent.getReport(); +assert( + lapse >= TIMEOUT, + 'The result of `(lapse >= TIMEOUT)` is true' +); +assert.sameValue( + $262.agent.getReport(), + 'timed-out', + '$262.agent.getReport() returns "timed-out"' +); +assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/non-bigint64-typedarray-throws.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/non-bigint64-typedarray-throws.js new file mode 100644 index 0000000000..9db40a9a65 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/non-bigint64-typedarray-throws.js @@ -0,0 +1,44 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-validatesharedintegertypedarray +description: > + Throws a TypeError if typedArray arg is not a BigInt64Array +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + ... + + + ValidateSharedIntegerTypedArray(typedArray [ , waitable ] ) + + ... + 5. If waitable is true, then + a. If typeName is not "BigInt64Array", + throw a TypeError exception. + +features: [Atomics, BigInt, SharedArrayBuffer] +---*/ + +const i64a = new BigUint64Array( + new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT) +); + +const poisoned = { + valueOf: function() { + throw new Test262Error('should not evaluate this code'); + } +}; + +assert.throws(TypeError, function() { + Atomics.wait(i64a, 0, 0n, 0); +}, '`Atomics.wait(i64a, 0, 0n, 0)` throws TypeError'); + +assert.throws(TypeError, function() { + Atomics.wait(i64a, poisoned, poisoned, poisoned); +}, '`Atomics.wait(i64a, poisoned, poisoned, poisoned)` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/non-shared-bufferdata-throws.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/non-shared-bufferdata-throws.js new file mode 100644 index 0000000000..ec45720916 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/non-shared-bufferdata-throws.js @@ -0,0 +1,34 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')) -- Atomics is not enabled unconditionally +// 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.buffer is not a SharedArrayBuffer +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + ... + 9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception. + ... + 4.If bufferData is a Data Block, return false. +features: [ArrayBuffer, Atomics, BigInt, TypedArray] +---*/ +const i64a = new BigInt64Array(new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); + +const poisoned = { + valueOf: function() { + throw new Test262Error('should not evaluate this code'); + } +}; + +assert.throws(TypeError, function() { + Atomics.wait(i64a, 0, 0n, 0); +}, '`Atomics.wait(i64a, 0, 0n, 0)` throws TypeError'); + +assert.throws(TypeError, function() { + Atomics.wait(i64a, poisoned, poisoned, poisoned); +}, '`Atomics.wait(i64a, poisoned, poisoned, poisoned)` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/null-bufferdata-throws.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/null-bufferdata-throws.js new file mode 100644 index 0000000000..9499b9f0e6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/null-bufferdata-throws.js @@ -0,0 +1,48 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')) -- Atomics is not enabled unconditionally +// 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: > + A null value for bufferData throws a TypeError +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). + ... + + ValidateSharedIntegerTypedArray(typedArray [ , onlyInt32 ] ) + + ... + 9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception. + + + IsSharedArrayBuffer( obj ) + + ... + 3.If bufferData is null, return false. + +includes: [detachArrayBuffer.js] +features: [ArrayBuffer, Atomics, BigInt, TypedArray] +---*/ + +const i64a = new BigInt64Array( + new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); +const poisoned = { + valueOf: function() { + throw new Test262Error('should not evaluate this code'); + } +}; + +try { + $DETACHBUFFER(i64a.buffer); // Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null +} catch (error) { + throw new Test262Error(`An unexpected error occurred when detaching ArrayBuffer: ${error.message}`); +} + +assert.throws(TypeError, function() { + Atomics.wait(i64a, poisoned, poisoned, poisoned); +}, '`Atomics.wait(i64a, poisoned, poisoned, poisoned)` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/out-of-range-index-throws.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/out-of-range-index-throws.js new file mode 100644 index 0000000000..7bb3c5ec75 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/out-of-range-index-throws.js @@ -0,0 +1,40 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// 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, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +const poisoned = { + valueOf: function() { + throw new Test262Error('should not evaluate this code'); + } +}; + +assert.throws(RangeError, function() { + Atomics.wait(i64a, Infinity, poisoned, poisoned); +}, '`Atomics.wait(i64a, Infinity, poisoned, poisoned)` throws RangeError'); +assert.throws(RangeError, function() { + Atomics.wait(i64a, 8, poisoned, poisoned); +}, '`Atomics.wait(i64a, 8, poisoned, poisoned)` throws RangeError'); +assert.throws(RangeError, function() { + Atomics.wait(i64a, 200, poisoned, poisoned); +}, '`Atomics.wait(i64a, 200, poisoned, poisoned)` throws RangeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/shell.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/shell.js diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/value-not-equal.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/value-not-equal.js new file mode 100644 index 0000000000..a97cd35bcf --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/value-not-equal.js @@ -0,0 +1,62 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// 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 arg does not match an index in the typedArray +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 3.Let v be ? ToBigInt64(value). + ... + 14.If v is not equal to w, then + a.Perform LeaveCriticalSection(WL). + b. Return the String "not-equal". + +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const RUNNING = 1; +const value = "42n"; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + $262.agent.report(Atomics.store(i64a, 0, ${value})); + $262.agent.report(Atomics.wait(i64a, 0, 0n)); + $262.agent.leaving(); + }); +`); + +// NB: We don't actually explicitly need to wait for the agent to start in this +// test case, we only do it for consistency with other test cases which do +// require the main agent to wait and yield control. + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +assert.sameValue( + $262.agent.getReport(), + '42', + '$262.agent.getReport() returns "42"' +); +assert.sameValue( + $262.agent.getReport(), + 'not-equal', + '$262.agent.getReport() returns "not-equal"' +); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/waiterlist-block-indexedposition-wake.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/waiterlist-block-indexedposition-wake.js new file mode 100644 index 0000000000..e1da72ccb0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/waiterlist-block-indexedposition-wake.js @@ -0,0 +1,78 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Get the correct WaiterList +info: | + Atomics.wait( typedArray, index, value, timeout ) + + ... + 11. Let WL be GetWaiterList(block, indexedPosition). + ... + + + GetWaiterList( block, i ) + + ... + 4. Return the WaiterList that is referenced by the pair (block, i). + +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var NUMAGENT = 2; +var RUNNING = 4; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + // Wait on index 0 + $262.agent.report(Atomics.wait(i64a, 0, 0n, Infinity)); + $262.agent.leaving(); + }); +`); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + // Wait on index 2 + $262.agent.report(Atomics.wait(i64a, 2, 0n, Infinity)); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); + +// Wait until all agents started. +$262.agent.waitUntil(i64a, RUNNING, BigInt(NUMAGENT)); + +// Notify index 1, notifies nothing +assert.sameValue(Atomics.notify(i64a, 1), 0, 'Atomics.notify(i64a, 1) returns 0'); + +// Notify index 3, notifies nothing +assert.sameValue(Atomics.notify(i64a, 3), 0, 'Atomics.notify(i64a, 3) returns 0'); + +// Notify index 2, notifies 1 +var woken = 0; +while ((woken = Atomics.notify(i64a, 2)) === 0) ; +assert.sameValue(woken, 1, 'Atomics.notify(i64a, 2) returns 1'); +assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"'); + +// Notify index 0, notifies 1 +var woken = 0; +while ((woken = Atomics.notify(i64a, 0)) === 0) ; +assert.sameValue(woken, 1, 'Atomics.notify(i64a, 0) returns 1'); +assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/waiterlist-order-of-operations-is-fifo.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/waiterlist-order-of-operations-is-fifo.js new file mode 100644 index 0000000000..f75888e49f --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/waiterlist-order-of-operations-is-fifo.js @@ -0,0 +1,95 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// 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: > + New waiters should be applied to the end of the list and woken by order they entered the list (FIFO) +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 16.Perform AddWaiter(WL, W). + ... + 3.Add W to the end of the list of waiters in WL. + +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var WAIT_INDEX = 0; +var RUNNING = 1; +var LOCK_INDEX = 2; +var NUMAGENT = 3; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +for (var i = 0; i < NUMAGENT; i++) { + var agentNum = i; + + $262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + // Synchronize workers before reporting the initial report. + while (Atomics.compareExchange(i64a, ${LOCK_INDEX}, 0n, 1n) !== 0n) ; + + // Report the agent number before waiting. + $262.agent.report(${agentNum}); + + // Wait until restarted by main thread. + var status = Atomics.wait(i64a, ${WAIT_INDEX}, 0n); + + // Report wait status. + $262.agent.report(status); + + // Report the agent number after waiting. + $262.agent.report(${agentNum}); + + $262.agent.leaving(); + }); + `); +} + +$262.agent.safeBroadcast(i64a); + +// Wait until all agents started. +$262.agent.waitUntil(i64a, RUNNING, BigInt(NUMAGENT)); + +// Agents may be started in any order. +const started = []; +for (var i = 0; i < NUMAGENT; i++) { + // Wait until an agent entered its critical section. + $262.agent.waitUntil(i64a, LOCK_INDEX, 1n); + + // Record the agent number. + started.push($262.agent.getReport()); + + // The agent may have been interrupted between reporting its initial report + // and the `Atomics.wait` call. Try to yield control to ensure the agent + // actually started to wait. + $262.agent.tryYield(); + + // Now continue with the next agent. + Atomics.store(i64a, LOCK_INDEX, 0n); +} + +// Agents must notify in the order they waited. +for (var i = 0; i < NUMAGENT; i++) { + var woken = 0; + while ((woken = Atomics.notify(i64a, WAIT_INDEX, 1)) === 0) ; + + assert.sameValue(woken, 1, + 'Atomics.notify(i64a, WAIT_INDEX, 1) returns 1, at index = ' + i); + + assert.sameValue($262.agent.getReport(), 'ok', + '$262.agent.getReport() returns "ok", at index = ' + i); + + assert.sameValue($262.agent.getReport(), started[i], + '$262.agent.getReport() returns the value of `started[' + i + ']`'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/wait/bigint/was-woken-before-timeout.js b/js/src/tests/test262/built-ins/Atomics/wait/bigint/was-woken-before-timeout.js new file mode 100644 index 0000000000..438d9363d4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/bigint/was-woken-before-timeout.js @@ -0,0 +1,64 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// 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: > + Test that Atomics.wait returns the right result when it was awoken before + a timeout +info: | + Atomics.wait( typedArray, index, value, timeout ) + + 2.Let i be ? ValidateAtomicAccess(typedArray, index). + ... + 2.Let accessIndex be ? ToIndex(requestIndex). + + 9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception. + ... + 3.If bufferData is a Data Block, return false + + If value is undefined, then + Let index be 0. +includes: [atomicsHelper.js] +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +---*/ + +const RUNNING = 1; +const TIMEOUT = $262.agent.timeouts.huge; + +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + Atomics.add(i64a, ${RUNNING}, 1n); + + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT}); + const duration = $262.agent.monotonicNow() - before; + + $262.agent.report(duration); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.safeBroadcast(i64a); +$262.agent.waitUntil(i64a, RUNNING, 1n); + +// Try to yield control to ensure the agent actually started to wait. +$262.agent.tryYield(); + +assert.sameValue(Atomics.notify(i64a, 0), 1, 'Atomics.notify(i64a, 0) returns 1'); + +const lapse = $262.agent.getReport(); + +assert( + lapse < TIMEOUT, + 'The result of `(lapse < TIMEOUT)` is true' +); +assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"'); + +reportCompare(0, 0); |