Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/wait/no-spurious-wakeup-no-operation.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics
2 // Copyright (C) 2017 Mozilla Corporation. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-atomics.wait
7 description: >
8 Test that Atomics.wait returns the right result when it timed out and that
9 the time to time out is reasonable.
10 info: |
11 17. Let awoken be Suspend(WL, W, t).
12 18. If awoken is true, then
13 a. Assert: W is not on the list of waiters in WL.
14 19. Else,
15 a.Perform RemoveWaiter(WL, W).
16 includes: [atomicsHelper.js]
17 features: [Atomics, SharedArrayBuffer, TypedArray]
18 ---*/
19
20 const RUNNING = 1;
21 const TIMEOUT = $262.agent.timeouts.small;
22
23 const i32a = new Int32Array(
24 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
25 );
26
27 $262.agent.start(`
28 $262.agent.receiveBroadcast(function(sab) {
29 const i32a = new Int32Array(sab);
30 Atomics.add(i32a, ${RUNNING}, 1);
31
32 const before = $262.agent.monotonicNow();
33 const unpark = Atomics.wait(i32a, 0, 0, ${TIMEOUT});
34 const duration = $262.agent.monotonicNow() - before;
35
36 $262.agent.report(duration);
37 $262.agent.report(unpark);
38 $262.agent.leaving();
39 });
40 `);
41
42 $262.agent.safeBroadcast(i32a);
43 $262.agent.waitUntil(i32a, RUNNING, 1);
44
45 // Try to yield control to ensure the agent actually started to wait.
46 $262.agent.tryYield();
47
48 // NO OPERATION OCCURS HERE!
49
50 const lapse = $262.agent.getReport();
51 assert(
52 lapse >= TIMEOUT,
53 'The result of `(lapse >= TIMEOUT)` is true'
54 );
55 assert.sameValue(
56 $262.agent.getReport(),
57 'timed-out',
58 '$262.agent.getReport() returns "timed-out"'
59 );
60 assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
61
62 reportCompare(0, 0);