代码拉取完成,页面将自动刷新
同步操作将从 OpenHarmony/build 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/config/clang/clang.gni")
import("//build/config/python.gni")
import("//build/ohos.gni")
import("//build/ohos_var.gni")
import("//build/templates/cxx/cxx.gni")
template("_testcase_resources") {
assert(defined(invoker.testcase_target_name))
assert(defined(invoker.test_output_dir))
assert(defined(invoker.module_out_path))
_deps = []
if (defined(invoker.deps)) {
_deps += invoker.deps
}
action_with_pydeps(target_name) {
if (defined(invoker.testonly)) {
testonly = invoker.testonly
}
deps = _deps
inputs = []
script = "//build/ohos/testfwk/testcase_resource_copy.py"
output_file = "$target_out_dir/$target_name.json"
outputs = [ output_file ]
depfile = "$target_gen_dir/$target_name.d"
args = []
if (defined(invoker.resource_config_file)) {
args += [
"--resource-config-file",
rebase_path(invoker.resource_config_file, root_build_dir),
]
inputs += [ invoker.resource_config_file ]
}
args += [
"--depfile",
rebase_path(depfile, root_build_dir),
"--testcase-target-name",
invoker.testcase_target_name,
"--part-build-out-path",
rebase_path(root_out_dir, root_build_dir),
"--resource-output-path",
rebase_path(invoker.test_output_dir + "/resource", root_build_dir),
"--module-out-path",
invoker.module_out_path,
"--output-file",
rebase_path(output_file, root_build_dir),
]
}
}
# ohos test template
template("_ohos_test") {
assert(defined(invoker.test_type), "test_type is required.")
assert(defined(invoker.module_out_path))
_deps = []
if (defined(invoker.deps)) {
_deps += invoker.deps
}
# generate module list file in gn stage
_gen_module_list_script = "//build/ohos/testfwk/gen_module_list_files.py"
_arguments = [
"--target",
target_name,
"--target_label",
get_label_info(":$target_name", "label_with_toolchain"),
"--source_dir",
rebase_path(get_label_info(":$target_name", "dir"), root_build_dir),
"--test_type",
invoker.test_type,
]
test_output_dir =
"$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}"
_module_list_file = "$root_out_dir/module_list_files/${invoker.module_out_path}/$target_name.mlf"
_arguments += [
"--output_dir",
rebase_path(test_output_dir, root_build_dir),
"--module_list_file",
rebase_path(_module_list_file, root_build_dir),
]
exec_script(_gen_module_list_script, _arguments)
# copy testcase resource
testcase_target_name = target_name
_testcase_resources("${testcase_target_name}_resource_copy") {
if (defined(invoker.resource_config_file)) {
resource_config_file = invoker.resource_config_file
}
module_out_path = invoker.module_out_path
deps = _deps
testonly = true
}
# copy fuzz config file
if (defined(invoker.fuzz_config_file)) {
fuzz_config_file = invoker.fuzz_config_file
script = "//build/ohos/testfwk/fuzz_config_file_copy.py"
_arguments = []
_arguments += [
"--fuzz-config-file-path",
rebase_path(fuzz_config_file, root_build_dir),
"--fuzz-config-file-output-path",
rebase_path(root_out_dir + "/tests/res", root_build_dir),
]
exec_script(script, _arguments)
}
_has_sources = defined(invoker.sources) && invoker.sources != []
if (_has_sources) {
_c_sources_file = "$target_gen_dir/$target_name.sources"
write_file(_c_sources_file, rebase_path(invoker.sources, root_build_dir))
}
ohos_executable(target_name) {
forward_variables_from(invoker,
"*",
[
"test_type",
"module_out_path",
"visibility",
])
forward_variables_from(invoker, [ "visibility" ])
if (!defined(deps)) {
deps = []
}
deps += [ ":${testcase_target_name}_resource_copy" ]
subsystem_name = "tests"
part_name = invoker.test_type
ohos_test = true
testonly = true
output_name = "$target_name"
}
}
template("ohos_unittest") {
_ohos_test(target_name) {
forward_variables_from(invoker, "*")
test_type = "unittest"
deps = []
if (defined(invoker.deps)) {
deps += invoker.deps
}
deps += [ "//third_party/googletest:gtest_main" ]
}
}
template("ohos_moduletest") {
_ohos_test(target_name) {
forward_variables_from(invoker, "*")
test_type = "moduletest"
deps = []
if (defined(invoker.deps)) {
deps += invoker.deps
}
deps += [ "//third_party/googletest:gtest_main" ]
}
}
template("ohos_systemtest") {
_ohos_test(target_name) {
forward_variables_from(invoker, "*")
test_type = "systemtest"
}
}
template("ohos_performancetest") {
_ohos_test(target_name) {
forward_variables_from(invoker, "*")
test_type = "performance"
deps = []
if (defined(invoker.deps)) {
deps += invoker.deps
}
deps += [
"//test/developertest/aw/cxx/hwext:performance_test_static",
"//third_party/googletest:gtest_main",
]
}
}
template("ohos_securitytest") {
_ohos_test(target_name) {
forward_variables_from(invoker, "*")
test_type = "security"
}
}
template("ohos_reliabilitytest") {
_ohos_test(target_name) {
forward_variables_from(invoker, "*")
test_type = "reliability"
}
}
template("ohos_distributedtest") {
_ohos_test(target_name) {
forward_variables_from(invoker, "*")
test_type = "distributedtest"
deps = []
if (defined(invoker.deps)) {
deps += invoker.deps
}
deps += [ "//test/developertest/aw/cxx/distributed:distributedtest_lib" ]
}
}
template("ohos_fuzztest") {
# Judge the compliation library.
# Do the FUZZ compliation if the compliation library is the musl.
if (use_musl) {
_ohos_test(target_name) {
forward_variables_from(invoker,
"*",
[
"deps",
"cflags",
])
test_type = "fuzztest"
deps = []
if (defined(invoker.deps)) {
deps += invoker.deps
}
cflags = []
if (defined(invoker.cflags)) {
cflags += invoker.cflags
}
cflags += [
"-fno-sanitize-coverage=trace-pc-guard,edge,trace-cmp,indirect-calls,8bit-counters",
"-fsanitize=fuzzer",
]
if (target_cpu == "arm64") {
libs =
[ "$clang_lib_base_path/aarch64-linux-ohos/libclang_rt.fuzzer.a" ]
} else if (target_cpu == "x86_64") {
libs = [ "$clang_lib_base_path/x86_64-linux-ohos/libclang_rt.fuzzer.a" ]
} else {
libs = [ "$clang_lib_base_path/arm-linux-ohos/libclang_rt.fuzzer.a" ]
}
}
} else {
group(target_name) {
not_needed(invoker, "*")
}
}
}
template("ohos_benchmarktest") {
_ohos_test(target_name) {
forward_variables_from(invoker, "*", [ "deps" ])
test_type = "benchmark"
deps = []
if (defined(invoker.deps)) {
deps += invoker.deps
}
deps += [ "//third_party/benchmark:benchmark" ]
}
}
template("_test_py_file_copy") {
assert(defined(invoker.sources), "sources is required.")
assert(defined(invoker.target_base_dir))
assert(defined(invoker.copy_output_dir))
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"sources",
"testonly",
"visibility",
])
script = "//build/ohos/testfwk/test_py_file_copy.py"
deps = []
if (defined(invoker.deps)) {
deps += invoker.deps
}
depfile = "$target_gen_dir/$target_name.d"
outfile = "$target_out_dir/$target_name.out"
outputs = [ outfile ]
args = [
"--target-base-dir",
rebase_path(invoker.target_base_dir, root_build_dir),
"--copy-output-dir",
rebase_path(invoker.copy_output_dir, root_build_dir),
"--outfile",
rebase_path(outfile, root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
"--source-files",
]
args += rebase_path(sources, root_build_dir)
}
}
# python test template
template("_ohos_test_py") {
assert(defined(invoker.test_type), "test_type is required.")
assert(defined(invoker.sources), "sources is required.")
_gen_module_list_script = "//build/ohos/testfwk/gen_module_list_files.py"
_arguments = [
"--target",
target_name,
"--target_label",
get_label_info(":$target_name", "label_with_toolchain"),
"--source_dir",
rebase_path(get_label_info(":$target_name", "dir"), root_build_dir),
"--test_type",
invoker.test_type,
]
if (defined(invoker.module_out_path)) {
test_output_dir =
"$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}"
_module_list_file = "$root_out_dir/module_list_files/${invoker.module_out_path}/$target_name.mlf"
} else {
test_output_dir = "$root_out_dir/tests/${invoker.test_type}"
_module_list_file = "$root_out_dir/module_list_files/$target_name.mlf"
}
_arguments += [
"--output_dir",
rebase_path(test_output_dir, root_build_dir),
"--module_list_file",
rebase_path(_module_list_file, root_build_dir),
]
exec_script(_gen_module_list_script, _arguments)
_test_py_file_copy(target_name) {
testonly = true
target_base_dir = get_label_info(":$target_name", "dir")
copy_output_dir = test_output_dir
sources = get_path_info(invoker.sources, "abspath")
}
}
template("ohos_unittest_py") {
_ohos_test_py(target_name) {
forward_variables_from(invoker, "*")
test_type = "unittest"
}
}
template("ohos_moduletest_py") {
_ohos_test_py(target_name) {
forward_variables_from(invoker, "*")
test_type = "moduletest"
}
}
template("ohos_systemtest_py") {
_ohos_test_py(target_name) {
forward_variables_from(invoker, "*")
test_type = "systemtest"
}
}
template("ohos_performancetest_py") {
_ohos_test_py(target_name) {
forward_variables_from(invoker, "*")
test_type = "performance"
}
}
template("ohos_securitytest_py") {
_ohos_test_py(target_name) {
forward_variables_from(invoker, "*")
test_type = "security"
}
}
template("ohos_reliabilitytest_py") {
_ohos_test_py(target_name) {
forward_variables_from(invoker, "*")
test_type = "reliability"
}
}
template("ohos_distributedtest_py") {
_ohos_test_py(target_name) {
forward_variables_from(invoker, "*")
test_type = "distributedtest"
}
}
template("ohos_fuzztest_py") {
_ohos_test_py(target_name) {
forward_variables_from(invoker, "*")
test_type = "fuzztest"
}
}
#js api test template
template("ohos_js_test") {
assert(defined(invoker.test_type), "test_type must be defined.")
assert(defined(invoker.hap_profile), "hap_profile must be defined.")
assert(defined(invoker.module_out_path), "module_out_path must be defined.")
# generate module list file in gn stage
_gen_module_list_script = "//build/ohos/testfwk/gen_module_list_files.py"
_arguments = [
"--target",
target_name,
"--target_label",
get_label_info(":$target_name", "label_with_toolchain"),
"--source_dir",
rebase_path(get_label_info(":$target_name", "dir"), root_build_dir),
"--test_type",
invoker.test_type,
]
_test_output_dir =
"$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}"
_module_list_file = "$root_out_dir/module_list_files/${invoker.module_out_path}/$target_name.mlf"
_arguments += [
"--output_dir",
rebase_path(_test_output_dir, root_build_dir),
"--module_list_file",
rebase_path(_module_list_file, root_build_dir),
]
exec_script(_gen_module_list_script, _arguments)
# copy testcase resource
testcase_target_name = target_name
_testcase_resources("${testcase_target_name}_resource_copy") {
if (defined(invoker.resource_config_file)) {
resource_config_file = invoker.resource_config_file
}
module_out_path = invoker.module_out_path
test_output_dir = _test_output_dir
}
_suite_path = get_label_info(":$target_name", "dir")
_template_path = "//test/developertest/libs/js_template"
_target_path = "${_template_path}/$target_name"
_target_js_copy = "${target_name}__js_copy"
action_with_pydeps(_target_js_copy) {
script = "//build/ohos/testfwk/test_js_file_copy.py"
outputs = [ "$target_out_dir/$target_name.out" ]
args = [
"--suite_path",
rebase_path(_suite_path, root_build_dir),
"--template_path",
rebase_path(_template_path, root_build_dir),
"--target_path",
rebase_path(_target_path, root_build_dir),
]
deps = [ ":${testcase_target_name}_resource_copy" ]
}
_target_js_assets = "${target_name}__intl_js_assets"
ohos_js_assets(_target_js_assets) {
source_dir = "${_target_path}/src/main/js/default"
deps = [ ":$_target_js_copy" ]
}
_target_resources = "${target_name}__resources"
ohos_resources(_target_resources) {
sources = [ "${_target_path}/src/main/resources" ]
deps = [ ":$_target_js_assets" ]
hap_profile = invoker.hap_profile
}
ohos_hap(target_name) {
forward_variables_from(invoker,
"*",
[
"test_type",
"module_out_path",
"visibility",
])
forward_variables_from(invoker, [ "visibility" ])
deps = [
":$_target_js_assets",
":$_target_resources",
]
final_hap_path = "$_test_output_dir/$target_name.hap"
js_build_mode = "debug"
testonly = true
}
}
template("ohos_js_unittest") {
ohos_js_test(target_name) {
forward_variables_from(invoker, "*")
test_type = "unittest"
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。