1# Copyright (c) 2021 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14import("//ark/js_runtime/js_runtime_config.gni") 15import("//ark/ts2abc/ts2panda/ts2abc_config.gni") 16import("//build/ohos.gni") 17import("//build/test.gni") 18 19if (is_standard_system) { 20 _icu_path_ = "common/common" 21} else { 22 _icu_path_ = "global/i18n" 23} 24 25template("host_unittest_action") { 26 _target_name_ = "${target_name}" 27 28 # unittest for phone running 29 ohos_unittest(_target_name_) { 30 resource_config_file = 31 "//ark/js_runtime/test/resource/js_runtime/ohos_test.xml" 32 forward_variables_from(invoker, "*") 33 } 34 35 _module_out_path_ = invoker.module_out_path 36 37 # unittest for host running 38 action("${_target_name_}Action") { 39 testonly = true 40 41 _host_test_target_ = ":${_target_name_}(${host_toolchain})" 42 _root_out_dir_ = get_label_info(_host_test_target_, "root_out_dir") 43 44 deps = [ _host_test_target_ ] 45 46 script = "//ark/js_runtime/test/run_ark_executable.py" 47 48 args = [ 49 "--script-file", 50 rebase_path(_root_out_dir_) + 51 "/tests/unittest/${_module_out_path_}/${_target_name_}", 52 "--expect-output", 53 "0", 54 "--env-path", 55 rebase_path(_root_out_dir_) + "/ark/ark:" + rebase_path(_root_out_dir_) + 56 "/ark/ark_js_runtime:" + rebase_path(_root_out_dir_) + "/test/test:" + 57 rebase_path(_root_out_dir_) + "/${_icu_path_}:" + 58 rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"), 59 ] 60 61 inputs = [ 62 "$_root_out_dir_/tests/unittest/${_module_out_path_}/${_target_name_}", 63 ] 64 outputs = [ "$target_out_dir/${_target_name_}/" ] 65 } 66} 67 68template("host_moduletest_action") { 69 _target_name_ = "${target_name}" 70 _deps_ = invoker.deps 71 _is_module_ = false 72 if (defined(invoker.is_module) && invoker.is_module) { 73 _is_module_ = true 74 } 75 76 _test_js_path_ = "./${_target_name_}.js" 77 _test_abc_path_ = "$target_out_dir/${_target_name_}.abc" 78 _test_expect_path_ = "./expect_output.txt" 79 80 ts2abc_gen_abc("gen_${_target_name_}_abc") { 81 extra_visibility = [ ":*" ] # Only targets in this file can depend on this. 82 extra_dependencies = _deps_ 83 src_js = rebase_path(_test_js_path_) 84 dst_file = rebase_path(_test_abc_path_) 85 extra_args = [ "--debug" ] 86 if (_is_module_) { 87 extra_args += [ "--module" ] 88 } 89 90 in_puts = [ 91 _test_js_path_, 92 _test_expect_path_, 93 ] 94 out_puts = [ _test_abc_path_ ] 95 } 96 97 _extra_modules_ = [] 98 if (defined(invoker.extra_modules)) { 99 foreach(module, invoker.extra_modules) { 100 _extra_modules_ += [ "$target_out_dir/${module}.abc" ] 101 } 102 } 103 _test_abc_paths_ = rebase_path(_test_abc_path_) 104 foreach(extra_module, _extra_modules_) { 105 _test_abc_paths_ += ":" + rebase_path(extra_module) 106 } 107 108 action("${_target_name_}Action") { 109 testonly = true 110 111 _host_jsvm_target_ = 112 "//ark/js_runtime/ecmascript/js_vm:ark_js_vm(${host_toolchain})" 113 _root_out_dir_ = get_label_info(_host_jsvm_target_, "root_out_dir") 114 deps = [ 115 ":gen_${_target_name_}_abc", 116 _host_jsvm_target_, 117 ] 118 deps += _deps_ 119 120 script = "//ark/js_runtime/test/run_ark_executable.py" 121 122 js_vm_options = " " 123 if (defined(invoker.is_set_maxNonmovableSpaceCapacity) && 124 invoker.is_set_maxNonmovableSpaceCapacity) { 125 js_vm_options += "--maxNonmovableSpaceCapacity=524288" # 0.5M 126 } 127 128 args = [ 129 "--script-file", 130 rebase_path(_root_out_dir_) + "/ark/ark_js_runtime/ark_js_vm", 131 "--script-options", 132 js_vm_options, 133 "--script-args", 134 _test_abc_paths_, 135 "--expect-file", 136 rebase_path(_test_expect_path_), 137 "--env-path", 138 rebase_path(_root_out_dir_) + "/ark/ark:" + rebase_path(_root_out_dir_) + 139 "/ark/ark_js_runtime:" + rebase_path(_root_out_dir_) + 140 "/${_icu_path_}:" + 141 rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"), 142 ] 143 144 inputs = [ _test_abc_path_ ] 145 inputs += _extra_modules_ 146 147 outputs = [ "$target_out_dir/${_target_name_}/" ] 148 } 149} 150