From 00e718c78da0cdb9329e76824081dedff710c5dc Mon Sep 17 00:00:00 2001 From: Wang Date: Thu, 11 Nov 2021 14:55:21 +0800 Subject: [PATCH] On branch master Your branch is up to date with 'origin/master'. Signed-off-by:lifansheng --- test/unittest/BUILD.gn | 15 ++++--- test/unittest/test.h | 2 +- .../{test_quickjs.cpp => test_ark.cpp} | 40 ++++++++++--------- 3 files changed, 32 insertions(+), 25 deletions(-) rename test/unittest/{test_quickjs.cpp => test_ark.cpp} (56%) mode change 100755 => 100644 diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index e051b81..594a60f 100755 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -10,7 +10,6 @@ # 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 (is_standard_system) { @@ -20,12 +19,15 @@ if (is_standard_system) { ohos_unittest("test_process_unittest") { module_out_path = module_output_path + configs = [ "//ark/js_runtime:ark_jsruntime_public_config" ] + include_dirs = [ "//base/compileruntime/js_sys_module/process", + "//ark/js_runtime", "//foundation/ace/napi", "//foundation/ace/napi/interfaces/kits", "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/native_engine/impl/quickjs", + "//foundation/ace/napi/native_engine/impl/ark", "//third_party/googletest/include", "//third_party/node/src", "//utils/native/base/include", @@ -34,24 +36,27 @@ ohos_unittest("test_process_unittest") { cflags = [ "-g3" ] sources = [ + "test_ark.cpp", "test_process.cpp", - "test_quickjs.cpp", ] deps = [ + "//ark/js_runtime:libark_jsruntime", "//base/compileruntime/js_sys_module/process:process_packages", "//foundation/ace/napi/:ace_napi", - "//foundation/ace/napi/:ace_napi_quickjs", + "//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", - "//third_party/quickjs:qjs", "//utils/native/base:utils", + "//utils/native/base:utilsecurec", ] if (is_standard_system) { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + } else { + external_deps = [ "hilog:libhilog" ] } } diff --git a/test/unittest/test.h b/test/unittest/test.h index af07722..753199c 100755 --- a/test/unittest/test.h +++ b/test/unittest/test.h @@ -27,7 +27,7 @@ public: void SetUp() override {} void TearDown() override {} protected: - NativeEngine* engine_; + NativeEngine *engine_; }; #endif /* FOUNDATION_ACE_NAPI_TEST_UNITTEST_TEST_H */ \ No newline at end of file diff --git a/test/unittest/test_quickjs.cpp b/test/unittest/test_ark.cpp old mode 100755 new mode 100644 similarity index 56% rename from test/unittest/test_quickjs.cpp rename to test/unittest/test_ark.cpp index d5d4c0b..f7e90b8 --- a/test/unittest/test_quickjs.cpp +++ b/test/unittest/test_ark.cpp @@ -15,9 +15,11 @@ #include "test.h" -#include "quickjs_native_engine.h" +#include "utils/log.h" +#include "ark_native_engine.h" -static NativeEngine* g_nativeEngine = nullptr; +using panda::RuntimeOption; +static NativeEngine *g_nativeEngine = nullptr; NativeEngineTest::NativeEngineTest() { @@ -26,35 +28,35 @@ NativeEngineTest::NativeEngineTest() NativeEngineTest::~NativeEngineTest() {} -int main(int argc, char** argv) +int main(int argc, char **argv) { testing::GTEST_FLAG(output) = "xml:./"; testing::InitGoogleTest(&argc, argv); - JSRuntime* rt = JS_NewRuntime(); - if (rt == nullptr) { + // Setup + RuntimeOption option; + option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC); + + const int64_t poolSize = 0x1000000; // 16M + option.SetGcPoolSize(poolSize); + + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + option.SetDebuggerLibraryPath(""); + EcmaVM *vm = panda::JSNApi::CreateJSVM(option); + if (vm == nullptr) { return 0; } - JSContext* ctx = JS_NewContext(rt); - if (ctx == nullptr) { - return 0; - } + g_nativeEngine = new ArkNativeEngine(vm, nullptr); - js_std_add_helpers(ctx, 0, nullptr); + int ret = testing::UnitTest::GetInstance()->Run(); - g_nativeEngine = new QuickJSNativeEngine(rt, ctx, nullptr); - - int ret = RUN_ALL_TESTS(); - - g_nativeEngine->Loop(LOOP_DEFAULT); + g_nativeEngine->Loop(LOOP_NOWAIT); delete g_nativeEngine; g_nativeEngine = nullptr; - - js_std_free_handlers(rt); - JS_FreeContext(ctx); - JS_FreeRuntime(rt); + panda::JSNApi::DestoryJSVM(vm); + vm = nullptr; return ret; }