diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 45f8f5905e070bac3e044ee1e4506100a78034f8..de881de9cef80c3ac8751d08a1d7cd490ffc22ff 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -44,7 +44,19 @@ group("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", + "${services_path}/audioprocessor/test/fuzztest/decoderonerror_fuzzer:fuzztest", + "${services_path}/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer:fuzztest", + "${services_path}/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer:fuzztest", + "${services_path}/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer:fuzztest", + "${services_path}/audioprocessor/test/fuzztest/encoderonerror_fuzzer:fuzztest", + "${services_path}/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer:fuzztest", + "${services_path}/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer:fuzztest", + "${services_path}/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer:fuzztest", "${services_path}/common/test/fuzztest/audiodatasetinit64_fuzzer:fuzztest", + "${services_path}/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer:fuzztest", + "${services_path}/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer:fuzztest", + "${services_path}/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer:fuzztest", + "${services_path}/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer:fuzztest", "onremotesinksvrdied_fuzzer:fuzztest", "onremotesourcesvrdied_fuzzer:fuzztest", "sinkhandlerfinishstartsa_fuzzer:fuzztest", diff --git a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..057426980105037d57444e45703d11ae6ec88750 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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("DecoderOnErrorFuzzTest") { + module_out_path = "distributed_audio/decoderonerror" + fuzz_config_file = + "${audio_processor_path}/test/fuzztest/decoderonerror_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "decoderonerror_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", + "${audio_processor_path}/decoder/include", + ] + + deps = [ + "${audio_transport_path}/decodetransport:distributed_audio_decode_transport", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "player_framework:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DecoderOnErrorFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DecoderOnErrorFuzzTest" ] +} +############################################################################### diff --git a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonerror_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/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.cpp b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..68cdb6fcc1bc8aea15d142b6114625c7c4c76593 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#include "decoderonerror_fuzzer.h" + +#include +#include + +#include "audio_decoder.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void DecoderOnErrorFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return; + } + int32_t type = *(reinterpret_cast(data)); + + std::shared_ptr decoder = std::make_shared(); + AudioEvent event(static_cast(type), ""); + decoder->OnError(event); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DecoderOnErrorFuzzTest(data, size); + return 0; +} + diff --git a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.h b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7f5ab292b84d9ce879c0e9e311ea61154db2ba16 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/decoderonerror_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef DECODERONERROR_FUZZER_H +#define DECODERONERROR_FUZZER_H + +#define FUZZ_PROJECT_NAME "decoderonerror_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonerror_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..888ca204fa47369528f7fdda4156f907965dd758 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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("DecoderOnInputAvailableFuzzTest") { + module_out_path = "distributed_audio/decoderoninputavailable" + fuzz_config_file = + "${audio_processor_path}/test/fuzztest/decoderoninputavailable_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "decoderoninputavailable_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", + "${audio_processor_path}/decoder/include", + ] + + deps = [ + "${audio_transport_path}/decodetransport:distributed_audio_decode_transport", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "player_framework:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DecoderOnInputAvailableFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DecoderOnInputAvailableFuzzTest" ] +} +############################################################################### diff --git a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderoninputavailable_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/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.cpp b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..12046073a3b2b291c7d6cac3ad399a2acf04d844 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#include "decoderoninputavailable_fuzzer.h" + +#include +#include + +#include "audio_decoder.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void DecoderOnInputAvailabelFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return; + } + + uint32_t index = *(reinterpret_cast(data)); + std::shared_ptr decoder = std::make_shared(); + decoder->OnInputBufferAvailable(index); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DecoderOnInputAvailabelFuzzTest(data, size); + return 0; +} + diff --git a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.h b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..decf9c8ce1450d5d7ea3de7dfa907040c2f235d2 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/decoderoninputavailable_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef DECODERONINPUTAVAILABLE_FUZZER_H +#define DECODERONINPUTAVAILABLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "decoderoninputavailable_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderoninputavailable_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6b620a8598f7c16147e0ceab6cc72550963c1fad --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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("DecoderOnOutputAvailableFuzzTest") { + module_out_path = "distributed_audio/decoderonoutputavailable" + fuzz_config_file = + "${audio_processor_path}/test/fuzztest/decoderonoutputavailable_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "decoderonoutputavailable_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", + "${audio_processor_path}/decoder/include", + ] + + deps = [ + "${audio_transport_path}/decodetransport:distributed_audio_decode_transport", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "player_framework:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DecoderOnOutputAvailableFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DecoderOnOutputAvailableFuzzTest" ] +} +############################################################################### diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_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/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.cpp b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..53c07911118b84ec02eb7cf09bb8f9ff64e5974c --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include "decoderonoutputavailable_fuzzer.h" + +#include +#include + +#include "audio_decoder.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void DecoderOnOutputAvailabelFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return; + } + + uint32_t index = *(reinterpret_cast(data)); + int64_t presentTimeUs = *(reinterpret_cast(data)); + int32_t infoSize = *(reinterpret_cast(data)); + int32_t offset = *(reinterpret_cast(data)); + int32_t bufferFlag = *(reinterpret_cast(data)); + Media::AVCodecBufferInfo info = {presentTimeUs, infoSize, offset}; + Media::AVCodecBufferFlag flag = static_cast(bufferFlag); + std::shared_ptr decoder = std::make_shared(); + decoder->OnOutputBufferAvailable(index, info, flag); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DecoderOnOutputAvailabelFuzzTest(data, size); + return 0; +} + diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.h b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..1b5f7177fc82da82da98a8d0706f454f6d218e97 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/decoderonoutputavailable_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef DECODERONOUTPUTAVAILABLE_FUZZER_H +#define DECODERONOUTPUTAVAILABLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "decoderonoutputavailable_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonoutputavailable_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e6a835d7c3c043117ad197e227fd5a718bba5704 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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("DecoderOnOutputChangedFuzzTest") { + module_out_path = "distributed_audio/decoderonoutputchanged" + fuzz_config_file = + "${audio_processor_path}/test/fuzztest/decoderonoutputchanged_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "decoderonoutputchanged_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", + "${audio_processor_path}/decoder/include", + ] + + deps = [ + "${audio_transport_path}/decodetransport:distributed_audio_decode_transport", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "player_framework:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DecoderOnOutputChangedFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DecoderOnOutputChangedFuzzTest" ] +} +############################################################################### diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_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/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.cpp b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9e8f79f15fff21d0bebe0c49cd2124070e30ed41 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#include "decoderonoutputchanged_fuzzer.h" + +#include +#include + +#include "audio_decoder.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void DecoderOnOutputChangedFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return; + } + + Media::Format format; + std::shared_ptr decoder = std::make_shared(); + decoder->OnOutputFormatChanged(format); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DecoderOnOutputChangedFuzzTest(data, size); + return 0; +} + diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.h b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..c8115c18bc5b9de574c32e32ac4f48f31e5a39e7 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/decoderonoutputchanged_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef DECODERONOUTPUTCHANGED_FUZZER_H +#define DECODERONOUTPUTCHANGED_FUZZER_H + +#define FUZZ_PROJECT_NAME "decoderonoutputchanged_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/decoderonoutputchanged_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4b1886a81f690b65ad36803d7c437ab1879c1428 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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("EncoderOnErrorFuzzTest") { + module_out_path = "distributed_audio/encoderonerror" + fuzz_config_file = + "${audio_processor_path}/test/fuzztest/encoderonerror_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "encoderonerror_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", + "${audio_processor_path}/encoder/include", + ] + + deps = [ + "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "player_framework:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"EncoderOnErrorFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":EncoderOnErrorFuzzTest" ] +} +############################################################################### diff --git a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonerror_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/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.cpp b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8b4c7eb0ed499eba8650a06b499f6f81a88b16c5 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#include "encoderonerror_fuzzer.h" + +#include +#include + +#include "audio_encoder.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void EncoderOnErrorFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return; + } + + int32_t type = *(reinterpret_cast(data)); + std::shared_ptr encoder = std::make_shared(); + AudioEvent event(static_cast(type), ""); + encoder->OnError(event); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::EncoderOnErrorFuzzTest(data, size); + return 0; +} + diff --git a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.h b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..b797dcab8a3913cddaf483cf9311c2cc958dcd35 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/encoderonerror_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef ENCODERONERROR_FUZZER_H +#define ENCODERONERROR_FUZZER_H + +#define FUZZ_PROJECT_NAME "encoderonerror_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonerror_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..318b77e6c77fec27196e8f30e1a452afa483a37a --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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("EncoderOnInputAvailableFuzzTest") { + module_out_path = "distributed_audio/encoderoninputavailable" + fuzz_config_file = + "${audio_processor_path}/test/fuzztest/encoderoninputavailable_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "encoderoninputavailable_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", + "${audio_processor_path}/encoder/include", + ] + + deps = [ + "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "player_framework:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"EncoderOnInputAvailableFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":EncoderOnInputAvailableFuzzTest" ] +} +############################################################################### diff --git a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderoninputavailable_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/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.cpp b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1876bc6ab4930b0a7758e61f19aef6a72bab2247 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#include "encoderoninputavailable_fuzzer.h" + +#include +#include + +#include "audio_encoder.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void EncoderOnInputAvailabelFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return; + } + + uint32_t index = *(reinterpret_cast(data)); + std::shared_ptr encoder = std::make_shared(); + encoder->OnInputBufferAvailable(index); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::EncoderOnInputAvailabelFuzzTest(data, size); + return 0; +} + diff --git a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.h b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..b33bee903b89b3eaac8ceb6c6e8cccd56469607c --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/encoderoninputavailable_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef ENCODERONINPUTAVAILABLE_FUZZER_H +#define ENCODERONINPUTAVAILABLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "encoderoninputavailable_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderoninputavailable_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2ed507fcdcd2ada95eba85175f1f0d8d7763338d --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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("EncoderOnOutputAvailableFuzzTest") { + module_out_path = "distributed_audio/encoderonoutputavailable" + fuzz_config_file = + "${audio_processor_path}/test/fuzztest/encoderonoutputavailable_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "encoderonoutputavailable_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", + "${audio_processor_path}/encoder/include", + ] + + deps = [ + "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "player_framework:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"EncoderOnOutputAvailableFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":EncoderOnOutputAvailableFuzzTest" ] +} +############################################################################### diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_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/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.cpp b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e730ae6bf30651448aa4f777ff030127de03576 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include "encoderonoutputavailable_fuzzer.h" + +#include +#include + +#include "audio_encoder.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void EncoderOnOutputAvailabelFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return; + } + + uint32_t index = *(reinterpret_cast(data)); + int64_t presentTimeUs = *(reinterpret_cast(data)); + int32_t infoSize = *(reinterpret_cast(data)); + int32_t offset = *(reinterpret_cast(data)); + int32_t bufferFlag = *(reinterpret_cast(data)); + Media::AVCodecBufferInfo info = {presentTimeUs, infoSize, offset}; + Media::AVCodecBufferFlag flag = static_cast(bufferFlag); + std::shared_ptr encoder = std::make_shared(); + encoder->OnOutputBufferAvailable(index, info, flag); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::EncoderOnOutputAvailabelFuzzTest(data, size); + return 0; +} + diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.h b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4634e5621d608d61777b8e3d092f157068d26c99 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/encoderonoutputavailable_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef ENCODERONOUTPUTAVAILABLE_FUZZER_H +#define ENCODERONOUTPUTAVAILABLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "encoderonoutputavailable_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonoutputavailable_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/BUILD.gn b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b80cacb83001ae93adc409320db5bf1fdd2b33ee --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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("EncoderOnOutputChangedFuzzTest") { + module_out_path = "distributed_audio/encoderonoutputchanged" + fuzz_config_file = + "${audio_processor_path}/test/fuzztest/encoderonoutputchanged_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "encoderonoutputchanged_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", + "${audio_processor_path}/encoder/include", + ] + + deps = [ + "${audio_transport_path}/encodetransport:distributed_audio_encode_transport", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "player_framework:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"EncoderOnOutputChangedFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":EncoderOnOutputChangedFuzzTest" ] +} +############################################################################### diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/corpus/init b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_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/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.cpp b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c5b65e545a368a1951e848cb085ffdff1f5fea5 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#include "encoderonoutputchanged_fuzzer.h" + +#include +#include + +#include "audio_encoder.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void EncoderOnOutputChangedFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return; + } + + Media::Format format; + std::shared_ptr encoder = std::make_shared(); + encoder->OnOutputFormatChanged(format); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::EncoderOnOutputChangedFuzzTest(data, size); + return 0; +} + diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.h b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..103dd1229869bb1d3ea999e4d5f267be0d5d0e75 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/encoderonoutputchanged_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef ENCODERONOUTPUTCHANGED_FUZZER_H +#define ENCODERONOUTPUTCHANGED_FUZZER_H + +#define FUZZ_PROJECT_NAME "encoderonoutputchanged_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/project.xml b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/audioprocessor/test/fuzztest/encoderonoutputchanged_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiotransport/audiochannel/audiodatachannel/src/audio_data_channel.cpp b/services/audiotransport/audiochannel/audiodatachannel/src/audio_data_channel.cpp index d68284641061a30ad2fb3efae731a695abcff8a4..71c3b114e25d2852a9719aff5f987f62b5de2f2c 100644 --- a/services/audiotransport/audiochannel/audiodatachannel/src/audio_data_channel.cpp +++ b/services/audiotransport/audiochannel/audiodatachannel/src/audio_data_channel.cpp @@ -169,6 +169,10 @@ void AudioDataChannel::OnStreamReceived(int32_t sessionId, const StreamData *dat return; } + if (data == nullptr) { + DHLOGE("Received stream data is nullptr."); + return; + } DHLOGI("On audio stream received, sessionId: %d dataSize: %zu.", sessionId, data->bufLen); auto audioData = std::make_shared(data->bufLen); if (memcpy_s(audioData->Data(), audioData->Capacity(), reinterpret_cast(data->buf), data->bufLen) diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b2690de12705522bfb2ca9d00b2240f0d6b95847 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn @@ -0,0 +1,71 @@ +# 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("SoftbusOnBytesReceivedFuzzTest") { + module_out_path = "distributed_audio/softbusonbytesreceived" + fuzz_config_file = + "${softbusadapter_path}/test/fuzztest/softbusonbytesreceived_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "softbusonbytesreceived_fuzzer.cpp" ] + + include_dirs = [ + "${audio_transport_path}/audiochannel/interface", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${softbusadapter_path}/include", + "//third_party/json/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${audio_transport_path}/audiochannel/audiodatachannel/include", + ] + + deps = [ + "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SoftbusOnBytesReceivedFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SoftbusOnBytesReceivedFuzzTest" ] +} +############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_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/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1023f6e80303a40521b5bcfb2d660f48ec0dabce --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#include "softbusonbytesreceived_fuzzer.h" + +#include +#include + +#include "audio_data_channel.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SoftbusOnBytesReceivedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + std::string peerDevId(reinterpret_cast(data), size); + int32_t sessionId = *(reinterpret_cast(data)); + uint32_t len = *(reinterpret_cast(data)); + void *bytes = nullptr; + std::shared_ptr dataChannel = std::make_shared(peerDevId); + dataChannel->OnBytesReceived(sessionId, bytes, len); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SoftbusOnBytesReceivedFuzzTest(data, size); + return 0; +} + diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..245aaab342df157b4e1deb9aaa2f1e26bfaf5d92 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef SOFTBUSONBYTESRECEIVED_FUZZER_H +#define SOFTBUSONBYTESRECEIVED_FUZZER_H + +#define FUZZ_PROJECT_NAME "softbusonbytesreceived_fuzzer" + +#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c8ae11449ffa8370b43b0bb65349baeaf5c369df --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn @@ -0,0 +1,71 @@ +# 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("SoftbusOnSessionClosedFuzzTest") { + module_out_path = "distributed_audio/softbusonsessionclosed" + fuzz_config_file = + "${softbusadapter_path}/test/fuzztest/softbusonsessionclosed_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "softbusonsessionclosed_fuzzer.cpp" ] + + include_dirs = [ + "${audio_transport_path}/audiochannel/interface", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${softbusadapter_path}/include", + "//third_party/json/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${audio_transport_path}/audiochannel/audiodatachannel/include", + ] + + deps = [ + "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SoftbusOnSessionClosedFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SoftbusOnSessionClosedFuzzTest" ] +} +############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_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/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4bf40259ae2459b42c49ea6931d2c2e7373b67b0 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#include "softbusonsessionclosed_fuzzer.h" + +#include +#include + +#include "audio_data_channel.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SoftbusOnSessionClosedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + std::string peerDevId(reinterpret_cast(data), size); + int32_t sessionId = *(reinterpret_cast(data)); + std::shared_ptr dataChannel = std::make_shared(peerDevId); + dataChannel->OnSessionClosed(sessionId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SoftbusOnSessionClosedFuzzTest(data, size); + return 0; +} + diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8641aaaa2db177f4f941c12d679a9252c29ddea9 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef SOFTBUSONSESSIONCLOSED_FUZZER_H +#define SOFTBUSONSESSIONCLOSED_FUZZER_H + +#define FUZZ_PROJECT_NAME "softbusonsessionclosed_fuzzer" + +#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d8e08c9cb7c22858a8c8b0ca9f9a8618c05d9f35 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn @@ -0,0 +1,71 @@ +# 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("SoftbusOnSessionOpenedFuzzTest") { + module_out_path = "distributed_audio/softbusonsessionopened" + fuzz_config_file = + "${softbusadapter_path}/test/fuzztest/softbusonsessionopened_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "softbusonsessionopened_fuzzer.cpp" ] + + include_dirs = [ + "${audio_transport_path}/audiochannel/interface", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${softbusadapter_path}/include", + "//third_party/json/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${audio_transport_path}/audiochannel/audiodatachannel/include", + ] + + deps = [ + "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SoftbusOnSessionOpenedFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SoftbusOnSessionOpenedFuzzTest" ] +} +############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonsessionopened_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/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6c540e5b63830f3254eca8f30b814ac1bc914f85 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#include "softbusonsessionopened_fuzzer.h" + +#include +#include + +#include "audio_data_channel.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SoftbusOnSessionOpenedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + std::string peerDevId(reinterpret_cast(data), size); + int32_t sessionId = *(reinterpret_cast(data)); + int32_t result = *(reinterpret_cast(data)); + std::shared_ptr dataChannel = std::make_shared(peerDevId); + dataChannel->OnSessionOpened(sessionId, result); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SoftbusOnSessionOpenedFuzzTest(data, size); + return 0; +} + diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8dbb5a98a3755b96e7bca50afc896e9b225c701b --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef SOFTBUSONSESSIONOPENED_FUZZER_H +#define SOFTBUSONSESSIONOPENED_FUZZER_H + +#define FUZZ_PROJECT_NAME "softbusonsessionopened_fuzzer" + +#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f8a875b642458c46fbb0b5a4e5c123a277cd86eb --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn @@ -0,0 +1,71 @@ +# 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("SoftbusOnStreamReceivedFuzzTest") { + module_out_path = "distributed_audio/softbusonstreamreceived" + fuzz_config_file = + "${softbusadapter_path}/test/fuzztest/softbusonstreamreceived_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "softbusonstreamreceived_fuzzer.cpp" ] + + include_dirs = [ + "${audio_transport_path}/audiochannel/interface", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${softbusadapter_path}/include", + "//third_party/json/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${audio_transport_path}/audiochannel/audiodatachannel/include", + ] + + deps = [ + "${audio_transport_path}/audiochannel/audiodatachannel:distributed_audio_data_channel", + "${services_path}/common:distributed_audio_utils", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SoftbusOnStreamReceivedFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SoftbusOnStreamReceivedFuzzTest" ] +} +############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..2b595da0c26af63ffb2d5f4132c086b2e5986fce --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_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/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3dcfab24b536a7ce5f678f8f17b72b48557b13d1 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#include "softbusonstreamreceived_fuzzer.h" + +#include +#include + +#include "audio_data_channel.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SoftbusOnStreamReceivedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + std::string peerDevId(reinterpret_cast(data), size); + int32_t sessionId = *(reinterpret_cast(data)); + StreamData *stream = nullptr; + StreamData *ext = nullptr; + StreamFrameInfo *info = nullptr; + std::shared_ptr dataChannel = std::make_shared(peerDevId); + dataChannel->OnStreamReceived(sessionId, stream, ext, info); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SoftbusOnStreamReceivedFuzzTest(data, size); + return 0; +} + diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..245aaab342df157b4e1deb9aaa2f1e26bfaf5d92 --- /dev/null +++ b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef SOFTBUSONBYTESRECEIVED_FUZZER_H +#define SOFTBUSONBYTESRECEIVED_FUZZER_H + +#define FUZZ_PROJECT_NAME "softbusonbytesreceived_fuzzer" + +#endif \ No newline at end of file