1# Copyright (c) 2021-2023 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/ets_runtime/js_runtime_config.gni")
15import("//arkcompiler/ets_runtime/test/test_helper.gni")
16
17module_output_path = "arkcompiler/ets_runtime"
18
19test_js_path = "//arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/js_files/"
20
21test_js_files = [
22  "heapdump",
23  "allocation",
24]
25
26foreach(file, test_js_files) {
27  es2abc_gen_abc("gen_${file}_abc") {
28    test_js = "${test_js_path}${file}.js"
29    test_abc = "$target_out_dir/abc_files/${file}.abc"
30
31    # Only targets in this file can depend on this.
32    extra_visibility = [ ":*" ]
33    src_js = rebase_path(test_js)
34    dst_file = rebase_path(test_abc)
35    extra_args = [ "--module" ]
36    extra_args += [ "--merge-abc" ]
37
38    in_puts = [ test_js ]
39    out_puts = [ test_abc ]
40  }
41}
42
43host_unittest_action("HeapDumpTest") {
44  module_out_path = module_output_path
45
46  sources = [
47    # test file
48    "heap_dump_test.cpp",
49  ]
50
51  configs = [ "../../../../:ecma_test_config" ]
52
53  deps = [
54    "$ark_third_party_root/icu/icu4c:shared_icui18n",
55    "$ark_third_party_root/icu/icu4c:shared_icuuc",
56    "../../../../:libark_jsruntime_test",
57    sdk_libc_secshared_dep,
58  ]
59
60  foreach(file, test_js_files) {
61    deps += [ ":gen_${file}_abc" ]
62  }
63
64  if (is_ohos && is_standard_system) {
65    test_abc_dir = "/data/test/"
66  } else {
67    test_abc_dir = rebase_path(target_out_dir + "/abc_files/")
68  }
69
70  test_js_dir = rebase_path(test_js_path)
71  defines = [
72    "HPROF_TEST_JS_FILES_DIR=\"${test_js_dir}\"",
73    "HPROF_TEST_ABC_FILES_DIR=\"${test_abc_dir}\"",
74  ]
75
76  # hiviewdfx libraries
77  external_deps = hiviewdfx_ext_deps
78  deps += hiviewdfx_deps
79}
80
81host_unittest_action("HeapTrackerFirstTest") {
82  module_out_path = module_output_path
83
84  sources = [
85    # test file
86    "heap_tracker_first_test.cpp",
87  ]
88
89  configs = [ "../../../../:ecma_test_config" ]
90
91  deps = [
92    "$ark_third_party_root/icu/icu4c:shared_icui18n",
93    "$ark_third_party_root/icu/icu4c:shared_icuuc",
94    "../../../../:libark_jsruntime_test",
95    sdk_libc_secshared_dep,
96  ]
97
98  # hiviewdfx libraries
99  external_deps = hiviewdfx_ext_deps
100  deps += hiviewdfx_deps
101}
102
103host_unittest_action("HeapTrackerSecondTest") {
104  module_out_path = module_output_path
105
106  sources = [
107    # test file
108    "heap_tracker_second_test.cpp",
109  ]
110
111  configs = [ "../../../../:ecma_test_config" ]
112
113  deps = [
114    "$ark_third_party_root/icu/icu4c:shared_icui18n",
115    "$ark_third_party_root/icu/icu4c:shared_icuuc",
116    "../../../../:libark_jsruntime_test",
117    sdk_libc_secshared_dep,
118  ]
119
120  # hiviewdfx libraries
121  external_deps = hiviewdfx_ext_deps
122  deps += hiviewdfx_deps
123}
124
125host_unittest_action("HeapTrackerThirdTest") {
126  module_out_path = module_output_path
127
128  sources = [
129    # test file
130    "heap_tracker_third_test.cpp",
131  ]
132
133  configs = [ "../../../../:ecma_test_config" ]
134
135  deps = [
136    "$ark_third_party_root/icu/icu4c:shared_icui18n",
137    "$ark_third_party_root/icu/icu4c:shared_icuuc",
138    "../../../../:libark_jsruntime_test",
139    sdk_libc_secshared_dep,
140  ]
141
142  # hiviewdfx libraries
143  external_deps = hiviewdfx_ext_deps
144  deps += hiviewdfx_deps
145}
146
147host_unittest_action("HProfTest") {
148  module_out_path = module_output_path
149
150  sources = [
151    # test file
152    "hprof_test.cpp",
153  ]
154
155  configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
156
157  deps = [
158    "$ark_third_party_root/icu/icu4c:shared_icui18n",
159    "$ark_third_party_root/icu/icu4c:shared_icuuc",
160    "//arkcompiler/ets_runtime:libark_jsruntime_test",
161    sdk_libc_secshared_dep,
162  ]
163
164  # hiviewdfx libraries
165  external_deps = hiviewdfx_ext_deps
166  external_deps += [ "zlib:libz" ]
167  deps += hiviewdfx_deps
168}
169
170host_unittest_action("HeapSamplingTest") {
171  module_out_path = module_output_path
172
173  sources = [
174    # test file
175    "heap_sampling_test.cpp",
176  ]
177
178  configs = [ "$js_root:ecma_test_config" ]
179
180  deps = [
181    "$ark_third_party_root/icu/icu4c:shared_icui18n",
182    "$ark_third_party_root/icu/icu4c:shared_icuuc",
183    "$js_root:libark_jsruntime_test",
184    sdk_libc_secshared_dep,
185  ]
186
187  # hiviewdfx libraries
188  external_deps = hiviewdfx_ext_deps
189  deps += hiviewdfx_deps
190}
191
192group("unittest") {
193  testonly = true
194  deps = [
195    ":HProfTest",
196    ":HeapDumpTest",
197    ":HeapSamplingTest",
198    ":HeapTrackerFirstTest",
199    ":HeapTrackerSecondTest",
200    ":HeapTrackerThirdTest",
201  ]
202}
203
204group("host_unittest") {
205  testonly = true
206  deps = [
207    ":HProfTestAction",
208    ":HeapDumpTestAction",
209    ":HeapSamplingTestAction",
210    ":HeapTrackerFirstTestAction",
211    ":HeapTrackerSecondTestAction",
212    ":HeapTrackerThirdTestAction",
213  ]
214  if (is_mac) {
215    deps -= [
216      ":HProfTestAction",
217      ":HeapDumpTestAction",
218      ":HeapSamplingTestAction",
219      ":HeapTrackerFirstTestAction",
220      ":HeapTrackerSecondTestAction",
221      ":HeapTrackerThirdTestAction",
222    ]
223  }
224}
225