1# Copyright (c) 2024 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("//base/startup/appspawn/appspawn.gni") 15import("//build/test.gni") 16 17ohos_unittest("AppSpawn_ut") { 18 module_out_path = "${module_output_path}" 19 deps = [] 20 defines = [ 21 "APPSPAWN_BASE_DIR=\"/data/appspawn_ut\"", 22 "APPSPAWN_LABEL=\"APPSPAWN_UT\"", 23 "APPSPAWN_TEST", 24 "APPSPAWN_DEBUG", 25 "DEBUG_BEGETCTL_BOOT", 26 "USER_TIMER_TO_CHECK", 27 "OHOS_DEBUG", 28 "GRAPHIC_PERMISSION_CHECK", 29 "capset=CapsetStub", 30 "unshare=UnshareStub", 31 "mount=MountStub", 32 "symlink=SymlinkStub", 33 "chdir=ChdirStub", 34 "chroot=ChrootStub", 35 "syscall=SyscallStub", 36 "umount2=Umount2Stub", 37 "access=AccessStub", 38 "dlopen=DlopenStub", 39 "dlsym=DlsymStub", 40 "dlclose=DlcloseStub", 41 "execv=ExecvStub", 42 "getprocpid=GetprocpidStub", 43 "setgroups=SetgroupsStub", 44 "setresgid=SetresgidStub", 45 "setresuid=SetresuidStub", 46 "setuid=SetuidStub", 47 "setgid=SetgidStub", 48 "execvp=ExecvpStub", 49 "ioctl=IoctlStub", 50 "execve=ExecveStub", 51 "setcon=SetconStub", 52 ] 53 54 include_dirs = [ 55 "${appspawn_path}", 56 "${appspawn_path}/common", 57 "${appspawn_path}/standard", 58 "${appspawn_path}/modules/modulemgr", 59 "${appspawn_path}/modules/ace_adapter", 60 "${appspawn_path}/modules/common", 61 "${appspawn_path}/modules/sandbox", 62 "${appspawn_path}/modules/sysevent", 63 "${appspawn_innerkits_path}/client", 64 "${appspawn_innerkits_path}/include", 65 "${appspawn_innerkits_path}/permission", 66 "${appspawn_path}/modules/module_engine/include", 67 "${appspawn_path}/test/mock", 68 "${appspawn_path}/test/unittest", 69 "${appspawn_path}/util/include", 70 ] 71 sources = [ 72 "${appspawn_path}/common/appspawn_server.c", 73 "${appspawn_path}/common/appspawn_trace.cpp", 74 "${appspawn_path}/modules/modulemgr/appspawn_modulemgr.c", 75 "${appspawn_path}/standard/appspawn_appmgr.c", 76 "${appspawn_path}/standard/appspawn_kickdog.c", 77 "${appspawn_path}/standard/appspawn_msgmgr.c", 78 "${appspawn_path}/standard/appspawn_service.c", 79 "${appspawn_path}/standard/nwebspawn_launcher.c", 80 "${appspawn_path}/util/src/appspawn_utils.c", 81 ] 82 83 # client 84 sources += [ 85 "${appspawn_innerkits_path}/client/appspawn_client.c", 86 "${appspawn_innerkits_path}/client/appspawn_msg.c", 87 "${appspawn_innerkits_path}/permission/appspawn_mount_permission.c", 88 ] 89 90 # modules sources 91 sources += [ 92 "${appspawn_path}/modules/ace_adapter/ace_adapter.cpp", 93 "${appspawn_path}/modules/ace_adapter/command_lexer.cpp", 94 "${appspawn_path}/modules/common/appspawn_adapter.cpp", 95 "${appspawn_path}/modules/common/appspawn_begetctl.c", 96 "${appspawn_path}/modules/common/appspawn_cgroup.c", 97 "${appspawn_path}/modules/common/appspawn_common.c", 98 "${appspawn_path}/modules/common/appspawn_dfx_dump.cpp", 99 "${appspawn_path}/modules/common/appspawn_namespace.c", 100 "${appspawn_path}/modules/common/appspawn_silk.c", 101 "${appspawn_path}/modules/nweb_adapter/nwebspawn_adapter.cpp", 102 "${appspawn_path}/modules/sandbox/appspawn_mount_template.c", 103 "${appspawn_path}/modules/sandbox/appspawn_permission.c", 104 "${appspawn_path}/modules/sandbox/appspawn_sandbox.c", 105 "${appspawn_path}/modules/sandbox/sandbox_cfgvar.c", 106 "${appspawn_path}/modules/sandbox/sandbox_expand.c", 107 "${appspawn_path}/modules/sandbox/sandbox_load.c", 108 "${appspawn_path}/modules/sandbox/sandbox_manager.c", 109 ] 110 111 # add stub 112 include_dirs += [ "${appspawn_path}/test/mock" ] 113 sources += [ 114 "${appspawn_path}/test/mock/app_spawn_stub.cpp", 115 "${appspawn_path}/test/mock/app_system_stub.c", 116 ] 117 118 # add test 119 include_dirs += [ "${appspawn_path}/test/unittest" ] 120 sources += [ 121 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp", 122 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_beget_test.cpp", 123 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_cgroup_test.cpp", 124 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_child_test.cpp", 125 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_cold_run_test.cpp", 126 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_command_lexer_test.cpp", 127 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp", 128 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp", 129 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp", 130 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandboxmgr_test.cpp", 131 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp", 132 "${appspawn_path}/test/unittest/app_spawn_standard_test/nweb_spawn_service_test.cpp", 133 "${appspawn_path}/test/unittest/app_spawn_test_helper.cpp", 134 ] 135 136 if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) { 137 sources += [ "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_test.cpp" ] 138 defines += [ "APPSPAWN_SANDBOX_NEW" ] 139 } else { 140 sources += [ 141 "${appspawn_path}/modules/sandbox/sandbox_utils.cpp", 142 "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp", 143 ] 144 } 145 146 configs = [ "${appspawn_path}:appspawn_config" ] 147 external_deps = [ 148 "ability_base:want", 149 "ability_runtime:app_manager", 150 "ability_runtime:appkit_native", 151 "ability_runtime:runtime", 152 "access_token:libtokenid_sdk", 153 "access_token:libtokensetproc_shared", 154 "ace_engine:ace_forward_compatibility", 155 "bundle_framework:appexecfwk_base", 156 "bundle_framework:appexecfwk_core", 157 "cJSON:cjson", 158 "c_utils:utils", 159 "config_policy:configpolicy_util", 160 "eventhandler:libeventhandler", 161 "hilog:libhilog", 162 "hitrace:hitrace_meter", 163 "init:libbegetutil", 164 "init:seccomp", 165 "ipc:ipc_core", 166 "napi:ace_napi", 167 "os_account:os_account_innerkits", 168 "resource_management:global_resmgr", 169 ] 170 if (enable_appspawn_dump_catcher) { 171 external_deps += [ "faultloggerd:libdfx_dumpcatcher" ] 172 } 173 if (asan_detector || is_asan) { 174 defines += [ "ASAN_DETECTOR" ] 175 sources += [ "${appspawn_path}/modules/asan/asan_detector.c" ] 176 } 177 178 if (build_selinux) { 179 defines += [ "WITH_SELINUX" ] 180 external_deps += [ 181 "selinux:libselinux", 182 "selinux_adapter:libhap_restorecon", 183 ] 184 } 185 186 if (appspawn_report_event) { 187 defines += [ "REPORT_EVENT" ] 188 external_deps += [ "hisysevent:libhisysevent" ] 189 sources += [ 190 "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp", 191 "${appspawn_path}/modules/sysevent/event_reporter.cpp", 192 ] 193 } 194 195 if (target_cpu == "arm64" || target_cpu == "x86_64" || 196 target_cpu == "riscv64") { 197 defines += [ "APPSPAWN_64" ] 198 } 199 200 if (dlp_permission_enable) { 201 cflags_cc = [ "-DWITH_DLP" ] 202 external_deps += [ "dlp_permission_service:libdlp_fuse" ] 203 } 204} 205