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