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: fix tick-processor tests and run them in CI #23100

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
118 changes: 118 additions & 0 deletions test/common/tick-processor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
'use strict';

const {
isWindows,
isSunOS,
isAIX,
isLinuxPPCBE,
isFreeBSD,
skip
} = require('../common');

const fs = require('fs');
const cp = require('child_process');
const path = require('path');

const tmpdir = require('./tmpdir');
tmpdir.refresh();

const LOG_FILE = path.join(tmpdir.path, 'tick-processor.log');
const START_PROF_PROCESS_TIMEOUT = 400;

let running = 0;
let ran = 0;

// The tick processor is not supported on all platforms.
function isCPPSymbolsNotMapped() {
if (isWindows || isSunOS || isAIX || isLinuxPPCBE || isFreeBSD) {
skip('C++ symbols are not mapped for this OS.');
return true;
}
return false;
}

function runTest(test) {
if (isCPPSymbolsNotMapped()) {
return;
}

ran++;
running = 0;
const proc = cp.spawn(process.execPath, [
'--no_logfile_per_isolate',
'--logfile=-',
'--prof',
'-pe', test.code
], {
stdio: [ 'ignore', 'pipe', 'inherit' ]
});

let ticks = '';
proc.stdout.on('data', (chunk) => ticks += chunk);

// Check if the pattern is already there or not.
setTimeout(() => {
if (running === 0) {
match(test, proc, () => ticks);
}
}, START_PROF_PROCESS_TIMEOUT);

proc.on('exit', () => {
running++;
if (running === 1) {
match(test, proc, () => ticks);
}
});
}

function match(test, parent, ticks) {
running++;

const { pattern, profProcessFlags: flags = [] } = test;
// Store current ticks log
fs.writeFileSync(LOG_FILE, ticks());

const proc = cp.spawn(process.execPath, [
'--prof-process',
'--call-graph-size=10',
...flags,
LOG_FILE
], {
stdio: [ 'ignore', 'pipe', 'inherit' ]
});

let out = '';

proc.stdout.on('data', (chunk) => out += chunk);
proc.stdout.once('end', () => {
proc.once('exit', () => {
fs.unlinkSync(LOG_FILE);

// Retry after timeout
if (!pattern.test(out)) {
running--;
// If the profiling is done without match, try up to ten times again
// and then fail.
if (running === 1) {
if (ran < 10) {
return runTest(test);
}
console.error(out);
throw new Error(`${pattern} Failed`);
}
return;
}

parent.stdout.removeAllListeners();
parent.kill();
});

proc.stdout.removeAllListeners();
proc.kill();
});
}

module.exports = {
runTest,
isCPPSymbolsNotMapped
};
20 changes: 20 additions & 0 deletions test/sequential/test-tick-processor-builtin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
require('../common');

const base = require('../common/tick-processor');

base.runTest({
// If the C++ symbols are not detected by the OS, no JS is going to be
// executed.
pattern: /Builtin: ObjectKeys| \d [0-6]\.\d% [0-6]\.\d% JavaScript/,
code: `let add = 0;
const obj = { a: 5 };
function f() {
for (var i = 0; i < 4e6; i++) {
obj.a = i;
add += Object.keys(obj).length;
}
return add;
};
f();`
});
16 changes: 16 additions & 0 deletions test/sequential/test-tick-processor-cpp-core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
require('../common');

const base = require('../common/tick-processor');

base.runTest({
// If the C++ symbols are not mapped to the OS they can end up as `UNKNOWN` or
// no JS is executed at all.
pattern: /MakeContext|\d\d\.\d% UNKNOWN|0 0\.0% 0\.0% JavaScript|[7-9]\d\.\d% [7-9]\d\.\d% write/,
code: `function f() {
for (var i = 0; i < 5e2; i++) {
require('vm').createContext({});
}
};
f();`
});
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
'use strict';
const common = require('../common');
const { isCPPSymbolsNotMapped } = require('./util');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const { skip } = require('../common');

if (!common.enoughTestCpu)
common.skip('test is CPU-intensive');
const { isCPPSymbolsNotMapped } = require('../common/tick-processor');

if (isCPPSymbolsNotMapped) {
common.skip('C++ symbols are not mapped for this OS.');
skip('C++ symbols are not mapped for this OS.');
}

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

// This test will produce a broken profile log.
// ensure prof-polyfill not stuck in infinite loop
// and success process


const assert = require('assert');
const { spawn, spawnSync } = require('child_process');
const path = require('path');
const { writeFileSync } = require('fs');

const LOG_FILE = path.join(tmpdir.path, 'tick-processor.log');
const RETRY_TIMEOUT = 150;
const RETRY_TIMEOUT = 250;
const BROKEN_PART = 'tick,';
const WARN_REG_EXP = /\(node:\d+\) \[BROKEN_PROFILE_FILE] Warning: Profile file .* is broken/;
const WARN_DETAIL_REG_EXP = /".*tick," at the file end is broken/;

const code = `function f() {
this.ts = Date.now();
setImmediate(function() { new f(); });
};
f();`;
const code = `
let add = 0;
function f() {
for (var i = 0; i < 1e3; i++) {
add += Date.now();
}
return add;
};
f();`;

const proc = spawn(process.execPath, [
'--no_logfile_per_isolate',
Expand All @@ -45,7 +47,6 @@ const proc = spawn(process.execPath, [
let ticks = '';
proc.stdout.on('data', (chunk) => ticks += chunk);


function runPolyfill(content) {
proc.kill();
content += BROKEN_PART;
Expand Down
15 changes: 15 additions & 0 deletions test/sequential/test-tick-processor-preprocess-flag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
require('../common');

const base = require('../common/tick-processor');

base.runTest({
pattern: /^{/,
code: `function f() {
for (var i = 0; i < 5e2; i++) {
require('vm').createContext({});
}
};
f();`,
profProcessFlags: ['--preprocess']
});
21 changes: 0 additions & 21 deletions test/tick-processor/test-tick-processor-builtin.js

This file was deleted.

21 changes: 0 additions & 21 deletions test/tick-processor/test-tick-processor-cpp-core.js

This file was deleted.

22 changes: 0 additions & 22 deletions test/tick-processor/test-tick-processor-preprocess-flag.js

This file was deleted.

28 changes: 0 additions & 28 deletions test/tick-processor/test-tick-processor-unknown.js

This file was deleted.

6 changes: 0 additions & 6 deletions test/tick-processor/testcfg.py

This file was deleted.

Loading