diff --git a/bundle.json b/bundle.json index f4d1b6a3d72cde88503a680a4810bba5685f6c86..ebbd5d0989ec6a50fa5d061c07a1b39d7bb11646 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 0000000000000000000000000000000000000000..c8a99e067452522d97f362fd87fcf6f648ee06d1 --- /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 0000000000000000000000000000000000000000..9d8fa6a841ad38432a79a9a7987758ea94f49e85 --- /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 0000000000000000000000000000000000000000..ef81c876045c64d1e6990656014d09bce46a9411 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..314f9b6e2e9bd6564e1f5edfe35d03a15885e361 --- /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 0000000000000000000000000000000000000000..55df6b6361d0ed893f2dca3958206955fe130098 --- /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 0000000000000000000000000000000000000000..b9e78c26ee0d7b79ddfc10c791321f76a5bf352c --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..e9ca48cb84985b224732e6d9fb67b7c411e3d06b --- /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 0000000000000000000000000000000000000000..a53388f4245e771bfe9f46455d624a52133ce736 --- /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 0000000000000000000000000000000000000000..186b8d10e2bbea63de0baf311151d2fc75f10d3c --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..37ba8bb3eaf8f2983f1ae1fa34e118309d606bee --- /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 0000000000000000000000000000000000000000..3bb6710e6b2331977706f8a679e33b2ac5d4d39b --- /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 0000000000000000000000000000000000000000..2804222a60ce1627ba3c2ecccc0db6266047bb31 --- /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 0000000000000000000000000000000000000000..91a0743946c284aacf5184900365ea65c1f31a92 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..2cb3b10bf7455dccfa7a2dcc2edf01f28f84154d --- /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 0000000000000000000000000000000000000000..70fa9cdce626434928a8ce09be28b7915a47d93e --- /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 0000000000000000000000000000000000000000..3317b2585179bb1b807003dc685ad79d6c709519 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..6f7f794cdf702dc7b25bd5735e6d67677f6c8944 --- /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 0000000000000000000000000000000000000000..e62a8ec0a26d1065050747a5d406567bd69279ac --- /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 0000000000000000000000000000000000000000..71c46a015a6c94ab51e10d354aeb4e4f1b770605 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..95c35128b2650bc7d1698d0f00eba2261c2e816b --- /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 0000000000000000000000000000000000000000..608402a599726049957c3167aa42dcd392c7c0b9 --- /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 0000000000000000000000000000000000000000..b57500e4b975eadd6eb8522e0551f9e8ba108f80 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..dac731352d4bb13af330d20670dcde1144ad4320 --- /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 0000000000000000000000000000000000000000..be3ee661c6a5d55726e907ba0585595f843e8d9f --- /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 0000000000000000000000000000000000000000..f05d05edb770c7780d7b52271c97d5289799548f --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..45cd392de5bdf39461787c269ce25ee8563e51f7 --- /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 0000000000000000000000000000000000000000..8272b8d13ea77563e7ef46090bf9708678b80ab6 --- /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 0000000000000000000000000000000000000000..b0cc33a01321092bb66718d70bf87d3c9e22631c --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..1fef111b8d855fa695e749f9ec34b66c502346d7 --- /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 0000000000000000000000000000000000000000..c24866a3c08aeae72e3b1a7a1d4b800075753358 --- /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 0000000000000000000000000000000000000000..6dc1482bd1555758c2ddb0ef461f5e59a4640a0c --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/SetNotificationBadgeNum_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +