diff --git a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-add.js b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-add.js new file mode 100644 index 0000000000..ee9a78e4dd --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-add.js @@ -0,0 +1,47 @@ +// 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 +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +const TIMEOUT = 2000; +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + var before = $262.agent.monotonicNow(); + var unpark = Atomics.wait(i64a, 0, 0, ${TIMEOUT}); + $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(100); + +Atomics.add(i64a, 0, 1); + +const lapse = getReport(); +assert( + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` +); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i64a, 0), 0); + + diff --git a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-and.js b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-and.js new file mode 100644 index 0000000000..1e056bb72b --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-and.js @@ -0,0 +1,47 @@ +// 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 wake on index which is subject to And operation +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +const TIMEOUT = 2000; +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0, ${TIMEOUT}); + $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(100); + +Atomics.and(i64a, 0, 1); + +const lapse = getReport(); +assert( + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` +); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i64a, 0), 0); + + diff --git a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-compareExchange.js b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-compareExchange.js new file mode 100644 index 0000000000..ee07ce4edb --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-compareExchange.js @@ -0,0 +1,45 @@ +// 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 wake on index which is subject to compareExchange operation +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +const TIMEOUT = 2000; +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0, ${TIMEOUT}); + $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(100); + +Atomics.compareExchange(i64a, 0, 0, 1); + +const lapse = getReport(); +assert( + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` +); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i64a, 0), 0); diff --git a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-exchange.js b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-exchange.js new file mode 100644 index 0000000000..7c1d11e91b --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-exchange.js @@ -0,0 +1,46 @@ +// 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 wake on index which is subject to exchange operation +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +const TIMEOUT = 2000; +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0, ${TIMEOUT}); + $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(100); + +Atomics.exchange(i64a, 0, 1); + +const lapse = getReport(); +assert( + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` +); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i64a, 0), 0); + diff --git a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-or.js b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-or.js new file mode 100644 index 0000000000..03d05e02c6 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-or.js @@ -0,0 +1,47 @@ +// 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 wake on index which is subject to Or operation +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +const TIMEOUT = 2000; +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0, ${TIMEOUT}); + $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(100); + +Atomics.or(i64a, 0, 1); + +const lapse = getReport(); +assert( + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` +); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i64a, 0), 0); + + diff --git a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store-padded-time.js b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store-padded-time.js deleted file mode 100644 index 2e7b540f65..0000000000 --- a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store-padded-time.js +++ /dev/null @@ -1,39 +0,0 @@ -// 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 actually waits and does not spuriously wake - up when the memory value is changed. -includes: [atomicsHelper.js] -features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] ----*/ - -$262.agent.start(` -$262.agent.receiveBroadcast(function(sab, id) { - var ia = new BigInt64Array(sab); - var then = $262.agent.monotonicNow(); - Atomics.wait(ia, 0, 0); - var diff = $262.agent.monotonicNow() - then; // Should be about 1000 ms but can be more - $262.agent.report(diff); - $262.agent.leaving(); -}) -`); - -var ia = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); - -$262.agent.broadcast(ia.buffer); -$262.agent.sleep(500); // Give the agent a chance to wait -Atomics.store(ia, 0, 1); // Change the value, should not wake the agent -$262.agent.sleep(500); // Wait some more so that we can tell -Atomics.wake(ia, 0); // Really wake it up -assert.sameValue((getReport() | 0) >= 1000 - $ATOMICS_MAX_TIME_EPSILON, true); - -function getReport() { - var r; - while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(10); - } - return r; -} diff --git a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store.js b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store.js index 2296fb1f0d..b97b74ba99 100644 --- a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store.js +++ b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-store.js @@ -15,36 +15,32 @@ function getReport() { return r; } -const TWO_SECOND_TIMEOUT = 2000; +const TIMEOUT = 2000; const i64a = new BigInt64Array( new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) ); $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { - var i64a = new BigInt64Array(sab); - var before = $262.agent.monotonicNow(); - $262.agent.report("ready"); - Atomics.wait(i64a, 0, 0, ${TWO_SECOND_TIMEOUT}); + const i64a = new BigInt64Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0, ${TIMEOUT}); $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); $262.agent.leaving(); }); `); $262.agent.broadcast(i64a.buffer); - -assert.sameValue(getReport(), "ready"); +$262.agent.sleep(100); Atomics.store(i64a, 0, 0x111111); -// We should expect that the waiting agents will continue to -// wait until they both timeout. If either of them reports -// a value that is less than the timeout value, it may mean that -// calling Atomics.store(...) is causing the agents to wake. -// -var lapse = getReport(); - +const lapse = getReport(); assert( - lapse >= TWO_SECOND_TIMEOUT, - `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` ); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i64a, 0), 0); + diff --git a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-sub.js b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-sub.js new file mode 100644 index 0000000000..7412a9adcb --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-sub.js @@ -0,0 +1,45 @@ +// 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 wake on index which is subject to Sub operation +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +const TIMEOUT = 2000; +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0, ${TIMEOUT}); + $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(100); + +Atomics.sub(i64a, 0, 1); + +const lapse = getReport(); +assert( + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` +); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i64a, 0), 0); diff --git a/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-xor.js b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-xor.js new file mode 100644 index 0000000000..20a7113436 --- /dev/null +++ b/test/built-ins/Atomics/wait/bigint/no-spurious-wakeup-on-xor.js @@ -0,0 +1,48 @@ +// 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 wake on index which is subject to xor operation +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +const TIMEOUT = 2000; +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + const i64a = new BigInt64Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i64a, 0, 0, ${TIMEOUT}); + $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(100); + +Atomics.xor(i64a, 0, 1); + +const lapse = getReport(); +assert( + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` +); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i64a, 0), 0); + + + diff --git a/test/built-ins/Atomics/wait/bigint/non-bigint64-typedarray-throws.js b/test/built-ins/Atomics/wait/bigint/non-bigint64-typedarray-throws.js index dfcc193b22..81b22757fc 100644 --- a/test/built-ins/Atomics/wait/bigint/non-bigint64-typedarray-throws.js +++ b/test/built-ins/Atomics/wait/bigint/non-bigint64-typedarray-throws.js @@ -10,8 +10,8 @@ info: | 1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true). ... - 5.If onlyInt32 is true, then - If typeName is not "Int32Array" or "BigInt64Array", throw a TypeError exception. + 5.If onlyBigInt64 is true, then + If typeName is not "BigInt64Array" or "BigInt64Array", throw a TypeError exception. features: [Atomics, Float32Array, Float64Array, Int8Array, TypedArray, Uint16Array, Uint8Array, Uint8ClampedArray] includes: [testAtomics.js, testBigIntTypedArray.js] ---*/ diff --git a/test/built-ins/Atomics/wait/bigint/value-not-equal.js b/test/built-ins/Atomics/wait/bigint/value-not-equal.js index 3541a6409f..df97451291 100644 --- a/test/built-ins/Atomics/wait/bigint/value-not-equal.js +++ b/test/built-ins/Atomics/wait/bigint/value-not-equal.js @@ -8,7 +8,7 @@ description: > info: | Atomics.wait( typedArray, index, value, timeout ) - 3.Let v be ? ToInt32(value). + 3.Let v be ? ToBigInt64(value). ... 14.If v is not equal to w, then a.Perform LeaveCriticalSection(WL). diff --git a/test/built-ins/Atomics/wait/did-timeout.js b/test/built-ins/Atomics/wait/did-timeout.js index 41ff82f5a6..c3fe8a8270 100644 --- a/test/built-ins/Atomics/wait/did-timeout.js +++ b/test/built-ins/Atomics/wait/did-timeout.js @@ -31,7 +31,7 @@ $262.agent.receiveBroadcast(function(sab, id) { $262.agent.report(Atomics.wait(i32a, 0, 0, 500)); // Timeout 500ms $262.agent.report($262.agent.monotonicNow() - before); // Actual time can be more than 500ms $262.agent.leaving(); -}) +}); `); var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); diff --git a/test/built-ins/Atomics/wait/false-for-timeout-agent.js b/test/built-ins/Atomics/wait/false-for-timeout-agent.js index 346ff60687..71a396bc10 100644 --- a/test/built-ins/Atomics/wait/false-for-timeout-agent.js +++ b/test/built-ins/Atomics/wait/false-for-timeout-agent.js @@ -46,7 +46,7 @@ $262.agent.receiveBroadcast(function(sab) { $262.agent.report(Atomics.wait(i32a, 0, 0, toPrimitive)); $262.agent.report($262.agent.monotonicNow() - before); $262.agent.leaving(); -}) +}); `); var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-add.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-add.js index 24fde8580b..1e70eeecbe 100644 --- a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-add.js +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-add.js @@ -4,7 +4,7 @@ /*--- esid: sec-atomics.wait description: > - Demonstrates that Atomics.store(...) is causing a waiting + Waiter does not spuriously wake on index which is subject to Add operation features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ function getReport() { @@ -15,7 +15,7 @@ function getReport() { return r; } -const TWO_SECOND_TIMEOUT = 2000; +const TIMEOUT = 2000; const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) ); @@ -24,29 +24,24 @@ $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { var i32a = new Int32Array(sab); var before = $262.agent.monotonicNow(); - $262.agent.report("ready"); - Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + var unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT}); $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); $262.agent.leaving(); }); `); $262.agent.broadcast(i32a.buffer); - -assert.sameValue(getReport(), "ready"); +$262.agent.sleep(100); Atomics.add(i32a, 0, 1); -// We should expect that the waiting agents will continue to -// wait until they both timeout. If either of them reports -// a value that is less than the timeout value, it may mean that -// calling Atomics.store(...) is causing the agents to wake. -// -var lapse = getReport(); - +const lapse = getReport(); assert( - lapse >= TWO_SECOND_TIMEOUT, - `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` ); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-and.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-and.js index 4c69ef53f7..345fe9a5b9 100644 --- a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-and.js +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-and.js @@ -4,7 +4,7 @@ /*--- esid: sec-atomics.wait description: > - Demonstrates that Atomics.store(...) is causing a waiting + Waiter does not spuriously wake on index which is subject to And operation features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ function getReport() { @@ -15,38 +15,33 @@ function getReport() { return r; } -const TWO_SECOND_TIMEOUT = 2000; +const TIMEOUT = 2000; const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) ); $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); - var before = $262.agent.monotonicNow(); - $262.agent.report("ready"); - Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + const i32a = new Int32Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT}); $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); $262.agent.leaving(); }); `); $262.agent.broadcast(i32a.buffer); - -assert.sameValue(getReport(), "ready"); +$262.agent.sleep(100); Atomics.and(i32a, 0, 1); -// We should expect that the waiting agents will continue to -// wait until they both timeout. If either of them reports -// a value that is less than the timeout value, it may mean that -// calling Atomics.store(...) is causing the agents to wake. -// -var lapse = getReport(); - +const lapse = getReport(); assert( - lapse >= TWO_SECOND_TIMEOUT, - `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` ); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-compareExchange.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-compareExchange.js index 81458cf612..16aedd6aa1 100644 --- a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-compareExchange.js +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-compareExchange.js @@ -4,7 +4,7 @@ /*--- esid: sec-atomics.wait description: > - Demonstrates that Atomics.store(...) is causing a waiting + Waiter does not spuriously wake on index which is subject to compareExchange operation features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ function getReport() { @@ -15,38 +15,31 @@ function getReport() { return r; } -const TWO_SECOND_TIMEOUT = 2000; +const TIMEOUT = 2000; const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) ); $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); - var before = $262.agent.monotonicNow(); - $262.agent.report("ready"); - Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + const i32a = new Int32Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT}); $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); $262.agent.leaving(); }); `); $262.agent.broadcast(i32a.buffer); - -assert.sameValue(getReport(), "ready"); +$262.agent.sleep(100); Atomics.compareExchange(i32a, 0, 0, 1); -// We should expect that the waiting agents will continue to -// wait until they both timeout. If either of them reports -// a value that is less than the timeout value, it may mean that -// calling Atomics.store(...) is causing the agents to wake. -// -var lapse = getReport(); - +const lapse = getReport(); assert( - lapse >= TWO_SECOND_TIMEOUT, - `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` ); - - +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-exchange.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-exchange.js index 383c548e5d..f9d0aa3d29 100644 --- a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-exchange.js +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-exchange.js @@ -4,7 +4,7 @@ /*--- esid: sec-atomics.wait description: > - Demonstrates that Atomics.store(...) is causing a waiting + Waiter does not spuriously wake on index which is subject to exchange operation features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ function getReport() { @@ -15,38 +15,32 @@ function getReport() { return r; } -const TWO_SECOND_TIMEOUT = 2000; +const TIMEOUT = 2000; const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) ); $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); - var before = $262.agent.monotonicNow(); - $262.agent.report("ready"); - Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + const i32a = new Int32Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT}); $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); $262.agent.leaving(); }); `); $262.agent.broadcast(i32a.buffer); - -assert.sameValue(getReport(), "ready"); +$262.agent.sleep(100); Atomics.exchange(i32a, 0, 1); -// We should expect that the waiting agents will continue to -// wait until they both timeout. If either of them reports -// a value that is less than the timeout value, it may mean that -// calling Atomics.store(...) is causing the agents to wake. -// -var lapse = getReport(); - +const lapse = getReport(); assert( - lapse >= TWO_SECOND_TIMEOUT, - `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` ); - +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-or.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-or.js index cb0ce55a7b..04c9f819af 100644 --- a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-or.js +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-or.js @@ -4,7 +4,7 @@ /*--- esid: sec-atomics.wait description: > - Demonstrates that Atomics.store(...) is causing a waiting + Waiter does not spuriously wake on index which is subject to Or operation features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ function getReport() { @@ -15,38 +15,33 @@ function getReport() { return r; } -const TWO_SECOND_TIMEOUT = 2000; +const TIMEOUT = 2000; const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) ); $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); - $262.agent.report("ready"); - var before = $262.agent.monotonicNow(); - Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + const i32a = new Int32Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT}); $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); $262.agent.leaving(); }); `); $262.agent.broadcast(i32a.buffer); - -assert.sameValue(getReport(), "ready"); +$262.agent.sleep(100); Atomics.or(i32a, 0, 1); -// We should expect that the waiting agents will continue to -// wait until they both timeout. If either of them reports -// a value that is less than the timeout value, it may mean that -// calling Atomics.store(...) is causing the agents to wake. -// -var lapse = getReport(); - +const lapse = getReport(); assert( - lapse >= TWO_SECOND_TIMEOUT, - `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` ); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-padded-time.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-padded-time.js deleted file mode 100644 index 077cef3db7..0000000000 --- a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-padded-time.js +++ /dev/null @@ -1,39 +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 that Atomics.wait actually waits and does not spuriously wake - up when the memory value is changed. -includes: [atomicsHelper.js] -features: [Atomics, SharedArrayBuffer, TypedArray] ----*/ - -$262.agent.start(` -$262.agent.receiveBroadcast(function(sab, id) { - var i32a = new Int32Array(sab); - var then = $262.agent.monotonicNow(); - Atomics.wait(i32a, 0, 0); - var diff = $262.agent.monotonicNow() - then; // Should be about 1000 ms but can be more - $262.agent.report(diff); - $262.agent.leaving(); -}); -`); - -var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); - -$262.agent.broadcast(i32a.buffer); -$262.agent.sleep(500); // Give the agent a chance to wait -Atomics.store(i32a, 0, 1); // Change the value, should not wake the agent -$262.agent.sleep(500); // Wait some more so that we can tell -Atomics.wake(i32a, 0); // Really wake it up -assert.sameValue((getReport() | 0) >= 1000 - $ATOMICS_MAX_TIME_EPSILON, true); - -function getReport() { - var r; - while ((r = $262.agent.getReport()) == null) { - $262.agent.sleep(10); - } - return r; -} diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store.js index fbac920c93..bc4e315847 100644 --- a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store.js +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store.js @@ -4,7 +4,7 @@ /*--- esid: sec-atomics.wait description: > - Demonstrates that Atomics.store(...) is causing a waiting + Waiter does not spuriously wake on index which is subject to Store operation features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ function getReport() { @@ -15,38 +15,32 @@ function getReport() { return r; } -const TWO_SECOND_TIMEOUT = 2000; +const TIMEOUT = 2000; const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) ); $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); - var before = $262.agent.monotonicNow(); - $262.agent.report("ready"); - Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + const i32a = new Int32Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT}); $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); $262.agent.leaving(); }); `); $262.agent.broadcast(i32a.buffer); - -assert.sameValue(getReport(), "ready"); +$262.agent.sleep(100); Atomics.store(i32a, 0, 0x111111); -// We should expect that the waiting agents will continue to -// wait until they both timeout. If either of them reports -// a value that is less than the timeout value, it may mean that -// calling Atomics.store(...) is causing the agents to wake. -// -var lapse = getReport(); - +const lapse = getReport(); assert( - lapse >= TWO_SECOND_TIMEOUT, - `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` ); - +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-sub.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-sub.js index 908f30e37a..1de7591ad4 100644 --- a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-sub.js +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-sub.js @@ -4,7 +4,7 @@ /*--- esid: sec-atomics.wait description: > - Demonstrates that Atomics.store(...) is causing a waiting + Waiter does not spuriously wake on index which is subject to Sub operation features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ function getReport() { @@ -15,38 +15,31 @@ function getReport() { return r; } -const TWO_SECOND_TIMEOUT = 2000; +const TIMEOUT = 2000; const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) ); $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); - var before = $262.agent.monotonicNow(); - $262.agent.report("ready"); - Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + const i32a = new Int32Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT}); $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); $262.agent.leaving(); }); `); $262.agent.broadcast(i32a.buffer); - -assert.sameValue(getReport(), "ready"); +$262.agent.sleep(100); Atomics.sub(i32a, 0, 1); -// We should expect that the waiting agents will continue to -// wait until they both timeout. If either of them reports -// a value that is less than the timeout value, it may mean that -// calling Atomics.store(...) is causing the agents to wake. -// -var lapse = getReport(); - +const lapse = getReport(); assert( - lapse >= TWO_SECOND_TIMEOUT, - `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` ); - - +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-xor.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-xor.js index 5356b3fd77..10d3d58144 100644 --- a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-xor.js +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-xor.js @@ -4,7 +4,7 @@ /*--- esid: sec-atomics.wait description: > - Demonstrates that Atomics.store(...) is causing a waiting + Waiter does not spuriously wake on index which is subject to xor operation features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ function getReport() { @@ -15,38 +15,34 @@ function getReport() { return r; } -const TWO_SECOND_TIMEOUT = 2000; +const TIMEOUT = 2000; const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) ); $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); - var before = $262.agent.monotonicNow(); - $262.agent.report("ready"); - Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + const i32a = new Int32Array(sab); + const before = $262.agent.monotonicNow(); + const unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT}); $262.agent.report($262.agent.monotonicNow() - before); + $262.agent.report(unpark); $262.agent.leaving(); }); `); $262.agent.broadcast(i32a.buffer); - -assert.sameValue(getReport(), "ready"); +$262.agent.sleep(100); Atomics.xor(i32a, 0, 1); -// We should expect that the waiting agents will continue to -// wait until they both timeout. If either of them reports -// a value that is less than the timeout value, it may mean that -// calling Atomics.store(...) is causing the agents to wake. -// -var lapse = getReport(); - +const lapse = getReport(); assert( - lapse >= TWO_SECOND_TIMEOUT, - `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` + lapse >= TIMEOUT, + `${lapse} should be at least ${TIMEOUT}` ); +assert.sameValue(getReport(), 'timed-out'); +assert.sameValue(Atomics.wake(i32a, 0), 0); + diff --git a/test/built-ins/Atomics/wait/null-for-timeout-agent.js b/test/built-ins/Atomics/wait/null-for-timeout-agent.js index 1793d59ffd..64850f1c0e 100644 --- a/test/built-ins/Atomics/wait/null-for-timeout-agent.js +++ b/test/built-ins/Atomics/wait/null-for-timeout-agent.js @@ -46,7 +46,7 @@ $262.agent.receiveBroadcast(function(sab) { $262.agent.report(Atomics.wait(i32a, 0, 0, toPrimitive)); $262.agent.report($262.agent.monotonicNow() - before); $262.agent.leaving(); -}) +}); `); var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); @@ -62,7 +62,7 @@ var timeDiffReport = getReport(); assert(timeDiffReport >= 0, 'timeout should be a min of 0ms'); -assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, 'timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON'); +assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, 'timeout should be a max of $ATOMICS_MAX_TIME_EPSILON'); assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/object-for-timeout-agent.js b/test/built-ins/Atomics/wait/object-for-timeout-agent.js index 477d24df09..11b7aee594 100644 --- a/test/built-ins/Atomics/wait/object-for-timeout-agent.js +++ b/test/built-ins/Atomics/wait/object-for-timeout-agent.js @@ -53,7 +53,7 @@ $262.agent.receiveBroadcast(function(sab) { $262.agent.report(Atomics.wait(i32a, 0, 0, toPrimitive)); $262.agent.report($262.agent.monotonicNow() - start); $262.agent.leaving(); -}) +}); `); var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));