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: use common platform helpers everywhere #7845

Merged
merged 1 commit into from
Jul 27, 2016
Merged
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
10 changes: 6 additions & 4 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ exports.isLinuxPPCBE = (process.platform === 'linux') &&
(os.endianness() === 'BE');
exports.isSunOS = process.platform === 'sunos';
exports.isFreeBSD = process.platform === 'freebsd';
exports.isLinux = process.platform === 'linux';
exports.isOSX = process.platform === 'darwin';

exports.enoughTestMem = os.totalmem() > 0x40000000; /* 1 Gb */
exports.rootDir = exports.isWindows ? 'c:\\' : '/';
Expand Down Expand Up @@ -61,7 +63,7 @@ function rmdirSync(p, originalEr) {
if (e.code === 'ENOTDIR')
throw originalEr;
if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') {
const enc = process.platform === 'linux' ? 'buffer' : 'utf8';
const enc = exports.isLinux ? 'buffer' : 'utf8';
fs.readdirSync(p, enc).forEach((f) => {
if (f instanceof Buffer) {
const buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]);
Expand Down Expand Up @@ -91,7 +93,7 @@ var inFreeBSDJail = null;
var localhostIPv4 = null;

exports.localIPv6Hosts = ['localhost'];
if (process.platform === 'linux') {
if (exports.isLinux) {
exports.localIPv6Hosts = [
// Debian/Ubuntu
'ip6-localhost',
Expand All @@ -110,7 +112,7 @@ Object.defineProperty(exports, 'inFreeBSDJail', {
get: function() {
if (inFreeBSDJail !== null) return inFreeBSDJail;

if (process.platform === 'freebsd' &&
if (exports.isFreeBSD &&
child_process.execSync('sysctl -n security.jail.jailed').toString() ===
'1\n') {
inFreeBSDJail = true;
Expand Down Expand Up @@ -469,7 +471,7 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {

// On Windows, v8's base::OS::Abort triggers an access violation,
// which corresponds to exit code 3221225477 (0xC0000005)
if (process.platform === 'win32')
if (exports.isWindows)
expectedExitCodes = [3221225477];

// When using --abort-on-uncaught-exception, V8 will use
Expand Down
2 changes: 1 addition & 1 deletion test/internet/test-dns-ipv6.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ TEST(function test_lookup_ipv6_hint(done) {
}, function(err, ip, family) {
if (err) {
// FreeBSD does not support V4MAPPED
if (process.platform === 'freebsd') {
if (common.isFreeBSD) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'EAI_BADFLAGS');
assert.strictEqual(err.hostname, 'www.google.com');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cwd-enoent-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fs = require('fs');
const spawn = require('child_process').spawn;

// Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX.
if (process.platform === 'sunos' || common.isWindows || common.isAix) {
if (common.isSunOS || common.isWindows || common.isAix) {
common.skip('cannot rmdir current working directory');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cwd-enoent-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var fs = require('fs');
var spawn = require('child_process').spawn;

// Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX.
if (process.platform === 'sunos' || common.isWindows || common.isAix) {
if (common.isSunOS || common.isWindows || common.isAix) {
common.skip('cannot rmdir current working directory');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cwd-enoent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var fs = require('fs');
var spawn = require('child_process').spawn;

// Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX.
if (process.platform === 'sunos' || common.isWindows || common.isAix) {
if (common.isSunOS || common.isWindows || common.isAix) {
common.skip('cannot rmdir current working directory');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-empty-packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var callbacks = 0;
var client;
var timer;

if (process.platform === 'darwin') {
if (common.isOSX) {
common.skip('because of 17894467 Apple bug');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-send-empty-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');

if (process.platform === 'darwin') {
if (common.isOSX) {
common.skip('because of 17894467 Apple bug');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-send-empty-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const common = require('../common');
const dgram = require('dgram');

if (process.platform === 'darwin') {
if (common.isOSX) {
common.skip('because of 17894467 Apple bug');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-domain-abort-on-uncaught.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ if (process.argv[2] === 'child') {

tests.forEach(function(test, testIndex) {
var testCmd = '';
if (process.platform !== 'win32') {
if (!common.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 && ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ if (process.argv[2] === 'child') {

tests.forEach(function(test, testIndex) {
var testCmd = '';
if (process.platform !== 'win32') {
if (!common.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 && ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function runTestWithAbortOnUncaughtException() {
function createTestCmdLine(options) {
var testCmd = '';

if (process.platform !== 'win32') {
if (!common.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 && ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ if (process.argv[2] === 'child') {
throwInDomainErrHandlerOpt = 'throwInDomainErrHandler';

var cmdToExec = '';
if (process.platform !== 'win32') {
if (!common.isWindows) {
// Do not create core files, as it can take a lot of disk space on
// continuous testing and developers' machines
cmdToExec += 'ulimit -c 0 && ';
Expand Down
18 changes: 11 additions & 7 deletions test/parallel/test-fs-read-file-sync-hostname.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
'use strict';
require('../common');
var assert = require('assert');
var fs = require('fs');
const common = require('../common');
const assert = require('assert');
const fs = require('fs');

// test reading from hostname
if (process.platform === 'linux2') {
var hostname = fs.readFileSync('/proc/sys/kernel/hostname');
assert.ok(hostname.length > 0);
if (!common.isLinux) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

common.isLinux checks if process.platform === 'linux', but this test was checking for linux2. Is that planned?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought linux2 was a python thing and was misspelled. Are there any linuxes where process.platform is set to linux2? From the conversation in the mailing list where the patch that introduced the test was discussed, it seems that the problem was that in using stat on a file in the /proc directory caused issues and readFileSync should not use any stat call in its implementation. Then, looking the stat manual found this:

For most files under the /proc directory, stat() does not return the file size in the st_size field; instead the field is returned with the value 0.

So if there are linux2 systems out there I think it would probably make sense testing in both linux and linux2. If someone could shed some light on this, it would be great.

common.skip('Test is linux specific.');
return;
}

// Test to make sure reading a file under the /proc directory works. See:
// https://groups.google.com/forum/#!topic/nodejs-dev/rxZ_RoH1Gn0
const hostname = fs.readFileSync('/proc/sys/kernel/hostname');
assert.ok(hostname.length > 0);
2 changes: 1 addition & 1 deletion test/parallel/test-fs-readdir-ucs2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const fs = require('fs');
const assert = require('assert');

if (process.platform !== 'linux') {
if (!common.isLinux) {
common.skip('Test is linux specific.');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-watch-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

if (!(process.platform === 'darwin' || common.isWindows)) {
if (!(common.isOSX || common.isWindows)) {
common.skip('recursive option is darwin/windows specific');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var arch = os.arch();
console.log('arch = ', arch);
assert.ok(arch.length > 0);

if (process.platform != 'sunos') {
if (!common.isSunOS) {
// not implemeneted yet
assert.ok(os.loadavg().length > 0);
assert.ok(os.freemem() > 0);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-process-constants-noatime.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

require('../common');
const common = require('../common');
const assert = require('assert');
const constants = process.binding('constants');

if (process.platform === 'linux') {
if (common.isLinux) {
assert('O_NOATIME' in constants.fs);
assert.strictEqual(constants.fs.O_NOATIME, 0x40000);
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-process-getgroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const common = require('../common');
var assert = require('assert');
var exec = require('child_process').exec;

if (process.platform === 'darwin') {
if (common.isOSX) {
common.skip('Output of `id -G` is unreliable on Darwin.');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-sigint-nested-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require('assert');

const spawn = require('child_process').spawn;

if (process.platform === 'win32') {
if (common.isWindows) {
// No way to send CTRL_C_EVENT to processes from JS right now.
common.skip('platform not supported');
return;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-sigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require('assert');

const spawn = require('child_process').spawn;

if (process.platform === 'win32') {
if (common.isWindows) {
// No way to send CTRL_C_EVENT to processes from JS right now.
common.skip('platform not supported');
return;
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-setproctitle.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';
// Original test written by Jakub Lekstan <kuebzky@gmail.com>
const common = require('../common');

require('../common');
// FIXME add sunos support
if ('linux freebsd darwin'.indexOf(process.platform) === -1) {
if (!(common.isFreeBSD || common.isOSX || common.isLinux)) {
console.log(`1..0 # Skipped: Unsupported platform [${process.platform}]`);
return;
}
Expand All @@ -26,7 +27,7 @@ exec('ps -p ' + process.pid + ' -o args=', function(error, stdout, stderr) {
assert.equal(stderr, '');

// freebsd always add ' (procname)' to the process title
if (process.platform === 'freebsd')
if (common.isFreeBSD)
title += ` (${path.basename(process.execPath)})`;

// omitting trailing whitespace and \n
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-util-sigint-watchdog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const common = require('../common');
const assert = require('assert');
const binding = process.binding('util');

if (process.platform === 'win32') {
if (common.isWindows) {
// No way to send CTRL_C_EVENT to processes from JS right now.
common.skip('platform not supported');
return;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-vm-sigint-existing-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const vm = require('vm');

const spawn = require('child_process').spawn;

if (process.platform === 'win32') {
if (common.isWindows) {
// No way to send CTRL_C_EVENT to processes from JS right now.
common.skip('platform not supported');
return;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-vm-sigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const vm = require('vm');

const spawn = require('child_process').spawn;

if (process.platform === 'win32') {
if (common.isWindows) {
// No way to send CTRL_C_EVENT to processes from JS right now.
common.skip('platform not supported');
return;
Expand Down
5 changes: 2 additions & 3 deletions test/pummel/test-net-pingpong.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ pingPongTest(common.PORT, 'localhost');
pingPongTest(common.PORT + 1, null);

// This IPv6 isn't working on Solaris
var solaris = /sunos/i.test(process.platform);
if (!solaris) pingPongTest(common.PORT + 2, '::1');
if (!common.isSunOS) pingPongTest(common.PORT + 2, '::1');

process.on('exit', function() {
assert.equal(solaris ? 2 : 3, tests_run);
assert.equal(common.isSunOS ? 2 : 3, tests_run);
});
4 changes: 2 additions & 2 deletions test/sequential/test-fs-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var path = require('path');
var fs = require('fs');

var expectFilePath = common.isWindows ||
process.platform === 'linux' ||
process.platform === 'darwin';
common.isLinux ||
common.isOSX;

var watchSeenOne = 0;
var watchSeenTwo = 0;
Expand Down