2015-10-02 06:38:16 +02:00
|
|
|
/* eslint-disable required-modules */
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-10-17 05:40:39 +02:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
const assert = require('assert');
|
|
|
|
const os = require('os');
|
|
|
|
const child_process = require('child_process');
|
2015-11-25 22:38:01 +01:00
|
|
|
const stream = require('stream');
|
2016-12-13 05:51:01 +01:00
|
|
|
const buffer = require('buffer');
|
2015-11-25 22:38:01 +01:00
|
|
|
const util = require('util');
|
2015-07-24 02:09:21 +02:00
|
|
|
const Timer = process.binding('timer_wrap').Timer;
|
2016-12-28 00:18:41 +01:00
|
|
|
const execSync = require('child_process').execSync;
|
2015-10-10 00:26:55 +02:00
|
|
|
|
2016-07-16 03:17:36 +02:00
|
|
|
const testRoot = process.env.NODE_TEST_DIR ?
|
2017-01-10 14:43:08 +01:00
|
|
|
fs.realpathSync(process.env.NODE_TEST_DIR) : __dirname;
|
2009-10-31 19:02:30 +01:00
|
|
|
|
2016-11-22 06:25:37 +01:00
|
|
|
exports.fixturesDir = path.join(__dirname, 'fixtures');
|
2014-12-17 14:34:21 +01:00
|
|
|
exports.tmpDirName = 'tmp';
|
2016-06-29 23:20:06 +02:00
|
|
|
// PORT should match the definition in test/testpy/__init__.py.
|
2013-02-26 07:19:16 +01:00
|
|
|
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
|
2015-05-25 17:01:42 +02:00
|
|
|
exports.isWindows = process.platform === 'win32';
|
2016-05-10 16:16:43 +02:00
|
|
|
exports.isWOW64 = exports.isWindows &&
|
2016-07-16 03:17:36 +02:00
|
|
|
(process.env.PROCESSOR_ARCHITEW6432 !== undefined);
|
2015-08-12 17:53:33 +02:00
|
|
|
exports.isAix = process.platform === 'aix';
|
2015-10-22 22:15:33 +02:00
|
|
|
exports.isLinuxPPCBE = (process.platform === 'linux') &&
|
|
|
|
(process.arch === 'ppc64') &&
|
|
|
|
(os.endianness() === 'BE');
|
|
|
|
exports.isSunOS = process.platform === 'sunos';
|
|
|
|
exports.isFreeBSD = process.platform === 'freebsd';
|
2016-05-29 17:53:40 +02:00
|
|
|
exports.isLinux = process.platform === 'linux';
|
|
|
|
exports.isOSX = process.platform === 'darwin';
|
2009-09-20 18:19:33 +02:00
|
|
|
|
2016-07-17 18:33:35 +02:00
|
|
|
exports.enoughTestMem = os.totalmem() > 0x40000000; /* 1 Gb */
|
2016-12-13 05:51:01 +01:00
|
|
|
exports.bufferMaxSizeMsg = new RegExp('^RangeError: "size" argument' +
|
|
|
|
' must not be larger than ' +
|
|
|
|
buffer.kMaxLength + '$');
|
2016-09-19 03:24:44 +02:00
|
|
|
const cpus = os.cpus();
|
2016-11-15 12:14:16 +01:00
|
|
|
exports.enoughTestCpu = Array.isArray(cpus) &&
|
|
|
|
(cpus.length > 1 || cpus[0].speed > 999);
|
2016-09-19 03:24:44 +02:00
|
|
|
|
2016-07-12 18:17:28 +02:00
|
|
|
exports.rootDir = exports.isWindows ? 'c:\\' : '/';
|
2016-09-28 20:14:23 +02:00
|
|
|
exports.buildType = process.config.target_defaults.default_configuration;
|
2015-11-06 18:51:48 +01:00
|
|
|
|
2015-06-03 05:44:03 +02:00
|
|
|
function rimrafSync(p) {
|
2016-12-08 06:47:15 +01:00
|
|
|
let st;
|
2015-06-03 05:44:03 +02:00
|
|
|
try {
|
2016-12-08 06:47:15 +01:00
|
|
|
st = fs.lstatSync(p);
|
2015-06-03 05:44:03 +02:00
|
|
|
} catch (e) {
|
|
|
|
if (e.code === 'ENOENT')
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (st && st.isDirectory())
|
|
|
|
rmdirSync(p, null);
|
|
|
|
else
|
|
|
|
fs.unlinkSync(p);
|
|
|
|
} catch (e) {
|
|
|
|
if (e.code === 'ENOENT')
|
|
|
|
return;
|
|
|
|
if (e.code === 'EPERM')
|
2015-10-01 21:15:03 +02:00
|
|
|
return rmdirSync(p, e);
|
2015-06-03 05:44:03 +02:00
|
|
|
if (e.code !== 'EISDIR')
|
|
|
|
throw e;
|
|
|
|
rmdirSync(p, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function rmdirSync(p, originalEr) {
|
|
|
|
try {
|
|
|
|
fs.rmdirSync(p);
|
|
|
|
} catch (e) {
|
|
|
|
if (e.code === 'ENOTDIR')
|
|
|
|
throw originalEr;
|
|
|
|
if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') {
|
2016-05-29 17:53:40 +02:00
|
|
|
const enc = exports.isLinux ? 'buffer' : 'utf8';
|
fs: Buffer and encoding enhancements to fs API
This makes several changes:
1. Allow path/filename to be passed in as a Buffer on fs methods
2. Add `options.encoding` to fs.readdir, fs.readdirSync, fs.readlink,
fs.readlinkSync and fs.watch.
3. Documentation updates
For 1... it's now possible to do:
```js
fs.open(Buffer('/fs/foo/bar'), 'w+', (err, fd) => { });
```
For 2...
```js
fs.readdir('/fs/foo/bar', {encoding:'hex'}, (err,list) => { });
fs.readdir('/fs/foo/bar', {encoding:'buffer'}, (err, list) => { });
```
encoding can also be passed as a string
```js
fs.readdir('/fs/foo/bar', 'hex', (err,list) => { });
```
The default encoding is set to UTF8 so this addresses the
discrepency that existed previously between fs.readdir and
fs.watch handling filenames differently.
Fixes: https://github.com/nodejs/node/issues/2088
Refs: https://github.com/nodejs/node/issues/3519
PR-URL: https://github.com/nodejs/node/pull/5616
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2016-03-09 05:58:45 +01:00
|
|
|
fs.readdirSync(p, enc).forEach((f) => {
|
|
|
|
if (f instanceof Buffer) {
|
|
|
|
const buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]);
|
|
|
|
rimrafSync(buf);
|
|
|
|
} else {
|
|
|
|
rimrafSync(path.join(p, f));
|
|
|
|
}
|
2015-06-03 05:44:03 +02:00
|
|
|
});
|
|
|
|
fs.rmdirSync(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 20:40:55 +02:00
|
|
|
exports.refreshTmpDir = function() {
|
2015-06-14 16:02:29 +02:00
|
|
|
rimrafSync(exports.tmpDir);
|
|
|
|
fs.mkdirSync(exports.tmpDir);
|
2015-06-09 20:40:55 +02:00
|
|
|
};
|
2015-06-03 05:44:03 +02:00
|
|
|
|
2014-12-17 14:34:21 +01:00
|
|
|
if (process.env.TEST_THREAD_ID) {
|
2015-10-12 06:11:57 +02:00
|
|
|
exports.PORT += process.env.TEST_THREAD_ID * 100;
|
2014-12-17 14:34:21 +01:00
|
|
|
exports.tmpDirName += '.' + process.env.TEST_THREAD_ID;
|
|
|
|
}
|
2015-10-12 06:11:57 +02:00
|
|
|
exports.tmpDir = path.join(testRoot, exports.tmpDirName);
|
2014-12-17 14:34:21 +01:00
|
|
|
|
2016-12-08 06:47:15 +01:00
|
|
|
let opensslCli = null;
|
|
|
|
let inFreeBSDJail = null;
|
|
|
|
let localhostIPv4 = null;
|
2015-02-09 05:56:38 +01:00
|
|
|
|
2016-02-28 07:18:22 +01:00
|
|
|
exports.localIPv6Hosts = ['localhost'];
|
2016-05-29 17:53:40 +02:00
|
|
|
if (exports.isLinux) {
|
2016-02-28 07:18:22 +01:00
|
|
|
exports.localIPv6Hosts = [
|
|
|
|
// Debian/Ubuntu
|
|
|
|
'ip6-localhost',
|
|
|
|
'ip6-loopback',
|
2015-12-17 07:16:46 +01:00
|
|
|
|
2016-02-28 07:18:22 +01:00
|
|
|
// SUSE
|
|
|
|
'ipv6-localhost',
|
|
|
|
'ipv6-loopback',
|
2015-12-17 07:16:46 +01:00
|
|
|
|
2016-02-28 07:18:22 +01:00
|
|
|
// Typically universal
|
|
|
|
'localhost',
|
|
|
|
];
|
|
|
|
}
|
2015-12-17 07:16:46 +01:00
|
|
|
|
2015-03-17 02:06:48 +01:00
|
|
|
Object.defineProperty(exports, 'inFreeBSDJail', {
|
|
|
|
get: function() {
|
2015-03-18 23:27:26 +01:00
|
|
|
if (inFreeBSDJail !== null) return inFreeBSDJail;
|
|
|
|
|
2016-05-29 17:53:40 +02:00
|
|
|
if (exports.isFreeBSD &&
|
2015-03-17 02:06:48 +01:00
|
|
|
child_process.execSync('sysctl -n security.jail.jailed').toString() ===
|
|
|
|
'1\n') {
|
2015-03-18 23:27:26 +01:00
|
|
|
inFreeBSDJail = true;
|
2015-03-17 02:06:48 +01:00
|
|
|
} else {
|
2015-03-18 23:27:26 +01:00
|
|
|
inFreeBSDJail = false;
|
2015-03-17 02:06:48 +01:00
|
|
|
}
|
2015-03-18 23:27:26 +01:00
|
|
|
return inFreeBSDJail;
|
2015-03-17 02:06:48 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-03-18 23:27:26 +01:00
|
|
|
Object.defineProperty(exports, 'localhostIPv4', {
|
2015-03-17 02:06:48 +01:00
|
|
|
get: function() {
|
2015-03-18 23:27:26 +01:00
|
|
|
if (localhostIPv4 !== null) return localhostIPv4;
|
|
|
|
|
2015-03-17 02:06:48 +01:00
|
|
|
if (exports.inFreeBSDJail) {
|
|
|
|
// Jailed network interfaces are a bit special - since we need to jump
|
|
|
|
// through loops, as well as this being an exception case, assume the
|
|
|
|
// user will provide this instead.
|
2015-03-18 23:27:26 +01:00
|
|
|
if (process.env.LOCALHOST) {
|
|
|
|
localhostIPv4 = process.env.LOCALHOST;
|
|
|
|
} else {
|
|
|
|
console.error('Looks like we\'re in a FreeBSD Jail. ' +
|
|
|
|
'Please provide your default interface address ' +
|
|
|
|
'as LOCALHOST or expect some tests to fail.');
|
|
|
|
}
|
2015-03-17 02:06:48 +01:00
|
|
|
}
|
2015-03-18 23:27:26 +01:00
|
|
|
|
|
|
|
if (localhostIPv4 === null) localhostIPv4 = '127.0.0.1';
|
|
|
|
|
|
|
|
return localhostIPv4;
|
2015-03-17 02:06:48 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-09 05:56:38 +01:00
|
|
|
// opensslCli defined lazily to reduce overhead of spawnSync
|
|
|
|
Object.defineProperty(exports, 'opensslCli', {get: function() {
|
|
|
|
if (opensslCli !== null) return opensslCli;
|
|
|
|
|
|
|
|
if (process.config.variables.node_shared_openssl) {
|
|
|
|
// use external command
|
|
|
|
opensslCli = 'openssl';
|
|
|
|
} else {
|
2015-08-13 18:14:34 +02:00
|
|
|
// use command built from sources included in Node.js repository
|
2015-02-09 05:56:38 +01:00
|
|
|
opensslCli = path.join(path.dirname(process.execPath), 'openssl-cli');
|
|
|
|
}
|
|
|
|
|
2015-07-29 13:48:04 +02:00
|
|
|
if (exports.isWindows) opensslCli += '.exe';
|
2015-02-09 05:56:38 +01:00
|
|
|
|
2016-12-08 06:47:15 +01:00
|
|
|
const opensslCmd = child_process.spawnSync(opensslCli, ['version']);
|
|
|
|
if (opensslCmd.status !== 0 || opensslCmd.error !== undefined) {
|
2015-02-09 05:56:38 +01:00
|
|
|
// openssl command cannot be executed
|
|
|
|
opensslCli = false;
|
|
|
|
}
|
|
|
|
return opensslCli;
|
2016-05-12 08:03:24 +02:00
|
|
|
}, enumerable: true});
|
2015-02-09 05:56:38 +01:00
|
|
|
|
2015-11-12 23:28:04 +01:00
|
|
|
Object.defineProperty(exports, 'hasCrypto', {
|
|
|
|
get: function() {
|
|
|
|
return process.versions.openssl ? true : false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(exports, 'hasFipsCrypto', {
|
|
|
|
get: function() {
|
2016-01-23 00:10:09 +01:00
|
|
|
return exports.hasCrypto && require('crypto').fips;
|
2015-11-12 23:28:04 +01:00
|
|
|
}
|
|
|
|
});
|
2015-02-09 05:56:38 +01:00
|
|
|
|
2015-07-29 13:48:04 +02:00
|
|
|
if (exports.isWindows) {
|
2015-08-27 22:47:15 +02:00
|
|
|
exports.PIPE = '\\\\.\\pipe\\libuv-test';
|
2015-10-12 06:11:57 +02:00
|
|
|
if (process.env.TEST_THREAD_ID) {
|
|
|
|
exports.PIPE += '.' + process.env.TEST_THREAD_ID;
|
|
|
|
}
|
2011-07-21 21:21:06 +02:00
|
|
|
} else {
|
|
|
|
exports.PIPE = exports.tmpDir + '/test.sock';
|
|
|
|
}
|
2014-10-29 17:21:12 +01:00
|
|
|
|
2016-12-08 06:47:15 +01:00
|
|
|
const ifaces = os.networkInterfaces();
|
2014-08-02 10:42:42 +02:00
|
|
|
exports.hasIPv6 = Object.keys(ifaces).some(function(name) {
|
|
|
|
return /lo/.test(name) && ifaces[name].some(function(info) {
|
|
|
|
return info.family === 'IPv6';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-12-19 05:19:18 +01:00
|
|
|
/*
|
|
|
|
* Check that when running a test with
|
|
|
|
* `$node --abort-on-uncaught-exception $file child`
|
|
|
|
* the process aborts.
|
|
|
|
*/
|
|
|
|
exports.childShouldThrowAndAbort = function() {
|
2017-01-08 14:19:00 +01:00
|
|
|
let testCmd = '';
|
2016-12-19 05:19:18 +01:00
|
|
|
if (!exports.isWindows) {
|
|
|
|
// Do not create core files, as it can take a lot of disk space on
|
|
|
|
// continuous testing and developers' machines
|
|
|
|
testCmd += 'ulimit -c 0 && ';
|
|
|
|
}
|
|
|
|
testCmd += `${process.argv[0]} --abort-on-uncaught-exception `;
|
|
|
|
testCmd += `${process.argv[1]} child`;
|
|
|
|
const child = child_process.exec(testCmd);
|
|
|
|
child.on('exit', function onExit(exitCode, signal) {
|
|
|
|
const errMsg = 'Test should have aborted ' +
|
|
|
|
`but instead exited with exit code ${exitCode}` +
|
|
|
|
` and signal ${signal}`;
|
|
|
|
assert(exports.nodeProcessAborted(exitCode, signal), errMsg);
|
|
|
|
});
|
|
|
|
};
|
2010-12-04 22:40:39 +01:00
|
|
|
|
2011-08-10 02:43:57 +02:00
|
|
|
exports.ddCommand = function(filename, kilobytes) {
|
2015-07-29 13:48:04 +02:00
|
|
|
if (exports.isWindows) {
|
2016-12-08 06:47:15 +01:00
|
|
|
const p = path.resolve(exports.fixturesDir, 'create-file.js');
|
2012-02-19 00:01:35 +01:00
|
|
|
return '"' + process.argv[0] + '" "' + p + '" "' +
|
|
|
|
filename + '" ' + (kilobytes * 1024);
|
2011-08-10 02:43:57 +02:00
|
|
|
} else {
|
|
|
|
return 'dd if=/dev/zero of="' + filename + '" bs=1024 count=' + kilobytes;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-01-11 02:15:53 +01:00
|
|
|
exports.spawnCat = function(options) {
|
2016-12-08 06:47:15 +01:00
|
|
|
const spawn = require('child_process').spawn;
|
2013-01-11 02:15:53 +01:00
|
|
|
|
2015-07-29 13:48:04 +02:00
|
|
|
if (exports.isWindows) {
|
2013-01-11 02:15:53 +01:00
|
|
|
return spawn('more', [], options);
|
|
|
|
} else {
|
|
|
|
return spawn('cat', [], options);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-23 23:18:55 +01:00
|
|
|
exports.spawnSyncCat = function(options) {
|
2016-12-08 06:47:15 +01:00
|
|
|
const spawnSync = require('child_process').spawnSync;
|
2015-01-23 23:18:55 +01:00
|
|
|
|
2015-07-29 13:48:04 +02:00
|
|
|
if (exports.isWindows) {
|
2015-01-23 23:18:55 +01:00
|
|
|
return spawnSync('more', [], options);
|
|
|
|
} else {
|
|
|
|
return spawnSync('cat', [], options);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-10 20:22:58 +02:00
|
|
|
exports.spawnPwd = function(options) {
|
2016-12-08 06:47:15 +01:00
|
|
|
const spawn = require('child_process').spawn;
|
2011-08-10 20:22:58 +02:00
|
|
|
|
2015-07-29 13:48:04 +02:00
|
|
|
if (exports.isWindows) {
|
2016-08-10 17:01:04 +02:00
|
|
|
return spawn('cmd.exe', ['/d', '/c', 'cd'], options);
|
2011-08-10 20:22:58 +02:00
|
|
|
} else {
|
|
|
|
return spawn('pwd', [], options);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-23 19:21:33 +02:00
|
|
|
|
|
|
|
exports.spawnSyncPwd = function(options) {
|
|
|
|
const spawnSync = require('child_process').spawnSync;
|
|
|
|
|
|
|
|
if (exports.isWindows) {
|
2016-08-10 17:01:04 +02:00
|
|
|
return spawnSync('cmd.exe', ['/d', '/c', 'cd'], options);
|
2016-05-23 19:21:33 +02:00
|
|
|
} else {
|
|
|
|
return spawnSync('pwd', [], options);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-07 20:41:07 +02:00
|
|
|
exports.platformTimeout = function(ms) {
|
2015-12-27 00:04:56 +01:00
|
|
|
if (process.config.target_defaults.default_configuration === 'Debug')
|
|
|
|
ms = 2 * ms;
|
|
|
|
|
2016-04-22 00:20:37 +02:00
|
|
|
if (exports.isAix)
|
|
|
|
return 2 * ms; // default localhost speed is slower on AIX
|
|
|
|
|
2015-04-07 20:41:07 +02:00
|
|
|
if (process.arch !== 'arm')
|
|
|
|
return ms;
|
|
|
|
|
2015-12-10 21:03:59 +01:00
|
|
|
const armv = process.config.variables.arm_version;
|
|
|
|
|
|
|
|
if (armv === '6')
|
2015-04-29 02:55:55 +02:00
|
|
|
return 7 * ms; // ARMv6
|
2015-04-07 20:41:07 +02:00
|
|
|
|
2015-12-10 21:03:59 +01:00
|
|
|
if (armv === '7')
|
|
|
|
return 2 * ms; // ARMv7
|
|
|
|
|
|
|
|
return ms; // ARMv8+
|
2015-04-07 20:41:07 +02:00
|
|
|
};
|
|
|
|
|
2016-12-08 06:47:15 +01:00
|
|
|
let knownGlobals = [
|
2016-11-22 06:25:37 +01:00
|
|
|
Buffer,
|
|
|
|
clearImmediate,
|
|
|
|
clearInterval,
|
|
|
|
clearTimeout,
|
|
|
|
console,
|
|
|
|
constructor, // Enumerable in V8 3.21.
|
|
|
|
global,
|
|
|
|
process,
|
|
|
|
setImmediate,
|
|
|
|
setInterval,
|
|
|
|
setTimeout
|
|
|
|
];
|
2014-01-30 13:02:58 +01:00
|
|
|
|
|
|
|
if (global.gc) {
|
2016-04-21 08:05:44 +02:00
|
|
|
knownGlobals.push(global.gc);
|
2014-01-30 13:02:58 +01:00
|
|
|
}
|
2011-08-10 02:43:57 +02:00
|
|
|
|
2014-01-30 13:02:58 +01:00
|
|
|
if (global.DTRACE_HTTP_SERVER_RESPONSE) {
|
|
|
|
knownGlobals.push(DTRACE_HTTP_SERVER_RESPONSE);
|
|
|
|
knownGlobals.push(DTRACE_HTTP_SERVER_REQUEST);
|
|
|
|
knownGlobals.push(DTRACE_HTTP_CLIENT_RESPONSE);
|
|
|
|
knownGlobals.push(DTRACE_HTTP_CLIENT_REQUEST);
|
|
|
|
knownGlobals.push(DTRACE_NET_STREAM_END);
|
|
|
|
knownGlobals.push(DTRACE_NET_SERVER_CONNECTION);
|
|
|
|
}
|
2010-12-04 22:40:39 +01:00
|
|
|
|
2014-01-30 13:02:58 +01:00
|
|
|
if (global.COUNTER_NET_SERVER_CONNECTION) {
|
|
|
|
knownGlobals.push(COUNTER_NET_SERVER_CONNECTION);
|
|
|
|
knownGlobals.push(COUNTER_NET_SERVER_CONNECTION_CLOSE);
|
|
|
|
knownGlobals.push(COUNTER_HTTP_SERVER_REQUEST);
|
|
|
|
knownGlobals.push(COUNTER_HTTP_SERVER_RESPONSE);
|
|
|
|
knownGlobals.push(COUNTER_HTTP_CLIENT_REQUEST);
|
|
|
|
knownGlobals.push(COUNTER_HTTP_CLIENT_RESPONSE);
|
|
|
|
}
|
2011-03-23 12:29:49 +01:00
|
|
|
|
2015-01-22 13:35:16 +01:00
|
|
|
if (global.LTTNG_HTTP_SERVER_RESPONSE) {
|
|
|
|
knownGlobals.push(LTTNG_HTTP_SERVER_RESPONSE);
|
|
|
|
knownGlobals.push(LTTNG_HTTP_SERVER_REQUEST);
|
|
|
|
knownGlobals.push(LTTNG_HTTP_CLIENT_RESPONSE);
|
|
|
|
knownGlobals.push(LTTNG_HTTP_CLIENT_REQUEST);
|
|
|
|
knownGlobals.push(LTTNG_NET_STREAM_END);
|
|
|
|
knownGlobals.push(LTTNG_NET_SERVER_CONNECTION);
|
|
|
|
}
|
|
|
|
|
2014-01-30 13:02:58 +01:00
|
|
|
if (global.ArrayBuffer) {
|
|
|
|
knownGlobals.push(ArrayBuffer);
|
|
|
|
knownGlobals.push(Int8Array);
|
|
|
|
knownGlobals.push(Uint8Array);
|
|
|
|
knownGlobals.push(Uint8ClampedArray);
|
|
|
|
knownGlobals.push(Int16Array);
|
|
|
|
knownGlobals.push(Uint16Array);
|
|
|
|
knownGlobals.push(Int32Array);
|
|
|
|
knownGlobals.push(Uint32Array);
|
|
|
|
knownGlobals.push(Float32Array);
|
|
|
|
knownGlobals.push(Float64Array);
|
|
|
|
knownGlobals.push(DataView);
|
|
|
|
}
|
2011-01-25 02:50:10 +01:00
|
|
|
|
2014-01-30 13:21:07 +01:00
|
|
|
// Harmony features.
|
|
|
|
if (global.Proxy) {
|
|
|
|
knownGlobals.push(Proxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (global.Symbol) {
|
|
|
|
knownGlobals.push(Symbol);
|
|
|
|
}
|
|
|
|
|
2016-07-21 18:44:01 +02:00
|
|
|
function allowGlobals(...whitelist) {
|
|
|
|
knownGlobals = knownGlobals.concat(whitelist);
|
|
|
|
}
|
|
|
|
exports.allowGlobals = allowGlobals;
|
|
|
|
|
2014-01-30 13:02:58 +01:00
|
|
|
function leakedGlobals() {
|
2016-12-08 06:47:15 +01:00
|
|
|
const leaked = [];
|
2011-08-13 23:51:31 +02:00
|
|
|
|
2016-12-08 06:47:15 +01:00
|
|
|
for (const val in global)
|
2016-11-22 06:25:37 +01:00
|
|
|
if (!knownGlobals.includes(global[val]))
|
2014-01-30 13:02:58 +01:00
|
|
|
leaked.push(val);
|
2010-12-04 22:40:39 +01:00
|
|
|
|
2014-01-30 13:02:58 +01:00
|
|
|
return leaked;
|
2016-01-15 09:53:11 +01:00
|
|
|
}
|
2014-01-30 13:02:58 +01:00
|
|
|
exports.leakedGlobals = leakedGlobals;
|
2010-12-04 22:40:39 +01:00
|
|
|
|
2014-01-30 13:02:58 +01:00
|
|
|
// Turn this off if the test should not check for global leaks.
|
|
|
|
exports.globalCheck = true;
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
if (!exports.globalCheck) return;
|
2016-12-08 06:47:15 +01:00
|
|
|
const leaked = leakedGlobals();
|
2014-01-30 13:02:58 +01:00
|
|
|
if (leaked.length > 0) {
|
|
|
|
console.error('Unknown globals: %s', leaked);
|
2016-11-22 06:25:37 +01:00
|
|
|
fail('Unknown global found');
|
2010-12-04 22:40:39 +01:00
|
|
|
}
|
|
|
|
});
|
2011-02-18 19:05:31 +01:00
|
|
|
|
|
|
|
|
2016-12-08 06:47:15 +01:00
|
|
|
const mustCallChecks = [];
|
2012-07-31 17:47:53 +02:00
|
|
|
|
|
|
|
|
2013-02-11 13:33:50 +01:00
|
|
|
function runCallChecks(exitCode) {
|
|
|
|
if (exitCode !== 0) return;
|
|
|
|
|
2016-12-08 06:47:15 +01:00
|
|
|
const failed = mustCallChecks.filter(function(context) {
|
2012-07-31 17:47:53 +02:00
|
|
|
return context.actual !== context.expected;
|
|
|
|
});
|
|
|
|
|
|
|
|
failed.forEach(function(context) {
|
|
|
|
console.log('Mismatched %s function calls. Expected %d, actual %d.',
|
|
|
|
context.name,
|
|
|
|
context.expected,
|
|
|
|
context.actual);
|
|
|
|
console.log(context.stack.split('\n').slice(2).join('\n'));
|
|
|
|
});
|
|
|
|
|
|
|
|
if (failed.length) process.exit(1);
|
|
|
|
}
|
2011-02-18 19:05:31 +01:00
|
|
|
|
2012-07-31 17:47:53 +02:00
|
|
|
|
|
|
|
exports.mustCall = function(fn, expected) {
|
2016-10-11 21:43:36 +02:00
|
|
|
if (expected === undefined)
|
|
|
|
expected = 1;
|
|
|
|
else if (typeof expected !== 'number')
|
|
|
|
throw new TypeError(`Invalid expected value: ${expected}`);
|
2012-07-31 17:47:53 +02:00
|
|
|
|
2016-12-08 06:47:15 +01:00
|
|
|
const context = {
|
2012-07-31 17:47:53 +02:00
|
|
|
expected: expected,
|
|
|
|
actual: 0,
|
2015-05-19 13:00:06 +02:00
|
|
|
stack: (new Error()).stack,
|
2012-07-31 17:47:53 +02:00
|
|
|
name: fn.name || '<anonymous>'
|
|
|
|
};
|
|
|
|
|
|
|
|
// add the exit listener only once to avoid listener leak warnings
|
|
|
|
if (mustCallChecks.length === 0) process.on('exit', runCallChecks);
|
|
|
|
|
|
|
|
mustCallChecks.push(context);
|
|
|
|
|
|
|
|
return function() {
|
|
|
|
context.actual++;
|
|
|
|
return fn.apply(this, arguments);
|
|
|
|
};
|
|
|
|
};
|
2014-02-18 01:29:23 +01:00
|
|
|
|
2015-01-10 21:36:16 +01:00
|
|
|
exports.hasMultiLocalhost = function hasMultiLocalhost() {
|
2016-12-08 06:47:15 +01:00
|
|
|
const TCP = process.binding('tcp_wrap').TCP;
|
|
|
|
const t = new TCP();
|
|
|
|
const ret = t.bind('127.0.0.2', exports.PORT);
|
2015-01-10 21:36:16 +01:00
|
|
|
t.close();
|
|
|
|
return ret === 0;
|
|
|
|
};
|
|
|
|
|
2014-12-15 19:58:37 +01:00
|
|
|
exports.fileExists = function(pathname) {
|
|
|
|
try {
|
|
|
|
fs.accessSync(pathname);
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2015-10-20 20:40:54 +02:00
|
|
|
|
2016-12-28 00:18:41 +01:00
|
|
|
exports.canCreateSymLink = function() {
|
|
|
|
// On Windows, creating symlinks requires admin privileges.
|
|
|
|
// We'll only try to run symlink test if we have enough privileges.
|
|
|
|
// On other platforms, creating symlinks shouldn't need admin privileges
|
|
|
|
if (exports.isWindows) {
|
|
|
|
// whoami.exe needs to be the one from System32
|
|
|
|
// If unix tools are in the path, they can shadow the one we want,
|
|
|
|
// so use the full path while executing whoami
|
|
|
|
const whoamiPath = path.join(process.env['SystemRoot'],
|
2017-01-01 06:39:57 +01:00
|
|
|
'System32', 'whoami.exe');
|
2016-12-28 00:18:41 +01:00
|
|
|
|
|
|
|
let err = false;
|
|
|
|
let output = '';
|
|
|
|
|
|
|
|
try {
|
|
|
|
output = execSync(whoamiPath + ' /priv', { timout: 1000 });
|
|
|
|
} catch (e) {
|
|
|
|
err = true;
|
|
|
|
} finally {
|
|
|
|
if (err || !output.includes('SeCreateSymbolicLinkPrivilege')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2016-11-22 06:25:37 +01:00
|
|
|
function fail(msg) {
|
2015-10-20 20:40:54 +02:00
|
|
|
assert.fail(null, null, msg);
|
2016-11-22 06:25:37 +01:00
|
|
|
}
|
|
|
|
exports.fail = fail;
|
2015-11-25 22:38:01 +01:00
|
|
|
|
2017-02-03 20:54:19 +01:00
|
|
|
exports.mustNotCall = function(msg) {
|
|
|
|
return function mustNotCall() {
|
|
|
|
fail(msg || 'function should not have been called');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-05-11 21:34:52 +02:00
|
|
|
exports.skip = function(msg) {
|
|
|
|
console.log(`1..0 # Skipped: ${msg}`);
|
|
|
|
};
|
2015-11-25 22:38:01 +01:00
|
|
|
|
|
|
|
// A stream to push an array into a REPL
|
|
|
|
function ArrayStream() {
|
|
|
|
this.run = function(data) {
|
2016-01-28 16:21:57 +01:00
|
|
|
data.forEach((line) => {
|
2015-11-25 22:38:01 +01:00
|
|
|
this.emit('data', line + '\n');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(ArrayStream, stream.Stream);
|
|
|
|
exports.ArrayStream = ArrayStream;
|
|
|
|
ArrayStream.prototype.readable = true;
|
|
|
|
ArrayStream.prototype.writable = true;
|
|
|
|
ArrayStream.prototype.pause = function() {};
|
|
|
|
ArrayStream.prototype.resume = function() {};
|
|
|
|
ArrayStream.prototype.write = function() {};
|
2015-11-03 02:56:24 +01:00
|
|
|
|
|
|
|
// Returns true if the exit code "exitCode" and/or signal name "signal"
|
|
|
|
// represent the exit code and/or signal name of a node process that aborted,
|
|
|
|
// false otherwise.
|
|
|
|
exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
|
|
|
|
// Depending on the compiler used, node will exit with either
|
|
|
|
// exit code 132 (SIGILL), 133 (SIGTRAP) or 134 (SIGABRT).
|
2016-12-08 06:47:15 +01:00
|
|
|
let expectedExitCodes = [132, 133, 134];
|
2015-11-03 02:56:24 +01:00
|
|
|
|
|
|
|
// On platforms using KSH as the default shell (like SmartOS),
|
|
|
|
// when a process aborts, KSH exits with an exit code that is
|
|
|
|
// greater than 256, and thus the exit code emitted with the 'exit'
|
|
|
|
// event is null and the signal is set to either SIGILL, SIGTRAP,
|
|
|
|
// or SIGABRT (depending on the compiler).
|
|
|
|
const expectedSignals = ['SIGILL', 'SIGTRAP', 'SIGABRT'];
|
|
|
|
|
|
|
|
// On Windows, v8's base::OS::Abort triggers an access violation,
|
|
|
|
// which corresponds to exit code 3221225477 (0xC0000005)
|
2016-05-29 17:53:40 +02:00
|
|
|
if (exports.isWindows)
|
2015-11-03 02:56:24 +01:00
|
|
|
expectedExitCodes = [3221225477];
|
|
|
|
|
|
|
|
// When using --abort-on-uncaught-exception, V8 will use
|
|
|
|
// base::OS::Abort to terminate the process.
|
|
|
|
// Depending on the compiler used, the shell or other aspects of
|
|
|
|
// the platform used to build the node binary, this will actually
|
|
|
|
// make V8 exit by aborting or by raising a signal. In any case,
|
|
|
|
// one of them (exit code or signal) needs to be set to one of
|
|
|
|
// the expected exit codes or signals.
|
|
|
|
if (signal !== null) {
|
2016-11-22 06:25:37 +01:00
|
|
|
return expectedSignals.includes(signal);
|
2015-11-03 02:56:24 +01:00
|
|
|
} else {
|
2016-11-22 06:25:37 +01:00
|
|
|
return expectedExitCodes.includes(exitCode);
|
2015-11-03 02:56:24 +01:00
|
|
|
}
|
|
|
|
};
|
2015-07-24 02:09:21 +02:00
|
|
|
|
|
|
|
exports.busyLoop = function busyLoop(time) {
|
2016-12-08 06:47:15 +01:00
|
|
|
const startTime = Timer.now();
|
|
|
|
const stopTime = startTime + time;
|
2015-07-24 02:09:21 +02:00
|
|
|
while (Timer.now() < stopTime) {}
|
|
|
|
};
|
2016-08-24 22:55:12 +02:00
|
|
|
|
|
|
|
exports.isAlive = function isAlive(pid) {
|
|
|
|
try {
|
|
|
|
process.kill(pid, 'SIGCONT');
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2016-09-17 18:25:03 +02:00
|
|
|
|
|
|
|
exports.expectWarning = function(name, expected) {
|
|
|
|
if (typeof expected === 'string')
|
|
|
|
expected = [expected];
|
|
|
|
process.on('warning', exports.mustCall((warning) => {
|
|
|
|
assert.strictEqual(warning.name, name);
|
|
|
|
assert.ok(expected.includes(warning.message),
|
|
|
|
`unexpected error message: "${warning.message}"`);
|
|
|
|
// Remove a warning message after it is seen so that we guarantee that we
|
|
|
|
// get each message only once.
|
|
|
|
expected.splice(expected.indexOf(warning.message), 1);
|
|
|
|
}, expected.length));
|
|
|
|
};
|
2016-10-23 19:00:41 +02:00
|
|
|
|
|
|
|
Object.defineProperty(exports, 'hasIntl', {
|
|
|
|
get: function() {
|
|
|
|
return process.binding('config').hasIntl;
|
|
|
|
}
|
|
|
|
});
|
2017-02-02 07:13:16 +01:00
|
|
|
|
|
|
|
// https://github.com/w3c/testharness.js/blob/master/testharness.js
|
|
|
|
exports.WPT = {
|
|
|
|
test: (fn, desc) => {
|
|
|
|
try {
|
|
|
|
fn();
|
|
|
|
} catch (err) {
|
|
|
|
if (err instanceof Error)
|
|
|
|
err.message = `In ${desc}:\n ${err.message}`;
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
assert_equals: assert.strictEqual,
|
|
|
|
assert_true: (value, message) => assert.strictEqual(value, true, message),
|
|
|
|
assert_false: (value, message) => assert.strictEqual(value, false, message),
|
|
|
|
assert_throws: (code, func, desc) => {
|
|
|
|
assert.throws(func, (err) => {
|
|
|
|
return typeof err === 'object' && 'name' in err && err.name === code.name;
|
|
|
|
}, desc);
|
|
|
|
},
|
|
|
|
assert_array_equals: assert.deepStrictEqual,
|
|
|
|
assert_unreached(desc) {
|
|
|
|
assert.fail(undefined, undefined, `Reached unreachable code: ${desc}`);
|
|
|
|
}
|
|
|
|
};
|
2016-10-24 22:09:34 +02:00
|
|
|
|
|
|
|
// Useful for testing expected internal/error objects
|
|
|
|
exports.expectsError = function expectsError(code, type, message) {
|
|
|
|
return function(error) {
|
|
|
|
assert.strictEqual(error.code, code);
|
|
|
|
if (type !== undefined)
|
|
|
|
assert(error instanceof type, 'error is not the expected type');
|
|
|
|
if (message !== undefined) {
|
|
|
|
if (!util.isRegExp(message))
|
|
|
|
message = new RegExp(String(message));
|
|
|
|
assert(message.test(error.message), 'error.message does not match');
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
};
|