mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
Atomics: spurious wakeup tests for all operations that alter value at index
This commit is contained in:
parent
13446afa37
commit
89fda0dbd5
@ -16,26 +16,26 @@ function getReport() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TWO_SECOND_TIMEOUT = 2000;
|
const TWO_SECOND_TIMEOUT = 2000;
|
||||||
const i32 = new Int32Array(
|
const i32a = new Int32Array(
|
||||||
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
|
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
|
||||||
);
|
);
|
||||||
|
|
||||||
$262.agent.start(`
|
$262.agent.start(`
|
||||||
$262.agent.receiveBroadcast(function(sab) {
|
$262.agent.receiveBroadcast(function(sab) {
|
||||||
var i32 = new Int32Array(sab);
|
var i32a = new Int32Array(sab);
|
||||||
var before = Date.now();
|
var before = Date.now();
|
||||||
$262.agent.report("ready");
|
$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.report(Date.now() - before);
|
||||||
$262.agent.leaving();
|
$262.agent.leaving();
|
||||||
});
|
});
|
||||||
`);
|
`);
|
||||||
|
|
||||||
$262.agent.broadcast(i32.buffer);
|
$262.agent.broadcast(i32a.buffer);
|
||||||
|
|
||||||
assert.sameValue(getReport(), "ready");
|
assert.sameValue(getReport(), "ready");
|
||||||
|
|
||||||
Atomics.add(i32, 0, 1);
|
Atomics.add(i32a, 0, 1);
|
||||||
|
|
||||||
// We should expect that the waiting agents will continue to
|
// We should expect that the waiting agents will continue to
|
||||||
// wait until they both timeout. If either of them reports
|
// wait until they both timeout. If either of them reports
|
||||||
|
52
test/built-ins/Atomics/wait/no-spurious-wakeup-on-and.js
Normal file
52
test/built-ins/Atomics/wait/no-spurious-wakeup-on-and.js
Normal file
@ -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}`
|
||||||
|
);
|
||||||
|
|
||||||
|
|
@ -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}`
|
||||||
|
);
|
||||||
|
|
||||||
|
|
@ -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}`
|
||||||
|
);
|
||||||
|
|
||||||
|
|
@ -24,16 +24,29 @@ $262.agent.start(`
|
|||||||
$262.agent.receiveBroadcast(function(sab) {
|
$262.agent.receiveBroadcast(function(sab) {
|
||||||
var i32a = new Int32Array(sab);
|
var i32a = new Int32Array(sab);
|
||||||
var before = Date.now();
|
var before = Date.now();
|
||||||
|
$262.agent.report("ready");
|
||||||
Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT});
|
Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT});
|
||||||
$262.agent.report("done");
|
$262.agent.report(Date.now() - before);
|
||||||
$262.agent.leaving();
|
$262.agent.leaving();
|
||||||
});
|
});
|
||||||
`);
|
`);
|
||||||
|
|
||||||
$262.agent.broadcast(i32a.buffer);
|
$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}`
|
||||||
|
);
|
||||||
|
|
||||||
|
|
52
test/built-ins/Atomics/wait/no-spurious-wakeup-on-sub.js
Normal file
52
test/built-ins/Atomics/wait/no-spurious-wakeup-on-sub.js
Normal file
@ -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}`
|
||||||
|
);
|
||||||
|
|
||||||
|
|
52
test/built-ins/Atomics/wait/no-spurious-wakeup-on-xor.js
Normal file
52
test/built-ins/Atomics/wait/no-spurious-wakeup-on-xor.js
Normal file
@ -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}`
|
||||||
|
);
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user