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_root/config/clang/clang.gni") 15import("$build_root/templates/cxx/cxx.gni") 16 17# ohos test template 18template("_ohos_test") { 19 assert(defined(invoker.test_type), "test_type is required.") 20 assert(defined(invoker.module_out_path)) 21 22 _deps = [] 23 if (defined(invoker.deps)) { 24 _deps += invoker.deps 25 } 26 27 test_output_dir = 28 "$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}" 29 30 # copy fuzz config file 31 if (defined(invoker.fuzz_config_file)) { 32 fuzz_config_file = invoker.fuzz_config_file 33 script = "//build/ohos/testfwk/fuzz_config_file_copy.py" 34 _arguments = [] 35 _arguments += [ 36 "--fuzz-config-file-path", 37 rebase_path(fuzz_config_file, root_build_dir), 38 "--fuzz-config-file-output-path", 39 rebase_path(root_out_dir + "/tests/res", root_build_dir), 40 ] 41 exec_script(script, _arguments) 42 } 43 44 _has_sources = defined(invoker.sources) && invoker.sources != [] 45 if (_has_sources) { 46 _c_sources_file = "$target_gen_dir/$target_name.sources" 47 write_file(_c_sources_file, rebase_path(invoker.sources, root_build_dir)) 48 } 49 50 ohos_executable(target_name) { 51 forward_variables_from(invoker, 52 "*", 53 [ 54 "test_type", 55 "module_out_path", 56 "visibility", 57 "resource_config_file", 58 ]) 59 forward_variables_from(invoker, [ "visibility" ]) 60 61 subsystem_name = "tests" 62 part_name = invoker.test_type 63 testonly = true 64 unit_test = true 65 output_name = "$target_name" 66 } 67} 68 69template("ohos_unittest") { 70 _ohos_test(target_name) { 71 forward_variables_from(invoker, "*") 72 test_type = "unittest" 73 deps = [] 74 if (defined(invoker.deps)) { 75 deps += invoker.deps 76 } 77 78 deps += 79 [ "//arkcompiler/toolchain/build/third_party_gn/googletest:gtest_main" ] 80 } 81} 82