Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,166 @@
'use strict';
// --- About this test suite
//
// JIT support for perf(1) was added in 2009 (see https://lkml.org/lkml/2009/6/8/499).
// It works by looking for a perf map file in /tmp/perf-<pid>.map, where <pid> is the
// PID of the target process.
//
// The structure of this file is stable. Perf expects each line to specify a symbol
// in the form:
//
// <start> <length> <name>
//
// where <start> is the hex representation of the instruction pointer for the beginning
// of the function, <length> is the byte length of the function, and <name> is the
// readable JIT name used for reporting.
//
// This file asserts that a node script run with the appropriate flags will produce
// a compliant perf map.
//
// NOTE: This test runs only on linux, as that is the only platform supported by perf, and
// accordingly the only platform where `perf-basic-prof*` v8 flags are available.
//
// MAINTAINERS' NOTE: As of early 2024, the most common failure mode for this test suite
// is for v8 options to change from version to version. If this suite fails, look there first.
// We use options to forcibly require certain test cases to JIT code, and the nodeFlags to do
// so can change.
const common = require('../common');
if (!common.isLinux) {
common.skip('--perf-basic-prof* is statically defined as linux-only');
}
const assert = require('assert');
const { spawnSync } = require('child_process');
const { readFileSync } = require('fs');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const testCases = [
{
title: '--perf-basic-prof interpreted',
nodeFlags: ['--perf-basic-prof', '--no-turbo-inlining', '--no-opt'],
matches: [
'JS:~functionOne .+/linux-perf-logger.js',
'JS:~functionTwo .+/linux-perf-logger.js',
String.raw`RegExp\.> src: 'test-regex' flags: 'gi'`,
],
noMatches: [
String.raw`JS:\*'functionOne`,
String.raw`JS:\*'functionTwo`,
],
},
{
title: '--perf-basic-prof compiled',
nodeFlags: ['--perf-basic-prof', '--no-turbo-inlining', '--always-turbofan',
'--minimum-invocations-before-optimization=0'],
matches: [
String.raw`RegExp\.> src: 'test-regex' flags: 'gi'`,
'JS:~functionOne .+/linux-perf-logger.js',
'JS:~functionTwo .+/linux-perf-logger.js',
String.raw`JS:\*'functionOne .+/linux-perf-logger.js`,
String.raw`JS:\*'functionTwo .+/linux-perf-logger.js`,
],
noMatches: [],
},
{
title: '--perf-basic-prof-only-functions interpreted',
nodeFlags: ['--perf-basic-prof-only-functions', '--no-turbo-inlining', '--no-opt'],
matches: [
'JS:~functionOne .+/linux-perf-logger.js',
'JS:~functionTwo .+/linux-perf-logger.js',
],
noMatches: [
String.raw`JS:\*'functionOne`,
String.raw`JS:\*'functionTwo`,
'test-regex',
],
},
{
title: '--perf-basic-prof-only-functions compiled',
nodeFlags: ['--perf-basic-prof-only-functions', '--no-turbo-inlining', '--always-turbofan',
'--minimum-invocations-before-optimization=0'],
matches: [
'JS:~functionOne .+/linux-perf-logger.js',
'JS:~functionTwo .+/linux-perf-logger.js',
String.raw`JS:\*'functionOne .+/linux-perf-logger.js`,
String.raw`JS:\*'functionTwo .+/linux-perf-logger.js`,
],
noMatches: [
'test-regex',
],
},
];
function runTest(test) {
const report = {
title: test.title,
perfMap: '[uninitialized]',
errors: [],
};
const args = test.nodeFlags.concat(fixtures.path('linux-perf-logger.js'));
const run = spawnSync(process.execPath, args, { cwd: tmpdir.path, encoding: 'utf8' });
if (run.error) {
report.errors.push(run.error.stack);
return report;
}
if (run.status !== 0) {
report.errors.push(`running script:\n${run.stderr}`);
return report;
}
try {
report.perfMap = readFileSync(`/tmp/perf-${run.pid}.map`, 'utf8');
} catch (err) {
report.errors.push(`reading perf map: ${err.stack}`);
return report;
}
const hexRegex = '[a-fA-F0-9]+';
for (const testRegex of test.matches) {
const lineRegex = new RegExp(`${hexRegex} ${hexRegex}.* ${testRegex}`);
if (!lineRegex.test(report.perfMap)) {
report.errors.push(`Expected to match ${lineRegex}`);
}
}
for (const regex of test.noMatches) {
const noMatch = new RegExp(regex);
if (noMatch.test(report.perfMap)) {
report.errors.push(`Expected not to match ${noMatch}`);
}
}
return report;
}
function serializeError(report, index) {
return `[ERROR ${index + 1}] ${report.title}
Errors:
${report.errors.map((err, i) => `${i + 1}. ${err}`).join('\n')}
Perf map content:
${report.perfMap}
</end perf map content>
`;
}
function runSuite() {
const failures = [];
for (const tc of testCases) {
const report = runTest(tc);
if (report.errors.length > 0) {
failures.push(report);
}
}
const errorsToReport = failures.map(serializeError).join('\n--------\n');
assert.strictEqual(failures.length, 0, `${failures.length} tests failed\n\n${errorsToReport}`);
}
runSuite();

View File

@ -0,0 +1,115 @@
'use strict';
// This test verifies that JavaScript functions are being correctly sampled by
// Linux perf. The test runs a JavaScript script, sampling the execution with
// Linux perf. It then uses `perf script` to generate a human-readable output,
// and uses regular expressions to find samples of the functions defined in
// `fixtures/linux-perf.js`.
// NOTE (mmarchini): this test is meant to run only on Linux machines with Linux
// perf installed. It will skip if those criteria are not met.
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const { spawnSync } = require('child_process');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
if (process.config.variables.node_shared)
common.skip("can't test Linux perf with shared libraries yet");
if (!common.isLinux)
common.skip('only testing Linux for now');
const frequency = 99;
const repeat = 5;
// Expected number of samples we'll capture per repeat
const sampleCount = 10;
const sleepTime = sampleCount * (1.0 / frequency);
const perfFlags = [
'record',
`-F${frequency}`,
'-g',
];
const nodeCommonFlags = [
'--perf-basic-prof',
'--interpreted-frames-native-stack',
'--no-turbo-inlining', // Otherwise simple functions might get inlined.
];
const perfInterpretedFramesArgs = [
...perfFlags,
'--',
process.execPath,
...nodeCommonFlags,
'--no-opt',
fixtures.path('linux-perf.js'),
`${sleepTime}`,
`${repeat}`,
];
const perfCompiledFramesArgs = [
...perfFlags,
'--',
process.execPath,
...nodeCommonFlags,
'--always-turbofan',
fixtures.path('linux-perf.js'),
`${sleepTime}`,
`${repeat}`,
];
const perfArgsList = [
perfInterpretedFramesArgs, perfCompiledFramesArgs,
];
const perfScriptArgs = [
'script',
];
const options = {
cwd: tmpdir.path,
encoding: 'utf-8',
};
let output = '';
for (const perfArgs of perfArgsList) {
const perf = spawnSync('perf', perfArgs, options);
assert.ifError(perf.error);
if (perf.status !== 0)
throw new Error(`Failed to execute 'perf': ${perf.stderr}`);
const perfScript = spawnSync('perf', perfScriptArgs, options);
assert.ifError(perfScript.error);
if (perfScript.status !== 0)
throw new Error(`Failed to execute perf script: ${perfScript.stderr}`);
output += perfScript.stdout;
}
const interpretedFunctionOneRe = /~functionOne/;
const compiledFunctionOneRe = /\*functionOne/;
const interpretedFunctionTwoRe = /~functionTwo/;
const compiledFunctionTwoRe = /\*functionTwo/;
function makeAssertMessage(message) {
return message + '\nPerf output:\n\n' + output;
}
assert.ok(output.match(interpretedFunctionOneRe),
makeAssertMessage("Couldn't find interpreted functionOne()"));
assert.ok(output.match(compiledFunctionOneRe),
makeAssertMessage("Couldn't find compiled functionOne()"));
assert.ok(output.match(interpretedFunctionTwoRe),
makeAssertMessage("Couldn't find interpreted functionTwo()"));
assert.ok(output.match(compiledFunctionTwoRe),
makeAssertMessage("Couldn't find compiled functionTwo"));

View File

@ -0,0 +1,36 @@
'use strict';
// This test verifies that `--trace-gc` flag is well integrated.
// We'll check here, that the console outputs gc events properly.
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().trim();
const lines = splitByLine(output);
const scavengeRegex = /\bScavenge\b/;
const eofRegex = /\bMark-Compact\b/;
lines.forEach((line, index) => {
const expected = index !== lines.length - 1 ? scavengeRegex : eofRegex;
assert.match(line, expected);
});
}
/**
* HELPERS
*/
function splitByLine(str) {
return str.split(/\n/);
}

View File

@ -0,0 +1,6 @@
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import testpy
def GetConfiguration(context, root):
return testpy.ParallelTestConfiguration(context, root, 'v8-updates')

View File

@ -0,0 +1,23 @@
prefix v8-updates
# To mark a test as flaky, list the test name in the appropriate section
# below, without ".js", followed by ": PASS,FLAKY". Example:
# sample-test : PASS,FLAKY
[true] # This section applies to all platforms
# https://github.com/nodejs/node/issues/50079
test-linux-perf: SKIP
[$system==win32]
[$system==linux]
[$system==macos]
[$arch==arm || $arch==arm64]
[$system==solaris] # Also applies to SmartOS
[$system==freebsd]
[$system==aix]