koffi 0.9.30 → 0.9.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/call.hh +2 -1
- package/src/call_arm32.cc +27 -15
- package/src/call_arm64.cc +4 -9
- package/src/call_x64_sysv.cc +4 -9
- package/src/call_x64_sysv_fwd.S +13 -3
- package/src/call_x64_win.cc +4 -9
- package/src/call_x86.cc +18 -16
- package/src/ffi.cc +93 -46
- package/src/ffi.hh +11 -6
- package/src/util.cc +35 -1
- package/src/util.hh +2 -0
- package/test/tests/misc.c +62 -1
- package/test/tests/misc.js +49 -1
- package/vendor/node-addon-api/CHANGELOG.md +57 -0
- package/vendor/node-addon-api/README.md +3 -3
- package/vendor/node-addon-api/doc/array_buffer.md +2 -2
- package/vendor/node-addon-api/doc/buffer.md +2 -2
- package/vendor/node-addon-api/doc/class_property_descriptor.md +13 -5
- package/vendor/node-addon-api/doc/env.md +5 -5
- package/vendor/node-addon-api/doc/object.md +12 -33
- package/vendor/node-addon-api/doc/object_reference.md +1 -1
- package/vendor/node-addon-api/doc/object_wrap.md +27 -0
- package/vendor/node-addon-api/doc/reference.md +2 -2
- package/vendor/node-addon-api/doc/threadsafe_function.md +3 -3
- package/vendor/node-addon-api/doc/typed_threadsafe_function.md +2 -2
- package/vendor/node-addon-api/napi-inl.h +111 -61
- package/vendor/node-addon-api/napi.h +79 -59
- package/vendor/node-addon-api/package.json +22 -6
- package/vendor/node-addon-api/test/async_context.cc +15 -0
- package/vendor/node-addon-api/test/async_context.js +69 -33
- package/vendor/node-addon-api/test/binding.cc +2 -0
- package/vendor/node-addon-api/test/binding.gyp +7 -0
- package/vendor/node-addon-api/test/common/index.js +23 -22
- package/vendor/node-addon-api/test/common/test_helper.h +10 -0
- package/vendor/node-addon-api/test/error_terminating_environment.js +1 -0
- package/vendor/node-addon-api/test/function.cc +29 -0
- package/vendor/node-addon-api/test/function.js +35 -23
- package/vendor/node-addon-api/test/index.js +40 -17
- package/vendor/node-addon-api/test/object/object.cc +2 -0
- package/vendor/node-addon-api/test/object/set_property.cc +8 -0
- package/vendor/node-addon-api/test/object/set_property.js +6 -5
- package/vendor/node-addon-api/test/object/subscript_operator.cc +19 -3
- package/vendor/node-addon-api/test/objectwrap_function.cc +45 -0
- package/vendor/node-addon-api/test/objectwrap_function.js +22 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +1 -1
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +2 -2
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc +1 -1
- package/vendor/node-addon-api/tools/clang-format.js +4 -1
- package/vendor/node-addon-api/unit-test/README.md +28 -0
- package/vendor/node-addon-api/unit-test/binding-file-template.js +39 -0
- package/vendor/node-addon-api/unit-test/binding.gyp +72 -0
- package/vendor/node-addon-api/unit-test/exceptions.js +32 -0
- package/vendor/node-addon-api/unit-test/generate-binding-cc.js +61 -0
- package/vendor/node-addon-api/unit-test/injectTestParams.js +101 -0
- package/vendor/node-addon-api/unit-test/listOfTestModules.js +88 -0
- package/vendor/node-addon-api/unit-test/matchModules.js +65 -0
- package/vendor/node-addon-api/unit-test/setup.js +13 -0
- package/vendor/node-addon-api/unit-test/spawnTask.js +26 -0
- package/vendor/node-addon-api/unit-test/test.js +30 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
const testUtil = require('./testUtil');
|
|
5
|
+
|
|
6
|
+
function test (binding) {
|
|
7
|
+
return testUtil.runGCTests([
|
|
8
|
+
'objectwrap function',
|
|
9
|
+
() => {
|
|
10
|
+
const { FunctionTest } = binding.objectwrap_function;
|
|
11
|
+
const newConstructed = new FunctionTest();
|
|
12
|
+
const functionConstructed = FunctionTest();
|
|
13
|
+
assert(newConstructed instanceof FunctionTest);
|
|
14
|
+
assert(functionConstructed instanceof FunctionTest);
|
|
15
|
+
assert.throws(() => (FunctionTest(true)), /an exception/);
|
|
16
|
+
},
|
|
17
|
+
// Do on gc before returning.
|
|
18
|
+
() => {}
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = require('./common').runTest(test);
|
|
@@ -81,7 +81,7 @@ public:
|
|
|
81
81
|
// Entry point for std::thread
|
|
82
82
|
void entryDelayedTSFN(int threadId) {
|
|
83
83
|
std::unique_lock<std::mutex> lk(mtx);
|
|
84
|
-
cv.wait(lk);
|
|
84
|
+
cv.wait(lk, [this] { return this->tsfn != nullptr; });
|
|
85
85
|
tsfn.BlockingCall([=](Napi::Env env, Function callback) {
|
|
86
86
|
callback.Call({Number::New(env, static_cast<double>(threadId))});
|
|
87
87
|
});
|
package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js
CHANGED
|
@@ -4,9 +4,9 @@ const assert = require('assert');
|
|
|
4
4
|
|
|
5
5
|
module.exports = require('../common').runTest(test);
|
|
6
6
|
|
|
7
|
-
async function test(binding) {
|
|
7
|
+
async function test (binding) {
|
|
8
8
|
const ctx = { };
|
|
9
|
-
const tsfn = new binding.
|
|
9
|
+
const tsfn = new binding.typed_threadsafe_function_ctx.TSFNWrap(ctx);
|
|
10
10
|
assert(tsfn.getContext() === ctx);
|
|
11
11
|
await tsfn.release();
|
|
12
12
|
}
|
package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc
CHANGED
|
@@ -99,7 +99,7 @@ class DelayedTSFNTask {
|
|
|
99
99
|
// Entry point for std::thread
|
|
100
100
|
void entryDelayedTSFN(int threadId) {
|
|
101
101
|
std::unique_lock<std::mutex> lk(mtx);
|
|
102
|
-
cv.wait(lk);
|
|
102
|
+
cv.wait(lk, [this] { return this->tsfn != nullptr; });
|
|
103
103
|
tsfn.BlockingCall(new double(threadId));
|
|
104
104
|
tsfn.Release();
|
|
105
105
|
};
|
|
@@ -20,7 +20,10 @@ function main (args) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const clangFormatPath = path.dirname(require.resolve('clang-format'));
|
|
23
|
-
const
|
|
23
|
+
const binary = process.platform === 'win32'
|
|
24
|
+
? 'node_modules\\.bin\\clang-format.cmd'
|
|
25
|
+
: 'node_modules/.bin/clang-format';
|
|
26
|
+
const options = ['--binary=' + binary, '--style=file'];
|
|
24
27
|
if (fix) {
|
|
25
28
|
options.push(FORMAT_START);
|
|
26
29
|
} else {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
# Enable running tests with specific filter conditions:
|
|
3
|
+
|
|
4
|
+
### Example:
|
|
5
|
+
|
|
6
|
+
- compile ad run only tests on objectwrap.cc and objectwrap.js
|
|
7
|
+
```
|
|
8
|
+
npm run unit --filter=objectwrap
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Wildcards are also possible:
|
|
13
|
+
|
|
14
|
+
### Example:
|
|
15
|
+
|
|
16
|
+
- compile and run all tests files ending with reference -> function_reference.cc object_reference.cc reference.cc
|
|
17
|
+
```
|
|
18
|
+
npm run unit --filter=*reference
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
# Multiple filter conditions are also allowed
|
|
22
|
+
|
|
23
|
+
### Example:
|
|
24
|
+
|
|
25
|
+
- compile and run all tests under folders threadsafe_function and typed_threadsafe_function and also the objectwrap.cc file
|
|
26
|
+
```
|
|
27
|
+
npm run unit --filter='*function objectwrap'
|
|
28
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param bindingConfigurations
|
|
6
|
+
* This method acts as a template to generate the content of binding.cc file
|
|
7
|
+
*/
|
|
8
|
+
module.exports.generateFileContent = function (bindingConfigurations) {
|
|
9
|
+
const content = [];
|
|
10
|
+
const inits = [];
|
|
11
|
+
const exports = [];
|
|
12
|
+
|
|
13
|
+
for (const config of bindingConfigurations) {
|
|
14
|
+
inits.push(`Object Init${config.objectName}(Env env);`);
|
|
15
|
+
exports.push(`exports.Set("${config.propertyName}", Init${config.objectName}(env));`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
content.push('#include "napi.h"');
|
|
19
|
+
content.push('using namespace Napi;');
|
|
20
|
+
|
|
21
|
+
inits.forEach(init => content.push(init));
|
|
22
|
+
|
|
23
|
+
content.push('Object Init(Env env, Object exports) {');
|
|
24
|
+
|
|
25
|
+
exports.forEach(exp => content.push(exp));
|
|
26
|
+
|
|
27
|
+
content.push('return exports;');
|
|
28
|
+
content.push('}');
|
|
29
|
+
content.push('NODE_API_MODULE(addon, Init);');
|
|
30
|
+
|
|
31
|
+
return Promise.resolve(content.join('\r\n'));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
module.exports.writeToBindingFile = function writeToBindingFile (content) {
|
|
35
|
+
const generatedFilePath = path.join(__dirname, 'generated', 'binding.cc');
|
|
36
|
+
fs.writeFileSync(generatedFilePath, '');
|
|
37
|
+
fs.writeFileSync(generatedFilePath, content, { flag: 'a' });
|
|
38
|
+
console.log('generated binding file ', generatedFilePath, new Date());
|
|
39
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
'target_defaults': {
|
|
3
|
+
'includes': ['../common.gypi'],
|
|
4
|
+
'include_dirs': ['../test/common', "./generated"],
|
|
5
|
+
'variables': {
|
|
6
|
+
'setup': ["<!@(node -p \"require('./setup')\")"],
|
|
7
|
+
'build_sources': [
|
|
8
|
+
"<!@(node -p \"require('./injectTestParams').filesToCompile()\")",
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
'targets': [
|
|
13
|
+
{
|
|
14
|
+
"target_name": "generateBindingCC",
|
|
15
|
+
"type": "none",
|
|
16
|
+
"actions": [ {
|
|
17
|
+
"action_name": "generateBindingCC",
|
|
18
|
+
"message": "Generating binding cc file",
|
|
19
|
+
"outputs": ["generated/binding.cc"],
|
|
20
|
+
"conditions": [
|
|
21
|
+
[ "'true'=='true'", {
|
|
22
|
+
"inputs": [""],
|
|
23
|
+
"action": [
|
|
24
|
+
"node",
|
|
25
|
+
"generate-binding-cc.js",
|
|
26
|
+
"<!@(node -p \"require('./injectTestParams').filesForBinding()\" )"
|
|
27
|
+
]
|
|
28
|
+
} ]
|
|
29
|
+
]
|
|
30
|
+
} ]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
'target_name': 'binding',
|
|
34
|
+
'includes': ['../except.gypi'],
|
|
35
|
+
'sources': ['>@(build_sources)'],
|
|
36
|
+
'dependencies': [ 'generateBindingCC' ]
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
'target_name': 'binding_noexcept',
|
|
40
|
+
'includes': ['../noexcept.gypi'],
|
|
41
|
+
'sources': ['>@(build_sources)'],
|
|
42
|
+
'dependencies': [ 'generateBindingCC' ]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
'target_name': 'binding_noexcept_maybe',
|
|
46
|
+
'includes': ['../noexcept.gypi'],
|
|
47
|
+
'sources': ['>@(build_sources)'],
|
|
48
|
+
'defines': ['NODE_ADDON_API_ENABLE_MAYBE']
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
'target_name': 'binding_swallowexcept',
|
|
52
|
+
'includes': ['../except.gypi'],
|
|
53
|
+
'sources': ['>@(build_sources)'],
|
|
54
|
+
'defines': ['NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS'],
|
|
55
|
+
'dependencies': [ 'generateBindingCC' ]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
'target_name': 'binding_swallowexcept_noexcept',
|
|
59
|
+
'includes': ['../noexcept.gypi'],
|
|
60
|
+
'sources': ['>@(build_sources)'],
|
|
61
|
+
'defines': ['NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS'],
|
|
62
|
+
'dependencies': [ 'generateBindingCC' ]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
'target_name': 'binding_custom_namespace',
|
|
66
|
+
'includes': ['../noexcept.gypi'],
|
|
67
|
+
'sources': ['>@(build_sources)'],
|
|
68
|
+
'defines': ['NAPI_CPP_CUSTOM_NAMESPACE=cstm'],
|
|
69
|
+
'dependencies': [ 'generateBindingCC' ]
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file points out anomalies/exceptions in test files when generating the binding.cc file
|
|
3
|
+
*
|
|
4
|
+
* nouns: words in file names that are misspelled
|
|
5
|
+
* *NOTE: a 'constructor' property is explicitly added to override javascript object constructor
|
|
6
|
+
*
|
|
7
|
+
* exportNames: anomalies in init function names
|
|
8
|
+
*
|
|
9
|
+
* propertyNames: anomalies in exported property name of init functions
|
|
10
|
+
*
|
|
11
|
+
* skipBinding: skip including this file in binding.cc
|
|
12
|
+
*/
|
|
13
|
+
module.exports = {
|
|
14
|
+
nouns: {
|
|
15
|
+
constructor: 'constructor',
|
|
16
|
+
threadsafe: 'threadSafe',
|
|
17
|
+
objectwrap: 'objectWrap'
|
|
18
|
+
},
|
|
19
|
+
exportNames: {
|
|
20
|
+
AsyncWorkerPersistent: 'PersistentAsyncWorker'
|
|
21
|
+
},
|
|
22
|
+
propertyNames: {
|
|
23
|
+
async_worker_persistent: 'persistentasyncworker',
|
|
24
|
+
objectwrap_constructor_exception: 'objectwrapConstructorException'
|
|
25
|
+
},
|
|
26
|
+
skipBinding: [
|
|
27
|
+
'global_object_delete_property',
|
|
28
|
+
'global_object_get_property',
|
|
29
|
+
'global_object_has_own_property',
|
|
30
|
+
'global_object_set_property'
|
|
31
|
+
]
|
|
32
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const listOfTestModules = require('./listOfTestModules');
|
|
2
|
+
const exceptions = require('./exceptions');
|
|
3
|
+
const { generateFileContent, writeToBindingFile } = require('./binding-file-template');
|
|
4
|
+
|
|
5
|
+
const buildDirs = listOfTestModules.dirs;
|
|
6
|
+
const buildFiles = listOfTestModules.files;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param none
|
|
10
|
+
* @requires list of files to bind as command-line argument
|
|
11
|
+
* @returns list of binding configurations
|
|
12
|
+
*/
|
|
13
|
+
function generateBindingConfigurations () {
|
|
14
|
+
const testFilesToBind = process.argv.slice(2);
|
|
15
|
+
console.log('test modules to bind: ', testFilesToBind);
|
|
16
|
+
|
|
17
|
+
const configs = [];
|
|
18
|
+
|
|
19
|
+
testFilesToBind.forEach((file) => {
|
|
20
|
+
const configName = file.split('.cc')[0];
|
|
21
|
+
|
|
22
|
+
if (buildDirs[configName]) {
|
|
23
|
+
for (const file of buildDirs[configName]) {
|
|
24
|
+
if (exceptions.skipBinding.includes(file)) continue;
|
|
25
|
+
configs.push(buildFiles[file]);
|
|
26
|
+
}
|
|
27
|
+
} else if (buildFiles[configName]) {
|
|
28
|
+
configs.push(buildFiles[configName]);
|
|
29
|
+
} else {
|
|
30
|
+
console.log('not found', file, configName);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return Promise.resolve(configs);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
generateBindingConfigurations().then(generateFileContent).then(writeToBindingFile);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Test cases
|
|
41
|
+
* @fires only when run directly from terminal with TEST=true
|
|
42
|
+
* eg: TEST=true node generate-binding-cc
|
|
43
|
+
*/
|
|
44
|
+
if (require.main === module && process.env.TEST === 'true') {
|
|
45
|
+
const assert = require('assert');
|
|
46
|
+
|
|
47
|
+
const setArgsAndCall = (fn, filterCondition) => { process.argv = [null, null, ...filterCondition.split(' ')]; return fn(); };
|
|
48
|
+
const assertPromise = (promise, expectedVal) => promise.then((val) => assert.deepEqual(val, expectedVal)).catch(console.log);
|
|
49
|
+
|
|
50
|
+
const expectedVal = [{
|
|
51
|
+
dir: '',
|
|
52
|
+
objectName: 'AsyncProgressWorker',
|
|
53
|
+
propertyName: 'async_progress_worker'
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
dir: '',
|
|
57
|
+
objectName: 'PersistentAsyncWorker',
|
|
58
|
+
propertyName: 'persistentasyncworker'
|
|
59
|
+
}];
|
|
60
|
+
assertPromise(setArgsAndCall(generateBindingConfigurations, 'async_progress_worker async_worker_persistent'), expectedVal);
|
|
61
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const listOfTestModules = require('./listOfTestModules');
|
|
5
|
+
|
|
6
|
+
const buildDirs = listOfTestModules.dirs;
|
|
7
|
+
const buildFiles = listOfTestModules.files;
|
|
8
|
+
|
|
9
|
+
if (!fs.existsSync('./generated')) {
|
|
10
|
+
fs.mkdirSync('./generated');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @returns : list of files to compile by node-gyp
|
|
15
|
+
* @param : none
|
|
16
|
+
* @requires : picks `filter` parameter from process.env
|
|
17
|
+
* This function is used as an utility method to inject a list of files to compile into binding.gyp
|
|
18
|
+
*/
|
|
19
|
+
module.exports.filesToCompile = function () {
|
|
20
|
+
// match filter argument with available test modules
|
|
21
|
+
const matchedModules = require('./matchModules').matchWildCards(process.env.npm_config_filter || '');
|
|
22
|
+
|
|
23
|
+
// standard list of files to compile
|
|
24
|
+
const addedFiles = './generated/binding.cc test_helper.h';
|
|
25
|
+
|
|
26
|
+
const filterConditions = matchedModules.split(' ').length ? matchedModules.split(' ') : [matchedModules];
|
|
27
|
+
const files = [];
|
|
28
|
+
|
|
29
|
+
// generate a list of all files to compile
|
|
30
|
+
for (const matchCondition of filterConditions) {
|
|
31
|
+
if (buildDirs[matchCondition.toLowerCase()]) {
|
|
32
|
+
for (const file of buildDirs[matchCondition.toLowerCase()]) {
|
|
33
|
+
const config = buildFiles[file];
|
|
34
|
+
const separator = config.dir.length ? '/' : '';
|
|
35
|
+
files.push(config.dir + separator + file);
|
|
36
|
+
}
|
|
37
|
+
} else if (buildFiles[matchCondition.toLowerCase()]) {
|
|
38
|
+
const config = buildFiles[matchCondition.toLowerCase()];
|
|
39
|
+
const separator = config.dir.length ? '/' : '';
|
|
40
|
+
files.push(config.dir + separator + matchCondition.toLowerCase());
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// generate a string of files to feed to the compiler
|
|
45
|
+
let filesToCompile = '';
|
|
46
|
+
files.forEach((file) => {
|
|
47
|
+
filesToCompile = `${filesToCompile} ../test/${file}.cc`;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// log list of compiled files
|
|
51
|
+
fs.writeFileSync(path.join(__dirname, '/generated/compilelist'), `${addedFiles} ${filesToCompile}`.split(' ').join('\r\n'));
|
|
52
|
+
|
|
53
|
+
// return file list
|
|
54
|
+
return `${addedFiles} ${filesToCompile}`;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @returns list of test files to bind exported init functions
|
|
59
|
+
* @param : none
|
|
60
|
+
* @requires : picks `filter` parameter from process.env
|
|
61
|
+
* This function is used as an utility method by the generateBindingCC step in binding.gyp
|
|
62
|
+
*/
|
|
63
|
+
module.exports.filesForBinding = function () {
|
|
64
|
+
const filterCondition = require('./matchModules').matchWildCards(process.env.npm_config_filter || '');
|
|
65
|
+
fs.writeFileSync(path.join(__dirname, '/generated/bindingList'), filterCondition.split(' ').join('\r\n'));
|
|
66
|
+
return filterCondition;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Test cases
|
|
71
|
+
* @fires only when run directly from terminal
|
|
72
|
+
* eg: node injectTestParams
|
|
73
|
+
*/
|
|
74
|
+
if (require.main === module) {
|
|
75
|
+
const assert = require('assert');
|
|
76
|
+
|
|
77
|
+
const setEnvAndCall = (fn, filterCondition) => { process.env.npm_config_filter = filterCondition; return fn(); };
|
|
78
|
+
|
|
79
|
+
assert.strictEqual(setEnvAndCall(exports.filesToCompile, 'typed*ex*'), './generated/binding.cc test_helper.h ../test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc');
|
|
80
|
+
|
|
81
|
+
const expectedFilesToMatch = [
|
|
82
|
+
'./generated/binding.cc test_helper.h ',
|
|
83
|
+
'../test/threadsafe_function/threadsafe_function.cc',
|
|
84
|
+
'../test/threadsafe_function/threadsafe_function_ctx.cc',
|
|
85
|
+
'../test/threadsafe_function/threadsafe_function_existing_tsfn.cc',
|
|
86
|
+
'../test/threadsafe_function/threadsafe_function_ptr.cc',
|
|
87
|
+
'../test/threadsafe_function/threadsafe_function_sum.cc',
|
|
88
|
+
'../test/threadsafe_function/threadsafe_function_unref.cc',
|
|
89
|
+
'../test/typed_threadsafe_function/typed_threadsafe_function.cc',
|
|
90
|
+
'../test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc',
|
|
91
|
+
'../test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc',
|
|
92
|
+
'../test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc',
|
|
93
|
+
'../test/typed_threadsafe_function/typed_threadsafe_function_sum.cc',
|
|
94
|
+
'../test/typed_threadsafe_function/typed_threadsafe_function_unref.cc'
|
|
95
|
+
];
|
|
96
|
+
assert.strictEqual(setEnvAndCall(exports.filesToCompile, 'threadsafe_function typed_threadsafe_function'), expectedFilesToMatch.join(' '));
|
|
97
|
+
|
|
98
|
+
assert.strictEqual(setEnvAndCall(exports.filesToCompile, 'objectwrap'), './generated/binding.cc test_helper.h ../test/objectwrap.cc');
|
|
99
|
+
|
|
100
|
+
console.log('ALL tests passed');
|
|
101
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const exceptions = require('./exceptions');
|
|
4
|
+
|
|
5
|
+
const buildFiles = {};
|
|
6
|
+
const buidDirs = {};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param fileName - expect to be in snake case , eg: this_is_a_test_file.cc
|
|
10
|
+
* @returns init function name in the file
|
|
11
|
+
*
|
|
12
|
+
* general format of init function name is camelCase version of the snake_case file name
|
|
13
|
+
*/
|
|
14
|
+
function getExportObjectName (fileName) {
|
|
15
|
+
fileName = fileName.split('_').map(token => exceptions.nouns[token] ? exceptions.nouns[token] : token).join('_');
|
|
16
|
+
const str = fileName.replace(/(_\w)/g, (k) => k[1].toUpperCase());
|
|
17
|
+
const exportObjectName = str.charAt(0).toUpperCase() + str.substring(1);
|
|
18
|
+
if (exceptions.exportNames[exportObjectName]) {
|
|
19
|
+
return exceptions.exportNames[exportObjectName];
|
|
20
|
+
}
|
|
21
|
+
return exportObjectName;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param fileName - expect to be in snake case , eg: this_is_a_test_file.cc
|
|
26
|
+
* @returns property name of exported init function
|
|
27
|
+
*/
|
|
28
|
+
function getExportPropertyName (fileName) {
|
|
29
|
+
if (exceptions.propertyNames[fileName.toLowerCase()]) {
|
|
30
|
+
return exceptions.propertyNames[fileName.toLowerCase()];
|
|
31
|
+
}
|
|
32
|
+
return fileName;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* creates a configuration list for all available test modules
|
|
37
|
+
* The configuration object contains the expected init function names and corresponding export property names
|
|
38
|
+
*/
|
|
39
|
+
function listOfTestModules (currentDirectory = path.join(__dirname, '/../test'), pre = '') {
|
|
40
|
+
fs.readdirSync(currentDirectory).forEach((file) => {
|
|
41
|
+
if (file === 'binding.cc' ||
|
|
42
|
+
file === 'binding.gyp' ||
|
|
43
|
+
file === 'build' ||
|
|
44
|
+
file === 'common' ||
|
|
45
|
+
file === 'thunking_manual.cc' ||
|
|
46
|
+
file === 'addon_build' ||
|
|
47
|
+
file[0] === '.') {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const absoluteFilepath = path.join(currentDirectory, file);
|
|
51
|
+
const fileName = file.toLowerCase().replace('.cc', '');
|
|
52
|
+
if (fs.statSync(absoluteFilepath).isDirectory()) {
|
|
53
|
+
buidDirs[fileName] = [];
|
|
54
|
+
listOfTestModules(absoluteFilepath, pre + file + '/');
|
|
55
|
+
} else {
|
|
56
|
+
if (!file.toLowerCase().endsWith('.cc')) return;
|
|
57
|
+
if (currentDirectory.trim().split('/test/').length > 1) {
|
|
58
|
+
buidDirs[currentDirectory.split('/test/')[1].toLowerCase()].push(fileName);
|
|
59
|
+
}
|
|
60
|
+
const relativePath = (currentDirectory.split(`${fileName}.cc`)[0]).split('/test/')[1] || '';
|
|
61
|
+
buildFiles[fileName] = { dir: relativePath, propertyName: getExportPropertyName(fileName), objectName: getExportObjectName(fileName) };
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
listOfTestModules();
|
|
66
|
+
|
|
67
|
+
module.exports = {
|
|
68
|
+
dirs: buidDirs,
|
|
69
|
+
files: buildFiles
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Test cases
|
|
74
|
+
* @fires only when run directly from terminal
|
|
75
|
+
* eg: node listOfTestModules
|
|
76
|
+
*/
|
|
77
|
+
if (require.main === module) {
|
|
78
|
+
const assert = require('assert');
|
|
79
|
+
assert.strictEqual(getExportObjectName('objectwrap_constructor_exception'), 'ObjectWrapConstructorException');
|
|
80
|
+
assert.strictEqual(getExportObjectName('typed_threadsafe_function'), 'TypedThreadSafeFunction');
|
|
81
|
+
assert.strictEqual(getExportObjectName('objectwrap_removewrap'), 'ObjectWrapRemovewrap');
|
|
82
|
+
assert.strictEqual(getExportObjectName('function_reference'), 'FunctionReference');
|
|
83
|
+
assert.strictEqual(getExportObjectName('async_worker'), 'AsyncWorker');
|
|
84
|
+
assert.strictEqual(getExportObjectName('async_progress_worker'), 'AsyncProgressWorker');
|
|
85
|
+
assert.strictEqual(getExportObjectName('async_worker_persistent'), 'PersistentAsyncWorker');
|
|
86
|
+
|
|
87
|
+
console.log('ALL tests passed');
|
|
88
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const listOfTestModules = require('./listOfTestModules');
|
|
2
|
+
const buildDirs = listOfTestModules.dirs;
|
|
3
|
+
const buildFiles = listOfTestModules.files;
|
|
4
|
+
|
|
5
|
+
function isWildcard (filter) {
|
|
6
|
+
if (filter.includes('*')) return true;
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function filterBy (wildcard, item) {
|
|
11
|
+
return new RegExp('^' + wildcard.replace(/\*/g, '.*') + '$').test(item);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param filterCondition
|
|
16
|
+
* matches all given wildcards with available test modules to generate an elaborate filter condition
|
|
17
|
+
*/
|
|
18
|
+
function matchWildCards (filterCondition) {
|
|
19
|
+
const conditions = filterCondition.split(' ').length ? filterCondition.split(' ') : [filterCondition];
|
|
20
|
+
const matches = [];
|
|
21
|
+
|
|
22
|
+
for (const filter of conditions) {
|
|
23
|
+
if (isWildcard(filter)) {
|
|
24
|
+
const matchedDirs = Object.keys(buildDirs).filter(e => filterBy(filter, e));
|
|
25
|
+
if (matchedDirs.length) {
|
|
26
|
+
matches.push(matchedDirs.join(' '));
|
|
27
|
+
}
|
|
28
|
+
const matchedModules = Object.keys(buildFiles).filter(e => filterBy(filter, e));
|
|
29
|
+
if (matchedModules.length) { matches.push(matchedModules.join(' ')); }
|
|
30
|
+
} else {
|
|
31
|
+
matches.push(filter);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return matches.join(' ');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports.matchWildCards = matchWildCards;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Test cases
|
|
42
|
+
* @fires only when run directly from terminal
|
|
43
|
+
* eg: node matchModules
|
|
44
|
+
*/
|
|
45
|
+
if (require.main === module) {
|
|
46
|
+
const assert = require('assert');
|
|
47
|
+
|
|
48
|
+
assert.strictEqual(matchWildCards('typed*ex'), 'typed*ex');
|
|
49
|
+
assert.strictEqual(matchWildCards('typed*ex*'), 'typed_threadsafe_function_existing_tsfn');
|
|
50
|
+
assert.strictEqual(matchWildCards('async*'), 'async_context async_progress_queue_worker async_progress_worker async_worker async_worker_persistent');
|
|
51
|
+
assert.strictEqual(matchWildCards('typed*func'), 'typed*func');
|
|
52
|
+
assert.strictEqual(matchWildCards('typed*func*'), 'typed_threadsafe_function');
|
|
53
|
+
assert.strictEqual(matchWildCards('typed*function'), 'typed_threadsafe_function');
|
|
54
|
+
assert.strictEqual(matchWildCards('object*inh'), 'object*inh');
|
|
55
|
+
assert.strictEqual(matchWildCards('object*inh*'), 'objectwrap_multiple_inheritance');
|
|
56
|
+
assert.strictEqual(matchWildCards('*remove*'), 'objectwrap_removewrap');
|
|
57
|
+
assert.strictEqual(matchWildCards('*function'), 'threadsafe_function typed_threadsafe_function');
|
|
58
|
+
assert.strictEqual(matchWildCards('**function'), 'threadsafe_function typed_threadsafe_function');
|
|
59
|
+
assert.strictEqual(matchWildCards('a*w*p*'), 'async_worker_persistent');
|
|
60
|
+
assert.strictEqual(matchWildCards('fun*ref'), 'fun*ref');
|
|
61
|
+
assert.strictEqual(matchWildCards('fun*ref*'), 'function_reference');
|
|
62
|
+
assert.strictEqual(matchWildCards('*reference'), 'function_reference object_reference reference');
|
|
63
|
+
|
|
64
|
+
console.log('ALL tests passed');
|
|
65
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const { generateFileContent, writeToBindingFile } = require('./binding-file-template');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @summary setup script to execute before node-gyp begins target actions
|
|
6
|
+
*/
|
|
7
|
+
if (!fs.existsSync('./generated')) {
|
|
8
|
+
// create generated folder
|
|
9
|
+
fs.mkdirSync('./generated');
|
|
10
|
+
// create empty binding.cc file
|
|
11
|
+
generateFileContent([]).then(writeToBindingFile);
|
|
12
|
+
// FIX: Its necessary to have an empty bindng.cc file, otherwise build fails first time
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const { spawn } = require('child_process');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* spawns a child process to run a given node.js script
|
|
5
|
+
*/
|
|
6
|
+
module.exports.runChildProcess = function (scriptName, options) {
|
|
7
|
+
const childProcess = spawn('node', [scriptName], options);
|
|
8
|
+
|
|
9
|
+
childProcess.stdout.on('data', data => {
|
|
10
|
+
console.log(`${data}`);
|
|
11
|
+
});
|
|
12
|
+
childProcess.stderr.on('data', data => {
|
|
13
|
+
console.log(`error: ${data}`);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
childProcess.on('error', (error) => {
|
|
18
|
+
console.log(`error: ${error.message}`);
|
|
19
|
+
reject(error);
|
|
20
|
+
});
|
|
21
|
+
childProcess.on('close', code => {
|
|
22
|
+
console.log(`child process exited with code ${code}`);
|
|
23
|
+
resolve(code);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const runChildProcess = require('./spawnTask').runChildProcess;
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Execute tests with given filter conditions as a child process
|
|
7
|
+
*/
|
|
8
|
+
const executeTests = async function () {
|
|
9
|
+
try {
|
|
10
|
+
const workingDir = path.join(__dirname, '../');
|
|
11
|
+
const relativeBuildPath = path.join('../', 'unit-test');
|
|
12
|
+
const buildPath = path.join(__dirname, './unit-test');
|
|
13
|
+
const envVars = { ...process.env, REL_BUILD_PATH: relativeBuildPath, BUILD_PATH: buildPath };
|
|
14
|
+
|
|
15
|
+
console.log('Starting to run tests in ', buildPath, new Date());
|
|
16
|
+
|
|
17
|
+
const code = await runChildProcess('test', { cwd: workingDir, env: envVars });
|
|
18
|
+
|
|
19
|
+
if (code !== '0') {
|
|
20
|
+
process.exitCode = code;
|
|
21
|
+
process.exit(process.exitCode);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
console.log('Completed running tests', new Date());
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.log('Error occured running tests', new Date());
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
executeTests();
|