mirror of
https://gitee.com/openharmony/filemanagement_storage_service
synced 2024-11-23 15:09:48 +00:00
!324 添加storage_service的FuzzerTest测试用例模板
Merge pull request !324 from 张凯祥/master
This commit is contained in:
commit
88ecd87435
@ -90,7 +90,8 @@
|
||||
"//foundation/filemanagement/storage_service/services/storage_manager/user/test:storage_manager_user_test",
|
||||
"//foundation/filemanagement/storage_service/services/storage_manager/volume/test:storage_manager_volume_test",
|
||||
"//foundation/filemanagement/storage_service/services/storage_manager/disk/test:storage_manager_disk_test",
|
||||
"//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/test:storage_manager_innerkits_test"
|
||||
"//foundation/filemanagement/storage_service/services/storage_manager/innerkits_impl/test:storage_manager_innerkits_test",
|
||||
"//foundation/filemanagement/storage_service/test/fuzztest:storage_service_fuzztest"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
20
test/fuzztest/BUILD.gn
Normal file
20
test/fuzztest/BUILD.gn
Normal file
@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
group("storage_service_fuzztest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
# deps file
|
||||
"//foundation/filemanagement/storage_service/test/fuzztest/storagetotalstatusservice_fuzzer:StorageTotalStatusServiceFuzzTest",
|
||||
]
|
||||
}
|
46
test/fuzztest/storagetotalstatusservice_fuzzer/BUILD.gn
Normal file
46
test/fuzztest/storagetotalstatusservice_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,46 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
ohos_fuzztest("StorageTotalStatusServiceFuzzTest") {
|
||||
module_out_path = "filemanagement/storage_service"
|
||||
fuzz_config_file = "//foundation/filemanagement/storage_service/test/fuzztest/storagetotalstatusservice_fuzzer"
|
||||
include_dirs = [
|
||||
"//foundation/filemanagement/storage_service/services/common/include",
|
||||
"//foundation/filemanagement/storage_service/services/storage_manager/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
]
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [
|
||||
"//foundation/filemanagement/storage_service/services/storage_manager/storage/src/storage_total_status_service.cpp",
|
||||
"//foundation/filemanagement/storage_service/test/fuzztest/storagetotalstatusservice_fuzzer/storagetotalstatusservice_fuzzer.cpp",
|
||||
]
|
||||
defines = [ "STORAGE_LOG_TAG = \"storage_service\"" ]
|
||||
deps = [
|
||||
"//foundation/bundlemanager/bundle_framework/services/bundlemgr:libbms",
|
||||
]
|
||||
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = [ ":StorageTotalStatusServiceFuzzTest" ]
|
||||
}
|
16
test/fuzztest/storagetotalstatusservice_fuzzer/corpus/init
Normal file
16
test/fuzztest/storagetotalstatusservice_fuzzer/corpus/init
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
FUZZ
|
25
test/fuzztest/storagetotalstatusservice_fuzzer/project.xml
Normal file
25
test/fuzztest/storagetotalstatusservice_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "storagetotalstatusservice_fuzzer.h"
|
||||
#include "storage/storage_total_status_service.h"
|
||||
#include "storage_service_log.h"
|
||||
namespace OHOS {
|
||||
namespace StorageManager {
|
||||
bool StorageTotalStatusServiceFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size <= 0)) {
|
||||
return false;
|
||||
}
|
||||
std::shared_ptr<StorageTotalStatusService> service = DelayedSingleton<StorageTotalStatusService>::GetInstance();
|
||||
int64_t result = service->GetTotalSize();
|
||||
// You can add other interfaces of class StorageTotalStatusService here.
|
||||
if (result >= 0) {
|
||||
LOGI("Storage total status service fuzz test of interface StorageTotalStatusService::GetTotalSize success!");
|
||||
return true;
|
||||
}
|
||||
LOGE("Storage total status service fuzz test of interface StorageTotalStatusService::GetTotalSize failed!");
|
||||
return false;
|
||||
}
|
||||
} // namespace StorageManager
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::StorageManager::StorageTotalStatusServiceFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef STORAGETOTALSTATUSSERVICE_FUZZER_H
|
||||
#define STORAGETOTALSTATUSSERVICE_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "storagetotalstatusservice_fuzzer"
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user