• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 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("//build/lite/config/component/lite_component.gni")
15import("//test/xts/tools/lite/build/common.gni")
16
17declare_args() {
18  ohos_xts_test_args = ""
19}
20
21template("testsuite_base") {
22  assert(defined(invoker.project_type),
23         "project_type is required in target ${target_name}")
24  assert(defined(invoker.suite_name),
25         "suite_name is required in target ${target_name}")
26
27  _project_type = invoker.project_type
28  _suite_name = invoker.suite_name
29  _module_target_name = "module_${target_name}"
30  _deps = []
31  if (_project_type == "hctest") {
32    _module_name = "${target_name}"
33    if (defined(invoker.output_name)) {
34      _module_name = "${invoker.output_name}"
35    }
36    _output_file =
37        rebase_path("${root_out_dir}/libs/libmodule_${_module_name}.a")
38    _archive_filename = "lib${_module_name}.a"
39    target("static_library", "${_module_target_name}") {
40      forward_variables_from(invoker, "*")
41    }
42  } else if (_project_type == "hcpptest") {
43    _module_name = "${target_name}"
44    if (defined(invoker.output_name)) {
45      _module_name = "${invoker.output_name}"
46    }
47    _extension = ""
48    if (defined(invoker.output_extension)) {
49      _extension = ".${invoker.output_extension}"
50    }
51    _output_file =
52        rebase_path("${root_out_dir}/bin/${_module_target_name}${_extension}")
53    _archive_filename = "${_module_name}${_extension}"
54    target("executable", "${_module_target_name}") {
55      forward_variables_from(invoker, "*")
56    }
57  } else if (_project_type == "hctest_prebuilt") {
58    _output_file =
59        rebase_path("${root_out_dir}/libs/lib${_module_target_name}.a")
60    _archive_filename = "lib${_module_target_name}.a"
61    _deps += [ "//test/xts/tools/lite/hctest:hctest" ]
62    copy(_module_target_name) {
63      sources = invoker.sources
64      outputs = [ "${root_out_dir}/libs/lib${_module_target_name}.a" ]
65    }
66  }
67
68  _project_dir = rebase_path(".")
69
70  _deps += [ ":${_module_target_name}" ]
71  if (defined(invoker.deps)) {
72    _deps += invoker.deps
73  }
74  _subsystem_name = ""
75  if (defined(invoker.subsystem_name)) {
76    _subsystem_name = invoker.subsystem_name
77  } else {
78    _local_path = rebase_path(".")
79    _args1 = [
80      "--method_name",
81      "get_subsystem_name",
82      "--arguments",
83      "path=${_local_path}",
84    ]
85    _subsystem_name = exec_script(rebase_path("$BUILD_DIR_PREFIX/utils.py"),
86                                  _args1,
87                                  "trim string")
88  }
89  target("testsuite_common", target_name) {
90    suite_name = _suite_name
91    project_type = _project_type
92    subsystem_name = _subsystem_name
93    output_file = _output_file
94    project_dir = _project_dir
95    archive_filename = _archive_filename
96    deps = _deps
97  }
98}
99
100template("hctest_suite") {
101  _include_dirs = [
102    "//commonlibrary/utils_lite/include",
103    "//test/xts/tools/lite/hctest/include",
104    "//third_party/unity/src",
105    "//kernel/liteos_m/kal",
106    "//foundation/systemabilitymgr/samgr_lite/interfaces/kits/samgr",
107  ]
108
109  _deps = [ "//test/xts/tools/lite/hctest:hctest" ]
110  _defines = [ "UNITY_INCLUDE_CONFIG_H" ]
111  target("testsuite_base", "${target_name}") {
112    forward_variables_from(invoker, "*")
113    project_type = "hctest"
114    if (defined(include_dirs)) {
115      include_dirs += _include_dirs
116    } else {
117      include_dirs = _include_dirs
118    }
119    if (defined(deps)) {
120      deps += _deps
121    } else {
122      deps = _deps
123    }
124    if (defined(defines)) {
125      defines += _defines
126    } else {
127      defines = _defines
128    }
129  }
130}
131
132template("ctest_prebuilt_suite") {
133  assert(defined(invoker.sources),
134         "sources is required in target ${target_name}")
135  target("testsuite_base", "${target_name}") {
136    forward_variables_from(invoker, "*")
137    project_type = "hctest_prebuilt"
138  }
139}
140
141template("hcpptest_suite") {
142  target("testsuite_base", "${target_name}") {
143    forward_variables_from(invoker, "*")
144    project_type = "hcpptest"
145    output_extension = "bin"
146    _include_dirs = [
147      "//third_party/googletest/googletest/include",
148      "//third_party/googletest/googletest/src",
149    ]
150    if (defined(include_dirs)) {
151      include_dirs += _include_dirs
152    } else {
153      include_dirs = _include_dirs
154    }
155    _deps = [ "//test/xts/tools/lite/hcpptest:hcpptest_main" ]
156    if (defined(deps)) {
157      deps += _deps
158    } else {
159      deps = _deps
160    }
161  }
162}
163
164template("pythontest_suite") {
165  assert(defined(invoker.script), "script is required in target ${target_name}")
166  assert(defined(invoker.suite_name),
167         "suite_name is required in target ${target_name}")
168  _suite_name = invoker.suite_name
169  _project_dir = rebase_path(".")
170
171  _subsystem_name = ""
172  if (defined(invoker.subsystem_name)) {
173    _subsystem_name = invoker.subsystem_name
174  } else {
175    _local_path = rebase_path(".")
176    _args1 = [
177      "--method_name",
178      "get_subsystem_name",
179      "--arguments",
180      "path=${_local_path}",
181    ]
182    _subsystem_name = exec_script(rebase_path("$BUILD_DIR_PREFIX/utils.py"),
183                                  _args1,
184                                  "trim string")
185  }
186  _deps = []
187  if (defined(invoker.deps)) {
188    _deps = invoker.deps + _deps
189  }
190  _outputs_dir = ""
191  if (defined(invoker.outputs_dir)) {
192    _outputs_dir = invoker.outputs_dir
193  }
194  _output_file = rebase_path("${invoker.script}")
195
196  _archive_filename = "${target_name}"
197
198  target("testsuite_common", "${target_name}") {
199    suite_name = _suite_name
200    project_type = "pythontest"
201    subsystem_name = _subsystem_name
202    output_file = _output_file
203    project_dir = _project_dir
204    archive_filename = _archive_filename
205    deps = _deps
206    outputs_dir = _outputs_dir
207  }
208}
209
210template("test_suite") {
211  assert(defined(invoker.deps), "deps is required in target ${target_name}")
212  _output = "${SUITE_OUTPUT_PREFIX}${target_name}.zip"
213  _suite_path = rebase_path("${SUITE_OUTPUT_PREFIX}${target_name}")
214  _origin_target_name = target_name
215
216  target("deploy_suite", "${target_name}_xdevice") {
217    suite_name = _origin_target_name
218  }
219  _deps = [ ":${target_name}_xdevice" ]
220  if (defined(invoker.deps)) {
221    _deps += invoker.deps
222  }
223
224  if (defined(invoker.version)) {
225    _version = invoker.version
226    _out_dir = rebase_path("${_suite_path}/testcases")
227    _args1 = [
228      "--method_name",
229      "record_test_component_info",
230      "--arguments",
231      "out_dir=${_out_dir}#version=${_version}",
232    ]
233    action("${target_name}_generate_module_data") {
234      script = rebase_path("$BUILD_DIR_PREFIX/utils.py")
235      deps = _deps
236      args = _args1
237      outputs = [ "${SUITE_OUTPUT_PREFIX}/${_origin_target_name}/${SUITE_TESTCASES_NAME}/module_info.json" ]
238    }
239  }
240
241  _gen_args = [
242    "archive_suite",
243    "--suite_path",
244    _suite_path,
245    "--build_enabled",
246    "true",
247  ]
248
249  _deps += [ ":${target_name}_generate_module_data" ]
250  action(target_name) {
251    script = rebase_path("$BUILD_DIR_PREFIX/suite.py")
252    deps = _deps
253    args = _gen_args
254    outputs = [ _output ]
255  }
256}
257
258template("executable_suite") {
259  assert(defined(invoker.suite_name),
260         "suite_name is required in target ${target_name}")
261  _suite_name = invoker.suite_name
262  _local_path = rebase_path(".")
263  _args1 = [
264    "--method_name",
265    "get_subsystem_name",
266    "--arguments",
267    "path=${_local_path}",
268  ]
269  _subsystem_name = exec_script(rebase_path("$BUILD_DIR_PREFIX/utils.py"),
270                                _args1,
271                                "trim string")
272
273  _extension = ""
274  if (defined(invoker.output_extension)) {
275    _extension = ".${invoker.output_extension}"
276  }
277  _outputs_dir = ""
278  if (defined(invoker.outputs_dir)) {
279    _outputs_dir = "${invoker.outputs_dir}"
280  }
281
282  _module_target_name = "module_${target_name}"
283  _source_file = rebase_path("${root_out_dir}/bin/${target_name}${_extension}")
284  _origi_target = target_name
285  target("executable", "${_module_target_name}") {
286    forward_variables_from(invoker, "*")
287    output_name = _origi_target
288  }
289  _output_file = rebase_path(
290          "${SUITE_OUTPUT_PREFIX}${_suite_name}/${SUITE_TESTCASES_NAME}/${_subsystem_name}/${_outputs_dir}")
291
292  _args2 = [
293    "--method_name",
294    "copy_file",
295    "--arguments",
296    "output=${_output_file}#sources=${_source_file}",
297  ]
298  action(target_name) {
299    script = rebase_path("$BUILD_DIR_PREFIX/utils.py")
300    deps = [ ":${_module_target_name}" ]
301    args = _args2
302    outputs = [ "${SUITE_OUTPUT_PREFIX}${_suite_name}/${SUITE_TESTCASES_NAME}/${_subsystem_name}/${target_name}${_extension}" ]
303  }
304}
305
306template("open_source_suite") {
307  assert(defined(invoker.suite_name),
308         "suite_name is required in target ${target_name}")
309  assert(defined(invoker.exec_command_path),
310         "exec_script_path is required in target ${target_name}")
311  _suite_name = invoker.suite_name
312  _exec_command_path = invoker.exec_command_path
313  _exec_sub_dir = invoker.exec_sub_dir
314
315  _prebuild_command = invoker.prebuild_command
316
317  _output_files = ""
318  if (defined(invoker.build_args)) {
319    foreach(target_file, invoker.build_args) {
320      _output_files =
321          _output_files +
322          rebase_path("${_exec_command_path}/${_exec_sub_dir}/${target_file}") +
323          ","
324    }
325  } else {
326    _output_files = rebase_path("${_exec_command_path}")
327  }
328
329  _pre_build_deps = []
330  if (defined(invoker.deps)) {
331    _pre_build_deps += invoker.deps
332  }
333  target("build_ext_component", "prebuild_${target_name}") {
334    exec_path = rebase_path("${_exec_command_path}")
335    command = _prebuild_command
336    deps = _pre_build_deps
337  }
338
339  _subsystem_name = ""
340  if (defined(invoker.subsystem_name)) {
341    _subsystem_name = invoker.subsystem_name
342  } else {
343    _local_path = rebase_path(".")
344    _args1 = [
345      "--method_name",
346      "get_subsystem_name",
347      "--arguments",
348      "path=${_local_path}",
349    ]
350    _subsystem_name = exec_script(rebase_path("$BUILD_DIR_PREFIX/utils.py"),
351                                  _args1,
352                                  "trim string")
353  }
354
355  _archive_filename = "${target_name}"
356  _project_dir = rebase_path(".")
357
358  _build_deps = [ ":prebuild_${target_name}" ]
359
360  _outputs_dir = ""
361  if (defined(invoker.outputs_dir)) {
362    _outputs_dir = invoker.outputs_dir
363  }
364
365  target("testsuite_common", "${target_name}") {
366    suite_name = _suite_name
367    subsystem_name = _subsystem_name
368    project_type = "open_source_test"
369    project_dir = _project_dir
370    output_file = _output_files
371    archive_filename = _archive_filename
372    outputs_dir = _outputs_dir
373    deps = _build_deps
374  }
375}
376template("hjsunit_suite") {
377  assert(defined(invoker.suite_name),
378         "suite_name is required in target ${target_name}")
379  assert(defined(invoker.hap_name),
380         "hap_name is required in target ${target_name}")
381  _suite_name = invoker.suite_name
382  _hap_name = invoker.hap_name
383
384  _hap_sign = "true"
385  if (defined(invoker.need_sign)) {
386    _hap_sign = invoker.need_sign
387  }
388
389  _output_files = ","
390
391  _subsystem_name = ""
392  if (defined(invoker.subsystem_name)) {
393    _subsystem_name = invoker.subsystem_name
394  } else {
395    _local_path = rebase_path(".")
396    _args1 = [
397      "--method_name",
398      "get_subsystem_name",
399      "--arguments",
400      "path=${_local_path}",
401    ]
402    _subsystem_name = exec_script(rebase_path("$BUILD_DIR_PREFIX/utils.py"),
403                                  _args1,
404                                  "trim string")
405  }
406
407  _archive_filename = "${target_name}"
408  _project_dir = rebase_path(".")
409
410  target("testsuite_common", "${target_name}") {
411    suite_name = _suite_name
412    subsystem_name = _subsystem_name
413    project_type = "hjsunit"
414    project_dir = _project_dir
415    output_file = _output_files
416    archive_filename = _archive_filename
417    hap_name = _hap_name
418    hap_sign = _hap_sign
419  }
420}
421