• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "storagetotalstatusservice_fuzzer.h"
16 #include "storage/storage_total_status_service.h"
17 #include "storage_service_log.h"
18 #include "storage_service_errno.h"
19 namespace OHOS {
20 namespace StorageManager {
StorageTotalStatusServiceFuzzTest(const uint8_t * data,size_t size)21 bool StorageTotalStatusServiceFuzzTest(const uint8_t *data, size_t size)
22 {
23     if ((data == nullptr) || (size <= 0)) {
24         return false;
25     }
26     std::shared_ptr<StorageTotalStatusService> service = DelayedSingleton<StorageTotalStatusService>::GetInstance();
27     int64_t totalSize;
28     int64_t systemSize;
29     int64_t freeSize;
30     int32_t result = service->GetTotalSize(totalSize);
31     if (result != E_OK) {
32         LOGI("Storage total status service fuzz test of interface StorageTotalStatusService::GetTotalSize failed!");
33         return false;
34     }
35     result = service->GetSystemSize(systemSize);
36     if (result != E_OK) {
37         LOGI("Storage total status service fuzz test of interface StorageTotalStatusService::GetSystemSize failed!");
38         return false;
39     }
40     result = service->GetFreeSize(freeSize);
41     if (result != E_OK) {
42         LOGI("Storage total status service fuzz test of interface StorageTotalStatusService::GetFreeSize failed!");
43         return false;
44     }
45     // You can add other interfaces of class StorageTotalStatusService here.
46 
47     LOGE("Storage total status service fuzz test of interface StorageTotalStatusService: success!");
48     return true;
49 }
50 } // namespace StorageManager
51 } // namespace OHOS
52 
53 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)54 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
55 {
56     /* Run your code on data */
57     OHOS::StorageManager::StorageTotalStatusServiceFuzzTest(data, size);
58     return 0;
59 }
60