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("//arkcompiler/toolchain/toolchain.gni") 15import("$build_root/config/components/ets_frontend/es2abc_config.gni") 16import("$build_root/test.gni") 17 18if (is_standard_system || ark_standalone_build) { 19 _icu_path_ = "thirdparty/icu" 20} else { 21 _icu_path_ = "global/i18n" 22} 23if (defined(timeout)) { 24 _timeout_ = timeout 25} else { 26 _timeout_ = 1200 27} 28template("host_unittest_action") { 29 _target_name_ = "${target_name}" 30 31 # unittest for running on OpenHarmony device 32 ohos_unittest(_target_name_) { 33 resource_config_file = 34 "//arkcompiler/toolchain/test/resource/tooling/ohos_test.xml" 35 forward_variables_from(invoker, "*") 36 } 37 38 _module_out_path_ = invoker.module_out_path 39 40 # unittest for running on host 41 action("${_target_name_}ActionWithoutQemu") { 42 testonly = true 43 44 _host_test_target_ = ":${_target_name_}(${host_toolchain})" 45 _root_out_dir_ = get_label_info(_host_test_target_, "root_out_dir") 46 47 deps = [ _host_test_target_ ] 48 49 script = "//arkcompiler/ets_runtime/script/run_ark_executable.py" 50 51 args = [ 52 "--script-file", 53 rebase_path(_root_out_dir_) + 54 "/tests/unittest/${_module_out_path_}/${_target_name_}", 55 "--expect-output", 56 "0", 57 "--env-path", 58 rebase_path(_root_out_dir_) + "/arkcompiler/ets_runtime:" + 59 rebase_path(_root_out_dir_) + "/arkcompiler/toolchain:" + 60 rebase_path(_root_out_dir_) + "/test/test:" + 61 rebase_path(_root_out_dir_) + "/${_icu_path_}:" + 62 rebase_path(_root_out_dir_) + "/thirdparty/cJSON:" + 63 rebase_path(_root_out_dir_) + "/thirdparty/libuv:" + 64 rebase_path(_root_out_dir_) + 65 "/thirdparty/bounds_checking_function:" + 66 rebase_path(_root_out_dir_) + "/thirdparty/openssl:" + 67 rebase_path(_root_out_dir_) + "/thirdparty/zlib:" + 68 rebase_path(_root_out_dir_) + "/resourceschedule/qos_manager:" + 69 rebase_path(_root_out_dir_) + "/hiviewdfx/hilog:" + 70 rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"), 71 "--timeout-limit", 72 "${_timeout_}", 73 ] 74 75 inputs = [ 76 "$_root_out_dir_/tests/unittest/${_module_out_path_}/${_target_name_}", 77 ] 78 outputs = [ "$target_out_dir/${_target_name_}/" ] 79 } 80 if (ark_standalone_build && host_os == "linux" && target_os == "ohos") { 81 import("$ark_third_party_root/musl/musl_template.gni") 82 import("$build_root/config/qemu/config.gni") 83 84 action("${_target_name_}ActionWithQemu") { 85 testonly = true 86 87 _host_test_target_ = ":${_target_name_}" 88 89 # path of root_out_dir based on root_src_dir 90 _root_out_dir_ = get_label_info(_host_test_target_, "root_out_dir") 91 92 deps = [ 93 "$ark_third_party_root/musl:soft_create_linker_for_qemu", 94 _host_test_target_, 95 ] 96 97 script = "${js_root}/script/run_ark_executable.py" 98 99 args = [ 100 "--script-file", 101 rebase_path( 102 "$_root_out_dir_/tests/unittest/${_module_out_path_}/${_target_name_}", 103 root_build_dir), 104 "--expect-output", 105 "0", 106 "--clang-lib-path", 107 rebase_path("${clang_base_path}/lib/${musl_arch}-linux-ohos", 108 root_build_dir), 109 "--qemu-binary-path", 110 "${QEMU_INSTALLATION_PATH}/bin/qemu-${musl_arch}", 111 "--qemu-ld-prefix", 112 rebase_path(musl_linker_so_out_dir, root_build_dir), 113 "--timeout-limit", 114 "${_timeout_}", 115 ] 116 117 inputs = [ 118 "$_root_out_dir_/tests/unittest/${_module_out_path_}/${_target_name_}", 119 ] 120 outputs = [ "$target_out_dir/${_target_name_}WithQemu/" ] 121 } 122 } 123 group("${_target_name_}Action") { 124 testonly = true 125 126 deps = [] 127 if (ark_standalone_build && host_os == "linux" && target_os == "ohos" && 128 run_with_qemu) { 129 deps += [ ":${_target_name_}ActionWithQemu" ] 130 } else { 131 deps += [ ":${_target_name_}ActionWithoutQemu" ] 132 } 133 } 134} 135