From 13192a904800cb8d54bb92457d1c74d21ee1b081 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 3 Feb 2018 09:52:29 -0700 Subject: [PATCH 01/10] lib: set process.execPath on OpenBSD --- lib/internal/bootstrap_node.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 33de5ae4be2f0d..c7d8c1f585647a 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -75,6 +75,13 @@ // URL::ToObject() method is used. NativeModule.require('internal/url'); + // On OpenBSD process.execPath will be relative unless we + // get the full path before hand. + if (process.platform === 'openbsd') { + const { realpathSync } = NativeModule.require('fs'); + process.execPath = realpathSync.native(process.execPath); + } + Object.defineProperty(process, 'argv0', { enumerable: true, configurable: false, From 455dc601ccffee3e9e6b69fe2ed5bc82abcdffc8 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 3 Feb 2018 09:53:57 -0700 Subject: [PATCH 02/10] test: update a few test scripts to work on OpenBSD --- test/common/index.js | 1 + test/parallel/test-child-process-exec-timeout.js | 8 ++++++-- .../test-child-process-spawnsync-validation-errors.js | 6 +++++- test/parallel/test-fs-utimes.js | 4 ++-- test/parallel/test-http-dns-error.js | 8 ++++++-- test/parallel/test-net-dns-error.js | 8 ++++++-- test/parallel/test-setproctitle.js | 2 +- 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/test/common/index.js b/test/common/index.js index e8546db3a2f4ea..0206ea825ff6d7 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -55,6 +55,7 @@ exports.isLinuxPPCBE = (process.platform === 'linux') && (os.endianness() === 'BE'); exports.isSunOS = process.platform === 'sunos'; exports.isFreeBSD = process.platform === 'freebsd'; +exports.isOpenBSD = process.platform === 'openbsd'; exports.isLinux = process.platform === 'linux'; exports.isOSX = process.platform === 'darwin'; diff --git a/test/parallel/test-child-process-exec-timeout.js b/test/parallel/test-child-process-exec-timeout.js index ed25d9bff825a9..6b3beda89221a0 100644 --- a/test/parallel/test-child-process-exec-timeout.js +++ b/test/parallel/test-child-process-exec-timeout.js @@ -17,14 +17,18 @@ const cmd = `"${process.execPath}" "${__filename}" child`; // Test the case where a timeout is set, and it expires. cp.exec(cmd, { timeout: 1 }, common.mustCall((err, stdout, stderr) => { assert.strictEqual(err.killed, true); - assert.strictEqual(err.code, null); + // TODO OpenBSD returns a null code + if (!common.isOpenBSD) + assert.strictEqual(err.code, null); + else + sigterm = null; // At least starting with Darwin Kernel Version 16.4.0, sending a SIGTERM to a // process that is still starting up kills it with SIGKILL instead of SIGTERM. // See: https://github.com/libuv/libuv/issues/1226 if (common.isOSX) assert.ok(err.signal === 'SIGTERM' || err.signal === 'SIGKILL'); else - assert.strictEqual(err.signal, 'SIGTERM'); + assert.strictEqual(err.signal, sigterm); assert.strictEqual(err.cmd, cmd); assert.strictEqual(stdout.trim(), ''); assert.strictEqual(stderr.trim(), ''); diff --git a/test/parallel/test-child-process-spawnsync-validation-errors.js b/test/parallel/test-child-process-spawnsync-validation-errors.js index 433e0fce167366..276a93b3b1f8b3 100644 --- a/test/parallel/test-child-process-spawnsync-validation-errors.js +++ b/test/parallel/test-child-process-spawnsync-validation-errors.js @@ -5,13 +5,17 @@ const spawnSync = require('child_process').spawnSync; const signals = process.binding('constants').os.signals; let invalidArgTypeError; +let errCode = 56; +if (common.isOpenBSD) + errCode = 46; if (common.isWindows) { invalidArgTypeError = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, 36); } else { invalidArgTypeError = - common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, 56); + common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, + errCode); } const invalidRangeError = diff --git a/test/parallel/test-fs-utimes.js b/test/parallel/test-fs-utimes.js index db8201d7cb9449..dae9c7dc9eabfc 100644 --- a/test/parallel/test-fs-utimes.js +++ b/test/parallel/test-fs-utimes.js @@ -178,8 +178,8 @@ process.on('exit', function() { const path = `${tmpdir.path}/test-utimes-precision`; fs.writeFileSync(path, ''); -// test Y2K38 for all platforms [except 'arm', and 'SunOS'] -if (!process.arch.includes('arm') && !common.isSunOS) { +// test Y2K38 for all platforms [except 'arm', 'OpenBSD' and 'SunOS'] +if (!process.arch.includes('arm') && !common.isOpenBSD && !common.isSunOS) { // because 2 ** 31 doesn't look right // eslint-disable-next-line space-infix-ops const Y2K38_mtime = 2**31; diff --git a/test/parallel/test-http-dns-error.js b/test/parallel/test-http-dns-error.js index 900cf40e6b209b..06a15c89fb46b3 100644 --- a/test/parallel/test-http-dns-error.js +++ b/test/parallel/test-http-dns-error.js @@ -32,6 +32,10 @@ const https = require('https'); const host = '*'.repeat(256); const MAX_TRIES = 5; +let errCode = 'ENOTFOUND'; +if (common.isOpenBSD) + errCode = 'EAI_FAIL'; + function tryGet(mod, tries) { // Bad host name should not throw an uncatchable exception. // Ensure that there is time to attach an error listener. @@ -41,7 +45,7 @@ function tryGet(mod, tries) { tryGet(mod, ++tries); return; } - assert.strictEqual(err.code, 'ENOTFOUND'); + assert.strictEqual(err.code, errCode); })); // http.get() called req1.end() for us } @@ -57,7 +61,7 @@ function tryRequest(mod, tries) { tryRequest(mod, ++tries); return; } - assert.strictEqual(err.code, 'ENOTFOUND'); + assert.strictEqual(err.code, errCode); })); req.end(); } diff --git a/test/parallel/test-net-dns-error.js b/test/parallel/test-net-dns-error.js index beebcd8cb9cf44..a5ae415592fed4 100644 --- a/test/parallel/test-net-dns-error.js +++ b/test/parallel/test-net-dns-error.js @@ -27,17 +27,21 @@ const net = require('net'); const host = '*'.repeat(256); +let errCode = 'ENOTFOUND'; +if (common.isOpenBSD) + errCode = 'EAI_FAIL'; + function do_not_call() { throw new Error('This function should not have been called.'); } const socket = net.connect(42, host, do_not_call); socket.on('error', common.mustCall(function(err) { - assert.strictEqual(err.code, 'ENOTFOUND'); + assert.strictEqual(err.code, errCode); })); socket.on('lookup', function(err, ip, type) { assert(err instanceof Error); - assert.strictEqual(err.code, 'ENOTFOUND'); + assert.strictEqual(err.code, errCode); assert.strictEqual(ip, undefined); assert.strictEqual(type, undefined); }); diff --git a/test/parallel/test-setproctitle.js b/test/parallel/test-setproctitle.js index 4bb88c4ba06922..1ab6bff6a30848 100644 --- a/test/parallel/test-setproctitle.js +++ b/test/parallel/test-setproctitle.js @@ -34,7 +34,7 @@ exec(cmd, common.mustCall((error, stdout, stderr) => { assert.strictEqual(stderr, ''); // freebsd always add ' (procname)' to the process title - if (common.isFreeBSD) + if (common.isFreeBSD || common.isOpenBSD) title += ` (${path.basename(process.execPath)})`; // omitting trailing whitespace and \n From 42f51a5a1f2faf5039630a71f75e2e7fc6ab135c Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 3 Feb 2018 10:29:53 -0700 Subject: [PATCH 03/10] test: define sigterm --- test/parallel/test-child-process-exec-timeout.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-child-process-exec-timeout.js b/test/parallel/test-child-process-exec-timeout.js index 6b3beda89221a0..6e4c817a41820b 100644 --- a/test/parallel/test-child-process-exec-timeout.js +++ b/test/parallel/test-child-process-exec-timeout.js @@ -16,6 +16,7 @@ const cmd = `"${process.execPath}" "${__filename}" child`; // Test the case where a timeout is set, and it expires. cp.exec(cmd, { timeout: 1 }, common.mustCall((err, stdout, stderr) => { + let sigterm = 'SIGTERM'; assert.strictEqual(err.killed, true); // TODO OpenBSD returns a null code if (!common.isOpenBSD) From de838fad141c529ad9f3c8b1fee1ef2221e9ef1a Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 3 Feb 2018 10:34:59 -0700 Subject: [PATCH 04/10] fix comment for openbsd --- test/parallel/test-child-process-exec-timeout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-child-process-exec-timeout.js b/test/parallel/test-child-process-exec-timeout.js index 6e4c817a41820b..14923b4f5777f9 100644 --- a/test/parallel/test-child-process-exec-timeout.js +++ b/test/parallel/test-child-process-exec-timeout.js @@ -18,7 +18,7 @@ const cmd = `"${process.execPath}" "${__filename}" child`; cp.exec(cmd, { timeout: 1 }, common.mustCall((err, stdout, stderr) => { let sigterm = 'SIGTERM'; assert.strictEqual(err.killed, true); - // TODO OpenBSD returns a null code + // TODO OpenBSD returns a null signal if (!common.isOpenBSD) assert.strictEqual(err.code, null); else From 59edf9f0f14f3bb343b6e9575acb4de65892ba03 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 3 Feb 2018 11:21:43 -0700 Subject: [PATCH 05/10] more descriptive comment --- test/parallel/test-child-process-exec-timeout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-child-process-exec-timeout.js b/test/parallel/test-child-process-exec-timeout.js index 14923b4f5777f9..fc6a99cfec5a9a 100644 --- a/test/parallel/test-child-process-exec-timeout.js +++ b/test/parallel/test-child-process-exec-timeout.js @@ -18,7 +18,7 @@ const cmd = `"${process.execPath}" "${__filename}" child`; cp.exec(cmd, { timeout: 1 }, common.mustCall((err, stdout, stderr) => { let sigterm = 'SIGTERM'; assert.strictEqual(err.killed, true); - // TODO OpenBSD returns a null signal + // TODO OpenBSD returns a null signal and 143 for code if (!common.isOpenBSD) assert.strictEqual(err.code, null); else From 22eb27cdea098fc01544b3e65087bc3ff2e8548b Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 3 Feb 2018 14:46:22 -0700 Subject: [PATCH 06/10] check code 143 on openbsd --- test/parallel/test-child-process-exec-timeout.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-child-process-exec-timeout.js b/test/parallel/test-child-process-exec-timeout.js index fc6a99cfec5a9a..e08aff908522f2 100644 --- a/test/parallel/test-child-process-exec-timeout.js +++ b/test/parallel/test-child-process-exec-timeout.js @@ -19,10 +19,12 @@ cp.exec(cmd, { timeout: 1 }, common.mustCall((err, stdout, stderr) => { let sigterm = 'SIGTERM'; assert.strictEqual(err.killed, true); // TODO OpenBSD returns a null signal and 143 for code - if (!common.isOpenBSD) - assert.strictEqual(err.code, null); - else + if (common.isOpenBSD) { + assert.strictEqual(err.code, 143); sigterm = null; + } else { + assert.strictEqual(err.code, null); + } // At least starting with Darwin Kernel Version 16.4.0, sending a SIGTERM to a // process that is still starting up kills it with SIGKILL instead of SIGTERM. // See: https://github.com/libuv/libuv/issues/1226 From d0c6dfa2a761cf3c594c945c887de71879e6c846 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 3 Feb 2018 14:46:48 -0700 Subject: [PATCH 07/10] check for non-elf obj on openbsd --- test/sequential/test-module-loading.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/sequential/test-module-loading.js b/test/sequential/test-module-loading.js index 6fa789f19865d6..7bc8428fac5939 100644 --- a/test/sequential/test-module-loading.js +++ b/test/sequential/test-module-loading.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const path = require('path'); const fs = require('fs'); @@ -189,7 +189,10 @@ try { require(`${loadOrder}file3`); } catch (e) { // Not a real .node module, but we know we require'd the right thing. - assert.ok(/file3\.node/.test(e.message.replace(backslash, '/'))); + if (common.isOpenBSD) // OpenBSD errors with non-ELF object error + assert.ok(/File not an ELF object/.test(e.message.replace(backslash, '/'))); + else + assert.ok(/file3\.node/.test(e.message.replace(backslash, '/'))); } assert.strictEqual(require(`${loadOrder}file4`).file4, 'file4.reg', msg); assert.strictEqual(require(`${loadOrder}file5`).file5, 'file5.reg2', msg); @@ -197,7 +200,10 @@ try { try { require(`${loadOrder}file7`); } catch (e) { - assert.ok(/file7\/index\.node/.test(e.message.replace(backslash, '/'))); + if (common.isOpenBSD) + assert.ok(/File not an ELF object/.test(e.message.replace(backslash, '/'))); + else + assert.ok(/file7\/index\.node/.test(e.message.replace(backslash, '/'))); } assert.strictEqual(require(`${loadOrder}file8`).file8, 'file8/index.reg', msg); From 7aa9a7c3bff9ad4bba4e5a4cb4814ef10e702f85 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 3 Feb 2018 14:47:07 -0700 Subject: [PATCH 08/10] skip v8 debug symbol test on openbsd --- test/parallel/test-postmortem-metadata.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/parallel/test-postmortem-metadata.js b/test/parallel/test-postmortem-metadata.js index 0c06108c58bd45..72a65d32a610bf 100644 --- a/test/parallel/test-postmortem-metadata.js +++ b/test/parallel/test-postmortem-metadata.js @@ -12,6 +12,9 @@ const args = [process.execPath]; if (common.isAIX) args.unshift('-Xany', '-B'); +if (common.isOpenBSD) + common.skip('no v8 debug symbols on OpenBSD'); + const nm = spawnSync('nm', args); if (nm.error && nm.error.errno === 'ENOENT') From 31d4c9ab785a5594cf69b5dbe969df0bfb97f69e Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Mon, 5 Feb 2018 17:40:10 -0700 Subject: [PATCH 09/10] expand comment in bootstrap_node.js --- lib/internal/bootstrap_node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index c7d8c1f585647a..5197ffb8d46fdb 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -76,7 +76,7 @@ NativeModule.require('internal/url'); // On OpenBSD process.execPath will be relative unless we - // get the full path before hand. + // get the full path before process.execPath is used. if (process.platform === 'openbsd') { const { realpathSync } = NativeModule.require('fs'); process.execPath = realpathSync.native(process.execPath); From ad7bf608f2e1932530db601a5594dfaf07233615 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Thu, 8 Feb 2018 07:35:37 -0700 Subject: [PATCH 10/10] revert --- .../test-child-process-spawnsync-validation-errors.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/parallel/test-child-process-spawnsync-validation-errors.js b/test/parallel/test-child-process-spawnsync-validation-errors.js index 276a93b3b1f8b3..433e0fce167366 100644 --- a/test/parallel/test-child-process-spawnsync-validation-errors.js +++ b/test/parallel/test-child-process-spawnsync-validation-errors.js @@ -5,17 +5,13 @@ const spawnSync = require('child_process').spawnSync; const signals = process.binding('constants').os.signals; let invalidArgTypeError; -let errCode = 56; -if (common.isOpenBSD) - errCode = 46; if (common.isWindows) { invalidArgTypeError = common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, 36); } else { invalidArgTypeError = - common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, - errCode); + common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, 56); } const invalidRangeError =