Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add --trace-gc flag test #42471

Merged
merged 5 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/fixtures/gc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let arr = new Array(300_000).fill('a');

for (let index = 0; index < arr.length; index++) {
arr[index] = Math.random();
}

arr = [];
// .gc() is called to generate a Mark-sweep event
global.gc();
41 changes: 41 additions & 0 deletions test/v8-updates/test-trace-gc-flag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

// This test verifies that `--trace-gc` flag is well integrated.
// We'll check here, that the console outputs gc events properly
tony-go marked this conversation as resolved.
Show resolved Hide resolved
require('../common');

const assert = require('assert');
const { spawnSync } = require('child_process');

const fixtures = require('../common/fixtures');

{
const childProcess = spawnSync(process.execPath, [
'--trace-gc',
'--expose-gc',
fixtures.path('gc.js'),
]);
const output = childProcess.stdout.toString();
const lines = splitByLine(output);

const scavengeRegex = /\bScavenge\b/;
const expectedOutput = [
scavengeRegex,
scavengeRegex,
scavengeRegex,
scavengeRegex,
/\bMark-sweep\b/,
];
lines.forEach((line, index) => {
const isMatched = line.match(expectedOutput[index]);
tony-go marked this conversation as resolved.
Show resolved Hide resolved
assert.ok(isMatched);
});
}

/**
* HELPERS
*/

function splitByLine(str) {
return str.split(/\n/);
}