mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-07-20 19:27:49 -04:00
fix: optimize fuzz test cases
Signed-off-by: guodongqi <guodongqi2@huawei.com>
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "hdf/srvmgr"
|
||||
module_output_path = "hdf/hdi"
|
||||
|
||||
ohos_fuzztest("LoadDeviceFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
@@ -11,17 +11,20 @@
|
||||
#include <cstdint>
|
||||
#include <hdf_base.h>
|
||||
#include "idevmgr_hdi.h"
|
||||
#include "parcel.h"
|
||||
|
||||
using namespace OHOS::HDI::DeviceManager::V1_0;
|
||||
|
||||
namespace OHOS {
|
||||
sptr<IDeviceManager> g_devicemanager = IDeviceManager::Get();
|
||||
sptr<IDeviceManager> g_deviceManager = IDeviceManager::Get();
|
||||
|
||||
bool LoadDeviceFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
std::string serviceName((const char *)data);
|
||||
if (g_devicemanager != nullptr && g_devicemanager->LoadDevice(serviceName) == HDF_SUCCESS) {
|
||||
Parcel parcel;
|
||||
parcel.WriteBuffer(data, size);
|
||||
auto servicename = parcel.ReadString();
|
||||
if (g_deviceManager != nullptr && g_deviceManager->LoadDevice(servicename) == HDF_SUCCESS) {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "hdf/srvmgr"
|
||||
module_output_path = "hdf/hdi"
|
||||
|
||||
ohos_fuzztest("RegisterServiceStatusListenerFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
+9
-5
@@ -15,6 +15,7 @@
|
||||
#include <refbase.h>
|
||||
#include "iservmgr_hdi.h"
|
||||
#include "iservstat_listener_hdi.h"
|
||||
#include "parcel.h"
|
||||
|
||||
using namespace OHOS::HDI::ServiceManager::V1_0;
|
||||
|
||||
@@ -32,8 +33,8 @@ void RegisterServStatListenerFuzzer::OnReceive(const ServiceStatus &status)
|
||||
} // namespace OHOS
|
||||
|
||||
namespace OHOS {
|
||||
sptr<IServiceManager> g_servmanager = IServiceManager::Get();
|
||||
sptr<IServStatListener> g_servstatlistener = new RegisterServStatListenerFuzzer();
|
||||
sptr<IServiceManager> g_servManager = IServiceManager::Get();
|
||||
sptr<IServStatListener> g_servStatListener = new RegisterServStatListenerFuzzer();
|
||||
|
||||
bool RegisterServiceStatusListenerFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
@@ -42,9 +43,12 @@ bool RegisterServiceStatusListenerFuzzTest(const uint8_t *data, size_t size)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (g_servmanager != nullptr &&
|
||||
g_servmanager->RegisterServiceStatusListener(g_servstatlistener, *((uint16_t *)data)) == HDF_SUCCESS) {
|
||||
g_servmanager->UnregisterServiceStatusListener(g_servstatlistener);
|
||||
Parcel parcel;
|
||||
parcel.WriteBuffer(data, size);
|
||||
auto deviceclass = parcel.ReadUint16();
|
||||
if (g_servManager != nullptr &&
|
||||
g_servManager->RegisterServiceStatusListener(g_servStatListener, deviceclass) == HDF_SUCCESS) {
|
||||
g_servManager->UnregisterServiceStatusListener(g_servStatListener);
|
||||
result = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,23 +12,26 @@
|
||||
#include <hdf_base.h>
|
||||
#include <hdi_base.h>
|
||||
#include "idevmgr_hdi.h"
|
||||
#include "parcel.h"
|
||||
|
||||
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();
|
||||
sptr<IDeviceManager> g_deviceManager = IDeviceManager::Get();
|
||||
|
||||
bool UnloadDeviceFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
std::string serviceName((const char *)data);
|
||||
if (g_devicemanager != nullptr && g_devicemanager->LoadDevice(TEST_SERVICE_NAME) == HDF_SUCCESS) {
|
||||
Parcel parcel;
|
||||
parcel.WriteBuffer(data, size);
|
||||
auto servicename = parcel.ReadString();
|
||||
if (g_deviceManager != nullptr && g_deviceManager->LoadDevice(TEST_SERVICE_NAME) == HDF_SUCCESS) {
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (g_devicemanager != nullptr && g_devicemanager->UnloadDevice(serviceName) == HDF_SUCCESS) {
|
||||
if (g_deviceManager != nullptr && g_deviceManager->UnloadDevice(servicename) == HDF_SUCCESS) {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -14,8 +14,10 @@ ohos_fuzztest("IoserviceBindFuzzTest") {
|
||||
fuzz_config_file =
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioservicebind_fuzzer"
|
||||
|
||||
include_dirs =
|
||||
[ "//drivers/framework/test/fuzztest/ioservice/ioservicebind_fuzzer.h" ]
|
||||
include_dirs = [
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioservicebind_fuzzer.h",
|
||||
"//utils/native/base/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
@@ -23,7 +25,10 @@ ohos_fuzztest("IoserviceBindFuzzTest") {
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "ioservicebind_fuzzer.cpp" ]
|
||||
external_deps = [ "device_driver_framework:libhdf_utils" ]
|
||||
external_deps = [
|
||||
"device_driver_framework:libhdf_utils",
|
||||
"utils_base:utils",
|
||||
]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
|
||||
@@ -11,12 +11,16 @@
|
||||
#include <cstdint>
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_io_service.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
bool IoserviceBindFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
struct HdfIoService *testServ = HdfIoServiceBind((const char *)data);
|
||||
Parcel parcel;
|
||||
parcel.WriteBuffer(data, size);
|
||||
auto servicename = parcel.ReadCString();
|
||||
struct HdfIoService *testServ = HdfIoServiceBind(servicename);
|
||||
if (testServ != nullptr) {
|
||||
result = true;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ ohos_fuzztest("IoserviceGroupListenFuzzTest") {
|
||||
|
||||
include_dirs = [
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioservicegrouplisten_fuzzer.h",
|
||||
"//utils/native/base/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_io_service.h"
|
||||
#include "osal_time.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct Eventlistener {
|
||||
@@ -52,7 +53,10 @@ static int OnDevEventReceived(
|
||||
bool IoserviceGroupListenFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
struct HdfIoService *serv = HdfIoServiceBind((const char *)data);
|
||||
Parcel parcel;
|
||||
parcel.WriteBuffer(data, size);
|
||||
auto servicename = parcel.ReadCString();
|
||||
struct HdfIoService *serv = HdfIoServiceBind(servicename);
|
||||
if (serv == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -14,8 +14,10 @@ ohos_fuzztest("IoserviceListenFuzzTest") {
|
||||
fuzz_config_file =
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioservicelisten_fuzzer"
|
||||
|
||||
include_dirs =
|
||||
[ "//drivers/framework/test/fuzztest/ioservice/ioservicelisten_fuzzer.h" ]
|
||||
include_dirs = [
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioservicelisten_fuzzer.h",
|
||||
"//utils/native/base/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_io_service.h"
|
||||
#include "osal_time.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct Eventlistener {
|
||||
@@ -52,7 +53,10 @@ static int OnDevEventReceived(
|
||||
bool IoserviceListenFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
struct HdfIoService *serv = HdfIoServiceBind((const char *)data);
|
||||
Parcel parcel;
|
||||
parcel.WriteBuffer(data, size);
|
||||
auto servicename = parcel.ReadCString();
|
||||
struct HdfIoService *serv = HdfIoServiceBind(servicename);
|
||||
if (serv == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -14,8 +14,10 @@ ohos_fuzztest("IoserviceRemoveFuzzTest") {
|
||||
fuzz_config_file =
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioserviceremove_fuzzer"
|
||||
|
||||
include_dirs =
|
||||
[ "//drivers/framework/test/fuzztest/ioservice/ioserviceremove_fuzzer.h" ]
|
||||
include_dirs = [
|
||||
"//drivers/framework/test/fuzztest/ioservice/ioserviceremove_fuzzer.h",
|
||||
"//utils/native/base/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
|
||||
@@ -11,12 +11,16 @@
|
||||
#include <cstdint>
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_io_service.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
bool IoserviceGroupRemoveServiceFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
struct HdfIoService *serv = HdfIoServiceBind((const char *)data);
|
||||
Parcel parcel;
|
||||
parcel.WriteBuffer(data, size);
|
||||
auto servicename = parcel.ReadCString();
|
||||
struct HdfIoService *serv = HdfIoServiceBind(servicename);
|
||||
if (serv == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user