1e509ee18Sopenharmony_ci# Copyright (c) 2021 Huawei Device Co., Ltd. 2e509ee18Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 3e509ee18Sopenharmony_ci# you may not use this file except in compliance with the License. 4e509ee18Sopenharmony_ci# You may obtain a copy of the License at 5e509ee18Sopenharmony_ci# 6e509ee18Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 7e509ee18Sopenharmony_ci# 8e509ee18Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 9e509ee18Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 10e509ee18Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11e509ee18Sopenharmony_ci# See the License for the specific language governing permissions and 12e509ee18Sopenharmony_ci# limitations under the License. 13e509ee18Sopenharmony_ci 14e509ee18Sopenharmony_ciimport("$build_root/config/clang/clang.gni") 15e509ee18Sopenharmony_ciimport("$build_root/templates/cxx/cxx.gni") 16e509ee18Sopenharmony_ci 17e509ee18Sopenharmony_ci# ohos test template 18e509ee18Sopenharmony_citemplate("_ohos_test") { 19e509ee18Sopenharmony_ci assert(defined(invoker.test_type), "test_type is required.") 20e509ee18Sopenharmony_ci assert(defined(invoker.module_out_path)) 21e509ee18Sopenharmony_ci 22e509ee18Sopenharmony_ci _deps = [] 23e509ee18Sopenharmony_ci if (defined(invoker.deps)) { 24e509ee18Sopenharmony_ci _deps += invoker.deps 25e509ee18Sopenharmony_ci } 26e509ee18Sopenharmony_ci 27e509ee18Sopenharmony_ci test_output_dir = 28e509ee18Sopenharmony_ci "$root_out_dir/tests/${invoker.test_type}/${invoker.module_out_path}" 29e509ee18Sopenharmony_ci 30e509ee18Sopenharmony_ci # copy fuzz config file 31e509ee18Sopenharmony_ci if (defined(invoker.fuzz_config_file)) { 32e509ee18Sopenharmony_ci fuzz_config_file = invoker.fuzz_config_file 33e509ee18Sopenharmony_ci script = "//build/ohos/testfwk/fuzz_config_file_copy.py" 34e509ee18Sopenharmony_ci _arguments = [] 35e509ee18Sopenharmony_ci _arguments += [ 36e509ee18Sopenharmony_ci "--fuzz-config-file-path", 37e509ee18Sopenharmony_ci rebase_path(fuzz_config_file, root_build_dir), 38e509ee18Sopenharmony_ci "--fuzz-config-file-output-path", 39e509ee18Sopenharmony_ci rebase_path(root_out_dir + "/tests/res", root_build_dir), 40e509ee18Sopenharmony_ci ] 41e509ee18Sopenharmony_ci exec_script(script, _arguments) 42e509ee18Sopenharmony_ci } 43e509ee18Sopenharmony_ci 44e509ee18Sopenharmony_ci _has_sources = defined(invoker.sources) && invoker.sources != [] 45e509ee18Sopenharmony_ci if (_has_sources) { 46e509ee18Sopenharmony_ci _c_sources_file = "$target_gen_dir/$target_name.sources" 47e509ee18Sopenharmony_ci write_file(_c_sources_file, rebase_path(invoker.sources, root_build_dir)) 48e509ee18Sopenharmony_ci } 49e509ee18Sopenharmony_ci 50e509ee18Sopenharmony_ci ohos_executable(target_name) { 51e509ee18Sopenharmony_ci forward_variables_from(invoker, 52e509ee18Sopenharmony_ci "*", 53e509ee18Sopenharmony_ci [ 54e509ee18Sopenharmony_ci "test_type", 55e509ee18Sopenharmony_ci "module_out_path", 56e509ee18Sopenharmony_ci "visibility", 57e509ee18Sopenharmony_ci "resource_config_file", 58e509ee18Sopenharmony_ci ]) 59e509ee18Sopenharmony_ci forward_variables_from(invoker, [ "visibility" ]) 60e509ee18Sopenharmony_ci 61e509ee18Sopenharmony_ci subsystem_name = "tests" 62e509ee18Sopenharmony_ci part_name = invoker.test_type 63e509ee18Sopenharmony_ci testonly = true 64e509ee18Sopenharmony_ci unit_test = true 65e509ee18Sopenharmony_ci output_name = "$target_name" 66e509ee18Sopenharmony_ci } 67e509ee18Sopenharmony_ci} 68e509ee18Sopenharmony_ci 69e509ee18Sopenharmony_citemplate("ohos_unittest") { 70e509ee18Sopenharmony_ci _ohos_test(target_name) { 71e509ee18Sopenharmony_ci forward_variables_from(invoker, "*") 72e509ee18Sopenharmony_ci test_type = "unittest" 73e509ee18Sopenharmony_ci deps = [] 74e509ee18Sopenharmony_ci if (defined(invoker.deps)) { 75e509ee18Sopenharmony_ci deps += invoker.deps 76e509ee18Sopenharmony_ci } 77e509ee18Sopenharmony_ci 78e509ee18Sopenharmony_ci # Add static link library judgment logic below 79e509ee18Sopenharmony_ci 80e509ee18Sopenharmony_ci if (defined(invoker.rtti_compile_flag) && invoker.rtti_compile_flag) { 81e509ee18Sopenharmony_ci deps += [ "//arkcompiler/toolchain/build/third_party_gn/googletest:gtest_rtti_main" ] 82e509ee18Sopenharmony_ci } else { 83e509ee18Sopenharmony_ci deps += [ 84e509ee18Sopenharmony_ci "//arkcompiler/toolchain/build/third_party_gn/googletest:gtest_main", 85e509ee18Sopenharmony_ci ] 86e509ee18Sopenharmony_ci } 87e509ee18Sopenharmony_ci } 88e509ee18Sopenharmony_ci} 89