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 19fd89071e..14eafc31f7 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 @@ -16,26 +16,26 @@ function getReport() { } const TWO_SECOND_TIMEOUT = 2000; -const i32 = new Int32Array( +const i32a = new Int32Array( new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) ); $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { - var i32 = new Int32Array(sab); + var i32a = new Int32Array(sab); var before = Date.now(); $262.agent.report("ready"); - Atomics.wait(i32, 0, 0, ${TWO_SECOND_TIMEOUT}); + Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); $262.agent.report(Date.now() - before); $262.agent.leaving(); }); `); -$262.agent.broadcast(i32.buffer); +$262.agent.broadcast(i32a.buffer); assert.sameValue(getReport(), "ready"); -Atomics.add(i32, 0, 1); +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 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 new file mode 100644 index 0000000000..64be29377e --- /dev/null +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-and.js @@ -0,0 +1,52 @@ +// 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 TWO_SECOND_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 = Date.now(); + $262.agent.report("ready"); + Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + $262.agent.report(Date.now() - before); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i32a.buffer); + +assert.sameValue(getReport(), "ready"); + +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(); + +assert( + lapse >= TWO_SECOND_TIMEOUT, + `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` +); + + 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 new file mode 100644 index 0000000000..1aec3286c2 --- /dev/null +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-compareExchange.js @@ -0,0 +1,52 @@ +// 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 TWO_SECOND_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 = Date.now(); + $262.agent.report("ready"); + Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + $262.agent.report(Date.now() - before); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i32a.buffer); + +assert.sameValue(getReport(), "ready"); + +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(); + +assert( + lapse >= TWO_SECOND_TIMEOUT, + `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` +); + + 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 new file mode 100644 index 0000000000..cb3f1d97f3 --- /dev/null +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-exchange.js @@ -0,0 +1,52 @@ +// 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 TWO_SECOND_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 = Date.now(); + $262.agent.report("ready"); + Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + $262.agent.report(Date.now() - before); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i32a.buffer); + +assert.sameValue(getReport(), "ready"); + +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(); + +assert( + lapse >= TWO_SECOND_TIMEOUT, + `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` +); + + diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-no-sleep.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-or.js similarity index 60% rename from test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-no-sleep.js rename to test/built-ins/Atomics/wait/no-spurious-wakeup-on-or.js index 97fdbdacce..258ecce13f 100644 --- a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-no-sleep.js +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-or.js @@ -24,16 +24,29 @@ $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { var i32a = new Int32Array(sab); var before = Date.now(); + $262.agent.report("ready"); Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); - $262.agent.report("done"); + $262.agent.report(Date.now() - before); $262.agent.leaving(); }); `); $262.agent.broadcast(i32a.buffer); -$262.agent.sleep(10); -Atomics.store(i32a, 0, 0x111111); -assert.sameValue(getReport(), "done"); +assert.sameValue(getReport(), "ready"); + +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(); + +assert( + lapse >= TWO_SECOND_TIMEOUT, + `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` +); 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 new file mode 100644 index 0000000000..0bd3ee6e82 --- /dev/null +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-sub.js @@ -0,0 +1,52 @@ +// 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 TWO_SECOND_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 = Date.now(); + $262.agent.report("ready"); + Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + $262.agent.report(Date.now() - before); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i32a.buffer); + +assert.sameValue(getReport(), "ready"); + +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(); + +assert( + lapse >= TWO_SECOND_TIMEOUT, + `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` +); + + 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 new file mode 100644 index 0000000000..ff4796715e --- /dev/null +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-xor.js @@ -0,0 +1,52 @@ +// 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 TWO_SECOND_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 = Date.now(); + $262.agent.report("ready"); + Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + $262.agent.report(Date.now() - before); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i32a.buffer); + +assert.sameValue(getReport(), "ready"); + +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(); + +assert( + lapse >= TWO_SECOND_TIMEOUT, + `${lapse} should be at least ${TWO_SECOND_TIMEOUT}` +); + +