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