diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 9c6060dac09c4ecff26e5830eb15c8a61b3daaf4..eb3901ee60927baedd4918d2dbea11eb673d8004 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -21,6 +21,9 @@ group("fuzztest") { deps = [ "${services_path}/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkserviceinit_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkservicepausedistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkserviceresumedistributedhardware_fuzzer:fuzztest", @@ -31,7 +34,11 @@ group("fuzztest") { "${services_path}/audiomanager/test/fuzztest/sinkstubonremoterequest_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceservicedump_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceserviceinit_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceserviceonstop_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", diff --git a/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2adc610bc4cb73e0aedd93096c2eee01f673f2b3 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright (c) 2025 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("SinkServiceInitFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sinkserviceinit_fuzzer" + fuzz_config_file = + "${services_path}/audiomanager/test/fuzztest/sinkserviceinit_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sinkserviceinit_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ + "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", + "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceInitFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkServiceInitFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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/sinkserviceinit_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a174cc60794a089fda6cb2f83ebd07496e6ebdb9 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 "sinkserviceinit_fuzzer.h" + +#include +#include +#include + +#include "daudio_sink_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkServiceInitFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + + FuzzedDataProvider fdp(data, size); + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + dAudioSinkService->isServiceStarted_ = true; + dAudioSinkService->Init(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceInitFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.h b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..47584fa0860cd857d3749700301e37570400ef5a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 SINKSERVICEINIT_FUZZER_H +#define SINKSERVICEINIT_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkserviceinit_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp index 72d70e2b40e8b5415f3bba68173145318e09a66a..cab6d723c984eb791b3d0453d305fd24e57a26d4 100644 --- a/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp +++ b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp @@ -43,69 +43,6 @@ void SinkServiceInitSinkFuzzTest(const uint8_t* data, size_t size) dAudioSinkService->InitSink(params, dAudioSinkIpcCallback); } - -void SinkServiceOnStartFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - - FuzzedDataProvider fdp(data, size); - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSinkService = std::make_shared(saId, runOnCreate); - dAudioSinkService->OnStart(); -} - -void SinkServiceOnStopFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - - FuzzedDataProvider fdp(data, size); - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSinkService = std::make_shared(saId, runOnCreate); - dAudioSinkService->OnStop(); -} - -void SinkServiceInitFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - - FuzzedDataProvider fdp(data, size); - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSinkService = std::make_shared(saId, runOnCreate); - dAudioSinkService->Init(); -} - -void SinkServiceDumpFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size == 0) { - return; - } - - FuzzedDataProvider fdp(data, size); - int32_t fd = fdp.ConsumeIntegral(); - size_t argsCount = fdp.ConsumeIntegralInRange(0, 10); - std::vector args; - - for (size_t i = 0; i < argsCount; ++i) { - std::string utf8Str = fdp.ConsumeRandomLengthString(100); - std::u16string utf16Str(utf8Str.begin(), utf8Str.end()); - args.emplace_back(utf16Str); - } - - auto dAudioSinkService = std::make_shared(DISTRIBUTED_HARDWARE_AUDIO_SINK_SA_ID, true); - dAudioSinkService->Dump(fd, args); -} } } @@ -114,10 +51,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::SinkServiceInitSinkFuzzTest(data, size); - OHOS::DistributedHardware::SinkServiceOnStartFuzzTest(data, size); - OHOS::DistributedHardware::SinkServiceOnStopFuzzTest(data, size); - OHOS::DistributedHardware::SinkServiceInitFuzzTest(data, size); - OHOS::DistributedHardware::SinkServiceDumpFuzzTest(data, size); return 0; } diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..29bd66e43ad90aacb0b51918723bd4a2cba3e046 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright (c) 2025 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("SinkServiceOnStartFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sinkserviceonstart_fuzzer" + fuzz_config_file = + "${services_path}/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sinkserviceonstart_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ + "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", + "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceOnStartFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkServiceOnStartFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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/sinkserviceonstart_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..649d2192a54e3827eb4ee1d17a85a4db4f85fba1 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 "sinkserviceonstart_fuzzer.h" + +#include +#include +#include + +#include "daudio_sink_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkServiceOnStartFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + + FuzzedDataProvider fdp(data, size); + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + dAudioSinkService->isServiceStarted_ = true; + dAudioSinkService->OnStart(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceOnStartFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.h b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..ebc6212a7e25a449db87b0f4975341962de61896 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 SINKSERVICEONSTART_FUZZER_H +#define SINKSERVICEONSTART_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkserviceonstart_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0f4bf45a6925e2197bbbe66b5d3400a5f4b3747a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright (c) 2025 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("SinkServiceOnStopFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sinkserviceonstop_fuzzer" + fuzz_config_file = + "${services_path}/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sinkserviceonstop_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ + "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", + "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceOnStopFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkServiceOnStopFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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/sinkserviceonstop_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c5f2fdfe38d65e1d4428f32fcbfff057afb6c10c --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 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 "sinkserviceonstop_fuzzer.h" + +#include +#include +#include + +#include "daudio_sink_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkServiceOnStopFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + + FuzzedDataProvider fdp(data, size); + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + dAudioSinkService->OnStop(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceOnStopFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.h b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..e57a7f6869b2292896b8cab8c88055c2dd1d505b --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 SINKSERVICEONSTOP_FUZZER_H +#define SINKSERVICEONSTOP_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkserviceonstop_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.cpp index 925e883ab65009c790290e6cb997eaf74ac04c91..95da8e4efd916db29d5c44581c62dfdbc5ae1c17 100644 --- a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.cpp +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.cpp @@ -44,68 +44,6 @@ void SourceServiceDAudioNotifyFuzzTest(const uint8_t* data, size_t size) dAudioSourceService->DAudioNotify(devId, dhId, eventType, eventContent); } - -void SourceServiceOnStartFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - FuzzedDataProvider fdp(data, size); - - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSourceService = std::make_shared(saId, runOnCreate); - dAudioSourceService->OnStart(); -} - -void SourceServiceOnStopFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - FuzzedDataProvider fdp(data, size); - - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSourceService = std::make_shared(saId, runOnCreate); - dAudioSourceService->OnStop(); -} - -void SourceServiceInitFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - FuzzedDataProvider fdp(data, size); - - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSourceService = std::make_shared(saId, runOnCreate); - dAudioSourceService->Init(); -} - -void SourceServiceDumpFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size == 0) { - return; - } - FuzzedDataProvider fdp(data, size); - - int32_t fd = fdp.ConsumeIntegral(); - size_t argsCount = fdp.ConsumeIntegralInRange(0, 10); - std::vector args; - for (size_t i = 0; i < argsCount; ++i) { - std::string utf8Str = fdp.ConsumeRandomLengthString(100); - std::u16string utf16Str(utf8Str.begin(), utf8Str.end()); - args.emplace_back(utf16Str); - } - - auto dAudioSourceService = std::make_shared(DISTRIBUTED_HARDWARE_AUDIO_SOURCE_SA_ID, true); - dAudioSourceService->Dump(fd, args); -} } } @@ -114,10 +52,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::SourceServiceDAudioNotifyFuzzTest(data, size); - OHOS::DistributedHardware::SourceServiceOnStartFuzzTest(data, size); - OHOS::DistributedHardware::SourceServiceOnStopFuzzTest(data, size); - OHOS::DistributedHardware::SourceServiceInitFuzzTest(data, size); - OHOS::DistributedHardware::SourceServiceDumpFuzzTest(data, size); return 0; } diff --git a/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7d43ec5a9240e3a5972f43fccb8ae9ba32005b14 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2025 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("SourceServiceDumpFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sourceservicedump_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceservicedump_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sourceservicedump_fuzzer.cpp" ] + + 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=\"SourceServiceDumpFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "audio_framework:audio_capturer", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "cJSON:cjson", + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceDumpFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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/sourceservicedump_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..198c7cfdb3da9d916357a68763c8aa71738f983e --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 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 "sourceservicedump_fuzzer.h" + +#include +#include +#include + +#include "daudio_source_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceDumpFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t fd = fdp.ConsumeIntegral(); + size_t argsCount = fdp.ConsumeIntegralInRange(0, 10); + std::vector args; + for (size_t i = 0; i < argsCount; ++i) { + std::string utf8Str = fdp.ConsumeRandomLengthString(100); + std::u16string utf16Str(utf8Str.begin(), utf8Str.end()); + args.emplace_back(utf16Str); + } + + auto dAudioSourceService = std::make_shared(fd, true); + dAudioSourceService->Dump(fd, args); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceDumpFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.h b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8cb8fc13082a1972007093bc4aa5e0c74bf17f05 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 SOURCESERVICEDUMP_FUZZER_H +#define SOURCESERVICEDUMP_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceservicedump_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7ca0b59a0414db9adaf67938fb3e536b14896fb1 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2025 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("SourceServiceInitFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sourceserviceinit_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceinit_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sourceserviceinit_fuzzer.cpp" ] + + 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=\"SourceServiceInitFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "audio_framework:audio_capturer", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "cJSON:cjson", + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceInitFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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/sourceserviceinit_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cfb3df1c4995f4037a084fbde6a9943a592632a5 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 "sourceserviceinit_fuzzer.h" + +#include +#include +#include + +#include "daudio_source_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceInitFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + dAudioSourceService->isServiceStarted_ = true; + dAudioSourceService->Init(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceInitFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.h b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..b5d08a3cabab12b86ac6f0804cc69362b886f7d3 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 SOURCESERVICEINIT_FUZZER_H +#define SOURCESERVICEINIT_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceserviceinit_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..52b55c7671a154dab6a3bb2883c0e17696d99d69 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2025 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("SourceServiceOnStartFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sourceserviceonstart_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sourceserviceonstart_fuzzer.cpp" ] + + 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=\"SourceServiceOnStartFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "audio_framework:audio_capturer", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "cJSON:cjson", + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceOnStartFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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/sourceserviceonstart_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eceafa3629d1a3cf5a0af0c9f3cfe201a1b0a9b0 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 "sourceserviceonstart_fuzzer.h" + +#include +#include +#include + +#include "daudio_source_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceOnStartFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + dAudioSourceService->isServiceStarted_ = true; + dAudioSourceService->OnStart(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceOnStartFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.h b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..91b049635173d67aa261cefeef3dfde43fa7b239 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 SOURCESERVICEONSTART_FUZZER_H +#define SOURCESERVICEONSTART_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceserviceonstart_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..76a8bcb1f7aafbf33ce45328f239e9effa8518b9 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2025 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("SourceServiceOnStopFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sourceserviceonstop_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sourceserviceonstop_fuzzer.cpp" ] + + 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=\"SourceServiceOnStopFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "audio_framework:audio_capturer", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "cJSON:cjson", + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceOnStopFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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/sourceserviceonstop_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..97567b2d7888fb06ec33255f735185f3bc6218ee --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 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 "sourceserviceonstop_fuzzer.h" + +#include +#include +#include + +#include "daudio_source_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceOnStopFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + dAudioSourceService->OnStop(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceOnStopFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.h b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..5a372f5aeb25043367f9a167387316e41fa052bf --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 SOURCESERVICEONSTOP_FUZZER_H +#define SOURCESERVICEONSTOP_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceserviceonstop_fuzzer" + +#endif \ No newline at end of file