• 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/ohos.gni")
15import("//build/test.gni")
16if (precise_xts) {
17  import("//out/preloader/precise_run.gni")
18}
19
20declare_args() {
21  SUITES_OUTPUT_ROOT = "$root_out_dir/suites"
22  SUITE_ARCHIVE_DIR = "$root_out_dir/suites/archives"
23  TESTCONFIG_FILENAME = "Test.xml"
24  XTS_ROOT = "//test/xts"
25  ACTS_ROOT = "//test/xts/acts"
26  HATS_ROOT = "//test/xts/hats"
27  HITS_ROOT = "//test/xts/hits"
28  DCTS_ROOT = "//test/xts/dcts"
29
30  # create testsuite archive is time-consuming, do it only if necessary
31  make_archive = false
32  XTS_SUITENAME = getenv("XTS_SUITENAME")
33}
34
35template("ohos_testsuite_base") {
36  assert(defined(invoker.project_type),
37         "project_type is required in target ${target_name}")
38
39  _part_name = "common"
40
41  if (defined(invoker.part_name)) {
42    _part_name = invoker.part_name
43  }
44
45  precise_build_boolean = true
46  if (precise_xts && filter_include(precise_run,
47                                    [
48                                      "all",
49                                      _part_name,
50                                    ]) == []) {
51    print("precise_xts is on ,${_part_name} is not on build")
52    precise_build_boolean = false
53  }
54  if (precise_build_boolean) {
55    _subsystem_name = "common"
56    if (defined(invoker.subsystem_name)) {
57      _subsystem_name = invoker.subsystem_name
58    }
59    _project_type = invoker.project_type
60
61    _build_part_boolean = false
62    tmp_subsystem_part = "${_subsystem_name}_${_part_name}"
63    _part_script_judge = "//test/xts/tools/build/judgePart.py"
64    _script_judge_args1 = [
65      rebase_path("$preloader_output_dir") + "/parts_config.json",
66      tmp_subsystem_part,
67      "judgePart",
68    ]
69    _build_part_boolean_str = exec_script(rebase_path(_part_script_judge),
70                                          _script_judge_args1,
71                                          "trim string")
72    if (_build_part_boolean_str == "True") {
73      _build_part_boolean = true
74    }
75
76    if (_subsystem_name == "kernel" || _subsystem_name == "common") {
77      _build_part_boolean = true
78    }
79
80    _test_files = ""
81    if (defined(invoker.generated_testfiles)) {
82      foreach(file, invoker.generated_testfiles) {
83        _test_files =
84            _test_files + "," + rebase_path("$root_gen_dir") + "/" + file
85      }
86    }
87
88    _is_testbundle = defined(invoker.is_testbundle) && invoker.is_testbundle
89
90    if (defined(invoker.sub_output_dir)) {
91      _output_file_dir = rebase_path(
92              "$root_out_dir/tests/moduletest/${invoker.sub_output_dir}")
93    } else if (defined(invoker.module_out_path)) {
94      _output_file_dir = rebase_path(
95              "$root_out_dir/tests/moduletest/${invoker.module_out_path}")
96    } else {
97      _output_file_dir = rebase_path("$root_out_dir/tests/moduletest")
98    }
99    _output_file = "${_output_file_dir}/module_${target_name}"
100
101    if (_project_type == "gtest" || _project_type == "ctestbundle") {
102      _output_file = "${_output_file_dir}/${target_name}"
103      _archive_filename = "${target_name}"
104      if (_build_part_boolean == true) {
105        target("ohos_moduletest", "module_${target_name}") {
106          forward_variables_from(invoker, "*")
107          testonly = true
108        }
109      } else {
110        print(tmp_subsystem_part + " is not build")
111        if (defined(invoker.public_configs)) {
112          print(invoker.public_configs)
113        }
114        if (defined(invoker.external_deps)) {
115          print(invoker.external_deps)
116        }
117        if (defined(invoker.deps)) {
118          print(invoker.deps)
119        }
120        if (defined(invoker.configs)) {
121          print(invoker.configs)
122        }
123        if (defined(invoker.sources)) {
124          print(invoker.sources)
125        }
126        not_needed(invoker, "*")
127      }
128    } else if (_project_type == "zunit" || _project_type == "javatestbundle") {
129      _output_file = "${_output_file_dir}/module_${target_name}.dex"
130      _archive_filename = "${target_name}.dex"
131      if (_build_part_boolean == true) {
132        target("ohos_java_moduletest", "module_${target_name}") {
133          forward_variables_from(invoker, "*")
134          testonly = true
135        }
136      }
137    } else if (_project_type == "hostjunit") {
138      _output_file = "${_output_file_dir}/module_${target_name}.jar"
139      if (defined(invoker.final_jar_path)) {
140        _output_file = invoker.final_jar_path
141      }
142      _archive_filename = "${target_name}.jar"
143      if (_build_part_boolean == true) {
144        target("java_library", "module_${target_name}") {
145          forward_variables_from(invoker, "*")
146          is_host_library = true
147        }
148      }
149    } else if (_project_type == "testhap" || _project_type == "haptestbundle" ||
150               _project_type == "testhapassist" || _project_type == "testapp" ||
151               _project_type == "testappassist") {
152      assert(defined(invoker.hap_name),
153             "hap_name is required in target ${target_name}")
154      assert(!defined(invoker.final_hap_path),
155             "please use hap_name instead of final_hap_path")
156
157      _hap_name = invoker.hap_name
158      _final_hap_path = ""
159      _target_name = ""
160      _suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}"
161      subsystem_name = XTS_SUITENAME
162      if (subsystem_name == "acts") {
163        _suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/acts"
164      }
165      if (_project_type == "testhapassist") {
166        _final_hap_path = "${_suite_out_dir}/testcases/${_hap_name}.hap"
167        _target_name = target_name
168      } else {
169        _final_hap_path = "${SUITES_OUTPUT_ROOT}/haps/${_hap_name}.hap"
170        _target_name = "module_${target_name}"
171      }
172      _output_file = _final_hap_path
173      _archive_filename = "${_hap_name}.hap"
174      if (_build_part_boolean == true) {
175        if (_project_type == "testapp") {
176          target("ohos_app", _target_name) {
177            forward_variables_from(invoker, "*")
178            subsystem_name = XTS_SUITENAME
179            hap_out_dir = "${SUITES_OUTPUT_ROOT}/haps"
180            testonly = true
181          }
182        } else if (_project_type == "testappassist") {
183          target("ohos_app", target_name) {
184            forward_variables_from(invoker, "*")
185            subsystem_name = XTS_SUITENAME
186            hap_out_dir = "${_suite_out_dir}/testcases"
187            testonly = true
188          }
189        } else {
190          target("ohos_hap", _target_name) {
191            forward_variables_from(invoker, "*")
192            subsystem_name = XTS_SUITENAME
193            final_hap_path = _final_hap_path
194            testonly = true
195          }
196        }
197      } else {
198        print(tmp_subsystem_part + " is not build")
199        not_needed(invoker, "*")
200      }
201    } else if (_project_type == "pythontest") {
202      if (defined(invoker.outputs_dir)) {
203        _out_put_dir = invoker.outputs_dir
204        _archive_filename = "${_subsystem_name}/${_out_put_dir}"
205      } else {
206        _archive_filename = "${_subsystem_name}"
207      }
208      _test_files = invoker.output_file
209      _deps = []
210      if (defined(invoker.deps)) {
211        _deps = invoker.deps
212      }
213    } else if (_project_type == "js_test_hap") {
214      _hap_name = invoker.test_hap_name
215      _output_file = invoker.hap_source_path
216      _archive_filename = "${_hap_name}.hap"
217    }
218
219    _apilibrary_deps = ""
220    if (_is_testbundle && defined(invoker.deps)) {
221      foreach(dep, invoker.deps) {
222        _apilibrary_deps = _apilibrary_deps + "," + dep
223      }
224    }
225
226    if (_project_type != "pythontest" && _project_type != "js_test_hap" &&
227        _project_type != "testhapassist" && _project_type != "testappassist") {
228      _deps = [ ":module_${target_name}" ]
229    } else if (_project_type == "pythontest") {
230      print("this is pythontest")
231    } else if (_project_type != "testhapassist" &&
232               _project_type != "testappassist") {
233      _deps = []
234    }
235    _suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}"
236
237    _archive_testfile = ""
238    subsystem_name = XTS_SUITENAME
239    if (subsystem_name == "acts") {
240      _suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/acts"
241    }
242    if (_project_type == "testhapassist" || _project_type == "testappassist") {
243      _archive_testfile =
244          "${_suite_out_dir}/testcases/module_${_archive_filename}"
245    } else if (_project_type == "testapp") {
246      _hap_name = invoker.hap_name
247      if (_hap_name == "validator" && subsystem_name == "acts") {
248        _suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/acts-validator"
249        _archive_testfile = "${_suite_out_dir}/testcases/${_archive_filename}"
250      } else {
251        _archive_testfile = "${_suite_out_dir}/testcases/${_archive_filename}"
252      }
253    } else {
254      _archive_testfile = "${_suite_out_dir}/testcases/${_archive_filename}"
255    }
256    _arguments = [
257      "build_module_with_testbundle",
258      "--build_gen_dir",
259      rebase_path("$root_gen_dir"),
260      "--build_target_name",
261      target_name,
262      "--buildgen_testfile",
263      rebase_path(_output_file),
264      "--project_path",
265      rebase_path("."),
266      "--test_xml",
267      rebase_path(TESTCONFIG_FILENAME),
268      "--project_type",
269      _project_type,
270      "--suite_out_dir",
271      rebase_path("${_suite_out_dir}"),
272      "--archive_testfile",
273      rebase_path("${_archive_testfile}"),
274    ]
275
276    if (_subsystem_name != "") {
277      _arguments += [
278        "--subsystem_name",
279        _subsystem_name,
280      ]
281    }
282    if (_part_name != "") {
283      _arguments += [
284        "--part_name",
285        _part_name,
286      ]
287    }
288    if (_apilibrary_deps != "") {
289      _arguments += [
290        "--apilibrary_deps",
291        _apilibrary_deps,
292      ]
293    }
294
295    if (_test_files != "") {
296      _arguments += [
297        "--test_files",
298        _test_files,
299      ]
300    }
301    if (_build_part_boolean == true && _project_type != "testhapassist" &&
302        _project_type != "testappassist") {
303      action(target_name) {
304        deps = _deps
305        script = rebase_path("//test/xts/tools/build/suite.py")
306        args = _arguments
307        outputs = [ _archive_testfile ]
308        testonly = true
309      }
310    } else if (_build_part_boolean == false) {
311      action(target_name) {
312        script = rebase_path("//test/xts/tools/build/judgePart.py")
313        args = _arguments
314        outputs = [ _archive_testfile ]
315        testonly = true
316      }
317      if (defined(_deps)) {
318        print(_deps)
319      }
320    }
321  } else {
322    group(target_name) {
323      print(target_name + " is not build")
324      not_needed(invoker, "*")
325    }
326  }
327}
328
329template("ohos_moduletest_suite") {
330  target("ohos_testsuite_base", "${target_name}") {
331    forward_variables_from(invoker, "*")
332    if (!defined(module_out_path)) {
333      module_out_path = "xts/modules"
334    }
335    project_type = "gtest"
336  }
337}
338
339template("ohos_hap_suite") {
340  target("ohos_testsuite_base", "${target_name}") {
341    forward_variables_from(invoker, "*")
342
343    # auto add HJUnitRunner entry ability and test-framework
344    if (defined(hap_profile)) {
345      # NOTE:: the GN tool disallow source files located in the ${out_dir}
346      # so we put the generated files in the xts dir. remember to REMOVE these.
347      _profile_relative_path = rebase_path(hap_profile, rebase_path(XTS_ROOT))
348      _fixed_profile_path =
349          "${XTS_ROOT}/autogen_apiobjs/${_profile_relative_path}"
350      _fixer_script = rebase_path(
351              "//test/xts/tools/build/adapter/haptest_manifest_fixer.py")
352      exec_script(_fixer_script,
353                  [
354                    "add_entryability",
355                    "--raw_file=" + rebase_path(hap_profile),
356                    "--dest_file=" + rebase_path(_fixed_profile_path),
357                  ])
358      hap_profile = _fixed_profile_path
359    }
360
361    if (defined(deps)) {
362      deps += [ "//test/xts/tools/hjunit:testkit_harmonyjunitrunner_java" ]
363    } else {
364      deps = [ "//test/xts/tools/hjunit:testkit_harmonyjunitrunner_java" ]
365    }
366
367    project_type = "testhap"
368  }
369}
370
371template("ohos_js_hap_suite") {
372  target("ohos_testsuite_base", "${target_name}") {
373    forward_variables_from(invoker, "*")
374    project_type = "testhap"
375
376    #js_build_mode = "debug"
377  }
378}
379
380template("ohos_js_app_suite") {
381  target("ohos_testsuite_base", "${target_name}") {
382    forward_variables_from(invoker, "*")
383    project_type = "testapp"
384  }
385}
386
387template("ohos_shell_app_suite") {
388  target("ohos_adapter_shell_app_suite", "${target_name}") {
389    forward_variables_from(invoker, "*")
390  }
391}
392
393template("ohos_prebuilt_suite") {
394  assert(!defined(invoker.source_files) || !defined(invoker.jar_path) ||
395             !defined(invoker.source_dir),
396         "source_files, jar_path or source_dir must be specified one.")
397  assert(!defined(invoker.final_jar_path),
398         "final_jar_path is not allowed in target ${target_name}")
399
400  if (defined(invoker.jar_path)) {
401    _output_name = "${target_name}.jar"
402    if (defined(invoker.output_name)) {
403      _output_name = "${invoker.output_name}.jar"
404    }
405
406    _output_type = "tools"
407    if (defined(invoker.output_type)) {
408      _output_type = invoker.output_type
409    }
410
411    _final_jar_path =
412        "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/${_output_type}/${_output_name}"
413
414    target("java_prebuilt", "${target_name}") {
415      forward_variables_from(invoker, "*")
416      final_jar_path = _final_jar_path
417      is_host_library = true
418    }
419  } else {
420    assert(defined(invoker.output_dir),
421           "output_dir is require in target ${target_name}")
422    _outputs = []
423    _copy_args = [
424      "--method_name",
425      "copy_file",
426    ]
427    _deps = []
428    _output_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/${invoker.output_dir}"
429    if (defined(invoker.source_dir)) {
430      _copy_args += [
431        "--arguments",
432        "output=" + rebase_path(_output_dir) + "#source_dirs=" +
433            rebase_path(invoker.source_dir) + "#to_dir=True",
434      ]
435      _outputs = [ _output_dir ]
436    } else if (defined(invoker.source_files)) {
437      _sources = ""
438      foreach(src, invoker.source_files) {
439        _sources = _sources + rebase_path(src) + ","
440      }
441      _copy_args += [
442        "--arguments",
443        "output=" + rebase_path(_output_dir) + "#sources=" + _sources +
444            "#to_dir=True",
445      ]
446      _outputs = [ _output_dir ]
447    }
448    if (defined(invoker.deps)) {
449      _deps = invoker.deps
450    }
451    action(target_name) {
452      script = rebase_path("//test/xts/tools/build/utils.py")
453      deps = _deps
454      args = _copy_args
455      outputs = _outputs
456    }
457  }
458}
459
460template("ohos_deploy_xdevice") {
461  _suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}"
462  subsystem_name = XTS_SUITENAME
463  if (subsystem_name == "acts") {
464    _hap_name = target_name
465    if (_hap_name == "validator") {
466      _suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/acts-validator"
467    } else {
468      _suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/acts"
469    }
470  }
471
472  _args = [
473    "build_xdevice",
474    "--source_dir",
475    rebase_path("//test/testfwk/xdevice"),
476    "--suite_out_dir",
477    rebase_path(_suite_out_dir),
478  ]
479
480  if (defined(invoker.configs_dir)) {
481    _args += [
482      "--configs_dir",
483      rebase_path(rebase_path(invoker.configs_dir)),
484    ]
485  }
486
487  if (defined(invoker.resources_dir)) {
488    _args += [
489      "--resources_dir",
490      rebase_path(rebase_path(invoker.resources_dir)),
491    ]
492  }
493
494  action(target_name) {
495    testonly = true
496    script = rebase_path("//test/xts/tools/build/suite.py")
497    args = _args
498    outputs = [
499      "${_suite_out_dir}/tools/xdevice-ohos-0.0.0.tar.gz",
500      "${_suite_out_dir}/tools/xdevice-0.0.0.tar.gz",
501      "${_suite_out_dir}/tools/xdevice-devicetest-0.0.0.tar.gz",
502      "${_suite_out_dir}/tools/run.sh",
503      "${_suite_out_dir}/tools/run.bat",
504    ]
505  }
506}
507
508template("ohos_test_suite") {
509  _output = "${SUITES_OUTPUT_ROOT}/${target_name}.zip"
510  _suite_path = rebase_path("${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}")
511  _suite_archive_dir = rebase_path("${SUITE_ARCHIVE_DIR}")
512  _prebuilts_files = rebase_path("//xts/resource")
513  _gen_args = [
514    "archive_suite",
515    "--suite_path",
516    _suite_path,
517    "--prebuilts_resource",
518    _prebuilts_files,
519    "--suite_archive_dir",
520    _suite_archive_dir,
521    "--make_archive",
522    "${make_archive}",
523  ]
524
525  _deps = []
526  if (defined(invoker.deps)) {
527    _deps += invoker.deps
528  }
529
530  action(target_name) {
531    testonly = true
532    script = rebase_path("//test/xts/tools/build/suite.py")
533    deps = _deps
534    args = _gen_args
535    outputs = [ _output ]
536  }
537}
538
539template("pythontest_suite") {
540  assert(defined(invoker.script), "script is required in target ${target_name}")
541
542  _subsystem_name = ""
543  if (defined(invoker.subsystem_name)) {
544    _subsystem_name = invoker.subsystem_name
545  } else {
546    _local_path = rebase_path(".")
547    _args1 = [
548      "--method_name",
549      "get_subsystem_name",
550      "--arguments",
551      "path=${_local_path}",
552    ]
553    _subsystem_name =
554        exec_script(rebase_path("//test/xts/tools/build/utils.py"),
555                    _args1,
556                    "trim string")
557  }
558  _deps = []
559  if (defined(invoker.deps)) {
560    _deps = invoker.deps + _deps
561  }
562  _outputs_dir = ""
563  if (defined(invoker.outputs_dir)) {
564    _outputs_dir = invoker.outputs_dir
565  }
566  _output_file = rebase_path("${invoker.script}")
567
568  target("ohos_testsuite_base", "${target_name}") {
569    project_type = "pythontest"
570    subsystem_name = _subsystem_name
571    output_file = _output_file
572    deps = _deps
573    outputs_dir = _outputs_dir
574  }
575}
576
577template("executable_suite") {
578  assert(defined(invoker.suite_name),
579         "suite_name is required in target ${target_name}")
580  _suite_name = invoker.suite_name
581  _local_path = rebase_path(".")
582  _args1 = [
583    "--method_name",
584    "get_subsystem_name",
585    "--arguments",
586    "path=${_local_path}",
587  ]
588  _subsystem_name = exec_script(rebase_path("//test/xts/tools/build/utils.py"),
589                                _args1,
590                                "trim string")
591
592  _outputs_dir = ""
593  if (defined(invoker.outputs_dir)) {
594    _outputs_dir = "${invoker.outputs_dir}"
595  }
596  ohos_executable(target_name) {
597    forward_variables_from(invoker,
598                           "*",
599                           [
600                             "test_type",
601                             "module_out_path",
602                             "visibility",
603                           ])
604    forward_variables_from(invoker, [ "visibility" ])
605    if (!defined(deps)) {
606      deps = []
607    }
608
609    subsystem_name = "tests"
610    part_name = "ssts"
611    ohos_test = true
612    testonly = true
613    output_name = "$target_name"
614    test_output_dir = "$SUITES_OUTPUT_ROOT/${_suite_name}/testcases/${_subsystem_name}/${_outputs_dir}"
615    if (defined(invoker.output_extension)) {
616      output_extension = invoker.output_extension
617    }
618  }
619}
620
621template("js_hap_suite") {
622  assert(defined(invoker.hap_source_path),
623         "hap_source_path is required in target ${target_name}")
624  assert(defined(invoker.test_hap_name),
625         "test_hap_name is required in target ${target_name}")
626  if (defined(invoker.deps)) {
627    _deps = invoker.deps
628  }
629  target("ohos_testsuite_base", "${target_name}") {
630    forward_variables_from(invoker, "*")
631    project_type = "js_test_hap"
632  }
633}
634
635template("ohos_hap_assist_suite") {
636  target("ohos_testsuite_base", target_name) {
637    forward_variables_from(invoker, "*")
638    project_type = "testhapassist"
639  }
640}
641
642template("ohos_app_assist_suite") {
643  target("ohos_testsuite_base", target_name) {
644    forward_variables_from(invoker, "*")
645    project_type = "testappassist"
646  }
647}
648
649template("ohos_sh_assist_suite") {
650  _part_name = "common"
651
652  if (defined(invoker.part_name)) {
653    _part_name = invoker.part_name
654  }
655
656  precise_build_boolean = true
657  if (precise_xts && filter_include(precise_run,
658                                    [
659                                      "all",
660                                      _part_name,
661                                    ]) == []) {
662    print("precise_xts is on ,${_part_name} is not on build")
663    precise_build_boolean = false
664  }
665
666  if (precise_build_boolean) {
667    action(target_name) {
668      forward_variables_from(invoker, "*")
669    }
670  } else {
671    group(target_name) {
672      print(target_name + " is not build")
673      not_needed(invoker, "*")
674    }
675  }
676}
677template("merge_xts_notice") {
678  _deps = []
679  if (defined(invoker.deps)) {
680    _deps += invoker.deps
681  }
682  target = invoker.target
683  action(target_name) {
684    _merged_notice_txt = "$root_out_dir/suites/${target}/NOTICE.txt"
685    _merged_notice_gz = "$root_out_dir/suites/${target}/NOTICE.xml.gz"
686    depfile =
687        "$root_out_dir/gen/build/ohos/packages/merge_system_notice_file_phone.d"
688
689    testonly = true
690    outputs = [
691      _merged_notice_txt,
692      _merged_notice_gz,
693    ]
694
695    deps = _deps
696
697    script = "//build/ohos/notice/merge_notice_files.py"
698    _notice_root_dir = "NOTICE_FILES"
699
700    args = [
701      "--image-name",
702      "system",
703      "--notice-root-dir",
704      rebase_path(_notice_root_dir, root_build_dir),
705      "--output-notice-txt",
706      rebase_path(_merged_notice_txt, root_out_dir),
707      "--output-notice-gz",
708      rebase_path(_merged_notice_gz, root_out_dir),
709      "--notice-title",
710      "Notices for files contained in the system filesystem image in this directory:",
711      "--static-library-notice-dir",
712      rebase_path(static_libraries_notice_dir, root_build_dir),
713      "--target-cpu",
714      target_cpu,
715      "--depfile",
716      rebase_path(depfile, root_build_dir),
717    ]
718  }
719}
720