diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 8605ec77d16b725f78a9832f3160eb412011c45a..68222b7c01414b68c8281ff8b9a241372bea9c0e 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -33,6 +33,17 @@ group("fuzztest") { "${hdf_ser_aud_path}/test/fuzztest/renderframe_fuzzer:fuzztest", "${hdf_ser_aud_path}/test/fuzztest/setextraparams_fuzzer:fuzztest", "${hdf_ser_aud_path}/test/fuzztest/unloadadapter_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer:fuzztest", "onremotesinksvrdied_fuzzer:fuzztest", "onremotesourcesvrdied_fuzzer:fuzztest", "sinkhandlerfinishstartsa_fuzzer:fuzztest", diff --git a/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a5633fc77455c2eec6193f44488ab5aeb814e44f --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkServiceDAudioNotifyFuzzTest") { + module_out_path = "distributed_audio/sinkservicedaudionotify_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkservicedaudionotify_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ "${services_path}/audiomanager/servicesink:distributed_audio_sink" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceDAudioNotifyFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkServiceDAudioNotifyFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/sinkservicedaudionotify_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/sinkservicedaudionotify_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c0db2652d798939873f69268d1a0d990332fa244 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/sinkservicedaudionotify_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sinkservicedaudionotify_fuzzer.h" + +#include +#include + +#include "daudio_sink_service.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkServiceDAudioNotifyFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + std::string dhId(reinterpret_cast(data), size); + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + int32_t eventType = *(reinterpret_cast(data)); + std::string eventContent(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + + dAudioSinkService->DAudioNotify(devId, dhId, eventType, eventContent); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceDAudioNotifyFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/sinkservicedaudionotify_fuzzer.h b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/sinkservicedaudionotify_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..26a62bb9bbad1706f60efaff3486979e8c398e14 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer/sinkservicedaudionotify_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SINKSERVICEDAUDIONOTIFY_FUZZER_H +#define SINKSERVICEDAUDIONOTIFY_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkservicedaudionotify_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..752c69d7bd587cec1a46a53e6c9d0bfb668361b0 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkServiceInitSinkFuzzTest") { + module_out_path = "distributed_audio/sinkserviceinitsink_fuzzer" + fuzz_config_file = + "${services_path}/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkserviceinitsink_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ "${services_path}/audiomanager/servicesink:distributed_audio_sink" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceInitSinkFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkServiceInitSinkFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49309af8172ea39aec116e5d5aec0b63801240ee --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sinkserviceinitsink_fuzzer.h" + +#include +#include + +#include "daudio_sink_service.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkServiceInitSinkFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + int32_t saId = *(reinterpret_cast(data)); + std::string params(reinterpret_cast(data), size); + bool runOnCreate = *(reinterpret_cast(data)); + + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + + dAudioSinkService->InitSink(params); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceInitSinkFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.h b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..ce432ee404f2c4f84e2bb3bb825eeef93572205a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SINKSERVICEINITSINK_FUZZER_H +#define SINKSERVICEINITSINK_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkserviceinitsink_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ef1cfd28f6cd71179a45ad51e03a76294413646e --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkServiceReleaseSinkFuzzTest") { + module_out_path = "distributed_audio/sinkservicereleasesink_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkservicereleasesink_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ "${services_path}/audiomanager/servicesink:distributed_audio_sink" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceReleaseSinkFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkServiceReleaseSinkFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/sinkservicereleasesink_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/sinkservicereleasesink_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..54c167f4523b545294d0062a9356a01e47b97ca3 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/sinkservicereleasesink_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sinkservicereleasesink_fuzzer.h" + +#include +#include + +#include "daudio_sink_service.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkServiceReleaseSinkFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + + dAudioSinkService->ReleaseSink(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceReleaseSinkFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/sinkservicereleasesink_fuzzer.h b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/sinkservicereleasesink_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..40e6ea152c98bae9e84dd4837eb8b71b306366c1 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer/sinkservicereleasesink_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SINKSERVICERELEASESINK_FUZZER_H +#define SINKSERVICERELEASESINK_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkservicereleasesink_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c1e4053fea1fde97fd2c3348c205856ff9f079cd --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkServiceSubscribeLocalHardwareFuzzTest") { + module_out_path = "distributed_audio/sinkservicesubscribelocalhardware_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkservicesubscribelocalhardware_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ "${services_path}/audiomanager/servicesink:distributed_audio_sink" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceSubscribeLocalHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkServiceSubscribeLocalHardwareFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/sinkservicesubscribelocalhardware_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/sinkservicesubscribelocalhardware_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..099261877f772a8237f3388c57fea70059b27a6a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/sinkservicesubscribelocalhardware_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sinkservicesubscribelocalhardware_fuzzer.h" + +#include +#include + +#include "daudio_sink_service.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkServiceSubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + std::string dhId(reinterpret_cast(data), size); + std::string param(reinterpret_cast(data), size); + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + + dAudioSinkService->SubscribeLocalHardware(dhId, param); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceSubscribeLocalHardwareFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/sinkservicesubscribelocalhardware_fuzzer.h b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/sinkservicesubscribelocalhardware_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..14e0492d241def2c9b37df9b047f0a1f626cab09 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer/sinkservicesubscribelocalhardware_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SINKSERVICESUBSCRIBELOCALHARDWARE_FUZZER_H +#define SINKSERVICESUBSCRIBELOCALHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkservicesubscribelocalhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6df43eabcde7ae31f2f5aa88dfcbba1e4b24a3a4 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkServiceUnSubscribeLocalHardwareFuzzTest") { + module_out_path = + "distributed_audio/sinkserviceunsubscribelocalhardware_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkserviceunsubscribelocalhardware_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ "${services_path}/audiomanager/servicesink:distributed_audio_sink" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceUnSubscribeLocalHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkServiceUnSubscribeLocalHardwareFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/sinkserviceunsubscribelocalhardware_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/sinkserviceunsubscribelocalhardware_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..79752e5da04cd9a9e1d0cfb9faa3032951935334 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/sinkserviceunsubscribelocalhardware_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sinkserviceunsubscribelocalhardware_fuzzer.h" + +#include +#include + +#include "daudio_sink_service.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkServiceUnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + std::string dhId(reinterpret_cast(data), size); + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + dAudioSinkService->UnsubscribeLocalHardware(dhId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceUnsubscribeLocalHardwareFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/sinkserviceunsubscribelocalhardware_fuzzer.h b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/sinkserviceunsubscribelocalhardware_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..35414926901d3127f5206df3085cad91d0b713df --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer/sinkserviceunsubscribelocalhardware_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SINKSERVICEUNSUBSCRIBELOCALHARDWARE_FUZZER_H +#define SINKSERVICEUNSUBSCRIBELOCALHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkserviceunsubscribelocalhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7179b7e05153bf419717d39929e375d38609d09a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceServiceConfigDistributedHardwareFuzzTest") { + module_out_path = + "distributed_audio/sourceserviceconfigdistributedhardware_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sourceserviceconfigdistributedhardware_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${driver_audio_path}/include", + "${mediastandardfwk_path}/audiocapturer/include", + "${mediastandardfwk_path}/audiomanager/include", + "${mediastandardfwk_path}/audiocommon/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/dfx_utils/include", + "${services_path}/common/audioparam", + "${innerkits_path}/native_cpp/audio_source/include", + "${distributedaudio_path}/audiohandler/include", + "${services_path}/audiomanager/servicesource/include", + ] + + deps = + [ "${services_path}/audiomanager/servicesource:distributed_audio_source" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceServiceConfigDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceConfigDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/sourceserviceconfigdistributedhardware_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/sourceserviceconfigdistributedhardware_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0c01f5ff318391b2d1aff800d734f881bc5d1343 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/sourceserviceconfigdistributedhardware_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sourceserviceconfigdistributedhardware_fuzzer.h" + +#include +#include + +#include "daudio_source_service.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceConfigDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string key(reinterpret_cast(data), size); + std::string value(reinterpret_cast(data), size); + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + dAudioSourceService->ConfigDistributedHardware(devId, dhId, key, value); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceConfigDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/sourceserviceconfigdistributedhardware_fuzzer.h b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/sourceserviceconfigdistributedhardware_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..93fe081b1103f4231fad0284a7f57b8e66f96e1c --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/sourceserviceconfigdistributedhardware_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCESERVICECONFIGDISTRIBUTEDHARDWARE_FUZZER_H +#define SOURCESERVICECONFIGDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceserviceconfigdistributedhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4e97920a6da3a24a0cdf48c5927784bc8a37b25a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn @@ -0,0 +1,75 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceServiceDAudioNotifyFuzzTest") { + module_out_path = "distributed_audio/sourceservicedaudionotify_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sourceservicedaudionotify_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${driver_audio_path}/include", + "${mediastandardfwk_path}/audiocapturer/include", + "${mediastandardfwk_path}/audiomanager/include", + "${mediastandardfwk_path}/audiocommon/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/dfx_utils/include", + "${services_path}/common/audioparam", + "${innerkits_path}/native_cpp/audio_source/include", + "${distributedaudio_path}/audiohandler/include", + "${services_path}/audiomanager/servicesource/include", + ] + + deps = + [ "${services_path}/audiomanager/servicesource:distributed_audio_source" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceServiceDAudioNotifyFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceDAudioNotifyFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7ed76da0c602071d905a2194f3150fc8e2e81ca5 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sourceservicedaudionotify_fuzzer.h" + +#include +#include + +#include "daudio_source_service.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceDAudioNotifyFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + std::string dhId(reinterpret_cast(data), size); + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + int32_t eventType = *(reinterpret_cast(data)); + std::string eventContent(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + + dAudioSourceService->DAudioNotify(devId, dhId, eventType, eventContent); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceDAudioNotifyFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.h b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..15f60793b6ab6080ef302c8d4a32f6d62e63d4b0 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCESERVICEDAUDIONOTIFY_FUZZER_H +#define SOURCESERVICEDAUDIONOTIFY_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceservicedaudionotify_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4843d04e283a419197e0e69a41ba5f8d6e4ec025 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn @@ -0,0 +1,77 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceServiceInitSourceFuzzTest") { + module_out_path = "distributed_audio/sourceserviceinitsource_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sourceserviceinitsource_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${driver_audio_path}/include", + "${mediastandardfwk_path}/audiocapturer/include", + "${mediastandardfwk_path}/audiomanager/include", + "${mediastandardfwk_path}/audiocommon/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/dfx_utils/include", + "${services_path}/common/audioparam", + "${innerkits_path}/native_cpp/audio_source/include", + "${distributedaudio_path}/audiohandler/include", + "${services_path}/audiomanager/servicesource/include", + ] + + deps = [ + "${innerkits_path}/native_cpp/audio_source:distributed_audio_source_sdk", + "${services_path}/audiomanager/servicesource:distributed_audio_source", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceServiceInitSourceFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceInitSourceFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/sourceserviceinitsource_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/sourceserviceinitsource_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1968f3c3a5518e28bac1028165191e533a543556 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/sourceserviceinitsource_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sourceserviceinitsource_fuzzer.h" + +#include +#include + +#include "daudio_ipc_callback.h" +#include "daudio_source_service.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceInitSourceFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + int32_t saId = *(reinterpret_cast(data)); + std::string params(reinterpret_cast(data), size); + bool runOnCreate = *(reinterpret_cast(data)); + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + sptr callback = new DAudioIpcCallback(); + dAudioSourceService->InitSource(params, callback); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceInitSourceFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/sourceserviceinitsource_fuzzer.h b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/sourceserviceinitsource_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..965c4c277e1a3f336e249964a471cdf04baf559a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/sourceserviceinitsource_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCESERVICEINITSOURCE_FUZZER_H +#define SOURCESERVICEINITSOURCE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceserviceinitsource_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c693288427d6678d3d118b4852d2d776db135481 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceServiceRegisterDistributedHardwareFuzzTest") { + module_out_path = + "distributed_audio/sourceserviceregisterdistributedhardware_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sourceserviceregisterdistributedhardware_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${driver_audio_path}/include", + "${mediastandardfwk_path}/audiocapturer/include", + "${mediastandardfwk_path}/audiomanager/include", + "${mediastandardfwk_path}/audiocommon/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/dfx_utils/include", + "${services_path}/common/audioparam", + "${innerkits_path}/native_cpp/audio_source/include", + "${distributedaudio_path}/audiohandler/include", + "${services_path}/audiomanager/servicesource/include", + ] + + deps = + [ "${services_path}/audiomanager/servicesource:distributed_audio_source" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceServiceRegisterDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceRegisterDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/sourceserviceregisterdistributedhardware_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/sourceserviceregisterdistributedhardware_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8efd5ad4ced3afa239e91cb84ab47f1a6a43dc45 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/sourceserviceregisterdistributedhardware_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sourceserviceregisterdistributedhardware_fuzzer.h" + +#include +#include + +#include "daudio_source_service.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceRegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + EnableParam param; + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + dAudioSourceService->RegisterDistributedHardware(devId, dhId, param, reqId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceRegisterDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/sourceserviceregisterdistributedhardware_fuzzer.h b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/sourceserviceregisterdistributedhardware_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..49d826b643fad5874cb1b8e95fcfa252480b8165 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/sourceserviceregisterdistributedhardware_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCESERVICEREGISTERDISTRIBUTEDHARDWARE_FUZZER_H +#define SOURCESERVICEREGISTERDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceserviceregisterdistributedhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..289fe9af4d503615b5c8b291ea33d51455696080 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn @@ -0,0 +1,75 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceServiceReleaseSourceFuzzTest") { + module_out_path = "distributed_audio/sourceservicereleasesource_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sourceservicereleasesource_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${driver_audio_path}/include", + "${mediastandardfwk_path}/audiocapturer/include", + "${mediastandardfwk_path}/audiomanager/include", + "${mediastandardfwk_path}/audiocommon/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/dfx_utils/include", + "${services_path}/common/audioparam", + "${innerkits_path}/native_cpp/audio_source/include", + "${distributedaudio_path}/audiohandler/include", + "${services_path}/audiomanager/servicesource/include", + ] + + deps = + [ "${services_path}/audiomanager/servicesource:distributed_audio_source" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceServiceReleaseSourceFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceReleaseSourceFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/sourceservicereleasesource_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/sourceservicereleasesource_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1c2184fd8865fe71639e51e0f62039b10ac857c9 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/sourceservicereleasesource_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sourceservicereleasesource_fuzzer.h" + +#include +#include + +#include "daudio_source_service.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceReleaseSourceFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + dAudioSourceService->ReleaseSource(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceReleaseSourceFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/sourceservicereleasesource_fuzzer.h b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/sourceservicereleasesource_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7e8e49c1c67dffdb8550a927a0c0aa546d2e7451 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/sourceservicereleasesource_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCESERVICERELEASESOURCE_FUZZER_H +#define SOURCESERVICERELEASESOURCE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceservicereleasesource_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..eaa6556f3686f9c9fab03129c5d1854234588ea3 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceServiceUnregisterDistributedHardwareFuzzTest") { + module_out_path = + "distributed_audio/sourceserviceunregisterdistributedhardware_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sourceserviceunregisterdistributedhardware_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${driver_audio_path}/include", + "${mediastandardfwk_path}/audiocapturer/include", + "${mediastandardfwk_path}/audiomanager/include", + "${mediastandardfwk_path}/audiocommon/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/dfx_utils/include", + "${services_path}/common/audioparam", + "${innerkits_path}/native_cpp/audio_source/include", + "${distributedaudio_path}/audiohandler/include", + "${services_path}/audiomanager/servicesource/include", + ] + + deps = + [ "${services_path}/audiomanager/servicesource:distributed_audio_source" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceServiceUnregisterDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceUnregisterDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9070613c5138e667b5a370016e77b8e896e3a8b8 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sourceserviceunregisterdistributedhardware_fuzzer.h" + +#include +#include + +#include "daudio_source_service.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceUnregisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + dAudioSourceService->UnregisterDistributedHardware(devId, dhId, reqId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceUnregisterDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.h b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..89c306494f12a38b77cdc58780b993988732dc3e --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/sourceserviceunregisterdistributedhardware_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCESERVICEUNREGISTERDISTRIBUTEDHARDWARE_FUZZER_H +#define SOURCESERVICEUNREGISTERDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceserviceunregisterdistributedhardware_fuzzer" + +#endif \ No newline at end of file