Skip to content

Commit

Permalink
test: add duplicate symbol test
Browse files Browse the repository at this point in the history
On OSX symbols are exported by default, and they overlap if two
different copies of the same symbol appear in a process. This change
ensures that, on OSX, symbols are hidden by default.

Re: nodejs/node-addon-api#456
  • Loading branch information
Gabriel Schulhof committed Mar 11, 2019
1 parent bb8b294 commit f6c37a4
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 0 deletions.
6 changes: 6 additions & 0 deletions addon.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,16 @@

'conditions': [
[ 'OS=="mac"', {
'cflags': [
'-fvisibility=hidden'
],
'defines': [
'_DARWIN_USE_64_BIT_INODE=1'
],
'xcode_settings': {
'OTHER_CFLAGS': [
'-fvisibility=hidden'
],
'DYLIB_INSTALL_NAME_BASE': '@rpath'
},
}],
Expand Down
10 changes: 10 additions & 0 deletions test/node_modules/duplicate_symbols/binding.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions test/node_modules/duplicate_symbols/binding.gyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions test/node_modules/duplicate_symbols/common.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/node_modules/duplicate_symbols/extra.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/node_modules/duplicate_symbols/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/node_modules/duplicate_symbols/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions test/test-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ function runHello(hostProcess) {
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
}

function runDuplicateBindings(hostProcess) {
if (!hostProcess) {
hostProcess = process.execPath
}
var testCode =
"console.log((function(bindings) {" +
"return bindings.pointerCheck1(bindings.pointerCheck2());" +
"})(require('duplicate_symbols')))"
console.log('running ', hostProcess);
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
}

function getEncoding() {
var code = 'import locale;print locale.getdefaultlocale()[1]'
return execFileSync('python', ['-c', code]).toString().trim()
Expand Down Expand Up @@ -52,6 +64,23 @@ test('build simple addon', function (t) {
proc.stderr.setEncoding('utf-8')
})

test('make sure addon symbols do not overlap', function (t) {
t.plan(3)

var addonPath = path.resolve(__dirname, 'node_modules', 'duplicate_symbols')
// Set the loglevel otherwise the output disappears when run via 'npm test'
var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) {
var logLines = stderr.toString().trim().split(/\r?\n/)
var lastLine = logLines[logLines.length-1]
t.strictEqual(err, null)
t.strictEqual(lastLine, 'gyp info ok', 'should end in ok')
t.strictEqual(runDuplicateBindings().trim(), 'not equal')
})
proc.stdout.setEncoding('utf-8')
proc.stderr.setEncoding('utf-8')
})

test('build simple addon in path with non-ascii characters', function (t) {
t.plan(1)

Expand Down

0 comments on commit f6c37a4

Please sign in to comment.