# 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. import("//ark/js_runtime/js_runtime_config.gni") import("//ark/ts2abc/ts2panda/ts2abc_config.gni") import("//build/ohos.gni") import("//build/test.gni") if (is_standard_system) { _icu_path_ = "common/common" } else { _icu_path_ = "global/i18n" } template("host_unittest_action") { _target_name_ = "${target_name}" # unittest for phone running ohos_unittest(_target_name_) { resource_config_file = "//ark/js_runtime/test/resource/js_runtime/ohos_test.xml" forward_variables_from(invoker, "*") } _module_out_path_ = invoker.module_out_path # unittest for host running action("${_target_name_}Action") { testonly = true _host_test_target_ = ":${_target_name_}(${host_toolchain})" _root_out_dir_ = get_label_info(_host_test_target_, "root_out_dir") deps = [ _host_test_target_ ] script = "//ark/js_runtime/test/run_ark_executable.py" args = [ "--script-file", rebase_path(_root_out_dir_) + "/tests/unittest/${_module_out_path_}/${_target_name_}", "--expect-output", "0", "--env-path", rebase_path(_root_out_dir_) + "/ark/ark:" + rebase_path(_root_out_dir_) + "/ark/ark_js_runtime:" + rebase_path(_root_out_dir_) + "/test/test:" + rebase_path(_root_out_dir_) + "/${_icu_path_}:" + rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"), ] inputs = [ "$_root_out_dir_/tests/unittest/${_module_out_path_}/${_target_name_}", ] outputs = [ "$target_out_dir/${_target_name_}/" ] } } template("host_moduletest_action") { _target_name_ = "${target_name}" _deps_ = invoker.deps _is_module_ = false if (defined(invoker.is_module) && invoker.is_module) { _is_module_ = true } _test_js_path_ = "./${_target_name_}.js" _test_abc_path_ = "$target_out_dir/${_target_name_}.abc" _test_expect_path_ = "./expect_output.txt" ts2abc_gen_abc("gen_${_target_name_}_abc") { extra_visibility = [ ":*" ] # Only targets in this file can depend on this. extra_dependencies = _deps_ src_js = rebase_path(_test_js_path_) dst_file = rebase_path(_test_abc_path_) extra_args = [ "--debug" ] if (_is_module_) { extra_args += [ "--module" ] } in_puts = [ _test_js_path_, _test_expect_path_, ] out_puts = [ _test_abc_path_ ] } _extra_modules_ = [] if (defined(invoker.extra_modules)) { foreach(module, invoker.extra_modules) { _extra_modules_ += [ "$target_out_dir/${module}.abc" ] } } _test_abc_paths_ = rebase_path(_test_abc_path_) foreach(extra_module, _extra_modules_) { _test_abc_paths_ += ":" + rebase_path(extra_module) } action("${_target_name_}Action") { testonly = true _host_jsvm_target_ = "//ark/js_runtime/ecmascript/js_vm:ark_js_vm(${host_toolchain})" _root_out_dir_ = get_label_info(_host_jsvm_target_, "root_out_dir") deps = [ ":gen_${_target_name_}_abc", _host_jsvm_target_, ] deps += _deps_ script = "//ark/js_runtime/test/run_ark_executable.py" js_vm_options = " " if (defined(invoker.is_set_maxNonmovableSpaceCapacity) && invoker.is_set_maxNonmovableSpaceCapacity) { js_vm_options += "--maxNonmovableSpaceCapacity=524288" # 0.5M } args = [ "--script-file", rebase_path(_root_out_dir_) + "/ark/ark_js_runtime/ark_js_vm", "--script-options", js_vm_options, "--script-args", _test_abc_paths_, "--expect-file", rebase_path(_test_expect_path_), "--env-path", rebase_path(_root_out_dir_) + "/ark/ark:" + rebase_path(_root_out_dir_) + "/ark/ark_js_runtime:" + rebase_path(_root_out_dir_) + "/${_icu_path_}:" + rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"), ] inputs = [ _test_abc_path_ ] inputs += _extra_modules_ outputs = [ "$target_out_dir/${_target_name_}/" ] } }