!374 整改Fuzz未使用随机值的用例

Merge pull request !374 from 刘昊苏/master
This commit is contained in:
openharmony_ci 2024-09-25 03:05:58 +00:00 committed by Gitee
commit fb3dd779c7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
13 changed files with 61 additions and 349 deletions

View File

@ -92,7 +92,7 @@ ohos_shared_library("scan_service") {
] ]
if (sane_enable) { if (sane_enable) {
external_deps += [ "backends:third_sane" ] external_deps += [ "backends:sane" ]
cflags_cc += [ "-DSANE_ENABLE" ] cflags_cc += [ "-DSANE_ENABLE" ]
} }

View File

@ -541,7 +541,7 @@ void ScanServiceAbility::SaneGetScanner()
SCAN_HILOGE("SaneGetScanner SetScannerSerialNumber failed, model:[%{public}s]", info.model.c_str()); SCAN_HILOGE("SaneGetScanner SetScannerSerialNumber failed, model:[%{public}s]", info.model.c_str());
} }
} }
std::lock_guard<std::mutex> autoLock(clearMapLock_); clearMapLock_.lock();
for (auto &t : saneGetUsbDeviceInfoMap) { for (auto &t : saneGetUsbDeviceInfoMap) {
SendDeviceInfo(t.second, SCAN_DEVICE_FOUND); SendDeviceInfo(t.second, SCAN_DEVICE_FOUND);
deviceInfos.emplace_back(t.second); deviceInfos.emplace_back(t.second);
@ -550,6 +550,7 @@ void ScanServiceAbility::SaneGetScanner()
SendDeviceInfo(t.second, SCAN_DEVICE_FOUND); SendDeviceInfo(t.second, SCAN_DEVICE_FOUND);
deviceInfos.emplace_back(t.second); deviceInfos.emplace_back(t.second);
} }
clearMapLock_.unlock();
g_scannerState = SCANNER_READY; g_scannerState = SCANNER_READY;
} }
#endif #endif

View File

@ -28,17 +28,6 @@ constexpr int MAX_SET_NUMBER = 100;
constexpr size_t FOO_MAX_LEN = 1024; constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4; constexpr size_t U32_AT_SIZE = 4;
void TestInitCupsResources(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintCupsClient::GetInstance()->InitCupsResources();
}
void TestStopCupsdService(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintCupsClient::GetInstance()->InitCupsResources();
PrintCupsClient::GetInstance()->StopCupsdService();
}
void TestQueryPPDInformation(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestQueryPPDInformation(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{ {
PrintCupsClient::GetInstance()->InitCupsResources(); PrintCupsClient::GetInstance()->InitCupsResources();
@ -47,6 +36,7 @@ void TestQueryPPDInformation(const uint8_t *data, size_t size, FuzzedDataProvide
std::vector<std::string> ppds; std::vector<std::string> ppds;
ppds.push_back(ppd); ppds.push_back(ppd);
PrintCupsClient::GetInstance()->QueryPPDInformation(makeModelStr.c_str(), ppds); PrintCupsClient::GetInstance()->QueryPPDInformation(makeModelStr.c_str(), ppds);
PrintCupsClient::GetInstance()->StopCupsdService();
} }
void TestAddPrinterToCups(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestAddPrinterToCups(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
@ -56,6 +46,7 @@ void TestAddPrinterToCups(const uint8_t *data, size_t size, FuzzedDataProvider *
std::string printerName = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string printerName = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
std::string printerMake = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string printerMake = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
PrintCupsClient::GetInstance()->AddPrinterToCups(printerUri, printerName, printerMake); PrintCupsClient::GetInstance()->AddPrinterToCups(printerUri, printerName, printerMake);
PrintCupsClient::GetInstance()->JobCompleteCallback();
} }
void TestQueryPrinterCapabilityByUri(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestQueryPrinterCapabilityByUri(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
@ -78,6 +69,8 @@ void TestAddCupsPrintJob(const uint8_t *data, size_t size, FuzzedDataProvider *d
{ {
PrintCupsClient::GetInstance()->InitCupsResources(); PrintCupsClient::GetInstance()->InitCupsResources();
PrintJob jobInfo; PrintJob jobInfo;
std::string option = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
jobInfo.SetOption(option);
PrintCupsClient::GetInstance()->AddCupsPrintJob(jobInfo); PrintCupsClient::GetInstance()->AddCupsPrintJob(jobInfo);
} }
@ -132,16 +125,11 @@ void TestQueryPrinterInfoByPrinterId(const uint8_t *data, size_t size, FuzzedDat
PrintCupsClient::GetInstance()->QueryPrinterInfoByPrinterId(printerId, info); PrintCupsClient::GetInstance()->QueryPrinterInfoByPrinterId(printerId, info);
} }
void TestJobCompleteCallback(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintCupsClient::GetInstance()->InitCupsResources();
PrintCupsClient::GetInstance()->JobCompleteCallback();
}
void TestCheckPrinterMakeModel(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestCheckPrinterMakeModel(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{ {
PrintCupsClient::GetInstance()->InitCupsResources(); PrintCupsClient::GetInstance()->InitCupsResources();
JobParameters jobParams; JobParameters jobParams;
jobParams.printerUri = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
PrintCupsClient::GetInstance()->CheckPrinterMakeModel(&jobParams); PrintCupsClient::GetInstance()->CheckPrinterMakeModel(&jobParams);
} }
@ -280,8 +268,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
} }
FuzzedDataProvider dataProvider(data, size); FuzzedDataProvider dataProvider(data, size);
OHOS::Print::TestInitCupsResources(data, size, &dataProvider);
OHOS::Print::TestStopCupsdService(data, size, &dataProvider);
OHOS::Print::TestQueryPPDInformation(data, size, &dataProvider); OHOS::Print::TestQueryPPDInformation(data, size, &dataProvider);
OHOS::Print::TestAddPrinterToCups(data, size, &dataProvider); OHOS::Print::TestAddPrinterToCups(data, size, &dataProvider);
OHOS::Print::TestQueryPrinterCapabilityByUri(data, size, &dataProvider); OHOS::Print::TestQueryPrinterCapabilityByUri(data, size, &dataProvider);
@ -293,7 +279,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
OHOS::Print::TestSetDefaultPrinter(data, size, &dataProvider); OHOS::Print::TestSetDefaultPrinter(data, size, &dataProvider);
OHOS::Print::TestQueryPrinterAttrList(data, size, &dataProvider); OHOS::Print::TestQueryPrinterAttrList(data, size, &dataProvider);
OHOS::Print::TestQueryPrinterInfoByPrinterId(data, size, &dataProvider); OHOS::Print::TestQueryPrinterInfoByPrinterId(data, size, &dataProvider);
OHOS::Print::TestJobCompleteCallback(data, size, &dataProvider);
OHOS::Print::TestCheckPrinterMakeModel(data, size, &dataProvider); OHOS::Print::TestCheckPrinterMakeModel(data, size, &dataProvider);
OHOS::Print::TestDeletePrinterFromCups(data, size, &dataProvider); OHOS::Print::TestDeletePrinterFromCups(data, size, &dataProvider);
OHOS::Print::TestCheckPrinterOnline(data, size, &dataProvider); OHOS::Print::TestCheckPrinterOnline(data, size, &dataProvider);

View File

@ -35,21 +35,14 @@ static constexpr const char *JOB_OPTIONS =
"\"documentFormat\":\"application/pdf\",\"files\":[\"/data/1.pdf\"]}"; "\"documentFormat\":\"application/pdf\",\"files\":[\"/data/1.pdf\"]}";
static const std::string DEFAULT_PRINTERID = "testId"; static const std::string DEFAULT_PRINTERID = "testId";
void TestInitialize(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestStartPrint(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{ {
PrintServiceAbilityMockPermission::MockPermission(); PrintServiceAbilityMockPermission::MockPermission();
PrintServiceAbility::GetInstance()->OnStart(); PrintServiceAbility::GetInstance()->OnStart();
PrintServiceAbility::GetInstance()->ManualStart();
auto cupsPrinter = std::make_shared<CupsPrinterInfo>(); auto cupsPrinter = std::make_shared<CupsPrinterInfo>();
PrintServiceAbility::GetInstance()->printSystemData_.addedPrinterMap_.Insert(DEFAULT_PRINTERID, cupsPrinter); PrintServiceAbility::GetInstance()->printSystemData_.addedPrinterMap_.Insert(DEFAULT_PRINTERID, cupsPrinter);
}
void TestStartService(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintServiceAbility::GetInstance()->StartService(); PrintServiceAbility::GetInstance()->StartService();
}
void TestStartPrint(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
std::string fileUri = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string fileUri = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
std::vector<std::string> fileList; std::vector<std::string> fileList;
fileList.push_back(fileUri); fileList.push_back(fileUri);
@ -58,6 +51,7 @@ void TestStartPrint(const uint8_t *data, size_t size, FuzzedDataProvider *dataPr
fdList.push_back(fd); fdList.push_back(fd);
std::string taskId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string taskId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
PrintServiceAbility::GetInstance()->StartPrint(fileList, fdList, taskId); PrintServiceAbility::GetInstance()->StartPrint(fileList, fdList, taskId);
PrintServiceAbility::GetInstance()->OnStop();
} }
void TestStopPrint(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestStopPrint(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
@ -97,10 +91,6 @@ void TestStartDiscoverPrinter(const uint8_t *data, size_t size, FuzzedDataProvid
extensionIds.push_back(printExtensionInfo.GetExtensionId()); extensionIds.push_back(printExtensionInfo.GetExtensionId());
} }
PrintServiceAbility::GetInstance()->StartDiscoverPrinter(extensionIds); PrintServiceAbility::GetInstance()->StartDiscoverPrinter(extensionIds);
}
void TestStopDiscoverPrinter(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintServiceAbility::GetInstance()->StopDiscoverPrinter(); PrintServiceAbility::GetInstance()->StopDiscoverPrinter();
} }
@ -238,7 +228,7 @@ void TestOff(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
PrintServiceAbility::GetInstance()->Off(taskId, type); PrintServiceAbility::GetInstance()->Off(taskId, type);
} }
void TestPrinterCallback(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestCallback(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{ {
PrintDocumentAdapter *printerAdapterPtr = new PrintDocumentAdapter(); PrintDocumentAdapter *printerAdapterPtr = new PrintDocumentAdapter();
sptr <PrintCallback> callback = new(std::nothrow) PrintCallback(printerAdapterPtr); sptr <PrintCallback> callback = new(std::nothrow) PrintCallback(printerAdapterPtr);
@ -250,11 +240,6 @@ void TestPrinterCallback(const uint8_t *data, size_t size, FuzzedDataProvider *d
delete printerAdapterPtr; delete printerAdapterPtr;
printerAdapterPtr = nullptr; printerAdapterPtr = nullptr;
} }
}
void TestExtCallback(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
std::vector <PrintExtensionInfo> printExtensionInfos; std::vector <PrintExtensionInfo> printExtensionInfos;
PrintServiceAbility::GetInstance()->QueryAllExtension(printExtensionInfos); PrintServiceAbility::GetInstance()->QueryAllExtension(printExtensionInfos);
std::vector <std::string> extensionIds; std::vector <std::string> extensionIds;
@ -321,12 +306,8 @@ void TestQueryPrinterCapabilityByUri(const uint8_t *data, size_t size, FuzzedDat
std::string printerUri = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string printerUri = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
std::string printerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string printerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
PrinterCapability printerCaps; PrinterCapability printerCaps;
PrintServiceAbility::GetInstance()->QueryPrinterCapabilityByUri(printerUri, printerId, printerCaps);
}
void TestSetHelper(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintServiceAbility::GetInstance()->SetHelper(nullptr); PrintServiceAbility::GetInstance()->SetHelper(nullptr);
PrintServiceAbility::GetInstance()->QueryPrinterCapabilityByUri(printerUri, printerId, printerCaps);
} }
void TestPrintByAdapter(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestPrintByAdapter(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
@ -506,6 +487,8 @@ void TestIsQueuedJobListEmpty(const uint8_t *data, size_t size, FuzzedDataProvid
void TestSetPrintJobCanceled(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestSetPrintJobCanceled(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{ {
PrintJob printJob; PrintJob printJob;
std::string printerid = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
printJob.SetPrinterId(printerid);
PrintServiceAbility::GetInstance()->SetPrintJobCanceled(printJob); PrintServiceAbility::GetInstance()->SetPrintJobCanceled(printJob);
} }
@ -513,6 +496,7 @@ void TestCancelUserPrintJobs(const uint8_t *data, size_t size, FuzzedDataProvide
{ {
int32_t userId = dataProvider->ConsumeIntegralInRange<int32_t>(0, MAX_SET_NUMBER); int32_t userId = dataProvider->ConsumeIntegralInRange<int32_t>(0, MAX_SET_NUMBER);
PrintServiceAbility::GetInstance()->CancelUserPrintJobs(userId); PrintServiceAbility::GetInstance()->CancelUserPrintJobs(userId);
PrintServiceAbility::GetInstance()->CallStatusBar();
} }
void TestSendExtensionEvent(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestSendExtensionEvent(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
@ -520,15 +504,6 @@ void TestSendExtensionEvent(const uint8_t *data, size_t size, FuzzedDataProvider
std::string extensionId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string extensionId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
std::string extInfo = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string extInfo = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
PrintServiceAbility::GetInstance()->SendExtensionEvent(extensionId, extInfo); PrintServiceAbility::GetInstance()->SendExtensionEvent(extensionId, extInfo);
}
void TestCallStatusBar(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintServiceAbility::GetInstance()->CallStatusBar();
}
void TestUpdatePrintUserMap(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintServiceAbility::GetInstance()->UpdatePrintUserMap(); PrintServiceAbility::GetInstance()->UpdatePrintUserMap();
} }
@ -550,25 +525,7 @@ void TestisEprint(const uint8_t *data, size_t size, FuzzedDataProvider *dataProv
{ {
std::string printerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string printerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
PrintServiceAbility::GetInstance()->isEprint(printerId); PrintServiceAbility::GetInstance()->isEprint(printerId);
}
void TestManualStart(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintServiceAbility::GetInstance()->ManualStart();
}
void TestGetPrintJobOrderId(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintServiceAbility::GetInstance()->GetPrintJobOrderId(); PrintServiceAbility::GetInstance()->GetPrintJobOrderId();
}
void TestOnStop(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintServiceAbility::GetInstance()->OnStop();
}
void TestWritePreferenceToFile(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
{
PrintServiceAbility::GetInstance()->WritePreferenceToFile(); PrintServiceAbility::GetInstance()->WritePreferenceToFile();
} }
@ -585,6 +542,9 @@ void TestBuildPrinterPreference(const uint8_t *data, size_t size, FuzzedDataProv
cap.SetOption(option); cap.SetOption(option);
PrinterPreference printPreference; PrinterPreference printPreference;
PrintServiceAbility::GetInstance()->BuildPrinterPreference(cap, printPreference); PrintServiceAbility::GetInstance()->BuildPrinterPreference(cap, printPreference);
std::string optionRandom = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
cap.SetOption(optionRandom);
PrintServiceAbility::GetInstance()->BuildPrinterPreference(cap, printPreference);
} }
void TestBuildPrinterPreferenceByDefault(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestBuildPrinterPreferenceByDefault(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
@ -598,6 +558,9 @@ void TestBuildPrinterPreferenceByDefault(const uint8_t *data, size_t size, Fuzze
nlohmann::json capOpt = nlohmann::json::parse(optJson); nlohmann::json capOpt = nlohmann::json::parse(optJson);
PreferenceSetting printerDefaultAttr; PreferenceSetting printerDefaultAttr;
PrintServiceAbility::GetInstance()->BuildPrinterPreferenceByDefault(capOpt, printerDefaultAttr); PrintServiceAbility::GetInstance()->BuildPrinterPreferenceByDefault(capOpt, printerDefaultAttr);
std::string capOptRandom = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
capOpt = nlohmann::json::parse(capOptRandom);
PrintServiceAbility::GetInstance()->BuildPrinterPreferenceByDefault(capOpt, printerDefaultAttr);
} }
void TestBuildPrinterPreferenceByOption(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestBuildPrinterPreferenceByOption(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
@ -653,6 +616,9 @@ void TestSendPrintJobEvent(const uint8_t *data, size_t size, FuzzedDataProvider
jobInfo.SetJobState(jobState); jobInfo.SetJobState(jobState);
PrintServiceAbility::GetInstance()->SendPrintJobEvent(jobInfo); PrintServiceAbility::GetInstance()->SendPrintJobEvent(jobInfo);
} }
uint32_t jobState = dataProvider->ConsumeIntegralInRange<uint32_t>(0, MAX_SET_NUMBER);
jobInfo.SetJobState(jobState);
PrintServiceAbility::GetInstance()->SendPrintJobEvent(jobInfo);
} }
void TestStartPrintJobCB(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider) void TestStartPrintJobCB(const uint8_t *data, size_t size, FuzzedDataProvider *dataProvider)
@ -824,12 +790,9 @@ void TestNotPublicFunction(const uint8_t *data, size_t size, FuzzedDataProvider
TestSetPrintJobCanceled(data, size, dataProvider); TestSetPrintJobCanceled(data, size, dataProvider);
TestCancelUserPrintJobs(data, size, dataProvider); TestCancelUserPrintJobs(data, size, dataProvider);
TestSendExtensionEvent(data, size, dataProvider); TestSendExtensionEvent(data, size, dataProvider);
TestCallStatusBar(data, size, dataProvider);
TestUpdatePrintUserMap(data, size, dataProvider);
TestNotifyAdapterJobChanged(data, size, dataProvider); TestNotifyAdapterJobChanged(data, size, dataProvider);
TestRegisterAdapterListener(data, size, dataProvider); TestRegisterAdapterListener(data, size, dataProvider);
TestisEprint(data, size, dataProvider); TestisEprint(data, size, dataProvider);
TestWritePreferenceToFile(data, size, dataProvider);
TestBuildPrinterPreferenceByOption(data, size, dataProvider); TestBuildPrinterPreferenceByOption(data, size, dataProvider);
TestBuildPrinterPreference(data, size, dataProvider); TestBuildPrinterPreference(data, size, dataProvider);
TestBuildPrinterPreferenceByDefault(data, size, dataProvider); TestBuildPrinterPreferenceByDefault(data, size, dataProvider);
@ -848,7 +811,6 @@ void TestNotPublicFunction(const uint8_t *data, size_t size, FuzzedDataProvider
TestSendPrinterChangeEvent(data, size, dataProvider); TestSendPrinterChangeEvent(data, size, dataProvider);
TestCheckJobQueueBlocked(data, size, dataProvider); TestCheckJobQueueBlocked(data, size, dataProvider);
TestGetListeningState(data, size, dataProvider); TestGetListeningState(data, size, dataProvider);
TestSetHelper(data, size, dataProvider);
TestMoreFunction(data, size, dataProvider); TestMoreFunction(data, size, dataProvider);
} }
@ -867,14 +829,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
} }
FuzzedDataProvider dataProvider(data, size); FuzzedDataProvider dataProvider(data, size);
OHOS::Print::TestInitialize(data, size, &dataProvider);
OHOS::Print::TestStartService(data, size, &dataProvider);
OHOS::Print::TestStartPrint(data, size, &dataProvider); OHOS::Print::TestStartPrint(data, size, &dataProvider);
OHOS::Print::TestStopPrint(data, size, &dataProvider); OHOS::Print::TestStopPrint(data, size, &dataProvider);
OHOS::Print::TestConnectPrinter(data, size, &dataProvider); OHOS::Print::TestConnectPrinter(data, size, &dataProvider);
OHOS::Print::TestDisconnectPrinter(data, size, &dataProvider); OHOS::Print::TestDisconnectPrinter(data, size, &dataProvider);
OHOS::Print::TestStartDiscoverPrinter(data, size, &dataProvider); OHOS::Print::TestStartDiscoverPrinter(data, size, &dataProvider);
OHOS::Print::TestStopDiscoverPrinter(data, size, &dataProvider);
OHOS::Print::TestQueryAllExtension(data, size, &dataProvider); OHOS::Print::TestQueryAllExtension(data, size, &dataProvider);
OHOS::Print::TestStartPrintJob(data, size, &dataProvider); OHOS::Print::TestStartPrintJob(data, size, &dataProvider);
OHOS::Print::TestCancelPrintJob(data, size, &dataProvider); OHOS::Print::TestCancelPrintJob(data, size, &dataProvider);
@ -888,8 +847,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
OHOS::Print::TestQueryPrinterCapability(data, size, &dataProvider); OHOS::Print::TestQueryPrinterCapability(data, size, &dataProvider);
OHOS::Print::TestOn(data, size, &dataProvider); OHOS::Print::TestOn(data, size, &dataProvider);
OHOS::Print::TestOff(data, size, &dataProvider); OHOS::Print::TestOff(data, size, &dataProvider);
OHOS::Print::TestPrinterCallback(data, size, &dataProvider); OHOS::Print::TestCallback(data, size, &dataProvider);
OHOS::Print::TestExtCallback(data, size, &dataProvider);
OHOS::Print::TestLoadExtSuccess(data, size, &dataProvider); OHOS::Print::TestLoadExtSuccess(data, size, &dataProvider);
OHOS::Print::TestQueryAllPrintJob(data, size, &dataProvider); OHOS::Print::TestQueryAllPrintJob(data, size, &dataProvider);
OHOS::Print::TestQueryPrintJobById(data, size, &dataProvider); OHOS::Print::TestQueryPrintJobById(data, size, &dataProvider);

View File

@ -21,6 +21,7 @@
#include "scancallbackstub_fuzzer.h" #include "scancallbackstub_fuzzer.h"
namespace OHOS::Scan { namespace OHOS::Scan {
constexpr uint8_t MAX_STRING_LENGTH = 255;
constexpr int MAX_SET_NUMBER = 100; constexpr int MAX_SET_NUMBER = 100;
constexpr size_t FOO_MAX_LEN = 1024; constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4; constexpr size_t U32_AT_SIZE = 4;
@ -93,6 +94,8 @@ void HandleSendSearchMessageFuzzTest(const uint8_t* data, size_t size, FuzzedDat
MessageParcel parcelData; MessageParcel parcelData;
std::string message = parcelData.ReadString(); std::string message = parcelData.ReadString();
parcelData.WriteString(message); parcelData.WriteString(message);
message = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
parcelData.WriteString(message);
ScanCallback callBack(nullptr, nullptr); ScanCallback callBack(nullptr, nullptr);
MessageParcel reply; MessageParcel reply;
callBack.HandleSendSearchMessage(parcelData, reply); callBack.HandleSendSearchMessage(parcelData, reply);

View File

@ -27,14 +27,10 @@ constexpr size_t U32_AT_SIZE = 4;
void DiscoveryCallBack(Scan_ScannerDevice** devices, int32_t deviceCount) {} void DiscoveryCallBack(Scan_ScannerDevice** devices, int32_t deviceCount) {}
void OHScanStartScannerDiscoveryFuzzTest(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
OH_Scan_StartScannerDiscovery(DiscoveryCallBack);
}
void OHScanOpenScannerFuzzTest(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void OHScanOpenScannerFuzzTest(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
OH_Scan_Init(); OH_Scan_Init();
OH_Scan_StartScannerDiscovery(DiscoveryCallBack);
std::string scannerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string scannerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
OH_Scan_OpenScanner(scannerId.c_str()); OH_Scan_OpenScanner(scannerId.c_str());
OH_Scan_CloseScanner(scannerId.c_str()); OH_Scan_CloseScanner(scannerId.c_str());
@ -93,7 +89,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
return 0; return 0;
} }
FuzzedDataProvider dataProvider(data, size); FuzzedDataProvider dataProvider(data, size);
OHOS::Scan::OHScanStartScannerDiscoveryFuzzTest(data, size, &dataProvider);
OHOS::Scan::OHScanOpenScannerFuzzTest(data, size, &dataProvider); OHOS::Scan::OHScanOpenScannerFuzzTest(data, size, &dataProvider);
OHOS::Scan::OHScanGetScannerParameterFuzzTest(data, size, &dataProvider); OHOS::Scan::OHScanGetScannerParameterFuzzTest(data, size, &dataProvider);
OHOS::Scan::OHScanSetScannerParameterFuzzTest(data, size, &dataProvider); OHOS::Scan::OHScanSetScannerParameterFuzzTest(data, size, &dataProvider);

View File

@ -133,6 +133,8 @@ void TestSetOptionConstraintRange(const uint8_t* data, size_t size, FuzzedDataPr
ScanRange optionConstraintRange; ScanRange optionConstraintRange;
scanOptDes.SetOptionConstraintRange(optionConstraintRange); scanOptDes.SetOptionConstraintRange(optionConstraintRange);
scanOptDes.GetOptionConstraintRange(optionConstraintRange); scanOptDes.GetOptionConstraintRange(optionConstraintRange);
std::string optionName = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
scanOptDes.SetOptionName(optionName);
} }
void TestScanOptionDescriptor(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestScanOptionDescriptor(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)

View File

@ -26,71 +26,47 @@ namespace Scan {
void TestOnStartDiscoverService(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestOnStartDiscoverService(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
ScanMdnsService::GetInstance().SetServiceType("_scanner._tcp"); std::string serviceName = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
ScanMdnsService::GetInstance().SetServiceType(serviceName.c_str());
ScanMdnsService::GetInstance().onStartDiscoverService(); ScanMdnsService::GetInstance().onStartDiscoverService();
ScanMdnsService::GetInstance().onStopDiscoverService();
} }
void TestSetServiceInfo(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestSetService(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
MDnsServiceInfo info; MDnsServiceInfo info;
ScanMdnsService::GetInstance().SetServiceInfo(info); ScanMdnsService::GetInstance().SetServiceInfo(info);
} sptr<ScanMDnsResolveObserver> resolveObserve;
ScanMdnsService::GetInstance().SetMDnsResolveCallBack(resolveObserve);
void TestSetMDnsResolveCallBack(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) sptr<ScanMDnsDiscoveryObserver> discoveryObserve;
{ ScanMdnsService::GetInstance().SetMDnsDiscoveryCallBack(discoveryObserve);
sptr<ScanMDnsResolveObserver> cb;
ScanMdnsService::GetInstance().SetMDnsResolveCallBack(cb);
}
void TestSetMDnsDiscoveryCallBack(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
sptr<ScanMDnsDiscoveryObserver> cb;
ScanMdnsService::GetInstance().SetMDnsDiscoveryCallBack(cb);
ScanMdnsService::GetInstance().onStartDiscoverService(); ScanMdnsService::GetInstance().onStartDiscoverService();
}
void TestSetServiceType(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
std::string stype = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string stype = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
ScanMdnsService::GetInstance().SetServiceType(stype); ScanMdnsService::GetInstance().SetServiceType(stype);
}
void TestGetMDnsResolveCallBack(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
ScanMdnsService::GetInstance().GetMDnsResolveCallBack(); ScanMdnsService::GetInstance().GetMDnsResolveCallBack();
}
void TestGetMDnsDiscoveryCallBack(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
ScanMdnsService::GetInstance().GetMDnsDiscoveryCallBack(); ScanMdnsService::GetInstance().GetMDnsDiscoveryCallBack();
}
void TestGetServiceInfo(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
ScanMdnsService::GetInstance().GetServiceInfo(); ScanMdnsService::GetInstance().GetServiceInfo();
} }
void TestGetServiceAttribute(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestGetServiceAttribute(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
MDnsServiceInfo serviceInfo; MDnsServiceInfo serviceInfo;
serviceInfo.name = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
std::string keyStr = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string keyStr = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
ScanMdnsService::GetInstance().GetServiceAttribute(serviceInfo, keyStr); ScanMdnsService::GetInstance().GetServiceAttribute(serviceInfo, keyStr);
} }
void TestonStopDiscoverService(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
ScanMdnsService::GetInstance().onStopDiscoverService();
}
void TestonResolveService(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestonResolveService(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
MDnsServiceInfo serviceInfo; MDnsServiceInfo serviceInfo;
serviceInfo.name = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
ScanMdnsService::GetInstance().onResolveService(serviceInfo); ScanMdnsService::GetInstance().onResolveService(serviceInfo);
} }
void TestToMDnsScaner(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestToMDnsScaner(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
MDnsServiceInfo serviceInfo; MDnsServiceInfo serviceInfo;
serviceInfo.name = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
ScanMdnsService::GetInstance().ToMDnsScaner(serviceInfo); ScanMdnsService::GetInstance().ToMDnsScaner(serviceInfo);
} }
@ -133,15 +109,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
} }
FuzzedDataProvider dataProvider(data, size); FuzzedDataProvider dataProvider(data, size);
OHOS::Scan::TestOnStartDiscoverService(data, size, &dataProvider); OHOS::Scan::TestOnStartDiscoverService(data, size, &dataProvider);
OHOS::Scan::TestSetServiceInfo(data, size, &dataProvider);
OHOS::Scan::TestSetMDnsResolveCallBack(data, size, &dataProvider);
OHOS::Scan::TestSetMDnsDiscoveryCallBack(data, size, &dataProvider);
OHOS::Scan::TestSetServiceType(data, size, &dataProvider);
OHOS::Scan::TestGetMDnsResolveCallBack(data, size, &dataProvider);
OHOS::Scan::TestGetMDnsDiscoveryCallBack(data, size, &dataProvider);
OHOS::Scan::TestGetServiceInfo(data, size, &dataProvider);
OHOS::Scan::TestGetServiceAttribute(data, size, &dataProvider); OHOS::Scan::TestGetServiceAttribute(data, size, &dataProvider);
OHOS::Scan::TestonStopDiscoverService(data, size, &dataProvider);
OHOS::Scan::TestonResolveService(data, size, &dataProvider); OHOS::Scan::TestonResolveService(data, size, &dataProvider);
OHOS::Scan::TestToMDnsScaner(data, size, &dataProvider); OHOS::Scan::TestToMDnsScaner(data, size, &dataProvider);
OHOS::Scan::TestHandleServiceFound(data, size, &dataProvider); OHOS::Scan::TestHandleServiceFound(data, size, &dataProvider);

View File

@ -74,11 +74,6 @@ ohos_fuzztest("ScanServiceAbilityFuzzTest") {
"usb_manager:usbsrv_client", "usb_manager:usbsrv_client",
] ]
if (sane_enable) {
external_deps += [ "backends:third_sane" ]
cflags_cc = [ "-DSANE_ENABLE" ]
}
if (security_guard_enabled) { if (security_guard_enabled) {
external_deps += [ external_deps += [
"security_guard:libsg_collect_sdk", "security_guard:libsg_collect_sdk",

View File

@ -33,10 +33,6 @@ namespace Scan {
{ {
int32_t scanVersion = dataProvider->ConsumeIntegralInRange<int32_t>(0, MAX_SET_NUMBER); int32_t scanVersion = dataProvider->ConsumeIntegralInRange<int32_t>(0, MAX_SET_NUMBER);
ScanServiceAbility::GetInstance()->InitScan(scanVersion); ScanServiceAbility::GetInstance()->InitScan(scanVersion);
}
void TestExitScan(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
ScanServiceAbility::GetInstance()->ExitScan(); ScanServiceAbility::GetInstance()->ExitScan();
} }
@ -82,16 +78,6 @@ namespace Scan {
ScanServiceAbility::GetInstance()->GetScanOptionDesc(scannerId, optionIndex, desc); ScanServiceAbility::GetInstance()->GetScanOptionDesc(scannerId, optionIndex, desc);
} }
void TestOpScanOptionValue(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestGetScanParameters(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestStartScan(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestStartScan(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
int32_t scanVersion = dataProvider->ConsumeIntegralInRange<int32_t>(0, MAX_SET_NUMBER); int32_t scanVersion = dataProvider->ConsumeIntegralInRange<int32_t>(0, MAX_SET_NUMBER);
@ -168,26 +154,6 @@ namespace Scan {
ScanServiceAbility::GetInstance()->GetScannerState(scannerState); ScanServiceAbility::GetInstance()->GetScannerState(scannerState);
} }
void TestGetScanProgress(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestActionSetAuto(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestActionGetValue(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestActionSetValue(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestSelectScanOptionDesc(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestSelectScanOptionDesc(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
SANE_Option_Descriptor optionDesc; SANE_Option_Descriptor optionDesc;
@ -212,11 +178,6 @@ namespace Scan {
ScanServiceAbility::GetInstance()->SelectScanOptionDesc(optionDescPtr, desc); ScanServiceAbility::GetInstance()->SelectScanOptionDesc(optionDescPtr, desc);
} }
void TestDoScanTask(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestOnStartScan(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestOnStartScan(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
std::string scannerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string scannerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
@ -308,40 +269,16 @@ namespace Scan {
ScanServiceAbility::GetInstance()->SetScannerSerialNumber(usbInfo); ScanServiceAbility::GetInstance()->SetScannerSerialNumber(usbInfo);
} }
void TestSaneGetScanner(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
ScanServiceAbility::GetInstance()->SaneGetScanner();
}
void TestOnStart(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
ScanServiceAbility::GetInstance()->OnStart();
}
void TestOnStop(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
ScanServiceAbility::GetInstance()->OnStop();
}
void TestServiceInit(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
ScanServiceAbility::GetInstance()->ServiceInit();
}
void TestInitServiceHandler(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
ScanServiceAbility::GetInstance()->InitServiceHandler();
}
void TestManualStart(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
ScanServiceAbility::GetInstance()->ManualStart();
}
void TestReInitScan(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestReInitScan(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
ScanServiceAbility::GetInstance()->ServiceInit();
ScanServiceAbility::GetInstance()->InitServiceHandler();
ScanServiceAbility::GetInstance()->OnStart();
ScanServiceAbility::GetInstance()->OnStop();
ScanServiceAbility::GetInstance()->ManualStart();
int32_t scanVersion = dataProvider->ConsumeIntegralInRange<int32_t>(0, MAX_SET_NUMBER); int32_t scanVersion = dataProvider->ConsumeIntegralInRange<int32_t>(0, MAX_SET_NUMBER);
ScanServiceAbility::GetInstance()->ReInitScan(scanVersion); ScanServiceAbility::GetInstance()->ReInitScan(scanVersion);
ScanServiceAbility::GetInstance()->SaneGetScanner();
} }
void TestCheckPermission(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestCheckPermission(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
@ -361,9 +298,9 @@ namespace Scan {
{ {
ScanOptionDescriptor desc; ScanOptionDescriptor desc;
SANE_Option_Descriptor optionDesc; SANE_Option_Descriptor optionDesc;
optionDesc.name = ""; optionDesc.name = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
optionDesc.title = ""; optionDesc.title = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
optionDesc.desc = ""; optionDesc.desc = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
ScanServiceAbility::GetInstance()->SetScanOptionDescriptor(desc, &optionDesc); ScanServiceAbility::GetInstance()->SetScanOptionDescriptor(desc, &optionDesc);
} }
@ -373,26 +310,6 @@ namespace Scan {
ScanServiceAbility::GetInstance()->GetScanHandle(scannerId); ScanServiceAbility::GetInstance()->GetScanHandle(scannerId);
} }
void TestWriteJpegHeader(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestGeneratePicture(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestGetPicFrame(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestWritePicData(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestGeneratePictureBatch(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestGeneratePictureBatch(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
int32_t status = E_SCAN_NONE; int32_t status = E_SCAN_NONE;
@ -403,11 +320,6 @@ namespace Scan {
ScanServiceAbility::GetInstance()->GeneratePictureSingle(scannerId, file_name, output_file, status, scanProPtr); ScanServiceAbility::GetInstance()->GeneratePictureSingle(scannerId, file_name, output_file, status, scanProPtr);
} }
void TestGeneratePictureSingle(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
return;
}
void TestAddFoundUsbScanner(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestAddFoundUsbScanner(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
ScanDeviceInfo info; ScanDeviceInfo info;
@ -472,6 +384,8 @@ namespace Scan {
void TestGetAddedScanner(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestGetAddedScanner(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
ScanDeviceInfo addedScanner; ScanDeviceInfo addedScanner;
std::string newDeviceId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
addedScanner.SetDeviceId(newDeviceId);
std::vector<ScanDeviceInfo> allAddedScanner; std::vector<ScanDeviceInfo> allAddedScanner;
allAddedScanner.push_back(addedScanner); allAddedScanner.push_back(addedScanner);
ScanServiceAbility::GetInstance()->GetAddedScanner(allAddedScanner); ScanServiceAbility::GetInstance()->GetAddedScanner(allAddedScanner);
@ -482,22 +396,12 @@ namespace Scan {
if (dataProvider == nullptr) { if (dataProvider == nullptr) {
return; return;
} }
OHOS::Scan::TestOnStart(data, size, dataProvider);
OHOS::Scan::TestOnStop(data, size, dataProvider);
OHOS::Scan::TestServiceInit(data, size, dataProvider);
OHOS::Scan::TestInitServiceHandler(data, size, dataProvider);
OHOS::Scan::TestManualStart(data, size, dataProvider);
OHOS::Scan::TestReInitScan(data, size, dataProvider); OHOS::Scan::TestReInitScan(data, size, dataProvider);
OHOS::Scan::TestCheckPermission(data, size, dataProvider); OHOS::Scan::TestCheckPermission(data, size, dataProvider);
OHOS::Scan::TestSendGetFrameResEvent(data, size, dataProvider); OHOS::Scan::TestSendGetFrameResEvent(data, size, dataProvider);
OHOS::Scan::TestSetScanOptionDescriptor(data, size, dataProvider); OHOS::Scan::TestSetScanOptionDescriptor(data, size, dataProvider);
OHOS::Scan::TestGetScanHandle(data, size, dataProvider); OHOS::Scan::TestGetScanHandle(data, size, dataProvider);
OHOS::Scan::TestWriteJpegHeader(data, size, dataProvider);
OHOS::Scan::TestGeneratePicture(data, size, dataProvider);
OHOS::Scan::TestGetPicFrame(data, size, dataProvider);
OHOS::Scan::TestWritePicData(data, size, dataProvider);
OHOS::Scan::TestGeneratePictureBatch(data, size, dataProvider); OHOS::Scan::TestGeneratePictureBatch(data, size, dataProvider);
OHOS::Scan::TestGeneratePictureSingle(data, size, dataProvider);
OHOS::Scan::TestAddFoundUsbScanner(data, size, dataProvider); OHOS::Scan::TestAddFoundUsbScanner(data, size, dataProvider);
OHOS::Scan::TestAddFoundTcpScanner(data, size, dataProvider); OHOS::Scan::TestAddFoundTcpScanner(data, size, dataProvider);
OHOS::Scan::TestSetScannerInfo(data, size, dataProvider); OHOS::Scan::TestSetScannerInfo(data, size, dataProvider);
@ -514,14 +418,11 @@ namespace Scan {
return; return;
} }
OHOS::Scan::TestInitScan(data, size, dataProvider); OHOS::Scan::TestInitScan(data, size, dataProvider);
OHOS::Scan::TestExitScan(data, size, dataProvider);
OHOS::Scan::TestGetScannerList(data, size, dataProvider); OHOS::Scan::TestGetScannerList(data, size, dataProvider);
OHOS::Scan::TestStopDiscover(data, size, dataProvider); OHOS::Scan::TestStopDiscover(data, size, dataProvider);
OHOS::Scan::TestOpenScanner(data, size, dataProvider); OHOS::Scan::TestOpenScanner(data, size, dataProvider);
OHOS::Scan::TestCloseScanner(data, size, dataProvider); OHOS::Scan::TestCloseScanner(data, size, dataProvider);
OHOS::Scan::TestGetScanOptionDesc(data, size, dataProvider); OHOS::Scan::TestGetScanOptionDesc(data, size, dataProvider);
OHOS::Scan::TestOpScanOptionValue(data, size, dataProvider);
OHOS::Scan::TestGetScanParameters(data, size, dataProvider);
OHOS::Scan::TestStartScan(data, size, dataProvider); OHOS::Scan::TestStartScan(data, size, dataProvider);
OHOS::Scan::TestGetSingleFrameFD(data, size, dataProvider); OHOS::Scan::TestGetSingleFrameFD(data, size, dataProvider);
OHOS::Scan::TestCancelScan(data, size, dataProvider); OHOS::Scan::TestCancelScan(data, size, dataProvider);
@ -530,12 +431,7 @@ namespace Scan {
OHOS::Scan::TestOn(data, size, dataProvider); OHOS::Scan::TestOn(data, size, dataProvider);
OHOS::Scan::TestOff(data, size, dataProvider); OHOS::Scan::TestOff(data, size, dataProvider);
OHOS::Scan::TestGetScannerState(data, size, dataProvider); OHOS::Scan::TestGetScannerState(data, size, dataProvider);
OHOS::Scan::TestGetScanProgress(data, size, dataProvider);
OHOS::Scan::TestActionSetAuto(data, size, dataProvider);
OHOS::Scan::TestActionGetValue(data, size, dataProvider);
OHOS::Scan::TestActionSetValue(data, size, dataProvider);
OHOS::Scan::TestSelectScanOptionDesc(data, size, dataProvider); OHOS::Scan::TestSelectScanOptionDesc(data, size, dataProvider);
OHOS::Scan::TestDoScanTask(data, size, dataProvider);
OHOS::Scan::TestOnStartScan(data, size, dataProvider); OHOS::Scan::TestOnStartScan(data, size, dataProvider);
OHOS::Scan::TestStartScanTask(data, size, dataProvider); OHOS::Scan::TestStartScanTask(data, size, dataProvider);
OHOS::Scan::TestSendDeviceInfoTCP(data, size, dataProvider); OHOS::Scan::TestSendDeviceInfoTCP(data, size, dataProvider);
@ -545,7 +441,6 @@ namespace Scan {
OHOS::Scan::TestUpdateUsbScannerId(data, size, dataProvider); OHOS::Scan::TestUpdateUsbScannerId(data, size, dataProvider);
OHOS::Scan::TestSendInitEvent(data, size, dataProvider); OHOS::Scan::TestSendInitEvent(data, size, dataProvider);
OHOS::Scan::TestSetScannerSerialNumber(data, size, dataProvider); OHOS::Scan::TestSetScannerSerialNumber(data, size, dataProvider);
OHOS::Scan::TestSaneGetScanner(data, size, dataProvider);
} }
#endif #endif
@ -567,14 +462,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::Scan::TestPublicFunction(data, size, &dataProvider); OHOS::Scan::TestPublicFunction(data, size, &dataProvider);
OHOS::Scan::ScanServiceAbilityMock::MockPermission(); OHOS::Scan::ScanServiceAbilityMock::MockPermission();
OHOS::Scan::TestInitScan(data, size, &dataProvider); OHOS::Scan::TestInitScan(data, size, &dataProvider);
OHOS::Scan::TestExitScan(data, size, &dataProvider);
// OHOS::Scan::TestGetScannerList(data, size, &dataProvider); // OHOS::Scan::TestGetScannerList(data, size, &dataProvider);
// OHOS::Scan::TestStopDiscover(data, size, dataProvider); // OHOS::Scan::TestStopDiscover(data, size, dataProvider);
OHOS::Scan::TestOpenScanner(data, size, &dataProvider); OHOS::Scan::TestOpenScanner(data, size, &dataProvider);
OHOS::Scan::TestCloseScanner(data, size, &dataProvider); OHOS::Scan::TestCloseScanner(data, size, &dataProvider);
OHOS::Scan::TestGetScanOptionDesc(data, size, &dataProvider); OHOS::Scan::TestGetScanOptionDesc(data, size, &dataProvider);
OHOS::Scan::TestOpScanOptionValue(data, size, &dataProvider);
OHOS::Scan::TestGetScanParameters(data, size, &dataProvider);
OHOS::Scan::TestStartScan(data, size, &dataProvider); OHOS::Scan::TestStartScan(data, size, &dataProvider);
OHOS::Scan::TestGetSingleFrameFD(data, size, &dataProvider); OHOS::Scan::TestGetSingleFrameFD(data, size, &dataProvider);
OHOS::Scan::TestCancelScan(data, size, &dataProvider); OHOS::Scan::TestCancelScan(data, size, &dataProvider);
@ -583,12 +475,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::Scan::TestOn(data, size, &dataProvider); OHOS::Scan::TestOn(data, size, &dataProvider);
OHOS::Scan::TestOff(data, size, &dataProvider); OHOS::Scan::TestOff(data, size, &dataProvider);
OHOS::Scan::TestGetScannerState(data, size, &dataProvider); OHOS::Scan::TestGetScannerState(data, size, &dataProvider);
OHOS::Scan::TestGetScanProgress(data, size, &dataProvider);
OHOS::Scan::TestActionSetAuto(data, size, &dataProvider);
OHOS::Scan::TestActionGetValue(data, size, &dataProvider);
OHOS::Scan::TestActionSetValue(data, size, &dataProvider);
OHOS::Scan::TestSelectScanOptionDesc(data, size, &dataProvider); OHOS::Scan::TestSelectScanOptionDesc(data, size, &dataProvider);
OHOS::Scan::TestDoScanTask(data, size, &dataProvider);
OHOS::Scan::TestOnStartScan(data, size, &dataProvider); OHOS::Scan::TestOnStartScan(data, size, &dataProvider);
OHOS::Scan::TestStartScanTask(data, size, &dataProvider); OHOS::Scan::TestStartScanTask(data, size, &dataProvider);
OHOS::Scan::TestSendDeviceInfoTCP(data, size, &dataProvider); OHOS::Scan::TestSendDeviceInfoTCP(data, size, &dataProvider);
@ -599,7 +486,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::Scan::TestSendInitEvent(data, size, &dataProvider); OHOS::Scan::TestSendInitEvent(data, size, &dataProvider);
// OHOS::Scan::TestSendDeviceSearchEnd(data, size, &dataProvider); // OHOS::Scan::TestSendDeviceSearchEnd(data, size, &dataProvider);
OHOS::Scan::TestSetScannerSerialNumber(data, size, &dataProvider); OHOS::Scan::TestSetScannerSerialNumber(data, size, &dataProvider);
OHOS::Scan::TestSaneGetScanner(data, size, &dataProvider);
OHOS::Scan::TestNotPublicFunction(data, size, &dataProvider); OHOS::Scan::TestNotPublicFunction(data, size, &dataProvider);
#endif #endif
return 0; return 0;

View File

@ -32,54 +32,6 @@ namespace Scan {
return true; return true;
} }
bool TestOnInitScan(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
MessageParcel datas;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(datas)) {
return false;
}
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_INIT_SCAN, datas, reply, option);
return true;
}
bool TestOnExitScan(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
MessageParcel datas;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(datas)) {
return false;
}
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_EXIT_SCAN, datas, reply, option);
return true;
}
bool TestOnGetScannerList(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
MessageParcel datas;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(datas)) {
return false;
}
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_GET_SCANNER_LIST, datas, reply, option);
return true;
}
bool TestOnStopDiscover(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
MessageParcel datas;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(datas)) {
return false;
}
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_STOP_DISCOVER, datas, reply, option);
return true;
}
bool TestOnOpenScanner(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) bool TestOnOpenScanner(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
MessageParcel datas; MessageParcel datas;
@ -90,7 +42,11 @@ namespace Scan {
} }
std::string scannerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string scannerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
datas.WriteString(scannerId); datas.WriteString(scannerId);
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_GET_SCANNER_LIST, datas, reply, option);
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_STOP_DISCOVER, datas, reply, option);
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_INIT_SCAN, datas, reply, option);
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_OPEN_SCANNER, datas, reply, option); ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_OPEN_SCANNER, datas, reply, option);
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_EXIT_SCAN, datas, reply, option);
return true; return true;
} }
@ -232,18 +188,6 @@ namespace Scan {
return true; return true;
} }
bool TestOnGetScannerState(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
MessageParcel datas;
MessageParcel reply;
MessageOption option;
if (!WriteInterfaceToken(datas)) {
return false;
}
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_GET_SCANNER_STATE, datas, reply, option);
return true;
}
bool TestOnGetScanProgress(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) bool TestOnGetScanProgress(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
MessageParcel datas; MessageParcel datas;
@ -255,6 +199,7 @@ namespace Scan {
std::string scannerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string scannerId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
datas.WriteString(scannerId); datas.WriteString(scannerId);
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_GET_SCAN_PROGRESS, datas, reply, option); ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_GET_SCAN_PROGRESS, datas, reply, option);
ScanServiceAbility::GetInstance()->OnRemoteRequest(CMD_GET_SCANNER_STATE, datas, reply, option);
return true; return true;
} }
@ -302,10 +247,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
return 0; return 0;
} }
FuzzedDataProvider dataProvider(data, size); FuzzedDataProvider dataProvider(data, size);
OHOS::Scan::TestOnInitScan(data, size, &dataProvider);
OHOS::Scan::TestOnExitScan(data, size, &dataProvider);
OHOS::Scan::TestOnGetScannerList(data, size, &dataProvider);
OHOS::Scan::TestOnStopDiscover(data, size, &dataProvider);
OHOS::Scan::TestOnOpenScanner(data, size, &dataProvider); OHOS::Scan::TestOnOpenScanner(data, size, &dataProvider);
OHOS::Scan::TestOnCloseScanner(data, size, &dataProvider); OHOS::Scan::TestOnCloseScanner(data, size, &dataProvider);
OHOS::Scan::TestOnGetScanOptionDesc(data, size, &dataProvider); OHOS::Scan::TestOnGetScanOptionDesc(data, size, &dataProvider);
@ -316,7 +257,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::Scan::TestOnCancelScan(data, size, &dataProvider); OHOS::Scan::TestOnCancelScan(data, size, &dataProvider);
OHOS::Scan::TestOnSetScanIOMode(data, size, &dataProvider); OHOS::Scan::TestOnSetScanIOMode(data, size, &dataProvider);
OHOS::Scan::TestOnGetScanSelectFd(data, size, &dataProvider); OHOS::Scan::TestOnGetScanSelectFd(data, size, &dataProvider);
OHOS::Scan::TestOnGetScannerState(data, size, &dataProvider);
OHOS::Scan::TestOnGetScanProgress(data, size, &dataProvider); OHOS::Scan::TestOnGetScanProgress(data, size, &dataProvider);
OHOS::Scan::TestOnEventOn(data, size, &dataProvider); OHOS::Scan::TestOnEventOn(data, size, &dataProvider);
OHOS::Scan::TestOnEventOff(data, size, &dataProvider); OHOS::Scan::TestOnEventOff(data, size, &dataProvider);

View File

@ -26,19 +26,10 @@ namespace Scan {
constexpr size_t FOO_MAX_LEN = 1024; constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4; constexpr size_t U32_AT_SIZE = 4;
void TestRefreshUsbDevice(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
DelayedSingleton<ScanUsbManager>::GetInstance()->RefreshUsbDevice();
}
void TestInit(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
DelayedSingleton<ScanUsbManager>::GetInstance()->Init();
}
void TestDealUsbDevStatusChange(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) void TestDealUsbDevStatusChange(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{ {
DelayedSingleton<ScanUsbManager>::GetInstance()->Init();
DelayedSingleton<ScanUsbManager>::GetInstance()->RefreshUsbDevice();
std::string devStr = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); std::string devStr = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
bool isAttach = dataProvider->ConsumeBool(); bool isAttach = dataProvider->ConsumeBool();
std::string devStrOne = "2-3"; std::string devStrOne = "2-3";
@ -46,10 +37,6 @@ namespace Scan {
DelayedSingleton<ScanUsbManager>::GetInstance()->DealUsbDevStatusChange(devStrOne, true); DelayedSingleton<ScanUsbManager>::GetInstance()->DealUsbDevStatusChange(devStrOne, true);
ScanServiceAbility::usbSnMap[devStrOne] = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); ScanServiceAbility::usbSnMap[devStrOne] = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH);
DelayedSingleton<ScanUsbManager>::GetInstance()->DealUsbDevStatusChange(devStrOne, false); DelayedSingleton<ScanUsbManager>::GetInstance()->DealUsbDevStatusChange(devStrOne, false);
}
void TestGetDeviceSerialNumber(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider)
{
USB::USBDevicePipe usbDevicePipe; USB::USBDevicePipe usbDevicePipe;
DelayedSingleton<ScanUsbManager>::GetInstance()->GetDeviceSerialNumber(usbDevicePipe); DelayedSingleton<ScanUsbManager>::GetInstance()->GetDeviceSerialNumber(usbDevicePipe);
} }
@ -109,10 +96,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
return 0; return 0;
} }
FuzzedDataProvider dataProvider(data, size); FuzzedDataProvider dataProvider(data, size);
OHOS::Scan::TestRefreshUsbDevice(data, size, &dataProvider);
OHOS::Scan::TestInit(data, size, &dataProvider);
OHOS::Scan::TestDealUsbDevStatusChange(data, size, &dataProvider); OHOS::Scan::TestDealUsbDevStatusChange(data, size, &dataProvider);
OHOS::Scan::TestGetDeviceSerialNumber(data, size, &dataProvider);
OHOS::Scan::TestUsbUpdateUsbScannerId(data, size, &dataProvider); OHOS::Scan::TestUsbUpdateUsbScannerId(data, size, &dataProvider);
OHOS::Scan::TestUsbDisConnectUsbScanner(data, size, &dataProvider); OHOS::Scan::TestUsbDisConnectUsbScanner(data, size, &dataProvider);

View File

@ -136,11 +136,6 @@ ohos_unittest("scan_service_test") {
"//third_party/zlib:libz", "//third_party/zlib:libz",
] ]
if (sane_enable) {
external_deps += [ "backends:third_sane" ]
cflags_cc = [ "-DSANE_ENABLE" ]
}
external_deps = [ external_deps = [
"ability_base:base", "ability_base:base",
"ability_base:want", "ability_base:want",