mirror of
https://gitee.com/openharmony/powermgr_battery_manager
synced 2024-12-29 01:54:55 +00:00
fix: add fuzz test
Signed-off-by: chenjunwu <chenjunwu4@huawei.com>
This commit is contained in:
parent
0e2f884af0
commit
72393aee33
@ -20,6 +20,7 @@ group("fuzztest") {
|
||||
|
||||
deps += [
|
||||
# deps file
|
||||
"getbatteryconfig_fuzzer:GetBatteryConfigFuzzTest",
|
||||
"getbatterytemperature_fuzzer:GetBatteryTemperatureFuzzTest",
|
||||
"getcapacity_fuzzer:GetCapacityFuzzTest",
|
||||
"getcapacitylevel_fuzzer:GetCapacityLevelFuzzTest",
|
||||
@ -34,5 +35,7 @@ group("fuzztest") {
|
||||
"gettechnology_fuzzer:GetTechnologyFuzzTest",
|
||||
"gettotalenergy_fuzzer:GetTotalEnergyFuzzTest",
|
||||
"getvoltage_fuzzer:GetVoltageFuzzTest",
|
||||
"isbatteryconfigsupported_fuzzer:IsBatteryConfigSupportedFuzzTest",
|
||||
"setbatteryconfig_fuzzer:SetBatteryConfigFuzzTest",
|
||||
]
|
||||
}
|
||||
|
58
test/fuzztest/getbatteryconfig_fuzzer/BUILD.gn
Normal file
58
test/fuzztest/getbatteryconfig_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,58 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("../../../batterymgr.gni")
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("GetBatteryConfigFuzzTest") {
|
||||
module_out_path = "${module_output_path}"
|
||||
fuzz_config_file =
|
||||
"${battery_manager_path}/test/fuzztest/getbatteryconfig_fuzzer"
|
||||
|
||||
include_dirs = [ "../battery_utils/" ]
|
||||
|
||||
configs = [
|
||||
"${battery_utils}:coverage_flags",
|
||||
"${battery_utils}:utils_config",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [
|
||||
"../battery_utils/battery_fuzzer_test.cpp",
|
||||
"./getbatteryconfig_fuzzer_test.cpp",
|
||||
]
|
||||
deps = [
|
||||
"${battery_service_zidl}:batterysrv_stub",
|
||||
"${battery_service}:batteryservice",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"drivers_interface_battery:libbattery_proxy_2.0",
|
||||
"hdf_core:libhdi",
|
||||
"hdf_core:libpub_utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
}
|
13
test/fuzztest/getbatteryconfig_fuzzer/corpus/init
Normal file
13
test/fuzztest/getbatteryconfig_fuzzer/corpus/init
Normal file
@ -0,0 +1,13 @@
|
||||
# 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
|
@ -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 "getbatteryconfig_fuzzer"
|
||||
|
||||
#include "battery_fuzzer_test.h"
|
||||
#include "battery_manager_ipc_interface_code.h"
|
||||
|
||||
using namespace OHOS::PowerMgr;
|
||||
|
||||
namespace {
|
||||
BatteryFuzzerTest g_serviceTest;
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
g_serviceTest.TestBatteryServiceStub(
|
||||
static_cast<uint32_t>(BatterySrvInterfaceCode::GET_BATTERY_CONFIG), data, size);
|
||||
return 0;
|
||||
}
|
25
test/fuzztest/getbatteryconfig_fuzzer/project.xml
Normal file
25
test/fuzztest/getbatteryconfig_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>180</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
58
test/fuzztest/isbatteryconfigsupported_fuzzer/BUILD.gn
Normal file
58
test/fuzztest/isbatteryconfigsupported_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,58 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("../../../batterymgr.gni")
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("IsBatteryConfigSupportedFuzzTest") {
|
||||
module_out_path = "${module_output_path}"
|
||||
fuzz_config_file =
|
||||
"${battery_manager_path}/test/fuzztest/isbatteryconfigsupported_fuzzer"
|
||||
|
||||
include_dirs = [ "../battery_utils/" ]
|
||||
|
||||
configs = [
|
||||
"${battery_utils}:coverage_flags",
|
||||
"${battery_utils}:utils_config",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [
|
||||
"../battery_utils/battery_fuzzer_test.cpp",
|
||||
"./isbatteryconfigsupported_fuzzer_test.cpp",
|
||||
]
|
||||
deps = [
|
||||
"${battery_service_zidl}:batterysrv_stub",
|
||||
"${battery_service}:batteryservice",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"drivers_interface_battery:libbattery_proxy_2.0",
|
||||
"hdf_core:libhdi",
|
||||
"hdf_core:libpub_utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
}
|
13
test/fuzztest/isbatteryconfigsupported_fuzzer/corpus/init
Normal file
13
test/fuzztest/isbatteryconfigsupported_fuzzer/corpus/init
Normal file
@ -0,0 +1,13 @@
|
||||
# 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
|
@ -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 "isbatteryconfigsupported_fuzzer"
|
||||
|
||||
#include "battery_fuzzer_test.h"
|
||||
#include "battery_manager_ipc_interface_code.h"
|
||||
|
||||
using namespace OHOS::PowerMgr;
|
||||
|
||||
namespace {
|
||||
BatteryFuzzerTest g_serviceTest;
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
g_serviceTest.TestBatteryServiceStub(
|
||||
static_cast<uint32_t>(BatterySrvInterfaceCode::SUPPORT_BATTERY_CONFIG), data, size);
|
||||
return 0;
|
||||
}
|
25
test/fuzztest/isbatteryconfigsupported_fuzzer/project.xml
Normal file
25
test/fuzztest/isbatteryconfigsupported_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>180</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
58
test/fuzztest/setbatteryconfig_fuzzer/BUILD.gn
Normal file
58
test/fuzztest/setbatteryconfig_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,58 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("../../../batterymgr.gni")
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("SetBatteryConfigFuzzTest") {
|
||||
module_out_path = "${module_output_path}"
|
||||
fuzz_config_file =
|
||||
"${battery_manager_path}/test/fuzztest/setbatteryconfig_fuzzer"
|
||||
|
||||
include_dirs = [ "../battery_utils/" ]
|
||||
|
||||
configs = [
|
||||
"${battery_utils}:coverage_flags",
|
||||
"${battery_utils}:utils_config",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [
|
||||
"../battery_utils/battery_fuzzer_test.cpp",
|
||||
"./setbatteryconfig_fuzzer_test.cpp",
|
||||
]
|
||||
deps = [
|
||||
"${battery_service_zidl}:batterysrv_stub",
|
||||
"${battery_service}:batteryservice",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"drivers_interface_battery:libbattery_proxy_2.0",
|
||||
"hdf_core:libhdi",
|
||||
"hdf_core:libpub_utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
}
|
13
test/fuzztest/setbatteryconfig_fuzzer/corpus/init
Normal file
13
test/fuzztest/setbatteryconfig_fuzzer/corpus/init
Normal file
@ -0,0 +1,13 @@
|
||||
# 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
|
25
test/fuzztest/setbatteryconfig_fuzzer/project.xml
Normal file
25
test/fuzztest/setbatteryconfig_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>180</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -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 "setbatteryconfig_fuzzer"
|
||||
|
||||
#include "battery_fuzzer_test.h"
|
||||
#include "battery_manager_ipc_interface_code.h"
|
||||
|
||||
using namespace OHOS::PowerMgr;
|
||||
|
||||
namespace {
|
||||
BatteryFuzzerTest g_serviceTest;
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
g_serviceTest.TestBatteryServiceStub(
|
||||
static_cast<uint32_t>(BatterySrvInterfaceCode::SET_BATTERY_CONFIG), data, size);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user