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