• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    if (!defined(deps)) {
37      deps = []
38    }
39    if (!defined(external_deps)) {
40      external_deps = []
41    }
42    # hiviewdfx libraries
43    external_deps += hiviewdfx_ext_deps
44    deps += hiviewdfx_deps
45  }
46
47  _module_out_path_ = invoker.module_out_path
48
49  # unittest for running on host
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_) + "/arkcompiler/toolchain:" +
69          rebase_path(_root_out_dir_) + "/test/test:" +
70          rebase_path(_root_out_dir_) + "/${_icu_path_}:" +
71          rebase_path(_root_out_dir_) + "/thirdparty/cJSON:" +
72          rebase_path(_root_out_dir_) + "/thirdparty/libuv:" +
73          rebase_path(_root_out_dir_) +
74          "/thirdparty/bounds_checking_function:" +
75          rebase_path(_root_out_dir_) + "/thirdparty/openssl:" +
76          rebase_path(_root_out_dir_) + "/thirdparty/zlib:" +
77          rebase_path(_root_out_dir_) + "/resourceschedule/qos_manager:" +
78          rebase_path(_root_out_dir_) + "/hiviewdfx/hilog:" +
79          rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"),
80      "--timeout-limit",
81      "${_timeout_}",
82    ]
83
84    inputs = [
85      "$_root_out_dir_/tests/unittest/${_module_out_path_}/${_target_name_}",
86    ]
87    outputs = [ "$target_out_dir/${_target_name_}/" ]
88  }
89  if (ark_standalone_build && host_os == "linux" && target_os == "ohos") {
90    import("$ark_third_party_root/musl/musl_template.gni")
91    import("$build_root/config/qemu/config.gni")
92
93    action("${_target_name_}ActionWithQemu") {
94      testonly = true
95
96      _host_test_target_ = ":${_target_name_}"
97
98      # path of root_out_dir based on root_src_dir
99      _root_out_dir_ = get_label_info(_host_test_target_, "root_out_dir")
100
101      deps = [
102        "$ark_third_party_root/musl:soft_create_linker_for_qemu",
103        _host_test_target_,
104      ]
105
106      script = "${js_root}/script/run_ark_executable.py"
107
108      args = [
109        "--script-file",
110        rebase_path(
111            "$_root_out_dir_/tests/unittest/${_module_out_path_}/${_target_name_}",
112            root_build_dir),
113        "--expect-output",
114        "0",
115        "--clang-lib-path",
116        rebase_path("${clang_base_path}/lib/${musl_arch}-linux-ohos",
117                    root_build_dir),
118        "--qemu-binary-path",
119        "${QEMU_INSTALLATION_PATH}/bin/qemu-${musl_arch}",
120        "--qemu-ld-prefix",
121        rebase_path(musl_linker_so_out_dir, root_build_dir),
122        "--timeout-limit",
123        "${_timeout_}",
124      ]
125
126      inputs = [
127        "$_root_out_dir_/tests/unittest/${_module_out_path_}/${_target_name_}",
128      ]
129      outputs = [ "$target_out_dir/${_target_name_}WithQemu/" ]
130    }
131  }
132  group("${_target_name_}Action") {
133    testonly = true
134
135    deps = []
136    if (ark_standalone_build && host_os == "linux" && target_os == "ohos" &&
137        !run_with_qemu) {
138      deps += [ ":${_target_name_}ActionWithoutQemu" ]
139    }
140  }
141}
142