From b3a150e6aae8ad06b6351feadbdfd4b3009009ee Mon Sep 17 00:00:00 2001 From: Daniel Balla Date: Thu, 25 Apr 2019 12:55:53 +0200 Subject: [PATCH] Add debug build option to napi modules (#1862) IoT.js-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu --- src/iotjs_magic_strings.h | 3 +++ src/modules/iotjs_module_process.c | 17 +++++++++++++++++ test/napi/common.js | 3 +++ test/napi/test_napi_arguments_return.js | 4 +++- test/napi/test_napi_arguments_return_this.js | 4 +++- test/napi/test_napi_arguments_throw.js | 4 +++- test/napi/test_napi_array.js | 4 +++- test/napi/test_napi_async.js | 3 ++- test/napi/test_napi_buffer.js | 4 +++- test/napi/test_napi_construct.js | 4 +++- test/napi/test_napi_conversions.js | 4 +++- test/napi/test_napi_create_error.js | 4 +++- test/napi/test_napi_env.js | 7 +++++-- test/napi/test_napi_exception.js | 4 +++- test/napi/test_napi_general.js | 4 +++- test/napi/test_napi_general_es2015.js | 4 +++- test/napi/test_napi_handle_scope.js | 5 +++-- test/napi/test_napi_is_error.js | 4 +++- test/napi/test_napi_make_callback.js | 3 ++- test/napi/test_napi_make_callback_error.js | 3 ++- test/napi/test_napi_object_wrap.js | 4 +++- test/napi/test_napi_promise.js | 3 ++- test/napi/test_napi_properties.js | 4 +++- test/napi/test_napi_reference.js | 4 +++- .../test_napi_strictequal_and_instanceof.js | 4 +++- test/napi/test_napi_string.js | 4 +++- test/napi/test_napi_symbol.js | 4 +++- test/napi/test_napi_throw.js | 4 +++- test/napi/test_napi_throw_error.js | 4 +++- test/tools/iotjs_build_info.js | 3 ++- tools/testrunner.py | 9 ++++++--- 31 files changed, 107 insertions(+), 32 deletions(-) diff --git a/src/iotjs_magic_strings.h b/src/iotjs_magic_strings.h index 6079d0bc81..f77bb19a49 100644 --- a/src/iotjs_magic_strings.h +++ b/src/iotjs_magic_strings.h @@ -103,6 +103,9 @@ #if ENABLE_MODULE_UART #define IOTJS_MAGIC_STRING_DATABITS "dataBits" #endif +#ifdef DEBUG +#define IOTJS_MAGIC_STRING_DEBUG "debug" +#endif #define IOTJS_MAGIC_STRING_DEBUGGERGETSOURCE "debuggerGetSource" #define IOTJS_MAGIC_STRING_DEBUGGERWAITSOURCE "debuggerWaitSource" #if ENABLE_MODULE_WEBSOCKET diff --git a/src/modules/iotjs_module_process.c b/src/modules/iotjs_module_process.c index 42d80e41de..30e2970857 100644 --- a/src/modules/iotjs_module_process.c +++ b/src/modules/iotjs_module_process.c @@ -383,6 +383,23 @@ jerry_value_t InitProcess(void) { #ifdef EXPOSE_GC iotjs_jval_set_method(process, IOTJS_MAGIC_STRING_GC, Gc); #endif +#ifdef DEBUG + jerry_property_descriptor_t prop_desc; + jerry_init_property_descriptor_fields(&prop_desc); + + prop_desc.is_value_defined = true; + prop_desc.is_writable_defined = true; + prop_desc.is_configurable_defined = true; + prop_desc.value = jerry_create_boolean(true); + + jerry_value_t property_name = + jerry_create_string((jerry_char_t*)IOTJS_MAGIC_STRING_DEBUG); + jerry_value_t prop_ret_val = + jerry_define_own_property(process, property_name, &prop_desc); + jerry_release_value(prop_ret_val); + jerry_release_value(property_name); + jerry_free_property_descriptor_fields(&prop_desc); +#endif /* FIXME: Move this platform dependent code path to libtuv * * See the related commit in libuv: diff --git a/test/napi/common.js b/test/napi/common.js index aa21c6a265..d607adef1c 100644 --- a/test/napi/common.js +++ b/test/napi/common.js @@ -2,6 +2,8 @@ var assert = require('assert'); var mustCallChecks = []; +var buildTypePath = process.debug ? 'Debug' : 'Release'; + function mustCall(fn, criteria) { if (typeof fn === 'number') { criteria = fn; @@ -62,6 +64,7 @@ function expectsError(fn, exact) { module.exports = { mustCall: mustCall, expectsError: expectsError, + buildTypePath: buildTypePath, // don't use port in a parallelized test PORT: process.env.NODE_COMMON_PORT || 12306 }; diff --git a/test/napi/test_napi_arguments_return.js b/test/napi/test_napi_arguments_return.js index 6fb59e0ad8..166412045e 100644 --- a/test/napi/test_napi_arguments_return.js +++ b/test/napi/test_napi_arguments_return.js @@ -1,6 +1,8 @@ 'use strict'; var assert = require('assert'); -var test = require('./build/Release/test_napi_arguments.node'); +var common = require('common.js'); +var test = require('./build/' + common.buildTypePath + + '/test_napi_arguments.node'); var obj = {}; diff --git a/test/napi/test_napi_arguments_return_this.js b/test/napi/test_napi_arguments_return_this.js index 2550fcc4d9..1fc826e28d 100644 --- a/test/napi/test_napi_arguments_return_this.js +++ b/test/napi/test_napi_arguments_return_this.js @@ -1,6 +1,8 @@ 'use strict'; var assert = require('assert'); -var test = require('./build/Release/test_napi_arguments.node'); +var common = require('common.js'); +var test = require('./build/' + common.buildTypePath + + '/test_napi_arguments.node'); var obj = {}; diff --git a/test/napi/test_napi_arguments_throw.js b/test/napi/test_napi_arguments_throw.js index 6da94f4925..29259ba9df 100644 --- a/test/napi/test_napi_arguments_throw.js +++ b/test/napi/test_napi_arguments_throw.js @@ -1,6 +1,8 @@ 'use strict'; var assert = require('assert'); -var test = require('./build/Release/test_napi_arguments.node'); +var common = require('common.js'); +var test = require('./build/' + common.buildTypePath + + '/test_napi_arguments.node'); try { test.Throw(new Error('foo')); diff --git a/test/napi/test_napi_array.js b/test/napi/test_napi_array.js index 40d5c9893d..37eb74d97c 100644 --- a/test/napi/test_napi_array.js +++ b/test/napi/test_napi_array.js @@ -1,8 +1,10 @@ 'use strict'; var assert = require('assert'); +var common = require('common.js'); // Testing api calls for arrays -var test_array = require('./build/Release/test_napi_array.node'); +var test_array = require('./build/' + common.buildTypePath + + '/test_napi_array.node'); var array = [ 1, diff --git a/test/napi/test_napi_async.js b/test/napi/test_napi_async.js index 79a88ac77e..fd88594261 100644 --- a/test/napi/test_napi_async.js +++ b/test/napi/test_napi_async.js @@ -2,7 +2,8 @@ var common = require('common.js'); var assert = require('assert'); -var test_async = require('./build/Release/test_napi_async.node'); +var test_async = require('./build/' + common.buildTypePath + + '/test_napi_async.node'); // Successful async execution and completion callback. test_async.Test(5, {}, common.mustCall(function(err, val) { diff --git a/test/napi/test_napi_buffer.js b/test/napi/test_napi_buffer.js index d23c49a49d..40d706a74b 100644 --- a/test/napi/test_napi_buffer.js +++ b/test/napi/test_napi_buffer.js @@ -1,7 +1,9 @@ 'use strict'; var global = process; -var binding = require('./build/Release/test_napi_buffer.node'); +var common = require('common.js'); +var binding = require('./build/' + common.buildTypePath + + '/test_napi_buffer.node'); var assert = require('assert'); assert.strictEqual(binding.newBuffer().toString(), binding.theText); diff --git a/test/napi/test_napi_construct.js b/test/napi/test_napi_construct.js index ac46d7887b..6c3e92bd43 100644 --- a/test/napi/test_napi_construct.js +++ b/test/napi/test_napi_construct.js @@ -1,6 +1,8 @@ 'use strict'; var assert = require('assert'); -var test = require('./build/Release/test_napi_construct.node'); +var common = require('common.js'); +var test = require('./build/' + common.buildTypePath + + '/test_napi_construct.node'); var val = test.Constructor(123); assert.strictEqual(val.value, 123); diff --git a/test/napi/test_napi_conversions.js b/test/napi/test_napi_conversions.js index c22f956218..a73d96c834 100644 --- a/test/napi/test_napi_conversions.js +++ b/test/napi/test_napi_conversions.js @@ -1,6 +1,8 @@ 'use strict'; var assert = require('assert'); -var test = require('./build/Release/test_napi_conversions.node'); +var common = require('common.js'); +var test = require('./build/' + common.buildTypePath + + '/test_napi_conversions.node'); assert.strictEqual(false, test.asBool(false)); assert.strictEqual(true, test.asBool(true)); diff --git a/test/napi/test_napi_create_error.js b/test/napi/test_napi_create_error.js index 2c0233839e..1a38b7b914 100644 --- a/test/napi/test_napi_create_error.js +++ b/test/napi/test_napi_create_error.js @@ -1,4 +1,6 @@ -var addon = require('./build/Release/test_napi_error_handling'); +var common = require('common.js'); +var addon = require('./build/' + common.buildTypePath + + '/test_napi_error_handling'); var assert = require('assert'); var ERROR_CODE = "ErrorCode"; diff --git a/test/napi/test_napi_env.js b/test/napi/test_napi_env.js index b057842ff4..bb80b45c49 100644 --- a/test/napi/test_napi_env.js +++ b/test/napi/test_napi_env.js @@ -1,7 +1,10 @@ 'use strict'; -var storeEnv = require('./build/Release/test_napi_env_store.node'); -var compareEnv = require('./build/Release/test_napi_env_compare.node'); +var common = require('common.js'); +var storeEnv = require('./build/' + common.buildTypePath + + '/test_napi_env_store.node'); +var compareEnv = require('./build/' + common.buildTypePath + + '/test_napi_env_compare.node'); var assert = require('assert'); // N-API environment pointers in two different modules must be different diff --git a/test/napi/test_napi_exception.js b/test/napi/test_napi_exception.js index 5edec9530e..270cbdd3a6 100644 --- a/test/napi/test_napi_exception.js +++ b/test/napi/test_napi_exception.js @@ -1,4 +1,6 @@ -var addon = require('./build/Release/test_napi_error_handling'); +var common = require('common.js'); +var addon = require('./build/' + common.buildTypePath + + '/test_napi_error_handling'); var assert = require('assert'); var ERROR_MSG = "ErrorMSG"; diff --git a/test/napi/test_napi_general.js b/test/napi/test_napi_general.js index 5b7716d514..67e402d57e 100644 --- a/test/napi/test_napi_general.js +++ b/test/napi/test_napi_general.js @@ -15,8 +15,10 @@ 'use strict'; var assert = require('assert'); +var common = require('common.js'); -var test_general = require('./build/Release/test_napi_general.node'); +var test_general = require('./build/' + common.buildTypePath + + '/test_napi_general.node'); assert.strictEqual(test_general.GetUndefined(), undefined); assert.strictEqual(test_general.GetNull(), null); diff --git a/test/napi/test_napi_general_es2015.js b/test/napi/test_napi_general_es2015.js index 0d3c442c2f..338f6a5ec9 100644 --- a/test/napi/test_napi_general_es2015.js +++ b/test/napi/test_napi_general_es2015.js @@ -16,7 +16,9 @@ 'use strict'; var assert = require('assert'); -var test_general = require('./build/Release/test_napi_general.node'); +var common = require('common.js'); +var test_general = require('./build/' + common.buildTypePath + + '/test_napi_general.node'); assert.strictEqual(test_general.GetUndefined(), undefined); assert.strictEqual(test_general.GetNull(), null); diff --git a/test/napi/test_napi_handle_scope.js b/test/napi/test_napi_handle_scope.js index 3c826c778a..59be7c9f24 100644 --- a/test/napi/test_napi_handle_scope.js +++ b/test/napi/test_napi_handle_scope.js @@ -1,6 +1,7 @@ - +var common = require('common.js'); var assert = require('assert'); -var testHandleScope = require('./build/Release/test_napi_handle_scope.node'); +var testHandleScope = require('./build/' + common.buildTypePath + + '/test_napi_handle_scope.node'); testHandleScope.NewScope(); diff --git a/test/napi/test_napi_is_error.js b/test/napi/test_napi_is_error.js index 5e041396ea..5328f06223 100644 --- a/test/napi/test_napi_is_error.js +++ b/test/napi/test_napi_is_error.js @@ -1,4 +1,6 @@ -var addon = require('./build/Release/test_napi_error_handling'); +var common = require('common.js'); +var addon = require('./build/' + common.buildTypePath + + '/test_napi_error_handling'); var assert = require('assert'); var err = new Error("ErrorMSG"); diff --git a/test/napi/test_napi_make_callback.js b/test/napi/test_napi_make_callback.js index 81aff3398f..f16354c726 100644 --- a/test/napi/test_napi_make_callback.js +++ b/test/napi/test_napi_make_callback.js @@ -2,7 +2,8 @@ var common = require('common.js'); var assert = require('assert'); -var binding = require('./build/Release/test_napi_make_callback.node'); +var binding = require('./build/' + common.buildTypePath + + '/test_napi_make_callback.node'); var makeCallback = binding.makeCallback; function myMultiArgFunc(arg1, arg2, arg3) { diff --git a/test/napi/test_napi_make_callback_error.js b/test/napi/test_napi_make_callback_error.js index 07c86240a6..204c242e35 100644 --- a/test/napi/test_napi_make_callback_error.js +++ b/test/napi/test_napi_make_callback_error.js @@ -2,7 +2,8 @@ var common = require('common.js'); var assert = require('assert'); -var binding = require('./build/Release/test_napi_make_callback.node'); +var binding = require('./build/' + common.buildTypePath + + '/test_napi_make_callback.node'); var makeCallback = binding.makeCallback; var first = true; diff --git a/test/napi/test_napi_object_wrap.js b/test/napi/test_napi_object_wrap.js index 44db1c4dd0..55ba6d61f7 100644 --- a/test/napi/test_napi_object_wrap.js +++ b/test/napi/test_napi_object_wrap.js @@ -1,7 +1,9 @@ 'use strict'; var assert = require('assert'); -var test = require('./build/Release/test_napi_object_wrap.node'); +var common = require('common.js'); +var test = require('./build/' + common.buildTypePath + + '/test_napi_object_wrap.node'); function context() { var obj = {}; diff --git a/test/napi/test_napi_promise.js b/test/napi/test_napi_promise.js index 81879ab604..331a3a31c1 100644 --- a/test/napi/test_napi_promise.js +++ b/test/napi/test_napi_promise.js @@ -5,7 +5,8 @@ var common = require('common.js'); // This tests the promise-related n-api calls var assert = require('assert'); -var test_promise = require('./build/Release/test_napi_promise.node'); +var test_promise = require('./build/' + common.buildTypePath + + '/test_napi_promise.node'); // A resolution { diff --git a/test/napi/test_napi_properties.js b/test/napi/test_napi_properties.js index 3a8c6b93be..afa97a9066 100644 --- a/test/napi/test_napi_properties.js +++ b/test/napi/test_napi_properties.js @@ -14,8 +14,10 @@ */ var assert = require('assert'); +var common = require('common.js'); -var prop_module = require('./build/Release/test_napi_properties.node'); +var prop_module = require('./build/' + common.buildTypePath + + '/test_napi_properties.node'); var obj = { array: [ diff --git a/test/napi/test_napi_reference.js b/test/napi/test_napi_reference.js index 5639294b6c..4ee305a3d4 100644 --- a/test/napi/test_napi_reference.js +++ b/test/napi/test_napi_reference.js @@ -2,8 +2,10 @@ // Flags: --expose-gc var assert = require('assert'); +var common = require('common.js'); -var test_reference = require('./build/Release/test_napi_reference.node'); +var test_reference = require('./build/' + common.buildTypePath + + '/test_napi_reference.node'); // This test script uses external values with finalizer callbacks // in order to track when values get garbage-collected. Each invocation diff --git a/test/napi/test_napi_strictequal_and_instanceof.js b/test/napi/test_napi_strictequal_and_instanceof.js index 1babaf153e..c7634b442c 100644 --- a/test/napi/test_napi_strictequal_and_instanceof.js +++ b/test/napi/test_napi_strictequal_and_instanceof.js @@ -1,7 +1,9 @@ 'use strict'; var assert = require('assert'); +var common = require('common.js'); var napi_test = - require('./build/Release/test_napi_strictequal_and_instanceof.node'); + require('./build/' + common.buildTypePath + + '/test_napi_strictequal_and_instanceof.node'); assert(napi_test !== null); assert.strictEqual(typeof napi_test, 'object'); diff --git a/test/napi/test_napi_string.js b/test/napi/test_napi_string.js index a68b799c52..a85294b593 100644 --- a/test/napi/test_napi_string.js +++ b/test/napi/test_napi_string.js @@ -1,6 +1,8 @@ 'use strict'; var assert = require('assert'); -var test = require('./build/Release/test_napi_string.node'); +var common = require('common.js'); +var test = require('./build/' + common.buildTypePath + + '/test_napi_string.node'); var empty = ''; assert.strictEqual(test.TestUtf8(empty), empty); diff --git a/test/napi/test_napi_symbol.js b/test/napi/test_napi_symbol.js index 3125fd90cc..4cbf7c4abd 100644 --- a/test/napi/test_napi_symbol.js +++ b/test/napi/test_napi_symbol.js @@ -1,8 +1,10 @@ 'use strict'; var assert = require('assert'); +var common = require('common.js'); // testing api calls for symbol -var test_symbol = require('./build/Release/test_napi_symbol.node'); +var test_symbol = require('./build/' + common.buildTypePath + + '/test_napi_symbol.node'); var sym = test_symbol.CreateSymbol('test'); assert.strictEqual(sym.toString(), 'Symbol(test)'); diff --git a/test/napi/test_napi_throw.js b/test/napi/test_napi_throw.js index 7abac4de64..35d9a13bb6 100644 --- a/test/napi/test_napi_throw.js +++ b/test/napi/test_napi_throw.js @@ -1,4 +1,6 @@ -var addon = require('./build/Release/test_napi_error_handling'); +var common = require('common.js'); +var addon = require('./build/' + common.buildTypePath + + '/test_napi_error_handling'); var assert = require('assert'); var ERROR_MSG = "ErrorMSG"; diff --git a/test/napi/test_napi_throw_error.js b/test/napi/test_napi_throw_error.js index a91f50f0dd..0abc00d463 100644 --- a/test/napi/test_napi_throw_error.js +++ b/test/napi/test_napi_throw_error.js @@ -1,4 +1,6 @@ -var addon = require('./build/Release/test_napi_error_handling'); +var common = require('common.js'); +var addon = require('./build/' + common.buildTypePath + + '/test_napi_error_handling'); var assert = require('assert'); var error; diff --git a/test/tools/iotjs_build_info.js b/test/tools/iotjs_build_info.js index efd8eef9d7..48338831e5 100644 --- a/test/tools/iotjs_build_info.js +++ b/test/tools/iotjs_build_info.js @@ -73,7 +73,8 @@ if (hasArrowFunction()) result = { 'builtins': builtins, 'features': features, - 'stability': stability + 'stability': stability, + 'debug': !!process.debug } console.log(JSON.stringify(result)) diff --git a/tools/testrunner.py b/tools/testrunner.py index fd8ecaa6b3..3d32e2c077 100755 --- a/tools/testrunner.py +++ b/tools/testrunner.py @@ -165,8 +165,9 @@ def __init__(self, options): self.builtins = set(build_info["builtins"]) self.features = set(build_info["features"]) self.stability = build_info["stability"] + self.debug = build_info["debug"] if options.n_api: - build_napi_test_module() + build_napi_test_module(self.debug) def run(self): Reporter.report_configuration(self) @@ -313,7 +314,7 @@ def skip_test(self, test): return False -def build_napi_test_module(): +def build_napi_test_module(is_debug): node_gyp = fs.join(path.PROJECT_ROOT, 'node_modules', '.bin', @@ -322,7 +323,9 @@ def build_napi_test_module(): print('==> Build N-API test module with node-gyp\n') project_root = fs.join(path.PROJECT_ROOT, 'test', 'napi') - Executor.check_run_cmd(node_gyp, ['configure', 'rebuild'], cwd=project_root) + debug_cmd = '--debug' if is_debug else '--release' + Executor.check_run_cmd(node_gyp, ['configure', debug_cmd ,'rebuild'], + cwd=project_root) def get_args():