• 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/config/clang/clang.gni")
15import("//build/config/python.gni")
16import("//build/ohos.gni")
17import("//build/ohos_var.gni")
18import("//build/templates/cxx/cxx.gni")
19
20if (!is_arkui_x) {
21  import("//build/rust/rustc_toolchain.gni")
22}
23
24template("_testcase_resources") {
25  assert(defined(invoker.testcase_target_name))
26  assert(defined(invoker.test_output_dir))
27  assert(defined(invoker.module_out_path))
28
29  _deps = []
30  if (defined(invoker.deps)) {
31    _deps += invoker.deps
32  }
33  action_with_pydeps(target_name) {
34    if (defined(invoker.testonly)) {
35      testonly = invoker.testonly
36    }
37    deps = _deps
38    inputs = []
39    script = "//build/ohos/testfwk/testcase_resource_copy.py"
40    output_file = "$target_out_dir/$target_name.json"
41    outputs = [ output_file ]
42    depfile = "$target_gen_dir/$target_name.d"
43    args = []
44    if (defined(invoker.resource_config_file)) {
45      args += [
46        "--resource-config-file",
47        rebase_path(invoker.resource_config_file, root_build_dir),
48      ]
49      inputs += [ invoker.resource_config_file ]
50    }
51    args += [
52      "--depfile",
53      rebase_path(depfile, root_build_dir),
54      "--testcase-target-name",
55      invoker.testcase_target_name,
56      "--part-build-out-path",
57      rebase_path(root_out_dir, root_build_dir),
58      "--resource-output-path",
59      rebase_path(invoker.test_output_dir + "/resource", root_build_dir),
60      "--module-out-path",
61      invoker.module_out_path,
62      "--output-file",
63      rebase_path(output_file, root_build_dir),
64    ]
65  }
66}
67
68# ohos test template
69template("_ohos_test") {
70  assert(defined(invoker.test_type), "test_type is required.")
71  assert(defined(invoker.module_out_path))
72
73  _deps = []
74  if (defined(invoker.deps)) {
75    _deps += invoker.deps
76  }
77
78  if (defined(invoker.crate_type)) {
79    _deps += [ "//build/rust:libstd.dylib.so" ]
80  }
81
82  test_output_dir =
83      "$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}"
84
85  # generate module list file in gn stage
86  if (!skip_generate_module_list_file) {
87    _gen_module_list_script = "//build/ohos/testfwk/gen_module_list_files.py"
88    _arguments = [
89      "--target",
90      target_name,
91      "--target_label",
92      get_label_info(":$target_name", "label_with_toolchain"),
93      "--source_dir",
94      rebase_path(get_label_info(":$target_name", "dir"), root_build_dir),
95      "--test_type",
96      invoker.test_type,
97    ]
98
99    _module_list_file = "$root_out_dir/module_list_files/${invoker.module_out_path}/$target_name.mlf"
100
101    _arguments += [
102      "--output_dir",
103      rebase_path(test_output_dir, root_build_dir),
104      "--module_list_file",
105      rebase_path(_module_list_file, root_build_dir),
106    ]
107    exec_script(_gen_module_list_script, _arguments)
108  }
109
110  # copy testcase resource
111  testcase_target_name = target_name
112  _testcase_resources("${testcase_target_name}_resource_copy") {
113    if (defined(invoker.resource_config_file)) {
114      resource_config_file = invoker.resource_config_file
115    }
116    module_out_path = invoker.module_out_path
117    deps = _deps
118    testonly = true
119  }
120
121  # copy fuzz config file
122  if (defined(invoker.fuzz_config_file)) {
123    fuzz_config_file = invoker.fuzz_config_file
124    action("${target_name}_copy_fuzz_config_file") {
125      script = "//build/ohos/testfwk/fuzz_config_file_copy.py"
126      inputs = [ fuzz_config_file ]
127      args = []
128      args += [
129        "--fuzz-config-file-path",
130        rebase_path(fuzz_config_file, root_build_dir),
131        "--fuzz-config-file-output-path",
132        rebase_path(root_out_dir + "/tests/res", root_build_dir),
133      ]
134      outputs = [ "$target_out_dir/${target_name}_result.txt" ]
135    }
136  }
137
138  _has_sources = defined(invoker.sources) && invoker.sources != []
139  if (_has_sources) {
140    _c_sources_file = "$target_gen_dir/$target_name.sources"
141    write_file(_c_sources_file, rebase_path(invoker.sources, root_build_dir))
142  }
143  write_file("$test_output_dir/${target_name}_path.txt",
144             get_label_info(":$target_name", "dir"),
145             "string")
146
147  ohos_executable(target_name) {
148    forward_variables_from(invoker,
149                           "*",
150                           [
151                             "test_type",
152                             "module_out_path",
153                             "visibility",
154                           ])
155    forward_variables_from(invoker, [ "visibility" ])
156    if (!defined(deps)) {
157      deps = []
158    }
159    deps += [ ":${testcase_target_name}_resource_copy" ]
160    if (defined(invoker.fuzz_config_file)) {
161      deps += [ ":${target_name}_copy_fuzz_config_file" ]
162    }
163
164    subsystem_name = "tests"
165    part_name = invoker.test_type
166    ohos_test = true
167    testonly = true
168    output_name = "$target_name"
169  }
170}
171
172template("ohos_unittest") {
173  _ohos_test(target_name) {
174    testonly = true
175    forward_variables_from(invoker, "*")
176    test_type = "unittest"
177    deps = []
178    external_deps = []
179    if (defined(invoker.deps)) {
180      deps += invoker.deps
181    }
182    if (defined(invoker.external_deps)) {
183      external_deps += invoker.external_deps
184    }
185
186    # Add static link library judgment logic below
187
188    if (defined(invoker.rtti_compile_flag) && invoker.rtti_compile_flag) {
189      external_deps += [ "googletest:gtest_rtti_main" ]
190    } else {
191      external_deps += [
192        "googletest:gtest_main",
193        "googletest:gtest",
194      ]
195    }
196  }
197}
198
199template("ohos_moduletest") {
200  _ohos_test(target_name) {
201    testonly = true
202    forward_variables_from(invoker, "*")
203    test_type = "moduletest"
204    deps = []
205    external_deps = []
206    if (defined(invoker.deps)) {
207      deps += invoker.deps
208    }
209    if (defined(invoker.external_deps)) {
210      external_deps += invoker.external_deps
211    }
212    external_deps += [ "googletest:gtest_main" ]
213  }
214}
215
216template("ohos_systemtest") {
217  _ohos_test(target_name) {
218    forward_variables_from(invoker, "*")
219    test_type = "systemtest"
220  }
221}
222
223template("ohos_performancetest") {
224  _ohos_test(target_name) {
225    testonly = true
226    forward_variables_from(invoker, "*")
227    test_type = "performance"
228    deps = []
229    external_deps = []
230    if (defined(invoker.deps)) {
231      deps += invoker.deps
232    }
233    deps +=
234        [ "//test/testfwk/developer_test/aw/cxx/hwext:performance_test_static" ]
235    if (defined(invoker.external_deps)) {
236      external_deps += invoker.external_deps
237    }
238    external_deps += [ "googletest:gtest_main" ]
239  }
240}
241
242template("ohos_securitytest") {
243  _ohos_test(target_name) {
244    forward_variables_from(invoker, "*")
245    test_type = "security"
246  }
247}
248
249template("ohos_reliabilitytest") {
250  _ohos_test(target_name) {
251    forward_variables_from(invoker, "*")
252    test_type = "reliability"
253  }
254}
255
256template("ohos_distributedtest") {
257  _ohos_test(target_name) {
258    forward_variables_from(invoker, "*")
259    test_type = "distributedtest"
260    deps = []
261    if (defined(invoker.deps)) {
262      deps += invoker.deps
263    }
264    deps += [
265      "//test/testfwk/developer_test/aw/cxx/distributed:distributedtest_lib",
266    ]
267  }
268}
269
270template("ohos_fuzztest") {
271  # Judge the compliation library.
272  # Do the FUZZ compliation if the compliation library is the musl.
273  if (use_musl) {
274    _ohos_test(target_name) {
275      forward_variables_from(invoker,
276                             "*",
277                             [
278                               "deps",
279                               "cflags",
280                             ])
281      test_type = "fuzztest"
282      deps = []
283      if (defined(invoker.deps)) {
284        deps += invoker.deps
285      }
286      cflags = []
287      if (defined(invoker.cflags)) {
288        cflags += invoker.cflags
289      }
290      cflags += [
291        "-fno-sanitize-coverage=trace-pc-guard,edge,trace-cmp,indirect-calls,8bit-counters",
292        "-fsanitize=fuzzer",
293      ]
294      if (target_cpu == "arm64") {
295        libs =
296            [ "$clang_lib_base_path/aarch64-linux-ohos/libclang_rt.fuzzer.a" ]
297      } else if (target_cpu == "x86_64") {
298        libs = [ "$clang_lib_base_path/x86_64-linux-ohos/libclang_rt.fuzzer.a" ]
299      } else {
300        libs = [ "$clang_lib_base_path/arm-linux-ohos/libclang_rt.fuzzer.a" ]
301      }
302    }
303  } else {
304    group(target_name) {
305      not_needed(invoker, "*")
306    }
307  }
308}
309
310template("ohos_benchmarktest") {
311  _ohos_test(target_name) {
312    testonly = true
313    forward_variables_from(invoker, "*", [ "deps" ])
314    test_type = "benchmark"
315
316    deps = []
317    external_deps = []
318    if (defined(invoker.deps)) {
319      deps += invoker.deps
320    }
321    if (defined(invoker.external_deps)) {
322      external_deps += invoker.external_deps
323    }
324    external_deps += [ "benchmark:benchmark" ]
325  }
326}
327
328template("_test_py_file_copy") {
329  assert(defined(invoker.sources), "sources is required.")
330  assert(defined(invoker.target_base_dir))
331  assert(defined(invoker.copy_output_dir))
332
333  action_with_pydeps(target_name) {
334    forward_variables_from(invoker,
335                           [
336                             "sources",
337                             "testonly",
338                             "visibility",
339                           ])
340    script = "//build/ohos/testfwk/test_py_file_copy.py"
341    deps = []
342    if (defined(invoker.deps)) {
343      deps += invoker.deps
344    }
345
346    depfile = "$target_gen_dir/$target_name.d"
347    outfile = "$target_out_dir/$target_name.out"
348    outputs = [ outfile ]
349    args = [
350      "--target-base-dir",
351      rebase_path(invoker.target_base_dir, root_build_dir),
352      "--copy-output-dir",
353      rebase_path(invoker.copy_output_dir, root_build_dir),
354      "--outfile",
355      rebase_path(outfile, root_build_dir),
356      "--depfile",
357      rebase_path(depfile, root_build_dir),
358      "--source-files",
359    ]
360    args += rebase_path(sources, root_build_dir)
361  }
362}
363
364# python test template
365template("_ohos_test_py") {
366  assert(defined(invoker.test_type), "test_type is required.")
367  assert(defined(invoker.sources), "sources is required.")
368
369  _gen_module_list_script = "//build/ohos/testfwk/gen_module_list_files.py"
370  _arguments = [
371    "--target",
372    target_name,
373    "--target_label",
374    get_label_info(":$target_name", "label_with_toolchain"),
375    "--source_dir",
376    rebase_path(get_label_info(":$target_name", "dir"), root_build_dir),
377    "--test_type",
378    invoker.test_type,
379  ]
380
381  if (defined(invoker.module_out_path)) {
382    test_output_dir =
383        "$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}"
384    _module_list_file = "$root_out_dir/module_list_files/${invoker.module_out_path}/$target_name.mlf"
385  } else {
386    test_output_dir = "$root_out_dir/tests/${invoker.test_type}"
387    _module_list_file = "$root_out_dir/module_list_files/$target_name.mlf"
388  }
389
390  _arguments += [
391    "--output_dir",
392    rebase_path(test_output_dir, root_build_dir),
393    "--module_list_file",
394    rebase_path(_module_list_file, root_build_dir),
395  ]
396  exec_script(_gen_module_list_script, _arguments)
397
398  _test_py_file_copy(target_name) {
399    testonly = true
400    target_base_dir = get_label_info(":$target_name", "dir")
401    copy_output_dir = test_output_dir
402    sources = get_path_info(invoker.sources, "abspath")
403  }
404}
405
406template("ohos_unittest_py") {
407  _ohos_test_py(target_name) {
408    forward_variables_from(invoker, "*")
409    test_type = "unittest"
410  }
411}
412
413template("ohos_moduletest_py") {
414  _ohos_test_py(target_name) {
415    forward_variables_from(invoker, "*")
416    test_type = "moduletest"
417  }
418}
419
420template("ohos_systemtest_py") {
421  _ohos_test_py(target_name) {
422    forward_variables_from(invoker, "*")
423    test_type = "systemtest"
424  }
425}
426
427template("ohos_performancetest_py") {
428  _ohos_test_py(target_name) {
429    forward_variables_from(invoker, "*")
430    test_type = "performance"
431  }
432}
433
434template("ohos_securitytest_py") {
435  _ohos_test_py(target_name) {
436    forward_variables_from(invoker, "*")
437    test_type = "security"
438  }
439}
440
441template("ohos_reliabilitytest_py") {
442  _ohos_test_py(target_name) {
443    forward_variables_from(invoker, "*")
444    test_type = "reliability"
445  }
446}
447
448template("ohos_distributedtest_py") {
449  _ohos_test_py(target_name) {
450    forward_variables_from(invoker, "*")
451    test_type = "distributedtest"
452  }
453}
454
455template("ohos_fuzztest_py") {
456  _ohos_test_py(target_name) {
457    forward_variables_from(invoker, "*")
458    test_type = "fuzztest"
459  }
460}
461
462#js api test template
463template("ohos_js_test") {
464  assert(defined(invoker.test_type), "test_type must be defined.")
465  assert(defined(invoker.hap_profile), "hap_profile must be defined.")
466  assert(defined(invoker.module_out_path), "module_out_path must be defined.")
467
468  # generate module list file in gn stage
469  _gen_module_list_script = "//build/ohos/testfwk/gen_module_list_files.py"
470  _arguments = [
471    "--target",
472    target_name,
473    "--target_label",
474    get_label_info(":$target_name", "label_with_toolchain"),
475    "--source_dir",
476    rebase_path(get_label_info(":$target_name", "dir"), root_build_dir),
477    "--test_type",
478    invoker.test_type,
479  ]
480
481  _test_output_dir =
482      "$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}"
483  _module_list_file = "$root_out_dir/module_list_files/${invoker.module_out_path}/$target_name.mlf"
484
485  write_file("$_test_output_dir/${target_name}_path.txt",
486             get_label_info(":$target_name", "dir"),
487             "string")
488
489  _arguments += [
490    "--output_dir",
491    rebase_path(_test_output_dir, root_build_dir),
492    "--module_list_file",
493    rebase_path(_module_list_file, root_build_dir),
494  ]
495  exec_script(_gen_module_list_script, _arguments)
496
497  # copy testcase resource
498  testcase_target_name = target_name
499  _testcase_resources("${testcase_target_name}_resource_copy") {
500    if (defined(invoker.resource_config_file)) {
501      resource_config_file = invoker.resource_config_file
502    }
503    module_out_path = invoker.module_out_path
504    test_output_dir = _test_output_dir
505  }
506
507  _suite_path = get_label_info(":$target_name", "dir")
508  _template_path = "//test/testfwk/developer_test/libs/js_template"
509  _target_path = "${_template_path}/$target_name"
510  _target_js_copy = "${target_name}__js_copy"
511  action_with_pydeps(_target_js_copy) {
512    script = "//build/ohos/testfwk/test_js_file_copy.py"
513    outputs = [ "$target_out_dir/$target_name.out" ]
514    args = [
515      "--suite_path",
516      rebase_path(_suite_path, root_build_dir),
517      "--template_path",
518      rebase_path(_template_path, root_build_dir),
519      "--target_path",
520      rebase_path(_target_path, root_build_dir),
521      "--test_output_dir",
522      rebase_path(_test_output_dir, root_build_dir),
523      "--target_name",
524      testcase_target_name,
525    ]
526    deps = [ ":${testcase_target_name}_resource_copy" ]
527  }
528
529  _target_js_assets = "${target_name}__intl_js_assets"
530  ohos_js_assets(_target_js_assets) {
531    source_dir = "${_target_path}/src/main/js/default"
532    deps = [ ":$_target_js_copy" ]
533  }
534  _target_resources = "${target_name}__resources"
535  ohos_resources(_target_resources) {
536    sources = [ "${_target_path}/src/main/resources" ]
537    deps = [ ":$_target_js_assets" ]
538    hap_profile = invoker.hap_profile
539  }
540
541  ohos_hap(target_name) {
542    forward_variables_from(invoker,
543                           "*",
544                           [
545                             "test_type",
546                             "module_out_path",
547                             "visibility",
548                           ])
549    forward_variables_from(invoker, [ "visibility" ])
550
551    deps = [
552      ":$_target_js_assets",
553      ":$_target_resources",
554    ]
555    final_hap_path = "$_test_output_dir/$target_name.hap"
556    js_build_mode = "debug"
557    testonly = true
558  }
559}
560
561template("ohos_js_unittest") {
562  ohos_js_test(target_name) {
563    forward_variables_from(invoker, "*")
564    test_type = "unittest"
565  }
566}
567
568template("ohos_js_stage_test") {
569  if (defined(invoker.part_name)) {
570    _part_name = invoker.part_name
571  }
572  if (defined(invoker.subsystem_name)) {
573    _subsystem_name = invoker.subsystem_name
574  }
575  if (defined(invoker.test_type)) {
576    _test_type = invoker.test_type
577  }
578  _build_part_boolean = true
579
580  if (defined(invoker.module_out_path)) {
581    _test_output_dir =
582        "$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}"
583  } else {
584    _test_output_dir = "$root_out_dir/tests/${invoker.test_type}"
585  }
586  write_file("$_test_output_dir/${target_name}_path.txt",
587             get_label_info(":$target_name", "dir"),
588             "string")
589
590  # generate module list file in gn stage
591  if (!skip_generate_module_list_file) {
592    _gen_module_list_script = "//build/ohos/testfwk/gen_module_list_files.py"
593    _arguments = [
594      "--target",
595      target_name,
596      "--target_label",
597      get_label_info(":$target_name", "label_with_toolchain"),
598      "--source_dir",
599      rebase_path(get_label_info(":$target_name", "dir"), root_build_dir),
600      "--test_type",
601      _test_type,
602    ]
603
604    _module_list_file = "$root_out_dir/module_list_files/${invoker.module_out_path}/$target_name.mlf"
605
606    _arguments += [
607      "--output_dir",
608      rebase_path(_test_output_dir, root_build_dir),
609      "--module_list_file",
610      rebase_path(_module_list_file, root_build_dir),
611    ]
612    exec_script(_gen_module_list_script, _arguments)
613  }
614
615  assert(defined(invoker.hap_name),
616         "hap_name is required in target ${target_name}")
617  assert(!defined(invoker.final_hap_path),
618         "please use hap_name instead of final_hap_path")
619  _hap_name = invoker.hap_name
620  _final_hap_path = ""
621  _target_name = ""
622  _final_hap_path =
623      "$root_out_dir/tests/haps/${invoker.module_out_path}/${_hap_name}.hap"
624  _target_name = "module_${target_name}"
625
626  _archive_filename = "${_hap_name}.hap"
627
628  if (_build_part_boolean == true) {
629    target("ohos_hap", _target_name) {
630      forward_variables_from(invoker, "*")
631      final_hap_path = _final_hap_path
632      testonly = true
633    }
634  } else {
635    print(tmp_subsystem_part + " is not build")
636    print(_target_name)
637    if (defined(invoker.certificate_profile)) {
638      print(invoker.certificate_profile)
639    }
640    if (defined(invoker.ets2abc)) {
641      print(invoker.ets2abc)
642    }
643    if (defined(invoker.deps)) {
644      print(invoker.deps)
645    }
646    if (defined(invoker.hap_profile)) {
647      print(invoker.hap_profile)
648    }
649    if (defined(invoker.testonly)) {
650      print(invoker.testonly)
651    }
652  }
653
654  _deps = [ ":module_${target_name}" ]
655
656  _archive_testfile = "$root_out_dir/tests/$_test_type/${invoker.module_out_path}/${_archive_filename}"
657  _arguments = []
658  _arguments = [
659    "--build_target_name",
660    target_name,
661    "--project_path",
662    rebase_path("."),
663    "--archive_testfile",
664    rebase_path("${_archive_testfile}"),
665    "--final_hap_path",
666    rebase_path("${_final_hap_path}"),
667    "--test_type",
668    _test_type,
669    "--module_out_path",
670    invoker.module_out_path,
671  ]
672  if (_subsystem_name != "") {
673    _arguments += [
674      "--subsystem_name",
675      _subsystem_name,
676    ]
677  }
678  if (_part_name != "") {
679    _arguments += [
680      "--part_name",
681      _part_name,
682    ]
683  }
684
685  action(target_name) {
686    deps = _deps
687    script = rebase_path("//build/ohos/testfwk/test_js_stage_file_copy.py")
688    args = _arguments
689    outputs = [ _archive_testfile ]
690    testonly = true
691  }
692}
693
694template("ohos_js_stage_unittest") {
695  ohos_js_stage_test(target_name) {
696    forward_variables_from(invoker, "*")
697    test_type = "unittest"
698  }
699}
700
701template("ohos_rust_unittest") {
702  _target_name = target_name
703  _rustflags = []
704  _public_deps = [ "//build/rust/tests:original_libstd.so" ]
705  ohos_unittest("$_target_name") {
706    forward_variables_from(invoker, "*")
707    public_deps = _public_deps
708    if (!defined(invoker.crate_name)) {
709      crate_name = _target_name
710    }
711    crate_type = "bin"
712    if (defined(invoker.crate_type)) {
713      assert(invoker.crate_type == crate_type,
714             "crate_type should be $crate_type or use default value.")
715    }
716
717    if (defined(invoker.rustc_lints)) {
718      rustc_lints = invoker.rustc_lints
719    }
720    if (defined(invoker.clippy_lints)) {
721      clippy_lints = invoker.clippy_lints
722    }
723
724    if (!defined(rustc_lints) && !defined(clippy_lints)) {
725      file_path =
726          get_path_info(get_path_info(invoker.sources, "dir"), "abspath")
727      file_path_split = string_split(file_path[0], "/")
728      source_dir_begin = file_path_split[2]
729
730      if (source_dir_begin == "openharmony") {
731        _rustflags += allowAllLints
732      } else if (source_dir_begin == "prebuilts") {
733        _rustflags += allowAllLints
734      } else if (source_dir_begin == "vendor") {
735        _rustflags += rustcVendorLints
736        _rustflags += clippyVendorLints
737      } else if (source_dir_begin == "device") {
738        _rustflags += rustcVendorLints
739        _rustflags += clippyVendorLints
740      } else {
741        _rustflags += rustcOhosLints
742        _rustflags += clippyOhosLints
743      }
744    }
745
746    if (defined(rustc_lints)) {
747      if (invoker.rustc_lints == "openharmony") {
748        _rustflags += rustcOhosLints
749      } else if (rustc_lints == "vendor") {
750        _rustflags += rustcVendorLints
751      } else if (rustc_lints == "none") {
752        _rustflags += allowAllLints
753      }
754    }
755    if (defined(clippy_lints)) {
756      if (invoker.clippy_lints == "openharmony") {
757        _rustflags += clippyOhosLints
758      } else if (clippy_lints == "vendor") {
759        _rustflags += clippyVendorLints
760      } else if (clippy_lints == "none") {
761        _rustflags += allowAllLints
762      }
763    }
764    if (!defined(rustflags)) {
765      rustflags = _rustflags
766    } else {
767      rustflags += _rustflags
768    }
769    edition = rust_default_edition
770    if (defined(invoker.edition)) {
771      edition = invoker.edition
772    }
773    rustflags += [
774      "--cfg",
775      "feature=\"test\"",
776      "--test",
777      "-Csymbol-mangling-version=v0",
778      "--edition=${edition}",
779    ]
780  }
781}
782
783template("ohos_rust_systemtest") {
784  _target_name = target_name
785  _rustflags = []
786  _public_deps = [ "//build/rust/tests:original_libstd.so" ]
787  ohos_systemtest("$_target_name") {
788    forward_variables_from(invoker, "*")
789    public_deps = _public_deps
790    if (!defined(invoker.crate_name)) {
791      crate_name = _target_name
792    }
793    crate_type = "bin"
794    if (defined(invoker.crate_type)) {
795      assert(invoker.crate_type == crate_type,
796             "crate_type should be $crate_type or use default value.")
797    }
798
799    if (defined(invoker.rustc_lints)) {
800      rustc_lints = invoker.rustc_lints
801    }
802    if (defined(invoker.clippy_lints)) {
803      clippy_lints = invoker.clippy_lints
804    }
805
806    if (!defined(rustc_lints) && !defined(clippy_lints)) {
807      file_path =
808          get_path_info(get_path_info(invoker.sources, "dir"), "abspath")
809      file_path_split = string_split(file_path[0], "/")
810      source_dir_begin = file_path_split[2]
811
812      if (source_dir_begin == "openharmony") {
813        _rustflags += allowAllLints
814      } else if (source_dir_begin == "prebuilts") {
815        _rustflags += allowAllLints
816      } else if (source_dir_begin == "vendor") {
817        _rustflags += rustcVendorLints
818        _rustflags += clippyVendorLints
819      } else if (source_dir_begin == "device") {
820        _rustflags += rustcVendorLints
821        _rustflags += clippyVendorLints
822      } else {
823        _rustflags += rustcOhosLints
824        _rustflags += clippyOhosLints
825      }
826    }
827
828    if (defined(rustc_lints)) {
829      if (invoker.rustc_lints == "openharmony") {
830        _rustflags += rustcOhosLints
831      } else if (rustc_lints == "vendor") {
832        _rustflags += rustcVendorLints
833      } else if (rustc_lints == "none") {
834        _rustflags += allowAllLints
835      }
836    }
837    if (defined(clippy_lints)) {
838      if (invoker.clippy_lints == "openharmony") {
839        _rustflags += clippyOhosLints
840      } else if (clippy_lints == "vendor") {
841        _rustflags += clippyVendorLints
842      } else if (clippy_lints == "none") {
843        _rustflags += allowAllLints
844      }
845    }
846    if (!defined(rustflags)) {
847      rustflags = _rustflags
848    } else {
849      rustflags += _rustflags
850    }
851    edition = rust_default_edition
852    if (defined(invoker.edition)) {
853      edition = invoker.edition
854    }
855    rustflags += [
856      "--cfg",
857      "feature=\"test\"",
858      "--test",
859      "-Csymbol-mangling-version=v0",
860      "--edition=${edition}",
861    ]
862  }
863}
864