mirror of https://github.com/tc39/test262.git
Atomics: spurious wakeup tests
This commit is contained in:
parent
22d3877a2a
commit
ab72a55748
|
@ -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);
|
||||
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
@ -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);
|
|
@ -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);
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
@ -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]
|
||||
---*/
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue