From f20c9201d2989519d5ea2d834659dad65ebb9d86 Mon Sep 17 00:00:00 2001 From: zengsiyu Date: Mon, 14 Mar 2022 23:38:50 +0800 Subject: [PATCH] fuzztest Change-Id: I76993b024515a3fee3ab7d48477eb79e8f7940bc Signed-off-by: zengsiyu --- bundle.json | 3 +- .../AddNotificationSlotGroups_fuzzer.cpp | 46 +++++++++++++ .../AddNotificationSlotGroups_fuzzer.h | 29 +++++++++ .../AddNotificationSlotGroups_fuzzer/BUILD.gn | 53 +++++++++++++++ .../project.xml | 25 ++++++++ .../AddNotificationSlots_fuzzer.cpp | 64 +++++++++++++++++++ .../AddNotificationSlots_fuzzer.h | 29 +++++++++ .../AddNotificationSlots_fuzzer/BUILD.gn | 53 +++++++++++++++ .../AddNotificationSlots_fuzzer/project.xml | 25 ++++++++ .../AddSlotByType_fuzzer.cpp | 37 +++++++++++ .../AddSlotByType_fuzzer.h | 21 ++++++ test/fuzztest/AddSlotByType_fuzzer/BUILD.gn | 53 +++++++++++++++ .../fuzztest/AddSlotByType_fuzzer/project.xml | 25 ++++++++ test/fuzztest/BUILD.gn | 31 +++++++++ .../GetNotificationSlotGroup_fuzzer/BUILD.gn | 53 +++++++++++++++ .../GetNotificationSlotGroup_fuzzer.cpp | 35 ++++++++++ .../GetNotificationSlotGroup_fuzzer.h | 21 ++++++ .../project.xml | 25 ++++++++ .../BUILD.gn | 53 +++++++++++++++ .../GetNotificationSlotNumAsBundle_fuzzer.cpp | 39 +++++++++++ .../GetNotificationSlotNumAsBundle_fuzzer.h | 29 +++++++++ .../project.xml | 25 ++++++++ .../GetNotificationSlot_fuzzer/BUILD.gn | 53 +++++++++++++++ .../GetNotificationSlot_fuzzer.cpp | 38 +++++++++++ .../GetNotificationSlot_fuzzer.h | 29 +++++++++ .../GetNotificationSlot_fuzzer/project.xml | 25 ++++++++ .../BUILD.gn | 53 +++++++++++++++ .../RemoveNotificationSlotGroup_fuzzer.cpp | 34 ++++++++++ .../RemoveNotificationSlotGroup_fuzzer.h | 21 ++++++ .../project.xml | 25 ++++++++ .../RemoveNotificationSlot_fuzzer/BUILD.gn | 53 +++++++++++++++ .../RemoveNotificationSlot_fuzzer.cpp | 37 +++++++++++ .../RemoveNotificationSlot_fuzzer.h | 21 ++++++ .../RemoveNotificationSlot_fuzzer/project.xml | 25 ++++++++ .../RemoveNotification_fuzzer/BUILD.gn | 53 +++++++++++++++ .../RemoveNotification_fuzzer.cpp | 35 ++++++++++ .../RemoveNotification_fuzzer.h | 21 ++++++ .../RemoveNotification_fuzzer/project.xml | 25 ++++++++ .../SetNotificationBadgeNum_fuzzer/BUILD.gn | 53 +++++++++++++++ .../SetNotificationBadgeNum_fuzzer.cpp | 33 ++++++++++ .../SetNotificationBadgeNum_fuzzer.h | 29 +++++++++ .../project.xml | 25 ++++++++ 42 files changed, 1461 insertions(+), 1 deletion(-) create mode 100644 test/fuzztest/AddNotificationSlotGroups_fuzzer/AddNotificationSlotGroups_fuzzer.cpp create mode 100644 test/fuzztest/AddNotificationSlotGroups_fuzzer/AddNotificationSlotGroups_fuzzer.h create mode 100644 test/fuzztest/AddNotificationSlotGroups_fuzzer/BUILD.gn create mode 100644 test/fuzztest/AddNotificationSlotGroups_fuzzer/project.xml create mode 100644 test/fuzztest/AddNotificationSlots_fuzzer/AddNotificationSlots_fuzzer.cpp create mode 100644 test/fuzztest/AddNotificationSlots_fuzzer/AddNotificationSlots_fuzzer.h create mode 100644 test/fuzztest/AddNotificationSlots_fuzzer/BUILD.gn create mode 100644 test/fuzztest/AddNotificationSlots_fuzzer/project.xml create mode 100644 test/fuzztest/AddSlotByType_fuzzer/AddSlotByType_fuzzer.cpp create mode 100644 test/fuzztest/AddSlotByType_fuzzer/AddSlotByType_fuzzer.h create mode 100644 test/fuzztest/AddSlotByType_fuzzer/BUILD.gn create mode 100644 test/fuzztest/AddSlotByType_fuzzer/project.xml create mode 100644 test/fuzztest/BUILD.gn create mode 100644 test/fuzztest/GetNotificationSlotGroup_fuzzer/BUILD.gn create mode 100644 test/fuzztest/GetNotificationSlotGroup_fuzzer/GetNotificationSlotGroup_fuzzer.cpp create mode 100644 test/fuzztest/GetNotificationSlotGroup_fuzzer/GetNotificationSlotGroup_fuzzer.h create mode 100644 test/fuzztest/GetNotificationSlotGroup_fuzzer/project.xml create mode 100644 test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/BUILD.gn create mode 100644 test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/GetNotificationSlotNumAsBundle_fuzzer.cpp create mode 100644 test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/GetNotificationSlotNumAsBundle_fuzzer.h create mode 100644 test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/project.xml create mode 100644 test/fuzztest/GetNotificationSlot_fuzzer/BUILD.gn create mode 100644 test/fuzztest/GetNotificationSlot_fuzzer/GetNotificationSlot_fuzzer.cpp create mode 100644 test/fuzztest/GetNotificationSlot_fuzzer/GetNotificationSlot_fuzzer.h create mode 100644 test/fuzztest/GetNotificationSlot_fuzzer/project.xml create mode 100644 test/fuzztest/RemoveNotificationSlotGroup_fuzzer/BUILD.gn create mode 100644 test/fuzztest/RemoveNotificationSlotGroup_fuzzer/RemoveNotificationSlotGroup_fuzzer.cpp create mode 100644 test/fuzztest/RemoveNotificationSlotGroup_fuzzer/RemoveNotificationSlotGroup_fuzzer.h create mode 100644 test/fuzztest/RemoveNotificationSlotGroup_fuzzer/project.xml create mode 100644 test/fuzztest/RemoveNotificationSlot_fuzzer/BUILD.gn create mode 100644 test/fuzztest/RemoveNotificationSlot_fuzzer/RemoveNotificationSlot_fuzzer.cpp create mode 100644 test/fuzztest/RemoveNotificationSlot_fuzzer/RemoveNotificationSlot_fuzzer.h create mode 100644 test/fuzztest/RemoveNotificationSlot_fuzzer/project.xml create mode 100644 test/fuzztest/RemoveNotification_fuzzer/BUILD.gn create mode 100644 test/fuzztest/RemoveNotification_fuzzer/RemoveNotification_fuzzer.cpp create mode 100644 test/fuzztest/RemoveNotification_fuzzer/RemoveNotification_fuzzer.h create mode 100644 test/fuzztest/RemoveNotification_fuzzer/project.xml create mode 100644 test/fuzztest/SetNotificationBadgeNum_fuzzer/BUILD.gn create mode 100644 test/fuzztest/SetNotificationBadgeNum_fuzzer/SetNotificationBadgeNum_fuzzer.cpp create mode 100644 test/fuzztest/SetNotificationBadgeNum_fuzzer/SetNotificationBadgeNum_fuzzer.h create mode 100644 test/fuzztest/SetNotificationBadgeNum_fuzzer/project.xml diff --git a/bundle.json b/bundle.json index f4d1b6a3d..ebbd5d098 100644 --- a/bundle.json +++ b/bundle.json @@ -87,7 +87,8 @@ "//base/notification/ans_standard/services/test/moduletest:moduletest", "//base/notification/ans_standard/frameworks/ans/test/moduletest:moduletest", "//base/notification/ans_standard/frameworks/ans/native/test/unittest:unittest", - "//base/notification/ans_standard/test:systemtest" + "//base/notification/ans_standard/test:systemtest", + "//base/notification/ans_standard/test/fuzztest:fuzztest" ] } } diff --git a/test/fuzztest/AddNotificationSlotGroups_fuzzer/AddNotificationSlotGroups_fuzzer.cpp b/test/fuzztest/AddNotificationSlotGroups_fuzzer/AddNotificationSlotGroups_fuzzer.cpp new file mode 100644 index 000000000..c8a99e067 --- /dev/null +++ b/test/fuzztest/AddNotificationSlotGroups_fuzzer/AddNotificationSlotGroups_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * 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 "AddNotificationSlotGroups_fuzzer.h" + +#define private public +#include "notification_helper.h" +#undef private + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + std::string description = reinterpret_cast(data); + Notification::NotificationSlotGroup group; + group.SetDescription(description); + + Notification::NotificationSlot slot; + std::vector slots; + slots.emplace_back(slot); + group.SetSlots(slots); + + std::vector groups; + groups.emplace_back(group); + return Notification::NotificationHelper::AddNotificationSlotGroups(groups) == ERR_OK; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} diff --git a/test/fuzztest/AddNotificationSlotGroups_fuzzer/AddNotificationSlotGroups_fuzzer.h b/test/fuzztest/AddNotificationSlotGroups_fuzzer/AddNotificationSlotGroups_fuzzer.h new file mode 100644 index 000000000..9d8fa6a84 --- /dev/null +++ b/test/fuzztest/AddNotificationSlotGroups_fuzzer/AddNotificationSlotGroups_fuzzer.h @@ -0,0 +1,29 @@ +/* + * 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 TEST_FUZZTEST_ADDNOTIFICATIONSLOTGROUPS_FUZZER_ADDNOTIFICATIONSLOTGROUPS_FUZZER_H +#define TEST_FUZZTEST_ADDNOTIFICATIONSLOTGROUPS_FUZZER_ADDNOTIFICATIONSLOTGROUPS_FUZZER_H + +#define FUZZ_PROJECT_NAME "AddNotificationSlotGroups_fuzzer" + +#include + +uint32_t U32_AT(const uint8_t *ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; +} + +#endif // TEST_FUZZTEST_ADDNOTIFICATIONSLOTGROUPS_FUZZER_ADDNOTIFICATIONSLOTGROUPS_FUZZER_H diff --git a/test/fuzztest/AddNotificationSlotGroups_fuzzer/BUILD.gn b/test/fuzztest/AddNotificationSlotGroups_fuzzer/BUILD.gn new file mode 100644 index 000000000..ef81c8760 --- /dev/null +++ b/test/fuzztest/AddNotificationSlotGroups_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AddNotificationSlotGroupsFuzzTest") { + module_out_path = module_output_path + + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "AddNotificationSlotGroups_fuzzer.cpp" ] + + deps = [ + "${frameworks_path}/ans/native:ans_innerkits", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AddNotificationSlotGroupsFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/AddNotificationSlotGroups_fuzzer/project.xml b/test/fuzztest/AddNotificationSlotGroups_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/AddNotificationSlotGroups_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/AddNotificationSlots_fuzzer/AddNotificationSlots_fuzzer.cpp b/test/fuzztest/AddNotificationSlots_fuzzer/AddNotificationSlots_fuzzer.cpp new file mode 100644 index 000000000..314f9b6e2 --- /dev/null +++ b/test/fuzztest/AddNotificationSlots_fuzzer/AddNotificationSlots_fuzzer.cpp @@ -0,0 +1,64 @@ +/* + * 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 "AddNotificationSlots_fuzzer.h" + +#include "notification_helper.h" + +constexpr uint8_t ENABLE = 2; +constexpr uint8_t SLOT_LEVEL_NUM = 6; +constexpr uint8_t SLOT_VISIBLENESS_TYPE_NUM = 4; +constexpr uint8_t SLOT_TYPE_NUM = 5; + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + std::string stringData = reinterpret_cast(data); + + Notification::NotificationSlot slot; + slot.SetDescription(stringData); + slot.SetEnableLight(*data % ENABLE); + slot.SetEnableVibration(*data % ENABLE); + slot.SetLedLightColor(U32_AT(data)); + + uint8_t level = *data % SLOT_LEVEL_NUM; + Notification::NotificationSlot::NotificationLevel notificatoinLevel = + Notification::NotificationSlot::NotificationLevel(level); + slot.SetLevel(notificatoinLevel); + + uint8_t visibleness = *data % SLOT_VISIBLENESS_TYPE_NUM; + Notification::NotificationConstant::VisiblenessType visiblenessType = + Notification::NotificationConstant::VisiblenessType(visibleness); + slot.SetLockscreenVisibleness(visiblenessType); + + slot.SetSlotGroup(stringData); + + uint8_t type = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + slot.SetType(slotType); + + std::vector slots; + slots.emplace_back(slot); + return Notification::NotificationHelper::AddNotificationSlots(slots) == ERR_OK; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} diff --git a/test/fuzztest/AddNotificationSlots_fuzzer/AddNotificationSlots_fuzzer.h b/test/fuzztest/AddNotificationSlots_fuzzer/AddNotificationSlots_fuzzer.h new file mode 100644 index 000000000..55df6b636 --- /dev/null +++ b/test/fuzztest/AddNotificationSlots_fuzzer/AddNotificationSlots_fuzzer.h @@ -0,0 +1,29 @@ +/* + * 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 TEST_FUZZTEST_ADDNOTIFICATIONSLOTS_FUZZER_ADDNOTIFICATIONSLOTS_FUZZER_H +#define TEST_FUZZTEST_ADDNOTIFICATIONSLOTS_FUZZER_ADDNOTIFICATIONSLOTS_FUZZER_H + +#define FUZZ_PROJECT_NAME "AddNotificationSlots_fuzzer" + +#include + +uint32_t U32_AT(const uint8_t *ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; +} + +#endif // TEST_FUZZTEST_ADDNOTIFICATIONSLOTS_FUZZER_ADDNOTIFICATIONSLOTS_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/AddNotificationSlots_fuzzer/BUILD.gn b/test/fuzztest/AddNotificationSlots_fuzzer/BUILD.gn new file mode 100644 index 000000000..b9e78c26e --- /dev/null +++ b/test/fuzztest/AddNotificationSlots_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AddNotificationSlotsFuzzTest") { + module_out_path = module_output_path + + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "AddNotificationSlots_fuzzer.cpp" ] + + deps = [ + "${frameworks_path}/ans/native:ans_innerkits", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AddNotificationSlotsFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/AddNotificationSlots_fuzzer/project.xml b/test/fuzztest/AddNotificationSlots_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/AddNotificationSlots_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/AddSlotByType_fuzzer/AddSlotByType_fuzzer.cpp b/test/fuzztest/AddSlotByType_fuzzer/AddSlotByType_fuzzer.cpp new file mode 100644 index 000000000..e9ca48cb8 --- /dev/null +++ b/test/fuzztest/AddSlotByType_fuzzer/AddSlotByType_fuzzer.cpp @@ -0,0 +1,37 @@ +/* + * 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 "AddSlotByType_fuzzer.h" + +#include "notification_helper.h" + +constexpr uint8_t SLOT_TYPE_NUM = 5; + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + uint8_t type = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + return Notification::NotificationHelper::AddSlotByType(slotType) == ERR_OK; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} diff --git a/test/fuzztest/AddSlotByType_fuzzer/AddSlotByType_fuzzer.h b/test/fuzztest/AddSlotByType_fuzzer/AddSlotByType_fuzzer.h new file mode 100644 index 000000000..a53388f42 --- /dev/null +++ b/test/fuzztest/AddSlotByType_fuzzer/AddSlotByType_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_ADDSLOTBYTYPE_FUZZER_ADDSLOTBYTYPE_FUZZER_H +#define TEST_FUZZTEST_ADDSLOTBYTYPE_FUZZER_ADDSLOTBYTYPE_FUZZER_H + +#define FUZZ_PROJECT_NAME "AddSlotByType_fuzzer" + +#endif // TEST_FUZZTEST_ADDSLOTBYTYPE_FUZZER_ADDSLOTBYTYPE_FUZZER_H diff --git a/test/fuzztest/AddSlotByType_fuzzer/BUILD.gn b/test/fuzztest/AddSlotByType_fuzzer/BUILD.gn new file mode 100644 index 000000000..186b8d10e --- /dev/null +++ b/test/fuzztest/AddSlotByType_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AddSlotByTypeFuzzTest") { + module_out_path = module_output_path + + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "AddSlotByType_fuzzer.cpp" ] + + deps = [ + "${frameworks_path}/ans/native:ans_innerkits", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AddSlotByTypeFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/AddSlotByType_fuzzer/project.xml b/test/fuzztest/AddSlotByType_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/AddSlotByType_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn new file mode 100644 index 000000000..37ba8bb3e --- /dev/null +++ b/test/fuzztest/BUILD.gn @@ -0,0 +1,31 @@ +# 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. + +import("//base/notification/ans_standard/notification.gni") + +group("fuzztest") { + testonly = true + + deps = [ + # "AddNotificationSlotGroups_fuzzer:AddNotificationSlotGroupsFuzzTest", + # "AddNotificationSlots_fuzzer:AddNotificationSlotsFuzzTest", + # "AddSlotByType_fuzzer:AddSlotByTypeFuzzTest", + # "GetNotificationSlotGroup_fuzzer:GetNotificationSlotGroupFuzzTest", + # "GetNotificationSlotNumAsBundle_fuzzer:GetNotificationSlotNumAsBundleFuzzTest", + # "GetNotificationSlot_fuzzer:GetNotificationSlotFuzzTest", + # "RemoveNotificationSlotGroup_fuzzer:RemoveNotificationSlotGroupFuzzTest", + # "RemoveNotificationSlot_fuzzer:RemoveNotificationSlotFuzzTest", + # "RemoveNotification_fuzzer:RemoveNotificationFuzzTest", + # "SetNotificationBadgeNum_fuzzer:SetNotificationBadgeNumFuzzTest", + ] +} diff --git a/test/fuzztest/GetNotificationSlotGroup_fuzzer/BUILD.gn b/test/fuzztest/GetNotificationSlotGroup_fuzzer/BUILD.gn new file mode 100644 index 000000000..3bb6710e6 --- /dev/null +++ b/test/fuzztest/GetNotificationSlotGroup_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("GetNotificationSlotGroupFuzzTest") { + module_out_path = module_output_path + + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "GetNotificationSlotGroup_fuzzer.cpp" ] + + deps = [ + "${frameworks_path}/ans/native:ans_innerkits", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetNotificationSlotGroupFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/GetNotificationSlotGroup_fuzzer/GetNotificationSlotGroup_fuzzer.cpp b/test/fuzztest/GetNotificationSlotGroup_fuzzer/GetNotificationSlotGroup_fuzzer.cpp new file mode 100644 index 000000000..2804222a6 --- /dev/null +++ b/test/fuzztest/GetNotificationSlotGroup_fuzzer/GetNotificationSlotGroup_fuzzer.cpp @@ -0,0 +1,35 @@ +/* + * 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 "GetNotificationSlotGroup_fuzzer.h" + +#include "notification_helper.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + std::string groupId = reinterpret_cast(data); + sptr group = nullptr; + return Notification::NotificationHelper::GetNotificationSlotGroup(groupId, group) == ERR_OK; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} diff --git a/test/fuzztest/GetNotificationSlotGroup_fuzzer/GetNotificationSlotGroup_fuzzer.h b/test/fuzztest/GetNotificationSlotGroup_fuzzer/GetNotificationSlotGroup_fuzzer.h new file mode 100644 index 000000000..91a074394 --- /dev/null +++ b/test/fuzztest/GetNotificationSlotGroup_fuzzer/GetNotificationSlotGroup_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_GETNOTIFICATIONSLOTGROUP_FUZZER_GETNOTIFICATIONSLOTGROUP_FUZZER_H +#define TEST_FUZZTEST_GETNOTIFICATIONSLOTGROUP_FUZZER_GETNOTIFICATIONSLOTGROUP_FUZZER_H + +#define FUZZ_PROJECT_NAME "GetNotificationSlotGroups_fuzzer" + +#endif // TEST_FUZZTEST_GETNOTIFICATIONSLOTGROUP_FUZZER_GETNOTIFICATIONSLOTGROUP_FUZZER_H diff --git a/test/fuzztest/GetNotificationSlotGroup_fuzzer/project.xml b/test/fuzztest/GetNotificationSlotGroup_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/GetNotificationSlotGroup_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/BUILD.gn b/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/BUILD.gn new file mode 100644 index 000000000..2cb3b10bf --- /dev/null +++ b/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("GetNotificationSlotNumAsBundleFuzzTest") { + module_out_path = module_output_path + + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "GetNotificationSlotNumAsBundle_fuzzer.cpp" ] + + deps = [ + "${frameworks_path}/ans/native:ans_innerkits", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetNotificationSlotNumAsBundleFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/GetNotificationSlotNumAsBundle_fuzzer.cpp b/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/GetNotificationSlotNumAsBundle_fuzzer.cpp new file mode 100644 index 000000000..70fa9cdce --- /dev/null +++ b/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/GetNotificationSlotNumAsBundle_fuzzer.cpp @@ -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. + */ + +#include "GetNotificationSlotNumAsBundle_fuzzer.h" + +#include "notification_helper.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + Notification::NotificationBundleOption bundleOption; + std::string bundleName = reinterpret_cast(data); + bundleOption.SetBundleName(bundleName); + int32_t uid = static_cast(U32_AT(data)); + bundleOption.SetUid(uid); + int num; + return Notification::NotificationHelper::GetNotificationSlotNumAsBundle(bundleOption, num) == ERR_OK; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} diff --git a/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/GetNotificationSlotNumAsBundle_fuzzer.h b/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/GetNotificationSlotNumAsBundle_fuzzer.h new file mode 100644 index 000000000..3317b2585 --- /dev/null +++ b/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/GetNotificationSlotNumAsBundle_fuzzer.h @@ -0,0 +1,29 @@ +/* + * 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 TEST_FUZZTEST_GETNOTIFICATIONSLOTNUMASBUNDLE_FUZZER_GETNOTIFICATIONSLOTNUMASBUNDLE_FUZZER_H +#define TEST_FUZZTEST_GETNOTIFICATIONSLOTNUMASBUNDLE_FUZZER_GETNOTIFICATIONSLOTNUMASBUNDLE_FUZZER_H + +#include + +#define FUZZ_PROJECT_NAME "GetNotificationSlotNumAsBundle_fuzzer" + +uint32_t U32_AT(const uint8_t *ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; +} + +#endif // TEST_FUZZTEST_GETNOTIFICATIONSLOTNUMASBUNDLE_FUZZER_GETNOTIFICATIONSLOTNUMASBUNDLE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/project.xml b/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/GetNotificationSlotNumAsBundle_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/GetNotificationSlot_fuzzer/BUILD.gn b/test/fuzztest/GetNotificationSlot_fuzzer/BUILD.gn new file mode 100644 index 000000000..6f7f794cd --- /dev/null +++ b/test/fuzztest/GetNotificationSlot_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("GetNotificationSlotFuzzTest") { + module_out_path = module_output_path + + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "GetNotificationSlot_fuzzer.cpp" ] + + deps = [ + "${frameworks_path}/ans/native:ans_innerkits", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetNotificationSlotFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/GetNotificationSlot_fuzzer/GetNotificationSlot_fuzzer.cpp b/test/fuzztest/GetNotificationSlot_fuzzer/GetNotificationSlot_fuzzer.cpp new file mode 100644 index 000000000..e62a8ec0a --- /dev/null +++ b/test/fuzztest/GetNotificationSlot_fuzzer/GetNotificationSlot_fuzzer.cpp @@ -0,0 +1,38 @@ +/* + * 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 "GetNotificationSlot_fuzzer.h" + +#include "notification_helper.h" + +constexpr uint8_t SLOT_TYPE_NUM = 5; + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + uint8_t type = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + sptr slot = nullptr; + return Notification::NotificationHelper::GetNotificationSlot(slotType, slot) == ERR_OK; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} diff --git a/test/fuzztest/GetNotificationSlot_fuzzer/GetNotificationSlot_fuzzer.h b/test/fuzztest/GetNotificationSlot_fuzzer/GetNotificationSlot_fuzzer.h new file mode 100644 index 000000000..71c46a015 --- /dev/null +++ b/test/fuzztest/GetNotificationSlot_fuzzer/GetNotificationSlot_fuzzer.h @@ -0,0 +1,29 @@ +/* + * 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 TEST_FUZZTEST_GETNOTIFICATIONSLOT_FUZZER_GETNOTIFICATIONSLOT_FUZZER_H +#define TEST_FUZZTEST_GETNOTIFICATIONSLOT_FUZZER_GETNOTIFICATIONSLOT_FUZZER_H + +#define FUZZ_PROJECT_NAME "GetNotificationSlot_fuzzer" + +#include + +uint32_t U32_AT(const uint8_t *ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; +} + +#endif // TEST_FUZZTEST_GETNOTIFICATIONSLOT_FUZZER_GETNOTIFICATIONSLOT_FUZZER_H diff --git a/test/fuzztest/GetNotificationSlot_fuzzer/project.xml b/test/fuzztest/GetNotificationSlot_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/GetNotificationSlot_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/BUILD.gn b/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/BUILD.gn new file mode 100644 index 000000000..95c35128b --- /dev/null +++ b/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("RemoveNotificationSlotGroupFuzzTest") { + module_out_path = module_output_path + + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "RemoveNotificationSlotGroup_fuzzer.cpp" ] + + deps = [ + "${frameworks_path}/ans/native:ans_innerkits", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":RemoveNotificationSlotGroupFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/RemoveNotificationSlotGroup_fuzzer.cpp b/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/RemoveNotificationSlotGroup_fuzzer.cpp new file mode 100644 index 000000000..608402a59 --- /dev/null +++ b/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/RemoveNotificationSlotGroup_fuzzer.cpp @@ -0,0 +1,34 @@ +/* + * 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 "RemoveNotificationSlotGroup_fuzzer.h" + +#include "notification_helper.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + std::string slotGroupId = reinterpret_cast(data); + return Notification::NotificationHelper::RemoveNotificationSlotGroup(slotGroupId) == ERR_OK; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} diff --git a/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/RemoveNotificationSlotGroup_fuzzer.h b/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/RemoveNotificationSlotGroup_fuzzer.h new file mode 100644 index 000000000..b57500e4b --- /dev/null +++ b/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/RemoveNotificationSlotGroup_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMOVENOTIFICATIONSLOTGROUP_FUZZER_REMOVENOTIFICATIONSLOTGROUP_FUZZER_H +#define TEST_FUZZTEST_REMOVENOTIFICATIONSLOTGROUP_FUZZER_REMOVENOTIFICATIONSLOTGROUP_FUZZER_H + +#define FUZZ_PROJECT_NAME "RemoveNotificationSlotGroup_fuzzer" + +#endif // TEST_FUZZTEST_REMOVENOTIFICATIONSLOTGROUP_FUZZER_REMOVENOTIFICATIONSLOTGROUP_FUZZER_H diff --git a/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/project.xml b/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/RemoveNotificationSlotGroup_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/RemoveNotificationSlot_fuzzer/BUILD.gn b/test/fuzztest/RemoveNotificationSlot_fuzzer/BUILD.gn new file mode 100644 index 000000000..dac731352 --- /dev/null +++ b/test/fuzztest/RemoveNotificationSlot_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("RemoveNotificationSlotFuzzTest") { + module_out_path = module_output_path + + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "RemoveNotificationSlot_fuzzer.cpp" ] + + deps = [ + "${frameworks_path}/ans/native:ans_innerkits", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":RemoveNotificationSlotFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/RemoveNotificationSlot_fuzzer/RemoveNotificationSlot_fuzzer.cpp b/test/fuzztest/RemoveNotificationSlot_fuzzer/RemoveNotificationSlot_fuzzer.cpp new file mode 100644 index 000000000..be3ee661c --- /dev/null +++ b/test/fuzztest/RemoveNotificationSlot_fuzzer/RemoveNotificationSlot_fuzzer.cpp @@ -0,0 +1,37 @@ +/* + * 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 "RemoveNotificationSlot_fuzzer.h" + +#include "notification_helper.h" + +constexpr uint8_t SLOT_TYPE_NUM = 5; + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + uint8_t type = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + return Notification::NotificationHelper::RemoveNotificationSlot(slotType) == ERR_OK; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} diff --git a/test/fuzztest/RemoveNotificationSlot_fuzzer/RemoveNotificationSlot_fuzzer.h b/test/fuzztest/RemoveNotificationSlot_fuzzer/RemoveNotificationSlot_fuzzer.h new file mode 100644 index 000000000..f05d05edb --- /dev/null +++ b/test/fuzztest/RemoveNotificationSlot_fuzzer/RemoveNotificationSlot_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMOVENOTIFICATIONSLOT_FUZZER_REMOVENOTIFICATIONSLOT_FUZZER_H +#define TEST_FUZZTEST_REMOVENOTIFICATIONSLOT_FUZZER_REMOVENOTIFICATIONSLOT_FUZZER_H + +#define FUZZ_PROJECT_NAME "RemoveNotificationSlot_fuzzer" + +#endif // TEST_FUZZTEST_REMOVENOTIFICATIONSLOT_FUZZER_REMOVENOTIFICATIONSLOT_FUZZER_H diff --git a/test/fuzztest/RemoveNotificationSlot_fuzzer/project.xml b/test/fuzztest/RemoveNotificationSlot_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/RemoveNotificationSlot_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/RemoveNotification_fuzzer/BUILD.gn b/test/fuzztest/RemoveNotification_fuzzer/BUILD.gn new file mode 100644 index 000000000..45cd392de --- /dev/null +++ b/test/fuzztest/RemoveNotification_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("RemoveNotificationFuzzTest") { + module_out_path = module_output_path + + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "RemoveNotification_fuzzer.cpp" ] + + deps = [ + "${frameworks_path}/ans/native:ans_innerkits", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":RemoveNotificationFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/RemoveNotification_fuzzer/RemoveNotification_fuzzer.cpp b/test/fuzztest/RemoveNotification_fuzzer/RemoveNotification_fuzzer.cpp new file mode 100644 index 000000000..8272b8d13 --- /dev/null +++ b/test/fuzztest/RemoveNotification_fuzzer/RemoveNotification_fuzzer.cpp @@ -0,0 +1,35 @@ +/* + * 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 "RemoveNotification_fuzzer.h" + +#include "notification_helper.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + std::string key = reinterpret_cast(data); + return Notification::NotificationHelper::RemoveNotification(key); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} + diff --git a/test/fuzztest/RemoveNotification_fuzzer/RemoveNotification_fuzzer.h b/test/fuzztest/RemoveNotification_fuzzer/RemoveNotification_fuzzer.h new file mode 100644 index 000000000..b0cc33a01 --- /dev/null +++ b/test/fuzztest/RemoveNotification_fuzzer/RemoveNotification_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMOVENOTIFICATION_FUZZER_REMOVENOTIFICATION_FUZZER_H +#define TEST_FUZZTEST_REMOVENOTIFICATION_FUZZER_REMOVENOTIFICATION_FUZZER_H + +#define FUZZ_PROJECT_NAME "RemoveNotification_fuzzer" + +#endif // TEST_FUZZTEST_REMOVENOTIFICATION_FUZZER_REMOVENOTIFICATION_FUZZER_H diff --git a/test/fuzztest/RemoveNotification_fuzzer/project.xml b/test/fuzztest/RemoveNotification_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/RemoveNotification_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/SetNotificationBadgeNum_fuzzer/BUILD.gn b/test/fuzztest/SetNotificationBadgeNum_fuzzer/BUILD.gn new file mode 100644 index 000000000..1fef111b8 --- /dev/null +++ b/test/fuzztest/SetNotificationBadgeNum_fuzzer/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("SetNotificationBadgeNumFuzzTest") { + module_out_path = module_output_path + + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "SetNotificationBadgeNum_fuzzer.cpp" ] + + deps = [ + "${frameworks_path}/ans/native:ans_innerkits", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetNotificationBadgeNumFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/SetNotificationBadgeNum_fuzzer/SetNotificationBadgeNum_fuzzer.cpp b/test/fuzztest/SetNotificationBadgeNum_fuzzer/SetNotificationBadgeNum_fuzzer.cpp new file mode 100644 index 000000000..c24866a3c --- /dev/null +++ b/test/fuzztest/SetNotificationBadgeNum_fuzzer/SetNotificationBadgeNum_fuzzer.cpp @@ -0,0 +1,33 @@ +/* + * 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 "SetNotificationBadgeNum_fuzzer.h" + +#include "notification_helper.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + return Notification::NotificationHelper::SetNotificationBadgeNum(U32_AT(data)) == ERR_OK; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} diff --git a/test/fuzztest/SetNotificationBadgeNum_fuzzer/SetNotificationBadgeNum_fuzzer.h b/test/fuzztest/SetNotificationBadgeNum_fuzzer/SetNotificationBadgeNum_fuzzer.h new file mode 100644 index 000000000..6dc1482bd --- /dev/null +++ b/test/fuzztest/SetNotificationBadgeNum_fuzzer/SetNotificationBadgeNum_fuzzer.h @@ -0,0 +1,29 @@ +/* + * 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 TEST_FUZZTEST_SETNOTIFICATIONBADGENUM_FUZZER_SETNOTIFICATIONBADGENUM_FUZZER_H +#define TEST_FUZZTEST_SETNOTIFICATIONBADGENUM_FUZZER_SETNOTIFICATIONBADGENUM_FUZZER_H + +#include + +#define FUZZ_PROJECT_NAME "SetNotificationBadgeNum_fuzzer" + +uint32_t U32_AT(const uint8_t *ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; +} + +#endif // TEST_FUZZTEST_SETNOTIFICATIONBADGENUM_FUZZER_SETNOTIFICATIONBADGENUM_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/SetNotificationBadgeNum_fuzzer/project.xml b/test/fuzztest/SetNotificationBadgeNum_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/SetNotificationBadgeNum_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee