From faa17baece44904fe89a4f4502dee80418c67ca8 Mon Sep 17 00:00:00 2001 From: yanghang Date: Mon, 15 Jul 2024 22:09:10 +0800 Subject: [PATCH] fix: add fuzz cases Signed-off-by: yanghang --- state_manager/test/fuzztest/BUILD.gn | 2 + .../BUILD.gn | 86 +++++++++++++++++++ .../corpus/init | 14 +++ .../project.xml | 25 ++++++ ...etlightbrightnessthreshold_fuzzer_test.cpp | 38 ++++++++ .../fuzztest/setmaxbrightness_fuzzer/BUILD.gn | 86 +++++++++++++++++++ .../setmaxbrightness_fuzzer/corpus/init | 14 +++ .../setmaxbrightness_fuzzer/project.xml | 25 ++++++ .../setmaxbrightness_fuzzer_test.cpp | 36 ++++++++ 9 files changed, 326 insertions(+) create mode 100644 state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/BUILD.gn create mode 100644 state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/corpus/init create mode 100644 state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/project.xml create mode 100644 state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/setlightbrightnessthreshold_fuzzer_test.cpp create mode 100644 state_manager/test/fuzztest/setmaxbrightness_fuzzer/BUILD.gn create mode 100644 state_manager/test/fuzztest/setmaxbrightness_fuzzer/corpus/init create mode 100644 state_manager/test/fuzztest/setmaxbrightness_fuzzer/project.xml create mode 100644 state_manager/test/fuzztest/setmaxbrightness_fuzzer/setmaxbrightness_fuzzer_test.cpp diff --git a/state_manager/test/fuzztest/BUILD.gn b/state_manager/test/fuzztest/BUILD.gn index 8b9a74c..836c737 100644 --- a/state_manager/test/fuzztest/BUILD.gn +++ b/state_manager/test/fuzztest/BUILD.gn @@ -32,5 +32,7 @@ group("fuzztest") { "registercallback_fuzzer:RegisterCallbackFuzzTest", "setbrightness_fuzzer:SetBrightnessFuzzTest", "setcoordinated_fuzzer:SetCoordinatedFuzzTest", + "setlightbrightnessthreshold_fuzzer:SetLightBrightnessThresholdFuzzTest", + "setmaxbrightness_fuzzer:SetMaxBrightnessFuzzTest", ] } diff --git a/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/BUILD.gn b/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/BUILD.gn new file mode 100644 index 0000000..b505296 --- /dev/null +++ b/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/BUILD.gn @@ -0,0 +1,86 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("../../../../displaymgr.gni") + +module_output_path = "display_manager/display_state_manager" + +##############################fuzztest########################################## +ohos_fuzztest("SetLightBrightnessThresholdFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${displaymgr_root_path}/test/fuzztest/setlightbrightnessthreshold_fuzzer" + + include_dirs = [ + "./", + "${displaymgr_root_path}/service/native/include", + "${displaymgr_root_path}/service/zidl/include", + "${displaymgr_inner_api}/native/include", + "../display_utils", + ] + + configs = [ + "${displaymgr_utils_path}:utils_config", + "${displaymgr_utils_path}:coverage_flags", + "${brightnessmgr_root_path}:brightness_manager_config", + ] + + deps = [ "${brightnessmgr_root_path}:brightness_manager" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${displaymgr_root_path}/service/native/src/display_auto_brightness.cpp", + "${displaymgr_root_path}/service/native/src/display_param_helper.cpp", + "${displaymgr_root_path}/service/native/src/display_power_mgr_service.cpp", + "${displaymgr_root_path}/service/native/src/display_setting_helper.cpp", + "${displaymgr_root_path}/service/native/src/display_system_ability.cpp", + "${displaymgr_root_path}/service/native/src/gradual_animator.cpp", + "${displaymgr_root_path}/service/native/src/screen_action.cpp", + "${displaymgr_root_path}/service/native/src/screen_controller.cpp", + "${displaymgr_root_path}/service/zidl/src/display_power_callback_proxy.cpp", + "${displaymgr_root_path}/service/zidl/src/display_power_mgr_stub.cpp", + "../display_utils/display_fuzzer.cpp", + "./setlightbrightnessthreshold_fuzzer_test.cpp", + ] + + external_deps = [ "power_manager:power_permission" ] + external_deps += [ + "ability_runtime:ability_manager", + "c_utils:utils", + "data_share:datashare_consumer", + "display_manager:displaymgr", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "image_framework:image_native", + "ipc:ipc_core", + "power_manager:power_ffrt", + "power_manager:power_setting", + "power_manager:power_sysparam", + "power_manager:powermgr_client", + "safwk:system_ability_fwk", + "window_manager:libdm", + ] + + if (has_sensors_sensor_part) { + external_deps += [ "sensor:sensor_interface_native" ] + } +} diff --git a/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/corpus/init b/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/corpus/init new file mode 100644 index 0000000..e7c3fec --- /dev/null +++ b/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/project.xml b/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/project.xml new file mode 100644 index 0000000..1244d8d --- /dev/null +++ b/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 180 + + 4096 + + diff --git a/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/setlightbrightnessthreshold_fuzzer_test.cpp b/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/setlightbrightnessthreshold_fuzzer_test.cpp new file mode 100644 index 0000000..2e87c7c --- /dev/null +++ b/state_manager/test/fuzztest/setlightbrightnessthreshold_fuzzer/setlightbrightnessthreshold_fuzzer_test.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* This files contains faultlog fuzzer test modules. */ + +#define FUZZ_PROJECT_NAME "setlightbrightnessthreshold_fuzzer" + +#include "display_fuzzer.h" +#include "display_power_mgr_ipc_interface_code.h" + +using namespace OHOS::PowerMgr; + +namespace { +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + DisplayFuzzerTest g_serviceTest; + g_serviceTest.TestDisplayServiceStub( + static_cast(DisplayPowerMgrInterfaceCode::SET_MAX_BRIGHTNESS), data, size); + g_serviceTest.TestDisplayServiceStub( + static_cast(DisplayPowerMgrInterfaceCode::SET_MAX_BRIGHTNESS_NIT), data, size); + return 0; +} diff --git a/state_manager/test/fuzztest/setmaxbrightness_fuzzer/BUILD.gn b/state_manager/test/fuzztest/setmaxbrightness_fuzzer/BUILD.gn new file mode 100644 index 0000000..37a0134 --- /dev/null +++ b/state_manager/test/fuzztest/setmaxbrightness_fuzzer/BUILD.gn @@ -0,0 +1,86 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("../../../../displaymgr.gni") + +module_output_path = "display_manager/display_state_manager" + +##############################fuzztest########################################## +ohos_fuzztest("SetMaxBrightnessFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${displaymgr_root_path}/test/fuzztest/setmaxbrightness_fuzzer" + + include_dirs = [ + "./", + "${displaymgr_root_path}/service/native/include", + "${displaymgr_root_path}/service/zidl/include", + "${displaymgr_inner_api}/native/include", + "../display_utils", + ] + + configs = [ + "${displaymgr_utils_path}:utils_config", + "${displaymgr_utils_path}:coverage_flags", + "${brightnessmgr_root_path}:brightness_manager_config", + ] + + deps = [ "${brightnessmgr_root_path}:brightness_manager" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${displaymgr_root_path}/service/native/src/display_auto_brightness.cpp", + "${displaymgr_root_path}/service/native/src/display_param_helper.cpp", + "${displaymgr_root_path}/service/native/src/display_power_mgr_service.cpp", + "${displaymgr_root_path}/service/native/src/display_setting_helper.cpp", + "${displaymgr_root_path}/service/native/src/display_system_ability.cpp", + "${displaymgr_root_path}/service/native/src/gradual_animator.cpp", + "${displaymgr_root_path}/service/native/src/screen_action.cpp", + "${displaymgr_root_path}/service/native/src/screen_controller.cpp", + "${displaymgr_root_path}/service/zidl/src/display_power_callback_proxy.cpp", + "${displaymgr_root_path}/service/zidl/src/display_power_mgr_stub.cpp", + "../display_utils/display_fuzzer.cpp", + "./setmaxbrightness_fuzzer_test.cpp", + ] + + external_deps = [ "power_manager:power_permission" ] + external_deps += [ + "ability_runtime:ability_manager", + "c_utils:utils", + "data_share:datashare_consumer", + "display_manager:displaymgr", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "image_framework:image_native", + "ipc:ipc_core", + "power_manager:power_ffrt", + "power_manager:power_setting", + "power_manager:power_sysparam", + "power_manager:powermgr_client", + "safwk:system_ability_fwk", + "window_manager:libdm", + ] + + if (has_sensors_sensor_part) { + external_deps += [ "sensor:sensor_interface_native" ] + } +} diff --git a/state_manager/test/fuzztest/setmaxbrightness_fuzzer/corpus/init b/state_manager/test/fuzztest/setmaxbrightness_fuzzer/corpus/init new file mode 100644 index 0000000..e7c3fec --- /dev/null +++ b/state_manager/test/fuzztest/setmaxbrightness_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/state_manager/test/fuzztest/setmaxbrightness_fuzzer/project.xml b/state_manager/test/fuzztest/setmaxbrightness_fuzzer/project.xml new file mode 100644 index 0000000..1244d8d --- /dev/null +++ b/state_manager/test/fuzztest/setmaxbrightness_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 180 + + 4096 + + diff --git a/state_manager/test/fuzztest/setmaxbrightness_fuzzer/setmaxbrightness_fuzzer_test.cpp b/state_manager/test/fuzztest/setmaxbrightness_fuzzer/setmaxbrightness_fuzzer_test.cpp new file mode 100644 index 0000000..71c70c4 --- /dev/null +++ b/state_manager/test/fuzztest/setmaxbrightness_fuzzer/setmaxbrightness_fuzzer_test.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* This files contains faultlog fuzzer test modules. */ + +#define FUZZ_PROJECT_NAME "setmaxbrightness_fuzzer" + +#include "display_fuzzer.h" +#include "display_power_mgr_ipc_interface_code.h" + +using namespace OHOS::PowerMgr; + +namespace { +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + DisplayFuzzerTest g_serviceTest; + g_serviceTest.TestDisplayServiceStub( + static_cast(DisplayPowerMgrInterfaceCode::SET_APS_LIGHT_AND_BRIGHTNESS_THRESOLD), data, size); + return 0; +} -- Gitee