diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index fcc2a5f1e232a0f43a02bded4b535401b7be33c5..9c6060dac09c4ecff26e5830eb15c8a61b3daaf4 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -37,6 +37,7 @@ group("fuzztest") { "${services_path}/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkservicedump_fuzzer:fuzztest", "${services_path}/common/test/fuzztest/audiodatasetinit64_fuzzer:fuzztest", + "${services_path}/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer:fuzztest", "onremotesinksvrdied_fuzzer:fuzztest", "onremotesourcesvrdied_fuzzer:fuzztest", "sinkhandlerfinishstartsa_fuzzer:fuzztest", diff --git a/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/BUILD.gn b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..def4c4d409667c9f6eaada6216cb20204106b89d --- /dev/null +++ b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/BUILD.gn @@ -0,0 +1,107 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkCtrlTransOnChannelEventFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sinkctrltransonchannelevent_fuzzer" + fuzz_config_file = + "${services_path}/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkctrltransonchannelevent_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${audio_client_path}/interface", + "${audio_client_path}/micclient/include", + "${audio_client_path}/spkclient/include", + "${audio_control_path}/controlsink/include", + "${audio_processor_path}/interface", + "${audio_transport_path}/interface", + "${audio_transport_path}/audioctrltransport/include", + "${audio_transport_path}/receiverengine/include", + "${audio_transport_path}/senderengine/include", + "${common_path}/dfx_utils/include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${innerkits_path}/native_cpp/audio_source/include", + "${services_path}/audiomanager/managersink/include", + "${services_path}/common/audioeventcallback", + "${services_path}/common/audiodata/include", + "${services_path}/common/audioparam", + ] + + deps = [ + "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkCtrlTransOnChannelEventFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "cJSON:cjson", + "distributed_hardware_fwk:distributed_av_sender", + "distributed_hardware_fwk:distributedhardwareutils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "access_token:libtokensetproc_shared", + "audio_framework:audio_capturer", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "cJSON:cjson", + "c_utils:utils", + "device_manager:devicemanagersdk", + "distributed_hardware_fwk:distributed_av_receiver", + "distributed_hardware_fwk:distributed_av_sender", + "distributed_hardware_fwk:distributedhardwareutils", + "distributed_hardware_fwk:libdhfwk_sdk", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "hdf_core:libhdf_ipc_adapter", + "hdf_core:libhdi", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "os_account:libaccountkits", + "os_account:os_account_innerkits", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkCtrlTransOnChannelEventFuzzTest" ] +} +############################################################################### diff --git a/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/corpus/init b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /dev/null +++ b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/project.xml b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/sinkctrltransonchannelevent_fuzzer.cpp b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/sinkctrltransonchannelevent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..238ab419c06af0f90ed68cd104e3f7d95a187014 --- /dev/null +++ b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/sinkctrltransonchannelevent_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "av_trans_message.h" +#include "av_trans_types.h" + +#include +#include "daudio_sink_ctrl_trans.h" +#include "sinkctrltransonchannelevent_fuzzer.h" +#include "transport/socket.h" + +#include + +#include "daudio_constants.h" +#include "daudio_errorcode.h" +#include "daudio_log.h" +#include "daudio_util.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkCtrlTransOnChannelEventFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return; + } + std::string devId = "devId"; + std::string sessionName = "sessionName"; + std::string peerSessName = "peerSessName"; + auto sinkCtrlTransCb = std::make_shared(); + auto ctrlTrans = DaudioSinkCtrlTrans(devId, sessionName, peerSessName, sinkCtrlTransCb); + FuzzedDataProvider fdp(data, size); + AVTransEvent event; + event.content = fdp.ConsumeRandomLengthString(); + event.peerDevId = fdp.ConsumeRandomLengthString(); + event.type = static_cast(fdp.ConsumeIntegral()); + ctrlTrans.OnChannelEvent(event); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkCtrlTransOnChannelEventFuzzTest(data, size); + return 0; +} + diff --git a/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/sinkctrltransonchannelevent_fuzzer.h b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/sinkctrltransonchannelevent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..3684a5d17c243d4ab2db378260e7b4d75b535b00 --- /dev/null +++ b/services/audiotransport/test/fuzztest/sinkctrltransonchannelevent_fuzzer/sinkctrltransonchannelevent_fuzzer.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SINKCTRLTRANSONCHANNELEVENT_FUZZER_H +#define SINKCTRLTRANSONCHANNELEVENT_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkctrltransonchannelevent_fuzzer" +#include "iaudio_ctrltrans_callback.h" +namespace OHOS { +namespace DistributedHardware { +class SinkCtrlTransOnChannelEventFuzzer : public IAudioCtrlTransCallback { +public: + SinkCtrlTransOnChannelEventFuzzer() = default; + ~SinkCtrlTransOnChannelEventFuzzer() = default; + + void OnCtrlTransEvent(const AVTransEvent &event) override + { + (void)event; + } + void OnCtrlTransMessage(const std::shared_ptr &message) override + { + (void)message; + } +}; +} +} +#endif \ No newline at end of file diff --git a/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/BUILD.gn b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ef486278c4721d1b2ccf6a0bd8940e419894f08f --- /dev/null +++ b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/BUILD.gn @@ -0,0 +1,107 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceCtrlTransOnChannelEventFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sourcectrltransonchannelevent_fuzzer" + fuzz_config_file = + "${services_path}/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sourcectrltransonchannelevent_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${audio_client_path}/interface", + "${audio_client_path}/micclient/include", + "${audio_client_path}/spkclient/include", + "${audio_control_path}/controlsink/include", + "${audio_processor_path}/interface", + "${audio_transport_path}/interface", + "${audio_transport_path}/audioctrltransport/include", + "${audio_transport_path}/receiverengine/include", + "${audio_transport_path}/senderengine/include", + "${common_path}/dfx_utils/include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${innerkits_path}/native_cpp/audio_source/include", + "${services_path}/audiomanager/managersink/include", + "${services_path}/common/audioeventcallback", + "${services_path}/common/audiodata/include", + "${services_path}/common/audioparam", + ] + + deps = [ + "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceCtrlTransOnChannelEventFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "cJSON:cjson", + "distributed_hardware_fwk:distributed_av_sender", + "distributed_hardware_fwk:distributedhardwareutils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "access_token:libtokensetproc_shared", + "audio_framework:audio_capturer", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "cJSON:cjson", + "c_utils:utils", + "device_manager:devicemanagersdk", + "distributed_hardware_fwk:distributed_av_receiver", + "distributed_hardware_fwk:distributed_av_sender", + "distributed_hardware_fwk:distributedhardwareutils", + "distributed_hardware_fwk:libdhfwk_sdk", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "hdf_core:libhdf_ipc_adapter", + "hdf_core:libhdi", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "os_account:libaccountkits", + "os_account:os_account_innerkits", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceCtrlTransOnChannelEventFuzzTest" ] +} +############################################################################### diff --git a/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/corpus/init b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /dev/null +++ b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/project.xml b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/sourcectrltransonchannelevent_fuzzer.cpp b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/sourcectrltransonchannelevent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..36f1a20d1f61b9a6240eb280d9e053ba14f51cf8 --- /dev/null +++ b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/sourcectrltransonchannelevent_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "av_trans_message.h" +#include "av_trans_types.h" + +#include +#include "daudio_sink_ctrl_trans.h" +#include "sourcectrltransonchannelevent_fuzzer.h" +#include "transport/socket.h" + +#include + +#include "daudio_constants.h" +#include "daudio_errorcode.h" +#include "daudio_log.h" +#include "daudio_util.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceCtrlTransOnChannelEventFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return; + } + std::string devId = "devId"; + std::string sessionName = "sessionName"; + std::string peerSessName = "peerSessName"; + auto sinkCtrlTransCb = std::make_shared(); + auto ctrlTrans = DaudioSinkCtrlTrans(devId, sessionName, peerSessName, sinkCtrlTransCb); + FuzzedDataProvider fdp(data, size); + AVTransEvent event; + event.content = fdp.ConsumeRandomLengthString(); + event.peerDevId = fdp.ConsumeRandomLengthString(); + event.type = static_cast(fdp.ConsumeIntegral()); + ctrlTrans.OnChannelEvent(event); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceCtrlTransOnChannelEventFuzzTest(data, size); + return 0; +} + diff --git a/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/sourcectrltransonchannelevent_fuzzer.h b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/sourcectrltransonchannelevent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..0833bc73fe8c12099daaf7fbd64cc2b3b4d34e6d --- /dev/null +++ b/services/audiotransport/test/fuzztest/sourcectrltransonchannelevent_fuzzer/sourcectrltransonchannelevent_fuzzer.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCECTRLTRANSONCHANNELEVENT_FUZZER_H +#define SOURCECTRLTRANSONCHANNELEVENT_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourcectrltransonchannelevent_fuzzer" +#include "iaudio_ctrltrans_callback.h" +namespace OHOS { +namespace DistributedHardware { +class SourceCtrlTransOnChannelEventFuzzer : public IAudioCtrlTransCallback { +public: + SourceCtrlTransOnChannelEventFuzzer() = default; + ~SourceCtrlTransOnChannelEventFuzzer() = default; + + void OnCtrlTransEvent(const AVTransEvent &event) override + { + (void)event; + } + void OnCtrlTransMessage(const std::shared_ptr &message) override + { + (void)message; + } +}; +} +} +#endif \ No newline at end of file