diff --git a/test/BUILD.gn b/test/BUILD.gn index 5af462a254a6d1801995c84d7c7e9bc148a92913..c55c11876a710495e8532207d885d7adc5ecba81 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -227,15 +227,12 @@ group("audio_fuzz_test") { "fuzztest/audiopipemanager_fuzzer:fuzztest", "fuzztest/audiopipeselector_fuzzer:fuzztest", "fuzztest/audiopnpserver_fuzzer:fuzztest", - "fuzztest/audiopolicy_fuzzer:fuzztest", # "fuzztest/audiopolicyanother_fuzzer:fuzztest", # "fuzztest/audiopolicyclient_fuzzer:fuzztest", - "fuzztest/audiopolicyconcurrency_fuzzer:fuzztest", "fuzztest/audiopolicymanager_fuzzer:fuzztest", # "fuzztest/audiopolicymore_fuzzer:fuzztest", - "fuzztest/audiopolicyproxy_fuzzer:fuzztest", # "fuzztest/audiopolicyservenhance_fuzzer:fuzztest", "fuzztest/audiopolicyserverhandler_fuzzer:fuzztest", diff --git a/test/fuzztest/audiobluetoothmanager_fuzzer/audiobluetoothmanager_fuzzer.cpp b/test/fuzztest/audiobluetoothmanager_fuzzer/audiobluetoothmanager_fuzzer.cpp index ecb0a9115a7bda5c8abfae6fd54c5679ca8b3269..63a2cf0e6efa5882a84f6f45f96ad1af65640777 100644 --- a/test/fuzztest/audiobluetoothmanager_fuzzer/audiobluetoothmanager_fuzzer.cpp +++ b/test/fuzztest/audiobluetoothmanager_fuzzer/audiobluetoothmanager_fuzzer.cpp @@ -32,7 +32,7 @@ const int32_t LIMITSIZE = 4; const int32_t SYSTEM_ABILITY_ID = 3009; const bool RUN_ON_CREATE = false; const std::u16string FORMMGR_INTERFACE_TOKEN = u"IAudioPolicy"; -const uint8_t TESTSIZE = 4; +const uint8_t TESTSIZE = 2; typedef void (*TestPtr)(const uint8_t *, size_t); bool g_hasServerInit = false; static size_t g_dataSize = 0; @@ -57,36 +57,6 @@ sptr GetServerPtr() return server; } -void AudioBluetoothManagerFuzzTest(const uint8_t *rawData, size_t size) -{ - if (rawData == nullptr || size < LIMITSIZE) { - return; - } - - sptr AudioPolicyServerPtr = GetServerPtr(); - - if (AudioPolicyServerPtr == nullptr) { - return; - } - - DeviceType devType = *reinterpret_cast(rawData); - bool isConnected = *reinterpret_cast(rawData); - std::string macAddress(reinterpret_cast(rawData), size); - std::string deviceName(reinterpret_cast(rawData), size); - - AudioStreamInfo audioStreamInfo = {}; - audioStreamInfo.samplingRate = *reinterpret_cast(rawData); - audioStreamInfo.encoding = *reinterpret_cast(rawData); - audioStreamInfo.format = *reinterpret_cast(rawData); - audioStreamInfo.channels = *reinterpret_cast(rawData); - - AudioPolicyServerPtr->audioPolicyService_ - .OnDeviceStatusUpdated(devType, isConnected, macAddress, deviceName, audioStreamInfo); - - AudioPolicyServerPtr->audioPolicyService_ - .OnDeviceConfigurationChanged(devType, macAddress, deviceName, audioStreamInfo); -} - void AudioA2dpManagerFuzzTest(const uint8_t *rawData, size_t size) { if (rawData == nullptr || size < LIMITSIZE) { @@ -115,29 +85,12 @@ void AudioHfpManagerFuzzTest(const uint8_t *rawData, size_t size) Bluetooth::AudioHfpManager::UpdateAudioScene(scene); Bluetooth::AudioHfpManager::IsAudioScoStateConnect(); } - -void FetchOutputDeviceForTrackInternalFuzzTest(const uint8_t *rawData, size_t size) -{ - if (rawData == nullptr || size < LIMITSIZE) { - return; - } - - MessageParcel data; - data.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - - AudioStreamChangeInfo streamChangeInfo = {}; - streamChangeInfo.audioRendererChangeInfo.Unmarshalling(data); -} } // namespace AudioStandard } // namesapce OHOS OHOS::AudioStandard::TestPtr g_testPtrs[OHOS::AudioStandard::TESTSIZE] = { - OHOS::AudioStandard::AudioBluetoothManagerFuzzTest, OHOS::AudioStandard::AudioA2dpManagerFuzzTest, OHOS::AudioStandard::AudioHfpManagerFuzzTest, - OHOS::AudioStandard::FetchOutputDeviceForTrackInternalFuzzTest }; /* Fuzzer entry point */ diff --git a/test/fuzztest/audiointerruptservicemore_fuzzer/audio_interrupt_service_more_fuzzer.cpp b/test/fuzztest/audiointerruptservicemore_fuzzer/audio_interrupt_service_more_fuzzer.cpp index 47b1270efa3ca11aed5c466abc2af08cc9aa9b39..b749bf5e8b8e4a6b576a7c5e12c6b470cd38256e 100644 --- a/test/fuzztest/audiointerruptservicemore_fuzzer/audio_interrupt_service_more_fuzzer.cpp +++ b/test/fuzztest/audiointerruptservicemore_fuzzer/audio_interrupt_service_more_fuzzer.cpp @@ -134,27 +134,6 @@ void MoreFuzzTest() interruptService->HandleSessionTimeOutEvent(pid); } -void AddAudioSessionFuzzTest() -{ - int32_t sessionStrategy = 0; - GetServerPtr()->ActivateAudioSession(sessionStrategy); - - AudioInterrupt incomingInterrupt; - incomingInterrupt.audioFocusType.streamType = STREAM_MUSIC; - incomingInterrupt.audioFocusType.sourceType = SOURCE_TYPE_VOICE_COMMUNICATION; - AudioInterrupt activeInterrupt; - activeInterrupt.audioFocusType.streamType = STREAM_MUSIC; - AudioFocusEntry focusEntry; - focusEntry.isReject = false; - - std::shared_ptr interruptService = std::make_shared(); - interruptService->CanMixForSession(incomingInterrupt, activeInterrupt, focusEntry); - interruptService->CanMixForIncomingSession(incomingInterrupt, activeInterrupt, focusEntry); - interruptService->CanMixForActiveSession(incomingInterrupt, activeInterrupt, focusEntry); - interruptService->IsIncomingStreamLowPriority(focusEntry); - interruptService->IsActiveStreamLowPriority(focusEntry); -} - void AddSetAudioManagerInterruptCallbackFuzzTest() { MessageParcel data; @@ -182,11 +161,10 @@ void ClearAudioFocusInfoListOnAccountsChangedFuzzTest() interruptService->ClearAudioFocusInfoListOnAccountsChanged(id); } -typedef void (*TestFuncs[4])(); +typedef void (*TestFuncs[3])(); TestFuncs g_testFuncs = { MoreFuzzTest, - AddAudioSessionFuzzTest, AddSetAudioManagerInterruptCallbackFuzzTest, ClearAudioFocusInfoListOnAccountsChangedFuzzTest, }; diff --git a/test/fuzztest/audiopolicy_fuzzer/BUILD.gn b/test/fuzztest/audiopolicy_fuzzer/BUILD.gn deleted file mode 100644 index 18ca79df49934789dc28ab972765e6f85289734e..0000000000000000000000000000000000000000 --- a/test/fuzztest/audiopolicy_fuzzer/BUILD.gn +++ /dev/null @@ -1,145 +0,0 @@ -# Copyright (c) 2022-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. - -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../accessibility.gni") -import("../../../appgallery.gni") -import("../../../bluetooth_part.gni") -import("../../../config.gni") - -ohos_fuzztest("AudioPolicyFuzzTest") { - module_out_path = "audio_framework/audio_framework_route" - fuzz_config_file = "../audiopolicy_fuzzer" - - include_dirs = [ - "../../../services/audio_policy/client/include", - "../../../services/audio_policy/server/include", - "../../../services/audio_policy/server/include/service", - "../../../services/audio_policy/server/include/service/manager", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - cflags_cc = cflags - cflags_cc += [ "-fno-access-control" ] - - configs = [ "../../../services/audio_policy:audio_policy_public_config" ] - - defines = [] - if (audio_framework_feature_dtmf_tone) { - defines += [ "FEATURE_DTMF_TONE" ] - } - if (use_libfuzzer || use_clang_coverage) { - defines += [ "TEST_COVERAGE" ] - } - - sources = [ "audio_policy_fuzzer.cpp" ] - - deps = [ - "../../../services/audio_service/idl:audio_framework_interface", - "../../../frameworks/native/audioutils:audio_utils", - "../../../services/audio_policy:audio_policy_client_static", - "../../../services/audio_policy:audio_policy_service_static", - ] - - external_deps = [ - "ability_base:want", - "ability_runtime:extension_manager", - "ability_runtime:wantagent_innerkits", - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken_shared", - "access_token:libtokensetproc_shared", - "background_task_mgr:bgtaskmgr_innerkits", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "data_share:datashare_common", - "data_share:datashare_consumer", - "hdf_core:libhdf_ipc_adapter", - "hdf_core:libhdi", - "hdf_core:libpub_utils", - "hilog:libhilog", - "ipc:ipc_single", - "kv_store:distributeddata_inner", - "media_foundation:media_monitor_client", - "media_foundation:media_monitor_common", - "os_account:os_account_innerkits", - "power_manager:powermgr_client", - "relational_store:native_appdatafwk", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] - if (accessibility_enable == true) { - external_deps += [ - "accessibility:accessibility_common", - "accessibility:accessibilityconfig", - ] - } - - if (build_variant == "user") { - defines += [ "AUDIO_BUILD_VARIANT_USER" ] - } else if (build_variant == "root") { - defines += [ "AUDIO_BUILD_VARIANT_ROOT" ] - } - - if (audio_framework_feature_support_os_account) { - defines += [ "SUPPORT_USER_ACCOUNT" ] - } - - if (audio_framework_feature_dtmf_tone) { - defines += [ "FEATURE_DTMF_TONE" ] - } - - if (audio_framework_config_policy_enable) { - defines += [ "USE_CONFIG_POLICY" ] - external_deps += [ "config_policy:configpolicy_util" ] - } - - if (accessibility_enable == true) { - external_deps += [ - "accessibility:accessibility_common", - "accessibility:accessibilityconfig", - ] - } - - if (appgallery_part_enable == true) { - defines += [ "FEATURE_APPGALLERY" ] - } - - if (bluetooth_part_enable == true) { - deps += - [ "../../../frameworks/native/bluetoothclient:audio_bluetooth_client" ] - external_deps += [ "bluetooth:btframework" ] - } - - if (audio_framework_feature_input) { - defines += [ "FEATURE_MULTIMODALINPUT_INPUT" ] - external_deps += [ "input:libmmi-client" ] - } - - if (audio_framework_feature_device_manager) { - defines += [ "FEATURE_DEVICE_MANAGER" ] - external_deps += [ "device_manager:devicemanagersdk" ] - } -} - -group("fuzztest") { - testonly = true - deps = [ ":AudioPolicyFuzzTest" ] -} diff --git a/test/fuzztest/audiopolicy_fuzzer/audio_policy_fuzzer.cpp b/test/fuzztest/audiopolicy_fuzzer/audio_policy_fuzzer.cpp deleted file mode 100644 index e0b47f39d2979cbbdb1142698fe727e4d07c206e..0000000000000000000000000000000000000000 --- a/test/fuzztest/audiopolicy_fuzzer/audio_policy_fuzzer.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/* - * 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 -#include "audio_policy_server.h" -#include "message_parcel.h" -#include "accesstoken_kit.h" -#include "nativetoken_kit.h" -#include "token_setproc.h" -#include "access_token.h" -#include "dfx_msg_manager.h" -using namespace std; - -namespace OHOS { -namespace AudioStandard { -bool g_hasPermission = false; -constexpr int32_t OFFSET = 4; -const std::u16string FORMMGR_INTERFACE_TOKEN = u"IAudioPolicy"; -const int32_t SYSTEM_ABILITY_ID = 3009; -const bool RUN_ON_CREATE = false; -const int32_t LIMITSIZE = 4; -const int32_t SHIFT_LEFT_8 = 8; -const int32_t SHIFT_LEFT_16 = 16; -const int32_t SHIFT_LEFT_24 = 24; -const uint32_t LIMIT_ONE = 0; -const uint32_t LIMIT_TWO = 30; -const uint32_t LIMIT_THREE = 60; -const uint32_t LIMIT_FOUR = 90; -const uint32_t LIMIT_FIVE = 120; -const uint32_t LIMIT_SIX = static_cast(AudioPolicyInterfaceCode::AUDIO_POLICY_MANAGER_CODE_MAX); -bool g_hasServerInit = false; -const uint8_t TESTSIZE = 5; -typedef void (*TestPtr)(const uint8_t *, size_t); - -sptr GetServerPtr() -{ - static sptr server = sptr::MakeSptr(SYSTEM_ABILITY_ID, RUN_ON_CREATE); - if (!g_hasServerInit && server != nullptr) { - server->OnStart(); - server->OnAddSystemAbility(AUDIO_DISTRIBUTED_SERVICE_ID, ""); -#ifdef FEATURE_MULTIMODALINPUT_INPUT - server->OnAddSystemAbility(MULTIMODAL_INPUT_SERVICE_ID, ""); -#endif - server->OnAddSystemAbility(BLUETOOTH_HOST_SYS_ABILITY_ID, ""); - server->OnAddSystemAbility(POWER_MANAGER_SERVICE_ID, ""); - server->OnAddSystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN, ""); - server->audioPolicyService_.SetDefaultDeviceLoadFlag(true); - g_hasServerInit = true; - } - return server; -} - -uint32_t Convert2Uint32(const uint8_t *ptr) -{ - if (ptr == nullptr) { - return 0; - } - /* Move the 0th digit to the left by 24 bits, the 1st digit to the left by 16 bits, - the 2nd digit to the left by 8 bits, and the 3rd digit not to the left */ - return (ptr[0] << SHIFT_LEFT_24) | (ptr[1] << SHIFT_LEFT_16) | (ptr[2] << SHIFT_LEFT_8) | (ptr[3]); -} - -void AudioFuzzTestGetPermission() -{ - if (!g_hasPermission) { - uint64_t tokenId; - constexpr int perNum = 10; - const char *perms[perNum] = { - "ohos.permission.MICROPHONE", - "ohos.permission.MANAGE_INTELLIGENT_VOICE", - "ohos.permission.MANAGE_AUDIO_CONFIG", - "ohos.permission.MICROPHONE_CONTROL", - "ohos.permission.MODIFY_AUDIO_SETTINGS", - "ohos.permission.ACCESS_NOTIFICATION_POLICY", - "ohos.permission.USE_BLUETOOTH", - "ohos.permission.CAPTURE_VOICE_DOWNLINK_AUDIO", - "ohos.permission.RECORD_VOICE_CALL", - "ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS", - }; - - NativeTokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 10, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "audiofuzztest", - .aplStr = "system_basic", - }; - tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); - g_hasPermission = true; - } -} - -void ReleaseServer() -{ - if (GetServerPtr() == nullptr) { - return; - } - GetServerPtr()->OnStop(); - DfxMsgManager::GetInstance().HandleThreadExit(); - g_hasServerInit = false; -} - -void AudioPolicyFuzzFirstLimitTest(const uint8_t *rawData, size_t size) -{ - if (rawData == nullptr || size < LIMITSIZE) { - return; - } - uint32_t code = Convert2Uint32(rawData) % (LIMIT_TWO - LIMIT_ONE + 1) + LIMIT_ONE; - - rawData = rawData + OFFSET; - size = size - OFFSET; - - MessageParcel data; - data.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - - MessageParcel reply; - MessageOption option; - if (code == static_cast(AudioPolicyInterfaceCode::SET_SYSTEM_VOLUMELEVEL_WITH_DEVICE)) { - return; - } - - GetServerPtr()->OnRemoteRequest(code, data, reply, option); - ReleaseServer(); -} - -void AudioPolicyFuzzSecondLimitTest(const uint8_t *rawData, size_t size) -{ - if (rawData == nullptr || size < LIMITSIZE) { - return; - } - uint32_t code = Convert2Uint32(rawData) % (LIMIT_THREE - LIMIT_TWO + 1) + LIMIT_TWO; - - rawData = rawData + OFFSET; - size = size - OFFSET; - - MessageParcel data; - data.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - - MessageParcel reply; - MessageOption option; - - GetServerPtr()->OnRemoteRequest(code, data, reply, option); - ReleaseServer(); -} - -void AudioPolicyFuzzThirdLimitTest(const uint8_t *rawData, size_t size) -{ - if (rawData == nullptr || size < LIMITSIZE) { - return; - } - uint32_t code = Convert2Uint32(rawData) % (LIMIT_FOUR - LIMIT_THREE + 1) + LIMIT_THREE; - - rawData = rawData + OFFSET; - size = size - OFFSET; - - MessageParcel data; - data.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - - MessageParcel reply; - MessageOption option; - if (code == static_cast(AudioPolicyInterfaceCode::ADD_AUDIO_INTERRUPT_ZONE_PIDS)) { - return; - } - - GetServerPtr()->OnRemoteRequest(code, data, reply, option); - ReleaseServer(); -} - -void AudioPolicyFuzzFouthLimitTest(const uint8_t *rawData, size_t size) -{ - if (rawData == nullptr || size < LIMITSIZE) { - return; - } - uint32_t code = Convert2Uint32(rawData) % (LIMIT_FIVE - LIMIT_FOUR + 1) + LIMIT_FOUR; - - rawData = rawData + OFFSET; - size = size - OFFSET; - - MessageParcel data; - data.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - - MessageParcel reply; - MessageOption option; - - GetServerPtr()->OnRemoteRequest(code, data, reply, option); - ReleaseServer(); -} - -void AudioPolicyFuzzFifthLimitTest(const uint8_t *rawData, size_t size) -{ - if (rawData == nullptr || size < LIMITSIZE) { - return; - } - uint32_t code = Convert2Uint32(rawData) % (LIMIT_SIX - LIMIT_FIVE + 1) + LIMIT_FIVE; - - rawData = rawData + OFFSET; - size = size - OFFSET; - - MessageParcel data; - data.WriteInterfaceToken(FORMMGR_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - - MessageParcel reply; - MessageOption option; - if (code == static_cast(AudioPolicyInterfaceCode::EXCLUDE_OUTPUT_DEVICES) || - code == static_cast(AudioPolicyInterfaceCode::UNEXCLUDE_OUTPUT_DEVICES)) { - return; - } - - GetServerPtr()->OnRemoteRequest(code, data, reply, option); - ReleaseServer(); -} -} // namespace AudioStandard -} // namesapce OHOS - -extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) -{ - OHOS::AudioStandard::AudioFuzzTestGetPermission(); - return 0; -} - -OHOS::AudioStandard::TestPtr g_testPtrs[OHOS::AudioStandard::TESTSIZE] = { - OHOS::AudioStandard::AudioPolicyFuzzFirstLimitTest, - OHOS::AudioStandard::AudioPolicyFuzzSecondLimitTest, - OHOS::AudioStandard::AudioPolicyFuzzThirdLimitTest, - OHOS::AudioStandard::AudioPolicyFuzzFouthLimitTest, - OHOS::AudioStandard::AudioPolicyFuzzFifthLimitTest -}; - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr || size <= 1) { - return 0; - } - uint8_t firstByte = *data % OHOS::AudioStandard::TESTSIZE; - if (firstByte >= OHOS::AudioStandard::TESTSIZE) { - return 0; - } - data = data + 1; - size = size - 1; - g_testPtrs[firstByte](data, size); - return 0; -} diff --git a/test/fuzztest/audiopolicy_fuzzer/project.xml b/test/fuzztest/audiopolicy_fuzzer/project.xml deleted file mode 100644 index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..0000000000000000000000000000000000000000 --- a/test/fuzztest/audiopolicy_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/audiopolicyconcurrency_fuzzer/BUILD.gn b/test/fuzztest/audiopolicyconcurrency_fuzzer/BUILD.gn deleted file mode 100644 index a8d3208f4ad817e0a509d7ffae94771e82bf7b50..0000000000000000000000000000000000000000 --- a/test/fuzztest/audiopolicyconcurrency_fuzzer/BUILD.gn +++ /dev/null @@ -1,102 +0,0 @@ -# Copyright (c) 2024 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. - -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../accessibility.gni") -import("../../../bluetooth_part.gni") -import("../../../config.gni") - -ohos_fuzztest("AudioPolicyConcurrencyFuzzTest") { - module_out_path = "audio_framework/audio_framework_route" - fuzz_config_file = "../audiopolicyconcurrency_fuzzer" - - include_dirs = [ - "../../../services/audio_policy/server/include", - "../../../services/audio_policy/server/include/service", - "../../../services/audio_policy/server/include/service/concurrency", - "../../../services/audio_policy/server/include/service/listener", - ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - cflags_cc = cflags - cflags_cc += [ "-fno-access-control" ] - - configs = [ "../../../services/audio_policy:audio_policy_public_config" ] - - defines = [] - if (audio_framework_feature_dtmf_tone) { - defines += [ "FEATURE_DTMF_TONE" ] - } - if (use_libfuzzer || use_clang_coverage) { - defines += [ "TEST_COVERAGE" ] - } - if (audio_framework_feature_input) { - defines += [ "FEATURE_MULTIMODALINPUT_INPUT" ] - } - - sources = [ "audio_policy_concurrency_fuzzer.cpp" ] - - deps = [ - "../../../services/audio_service/idl:audio_framework_interface", - "../../../services/audio_policy:audio_policy_service_static", - "../../../services/audio_service:audio_client", - ] - - external_deps = [ - "ability_base:want", - "ability_runtime:extension_manager", - "ability_runtime:wantagent_innerkits", - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken_shared", - "access_token:libtokensetproc_shared", - "background_task_mgr:bgtaskmgr_innerkits", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "data_share:datashare_common", - "data_share:datashare_consumer", - "hdf_core:libhdf_ipc_adapter", - "hdf_core:libhdi", - "hdf_core:libpub_utils", - "hilog:libhilog", - "ipc:ipc_single", - "kv_store:distributeddata_inner", - "media_foundation:media_monitor_client", - "media_foundation:media_monitor_common", - "os_account:os_account_innerkits", - "power_manager:powermgr_client", - "relational_store:native_appdatafwk", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] - if (accessibility_enable == true) { - external_deps += [ - "accessibility:accessibility_common", - "accessibility:accessibilityconfig", - ] - } - if (bluetooth_part_enable == true) { - external_deps += [ "bluetooth:btframework" ] - } -} - -group("fuzztest") { - testonly = true - deps = [ ":AudioPolicyConcurrencyFuzzTest" ] -} diff --git a/test/fuzztest/audiopolicyconcurrency_fuzzer/audio_policy_concurrency_fuzzer.cpp b/test/fuzztest/audiopolicyconcurrency_fuzzer/audio_policy_concurrency_fuzzer.cpp deleted file mode 100644 index 937a1386a529a70087bc9b887964419f41ba4d28..0000000000000000000000000000000000000000 --- a/test/fuzztest/audiopolicyconcurrency_fuzzer/audio_policy_concurrency_fuzzer.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2024 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 -#include -#include -#include "audio_policy_server.h" -#include "audio_concurrency_service.h" -#include "power_state_listener.h" -#include "audio_device_info.h" -#include "message_parcel.h" -#include "accesstoken_kit.h" -#include "audio_routing_manager.h" -#include "audio_stream_manager.h" -#include "nativetoken_kit.h" -#include "token_setproc.h" -#include "access_token.h" -using namespace std; - -namespace OHOS { -namespace AudioStandard { -const int32_t LIMITSIZE = 4; -const int32_t SYSTEM_ABILITY_ID = 3009; -const bool RUN_ON_CREATE = false; -bool g_hasPermission = false; -bool g_hasServerInit = false; -static const uint8_t *RAW_DATA = nullptr; -static size_t g_dataSize = 0; -static size_t g_pos; -const size_t THRESHOLD = 10; - -sptr GetServerPtr() -{ - static sptr server = sptr::MakeSptr(SYSTEM_ABILITY_ID, RUN_ON_CREATE); - if (!g_hasServerInit && server != nullptr) { - server->OnStart(); - server->OnAddSystemAbility(AUDIO_DISTRIBUTED_SERVICE_ID, ""); -#ifdef FEATURE_MULTIMODALINPUT_INPUT - server->OnAddSystemAbility(MULTIMODAL_INPUT_SERVICE_ID, ""); -#endif - server->OnAddSystemAbility(BLUETOOTH_HOST_SYS_ABILITY_ID, ""); - server->OnAddSystemAbility(POWER_MANAGER_SERVICE_ID, ""); - server->OnAddSystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN, ""); - server->audioPolicyService_.SetDefaultDeviceLoadFlag(true); - g_hasServerInit = true; - } - return server; -} - -void AudioFuzzTestGetPermission() -{ - if (!g_hasPermission) { - uint64_t tokenId; - constexpr int perNum = 10; - const char *perms[perNum] = { - "ohos.permission.MICROPHONE", - "ohos.permission.MANAGE_INTELLIGENT_VOICE", - "ohos.permission.MANAGE_AUDIO_CONFIG", - "ohos.permission.MICROPHONE_CONTROL", - "ohos.permission.MODIFY_AUDIO_SETTINGS", - "ohos.permission.ACCESS_NOTIFICATION_POLICY", - "ohos.permission.USE_BLUETOOTH", - "ohos.permission.CAPTURE_VOICE_DOWNLINK_AUDIO", - "ohos.permission.RECORD_VOICE_CALL", - "ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS", - }; - - NativeTokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 10, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "audiofuzztest", - .aplStr = "system_basic", - }; - tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); - g_hasPermission = true; - } -} - -/* -* describe: get data from outside untrusted data(RAW_DATA) which size is according to sizeof(T) -* tips: only support basic type -*/ -template -T GetData() -{ - T object {}; - size_t objectSize = sizeof(object); - if (RAW_DATA == nullptr || objectSize > g_dataSize - g_pos) { - return object; - } - errno_t ret = memcpy_s(&object, objectSize, RAW_DATA + g_pos, objectSize); - if (ret != EOK) { - return {}; - } - g_pos += objectSize; - return object; -} - -template -uint32_t GetArrLength(T& arr) -{ - if (arr == nullptr) { - AUDIO_INFO_LOG("%{public}s: The array length is equal to 0", __func__); - return 0; - } - return sizeof(arr) / sizeof(arr[0]); -} - -void AudioPowerStateListenerFuzzTest() -{ - sptr audioPolicyServer; - sptr powerStub = - static_cast>(new(std::nothrow) PowerStateListener(audioPolicyServer)); - uint32_t code = GetData(); - MessageParcel data; - MessageParcel reply; - MessageOption option; - powerStub->OnRemoteRequest(code, data, reply, option); - powerStub->OnSyncSleepCallbackStub(data); - powerStub->OnSyncWakeupCallbackStub(data); - if (GetServerPtr() == nullptr) { - return; - } - GetServerPtr()->RegisterPowerStateListener(); - if (GetServerPtr()->powerStateListener_ != nullptr) { - GetServerPtr()->powerStateListener_->OnSyncSleep(true); - GetServerPtr()->powerStateListener_->OnSyncWakeup(true); - } - sptr syncStub = - static_cast>(new(std::nothrow) SyncHibernateListener(audioPolicyServer)); - syncStub->OnRemoteRequest(code, data, reply, option); - - GetServerPtr()->syncHibernateListener_->OnSyncHibernate(); - GetServerPtr()->syncHibernateListener_->OnSyncWakeup(true); -} - -typedef void (*TestFuncs[2])(); - -TestFuncs g_testFuncs = { - AudioPowerStateListenerFuzzTest, -}; - -bool FuzzTest(const uint8_t* rawData, size_t size) -{ - if (rawData == nullptr) { - return false; - } - - // initialize data - RAW_DATA = rawData; - g_dataSize = size; - g_pos = 0; - - uint32_t code = GetData(); - uint32_t len = GetArrLength(g_testFuncs); - if (len > 0) { - g_testFuncs[code % len](); - } else { - AUDIO_INFO_LOG("%{public}s: The len length is equal to 0", __func__); - } - - return true; -} -} // namespace AudioStandard -} // namesapce OHOS - -extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) -{ - OHOS::AudioStandard::AudioFuzzTestGetPermission(); - return 0; -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - if (size < OHOS::AudioStandard::THRESHOLD) { - return 0; - } - - OHOS::AudioStandard::FuzzTest(data, size); - return 0; -} \ No newline at end of file diff --git a/test/fuzztest/audiopolicyconcurrency_fuzzer/project.xml b/test/fuzztest/audiopolicyconcurrency_fuzzer/project.xml deleted file mode 100644 index 7133b2b92440904a5ed04b838733acea0f97486a..0000000000000000000000000000000000000000 --- a/test/fuzztest/audiopolicyconcurrency_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/audiopolicyproxy_fuzzer/BUILD.gn b/test/fuzztest/audiopolicyproxy_fuzzer/BUILD.gn deleted file mode 100644 index 0fe0a47594cf20a8cbb154941a3d632fbbbbde8c..0000000000000000000000000000000000000000 --- a/test/fuzztest/audiopolicyproxy_fuzzer/BUILD.gn +++ /dev/null @@ -1,145 +0,0 @@ -# Copyright (c) 2024 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. - -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../accessibility.gni") -import("../../../appgallery.gni") -import("../../../bluetooth_part.gni") -import("../../../config.gni") - -ohos_fuzztest("AudioPolicyProxyFuzzTest") { - module_out_path = "audio_framework/audio_framework_route" - fuzz_config_file = "../audiopolicyproxy_fuzzer" - - include_dirs = [ - "../../../services/audio_policy/client/include", - "../../../services/audio_policy/server/include", - "../../../services/audio_policy/server/include/service", - "../../../services/audio_policy/server/include/service/manager", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - cflags_cc = cflags - cflags_cc += [ "-fno-access-control" ] - - configs = [ "../../../services/audio_policy:audio_policy_public_config" ] - - sources = [ "audio_policy_proxy_fuzzer.cpp" ] - - defines = [] - if (audio_framework_feature_dtmf_tone) { - defines += [ "FEATURE_DTMF_TONE" ] - } - if (use_libfuzzer || use_clang_coverage) { - defines += [ "TEST_COVERAGE" ] - } - - deps = [ - "../../../services/audio_service/idl:audio_framework_interface", - "../../../frameworks/native/audioutils:audio_utils", - "../../../services/audio_policy:audio_policy_client_static", - "../../../services/audio_policy:audio_policy_service_static", - ] - - external_deps = [ - "ability_base:want", - "ability_runtime:extension_manager", - "ability_runtime:wantagent_innerkits", - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken_shared", - "access_token:libtokensetproc_shared", - "background_task_mgr:bgtaskmgr_innerkits", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "data_share:datashare_common", - "data_share:datashare_consumer", - "hdf_core:libhdf_ipc_adapter", - "hdf_core:libhdi", - "hdf_core:libpub_utils", - "hilog:libhilog", - "ipc:ipc_single", - "kv_store:distributeddata_inner", - "media_foundation:media_monitor_client", - "media_foundation:media_monitor_common", - "os_account:os_account_innerkits", - "power_manager:powermgr_client", - "relational_store:native_appdatafwk", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] - if (accessibility_enable == true) { - external_deps += [ - "accessibility:accessibility_common", - "accessibility:accessibilityconfig", - ] - } - - if (build_variant == "user") { - defines += [ "AUDIO_BUILD_VARIANT_USER" ] - } else if (build_variant == "root") { - defines += [ "AUDIO_BUILD_VARIANT_ROOT" ] - } - - if (audio_framework_feature_support_os_account) { - defines += [ "SUPPORT_USER_ACCOUNT" ] - } - - if (audio_framework_feature_dtmf_tone) { - defines += [ "FEATURE_DTMF_TONE" ] - } - - if (audio_framework_config_policy_enable) { - defines += [ "USE_CONFIG_POLICY" ] - external_deps += [ "config_policy:configpolicy_util" ] - } - - if (accessibility_enable == true) { - external_deps += [ - "accessibility:accessibility_common", - "accessibility:accessibilityconfig", - ] - } - - if (appgallery_part_enable == true) { - defines += [ "FEATURE_APPGALLERY" ] - } - - if (bluetooth_part_enable == true) { - deps += - [ "../../../frameworks/native/bluetoothclient:audio_bluetooth_client" ] - external_deps += [ "bluetooth:btframework" ] - } - - if (audio_framework_feature_input) { - defines += [ "FEATURE_MULTIMODALINPUT_INPUT" ] - external_deps += [ "input:libmmi-client" ] - } - - if (audio_framework_feature_device_manager) { - defines += [ "FEATURE_DEVICE_MANAGER" ] - external_deps += [ "device_manager:devicemanagersdk" ] - } -} - -group("fuzztest") { - testonly = true - # deps = [ ":AudioPolicyProxyFuzzTest" ] -} diff --git a/test/fuzztest/audiopolicyproxy_fuzzer/audio_policy_proxy_fuzzer.cpp b/test/fuzztest/audiopolicyproxy_fuzzer/audio_policy_proxy_fuzzer.cpp deleted file mode 100644 index b48e156cfde708e9d3a5f72546df79165f8040d8..0000000000000000000000000000000000000000 --- a/test/fuzztest/audiopolicyproxy_fuzzer/audio_policy_proxy_fuzzer.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2024 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 -#include -#include -#include "audio_policy_server.h" -#include "audio_policy_proxy.h" -#include "audio_device_info.h" -#include "message_parcel.h" -#include "accesstoken_kit.h" -#include "audio_routing_manager.h" -#include "audio_stream_manager.h" -#include "nativetoken_kit.h" -#include "token_setproc.h" -#include "access_token.h" -using namespace std; - -namespace OHOS { -namespace AudioStandard { -const int32_t LIMITSIZE = 4; -const std::u16string FORMMGR_INTERFACE_TOKEN = u"IAudioPolicy"; -const int32_t SYSTEM_ABILITY_ID = 3009; -const float FLOAT_VOLUME = 1.0f; -const bool RUN_ON_CREATE = false; -bool g_hasPermission = false; -bool g_hasServerInit = false; -static const uint8_t *RAW_DATA = nullptr; -static size_t g_dataSize = 0; -static size_t g_pos; -const size_t THRESHOLD = 10; - -sptr GetServerPtr() -{ - static sptr server = sptr::MakeSptr(SYSTEM_ABILITY_ID, RUN_ON_CREATE); - if (!g_hasServerInit && server != nullptr) { - server->OnStart(); - server->OnAddSystemAbility(AUDIO_DISTRIBUTED_SERVICE_ID, ""); -#ifdef FEATURE_MULTIMODALINPUT_INPUT - server->OnAddSystemAbility(MULTIMODAL_INPUT_SERVICE_ID, ""); -#endif - server->OnAddSystemAbility(BLUETOOTH_HOST_SYS_ABILITY_ID, ""); - server->OnAddSystemAbility(POWER_MANAGER_SERVICE_ID, ""); - server->OnAddSystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN, ""); - server->audioPolicyService_.SetDefaultDeviceLoadFlag(true); - g_hasServerInit = true; - } - return server; -} - -void AudioFuzzTestGetPermission() -{ - if (!g_hasPermission) { - uint64_t tokenId; - constexpr int perNum = 10; - const char *perms[perNum] = { - "ohos.permission.MICROPHONE", - "ohos.permission.MANAGE_INTELLIGENT_VOICE", - "ohos.permission.MANAGE_AUDIO_CONFIG", - "ohos.permission.MICROPHONE_CONTROL", - "ohos.permission.MODIFY_AUDIO_SETTINGS", - "ohos.permission.ACCESS_NOTIFICATION_POLICY", - "ohos.permission.USE_BLUETOOTH", - "ohos.permission.CAPTURE_VOICE_DOWNLINK_AUDIO", - "ohos.permission.RECORD_VOICE_CALL", - "ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS", - }; - - NativeTokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 10, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "audiofuzztest", - .aplStr = "system_basic", - }; - tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); - g_hasPermission = true; - } -} - -/* -* describe: get data from outside untrusted data(RAW_DATA) which size is according to sizeof(T) -* tips: only support basic type -*/ -template -T GetData() -{ - T object {}; - size_t objectSize = sizeof(object); - if (RAW_DATA == nullptr || objectSize > g_dataSize - g_pos) { - return object; - } - errno_t ret = memcpy_s(&object, objectSize, RAW_DATA + g_pos, objectSize); - if (ret != EOK) { - return {}; - } - g_pos += objectSize; - return object; -} - -template -uint32_t GetArrLength(T& arr) -{ - if (arr == nullptr) { - AUDIO_INFO_LOG("%{public}s: The array length is equal to 0", __func__); - return 0; - } - return sizeof(arr) / sizeof(arr[0]); -} - -typedef void (*TestFuncs[3])(); - -TestFuncs g_testFuncs = { - AudioPolicyCallbackFuzzTest, - AudioPolicyMicrophoneFuzzTest, - AudioPolicyVolumeFuzzTest, -}; - -bool FuzzTest(const uint8_t* rawData, size_t size) -{ - if (rawData == nullptr) { - return false; - } - - // initialize data - RAW_DATA = rawData; - g_dataSize = size; - g_pos = 0; - - uint32_t code = GetData(); - uint32_t len = GetArrLength(g_testFuncs); - if (len > 0) { - g_testFuncs[code % len](); - } else { - AUDIO_INFO_LOG("%{public}s: The len length is equal to 0", __func__); - } - - return true; -} -} // namespace AudioStandard -} // namesapce OHOS - -extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) -{ - OHOS::AudioStandard::AudioFuzzTestGetPermission(); - return 0; -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - if (size < OHOS::AudioStandard::THRESHOLD) { - return 0; - } - - OHOS::AudioStandard::FuzzTest(data, size); - return 0; -} \ No newline at end of file diff --git a/test/fuzztest/audiopolicyproxy_fuzzer/project.xml b/test/fuzztest/audiopolicyproxy_fuzzer/project.xml deleted file mode 100644 index 7133b2b92440904a5ed04b838733acea0f97486a..0000000000000000000000000000000000000000 --- a/test/fuzztest/audiopolicyproxy_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - -