mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-08-26 18:17:07 -04:00
test: add framework fuzztest
Signed-off-by: guodongqi <guodongqi2@huawei.com>
This commit is contained in:
+2
-2
@@ -11,10 +11,10 @@ module_output_path = "hdf/hdi"
|
||||
ohos_fuzztest("LoadDeviceFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file = "//drivers/framework/test/fuzztest/loaddevice_fuzzer"
|
||||
fuzz_config_file = "//drivers/framework/test/fuzztest/hdimanager/loaddevice_fuzzer"
|
||||
|
||||
include_dirs = [
|
||||
"//drivers/framework/test/fuzztest/loaddevice_fuzzer",
|
||||
"//drivers/framework/test/fuzztest/hdimanager/loaddevice_fuzzer",
|
||||
"//drivers/adapter/uhdf2/include/hdi",
|
||||
"//drivers/adapter/uhdf2/osal/include",
|
||||
"//drivers/framework/include/utils",
|
||||
+5
-3
@@ -9,17 +9,19 @@
|
||||
#include "loaddevice_fuzzer.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <hdf_base.h>
|
||||
#include "idevmgr_hdi.h"
|
||||
|
||||
using namespace OHOS::HDI::DeviceManager::V1_0;
|
||||
|
||||
namespace OHOS {
|
||||
sptr<IDeviceManager> g_devicemanager = IDeviceManager::Get();
|
||||
|
||||
bool LoadDeviceFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
std::string serviceName((const char *)data);
|
||||
sptr<IDeviceManager> devicemanager = IDeviceManager::Get();
|
||||
if (!devicemanager->LoadDevice(serviceName)) {
|
||||
if (g_devicemanager != nullptr && g_devicemanager->LoadDevice(serviceName) == HDF_SUCCESS) {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
@@ -29,5 +31,5 @@ bool LoadDeviceFuzzTest(const uint8_t *data, size_t size)
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
OHOS::LoadDeviceFuzzTest(data, size);
|
||||
return 0;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
+2
-2
@@ -10,8 +10,8 @@
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<max_total_time>120</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
<rss_limit_mb>2048</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
+2
-2
@@ -12,10 +12,10 @@ ohos_fuzztest("RegisterServiceStatusListenerFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"//drivers/framework/test/fuzztest/registerservicestatuslistener_fuzzer"
|
||||
"//drivers/framework/test/fuzztest/hdimanager/registerservicestatuslistener_fuzzer"
|
||||
|
||||
include_dirs = [
|
||||
"//drivers/framework/test/fuzztest/registerservicestatuslistener_fuzzer",
|
||||
"//drivers/framework/test/fuzztest/hdimanager/registerservicestatuslistener_fuzzer",
|
||||
"//drivers/adapter/uhdf2/include/hdi",
|
||||
"//drivers/adapter/uhdf2/osal/include",
|
||||
"//drivers/framework/include/utils",
|
||||
+2
-2
@@ -10,8 +10,8 @@
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<max_total_time>120</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
<rss_limit_mb>2048</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
+10
-4
@@ -9,6 +9,7 @@
|
||||
#include "registerservicestatuslistener_fuzzer.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <hdf_base.h>
|
||||
#include <hdi_base.h>
|
||||
#include <iremote_broker.h>
|
||||
#include <refbase.h>
|
||||
@@ -31,14 +32,19 @@ void RegisterServStatListenerFuzzer::OnReceive(const ServiceStatus &status)
|
||||
} // namespace OHOS
|
||||
|
||||
namespace OHOS {
|
||||
sptr<IServiceManager> g_servmanager = IServiceManager::Get();
|
||||
sptr<IServStatListener> g_servstatlistener = new RegisterServStatListenerFuzzer();
|
||||
|
||||
bool RegisterServiceStatusListenerFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
sptr<IServiceManager> servmanager = IServiceManager::Get();
|
||||
sptr<IServStatListener> servstatlistener = new RegisterServStatListenerFuzzer();
|
||||
if (!servmanager->RegisterServiceStatusListener(servstatlistener, reinterpret_cast<uintptr_t>(data))) {
|
||||
if (g_servmanager != nullptr &&
|
||||
g_servmanager->RegisterServiceStatusListener(
|
||||
g_servstatlistener, reinterpret_cast<uintptr_t>(data)) == HDF_SUCCESS) {
|
||||
g_servmanager->UnregisterServiceStatusListener(g_servstatlistener);
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -46,5 +52,5 @@ bool RegisterServiceStatusListenerFuzzTest(const uint8_t *data, size_t size)
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
OHOS::RegisterServiceStatusListenerFuzzTest(data, size);
|
||||
return 0;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
+2
-2
@@ -11,10 +11,10 @@ module_output_path = "hdf/hdi"
|
||||
ohos_fuzztest("UnloadDeviceFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file = "//drivers/framework/test/fuzztest/unloaddevice_fuzzer"
|
||||
fuzz_config_file = "//drivers/framework/test/fuzztest/hdimanager/unloaddevice_fuzzer"
|
||||
|
||||
include_dirs = [
|
||||
"//drivers/framework/test/fuzztest/unloaddevice_fuzzer",
|
||||
"//drivers/framework/test/fuzztest/hdimanager/unloaddevice_fuzzer",
|
||||
"//drivers/adapter/uhdf2/include/hdi",
|
||||
"//drivers/adapter/uhdf2/osal/include",
|
||||
"//drivers/framework/include/utils",
|
||||
+2
-2
@@ -10,8 +10,8 @@
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<max_total_time>120</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
<rss_limit_mb>2048</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
+7
-4
@@ -9,6 +9,8 @@
|
||||
#include "unloaddevice_fuzzer.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <hdf_base.h>
|
||||
#include <hdi_base.h>
|
||||
#include "idevmgr_hdi.h"
|
||||
|
||||
using namespace OHOS::HDI::DeviceManager::V1_0;
|
||||
@@ -16,16 +18,17 @@ using namespace OHOS::HDI::DeviceManager::V1_0;
|
||||
static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service";
|
||||
|
||||
namespace OHOS {
|
||||
sptr<IDeviceManager> g_devicemanager = IDeviceManager::Get();
|
||||
|
||||
bool UnloadDeviceFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
std::string serviceName((const char *)data);
|
||||
sptr<IDeviceManager> devicemanager = IDeviceManager::Get();
|
||||
if (!devicemanager->LoadDevice(TEST_SERVICE_NAME)) {
|
||||
if (g_devicemanager != nullptr && g_devicemanager->LoadDevice(TEST_SERVICE_NAME) == HDF_SUCCESS) {
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (!devicemanager->UnloadDevice(serviceName)) {
|
||||
if (g_devicemanager != nullptr && g_devicemanager->UnloadDevice(serviceName) == HDF_SUCCESS) {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
@@ -35,5 +38,5 @@ bool UnloadDeviceFuzzTest(const uint8_t *data, size_t size)
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
OHOS::UnloadDeviceFuzzTest(data, size);
|
||||
return 0;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
#
|
||||
# HDF is dual licensed: you can use it either under the terms of
|
||||
# the GPL, or the BSD license, at your option.
|
||||
# See the LICENSE file in the root of this repository for complete details.
|
||||
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "hdf/ioservice"
|
||||
|
||||
ohos_fuzztest("IoserviceBindFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioservicebind_fuzzer"
|
||||
|
||||
include_dirs =
|
||||
[ "//drivers/framework/test/fuzztest/ioservice/ioservicebind_fuzzer.h" ]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "ioservicebind_fuzzer.cpp" ]
|
||||
external_deps = [ "device_driver_framework:libhdf_utils" ]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":IoserviceBindFuzzTest" ]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
#
|
||||
# HDF is dual licensed: you can use it either under the terms of
|
||||
# the GPL, or the BSD license, at your option.
|
||||
# See the LICENSE file in the root of this repository for complete details.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "ioservicebind_fuzzer.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_io_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
bool IoserviceBindFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
struct HdfIoService *testServ = HdfIoServiceBind((const char *)data);
|
||||
if (testServ != nullptr) {
|
||||
result = true;
|
||||
}
|
||||
HdfIoServiceRecycle(testServ);
|
||||
return result;
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
OHOS::IoserviceBindFuzzTest(data, size);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef IOSERVICE_BIND_FUZZER_H
|
||||
#define IOSERVICE_BIND_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "ioservicebind_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
HDF is dual licensed: you can use it either under the terms of
|
||||
the GPL, or the BSD license, at your option.
|
||||
See the LICENSE file in the root of this repository for complete details.
|
||||
-->
|
||||
<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>120</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>2048</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,42 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
#
|
||||
# HDF is dual licensed: you can use it either under the terms of
|
||||
# the GPL, or the BSD license, at your option.
|
||||
# See the LICENSE file in the root of this repository for complete details.
|
||||
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "hdf/ioservice"
|
||||
|
||||
ohos_fuzztest("IoserviceGroupListenFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioservicegrouplisten_fuzzer"
|
||||
|
||||
include_dirs = [
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioservicegrouplisten_fuzzer.h",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
if (is_standard_system) {
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"utils_base:utils",
|
||||
]
|
||||
} else {
|
||||
external_deps = [ "hilog:libhilog" ]
|
||||
}
|
||||
sources = [ "ioservicegrouplisten_fuzzer.cpp" ]
|
||||
external_deps += [ "device_driver_framework:libhdf_utils" ]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":IoserviceGroupListenFuzzTest" ]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
#
|
||||
# HDF is dual licensed: you can use it either under the terms of
|
||||
# the GPL, or the BSD license, at your option.
|
||||
# See the LICENSE file in the root of this repository for complete details.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "ioservicegrouplisten_fuzzer.h"
|
||||
#include <cinttypes>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_io_service.h"
|
||||
#include "osal_time.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct Eventlistener {
|
||||
struct HdfDevEventlistener listener;
|
||||
int32_t eventCount;
|
||||
};
|
||||
static int OnDevEventReceived(
|
||||
struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id, struct HdfSBuf *data);
|
||||
static int eventCount = 0;
|
||||
|
||||
static struct Eventlistener listener0 = {
|
||||
.listener.onReceive = OnDevEventReceived,
|
||||
.listener.priv = (void *)"listener0",
|
||||
.eventCount = 0,
|
||||
};
|
||||
|
||||
static int OnDevEventReceived(
|
||||
struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id, struct HdfSBuf *data)
|
||||
{
|
||||
OsalTimespec time;
|
||||
OsalGetTime(&time);
|
||||
HDF_LOGI("%{public}s: received event[%{public}d] from %{public}s at %" PRIu64 ".%" PRIu64 "",
|
||||
(char *)listener->priv, eventCount++, (char *)service->priv, time.sec, time.usec);
|
||||
|
||||
const char *string = HdfSbufReadString(data);
|
||||
if (string == nullptr) {
|
||||
HDF_LOGE("failed to read string in event data");
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
struct Eventlistener *listenercount = CONTAINER_OF(listener, struct Eventlistener, listener);
|
||||
listenercount->eventCount++;
|
||||
HDF_LOGI("%{public}s: dev event received: %{public}u %{public}s", (char *)service->priv, id, string);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
bool IoserviceGroupListenFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
struct HdfIoService *serv = HdfIoServiceBind((const char *)data);
|
||||
if (serv == nullptr) {
|
||||
return false;
|
||||
}
|
||||
struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
|
||||
if (group == nullptr) {
|
||||
HdfIoServiceRecycle(serv);
|
||||
return false;
|
||||
}
|
||||
int ret = HdfIoServiceGroupAddService(group, serv);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HdfIoServiceGroupRecycle(group);
|
||||
HdfIoServiceRecycle(serv);
|
||||
return false;
|
||||
}
|
||||
if (HdfIoServiceGroupRegisterListener(group, &listener0.listener) == HDF_SUCCESS) {
|
||||
ret = HdfIoServiceGroupUnregisterListener(group, &listener0.listener);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HdfIoServiceGroupRecycle(group);
|
||||
HdfIoServiceRecycle(serv);
|
||||
return false;
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
HdfIoServiceGroupRecycle(group);
|
||||
HdfIoServiceRecycle(serv);
|
||||
return result;
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
OHOS::IoserviceGroupListenFuzzTest(data, size);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef IOSERVICE_GROUP_LISTEN_FUZZER_H
|
||||
#define IOSERVICE_GROUP_LISTEN_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "ioservicegrouplisten_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
HDF is dual licensed: you can use it either under the terms of
|
||||
the GPL, or the BSD license, at your option.
|
||||
See the LICENSE file in the root of this repository for complete details.
|
||||
-->
|
||||
<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>120</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>2048</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
#
|
||||
# HDF is dual licensed: you can use it either under the terms of
|
||||
# the GPL, or the BSD license, at your option.
|
||||
# See the LICENSE file in the root of this repository for complete details.
|
||||
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "hdf/ioservice"
|
||||
|
||||
ohos_fuzztest("IoserviceListenFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioservicelisten_fuzzer"
|
||||
|
||||
include_dirs =
|
||||
[ "//drivers/framework/test/fuzztest/ioservice/ioservicelisten_fuzzer.h" ]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
if (is_standard_system) {
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"utils_base:utils",
|
||||
]
|
||||
} else {
|
||||
external_deps = [ "hilog:libhilog" ]
|
||||
}
|
||||
sources = [ "ioservicelisten_fuzzer.cpp" ]
|
||||
external_deps += [ "device_driver_framework:libhdf_utils" ]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":IoserviceListenFuzzTest" ]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
#
|
||||
# HDF is dual licensed: you can use it either under the terms of
|
||||
# the GPL, or the BSD license, at your option.
|
||||
# See the LICENSE file in the root of this repository for complete details.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "ioservicelisten_fuzzer.h"
|
||||
#include <cinttypes>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_io_service.h"
|
||||
#include "osal_time.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct Eventlistener {
|
||||
struct HdfDevEventlistener listener;
|
||||
int32_t eventCount;
|
||||
};
|
||||
static int OnDevEventReceived(
|
||||
struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id, struct HdfSBuf *data);
|
||||
static int eventCount = 0;
|
||||
|
||||
static struct Eventlistener listener0 = {
|
||||
.listener.onReceive = OnDevEventReceived,
|
||||
.listener.priv = (void *)"listener0",
|
||||
.eventCount = 0,
|
||||
};
|
||||
|
||||
static int OnDevEventReceived(
|
||||
struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id, struct HdfSBuf *data)
|
||||
{
|
||||
OsalTimespec time;
|
||||
OsalGetTime(&time);
|
||||
HDF_LOGI("%{public}s: received event[%{public}d] from %{public}s at %" PRIu64 ".%" PRIu64 "",
|
||||
(char *)listener->priv, eventCount++, (char *)service->priv, time.sec, time.usec);
|
||||
|
||||
const char *string = HdfSbufReadString(data);
|
||||
if (string == nullptr) {
|
||||
HDF_LOGE("failed to read string in event data");
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
struct Eventlistener *listenercount = CONTAINER_OF(listener, struct Eventlistener, listener);
|
||||
listenercount->eventCount++;
|
||||
HDF_LOGI("%{public}s: dev event received: %{public}u %{public}s", (char *)service->priv, id, string);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
bool IoserviceListenFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
struct HdfIoService *serv = HdfIoServiceBind((const char *)data);
|
||||
if (serv == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (HdfDeviceRegisterEventListener(serv, &listener0.listener) == HDF_SUCCESS) {
|
||||
int ret = HdfDeviceUnregisterEventListener(serv, &listener0.listener);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HdfIoServiceRecycle(serv);
|
||||
return false;
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
HdfIoServiceRecycle(serv);
|
||||
return result;
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
OHOS::IoserviceListenFuzzTest(data, size);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef IOSERVICE_LISTEN_FUZZER_H
|
||||
#define IOSERVICE_LISTEN_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "ioservicelisten_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
HDF is dual licensed: you can use it either under the terms of
|
||||
the GPL, or the BSD license, at your option.
|
||||
See the LICENSE file in the root of this repository for complete details.
|
||||
-->
|
||||
<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>120</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>2048</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,39 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
#
|
||||
# HDF is dual licensed: you can use it either under the terms of
|
||||
# the GPL, or the BSD license, at your option.
|
||||
# See the LICENSE file in the root of this repository for complete details.
|
||||
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "hdf/ioservice"
|
||||
|
||||
ohos_fuzztest("IoserviceNameGetByDeviceClassFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file = "//drivers/framework/test/fuzztest/ioservice/ioservicenamegetbydeviceclass_fuzzer"
|
||||
|
||||
include_dirs = [ "//drivers/framework/test/fuzztest/ioservice/ioservicenamegetbydeviceclass_fuzzer.h" ]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
if (is_standard_system) {
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"utils_base:utils",
|
||||
]
|
||||
} else {
|
||||
external_deps = [ "hilog:libhilog" ]
|
||||
}
|
||||
sources = [ "ioservicenamegetbydeviceclass_fuzzer.cpp" ]
|
||||
external_deps += [ "device_driver_framework:libhdf_utils" ]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":IoserviceNameGetByDeviceClassFuzzTest" ]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
#
|
||||
# HDF is dual licensed: you can use it either under the terms of
|
||||
# the GPL, or the BSD license, at your option.
|
||||
# See the LICENSE file in the root of this repository for complete details.
|
||||
|
||||
FUZZ
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "ioservicenamegetbydeviceclass_fuzzer.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <hdf_sbuf.h>
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_io_service_if.h"
|
||||
|
||||
namespace OHOS {
|
||||
bool IoserviceNameGetByDeviceClassFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
struct HdfSBuf *reply = HdfSbufObtainDefaultSize();
|
||||
int32_t ret = HdfGetServiceNameByDeviceClass(static_cast<DeviceClass>(*data), reply);
|
||||
if (ret == HDF_SUCCESS) {
|
||||
result = true;
|
||||
}
|
||||
HdfSbufRecycle(reply);
|
||||
return result;
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
OHOS::IoserviceNameGetByDeviceClassFuzzTest(data, size);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef IOSERVICE_NAME_GET_BY_DEVICE_CLASS_FUZZER_H
|
||||
#define IOSERVICE_NAME_GET_BY_DEVICE_CLASS_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "ioservicenamegetbydeviceclass_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
HDF is dual licensed: you can use it either under the terms of
|
||||
the GPL, or the BSD license, at your option.
|
||||
See the LICENSE file in the root of this repository for complete details.
|
||||
-->
|
||||
<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>120</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>2048</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
#
|
||||
# HDF is dual licensed: you can use it either under the terms of
|
||||
# the GPL, or the BSD license, at your option.
|
||||
# See the LICENSE file in the root of this repository for complete details.
|
||||
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "hdf/ioservice"
|
||||
|
||||
ohos_fuzztest("IoserviceGroupRemoveServiceFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioserviceremove_fuzzer"
|
||||
|
||||
include_dirs =
|
||||
[ "//drivers/framework/test/fuzztest/ioservice/ioserviceremove_fuzzer.h" ]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
if (is_standard_system) {
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"utils_base:utils",
|
||||
]
|
||||
} else {
|
||||
external_deps = [ "hilog:libhilog" ]
|
||||
}
|
||||
sources = [ "ioserviceremove_fuzzer.cpp" ]
|
||||
external_deps += [ "device_driver_framework:libhdf_utils" ]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":IoserviceGroupRemoveServiceFuzzTest" ]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
#
|
||||
# HDF is dual licensed: you can use it either under the terms of
|
||||
# the GPL, or the BSD license, at your option.
|
||||
# See the LICENSE file in the root of this repository for complete details.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "ioserviceremove_fuzzer.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_io_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
bool IoserviceGroupRemoveServiceFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
struct HdfIoService *serv = HdfIoServiceBind((const char *)data);
|
||||
if (serv == nullptr) {
|
||||
return false;
|
||||
}
|
||||
struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
|
||||
if (group == nullptr) {
|
||||
HdfIoServiceRecycle(serv);
|
||||
return false;
|
||||
}
|
||||
int ret = HdfIoServiceGroupAddService(group, serv);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HdfIoServiceGroupRecycle(group);
|
||||
HdfIoServiceRecycle(serv);
|
||||
return false;
|
||||
}
|
||||
HdfIoServiceGroupRemoveService(group, serv);
|
||||
if (group == nullptr) {
|
||||
result = true;
|
||||
}
|
||||
HdfIoServiceGroupRecycle(group);
|
||||
HdfIoServiceRecycle(serv);
|
||||
return result;
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
OHOS::IoserviceGroupRemoveServiceFuzzTest(data, size);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef IOSERVICE_REMOVE_FUZZER_H
|
||||
#define IOSERVICE_REMOVE_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "ioserviceremove_fuzzer"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
|
||||
HDF is dual licensed: you can use it either under the terms of
|
||||
the GPL, or the BSD license, at your option.
|
||||
See the LICENSE file in the root of this repository for complete details.
|
||||
-->
|
||||
<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>120</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>2048</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
Reference in New Issue
Block a user