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_command_lexer_test.cpp",
126    "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp",
127    "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_module_interface_test.cpp",
128    "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandboxmgr_test.cpp",
129    "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_service_test.cpp",
130    "${appspawn_path}/test/unittest/app_spawn_standard_test/nweb_spawn_service_test.cpp",
131    "${appspawn_path}/test/unittest/app_spawn_test_helper.cpp",
132  ]
133
134  if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) {
135    sources += [ "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_test.cpp" ]
136    defines += [ "APPSPAWN_SANDBOX_NEW" ]
137  } else {
138    sources += [
139      "${appspawn_path}/modules/sandbox/sandbox_utils.cpp",
140      "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp",
141    ]
142  }
143
144  configs = [ "${appspawn_path}:appspawn_config" ]
145  external_deps = [
146    "ability_base:want",
147    "ability_runtime:app_manager",
148    "ability_runtime:appkit_native",
149    "ability_runtime:runtime",
150    "access_token:libtokenid_sdk",
151    "access_token:libtokensetproc_shared",
152    "ace_engine:ace_forward_compatibility",
153    "bundle_framework:appexecfwk_base",
154    "bundle_framework:appexecfwk_core",
155    "cJSON:cjson",
156    "c_utils:utils",
157    "config_policy:configpolicy_util",
158    "eventhandler:libeventhandler",
159    "hilog:libhilog",
160    "hitrace:hitrace_meter",
161    "init:libbegetutil",
162    "init:seccomp",
163    "ipc:ipc_core",
164    "napi:ace_napi",
165    "os_account:os_account_innerkits",
166    "resource_management:global_resmgr",
167  ]
168  if (enable_appspawn_dump_catcher) {
169    external_deps += [ "faultloggerd:libdfx_dumpcatcher" ]
170  }
171  if (asan_detector || is_asan) {
172    defines += [ "ASAN_DETECTOR" ]
173    sources += [ "${appspawn_path}/modules/asan/asan_detector.c" ]
174  }
175
176  if (build_selinux) {
177    defines += [ "WITH_SELINUX" ]
178    external_deps += [
179      "selinux:libselinux",
180      "selinux_adapter:libhap_restorecon",
181    ]
182  }
183
184  if (appspawn_report_event) {
185    defines += [ "REPORT_EVENT" ]
186    external_deps += [ "hisysevent:libhisysevent" ]
187    sources += [
188      "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp",
189      "${appspawn_path}/modules/sysevent/event_reporter.cpp",
190    ]
191  }
192
193  if (target_cpu == "arm64" || target_cpu == "x86_64" ||
194      target_cpu == "riscv64") {
195    defines += [ "APPSPAWN_64" ]
196  }
197
198  if (dlp_permission_enable) {
199    cflags_cc = [ "-DWITH_DLP" ]
200    external_deps += [ "dlp_permission_service:libdlp_fuse" ]
201  }
202}
203
204ohos_unittest("AppSpawn_coldrun_ut") {
205  module_out_path = "${module_output_path}"
206  deps = []
207  defines = [
208    "APPSPAWN_BASE_DIR=\"/data/appspawn_ut\"",
209    "APPSPAWN_LABEL=\"APPSPAWN_UT\"",
210    "APPSPAWN_TEST",
211    "APPSPAWN_DEBUG",
212    "DEBUG_BEGETCTL_BOOT",
213    "USER_TIMER_TO_CHECK",
214    "OHOS_DEBUG",
215    "GRAPHIC_PERMISSION_CHECK",
216    "capset=CapsetStub",
217    "unshare=UnshareStub",
218    "mount=MountStub",
219    "symlink=SymlinkStub",
220    "chdir=ChdirStub",
221    "chroot=ChrootStub",
222    "syscall=SyscallStub",
223    "umount2=Umount2Stub",
224    "access=AccessStub",
225    "dlopen=DlopenStub",
226    "dlsym=DlsymStub",
227    "dlclose=DlcloseStub",
228    "execv=ExecvStub",
229    "getprocpid=GetprocpidStub",
230    "setgroups=SetgroupsStub",
231    "setresgid=SetresgidStub",
232    "setresuid=SetresuidStub",
233    "setuid=SetuidStub",
234    "setgid=SetgidStub",
235    "execvp=ExecvpStub",
236    "ioctl=IoctlStub",
237    "execve=ExecveStub",
238    "setcon=SetconStub",
239  ]
240
241  include_dirs = [
242    "${appspawn_path}",
243    "${appspawn_path}/common",
244    "${appspawn_path}/standard",
245    "${appspawn_path}/modules/modulemgr",
246    "${appspawn_path}/modules/ace_adapter",
247    "${appspawn_path}/modules/common",
248    "${appspawn_path}/modules/sandbox",
249    "${appspawn_path}/modules/sysevent",
250    "${appspawn_innerkits_path}/client",
251    "${appspawn_innerkits_path}/include",
252    "${appspawn_innerkits_path}/permission",
253    "${appspawn_path}/modules/module_engine/include",
254    "${appspawn_path}/test/mock",
255    "${appspawn_path}/test/unittest",
256    "${appspawn_path}/util/include",
257  ]
258  sources = [
259    "${appspawn_path}/common/appspawn_server.c",
260    "${appspawn_path}/common/appspawn_trace.cpp",
261    "${appspawn_path}/modules/modulemgr/appspawn_modulemgr.c",
262    "${appspawn_path}/standard/appspawn_appmgr.c",
263    "${appspawn_path}/standard/appspawn_kickdog.c",
264    "${appspawn_path}/standard/appspawn_msgmgr.c",
265    "${appspawn_path}/standard/appspawn_service.c",
266    "${appspawn_path}/standard/nwebspawn_launcher.c",
267    "${appspawn_path}/util/src/appspawn_utils.c",
268  ]
269
270  # client
271  sources += [
272    "${appspawn_innerkits_path}/client/appspawn_client.c",
273    "${appspawn_innerkits_path}/client/appspawn_msg.c",
274    "${appspawn_innerkits_path}/permission/appspawn_mount_permission.c",
275  ]
276
277  # modules sources
278  sources += [
279    "${appspawn_path}/modules/ace_adapter/ace_adapter.cpp",
280    "${appspawn_path}/modules/ace_adapter/command_lexer.cpp",
281    "${appspawn_path}/modules/common/appspawn_adapter.cpp",
282    "${appspawn_path}/modules/common/appspawn_begetctl.c",
283    "${appspawn_path}/modules/common/appspawn_cgroup.c",
284    "${appspawn_path}/modules/common/appspawn_common.c",
285    "${appspawn_path}/modules/common/appspawn_dfx_dump.cpp",
286    "${appspawn_path}/modules/common/appspawn_namespace.c",
287    "${appspawn_path}/modules/common/appspawn_silk.c",
288    "${appspawn_path}/modules/nweb_adapter/nwebspawn_adapter.cpp",
289    "${appspawn_path}/modules/sandbox/appspawn_mount_template.c",
290    "${appspawn_path}/modules/sandbox/appspawn_permission.c",
291    "${appspawn_path}/modules/sandbox/appspawn_sandbox.c",
292    "${appspawn_path}/modules/sandbox/sandbox_cfgvar.c",
293    "${appspawn_path}/modules/sandbox/sandbox_expand.c",
294    "${appspawn_path}/modules/sandbox/sandbox_load.c",
295    "${appspawn_path}/modules/sandbox/sandbox_manager.c",
296  ]
297
298  # add stub
299  include_dirs += [ "${appspawn_path}/test/mock" ]
300  sources += [
301    "${appspawn_path}/test/mock/app_spawn_stub.cpp",
302    "${appspawn_path}/test/mock/app_system_stub.c",
303  ]
304
305  # add test
306  include_dirs += [ "${appspawn_path}/test/unittest" ]
307  sources += [
308    "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_cold_run_test.cpp",
309    "${appspawn_path}/test/unittest/app_spawn_test_helper.cpp",
310  ]
311
312  if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) {
313    defines += [ "APPSPAWN_SANDBOX_NEW" ]
314  } else {
315    sources += [ "${appspawn_path}/modules/sandbox/sandbox_utils.cpp" ]
316  }
317
318  configs = [ "${appspawn_path}:appspawn_config" ]
319  external_deps = [
320    "ability_base:want",
321    "ability_runtime:app_manager",
322    "ability_runtime:appkit_native",
323    "ability_runtime:runtime",
324    "access_token:libtokenid_sdk",
325    "access_token:libtokensetproc_shared",
326    "ace_engine:ace_forward_compatibility",
327    "bundle_framework:appexecfwk_base",
328    "bundle_framework:appexecfwk_core",
329    "cJSON:cjson",
330    "c_utils:utils",
331    "config_policy:configpolicy_util",
332    "eventhandler:libeventhandler",
333    "hilog:libhilog",
334    "hitrace:hitrace_meter",
335    "init:libbegetutil",
336    "init:seccomp",
337    "ipc:ipc_core",
338    "napi:ace_napi",
339    "os_account:os_account_innerkits",
340    "resource_management:global_resmgr",
341  ]
342  if (enable_appspawn_dump_catcher) {
343    external_deps += [ "faultloggerd:libdfx_dumpcatcher" ]
344  }
345  if (asan_detector || is_asan) {
346    defines += [ "ASAN_DETECTOR" ]
347    sources += [ "${appspawn_path}/modules/asan/asan_detector.c" ]
348  }
349
350  if (build_selinux) {
351    defines += [ "WITH_SELINUX" ]
352    external_deps += [
353      "selinux:libselinux",
354      "selinux_adapter:libhap_restorecon",
355    ]
356  }
357
358  if (appspawn_report_event) {
359    defines += [ "REPORT_EVENT" ]
360    external_deps += [ "hisysevent:libhisysevent" ]
361    sources += [
362      "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp",
363      "${appspawn_path}/modules/sysevent/event_reporter.cpp",
364    ]
365  }
366
367  if (target_cpu == "arm64" || target_cpu == "x86_64" ||
368      target_cpu == "riscv64") {
369    defines += [ "APPSPAWN_64" ]
370  }
371
372  if (dlp_permission_enable) {
373    cflags_cc = [ "-DWITH_DLP" ]
374    external_deps += [ "dlp_permission_service:libdlp_fuse" ]
375  }
376}
377
378ohos_unittest("AppSpawn_common_ut") {
379  module_out_path = "${module_output_path}"
380  deps = []
381  defines = [
382    "APPSPAWN_BASE_DIR=\"/data/appspawn_ut\"",
383    "APPSPAWN_LABEL=\"APPSPAWN_UT\"",
384    "APPSPAWN_TEST",
385    "APPSPAWN_DEBUG",
386    "DEBUG_BEGETCTL_BOOT",
387    "USER_TIMER_TO_CHECK",
388    "OHOS_DEBUG",
389    "GRAPHIC_PERMISSION_CHECK",
390    "capset=CapsetStub",
391    "unshare=UnshareStub",
392    "mount=MountStub",
393    "symlink=SymlinkStub",
394    "chdir=ChdirStub",
395    "chroot=ChrootStub",
396    "syscall=SyscallStub",
397    "umount2=Umount2Stub",
398    "access=AccessStub",
399    "dlopen=DlopenStub",
400    "dlsym=DlsymStub",
401    "dlclose=DlcloseStub",
402    "execv=ExecvStub",
403    "getprocpid=GetprocpidStub",
404    "setgroups=SetgroupsStub",
405    "setresgid=SetresgidStub",
406    "setresuid=SetresuidStub",
407    "setuid=SetuidStub",
408    "setgid=SetgidStub",
409    "execvp=ExecvpStub",
410    "ioctl=IoctlStub",
411    "execve=ExecveStub",
412    "setcon=SetconStub",
413  ]
414
415  include_dirs = [
416    "${appspawn_path}",
417    "${appspawn_path}/common",
418    "${appspawn_path}/standard",
419    "${appspawn_path}/modules/modulemgr",
420    "${appspawn_path}/modules/ace_adapter",
421    "${appspawn_path}/modules/common",
422    "${appspawn_path}/modules/sandbox",
423    "${appspawn_path}/modules/sysevent",
424    "${appspawn_innerkits_path}/client",
425    "${appspawn_innerkits_path}/include",
426    "${appspawn_innerkits_path}/permission",
427    "${appspawn_path}/modules/module_engine/include",
428    "${appspawn_path}/test/mock",
429    "${appspawn_path}/test/unittest",
430    "${appspawn_path}/util/include",
431  ]
432  sources = [
433    "${appspawn_path}/common/appspawn_server.c",
434    "${appspawn_path}/common/appspawn_trace.cpp",
435    "${appspawn_path}/modules/modulemgr/appspawn_modulemgr.c",
436    "${appspawn_path}/standard/appspawn_appmgr.c",
437    "${appspawn_path}/standard/appspawn_kickdog.c",
438    "${appspawn_path}/standard/appspawn_msgmgr.c",
439    "${appspawn_path}/standard/appspawn_service.c",
440    "${appspawn_path}/standard/nwebspawn_launcher.c",
441    "${appspawn_path}/util/src/appspawn_utils.c",
442  ]
443
444  # client
445  sources += [
446    "${appspawn_innerkits_path}/client/appspawn_client.c",
447    "${appspawn_innerkits_path}/client/appspawn_msg.c",
448    "${appspawn_innerkits_path}/permission/appspawn_mount_permission.c",
449  ]
450
451  # modules sources
452  sources += [
453    "${appspawn_path}/modules/ace_adapter/ace_adapter.cpp",
454    "${appspawn_path}/modules/ace_adapter/command_lexer.cpp",
455    "${appspawn_path}/modules/common/appspawn_adapter.cpp",
456    "${appspawn_path}/modules/common/appspawn_begetctl.c",
457    "${appspawn_path}/modules/common/appspawn_cgroup.c",
458    "${appspawn_path}/modules/common/appspawn_common.c",
459    "${appspawn_path}/modules/common/appspawn_dfx_dump.cpp",
460    "${appspawn_path}/modules/common/appspawn_namespace.c",
461    "${appspawn_path}/modules/common/appspawn_silk.c",
462    "${appspawn_path}/modules/nweb_adapter/nwebspawn_adapter.cpp",
463    "${appspawn_path}/modules/sandbox/appspawn_mount_template.c",
464    "${appspawn_path}/modules/sandbox/appspawn_permission.c",
465    "${appspawn_path}/modules/sandbox/appspawn_sandbox.c",
466    "${appspawn_path}/modules/sandbox/sandbox_cfgvar.c",
467    "${appspawn_path}/modules/sandbox/sandbox_expand.c",
468    "${appspawn_path}/modules/sandbox/sandbox_load.c",
469    "${appspawn_path}/modules/sandbox/sandbox_manager.c",
470  ]
471
472  # add stub
473  include_dirs += [ "${appspawn_path}/test/mock" ]
474  sources += [
475    "${appspawn_path}/test/mock/app_spawn_stub.cpp",
476    "${appspawn_path}/test/mock/app_system_stub.c",
477  ]
478
479  # add test
480  include_dirs += [ "${appspawn_path}/test/unittest" ]
481  sources += [
482    "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp",
483    "${appspawn_path}/test/unittest/app_spawn_test_helper.cpp",
484  ]
485
486  if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) {
487    defines += [ "APPSPAWN_SANDBOX_NEW" ]
488  } else {
489    sources += [ "${appspawn_path}/modules/sandbox/sandbox_utils.cpp" ]
490  }
491
492  configs = [ "${appspawn_path}:appspawn_config" ]
493  external_deps = [
494    "ability_base:want",
495    "ability_runtime:app_manager",
496    "ability_runtime:appkit_native",
497    "ability_runtime:runtime",
498    "access_token:libtokenid_sdk",
499    "access_token:libtokensetproc_shared",
500    "ace_engine:ace_forward_compatibility",
501    "bundle_framework:appexecfwk_base",
502    "bundle_framework:appexecfwk_core",
503    "cJSON:cjson",
504    "c_utils:utils",
505    "config_policy:configpolicy_util",
506    "eventhandler:libeventhandler",
507    "hilog:libhilog",
508    "hitrace:hitrace_meter",
509    "init:libbegetutil",
510    "init:seccomp",
511    "ipc:ipc_core",
512    "napi:ace_napi",
513    "os_account:os_account_innerkits",
514    "resource_management:global_resmgr",
515  ]
516  if (enable_appspawn_dump_catcher) {
517    external_deps += [ "faultloggerd:libdfx_dumpcatcher" ]
518  }
519  if (asan_detector || is_asan) {
520    defines += [ "ASAN_DETECTOR" ]
521    sources += [ "${appspawn_path}/modules/asan/asan_detector.c" ]
522  }
523
524  if (build_selinux) {
525    defines += [ "WITH_SELINUX" ]
526    external_deps += [
527      "selinux:libselinux",
528      "selinux_adapter:libhap_restorecon",
529    ]
530  }
531
532  if (appspawn_report_event) {
533    defines += [ "REPORT_EVENT" ]
534    external_deps += [ "hisysevent:libhisysevent" ]
535    sources += [
536      "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp",
537      "${appspawn_path}/modules/sysevent/event_reporter.cpp",
538    ]
539  }
540
541  if (target_cpu == "arm64" || target_cpu == "x86_64" ||
542      target_cpu == "riscv64") {
543    defines += [ "APPSPAWN_64" ]
544  }
545
546  if (dlp_permission_enable) {
547    cflags_cc = [ "-DWITH_DLP" ]
548    external_deps += [ "dlp_permission_service:libdlp_fuse" ]
549  }
550}
551