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