1# Copyright (c) 2024 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_frontend/es2panda/es2abc_config.gni")
15import("//arkcompiler/runtime_core/ark_config.gni")
16import("$ark_root/tests/test_helper.gni")
17
18abc2prog_test_configs = [
19  "$ark_root:ark_config",
20  "$ark_root/assembler:arkassembler_public_config",
21  "$ark_root/libpandabase:arkbase_public_config",
22  "$ark_root/libpandafile:arkfile_public_config",
23  sdk_libc_secshared_config,
24]
25
26abc2prog_test_deps = [
27  "$ark_root/abc2program:abc2program",
28  "$ark_root/assembler:libarkassembler_static",
29  "$ark_root/libpandabase:libarkbase_static",
30  "$ark_root/libpandafile:libarkfile_static",
31]
32
33test_ts_dir = "//arkcompiler/runtime_core/abc2program/tests/ts/"
34test_json_dir = "//arkcompiler/runtime_core/abc2program/tests/json/"
35
36abc2prog_test_ts_files = [
37  "HelloWorld",
38  "Annotations",
39]
40
41foreach(file, abc2prog_test_ts_files) {
42  es2abc_gen_abc("gen_${file}_abc") {
43    test_ts = "${test_ts_dir}${file}.ts"
44    test_abc = "$target_out_dir/${file}.abc"
45
46    src_js = rebase_path(test_ts)
47    dst_file = rebase_path(test_abc)
48    extra_args = [ "--module" ]
49    if (file == "Annotations") {
50      extra_args += [ "--enable-annotations" ]
51    }
52    in_puts = [ test_ts ]
53    out_puts = [ test_abc ]
54  }
55}
56
57abc2prog_debug_test_ts_files = [ "HelloWorld" ]
58
59foreach(file, abc2prog_debug_test_ts_files) {
60  es2abc_gen_abc("gen_${file}_debug_abc") {
61    test_ts = "${test_ts_dir}${file}.ts"
62    test_abc = "$target_out_dir/${file}Debug.abc"
63
64    src_js = rebase_path(test_ts)
65    dst_file = rebase_path(test_abc)
66    extra_args = [
67      "--debug",
68      "--module",
69    ]
70    in_puts = [ test_ts ]
71    out_puts = [ test_abc ]
72  }
73}
74
75abc2prog_test_json_files = [ "JsonTest" ]
76
77foreach(file, abc2prog_test_json_files) {
78  es2abc_gen_abc("gen_${file}_abc") {
79    test_json = "${test_json_dir}${file}.json"
80    test_abc = "$target_out_dir/${file}.abc"
81
82    src_js = rebase_path(test_json)
83    dst_file = rebase_path(test_abc)
84    extra_args = [
85      "--module",
86      "--merge-abc",
87    ]
88    in_puts = [ test_json ]
89    out_puts = [ test_abc ]
90  }
91}
92
93abc2prog_include_dirs = [
94  "$ark_root/abc2program",
95  "$ark_root/assembler",
96  "$target_gen_dir",
97  "$target_gen_dir/../",
98  "$target_gen_dir/../../assembler",
99]
100
101script_sources = [
102  "cpp_sources/abc2program_test_utils.cpp",
103  "cpp_sources/hello_world_test.cpp",
104]
105
106host_unittest_action("Abc2ProgScriptTest") {
107  module_out_path = module_output_path
108  sources = script_sources
109  include_dirs = abc2prog_include_dirs
110  configs = abc2prog_test_configs
111  deps = abc2prog_test_deps
112  test_abc_dir = rebase_path(target_out_dir)
113  test_abc_dump_dir = rebase_path(test_ts_dir)
114  defines = [
115    "GRAPH_TEST_ABC_DIR=\"${test_abc_dir}/\"",
116    "GRAPH_TEST_ABC_DUMP_DIR=\"${test_abc_dump_dir}/\"",
117  ]
118
119  foreach(file, abc2prog_test_ts_files) {
120    deps += [ ":gen_${file}_abc" ]
121  }
122  foreach(file, abc2prog_debug_test_ts_files) {
123    deps += [ ":gen_${file}_debug_abc" ]
124  }
125  foreach(file, abc2prog_test_json_files) {
126    deps += [ ":gen_${file}_abc" ]
127  }
128}
129
130group("host_unittest") {
131  testonly = true
132  deps = [ ":Abc2ProgScriptTestAction" ]
133}
134