• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
19metadata_file_path = "//arkcompiler/ets_runtime/ecmascript/js_type_metadata/"
20
21test_js_path = "//arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests/js_files/"
22
23target_test_path = "/tests/unittest/arkcompiler/ets_runtime/resource/obj/arkcompiler/ets_runtime/ecmascript/dfx/hprof/tests"
24
25test_js_files = [
26  "heapdump",
27  "allocation",
28  "heap_snapshot",
29]
30
31foreach(file, test_js_files) {
32  es2abc_gen_abc("gen_${file}_abc") {
33    test_js = "${test_js_path}${file}.js"
34    test_abc = "$target_out_dir/abc_files/${file}.abc"
35
36    # Only targets in this file can depend on this.
37    extra_visibility = [ ":*" ]
38    src_js = rebase_path(test_js)
39    dst_file = rebase_path(test_abc)
40    extra_args = [ "--module" ]
41    extra_args += [ "--merge-abc" ]
42
43    in_puts = [ test_js ]
44    out_puts = [ test_abc ]
45  }
46}
47
48host_unittest_action("HeapDumpTest") {
49  module_out_path = module_output_path
50
51  sources = [
52    # test file
53    "heap_dump_test.cpp",
54  ]
55
56  configs = [ "../../../../:ecma_test_config" ]
57
58  deps = [
59    "$ark_third_party_root/icu/icu4c:shared_icui18n",
60    "$ark_third_party_root/icu/icu4c:shared_icuuc",
61    "../../../../:libark_jsruntime_test",
62    sdk_libc_secshared_dep,
63  ]
64
65  foreach(file, test_js_files) {
66    deps += [ ":gen_${file}_abc" ]
67  }
68
69  if (is_ohos && is_standard_system) {
70    test_abc_dir = "/data/test/"
71  } else {
72    test_abc_dir = rebase_path(target_out_dir + "/abc_files/")
73  }
74
75  test_js_dir = rebase_path(test_js_path)
76  defines = [
77    "HPROF_TEST_JS_FILES_DIR=\"${test_js_dir}\"",
78    "HPROF_TEST_ABC_FILES_DIR=\"${test_abc_dir}\"",
79  ]
80
81  # hiviewdfx libraries
82  external_deps = hiviewdfx_ext_deps
83  deps += hiviewdfx_deps
84}
85
86host_unittest_action("HeapSnapShotTest") {
87  module_out_path = module_output_path
88
89  sources = [
90    # test file
91    "heap_snapshot_test.cpp",
92  ]
93
94  configs = [ "../../../../:ecma_test_config" ]
95
96  deps = [
97    "$ark_third_party_root/icu/icu4c:shared_icui18n",
98    "$ark_third_party_root/icu/icu4c:shared_icuuc",
99    "../../../../:libark_jsruntime_test",
100    sdk_libc_secshared_dep,
101  ]
102
103  foreach(file, test_js_files) {
104    deps += [ ":gen_${file}_abc" ]
105  }
106
107  if (is_ohos && is_standard_system) {
108    test_abc_dir = "/data/test/"
109  } else {
110    test_abc_dir = rebase_path(target_out_dir + "/abc_files/")
111  }
112
113  test_js_dir = rebase_path(test_js_path)
114  defines = [
115    "HPROF_TEST_JS_FILES_DIR=\"${test_js_dir}\"",
116    "HPROF_TEST_ABC_FILES_DIR=\"${test_abc_dir}\"",
117  ]
118
119  # hiviewdfx libraries
120  external_deps = hiviewdfx_ext_deps
121  deps += hiviewdfx_deps
122}
123
124host_unittest_action("HeapTrackerFirstTest") {
125  module_out_path = module_output_path
126
127  sources = [
128    # test file
129    "heap_tracker_first_test.cpp",
130  ]
131
132  configs = [ "../../../../:ecma_test_config" ]
133
134  deps = [
135    "$ark_third_party_root/icu/icu4c:shared_icui18n",
136    "$ark_third_party_root/icu/icu4c:shared_icuuc",
137    "../../../../:libark_jsruntime_test",
138    sdk_libc_secshared_dep,
139  ]
140
141  # hiviewdfx libraries
142  external_deps = hiviewdfx_ext_deps
143  deps += hiviewdfx_deps
144}
145
146host_unittest_action("HeapTrackerSecondTest") {
147  module_out_path = module_output_path
148
149  sources = [
150    # test file
151    "heap_tracker_second_test.cpp",
152  ]
153
154  configs = [ "../../../../:ecma_test_config" ]
155
156  deps = [
157    "$ark_third_party_root/icu/icu4c:shared_icui18n",
158    "$ark_third_party_root/icu/icu4c:shared_icuuc",
159    "../../../../:libark_jsruntime_test",
160    sdk_libc_secshared_dep,
161  ]
162
163  # hiviewdfx libraries
164  external_deps = hiviewdfx_ext_deps
165  deps += hiviewdfx_deps
166}
167
168host_unittest_action("HeapTrackerThirdTest") {
169  module_out_path = module_output_path
170
171  sources = [
172    # test file
173    "heap_tracker_third_test.cpp",
174  ]
175
176  configs = [ "../../../../:ecma_test_config" ]
177
178  deps = [
179    "$ark_third_party_root/icu/icu4c:shared_icui18n",
180    "$ark_third_party_root/icu/icu4c:shared_icuuc",
181    "../../../../:libark_jsruntime_test",
182    sdk_libc_secshared_dep,
183  ]
184
185  # hiviewdfx libraries
186  external_deps = hiviewdfx_ext_deps
187  deps += hiviewdfx_deps
188}
189
190host_unittest_action("HProfTest") {
191  module_out_path = module_output_path
192
193  sources = [
194    # test file
195    "hprof_test.cpp",
196  ]
197
198  configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
199
200  deps = [
201    "$ark_third_party_root/icu/icu4c:shared_icui18n",
202    "$ark_third_party_root/icu/icu4c:shared_icuuc",
203    "//arkcompiler/ets_runtime:libark_jsruntime_test",
204    sdk_libc_secshared_dep,
205  ]
206
207  # hiviewdfx libraries
208  external_deps = hiviewdfx_ext_deps
209  external_deps += [ "zlib:libz" ]
210  deps += hiviewdfx_deps
211}
212
213host_unittest_action("HeapSamplingTest") {
214  module_out_path = module_output_path
215
216  sources = [
217    # test file
218    "heap_sampling_test.cpp",
219  ]
220
221  configs = [ "$js_root:ecma_test_config" ]
222
223  deps = [
224    "$ark_third_party_root/icu/icu4c:shared_icui18n",
225    "$ark_third_party_root/icu/icu4c:shared_icuuc",
226    "$js_root:libark_jsruntime_test",
227    sdk_libc_secshared_dep,
228  ]
229
230  # hiviewdfx libraries
231  external_deps = hiviewdfx_ext_deps
232  deps += hiviewdfx_deps
233}
234
235host_unittest_action("RawHeapTranslateTest") {
236  module_out_path = module_output_path
237
238  sources = [
239    # test file
240    "../rawheap_translate/metadata_parse.cpp",
241    "../rawheap_translate/utils.cpp",
242    "rawheap_translate_test.cpp",
243  ]
244
245  configs = [ "$js_root:ecma_test_config" ]
246
247  deps = [
248    "$ark_third_party_root/icu/icu4c:shared_icui18n",
249    "$ark_third_party_root/icu/icu4c:shared_icuuc",
250    "$js_root:libark_jsruntime_test",
251    sdk_libc_secshared_dep,
252  ]
253
254  cflags_cc = [ "-std=c++17" ]
255
256  external_deps = [
257    "bounds_checking_function:libsec_static",
258    "cJSON:cjson_static",
259  ]
260
261  # hiviewdfx libraries
262  external_deps += hiviewdfx_ext_deps
263  deps += hiviewdfx_deps
264}
265
266action("copy_metadata_for_test") {
267  script = "$js_root/script/metadata_copy_for_test.py"
268
269  target_path = rebase_path(root_out_dir) + "$target_test_path/metadata"
270
271  args = [
272    "--metadata",
273    rebase_path("$js_root/ecmascript/js_type_metadata"),
274    "--outputs",
275    rebase_path("$target_path"),
276  ]
277
278  outputs = [ "$root_gen_dir/arkcompiler/ets_runtime/metadata_copy_dummy.txt" ]
279}
280
281host_unittest_action("JSMetadataTest") {
282  module_out_path = module_output_path
283
284  sources = [ "js_metadata_test.cpp" ]
285
286  configs = [ "../../../../:ecma_test_config" ]
287
288  deps = [
289    ":copy_metadata_for_test",
290    "$ark_third_party_root/icu/icu4c:shared_icui18n",
291    "$ark_third_party_root/icu/icu4c:shared_icuuc",
292    "../../../../:libark_jsruntime_test",
293    sdk_libc_secshared_dep,
294  ]
295
296  if (is_ohos && is_standard_system) {
297    metadata_file_path = "/data/test/"
298  }
299
300  metadata_file_path = rebase_path(metadata_file_path)
301  defines = [ "METADATA_SOURCE_FILE_DIR=\"${metadata_file_path}\"" ]
302
303  # hiviewdfx libraries
304  external_deps = hiviewdfx_ext_deps
305  external_deps += [ "cJSON:cjson_static" ]
306  deps += hiviewdfx_deps
307}
308
309group("unittest") {
310  testonly = true
311  deps = [
312    ":HProfTest",
313    ":HeapDumpTest",
314    ":HeapSamplingTest",
315    ":HeapSnapShotTest",
316    ":HeapTrackerFirstTest",
317    ":HeapTrackerSecondTest",
318    ":HeapTrackerThirdTest",
319    ":JSMetadataTest",
320    ":RawHeapTranslateTest",
321  ]
322}
323
324group("host_unittest") {
325  testonly = true
326  deps = [
327    ":HProfTestAction",
328    ":HeapDumpTestAction",
329    ":HeapSamplingTestAction",
330    ":HeapSnapShotTestAction",
331    ":HeapTrackerFirstTestAction",
332    ":HeapTrackerSecondTestAction",
333    ":HeapTrackerThirdTestAction",
334    ":JSMetadataTestAction",
335    ":RawHeapTranslateTestAction",
336  ]
337  if (is_mac) {
338    deps -= [
339      ":HProfTestAction",
340      ":HeapDumpTestAction",
341      ":HeapSamplingTestAction",
342      ":HeapSnapShotTestAction",
343      ":HeapTrackerFirstTestAction",
344      ":HeapTrackerSecondTestAction",
345      ":HeapTrackerThirdTestAction",
346      ":JSMetadataTestAction",
347      ":RawHeapTranslateTestAction",
348    ]
349  }
350}
351