Skip to content

Commit 5cf24d0

Browse files
Matheus Marchinimmarchini
authored andcommitted
test: increase Linux test coverate
Some tests (`test/addon/jsapi-test.js` and `test/plugin/scan-test.js`) were not running on Linux because LLDB is not able to save core dumps on that platform. These changes use a simpler approach to save core dumps on Linux so these tests can also be run there. Ref: #209 PR-URL: #222 Refs: #209 Reviewed-By: Joyee Cheung <[email protected]>
1 parent d5e0ada commit 5cf24d0

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

test/addon/jsapi-test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ tape('llnode API', (t) => {
1515
if (process.env.LLNODE_CORE && process.env.LLNODE_NODE_EXE) {
1616
test(process.env.LLNODE_NODE_EXE, process.env.LLNODE_CORE, t);
1717
t.end();
18-
} else if (process.platform === 'linux') {
19-
t.skip('No `process save-core` on linux');
20-
t.end();
2118
} else {
2219
common.saveCore({
2320
scenario: 'inspect-scenario.js'

test/common.js

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ SessionOutput.prototype.wait = function wait(regexp, callback, allLines) {
9898

9999
function onLine(line) {
100100
lines.push(line);
101-
debug(`[LINE][${self.session.lldb.pid}]`, line);
101+
if (self.session)
102+
debug(`[LINE][${self.session.lldb.pid}]`, line);
102103

103104
if (!regexp.test(line))
104105
return;
@@ -205,10 +206,7 @@ Session.create = function create(scenario) {
205206
return new Session({ scenario: scenario });
206207
};
207208

208-
exports.saveCore = function saveCore(options, cb) {
209-
const scenario = options.scenario;
210-
const core = options.core || exports.core;
211-
209+
function saveCoreLLDB(scenario, core, cb) {
212210
// Create a core and test
213211
const sess = Session.create(scenario);
214212
sess.timeoutAfter(exports.saveCoreTimeout);
@@ -234,6 +232,47 @@ exports.saveCore = function saveCore(options, cb) {
234232
});
235233
}
236234

235+
function spawnWithTimeout(cmd, cb) {
236+
const proc = spawn(cmd, {
237+
shell: true,
238+
stdio: ['pipe', 'pipe', 'pipe'] });
239+
const stdout = new SessionOutput(null, proc.stdout, exports.saveCoreTimeout);
240+
const stderr = new SessionOutput(null, proc.stderr, exports.saveCoreTimeout);
241+
stdout.on('line', (line) => { debug('[stdout]', line); });
242+
stderr.on('line', (line) => { debug('[stderr]', line); });
243+
244+
const timeout = setTimeout(() => {
245+
console.error(`timeout while saving core dump for scenario "${scenario}"`);
246+
proc.kill();
247+
}, exports.saveCoreTimeout);
248+
249+
proc.on('exit', (status) => {
250+
clearTimeout(timeout);
251+
cb(null);
252+
});
253+
}
254+
255+
function saveCoreLinux(executable, scenario, core, cb) {
256+
const cmd = `ulimit -c unlimited && ${executable} ` +
257+
`--abort_on_uncaught_exception --expose_externalize_string ` +
258+
`${path.join(exports.fixturesDir, scenario)}; `;
259+
spawnWithTimeout(cmd, () => {
260+
// FIXME (mmarchini): Should also handle different core system settings.
261+
spawnWithTimeout(`mv ./core ${core}`, cb);
262+
});
263+
}
264+
265+
exports.saveCore = function saveCore(options, cb) {
266+
const scenario = options.scenario;
267+
const core = options.core || exports.core;
268+
269+
if (process.platform === 'linux') {
270+
saveCoreLinux(process.execPath, scenario, core, cb);
271+
} else {
272+
saveCoreLLDB(scenario, core, cb);
273+
}
274+
}
275+
237276
// Load the core dump with the executable
238277
Session.loadCore = function loadCore(executable, core, cb) {
239278
const ranges = process.env.LLNODE_NO_RANGES ? undefined : core + '.ranges';

test/plugin/scan-test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ tape('v8 findrefs and friends', (t) => {
1010
// Use prepared core and executable to test
1111
if (process.env.LLNODE_CORE && process.env.LLNODE_NODE_EXE) {
1212
test(process.env.LLNODE_NODE_EXE, process.env.LLNODE_CORE, t);
13-
} else if (process.platform === 'linux') {
14-
t.skip('No `process save-core` on linux');
15-
t.end();
1613
} else {
1714
common.saveCore({
1815
scenario: 'inspect-scenario.js'

0 commit comments

Comments
 (0)