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 0000000000000000000000000000000000000000..ee9a78e4ddcc6d4a93f0ceb087236bb90826424b --- /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 0000000000000000000000000000000000000000..1e056bb72b8b6830ba7485547d0f144c5b4d2b14 --- /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 0000000000000000000000000000000000000000..ee07ce4edba928624c52aaa44d9886d78e805f3b --- /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 0000000000000000000000000000000000000000..7c1d11e91b9f9920c62369b6894d83a43719128a --- /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 0000000000000000000000000000000000000000..03d05e02c61f1810e6295e1df1c5f65ed2531e8e --- /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 2e7b540f6578388410fdd5d39799af15597d39d7..0000000000000000000000000000000000000000 --- 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 2296fb1f0d3766811011674d6d0612f0a53f876b..b97b74ba993429711ec09a7409e8cb2e2cf966b4 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 0000000000000000000000000000000000000000..7412a9adcb4fa7576e983a80cd7257e31507dca4 --- /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 0000000000000000000000000000000000000000..20a711343636309a32927398b5f4413c250d8668 --- /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 dfcc193b2270a5cd17158623fda9d5babed45d65..81b22757fc572d186de42cb3400df0da589d02d1 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 3541a6409f64c85ae04c5db8c6981841c1359f95..df97451291a17caa763625fbf8e93de6e68c3f16 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 41ff82f5a65d0a987f253cc58a34b47c2a2e45fa..c3fe8a8270f7ad91fae59facc570ba0416ff27a2 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 346ff606870f72aac3c1ea45a2c44355c9297c96..71a396bc1048fb06959c5a483860a66e368bad58 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 24fde8580b6366203799c811d69525c9a0489aed..1e70eeecbeeb3434ad5c152bab2ee7672b946fdf 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 4c69ef53f7ca0c4f64f18388f9e2a5df4b9c0e42..345fe9a5b96783a50029d83577961683277b77c2 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 81458cf612f2f05f895ad57bf2d697fd6470b186..16aedd6aa1a774d2ca46dd7e6209bc6bd989e498 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 383c548e5d9d960cc31cac75cc7838ce9247a466..f9d0aa3d29e8132a14d823689a1071641545c0ee 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 cb0ce55a7b3e0daed2e6483e4712b8c706707701..04c9f819af47aa6ecaf9849e2660180bada57796 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 077cef3db735f73449b02cab0f13191dc870a48a..0000000000000000000000000000000000000000 --- 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 fbac920c9339a20f8c6db092b262163f4e2a18ab..bc4e3158472309f1b63e43ccfe4e52021f2d050e 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 908f30e37a8796d83965d0d6ad2c0f1005c4249d..1de7591ad423034cc1a1d74ecb99b5bf479d398d 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 5356b3fd779cd00d21206f7b2d34271a7ca7a7a5..10d3d581444c8f4516f2c96d856af8f918248543 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 1793d59ffdae3ebe53c9dd452d4064ca89cf969c..64850f1c0efd0d93aecdefbf9afc0873829a8d10 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 477d24df09ae3ba9acbfea67ffec30e9d0c9b7f4..11b7aee594978a31e47536bb4c33a1bb0758a063 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));