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/ets_runtime" 18 19metadata_file_path = "//arkcompiler/ets_runtime/ecmascript/js_type_metadata/" 20 21target_test_path = "/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 "heapdump1", 28 "allocation", 29 "heap_snapshot", 30] 31 32foreach(file, test_js_files) { 33 es2abc_gen_abc("gen_${file}_abc") { 34 test_js = "${test_js_path}${file}.js" 35 test_abc = "$target_out_dir/abc_files/${file}.abc" 36 37 # Only targets in this file can depend on this. 38 extra_visibility = [ ":*" ] 39 src_js = rebase_path(test_js) 40 dst_file = rebase_path(test_abc) 41 extra_args = [ "--module" ] 42 extra_args += [ "--merge-abc" ] 43 44 in_puts = [ test_js ] 45 out_puts = [ test_abc ] 46 } 47} 48 49metadata_json_path = rebase_path(root_out_dir) + "$target_test_path/" 50 51action("gen_metadata_for_test") { 52 script = "$js_root/script/metadata_generate.py" 53 54 args = [ 55 "--enum", 56 rebase_path("$metadata_file_path/type_enums.json"), 57 "--metadata", 58 rebase_path("$metadata_file_path"), 59 "--output", 60 rebase_path(metadata_json_path + "metadata.json"), 61 "--version", 62 "1.0.0", 63 ] 64 65 outputs = [ "$root_gen_dir/arkcompiler/ets_runtime/metadata_json_dummy.txt" ] 66} 67 68host_unittest_action("HeapDumpTest") { 69 module_out_path = module_output_path 70 71 sources = [ 72 # test file 73 "../rawheap_translate/metadata_parse.cpp", 74 "../rawheap_translate/rawheap_translate.cpp", 75 "../rawheap_translate/serializer.cpp", 76 "../rawheap_translate/string_hashmap.cpp", 77 "../rawheap_translate/utils.cpp", 78 "heap_dump_test.cpp", 79 ] 80 81 configs = [ "../../../../:ecma_test_config" ] 82 83 deps = [ 84 ":gen_metadata_for_test", 85 "../../../../:libark_jsruntime_test", 86 ] 87 88 foreach(file, test_js_files) { 89 deps += [ ":gen_${file}_abc" ] 90 } 91 92 if (is_ohos && is_standard_system) { 93 test_abc_dir = "/data/test/" 94 test_metadata_dir = "/system/lib64/module/arkcompiler/" 95 } else { 96 test_abc_dir = rebase_path(target_out_dir + "/abc_files/") 97 test_metadata_dir = rebase_path("$metadata_json_path") 98 } 99 100 test_js_dir = rebase_path(test_js_path) 101 defines = [ 102 "HPROF_TEST_JS_FILES_DIR=\"${test_js_dir}\"", 103 "HPROF_TEST_ABC_FILES_DIR=\"${test_abc_dir}\"", 104 "HPROF_TEST_METADATA_JSON_DIR=\"${test_metadata_dir}\"", 105 ] 106 107 external_deps = [ 108 "bounds_checking_function:libsec_static", 109 "cJSON:cjson_static", 110 "icu:shared_icui18n", 111 "icu:shared_icuuc", 112 ] 113 114 # hiviewdfx libraries 115 external_deps += hiviewdfx_ext_deps 116 deps += hiviewdfx_deps 117} 118 119host_unittest_action("HeapSnapShotTest") { 120 module_out_path = module_output_path 121 122 sources = [ 123 # test file 124 "heap_snapshot_test.cpp", 125 ] 126 127 configs = [ "../../../../:ecma_test_config" ] 128 129 deps = [ "../../../../:libark_jsruntime_test" ] 130 131 foreach(file, test_js_files) { 132 deps += [ ":gen_${file}_abc" ] 133 } 134 135 if (is_ohos && is_standard_system) { 136 test_abc_dir = "/data/test/" 137 } else { 138 test_abc_dir = rebase_path(target_out_dir + "/abc_files/") 139 } 140 141 test_js_dir = rebase_path(test_js_path) 142 defines = [ 143 "HPROF_TEST_JS_FILES_DIR=\"${test_js_dir}\"", 144 "HPROF_TEST_ABC_FILES_DIR=\"${test_abc_dir}\"", 145 ] 146 147 # hiviewdfx libraries 148 external_deps = hiviewdfx_ext_deps 149 external_deps += [ 150 "icu:shared_icui18n", 151 "icu:shared_icuuc", 152 ] 153 deps += hiviewdfx_deps 154} 155 156host_unittest_action("HeapTrackerFirstTest") { 157 module_out_path = module_output_path 158 159 sources = [ 160 # test file 161 "heap_tracker_first_test.cpp", 162 ] 163 164 configs = [ "../../../../:ecma_test_config" ] 165 166 deps = [ "../../../../:libark_jsruntime_test" ] 167 168 # hiviewdfx libraries 169 external_deps = hiviewdfx_ext_deps 170 external_deps += [ 171 "icu:shared_icui18n", 172 "icu:shared_icuuc", 173 ] 174 deps += hiviewdfx_deps 175} 176 177host_unittest_action("HeapTrackerSecondTest") { 178 module_out_path = module_output_path 179 180 sources = [ 181 # test file 182 "heap_tracker_second_test.cpp", 183 ] 184 185 configs = [ "../../../../:ecma_test_config" ] 186 187 deps = [ "../../../../:libark_jsruntime_test" ] 188 189 # hiviewdfx libraries 190 external_deps = hiviewdfx_ext_deps 191 external_deps += [ 192 "icu:shared_icui18n", 193 "icu:shared_icuuc", 194 ] 195 deps += hiviewdfx_deps 196} 197 198host_unittest_action("HeapTrackerThirdTest") { 199 module_out_path = module_output_path 200 201 sources = [ 202 # test file 203 "heap_tracker_third_test.cpp", 204 ] 205 206 configs = [ "../../../../:ecma_test_config" ] 207 208 deps = [ "../../../../:libark_jsruntime_test" ] 209 210 # hiviewdfx libraries 211 external_deps = hiviewdfx_ext_deps 212 external_deps += [ 213 "icu:shared_icui18n", 214 "icu:shared_icuuc", 215 ] 216 deps += hiviewdfx_deps 217} 218 219host_unittest_action("HProfTest") { 220 module_out_path = module_output_path 221 222 sources = [ 223 # test file 224 "hprof_test.cpp", 225 ] 226 227 configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ] 228 229 deps = [ "$js_root:libark_jsruntime_test" ] 230 231 # hiviewdfx libraries 232 external_deps = hiviewdfx_ext_deps 233 external_deps += [ 234 "icu:shared_icui18n", 235 "icu:shared_icuuc", 236 ] 237 external_deps += [ "zlib:libz" ] 238 deps += hiviewdfx_deps 239} 240 241host_unittest_action("HeapSamplingTest") { 242 module_out_path = module_output_path 243 244 sources = [ 245 # test file 246 "heap_sampling_test.cpp", 247 ] 248 249 configs = [ "$js_root:ecma_test_config" ] 250 251 deps = [ "$js_root:libark_jsruntime_test" ] 252 253 # hiviewdfx libraries 254 external_deps = hiviewdfx_ext_deps 255 external_deps += [ 256 "icu:shared_icui18n", 257 "icu:shared_icuuc", 258 ] 259 deps += hiviewdfx_deps 260} 261 262host_unittest_action("RawHeapTranslateTest") { 263 module_out_path = module_output_path 264 265 sources = [ 266 # test file 267 "../rawheap_translate/metadata_parse.cpp", 268 "../rawheap_translate/utils.cpp", 269 "rawheap_translate_test.cpp", 270 ] 271 272 configs = [ "$js_root:ecma_test_config" ] 273 274 deps = [ "$js_root:libark_jsruntime_test" ] 275 276 cflags_cc = [ "-std=c++17" ] 277 278 external_deps = [ 279 "bounds_checking_function:libsec_static", 280 "cJSON:cjson_static", 281 "icu:shared_icui18n", 282 "icu:shared_icuuc", 283 ] 284 285 # hiviewdfx libraries 286 external_deps += hiviewdfx_ext_deps 287 deps += hiviewdfx_deps 288} 289 290action("copy_metadata_for_test") { 291 script = "$js_root/script/metadata_copy_for_test.py" 292 293 target_path = rebase_path(root_out_dir) + "$target_test_path/metadata" 294 295 args = [ 296 "--metadata", 297 rebase_path("$js_root/ecmascript/js_type_metadata"), 298 "--outputs", 299 rebase_path("$target_path"), 300 ] 301 302 outputs = [ "$root_gen_dir/arkcompiler/ets_runtime/metadata_copy_dummy.txt" ] 303} 304 305host_unittest_action("JSMetadataTest") { 306 module_out_path = module_output_path 307 308 sources = [ "js_metadata_test.cpp" ] 309 310 configs = [ "../../../../:ecma_test_config" ] 311 312 deps = [ 313 ":copy_metadata_for_test", 314 "../../../../:libark_jsruntime_test", 315 ] 316 317 if (is_ohos && is_standard_system) { 318 metadata_file_path = "/data/test/" 319 } 320 321 metadata_file_path = rebase_path(metadata_file_path) 322 defines = [ "METADATA_SOURCE_FILE_DIR=\"${metadata_file_path}\"" ] 323 324 # hiviewdfx libraries 325 external_deps = hiviewdfx_ext_deps 326 external_deps += [ 327 "icu:shared_icui18n", 328 "icu:shared_icuuc", 329 ] 330 external_deps += [ "cJSON:cjson_static" ] 331 deps += hiviewdfx_deps 332} 333 334host_unittest_action("LocalHandleLeakDetectTest") { 335 module_out_path = module_output_path 336 337 sources = [] 338 339 if (enable_handle_leak_detect) { 340 sources += [ 341 # test file 342 "local_handle_leak_detect_test.cpp", 343 ] 344 } 345 346 configs = [ "$js_root:ecma_test_config" ] 347 348 deps = [ "$js_root:libark_jsruntime_test" ] 349 350 external_deps = [ 351 "icu:shared_icui18n", 352 "icu:shared_icuuc", 353 ] 354 external_deps += hiviewdfx_ext_deps 355 356 cflags_cc = [ 357 "-Wno-gnu-anonymous-struct", 358 "-Wno-nested-anon-types", 359 "-Wno-variadic-macros", 360 ] 361} 362 363host_unittest_action("GlobalHandleLeakDetectTest") { 364 module_out_path = module_output_path 365 366 sources = [ 367 # test file 368 "global_handle_leak_detect_test.cpp", 369 ] 370 371 configs = [ "$js_root:ecma_test_config" ] 372 373 deps = [ "$js_root:libark_jsruntime_test" ] 374 375 external_deps = [ 376 "icu:shared_icui18n", 377 "icu:shared_icuuc", 378 ] 379 external_deps += hiviewdfx_ext_deps 380 381 cflags_cc = [ 382 "-Wno-gnu-anonymous-struct", 383 "-Wno-nested-anon-types", 384 "-Wno-variadic-macros", 385 ] 386} 387 388group("unittest") { 389 testonly = true 390 deps = [ 391 ":GlobalHandleLeakDetectTest", 392 ":HProfTest", 393 ":HeapDumpTest", 394 ":HeapSamplingTest", 395 ":HeapSnapShotTest", 396 ":HeapTrackerFirstTest", 397 ":HeapTrackerSecondTest", 398 ":HeapTrackerThirdTest", 399 ":JSMetadataTest", 400 ":RawHeapTranslateTest", 401 ] 402 403 # TODO: CMC-GC UT FIX LATER 404 if (ets_runtime_enable_cmc_gc) { 405 deps -= [ 406 ":HProfTest", 407 ":HeapDumpTest", 408 ":HeapSnapShotTest", 409 ":HeapTrackerFirstTest", 410 ":HeapTrackerSecondTest", 411 ":HeapTrackerThirdTest", 412 ] 413 } 414} 415 416group("host_unittest") { 417 testonly = true 418 deps = [ 419 ":GlobalHandleLeakDetectTestAction", 420 ":HProfTestAction", 421 ":HeapDumpTestAction", 422 ":HeapSamplingTestAction", 423 ":HeapSnapShotTestAction", 424 ":HeapTrackerFirstTestAction", 425 ":HeapTrackerSecondTestAction", 426 ":HeapTrackerThirdTestAction", 427 ":JSMetadataTestAction", 428 ":RawHeapTranslateTestAction", 429 ] 430 if (is_mac) { 431 deps -= [ 432 ":GlobalHandleLeakDetectTestAction", 433 ":HProfTestAction", 434 ":HeapDumpTestAction", 435 ":HeapSamplingTestAction", 436 ":HeapSnapShotTestAction", 437 ":HeapTrackerFirstTestAction", 438 ":HeapTrackerSecondTestAction", 439 ":HeapTrackerThirdTestAction", 440 ":JSMetadataTestAction", 441 ":RawHeapTranslateTestAction", 442 ] 443 } else if (ets_runtime_enable_cmc_gc) { 444 # TODO: CMC-GC UT FIX LATER 445 deps -= [ 446 ":HProfTestAction", 447 ":HeapDumpTestAction", 448 ":HeapSnapShotTestAction", 449 ":HeapTrackerFirstTestAction", 450 ":HeapTrackerSecondTestAction", 451 ":HeapTrackerThirdTestAction", 452 ] 453 } 454} 455