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
14#####################hydra-fuzz###################
15import("//build/config/features.gni")
16import("//build/ohos.gni")
17import("//build/test.gni")
18import("../../../services/samgr/var.gni")
19module_output_path = "samgr/samgr"
20samgr_dir = "../../../"
21samgr_services_dir = "${samgr_dir}/services/samgr/native"
22
23config("sam_fuzz_test_config") {
24  include_dirs = [
25    "${samgr_dir}/services/dfx/include",
26    "${samgr_dir}/services/lsamgr/include",
27    "${samgr_dir}/services/samgr/native/test/unittest/include",
28    "${samgr_dir}/test/fuzztest/samgr_fuzzer/include",
29  ]
30}
31
32##############################fuzztest##########################################
33cancelunloadsystemability_test = {
34  targetName = "CancelUnloadSystemAbilityFuzzTest"
35  configFuzzer = "cancelunloadsystemability_fuzzer"
36  source = "src/cancelunloadsystemability_fuzzer.cpp"
37}
38
39checkremotesystemability_test = {
40  targetName = "CheckRemoteSystemAbilityFuzzTest"
41  configFuzzer = "checkremotesystemability_fuzzer"
42  source = "src/checkremotesystemability_fuzzer.cpp"
43}
44
45getextensionsaids_test = {
46  targetName = "GetExtensionSaIdsFuzzTest"
47  configFuzzer = "getextensionsaids_fuzzer"
48  source = "src/getextensionsaids_fuzzer.cpp"
49}
50
51getextensionsalist_test = {
52  targetName = "GetExtensionSaListFuzzTest"
53  configFuzzer = "getextensionsalist_fuzzer"
54  source = "src/getextensionsalist_fuzzer.cpp"
55}
56
57getondemandpolicy_test = {
58  targetName = "GetOnDemandPolicyFuzzTest"
59  configFuzzer = "getondemandpolicy_fuzzer"
60  source = "src/getondemandpolicy_fuzzer.cpp"
61}
62
63getsystemability_test = {
64  targetName = "GetSystemAbilityFuzzTest"
65  configFuzzer = "getsystemability_fuzzer"
66  source = "src/getsystemability_fuzzer.cpp"
67}
68
69getsaextensioninfo_test = {
70  targetName = "GetSaExtensionInfoFuzzTest"
71  configFuzzer = "getsaextensioninfo_fuzzer"
72  source = "src/getsaextensioninfo_fuzzer.cpp"
73}
74
75loadremotesystemability_test = {
76  targetName = "LoadRemoteSystemAbilityFuzzTest"
77  configFuzzer = "loadremotesystemability_fuzzer"
78  source = "src/loadremotesystemability_fuzzer.cpp"
79}
80
81unloadallidlesystemability_test = {
82  targetName = "UnloadAllIdleSystemAbilityFuzzTest"
83  configFuzzer = "unloadallidlesystemability_fuzzer"
84  source = "src/unloadallidlesystemability_fuzzer.cpp"
85}
86
87unsubscribesystemprocess_test = {
88  targetName = "UnSubscribeSystemProcessFuzzTest"
89  configFuzzer = "unsubscribesystemprocess_fuzzer"
90  source = "src/unsubscribesystemprocess_fuzzer.cpp"
91}
92
93unsubscribesystemability_test = {
94  targetName = "UnSubscribeSystemAbilityFuzzTest"
95  configFuzzer = "unsubscribesystemability_fuzzer"
96  source = "src/unsubscribesystemability_fuzzer.cpp"
97}
98
99addsystemability_test = {
100  targetName = "AddSystemAbilityFuzzTest"
101  configFuzzer = "addsystemability_fuzzer"
102  source = "src/addsystemability_fuzzer.cpp"
103}
104
105addsystemprocess_test = {
106  targetName = "AddSystemProcessFuzzTest"
107  configFuzzer = "addsystemprocess_fuzzer"
108  source = "src/addsystemprocess_fuzzer.cpp"
109}
110
111samgr_fuzztests = [
112  cancelunloadsystemability_test,
113  checkremotesystemability_test,
114  getextensionsaids_test,
115  getextensionsalist_test,
116  getondemandpolicy_test,
117  getsystemability_test,
118  getsaextensioninfo_test,
119  loadremotesystemability_test,
120  unloadallidlesystemability_test,
121  unsubscribesystemprocess_test,
122  unsubscribesystemability_test,
123  addsystemability_test,
124  addsystemprocess_test,
125]
126foreach(item, samgr_fuzztests) {
127  ohos_fuzztest(item.targetName) {
128    module_out_path = module_output_path
129
130    fuzz_config_file =
131        "${samgr_dir}/test/fuzztest/samgr_fuzzer/project/${item.configFuzzer}"
132
133    configs = [
134      ":sam_fuzz_test_config",
135      "${samgr_dir}/services/samgr/native:sam_config",
136      "${samgr_dir}/test/resource:coverage_flags",
137    ]
138
139    cflags = [
140      "-g",
141      "-O0",
142      "-Wno-unused-variable",
143      "-fno-omit-frame-pointer",
144    ]
145    sources = [
146      "${samgr_dir}/services/dfx/source/hisysevent_adapter.cpp",
147      "${samgr_dir}/utils/native/source/tools.cpp",
148      "${samgr_services_dir}/source/ability_death_recipient.cpp",
149      "${samgr_services_dir}/source/collect/device_param_collect.cpp",
150      "${samgr_services_dir}/source/collect/device_status_collect_manager.cpp",
151      "${samgr_services_dir}/source/collect/device_timed_collect.cpp",
152      "${samgr_services_dir}/source/collect/icollect_plugin.cpp",
153      "${samgr_services_dir}/source/collect/ref_count_collect.cpp",
154      "${samgr_services_dir}/source/ffrt_handler.cpp",
155      "${samgr_services_dir}/source/memory_guard.cpp",
156      "${samgr_services_dir}/source/rpc_callback_imp.cpp",
157      "${samgr_services_dir}/source/samgr_time_handler.cpp",
158      "${samgr_services_dir}/source/schedule/system_ability_event_handler.cpp",
159      "${samgr_services_dir}/source/schedule/system_ability_state_machine.cpp",
160      "${samgr_services_dir}/source/schedule/system_ability_state_scheduler.cpp",
161      "${samgr_services_dir}/source/system_ability_manager.cpp",
162      "${samgr_services_dir}/source/system_ability_manager_dumper.cpp",
163      "${samgr_services_dir}/source/system_ability_manager_stub.cpp",
164      "${samgr_services_dir}/source/system_ability_manager_util.cpp",
165      "${samgr_services_dir}/test/unittest/src/mock_accesstoken_kit.cpp",
166      "${samgr_services_dir}/test/unittest/src/mock_permission.cpp",
167      "src/fuzztest_utils.cpp",
168      item.source,
169    ]
170    deps = []
171
172    external_deps = [
173      "access_token:libaccesstoken_sdk",
174      "access_token:libnativetoken_shared",
175      "access_token:libtokensetproc_shared",
176      "c_utils:utils",
177      "eventhandler:libeventhandler",
178      "ffrt:libffrt",
179      "hilog:libhilog",
180      "hisysevent:libhisysevent",
181      "hitrace:hitrace_meter",
182      "init:libbeget_proxy",
183      "init:libbegetutil",
184      "ipc:ipc_core",
185      "ipc:libdbinder",
186      "safwk:system_ability_fwk",
187      "samgr:samgr_common",
188      "samgr:samgr_proxy",
189    ]
190    defines = []
191    if (hicollie_able) {
192      external_deps += [ "hicollie:libhicollie" ]
193      defines += [ "HICOLLIE_ENABLE" ]
194    }
195
196    if (support_device_manager) {
197      sources += [
198        "${samgr_services_dir}/source/collect/device_networking_collect.cpp",
199      ]
200      external_deps += [ "device_manager:devicemanagersdk" ]
201      defines += [ "SUPPORT_DEVICE_MANAGER" ]
202    }
203  }
204}
205
206###############################################################################
207group("fuzztest") {
208  testonly = true
209  deps = []
210  deps += [
211    # deps file
212    ":AddSystemAbilityFuzzTest",
213    ":AddSystemProcessFuzzTest",
214    ":CancelUnloadSystemAbilityFuzzTest",
215    ":CheckRemoteSystemAbilityFuzzTest",
216    ":GetExtensionSaIdsFuzzTest",
217    ":GetExtensionSaListFuzzTest",
218    ":GetOnDemandPolicyFuzzTest",
219    ":GetSaExtensionInfoFuzzTest",
220    ":GetSystemAbilityFuzzTest",
221    ":LoadRemoteSystemAbilityFuzzTest",
222    ":UnSubscribeSystemAbilityFuzzTest",
223    ":UnSubscribeSystemProcessFuzzTest",
224    ":UnloadAllIdleSystemAbilityFuzzTest",
225  ]
226}
227###############################################################################
228