11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciif (common.isWindows)
51cb0ef41Sopenharmony_ci  common.skip('dlopen global symbol loading is not supported on this os.');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst path = require('path');
91cb0ef41Sopenharmony_ciconst os = require('os');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst bindingPath = require.resolve(`./build/${common.buildType}/binding`);
121cb0ef41Sopenharmony_ciconsole.log('process.dlopen:', bindingPath);
131cb0ef41Sopenharmony_ciprocess.dlopen(module, bindingPath,
141cb0ef41Sopenharmony_ci               os.constants.dlopen.RTLD_NOW | os.constants.dlopen.RTLD_GLOBAL);
151cb0ef41Sopenharmony_ciconsole.log('module.exports.load:', `${path.dirname(bindingPath)}/ping.so`);
161cb0ef41Sopenharmony_cimodule.exports.load(`${path.dirname(bindingPath)}/ping.so`);
171cb0ef41Sopenharmony_ciassert.strictEqual(module.exports.ping(), 'pong');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci// Check that after the addon is loaded with
201cb0ef41Sopenharmony_ci// process.dlopen() a require() call fails.
211cb0ef41Sopenharmony_ciconsole.log('require:', `./build/${common.buildType}/binding`);
221cb0ef41Sopenharmony_ciconst re = /^Error: Module did not self-register: '.*[\\/]binding\.node'\.$/;
231cb0ef41Sopenharmony_ciassert.throws(() => require(`./build/${common.buildType}/binding`), re);
24