Skip to content

Commit d9e4998

Browse files
tony-gotargos
authored andcommitted
test: add trace-gc flag test
PR-URL: #42471 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
1 parent a2bbd36 commit d9e4998

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

test/fixtures/gc.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let arr = new Array(300_000).fill('a');
2+
3+
for (let index = 0; index < arr.length; index++) {
4+
arr[index] = Math.random();
5+
}
6+
7+
arr = [];
8+
// .gc() is called to generate a Mark-sweep event
9+
global.gc();

test/v8-updates/test-trace-gc-flag.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
// This test verifies that `--trace-gc` flag is well integrated.
4+
// We'll check here, that the console outputs gc events properly.
5+
require('../common');
6+
7+
const assert = require('assert');
8+
const { spawnSync } = require('child_process');
9+
10+
const fixtures = require('../common/fixtures');
11+
12+
{
13+
const childProcess = spawnSync(process.execPath, [
14+
'--trace-gc',
15+
'--expose-gc',
16+
fixtures.path('gc.js'),
17+
]);
18+
const output = childProcess.stdout.toString().trim();
19+
const lines = splitByLine(output);
20+
21+
const scavengeRegex = /\bScavenge\b/;
22+
const expectedOutput = [
23+
scavengeRegex,
24+
scavengeRegex,
25+
scavengeRegex,
26+
scavengeRegex,
27+
/\bMark-sweep\b/,
28+
];
29+
lines.forEach((line, index) => {
30+
assert.match(line, expectedOutput[index]);
31+
});
32+
}
33+
34+
/**
35+
* HELPERS
36+
*/
37+
38+
function splitByLine(str) {
39+
return str.split(/\n/);
40+
}

0 commit comments

Comments
 (0)