From 5cbfc3476c21665b412449e9e5f9be26199e40e2 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Tue, 19 Oct 2021 17:14:55 +0800 Subject: [PATCH 1/5] Signed-off-by: lifansheng On branch master Your branch is up to date with 'origin/master'. --- convertxml/build_ts_js.py | 21 +++++++++++++++++---- convertxml/src/js_convertxml.ts | 4 ++-- uri/build_ts_js.py | 27 +++++++++++++++++++++------ uri/src/js_uri.ts | 2 +- url/build_ts_js.py | 22 ++++++++++++++++++---- 5 files changed, 59 insertions(+), 17 deletions(-) diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py index a5bad68b..4c4993e0 100755 --- a/convertxml/build_ts_js.py +++ b/convertxml/build_ts_js.py @@ -15,6 +15,12 @@ import os import platform import argparse +import subprocess + +def run_command(cmd): + print(" ".join(cmd)) + proc = subprocess.Popen(cmd) + proc.wait() if __name__ == '__main__': @@ -26,7 +32,14 @@ if __name__ == '__main__': help='the converted target file') input_arguments = parser.parse_args() - os.system('../../../../prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64/bin/node ' - '../../../../ark/ts2abc/ts2panda/node_modules/typescript/bin/tsc') - os.system('cp -r ./out/js_convertxml.js ' + input_arguments.dst_file) - os.system('rm -rf ./out') \ No newline at end of file + node = '../../../../prebuilts/build-tools/common/nodejs/\ +node-v12.18.4-linux-x64/bin/node' + tsc = '../../../../ark/ts2abc/ts2panda/node_modules/typescript/bin/tsc' + cmd = [node, tsc] + run_command(cmd) + + cmd = ['cp', "-r", './out/js_convertxml.js', input_arguments.dst_file] + run_command(cmd) + + cmd = ['rm', "-rf", './out'] + run_command(cmd) \ No newline at end of file diff --git a/convertxml/src/js_convertxml.ts b/convertxml/src/js_convertxml.ts index 3e9b4c03..33dadea6 100644 --- a/convertxml/src/js_convertxml.ts +++ b/convertxml/src/js_convertxml.ts @@ -16,7 +16,7 @@ declare function requireInternal(s : string) : any; const convertXml = requireInternal("ConvertXML"); class ConvertXml { - convertxmlclass; + convertxmlclass : any; constructor() { this.convertxmlclass = new convertXml.ConvertXml(); } @@ -107,7 +107,7 @@ function DealPriorReplace(strXml : string, idx : any, idxThir : any) return strXml; } -function DealLaterReplace(strXml, idx, idxThir) +function DealLaterReplace(strXml : string, idx : any, idxThir : any) { var i = idx + 1; for (; i < idxThir ; i++) { diff --git a/uri/build_ts_js.py b/uri/build_ts_js.py index 6aec6835..f4484ff7 100755 --- a/uri/build_ts_js.py +++ b/uri/build_ts_js.py @@ -12,21 +12,36 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +# + import os import platform import argparse +import subprocess + +def run_command(cmd): + print(" ".join(cmd)) + proc = subprocess.Popen(cmd) + proc.wait() if __name__ == '__main__': build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) os.chdir("%s/base/compileruntime/js_api_module/uri" % build_path) - + parser = argparse.ArgumentParser() parser.add_argument('--dst-file', help='the converted target file') input_arguments = parser.parse_args() - - os.system('../../../../prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64/bin/node ' - '../../../../ark/ts2abc/ts2panda/node_modules/typescript/bin/tsc') - os.system('cp -r ./out/js_uri.js ' + input_arguments.dst_file) - os.system('rm -rf ./out') \ No newline at end of file + + node = '../../../../prebuilts/build-tools/common/nodejs/\ +node-v12.18.4-linux-x64/bin/node' + tsc = '../../../../ark/ts2abc/ts2panda/node_modules/typescript/bin/tsc' + cmd = [node, tsc] + run_command(cmd) + + cmd = ['cp', "-r", './out/js_uri.js', input_arguments.dst_file] + run_command(cmd) + + cmd = ['rm', "-rf", './out'] + run_command(cmd) \ No newline at end of file diff --git a/uri/src/js_uri.ts b/uri/src/js_uri.ts index a8ce10e8..2e53e1dd 100644 --- a/uri/src/js_uri.ts +++ b/uri/src/js_uri.ts @@ -96,7 +96,7 @@ function toAscllString(uriStr:any) { } } -function createNewUri(uriStr) { +function createNewUri(uriStr:string) { return new URI(uriStr); } diff --git a/url/build_ts_js.py b/url/build_ts_js.py index 5edfb67a..79591be1 100755 --- a/url/build_ts_js.py +++ b/url/build_ts_js.py @@ -12,9 +12,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import os import platform import argparse +import subprocess + +def run_command(cmd): + print(" ".join(cmd)) + proc = subprocess.Popen(cmd) + proc.wait() if __name__ == '__main__': @@ -26,7 +33,14 @@ if __name__ == '__main__': help='the converted target file') input_arguments = parser.parse_args() - os.system('../../../../prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64/bin/node ' - '../../../../ark/ts2abc/ts2panda/node_modules/typescript/bin/tsc') - os.system('cp -r ./out/js_url.js ' + input_arguments.dst_file) - os.system('rm -rf ./out') \ No newline at end of file + node = '../../../../prebuilts/build-tools/common/nodejs/\ +node-v12.18.4-linux-x64/bin/node' + tsc = '../../../../ark/ts2abc/ts2panda/node_modules/typescript/bin/tsc' + cmd = [node, tsc] + run_command(cmd) + + cmd = ['cp', "-r", './out/js_url.js', input_arguments.dst_file] + run_command(cmd) + + cmd = ['rm', "-rf", './out'] + run_command(cmd) \ No newline at end of file -- Gitee From 0d96a72f0dd56caaea85a5f00e9a3e8edf22da20 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Tue, 26 Oct 2021 17:56:14 +0800 Subject: [PATCH 2/5] Signed-off-by: lifansheng On branch master Your branch is up to date with 'origin/master'. --- convertxml/build_ts_js.py | 11 ++++++++--- uri/build_ts_js.py | 8 ++++++-- uri/src/js_uri.ts | 2 +- url/build_ts_js.py | 8 ++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py index 4c4993e0..e3c8247f 100755 --- a/convertxml/build_ts_js.py +++ b/convertxml/build_ts_js.py @@ -19,8 +19,12 @@ import subprocess def run_command(cmd): print(" ".join(cmd)) - proc = subprocess.Popen(cmd) - proc.wait() + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, universal_newlines=True) + out, err = proc.communicate() + if out != "": + print(out) + exit(1) if __name__ == '__main__': @@ -42,4 +46,5 @@ node-v12.18.4-linux-x64/bin/node' run_command(cmd) cmd = ['rm', "-rf", './out'] - run_command(cmd) \ No newline at end of file + run_command(cmd) + exit(0) \ No newline at end of file diff --git a/uri/build_ts_js.py b/uri/build_ts_js.py index f4484ff7..597e66c5 100755 --- a/uri/build_ts_js.py +++ b/uri/build_ts_js.py @@ -21,8 +21,12 @@ import subprocess def run_command(cmd): print(" ".join(cmd)) - proc = subprocess.Popen(cmd) - proc.wait() + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, universal_newlines=True) + out, err = proc.communicate() + if out != "": + print(out) + exit(1) if __name__ == '__main__': diff --git a/uri/src/js_uri.ts b/uri/src/js_uri.ts index 2e53e1dd..d5a1c0d9 100644 --- a/uri/src/js_uri.ts +++ b/uri/src/js_uri.ts @@ -96,7 +96,7 @@ function toAscllString(uriStr:any) { } } -function createNewUri(uriStr:string) { +function createNewUri(uriStr : string) { return new URI(uriStr); } diff --git a/url/build_ts_js.py b/url/build_ts_js.py index 79591be1..826c0812 100755 --- a/url/build_ts_js.py +++ b/url/build_ts_js.py @@ -20,8 +20,12 @@ import subprocess def run_command(cmd): print(" ".join(cmd)) - proc = subprocess.Popen(cmd) - proc.wait() + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, universal_newlines=True) + out, err = proc.communicate() + if out != "": + print(out) + exit(1) if __name__ == '__main__': -- Gitee From 33c5c39d13f062a56bcee4c14f96d9b94000f3c2 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Thu, 28 Oct 2021 16:50:15 +0800 Subject: [PATCH 3/5] Signed-off-by: lifansheng On branch master Your branch is up to date with 'origin/master'. --- test_uri/unittest/BUILD.gn | 180 +++++++++++++++++++------ test_uri/unittest/test_ark.cpp | 62 +++++++++ test_uri/unittest/test_jerryscript.cpp | 43 ++++++ test_uri/unittest/test_v8.cpp | 89 ++++++++++++ 4 files changed, 331 insertions(+), 43 deletions(-) create mode 100644 test_uri/unittest/test_ark.cpp create mode 100644 test_uri/unittest/test_jerryscript.cpp create mode 100644 test_uri/unittest/test_v8.cpp diff --git a/test_uri/unittest/BUILD.gn b/test_uri/unittest/BUILD.gn index 51f6637c..3f01a2fb 100755 --- a/test_uri/unittest/BUILD.gn +++ b/test_uri/unittest/BUILD.gn @@ -11,53 +11,147 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/test.gni") +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") + import("//build/lite/config/subsystem/aafwk/config.gni") + import("//build/lite/config/test.gni") -if (is_standard_system) { - module_output_path = "jsapi_api/napi" -} + test_output_root = "$root_out_dir/test/unittest/jsfwk" + + executable("test_jerryscript_uri_unittest") { + output_extension = "bin" + output_dir = test_output_root + + include_dirs = [ + "//base/compileruntime/js_api_module/uri", + "//utils/native/base/include", + "//third_party/node/src", + "//foundation/ace/napi", + "//foundation/ace/napi/interfaces/kits", + "//third_party/googletest/include", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/native_engine/impl/jerryscript", + ] + + cflags = [ "-g3" ] -ohos_unittest("test_uri_unittest") { - module_out_path = module_output_path - - include_dirs = [ - "//base/compileruntime/js_api_module/uri", - "//foundation/ace/napi", - "//foundation/ace/napi/interfaces/kits", - "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/native_engine/impl/quickjs", - "//third_party/icu/icu4c/source/common", - "//third_party/googletest/include", - "//third_party/node/src", - "//utils/native/base/include", - ] - - cflags = [ "-g3" ] - - sources = [ - "test_napi.cpp", - "test_quickjs.cpp", - ] - - deps = [ - "//base/compileruntime/js_api_module/uri:uri_packages", - "//foundation/ace/napi/:ace_napi", - "//foundation/ace/napi/:ace_napi_quickjs", - "//third_party/googletest:gtest", - "//third_party/googletest:gtest_main", - "//third_party/icu/icu4c:static_icuuc", - "//third_party/libuv:uv_static", - "//third_party/quickjs:qjs", - "//utils/native/base:utils", - "//utils/native/base:utilsecurec", - ] + sources = [ + "test_jerryscript.cpp", + "test_napi.cpp", + ] + + deps = [ + "//base//hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//base/compileruntime/js_api_module/uri:uri_packages", + "//foundation/ace/napi/:ace_napi", + "//foundation/ace/napi/:ace_napi_jerryscript", + "//test/developertest/third_party/lib/cpp:gtest_main", + "//third_party/icu/icu4c:static_icuuc", + "//third_party/jerryscript/jerry-core:jerry-core_shared", + "//third_party/jerryscript/jerry-ext:jerry-ext_shared", + "//third_party/jerryscript/jerry-port/default:jerry-port-default_shared", + "//utils/native/base:utilsecurec", + ] + } + + group("unittest") { + deps = [ ":test_jerryscript_uri_unittest" ] + } +} else { + import("//build/test.gni") if (is_standard_system) { - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + module_output_path = "jsapi_api/napi" } -} -group("unittest") { - testonly = true - deps = [ ":test_uri_unittest" ] + ohos_unittest("test_quickjs_uri_unittest") { + module_out_path = module_output_path + + include_dirs = [ + "//base/compileruntime/js_api_module/uri", + "//foundation/ace/napi", + "//foundation/ace/napi/interfaces/kits", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/native_engine/impl/quickjs", + "//third_party/googletest/include", + "//third_party/node/src", + "//utils/native/base/include", + ] + + cflags = [ "-g3" ] + + sources = [ + "test_napi.cpp", + "test_quickjs.cpp", + ] + + deps = [ + "//base/compileruntime/js_api_module/uri:uri_packages", + "//foundation/ace/napi/:ace_napi", + "//foundation/ace/napi/:ace_napi_quickjs", + "//third_party/googletest:gtest", + "//third_party/googletest:gtest_main", + "//third_party/icu/icu4c:static_icuuc", + "//third_party/libuv:uv_static", + "//third_party/quickjs:qjs", + "//utils/native/base:utils", + "//utils/native/base:utilsecurec", + ] + + if (is_standard_system) { + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + } + } + + ohos_unittest("test_ark_uri_unittest") { + module_out_path = module_output_path + + configs = [ "//ark/js_runtime:ark_jsruntime_public_config" ] + + include_dirs = [ + "//base/compileruntime/js_api_module/uri", + "//ark/js_runtime", + "//foundation/ace/napi", + "//foundation/ace/napi/interfaces/kits", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/native_engine/impl/ark", + "//third_party/googletest/include", + "//third_party/node/src", + "//utils/native/base/include", + ] + + cflags = [ "-g3" ] + + sources = [ + "test_ark.cpp", + "test_napi.cpp", + ] + + deps = [ + "//ark/js_runtime:libark_jsruntime", + "//base/compileruntime/js_api_module/uri:uri_packages", + "//foundation/ace/napi/:ace_napi", + "//foundation/ace/napi/:ace_napi_ark", + "//third_party/googletest:gtest", + "//third_party/googletest:gtest_main", + "//third_party/icu/icu4c:static_icuuc", + "//third_party/libuv:uv_static", + "//utils/native/base:utils", + "//utils/native/base:utilsecurec", + ] + + if (is_standard_system) { + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + } else { + external_deps = [ "hilog:libhilog" ] + } + } + + group("unittest") { + testonly = true + deps = [ + ":test_ark_uri_unittest", + # ":test_quickjs_uri_unittest", + ] + } } diff --git a/test_uri/unittest/test_ark.cpp b/test_uri/unittest/test_ark.cpp new file mode 100644 index 00000000..3c6039ec --- /dev/null +++ b/test_uri/unittest/test_ark.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test.h" + +#include "utils/log.h" +#include "ark_native_engine.h" + +using panda::RuntimeOption; +static NativeEngine *g_nativeEngine = nullptr; + +NativeEngineTest::NativeEngineTest() +{ + engine_ = g_nativeEngine; +} + +NativeEngineTest::~NativeEngineTest() {} + +int main(int argc, char **argv) +{ + testing::GTEST_FLAG(output) = "xml:./"; + testing::InitGoogleTest(&argc, argv); + + // Setup + RuntimeOption option; + option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC); + // const int64_t poolSize = 0x10000000; // 256M + const int64_t poolSize = 0x1000000; // 16M + option.SetGcPoolSize(poolSize); + //option.SetPandaStdFile("pandastdlib/arkstdlib.abc"); + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + option.SetDebuggerLibraryPath(""); + EcmaVM *vm = panda::JSNApi::CreateJSVM(option); + if (vm == nullptr) { + return 0; + } + + g_nativeEngine = new ArkNativeEngine(vm, nullptr); + + int ret = testing::UnitTest::GetInstance()->Run(); + + g_nativeEngine->Loop(LOOP_NOWAIT); + + delete g_nativeEngine; + g_nativeEngine = nullptr; + panda::JSNApi::DestoryJSVM(vm); + vm = nullptr; + + return ret; +} diff --git a/test_uri/unittest/test_jerryscript.cpp b/test_uri/unittest/test_jerryscript.cpp new file mode 100644 index 00000000..9f75b62e --- /dev/null +++ b/test_uri/unittest/test_jerryscript.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test.h" + +#include "jerryscript_native_engine.h" + +static NativeEngine *g_nativeEngine = nullptr; + +NativeEngineTest::NativeEngineTest() +{ + engine_ = g_nativeEngine; +} + +NativeEngineTest::~NativeEngineTest() {} + +int main(int argc, char **argv) +{ + testing::GTEST_FLAG(output) = "xml:./"; + testing::InitGoogleTest(&argc, argv); + + jerry_init(jerry_init_flag_t::JERRY_INIT_EMPTY); + g_nativeEngine = new JerryScriptNativeEngine(0); // default instance id 0 + int ret = RUN_ALL_TESTS(); + g_nativeEngine->Loop(LoopMode::LOOP_DEFAULT); + delete g_nativeEngine; + g_nativeEngine = nullptr; + jerry_cleanup(); + + return ret; +} diff --git a/test_uri/unittest/test_v8.cpp b/test_uri/unittest/test_v8.cpp new file mode 100644 index 00000000..1b76fabd --- /dev/null +++ b/test_uri/unittest/test_v8.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test.h" + +#include "utils/log.h" +#include "v8_native_engine.h" + +static NativeEngine* g_nativeEngine = nullptr; + +NativeEngineTest::NativeEngineTest() +{ + engine_ = g_nativeEngine; +} + +NativeEngineTest::~NativeEngineTest() {} + +extern const char _binary_strip_native_min_js_bin_start[]; +extern const char _binary_strip_native_min_js_bin_end[]; + +int main(int argc, char** argv) +{ + int retCode = 0; + + testing::GTEST_FLAG(output) = "xml:./"; + testing::InitGoogleTest(&argc, argv); + + static v8::StartupData snapshotBlob = { + .data = _binary_strip_native_min_js_bin_start, + .raw_size = _binary_strip_native_min_js_bin_end - _binary_strip_native_min_js_bin_start, + }; + v8::V8::SetSnapshotDataBlob(&snapshotBlob); + + std::unique_ptr platform = v8::platform::NewDefaultPlatform(); + v8::V8::InitializePlatform(platform.get()); + if (!v8::V8::Initialize()) { + return retCode; + } + v8::Isolate::CreateParams createParams; + createParams.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); + + if (createParams.array_buffer_allocator == nullptr) { + return retCode; + } + + v8::Isolate* isolate = v8::Isolate::New(createParams); + { + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + v8::Local global = v8::ObjectTemplate::New(isolate); + v8::Local context = v8::Context::New(isolate, nullptr, global); + + v8::Persistent persistContext; + persistContext.Reset(isolate, context); + + if (context.IsEmpty()) { + return retCode; + } + + v8::Context::Scope contextScope(context); + { + g_nativeEngine = new V8NativeEngine(platform.get(), isolate, persistContext, 0); // default instance id 0 + + retCode = testing::UnitTest::GetInstance()->Run(); + + g_nativeEngine->Loop(LOOP_DEFAULT); + delete g_nativeEngine; + g_nativeEngine = nullptr; + } + } + isolate->Dispose(); + v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); + delete createParams.array_buffer_allocator; + + return retCode; +} -- Gitee From 9fe020c7ba2c625b54523f6d066896299ea26918 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Fri, 29 Oct 2021 10:49:09 +0800 Subject: [PATCH 4/5] Signed-off-by: lifansheng On branch master Your branch is up to date with 'origin/master'. --- test_uri/unittest/test_ark.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_uri/unittest/test_ark.cpp b/test_uri/unittest/test_ark.cpp index 3c6039ec..f7e90b87 100644 --- a/test_uri/unittest/test_ark.cpp +++ b/test_uri/unittest/test_ark.cpp @@ -36,10 +36,10 @@ int main(int argc, char **argv) // Setup RuntimeOption option; option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC); - // const int64_t poolSize = 0x10000000; // 256M + const int64_t poolSize = 0x1000000; // 16M option.SetGcPoolSize(poolSize); - //option.SetPandaStdFile("pandastdlib/arkstdlib.abc"); + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); option.SetDebuggerLibraryPath(""); EcmaVM *vm = panda::JSNApi::CreateJSVM(option); -- Gitee From 0cc474874a051f8f15d24d27133beb826a306046 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Fri, 29 Oct 2021 16:49:23 +0800 Subject: [PATCH 5/5] Signed-off-by: lifansheng On branch master Your branch is up to date with 'origin/master'. --- test_uri/unittest/BUILD.gn | 185 +++++++------------------ test_uri/unittest/test_jerryscript.cpp | 43 ------ test_uri/unittest/test_quickjs.cpp | 60 -------- test_uri/unittest/test_v8.cpp | 89 ------------ 4 files changed, 47 insertions(+), 330 deletions(-) delete mode 100644 test_uri/unittest/test_jerryscript.cpp delete mode 100755 test_uri/unittest/test_quickjs.cpp delete mode 100644 test_uri/unittest/test_v8.cpp diff --git a/test_uri/unittest/BUILD.gn b/test_uri/unittest/BUILD.gn index 3f01a2fb..d214df25 100755 --- a/test_uri/unittest/BUILD.gn +++ b/test_uri/unittest/BUILD.gn @@ -10,148 +10,57 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import("//build/test.gni") -if (defined(ohos_lite)) { - import("//build/lite/config/component/lite_component.gni") - import("//build/lite/config/subsystem/aafwk/config.gni") - import("//build/lite/config/test.gni") - - test_output_root = "$root_out_dir/test/unittest/jsfwk" - - executable("test_jerryscript_uri_unittest") { - output_extension = "bin" - output_dir = test_output_root - - include_dirs = [ - "//base/compileruntime/js_api_module/uri", - "//utils/native/base/include", - "//third_party/node/src", - "//foundation/ace/napi", - "//foundation/ace/napi/interfaces/kits", - "//third_party/googletest/include", - "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/native_engine/impl/jerryscript", - ] - - cflags = [ "-g3" ] - - sources = [ - "test_jerryscript.cpp", - "test_napi.cpp", - ] - - deps = [ - "//base//hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//base/compileruntime/js_api_module/uri:uri_packages", - "//foundation/ace/napi/:ace_napi", - "//foundation/ace/napi/:ace_napi_jerryscript", - "//test/developertest/third_party/lib/cpp:gtest_main", - "//third_party/icu/icu4c:static_icuuc", - "//third_party/jerryscript/jerry-core:jerry-core_shared", - "//third_party/jerryscript/jerry-ext:jerry-ext_shared", - "//third_party/jerryscript/jerry-port/default:jerry-port-default_shared", - "//utils/native/base:utilsecurec", - ] - } +if (is_standard_system) { + module_output_path = "jsapi_api/napi" +} - group("unittest") { - deps = [ ":test_jerryscript_uri_unittest" ] - } -} else { - import("//build/test.gni") +ohos_unittest("test_uri_unittest") { + module_out_path = module_output_path + + configs = [ "//ark/js_runtime:ark_jsruntime_public_config" ] + + include_dirs = [ + "//base/compileruntime/js_api_module/uri", + "//ark/js_runtime", + "//foundation/ace/napi", + "//foundation/ace/napi/interfaces/kits", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/native_engine/impl/ark", + "//third_party/googletest/include", + "//third_party/node/src", + "//utils/native/base/include", + ] + + cflags = [ "-g3" ] + + sources = [ + "test_ark.cpp", + "test_napi.cpp", + ] + + deps = [ + "//ark/js_runtime:libark_jsruntime", + "//base/compileruntime/js_api_module/uri:uri_packages", + "//foundation/ace/napi/:ace_napi", + "//foundation/ace/napi/:ace_napi_ark", + "//third_party/googletest:gtest", + "//third_party/googletest:gtest_main", + "//third_party/icu/icu4c:static_icuuc", + "//third_party/libuv:uv_static", + "//utils/native/base:utils", + "//utils/native/base:utilsecurec", + ] if (is_standard_system) { - module_output_path = "jsapi_api/napi" - } - - ohos_unittest("test_quickjs_uri_unittest") { - module_out_path = module_output_path - - include_dirs = [ - "//base/compileruntime/js_api_module/uri", - "//foundation/ace/napi", - "//foundation/ace/napi/interfaces/kits", - "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/native_engine/impl/quickjs", - "//third_party/googletest/include", - "//third_party/node/src", - "//utils/native/base/include", - ] - - cflags = [ "-g3" ] - - sources = [ - "test_napi.cpp", - "test_quickjs.cpp", - ] - - deps = [ - "//base/compileruntime/js_api_module/uri:uri_packages", - "//foundation/ace/napi/:ace_napi", - "//foundation/ace/napi/:ace_napi_quickjs", - "//third_party/googletest:gtest", - "//third_party/googletest:gtest_main", - "//third_party/icu/icu4c:static_icuuc", - "//third_party/libuv:uv_static", - "//third_party/quickjs:qjs", - "//utils/native/base:utils", - "//utils/native/base:utilsecurec", - ] - - if (is_standard_system) { - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - } - } - - ohos_unittest("test_ark_uri_unittest") { - module_out_path = module_output_path - - configs = [ "//ark/js_runtime:ark_jsruntime_public_config" ] - - include_dirs = [ - "//base/compileruntime/js_api_module/uri", - "//ark/js_runtime", - "//foundation/ace/napi", - "//foundation/ace/napi/interfaces/kits", - "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/native_engine/impl/ark", - "//third_party/googletest/include", - "//third_party/node/src", - "//utils/native/base/include", - ] - - cflags = [ "-g3" ] - - sources = [ - "test_ark.cpp", - "test_napi.cpp", - ] - - deps = [ - "//ark/js_runtime:libark_jsruntime", - "//base/compileruntime/js_api_module/uri:uri_packages", - "//foundation/ace/napi/:ace_napi", - "//foundation/ace/napi/:ace_napi_ark", - "//third_party/googletest:gtest", - "//third_party/googletest:gtest_main", - "//third_party/icu/icu4c:static_icuuc", - "//third_party/libuv:uv_static", - "//utils/native/base:utils", - "//utils/native/base:utilsecurec", - ] - - if (is_standard_system) { - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - } else { - external_deps = [ "hilog:libhilog" ] - } + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + } else { + external_deps = [ "hilog:libhilog" ] } +} - group("unittest") { - testonly = true - deps = [ - ":test_ark_uri_unittest", - # ":test_quickjs_uri_unittest", - ] - } +group("unittest") { + testonly = true + deps = [ ":test_uri_unittest" ] } diff --git a/test_uri/unittest/test_jerryscript.cpp b/test_uri/unittest/test_jerryscript.cpp deleted file mode 100644 index 9f75b62e..00000000 --- a/test_uri/unittest/test_jerryscript.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test.h" - -#include "jerryscript_native_engine.h" - -static NativeEngine *g_nativeEngine = nullptr; - -NativeEngineTest::NativeEngineTest() -{ - engine_ = g_nativeEngine; -} - -NativeEngineTest::~NativeEngineTest() {} - -int main(int argc, char **argv) -{ - testing::GTEST_FLAG(output) = "xml:./"; - testing::InitGoogleTest(&argc, argv); - - jerry_init(jerry_init_flag_t::JERRY_INIT_EMPTY); - g_nativeEngine = new JerryScriptNativeEngine(0); // default instance id 0 - int ret = RUN_ALL_TESTS(); - g_nativeEngine->Loop(LoopMode::LOOP_DEFAULT); - delete g_nativeEngine; - g_nativeEngine = nullptr; - jerry_cleanup(); - - return ret; -} diff --git a/test_uri/unittest/test_quickjs.cpp b/test_uri/unittest/test_quickjs.cpp deleted file mode 100755 index b14aa3ce..00000000 --- a/test_uri/unittest/test_quickjs.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test.h" - -#include "quickjs_native_engine.h" - -static NativeEngine *g_nativeEngine = nullptr; - -NativeEngineTest::NativeEngineTest() -{ - engine_ = g_nativeEngine; -} - -NativeEngineTest::~NativeEngineTest() {} - -int main(int argc, char **argv) -{ - testing::GTEST_FLAG(output) = "xml:./"; - testing::InitGoogleTest(&argc, argv); - - JSRuntime *rt = JS_NewRuntime(); - if (rt == nullptr) { - return 0; - } - - JSContext *ctx = JS_NewContext(rt); - if (ctx == nullptr) { - return 0; - } - - js_std_add_helpers(ctx, 0, nullptr); - - g_nativeEngine = new QuickJSNativeEngine(rt, ctx, 0); // default instance id 0 - - int ret = RUN_ALL_TESTS(); - - g_nativeEngine->Loop(LOOP_DEFAULT); - - delete g_nativeEngine; - g_nativeEngine = nullptr; - - js_std_free_handlers(rt); - JS_FreeContext(ctx); - JS_FreeRuntime(rt); - - return ret; -} diff --git a/test_uri/unittest/test_v8.cpp b/test_uri/unittest/test_v8.cpp deleted file mode 100644 index 1b76fabd..00000000 --- a/test_uri/unittest/test_v8.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test.h" - -#include "utils/log.h" -#include "v8_native_engine.h" - -static NativeEngine* g_nativeEngine = nullptr; - -NativeEngineTest::NativeEngineTest() -{ - engine_ = g_nativeEngine; -} - -NativeEngineTest::~NativeEngineTest() {} - -extern const char _binary_strip_native_min_js_bin_start[]; -extern const char _binary_strip_native_min_js_bin_end[]; - -int main(int argc, char** argv) -{ - int retCode = 0; - - testing::GTEST_FLAG(output) = "xml:./"; - testing::InitGoogleTest(&argc, argv); - - static v8::StartupData snapshotBlob = { - .data = _binary_strip_native_min_js_bin_start, - .raw_size = _binary_strip_native_min_js_bin_end - _binary_strip_native_min_js_bin_start, - }; - v8::V8::SetSnapshotDataBlob(&snapshotBlob); - - std::unique_ptr platform = v8::platform::NewDefaultPlatform(); - v8::V8::InitializePlatform(platform.get()); - if (!v8::V8::Initialize()) { - return retCode; - } - v8::Isolate::CreateParams createParams; - createParams.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); - - if (createParams.array_buffer_allocator == nullptr) { - return retCode; - } - - v8::Isolate* isolate = v8::Isolate::New(createParams); - { - v8::Isolate::Scope isolateScope(isolate); - v8::HandleScope handleScope(isolate); - v8::Local global = v8::ObjectTemplate::New(isolate); - v8::Local context = v8::Context::New(isolate, nullptr, global); - - v8::Persistent persistContext; - persistContext.Reset(isolate, context); - - if (context.IsEmpty()) { - return retCode; - } - - v8::Context::Scope contextScope(context); - { - g_nativeEngine = new V8NativeEngine(platform.get(), isolate, persistContext, 0); // default instance id 0 - - retCode = testing::UnitTest::GetInstance()->Run(); - - g_nativeEngine->Loop(LOOP_DEFAULT); - delete g_nativeEngine; - g_nativeEngine = nullptr; - } - } - isolate->Dispose(); - v8::V8::Dispose(); - v8::V8::ShutdownPlatform(); - delete createParams.array_buffer_allocator; - - return retCode; -} -- Gitee