Skip to content

Commit 4fb193d

Browse files
committed
fixup! cli: add --trace-atomics-wait flag
1 parent f982160 commit 4fb193d

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

doc/api/cli.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -837,11 +837,11 @@ The output could look like this:
837837

838838
The fields here correspond to:
839839

840-
- The thread id as given by [`worker_threads.threadId`][]
841-
- The base address of the `SharedArrayBuffer` in question, as well as the
840+
* The thread id as given by [`worker_threads.threadId`][]
841+
* The base address of the `SharedArrayBuffer` in question, as well as the
842842
byte offset corresponding to the index passed to `Atomics.wait()`
843-
- The expected value that was passed to `Atomics.wait()`
844-
- The timeout passed to `Atomics.wait`
843+
* The expected value that was passed to `Atomics.wait()`
844+
* The timeout passed to `Atomics.wait`
845845

846846
### `--trace-deprecation`
847847
<!-- YAML

test/parallel/test-trace-atomics-wait.js

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,48 @@ const proc = child_process.spawnSync(
3131
if (proc.status !== 0) console.log(proc);
3232
assert.strictEqual(proc.status, 0);
3333

34-
const expectedLines = [
35-
{ threadId: 0, offset: 0, value: 1, timeout: 'inf',
36-
message: 'started' },
37-
{ threadId: 0, offset: 0, value: 1, timeout: 'inf',
38-
message: 'did not wait because the values mismatched' },
39-
{ threadId: 0, offset: 0, value: 0, timeout: '10',
40-
message: 'started' },
41-
{ threadId: 0, offset: 0, value: 0, timeout: '10',
42-
message: 'timed out' },
43-
{ threadId: 0, offset: 4, value: 0, timeout: 'inf',
44-
message: 'started' },
45-
{ threadId: 1, offset: 4, value: -1, timeout: 'inf',
46-
message: 'started' },
47-
{ threadId: 0, offset: 4, value: 0, timeout: 'inf',
48-
message: 'was woken up by another thread' },
49-
{ threadId: 1, offset: 4, value: -1, timeout: 'inf',
50-
message: 'was woken up by another thread' }
51-
];
34+
const SABAddress = proc.stderr.match(/Atomics\.wait\((?<SAB>.+) \+/).groups.SAB;
35+
const actualTimeline = proc.stderr
36+
.replace(new RegExp(SABAddress, 'g'), '<address>')
37+
.replace(/infinity/g, 'inf')
38+
.replace(/\r/g, '')
39+
.trim();
40+
console.log('+++ normalized stdout +++');
41+
console.log(actualTimeline);
42+
console.log('--- normalized stdout ---');
5243

53-
let SABAddress;
54-
const re = /^\[Thread (?<threadId>\d+)\] Atomics\.wait\((?<SAB>(?:0x)?[0-9a-f]+) \+ (?<offset>\d+), (?<value>-?\d+), (?<timeout>inf|infinity|[0-9.]+)\) (?<message>.+)$/;
55-
for (const line of proc.stderr.split('\n').map((line) => line.trim())) {
56-
if (!line) continue;
57-
console.log('Matching', { line });
58-
const actual = line.match(re).groups;
59-
const expected = expectedLines.shift();
44+
const begin =
45+
`[Thread 0] Atomics.wait(<address> + 0, 1, inf) started
46+
[Thread 0] Atomics.wait(<address> + 0, 1, inf) did not wait because the \
47+
values mismatched
48+
[Thread 0] Atomics.wait(<address> + 0, 0, 10) started
49+
[Thread 0] Atomics.wait(<address> + 0, 0, 10) timed out`;
6050

61-
if (SABAddress === undefined)
62-
SABAddress = actual.SAB;
63-
else
64-
assert.strictEqual(actual.SAB, SABAddress);
51+
const expectedTimelines = [
52+
`${begin}
53+
[Thread 0] Atomics.wait(<address> + 4, 0, inf) started
54+
[Thread 1] Atomics.wait(<address> + 4, -1, inf) started
55+
[Thread 0] Atomics.wait(<address> + 4, 0, inf) was woken up by another thread
56+
[Thread 1] Atomics.wait(<address> + 4, -1, inf) was woken up by another thread`,
57+
`${begin}
58+
[Thread 0] Atomics.wait(<address> + 4, 0, inf) started
59+
[Thread 0] Atomics.wait(<address> + 4, 0, inf) was woken up by another thread
60+
[Thread 1] Atomics.wait(<address> + 4, -1, inf) started
61+
[Thread 1] Atomics.wait(<address> + 4, -1, inf) did not wait because the \
62+
values mismatched`,
63+
`${begin}
64+
[Thread 0] Atomics.wait(<address> + 4, 0, inf) started
65+
[Thread 1] Atomics.wait(<address> + 4, -1, inf) started
66+
[Thread 0] Atomics.wait(<address> + 4, 0, inf) was woken up by another thread
67+
[Thread 1] Atomics.wait(<address> + 4, -1, inf) did not wait because the \
68+
values mismatched`,
69+
`${begin}
70+
[Thread 0] Atomics.wait(<address> + 4, 0, inf) started
71+
[Thread 0] Atomics.wait(<address> + 4, 0, inf) did not wait because the \
72+
values mismatched
73+
[Thread 1] Atomics.wait(<address> + 4, -1, inf) started
74+
[Thread 1] Atomics.wait(<address> + 4, -1, inf) did not wait because the \
75+
values mismatched`
76+
];
6577

66-
assert.strictEqual(+actual.threadId, expected.threadId);
67-
assert.strictEqual(+actual.offset, expected.offset);
68-
assert.strictEqual(+actual.value, expected.value);
69-
assert.strictEqual(actual.message, expected.message);
70-
if (expected.timeout === 'inf')
71-
assert.match(actual.timeout, /inf(inity)?/);
72-
else
73-
assert.strictEqual(actual.timeout, expected.timeout);
74-
}
78+
assert(expectedTimelines.includes(actualTimeline));

0 commit comments

Comments
 (0)