mirror of
https://gitee.com/openharmony/distributeddatamgr_datamgr_service
synced 2024-11-23 06:50:35 +00:00
kvfuzz迁出
Signed-off-by: htt1997 <hutao105@huawei.com>
This commit is contained in:
parent
a368450041
commit
9419bba038
6
BUILD.gn
6
BUILD.gn
@ -30,13 +30,7 @@ group("fuzztest") {
|
||||
deps = []
|
||||
deps += [
|
||||
"test/fuzztest/autolaunch_fuzzer:fuzztest",
|
||||
"test/fuzztest/blob_fuzzer:fuzztest",
|
||||
"test/fuzztest/devicekvstore_fuzzer:fuzztest",
|
||||
"test/fuzztest/distributedkvdatamanager_fuzzer:fuzztest",
|
||||
"test/fuzztest/kvstoredisksize_fuzzer:fuzztest",
|
||||
"test/fuzztest/singlekvstore_fuzzer:fuzztest",
|
||||
"test/fuzztest/taskscheduler_fuzzer:fuzztest",
|
||||
"test/fuzztest/typesutil_fuzzer:fuzztest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
||||
|
@ -75,6 +75,8 @@ ohos_unittest("KvStoreDataServiceTest") {
|
||||
"../src/session_manager/session_manager.cpp",
|
||||
"../src/session_manager/upgrade_manager.cpp",
|
||||
"unittest/kvstore_data_service_test.cpp",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src/ikvstore_data_service.cpp",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src/kvstore_client_death_observer.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
@ -99,6 +99,9 @@ ohos_shared_library("distributeddatasvc") {
|
||||
"rdb/rdb_service_stub.cpp",
|
||||
"rdb/rdb_store_observer_impl.cpp",
|
||||
"rdb/rdb_syncer.cpp",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src/change_notification.cpp",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src/data_query.cpp",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/kvdb/src/kv_types_util.cpp",
|
||||
]
|
||||
cflags = [ "-Wno-multichar" ]
|
||||
|
||||
|
@ -1,62 +0,0 @@
|
||||
# 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.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("BlobFuzzTest") {
|
||||
module_out_path = "datamgr_service/distributeddatafwk"
|
||||
|
||||
include_dirs = [
|
||||
"ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/common",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/rdb/include",
|
||||
"//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include",
|
||||
"//foundation/distributeddatamgr/data_share/interfaces/inner_api/common/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
]
|
||||
|
||||
fuzz_config_file = "//foundation/distributeddatamgr/datamgr_service/test/fuzztest/blob_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
|
||||
sources = [ "blob_fuzzer.cpp" ]
|
||||
|
||||
deps = []
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"ipc:ipc_core",
|
||||
"kv_store:distributeddata_inner",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":BlobFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* 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 "blob_fuzzer.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "securec.h"
|
||||
#include "types.h"
|
||||
|
||||
using namespace OHOS::DistributedKv;
|
||||
namespace OHOS {
|
||||
void BlobSelfOption(const Blob &blob)
|
||||
{
|
||||
blob.Empty();
|
||||
blob.Size();
|
||||
blob.Data();
|
||||
blob.ToString();
|
||||
blob.RawSize();
|
||||
}
|
||||
|
||||
void BlobEachOtherOption(const Blob &blob1, const Blob &blob2)
|
||||
{
|
||||
blob1.Compare(blob2);
|
||||
Blob blobOut;
|
||||
blob1.Compare(blobOut);
|
||||
blob1.StartsWith(blob2);
|
||||
}
|
||||
|
||||
void BlobOption(const Blob &blob)
|
||||
{
|
||||
BlobSelfOption(blob);
|
||||
Blob blobTmp(blob);
|
||||
BlobEachOtherOption(blob, blobTmp);
|
||||
|
||||
Blob blobPrefix = { "fuzz" };
|
||||
blobTmp = blobPrefix.ToString() + blob.ToString();
|
||||
if (blobPrefix[0] == blobTmp[0] && (!(blobPrefix == blobTmp))) {
|
||||
BlobEachOtherOption(blobTmp, blobPrefix);
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
std::string fuzzStr(reinterpret_cast<const char *>(data), size);
|
||||
std::vector<uint8_t> fuzzVec(fuzzStr.begin(), fuzzStr.end());
|
||||
|
||||
int count = 10;
|
||||
char str[count + 1];
|
||||
auto ret = memcpy_s(str, count + 1, data, std::min(static_cast<size_t> (count + 1), size));
|
||||
if (ret != EOK) {
|
||||
return 0;
|
||||
}
|
||||
str[count] = '\0';
|
||||
Blob blob1(str);
|
||||
blob1 = str;
|
||||
Blob blob2(fuzzStr);
|
||||
blob2 = fuzzStr;
|
||||
Blob blob3(fuzzVec);
|
||||
Blob blob4(str, count + 1);
|
||||
Blob blob5(blob4);
|
||||
Blob blob6(std::move(blob5));
|
||||
Blob blob7 = blob6;
|
||||
blob7 = Blob(blob6);
|
||||
auto buffer = std::make_unique<uint8_t[]>(count);
|
||||
uint8_t *writePtr = buffer.get();
|
||||
Blob blob8(fuzzStr);
|
||||
blob8.WriteToBuffer(writePtr, count);
|
||||
OHOS::BlobOption(blob8);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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 BLOB_FUZZER_H
|
||||
#define BLOB_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "Blob_fuzzer"
|
||||
|
||||
#endif // BLOB_FUZZER_H
|
||||
|
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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
|
@ -1,25 +0,0 @@
|
||||
<?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>30</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -1,73 +0,0 @@
|
||||
# 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.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("DeviceKvStoreFuzzTest") {
|
||||
module_out_path = "datamgr_service/distributeddatafwk"
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/common",
|
||||
"//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
]
|
||||
|
||||
fuzz_config_file = "//foundation/distributeddatamgr/datamgr_service/test/fuzztest/devicekvstore_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "devicekvstore_fuzzer.cpp" ]
|
||||
|
||||
defines = [
|
||||
"SQLITE_ENABLE_SNAPSHOT",
|
||||
"_LARGEFILE64_SOURCE",
|
||||
"_FILE_OFFSET_BITS=64",
|
||||
"SQLITE_HAS_CODEC",
|
||||
"SQLITE_ENABLE_JSON1",
|
||||
"USING_HILOG_LOGGER",
|
||||
"USE_SQLITE_SYMBOLS",
|
||||
"USING_DB_JSON_EXTRACT_AUTOMATICALLY",
|
||||
"LOW_LEVEL_MEM_DEV",
|
||||
"JSONCPP_USE_BUILDER",
|
||||
"OMIT_FLATBUFFER",
|
||||
"RELATIONAL_STORE",
|
||||
"SQLITE_DISTRIBUTE_RELATIONAL",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter",
|
||||
"//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner",
|
||||
]
|
||||
|
||||
external_deps = [ "c_utils:utils" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":DeviceKvStoreFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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
|
@ -1,509 +0,0 @@
|
||||
/*
|
||||
* 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 "devicekvstore_fuzzer.h"
|
||||
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <vector>
|
||||
|
||||
#include "distributed_kv_data_manager.h"
|
||||
#include "store_errno.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::DistributedKv;
|
||||
|
||||
namespace OHOS {
|
||||
static std::shared_ptr<SingleKvStore> deviceKvStore_ = nullptr;
|
||||
|
||||
class DeviceObserverTestImpl : public KvStoreObserver {
|
||||
public:
|
||||
DeviceObserverTestImpl();
|
||||
~DeviceObserverTestImpl()
|
||||
{
|
||||
}
|
||||
DeviceObserverTestImpl(const DeviceObserverTestImpl &) = delete;
|
||||
DeviceObserverTestImpl &operator=(const DeviceObserverTestImpl &) = delete;
|
||||
DeviceObserverTestImpl(DeviceObserverTestImpl &&) = delete;
|
||||
DeviceObserverTestImpl &operator=(DeviceObserverTestImpl &&) = delete;
|
||||
|
||||
void OnChange(const ChangeNotification &changeNotification);
|
||||
};
|
||||
|
||||
void DeviceObserverTestImpl::OnChange(const ChangeNotification &changeNotification)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceObserverTestImpl::DeviceObserverTestImpl()
|
||||
{
|
||||
}
|
||||
class DeviceSyncCallbackTestImpl : public KvStoreSyncCallback {
|
||||
public:
|
||||
void SyncCompleted(const std::map<std::string, Status> &results);
|
||||
};
|
||||
|
||||
void DeviceSyncCallbackTestImpl::SyncCompleted(const std::map<std::string, Status> &results)
|
||||
{
|
||||
}
|
||||
|
||||
void SetUpTestCase(void)
|
||||
{
|
||||
DistributedKvDataManager manager;
|
||||
Options options = {
|
||||
.createIfMissing = true,
|
||||
.encrypt = false,
|
||||
.autoSync = true,
|
||||
.kvStoreType = KvStoreType::DEVICE_COLLABORATION
|
||||
};
|
||||
options.area = EL1;
|
||||
AppId appId = { "devicekvstorefuzzertest" };
|
||||
options.baseDir = std::string("/data/service/el1/public/database/") + appId.appId;
|
||||
/* define kvstore(database) name. */
|
||||
StoreId storeId = { "fuzzer_device" };
|
||||
mkdir(options.baseDir.c_str(), (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
|
||||
/* [create and] open and initialize kvstore instance. */
|
||||
manager.GetSingleKvStore(options, appId, storeId, deviceKvStore_);
|
||||
}
|
||||
|
||||
void TearDown(void)
|
||||
{
|
||||
(void)remove("/data/service/el1/public/database/devicekvstorefuzzertest/key");
|
||||
(void)remove("/data/service/el1/public/database/devicekvstorefuzzertest/kvdb");
|
||||
(void)remove("/data/service/el1/public/database/devicekvstorefuzzertest");
|
||||
}
|
||||
|
||||
void PutFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string skey(data, data + size);
|
||||
std::string svalue(data, data + size);
|
||||
Key key = { skey };
|
||||
Value val = { svalue };
|
||||
deviceKvStore_->Put(key, val);
|
||||
deviceKvStore_->Delete(key);
|
||||
}
|
||||
|
||||
void PutBatchFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string skey(data, data + size);
|
||||
std::string svalue(data, data + size);
|
||||
std::vector<Entry> entries;
|
||||
std::vector<Key> keys;
|
||||
Entry entry1, entry2, entry3;
|
||||
entry1.key = { skey + "test_key1" };
|
||||
entry1.value = { svalue + "test_val1" };
|
||||
entry2.key = { skey + "test_key2" };
|
||||
entry2.value = { svalue + "test_val2" };
|
||||
entry3.key = { skey + "test_key3" };
|
||||
entry3.value = { svalue + "test_val3" };
|
||||
entries.push_back(entry1);
|
||||
entries.push_back(entry2);
|
||||
entries.push_back(entry3);
|
||||
keys.push_back(entry1.key);
|
||||
keys.push_back(entry2.key);
|
||||
keys.push_back(entry3.key);
|
||||
deviceKvStore_->PutBatch(entries);
|
||||
deviceKvStore_->DeleteBatch(keys);
|
||||
}
|
||||
|
||||
void GetFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string skey(data, data + size);
|
||||
std::string svalue(data, data + size);
|
||||
Key key = { skey };
|
||||
Value val = { svalue };
|
||||
Value val1;
|
||||
deviceKvStore_->Put(key, val);
|
||||
deviceKvStore_->Get(key, val1);
|
||||
deviceKvStore_->Delete(key);
|
||||
}
|
||||
|
||||
void GetEntriesFuzz1(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
std::string keys = "test_";
|
||||
size_t sum = 10;
|
||||
std::vector<Entry> results;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + keys + std::to_string(i), { keys + std::to_string(i) });
|
||||
}
|
||||
deviceKvStore_->GetEntries(prefix, results);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void GetEntriesFuzz2(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
std::vector<Entry> entries;
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
deviceKvStore_->GetEntries(dataQuery, entries);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SyncCallbackFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
auto syncCallback = std::make_shared<DeviceSyncCallbackTestImpl>();
|
||||
deviceKvStore_->RegisterSyncCallback(syncCallback);
|
||||
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
|
||||
std::map<std::string, Status> results;
|
||||
syncCallback->SyncCompleted(results);
|
||||
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
deviceKvStore_->UnRegisterSyncCallback();
|
||||
}
|
||||
|
||||
void GetResultSetFuzz1(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
std::string keys = "test_";
|
||||
int position = static_cast<int>(size);
|
||||
std::shared_ptr<KvStoreResultSet> resultSet;
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
auto status = deviceKvStore_->GetResultSet(prefix, resultSet);
|
||||
if (status != Status::SUCCESS) {
|
||||
return;
|
||||
}
|
||||
resultSet->Move(position);
|
||||
resultSet->MoveToPosition(position);
|
||||
Entry entry;
|
||||
resultSet->GetEntry(entry);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void GetResultSetFuzz2(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
std::shared_ptr<KvStoreResultSet> resultSet;
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
deviceKvStore_->GetResultSet(dataQuery, resultSet);
|
||||
deviceKvStore_->CloseResultSet(resultSet);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void GetResultSetFuzz3(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
std::shared_ptr<KvStoreResultSet> resultSet;
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
deviceKvStore_->GetResultSet(dataQuery, resultSet);
|
||||
auto status = deviceKvStore_->GetResultSet(prefix, resultSet);
|
||||
if (status != Status::SUCCESS) {
|
||||
return;
|
||||
}
|
||||
int cnt = resultSet->GetCount();
|
||||
if (static_cast<int>(size) != cnt) {
|
||||
return;
|
||||
}
|
||||
resultSet->GetPosition();
|
||||
resultSet->IsBeforeFirst();
|
||||
resultSet->IsFirst();
|
||||
resultSet->MoveToPrevious();
|
||||
resultSet->IsBeforeFirst();
|
||||
resultSet->IsFirst();
|
||||
while (resultSet->MoveToNext()) {
|
||||
Entry entry;
|
||||
resultSet->GetEntry(entry);
|
||||
}
|
||||
Entry entry;
|
||||
resultSet->GetEntry(entry);
|
||||
resultSet->IsLast();
|
||||
resultSet->IsAfterLast();
|
||||
resultSet->MoveToNext();
|
||||
resultSet->IsLast();
|
||||
resultSet->IsAfterLast();
|
||||
resultSet->Move(1);
|
||||
resultSet->IsLast();
|
||||
resultSet->IsAfterLast();
|
||||
resultSet->MoveToFirst();
|
||||
resultSet->GetEntry(entry);
|
||||
resultSet->MoveToLast();
|
||||
resultSet->GetEntry(entry);
|
||||
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void GetCountFuzz1(const uint8_t *data, size_t size)
|
||||
{
|
||||
int count;
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery query;
|
||||
query.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
deviceKvStore_->GetCount(query, count);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void GetCountFuzz2(const uint8_t *data, size_t size)
|
||||
{
|
||||
int count;
|
||||
size_t sum = 10;
|
||||
std::vector<std::string> keys;
|
||||
std::string prefix(data, data + size);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
keys.push_back(prefix);
|
||||
}
|
||||
DataQuery query;
|
||||
query.InKeys(keys);
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
deviceKvStore_->GetCount(query, count);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SyncFuzz1(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
std::string deviceId(data, data + size);
|
||||
std::vector<std::string> deviceIds = { deviceId };
|
||||
uint32_t allowedDelayMs = 200;
|
||||
deviceKvStore_->Sync(deviceIds, SyncMode::PUSH, allowedDelayMs);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SyncFuzz2(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
std::string deviceId(data, data + size);
|
||||
std::vector<std::string> deviceIds = { deviceId };
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix("name");
|
||||
deviceKvStore_->Sync(deviceIds, SyncMode::PULL, dataQuery, nullptr);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SubscribeKvStoreFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
auto observer = std::make_shared<DeviceObserverTestImpl>();
|
||||
deviceKvStore_->SubscribeKvStore(SubscribeType::SUBSCRIBE_TYPE_ALL, observer);
|
||||
deviceKvStore_->UnSubscribeKvStore(SubscribeType::SUBSCRIBE_TYPE_ALL, observer);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveDeviceDataFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::string deviceId(data, data + size);
|
||||
std::vector<Entry> input;
|
||||
auto cmp = [](const Key &entry, const Key &sentry) { return entry.Data() < sentry.Data(); };
|
||||
std::map<Key, Value, decltype(cmp)> dictionary(cmp);
|
||||
for (size_t i = 0; i < sum; ++i) {
|
||||
Entry entry;
|
||||
entry.key = std::to_string(i).append("_k");
|
||||
entry.value = std::to_string(i).append("_v");
|
||||
dictionary[entry.key] = entry.value;
|
||||
input.push_back(entry);
|
||||
}
|
||||
deviceKvStore_->PutBatch(input);
|
||||
deviceKvStore_->RemoveDeviceData(deviceId);
|
||||
deviceKvStore_->RemoveDeviceData("");
|
||||
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(std::to_string(i).append("_k"));
|
||||
}
|
||||
}
|
||||
|
||||
void GetSecurityLevelFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::vector<std::string> keys;
|
||||
std::string prefix(data, data + size);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
keys.push_back(prefix);
|
||||
}
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
SecurityLevel securityLevel;
|
||||
deviceKvStore_->GetSecurityLevel(securityLevel);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SyncParamFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::vector<std::string> keys;
|
||||
std::string prefix(data, data + size);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
keys.push_back(prefix);
|
||||
}
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
|
||||
KvSyncParam syncParam { 500 };
|
||||
deviceKvStore_->SetSyncParam(syncParam);
|
||||
|
||||
KvSyncParam syncParamRet;
|
||||
deviceKvStore_->GetSyncParam(syncParamRet);
|
||||
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SetCapabilityEnabledFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::vector<std::string> keys;
|
||||
std::string prefix(data, data + size);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
keys.push_back(prefix);
|
||||
}
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Put(prefix + skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
|
||||
deviceKvStore_->SetCapabilityEnabled(true);
|
||||
deviceKvStore_->SetCapabilityEnabled(false);
|
||||
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
deviceKvStore_->Delete(prefix + skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SetCapabilityRangeFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string label(data, data + size);
|
||||
std::vector<std::string> local = { label + "_local1", label + "_local2" };
|
||||
std::vector<std::string> remote = { label + "_remote1", label + "_remote2" };
|
||||
deviceKvStore_->SetCapabilityRange(local, remote);
|
||||
}
|
||||
|
||||
void SubscribeWithQueryFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string deviceId(data, data + size);
|
||||
std::vector<std::string> deviceIds = { deviceId + "_1", deviceId + "_2" };
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix("name");
|
||||
deviceKvStore_->SubscribeWithQuery(deviceIds, dataQuery);
|
||||
deviceKvStore_->UnsubscribeWithQuery(deviceIds, dataQuery);
|
||||
}
|
||||
|
||||
void UnSubscribeWithQueryFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string deviceId(data, data + size);
|
||||
std::vector<std::string> deviceIds = { deviceId + "_1", deviceId + "_2" };
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix("name");
|
||||
deviceKvStore_->UnsubscribeWithQuery(deviceIds, dataQuery);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::SetUpTestCase();
|
||||
OHOS::PutFuzz(data, size);
|
||||
OHOS::PutBatchFuzz(data, size);
|
||||
OHOS::GetFuzz(data, size);
|
||||
OHOS::GetEntriesFuzz1(data, size);
|
||||
OHOS::GetEntriesFuzz2(data, size);
|
||||
OHOS::GetResultSetFuzz1(data, size);
|
||||
OHOS::GetResultSetFuzz2(data, size);
|
||||
OHOS::GetResultSetFuzz3(data, size);
|
||||
OHOS::GetCountFuzz1(data, size);
|
||||
OHOS::GetCountFuzz2(data, size);
|
||||
OHOS::SyncFuzz1(data, size);
|
||||
OHOS::SyncFuzz2(data, size);
|
||||
OHOS::SubscribeKvStoreFuzz(data, size);
|
||||
OHOS::RemoveDeviceDataFuzz(data, size);
|
||||
OHOS::GetSecurityLevelFuzz(data, size);
|
||||
OHOS::SyncCallbackFuzz(data, size);
|
||||
OHOS::SyncParamFuzz(data, size);
|
||||
OHOS::SetCapabilityEnabledFuzz(data, size);
|
||||
OHOS::SetCapabilityRangeFuzz(data, size);
|
||||
OHOS::SubscribeWithQueryFuzz(data, size);
|
||||
OHOS::UnSubscribeWithQueryFuzz(data, size);
|
||||
OHOS::TearDown();
|
||||
return 0;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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 DEVICEKVSTORE_FUZZER_H
|
||||
#define DEVICEKVSTORE_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "devicekvstore_fuzzer"
|
||||
|
||||
#endif // DEVICEKVSTORE_FUZZER_H
|
||||
|
@ -1,25 +0,0 @@
|
||||
<?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>
|
@ -1,73 +0,0 @@
|
||||
# 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.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("DistributedKvDataManagerFuzzTest") {
|
||||
module_out_path = "datamgr_service/distributeddatafwk"
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/common",
|
||||
"//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
]
|
||||
|
||||
fuzz_config_file = "//foundation/distributeddatamgr/datamgr_service/test/fuzztest/distributedkvdatamanager_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "distributedkvdatamanager_fuzzer.cpp" ]
|
||||
|
||||
defines = [
|
||||
"SQLITE_ENABLE_SNAPSHOT",
|
||||
"_LARGEFILE64_SOURCE",
|
||||
"_FILE_OFFSET_BITS=64",
|
||||
"SQLITE_HAS_CODEC",
|
||||
"SQLITE_ENABLE_JSON1",
|
||||
"USING_HILOG_LOGGER",
|
||||
"USE_SQLITE_SYMBOLS",
|
||||
"USING_DB_JSON_EXTRACT_AUTOMATICALLY",
|
||||
"LOW_LEVEL_MEM_DEV",
|
||||
"JSONCPP_USE_BUILDER",
|
||||
"OMIT_FLATBUFFER",
|
||||
"RELATIONAL_STORE",
|
||||
"SQLITE_DISTRIBUTE_RELATIONAL",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter",
|
||||
"//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner",
|
||||
]
|
||||
|
||||
external_deps = [ "c_utils:utils" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":DistributedKvDataManagerFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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
|
@ -1,219 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "distributedkvdatamanager_fuzzer.h"
|
||||
|
||||
#include <vector>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "distributed_kv_data_manager.h"
|
||||
#include "kvstore_death_recipient.h"
|
||||
#include "types.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::DistributedKv;
|
||||
|
||||
class DistributedKvDataManagerFuzzer {
|
||||
/* Keep C++ file names the same as the class name */
|
||||
};
|
||||
|
||||
namespace OHOS {
|
||||
static std::shared_ptr<SingleKvStore> singleKvStore_ = nullptr;
|
||||
|
||||
static DistributedKvDataManager manager;
|
||||
static Options create;
|
||||
static Options noCreate;
|
||||
static UserId userId;
|
||||
static AppId appId;
|
||||
static StoreId storeIdTest;
|
||||
|
||||
class MyDeathRecipient : public KvStoreDeathRecipient {
|
||||
public:
|
||||
MyDeathRecipient()
|
||||
{
|
||||
}
|
||||
virtual ~MyDeathRecipient()
|
||||
{
|
||||
}
|
||||
void OnRemoteDied() override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
void SetUpTestCase(void)
|
||||
{
|
||||
userId.userId = "account";
|
||||
appId.appId = "distributedkvdatamanagerfuzzertest";
|
||||
create.createIfMissing = true;
|
||||
create.encrypt = false;
|
||||
create.autoSync = true;
|
||||
create.kvStoreType = SINGLE_VERSION;
|
||||
create.area = EL1;
|
||||
create.baseDir = std::string("/data/service/el1/public/database/") + appId.appId;
|
||||
mkdir(create.baseDir.c_str(), (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
|
||||
|
||||
manager.CloseAllKvStore(appId);
|
||||
manager.DeleteAllKvStore(appId, create.baseDir);
|
||||
}
|
||||
|
||||
void TearDown(void)
|
||||
{
|
||||
manager.CloseAllKvStore(appId);
|
||||
manager.DeleteAllKvStore(appId, create.baseDir);
|
||||
(void)remove("/data/service/el1/public/database/distributedkvdatamanagerfuzzertest/key");
|
||||
(void)remove("/data/service/el1/public/database/distributedkvdatamanagerfuzzertest/kvdb");
|
||||
(void)remove("/data/service/el1/public/database/distributedkvdatamanagerfuzzertest");
|
||||
}
|
||||
|
||||
void GetKvStoreFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
StoreId storeId;
|
||||
storeId.storeId = std::string(data, data + size);
|
||||
std::shared_ptr<SingleKvStore> notExistKvStore;
|
||||
manager.GetSingleKvStore(create, appId, storeId, notExistKvStore);
|
||||
std::shared_ptr<SingleKvStore> existKvStore;
|
||||
manager.GetSingleKvStore(noCreate, appId, storeId, existKvStore);
|
||||
manager.CloseKvStore(appId, storeId);
|
||||
manager.DeleteKvStore(appId, storeId);
|
||||
}
|
||||
|
||||
void GetAllKvStoreFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::vector<StoreId> storeIds;
|
||||
manager.GetAllKvStoreId(appId, storeIds);
|
||||
|
||||
std::shared_ptr<SingleKvStore> KvStore;
|
||||
std::string storeId_base(data, data + size);
|
||||
int sum = 10;
|
||||
for (int i = 0; i < sum; i++) {
|
||||
StoreId storeId;
|
||||
storeId.storeId = storeId_base + "_" + std::to_string(i);
|
||||
manager.GetSingleKvStore(create, appId, storeId, KvStore);
|
||||
}
|
||||
manager.GetAllKvStoreId(appId, storeIds);
|
||||
manager.CloseAllKvStore(appId);
|
||||
|
||||
manager.GetAllKvStoreId(appId, storeIds);
|
||||
}
|
||||
|
||||
void CloseKvStoreFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
StoreId storeId;
|
||||
storeId.storeId = std::string(data, data + size);
|
||||
manager.CloseKvStore(appId, storeId);
|
||||
std::shared_ptr<SingleKvStore> kvStore;
|
||||
manager.GetSingleKvStore(create, appId, storeId, kvStore);
|
||||
manager.CloseKvStore(appId, storeId);
|
||||
manager.CloseKvStore(appId, storeId);
|
||||
}
|
||||
|
||||
void DeleteKvStoreFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
StoreId storeId;
|
||||
storeId.storeId = std::string(data, data + size);
|
||||
manager.DeleteKvStore(appId, storeId, create.baseDir);
|
||||
|
||||
std::shared_ptr<SingleKvStore> kvStore;
|
||||
manager.GetSingleKvStore(create, appId, storeId, kvStore);
|
||||
manager.CloseKvStore(appId, storeId);
|
||||
manager.DeleteKvStore(appId, storeId, create.baseDir);
|
||||
|
||||
manager.CloseKvStore(appId, storeId);
|
||||
}
|
||||
|
||||
void DeleteAllKvStoreFuzz1(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::vector<StoreId> storeIds;
|
||||
manager.GetAllKvStoreId(appId, storeIds);
|
||||
|
||||
manager.DeleteAllKvStore(appId, create.baseDir);
|
||||
std::shared_ptr<SingleKvStore> KvStore;
|
||||
std::string storeId_base(data, data + size);
|
||||
int sum = 10;
|
||||
for (int i = 0; i < sum; i++) {
|
||||
StoreId storeId;
|
||||
storeId.storeId = storeId_base + "_" + std::to_string(i);
|
||||
manager.GetSingleKvStore(create, appId, storeId, KvStore);
|
||||
|
||||
manager.CloseKvStore(appId, storeId);
|
||||
}
|
||||
manager.DeleteAllKvStore(appId, create.baseDir);
|
||||
}
|
||||
|
||||
void DeleteAllKvStoreFuzz2(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::vector<StoreId> storeIds;
|
||||
manager.GetAllKvStoreId(appId, storeIds);
|
||||
|
||||
std::shared_ptr<SingleKvStore> KvStore;
|
||||
std::string storeId_base(data, data + size);
|
||||
manager.GetSingleKvStore(create, appId, storeIdTest, KvStore);
|
||||
manager.CloseKvStore(appId, storeIdTest);
|
||||
int sum = 10;
|
||||
for (int i = 0; i < sum; i++) {
|
||||
StoreId storeId;
|
||||
storeId.storeId = storeId_base + "_" + std::to_string(i);
|
||||
manager.GetSingleKvStore(create, appId, storeId, KvStore);
|
||||
}
|
||||
manager.DeleteAllKvStore(appId, create.baseDir);
|
||||
}
|
||||
|
||||
void DeleteAllKvStoreFuzz3(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::vector<StoreId> storeIds;
|
||||
manager.GetAllKvStoreId(appId, storeIds);
|
||||
|
||||
std::shared_ptr<SingleKvStore> KvStore;
|
||||
std::string storeId_base(data, data + size);
|
||||
int sum = 10;
|
||||
for (int i = 0; i < sum; i++) {
|
||||
StoreId storeId;
|
||||
storeId.storeId = storeId_base + "_" + std::to_string(i);
|
||||
manager.GetSingleKvStore(create, appId, storeId, KvStore);
|
||||
}
|
||||
manager.DeleteAllKvStore(appId, create.baseDir);
|
||||
}
|
||||
|
||||
void RegisterKvStoreServiceDeathRecipientFuzz()
|
||||
{
|
||||
std::shared_ptr<KvStoreDeathRecipient> kvStoreDeathRecipient = std::make_shared<MyDeathRecipient>();
|
||||
manager.RegisterKvStoreServiceDeathRecipient(kvStoreDeathRecipient);
|
||||
kvStoreDeathRecipient->OnRemoteDied();
|
||||
}
|
||||
|
||||
void UnRegisterKvStoreServiceDeathRecipientFuzz()
|
||||
{
|
||||
std::shared_ptr<KvStoreDeathRecipient> kvStoreDeathRecipient = std::make_shared<MyDeathRecipient>();
|
||||
manager.UnRegisterKvStoreServiceDeathRecipient(kvStoreDeathRecipient);
|
||||
kvStoreDeathRecipient->OnRemoteDied();
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::SetUpTestCase();
|
||||
OHOS::GetKvStoreFuzz(data, size);
|
||||
OHOS::GetAllKvStoreFuzz(data, size);
|
||||
OHOS::CloseKvStoreFuzz(data, size);
|
||||
OHOS::DeleteKvStoreFuzz(data, size);
|
||||
OHOS::DeleteAllKvStoreFuzz1(data, size);
|
||||
OHOS::DeleteAllKvStoreFuzz2(data, size);
|
||||
OHOS::DeleteAllKvStoreFuzz3(data, size);
|
||||
OHOS::RegisterKvStoreServiceDeathRecipientFuzz();
|
||||
OHOS::UnRegisterKvStoreServiceDeathRecipientFuzz();
|
||||
OHOS::TearDown();
|
||||
return 0;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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 DISTRIBUTEDKVDATAMANAGER_FUZZER_H
|
||||
#define DISTRIBUTEDKVDATAMANAGER_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "distributedkvdatamanager_fuzzer"
|
||||
|
||||
#endif // DISTRIBUTEDKVDATAMANAGER_FUZZER_H
|
||||
|
@ -1,25 +0,0 @@
|
||||
<?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>
|
@ -1,73 +0,0 @@
|
||||
# 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.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("SingleKvStoreFuzzTest") {
|
||||
module_out_path = "datamgr_service/distributeddatafwk"
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/common",
|
||||
"//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
]
|
||||
|
||||
fuzz_config_file = "//foundation/distributeddatamgr/datamgr_service/test/fuzztest/singlekvstore_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "singlekvstore_fuzzer.cpp" ]
|
||||
|
||||
defines = [
|
||||
"SQLITE_ENABLE_SNAPSHOT",
|
||||
"_LARGEFILE64_SOURCE",
|
||||
"_FILE_OFFSET_BITS=64",
|
||||
"SQLITE_HAS_CODEC",
|
||||
"SQLITE_ENABLE_JSON1",
|
||||
"USING_HILOG_LOGGER",
|
||||
"USE_SQLITE_SYMBOLS",
|
||||
"USING_DB_JSON_EXTRACT_AUTOMATICALLY",
|
||||
"LOW_LEVEL_MEM_DEV",
|
||||
"JSONCPP_USE_BUILDER",
|
||||
"OMIT_FLATBUFFER",
|
||||
"RELATIONAL_STORE",
|
||||
"SQLITE_DISTRIBUTE_RELATIONAL",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter",
|
||||
"//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner",
|
||||
]
|
||||
|
||||
external_deps = [ "c_utils:utils" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":SingleKvStoreFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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
|
@ -1,25 +0,0 @@
|
||||
<?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>
|
@ -1,508 +0,0 @@
|
||||
/*
|
||||
* 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 "singlekvstore_fuzzer.h"
|
||||
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <vector>
|
||||
|
||||
#include "distributed_kv_data_manager.h"
|
||||
#include "store_errno.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::DistributedKv;
|
||||
|
||||
namespace OHOS {
|
||||
static std::shared_ptr<SingleKvStore> singleKvStore_ = nullptr;
|
||||
|
||||
class DeviceObserverTestImpl : public KvStoreObserver {
|
||||
public:
|
||||
DeviceObserverTestImpl();
|
||||
~DeviceObserverTestImpl()
|
||||
{
|
||||
}
|
||||
DeviceObserverTestImpl(const DeviceObserverTestImpl &) = delete;
|
||||
DeviceObserverTestImpl &operator=(const DeviceObserverTestImpl &) = delete;
|
||||
DeviceObserverTestImpl(DeviceObserverTestImpl &&) = delete;
|
||||
DeviceObserverTestImpl &operator=(DeviceObserverTestImpl &&) = delete;
|
||||
|
||||
void OnChange(const ChangeNotification &changeNotification);
|
||||
};
|
||||
|
||||
void DeviceObserverTestImpl::OnChange(const ChangeNotification &changeNotification)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceObserverTestImpl::DeviceObserverTestImpl()
|
||||
{
|
||||
}
|
||||
|
||||
class DeviceSyncCallbackTestImpl : public KvStoreSyncCallback {
|
||||
public:
|
||||
void SyncCompleted(const std::map<std::string, Status> &results);
|
||||
};
|
||||
|
||||
void DeviceSyncCallbackTestImpl::SyncCompleted(const std::map<std::string, Status> &results)
|
||||
{
|
||||
}
|
||||
|
||||
void SetUpTestCase(void)
|
||||
{
|
||||
DistributedKvDataManager manager;
|
||||
Options options = { .createIfMissing = true,
|
||||
.encrypt = false,
|
||||
.autoSync = true,
|
||||
.kvStoreType = KvStoreType::SINGLE_VERSION };
|
||||
options.area = EL1;
|
||||
AppId appId = { "kvstorefuzzertest" };
|
||||
options.baseDir = std::string("/data/service/el1/public/database/") + appId.appId;
|
||||
/* define kvstore(database) name. */
|
||||
StoreId storeId = { "fuzzer_single" };
|
||||
mkdir(options.baseDir.c_str(), (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
|
||||
/* [create and] open and initialize kvstore instance. */
|
||||
manager.GetSingleKvStore(options, appId, storeId, singleKvStore_);
|
||||
}
|
||||
|
||||
void TearDown(void)
|
||||
{
|
||||
(void)remove("/data/service/el1/public/database/singlekvstorefuzzertest/key");
|
||||
(void)remove("/data/service/el1/public/database/singlekvstorefuzzertest/kvdb");
|
||||
(void)remove("/data/service/el1/public/database/singlekvstorefuzzertest");
|
||||
}
|
||||
|
||||
void PutFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string skey(data, data + size);
|
||||
std::string svalue(data, data + size);
|
||||
Key key = { skey };
|
||||
Value val = { svalue };
|
||||
singleKvStore_->Put(key, val);
|
||||
singleKvStore_->Delete(key);
|
||||
}
|
||||
|
||||
void PutBatchFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string skey(data, data + size);
|
||||
std::string svalue(data, data + size);
|
||||
std::vector<Entry> entries;
|
||||
std::vector<Key> keys;
|
||||
Entry entry1, entry2, entry3;
|
||||
entry1.key = { skey + "test_key1" };
|
||||
entry1.value = { svalue + "test_val1" };
|
||||
entry2.key = { skey + "test_key2" };
|
||||
entry2.value = { svalue + "test_val2" };
|
||||
entry3.key = { skey + "test_key3" };
|
||||
entry3.value = { svalue + "test_val3" };
|
||||
entries.push_back(entry1);
|
||||
entries.push_back(entry2);
|
||||
entries.push_back(entry3);
|
||||
keys.push_back(entry1.key);
|
||||
keys.push_back(entry2.key);
|
||||
keys.push_back(entry3.key);
|
||||
singleKvStore_->PutBatch(entries);
|
||||
singleKvStore_->DeleteBatch(keys);
|
||||
}
|
||||
|
||||
void GetFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string skey(data, data + size);
|
||||
std::string svalue(data, data + size);
|
||||
Key key = { skey };
|
||||
Value val = { svalue };
|
||||
Value val1;
|
||||
singleKvStore_->Put(key, val);
|
||||
singleKvStore_->Get(key, val1);
|
||||
singleKvStore_->Delete(key);
|
||||
}
|
||||
|
||||
void GetEntriesFuzz1(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
std::string keys = "test_";
|
||||
size_t sum = 10;
|
||||
std::vector<Entry> results;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + keys + std::to_string(i), { keys + std::to_string(i) });
|
||||
}
|
||||
singleKvStore_->GetEntries(prefix, results);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void GetEntriesFuzz2(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
std::vector<Entry> entries;
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
singleKvStore_->GetEntries(dataQuery, entries);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SubscribeKvStoreFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
auto observer = std::make_shared<DeviceObserverTestImpl>();
|
||||
singleKvStore_->SubscribeKvStore(SubscribeType::SUBSCRIBE_TYPE_ALL, observer);
|
||||
singleKvStore_->UnSubscribeKvStore(SubscribeType::SUBSCRIBE_TYPE_ALL, observer);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SyncCallbackFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
auto syncCallback = std::make_shared<DeviceSyncCallbackTestImpl>();
|
||||
singleKvStore_->RegisterSyncCallback(syncCallback);
|
||||
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
|
||||
std::map<std::string, Status> results;
|
||||
syncCallback->SyncCompleted(results);
|
||||
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
singleKvStore_->UnRegisterSyncCallback();
|
||||
}
|
||||
|
||||
void GetResultSetFuzz1(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
std::string keys = "test_";
|
||||
int position = static_cast<int>(size);
|
||||
std::shared_ptr<KvStoreResultSet> resultSet;
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
auto status = singleKvStore_->GetResultSet(prefix, resultSet);
|
||||
if (status != Status::SUCCESS) {
|
||||
return;
|
||||
}
|
||||
resultSet->Move(position);
|
||||
resultSet->MoveToPosition(position);
|
||||
Entry entry;
|
||||
resultSet->GetEntry(entry);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void GetResultSetFuzz2(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
std::shared_ptr<KvStoreResultSet> resultSet;
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
singleKvStore_->GetResultSet(dataQuery, resultSet);
|
||||
singleKvStore_->CloseResultSet(resultSet);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void GetResultSetFuzz3(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
std::shared_ptr<KvStoreResultSet> resultSet;
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
singleKvStore_->GetResultSet(dataQuery, resultSet);
|
||||
auto status = singleKvStore_->GetResultSet(prefix, resultSet);
|
||||
if (status != Status::SUCCESS) {
|
||||
return;
|
||||
}
|
||||
int cnt = resultSet->GetCount();
|
||||
if (static_cast<int>(size) != cnt) {
|
||||
return;
|
||||
}
|
||||
resultSet->GetPosition();
|
||||
resultSet->IsBeforeFirst();
|
||||
resultSet->IsFirst();
|
||||
resultSet->MoveToPrevious();
|
||||
resultSet->IsBeforeFirst();
|
||||
resultSet->IsFirst();
|
||||
while (resultSet->MoveToNext()) {
|
||||
Entry entry;
|
||||
resultSet->GetEntry(entry);
|
||||
}
|
||||
Entry entry;
|
||||
resultSet->GetEntry(entry);
|
||||
resultSet->IsLast();
|
||||
resultSet->IsAfterLast();
|
||||
resultSet->MoveToNext();
|
||||
resultSet->IsLast();
|
||||
resultSet->IsAfterLast();
|
||||
resultSet->Move(1);
|
||||
resultSet->IsLast();
|
||||
resultSet->IsAfterLast();
|
||||
resultSet->MoveToFirst();
|
||||
resultSet->GetEntry(entry);
|
||||
resultSet->MoveToLast();
|
||||
resultSet->GetEntry(entry);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void GetCountFuzz1(const uint8_t *data, size_t size)
|
||||
{
|
||||
int count;
|
||||
std::string prefix(data, data + size);
|
||||
DataQuery query;
|
||||
query.KeyPrefix(prefix);
|
||||
std::string keys = "test_";
|
||||
size_t sum = 10;
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + keys + std::to_string(i), keys + std::to_string(i));
|
||||
}
|
||||
singleKvStore_->GetCount(query, count);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + keys + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void GetCountFuzz2(const uint8_t *data, size_t size)
|
||||
{
|
||||
int count;
|
||||
size_t sum = 10;
|
||||
std::vector<std::string> keys;
|
||||
std::string prefix(data, data + size);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
keys.push_back(prefix);
|
||||
}
|
||||
DataQuery query;
|
||||
query.InKeys(keys);
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
singleKvStore_->GetCount(query, count);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveDeviceDataFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::string deviceId(data, data + size);
|
||||
std::vector<Entry> input;
|
||||
auto cmp = [](const Key &entry, const Key &sentry) { return entry.Data() < sentry.Data(); };
|
||||
std::map<Key, Value, decltype(cmp)> dictionary(cmp);
|
||||
for (size_t i = 0; i < sum; ++i) {
|
||||
Entry entry;
|
||||
entry.key = std::to_string(i).append("_k");
|
||||
entry.value = std::to_string(i).append("_v");
|
||||
dictionary[entry.key] = entry.value;
|
||||
input.push_back(entry);
|
||||
}
|
||||
singleKvStore_->PutBatch(input);
|
||||
singleKvStore_->RemoveDeviceData(deviceId);
|
||||
singleKvStore_->RemoveDeviceData("");
|
||||
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(std::to_string(i).append("_k"));
|
||||
}
|
||||
}
|
||||
|
||||
void GetSecurityLevelFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::vector<std::string> keys;
|
||||
std::string prefix(data, data + size);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
keys.push_back(prefix);
|
||||
}
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
SecurityLevel securityLevel;
|
||||
singleKvStore_->GetSecurityLevel(securityLevel);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SyncFuzz1(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
std::string deviceId(data, data + size);
|
||||
std::vector<std::string> deviceIds = { deviceId };
|
||||
uint32_t allowedDelayMs = 200;
|
||||
singleKvStore_->Sync(deviceIds, SyncMode::PUSH, allowedDelayMs);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SyncFuzz2(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
std::string deviceId(data, data + size);
|
||||
std::vector<std::string> deviceIds = { deviceId };
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix("name");
|
||||
singleKvStore_->Sync(deviceIds, SyncMode::PULL, dataQuery, nullptr);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SyncParamFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::vector<std::string> keys;
|
||||
std::string prefix(data, data + size);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
keys.push_back(prefix);
|
||||
}
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
|
||||
KvSyncParam syncParam { 500 };
|
||||
singleKvStore_->SetSyncParam(syncParam);
|
||||
|
||||
KvSyncParam syncParamRet;
|
||||
singleKvStore_->GetSyncParam(syncParamRet);
|
||||
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SetCapabilityEnabledFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
size_t sum = 10;
|
||||
std::vector<std::string> keys;
|
||||
std::string prefix(data, data + size);
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
keys.push_back(prefix);
|
||||
}
|
||||
std::string skey = "test_";
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Put(prefix + skey + std::to_string(i), skey + std::to_string(i));
|
||||
}
|
||||
|
||||
singleKvStore_->SetCapabilityEnabled(true);
|
||||
singleKvStore_->SetCapabilityEnabled(false);
|
||||
|
||||
for (size_t i = 0; i < sum; i++) {
|
||||
singleKvStore_->Delete(prefix + skey + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void SetCapabilityRangeFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string label(data, data + size);
|
||||
std::vector<std::string> local = { label + "_local1", label + "_local2" };
|
||||
std::vector<std::string> remote = { label + "_remote1", label + "_remote2" };
|
||||
singleKvStore_->SetCapabilityRange(local, remote);
|
||||
}
|
||||
|
||||
void SubscribeWithQueryFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string deviceId(data, data + size);
|
||||
std::vector<std::string> deviceIds = { deviceId + "_1", deviceId + "_2" };
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix("name");
|
||||
singleKvStore_->SubscribeWithQuery(deviceIds, dataQuery);
|
||||
singleKvStore_->UnsubscribeWithQuery(deviceIds, dataQuery);
|
||||
}
|
||||
|
||||
void UnSubscribeWithQueryFuzz(const uint8_t *data, size_t size)
|
||||
{
|
||||
std::string deviceId(data, data + size);
|
||||
std::vector<std::string> deviceIds = { deviceId + "_1", deviceId + "_2" };
|
||||
DataQuery dataQuery;
|
||||
dataQuery.KeyPrefix("name");
|
||||
singleKvStore_->UnsubscribeWithQuery(deviceIds, dataQuery);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::SetUpTestCase();
|
||||
OHOS::PutFuzz(data, size);
|
||||
OHOS::PutBatchFuzz(data, size);
|
||||
OHOS::GetFuzz(data, size);
|
||||
OHOS::GetEntriesFuzz1(data, size);
|
||||
OHOS::GetEntriesFuzz2(data, size);
|
||||
OHOS::GetResultSetFuzz1(data, size);
|
||||
OHOS::GetResultSetFuzz2(data, size);
|
||||
OHOS::GetResultSetFuzz3(data, size);
|
||||
OHOS::GetCountFuzz1(data, size);
|
||||
OHOS::GetCountFuzz2(data, size);
|
||||
OHOS::SyncFuzz1(data, size);
|
||||
OHOS::SyncFuzz2(data, size);
|
||||
OHOS::SubscribeKvStoreFuzz(data, size);
|
||||
OHOS::RemoveDeviceDataFuzz(data, size);
|
||||
OHOS::GetSecurityLevelFuzz(data, size);
|
||||
OHOS::SyncCallbackFuzz(data, size);
|
||||
OHOS::SyncParamFuzz(data, size);
|
||||
OHOS::SetCapabilityEnabledFuzz(data, size);
|
||||
OHOS::SetCapabilityRangeFuzz(data, size);
|
||||
OHOS::SubscribeWithQueryFuzz(data, size);
|
||||
OHOS::UnSubscribeWithQueryFuzz(data, size);
|
||||
OHOS::TearDown();
|
||||
return 0;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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 SINGLEKVSTORE_FUZZER_H
|
||||
#define SINGLEKVSTORE_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "singlekvstore_fuzzer"
|
||||
|
||||
#endif // SINGLEKVSTORE_FUZZER_H
|
||||
|
@ -1,51 +0,0 @@
|
||||
# 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.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("TaskSchedulerFuzzTest") {
|
||||
module_out_path = "datamgr_service/distributeddatafwk"
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/common",
|
||||
]
|
||||
|
||||
fuzz_config_file = "//foundation/distributeddatamgr/datamgr_service/test/fuzztest/taskscheduler_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
|
||||
sources = [ "taskscheduler_fuzzer.cpp" ]
|
||||
|
||||
deps = []
|
||||
|
||||
external_deps = [ "c_utils:utils" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":TaskSchedulerFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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
|
@ -1,25 +0,0 @@
|
||||
<?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>30</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* 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 "taskscheduler_fuzzer.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "task_scheduler.h"
|
||||
|
||||
namespace OHOS {
|
||||
static constexpr int MAX_DELAY_TIME = 5;
|
||||
static constexpr int MAX_INTERVAL_TIME = 3;
|
||||
void AtFuzz(size_t time)
|
||||
{
|
||||
TaskScheduler taskScheduler;
|
||||
std::chrono::steady_clock::time_point tp = std::chrono::steady_clock::now() +
|
||||
std::chrono::duration<int>(time % MAX_DELAY_TIME);
|
||||
auto task = taskScheduler.At(tp, []() { });
|
||||
std::this_thread::sleep_for(std::chrono::seconds(MAX_INTERVAL_TIME));
|
||||
taskScheduler.Remove(task);
|
||||
}
|
||||
|
||||
void EveryFUZZ(size_t time)
|
||||
{
|
||||
TaskScheduler taskScheduler;
|
||||
std::chrono::duration<int> delay(time % MAX_DELAY_TIME);
|
||||
std::chrono::duration<int> interval(time % MAX_INTERVAL_TIME);
|
||||
taskScheduler.Every(delay, interval, []() { });
|
||||
std::this_thread::sleep_for(std::chrono::seconds(MAX_INTERVAL_TIME));
|
||||
taskScheduler.Every(0, delay, interval, []() { });
|
||||
taskScheduler.Every(1, delay, interval, []() { });
|
||||
std::this_thread::sleep_for(std::chrono::seconds(MAX_INTERVAL_TIME));
|
||||
taskScheduler.Every(interval, []() { });
|
||||
taskScheduler.Clean();
|
||||
}
|
||||
|
||||
void ResetFuzz(size_t time)
|
||||
{
|
||||
TaskScheduler taskScheduler;
|
||||
std::chrono::duration<int> interval(time % MAX_INTERVAL_TIME);
|
||||
std::chrono::steady_clock::time_point tp1 = std::chrono::steady_clock::now() +
|
||||
std::chrono::duration<int>(MAX_DELAY_TIME / 2);
|
||||
auto schedulerTask = taskScheduler.At(tp1, []() {});
|
||||
taskScheduler.Reset(schedulerTask, interval);
|
||||
}
|
||||
} // namespace OHOS
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::AtFuzz(size);
|
||||
OHOS::EveryFUZZ(size);
|
||||
OHOS::ResetFuzz(size);
|
||||
return 0;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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 TASKSCHEDULER_FUZZER_H
|
||||
#define TASKSCHEDULER_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "taskscheduler_fuzzer"
|
||||
|
||||
#endif // TASKSCHEDULER_FUZZER_H
|
||||
|
@ -1,61 +0,0 @@
|
||||
# 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.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("TypesUtilFuzzTest") {
|
||||
module_out_path = "datamgr_service/distributeddatafwk"
|
||||
|
||||
include_dirs = [
|
||||
"ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/common",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src",
|
||||
"//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/kvdb/include",
|
||||
"//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
]
|
||||
|
||||
fuzz_config_file = "//foundation/distributeddatamgr/datamgr_service/test/fuzztest/typesutil_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
|
||||
sources = [ "typesutil_fuzzer.cpp" ]
|
||||
|
||||
deps = []
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"ipc:ipc_core",
|
||||
"kv_store:distributeddata_inner",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":TypesUtilFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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
|
@ -1,25 +0,0 @@
|
||||
<?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>30</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -1,177 +0,0 @@
|
||||
/*
|
||||
* 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 "typesutil_fuzzer.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "change_notification.h"
|
||||
#include "itypes_util.h"
|
||||
#include "kv_types_util.h"
|
||||
#include "types.h"
|
||||
|
||||
using namespace OHOS::DistributedKv;
|
||||
namespace OHOS {
|
||||
void ClientDevFuzz(const std::string &strBase)
|
||||
{
|
||||
DeviceInfo clientDev;
|
||||
clientDev.deviceId = strBase;
|
||||
clientDev.deviceName = strBase;
|
||||
clientDev.deviceType = strBase;
|
||||
MessageParcel parcel;
|
||||
ITypesUtil::Marshal(parcel, clientDev);
|
||||
DeviceInfo serverDev;
|
||||
ITypesUtil::Unmarshal(parcel, serverDev);
|
||||
}
|
||||
|
||||
void EntryFuzz(const std::string &strBase)
|
||||
{
|
||||
Entry entryIn;
|
||||
entryIn.key = strBase;
|
||||
entryIn.value = strBase;
|
||||
MessageParcel parcel;
|
||||
ITypesUtil::Marshal(parcel, entryIn);
|
||||
Entry entryOut;
|
||||
ITypesUtil::Unmarshal(parcel, entryOut);
|
||||
}
|
||||
|
||||
void BlobFuzz(const std::string &strBase)
|
||||
{
|
||||
Blob blobIn = strBase;
|
||||
MessageParcel parcel;
|
||||
ITypesUtil::Marshal(parcel, blobIn);
|
||||
Blob blobOut;
|
||||
ITypesUtil::Unmarshal(parcel, blobOut);
|
||||
}
|
||||
|
||||
void VecFuzz(const std::vector<uint8_t> &vec)
|
||||
{
|
||||
std::vector<uint8_t> vecIn(vec);
|
||||
MessageParcel parcel;
|
||||
ITypesUtil::Marshal(parcel, vecIn);
|
||||
std::vector<uint8_t> vecOut;
|
||||
ITypesUtil::Unmarshal(parcel, vecOut);
|
||||
}
|
||||
|
||||
void OptionsFuzz(const std::string &strBase)
|
||||
{
|
||||
Options optionsIn = {
|
||||
.createIfMissing = true,
|
||||
.encrypt = false,
|
||||
.autoSync = true,
|
||||
.kvStoreType = KvStoreType::SINGLE_VERSION
|
||||
};
|
||||
optionsIn.area = EL1;
|
||||
optionsIn.baseDir = strBase;
|
||||
MessageParcel parcel;
|
||||
ITypesUtil::Marshal(parcel, optionsIn);
|
||||
Options optionsOut;
|
||||
ITypesUtil::Unmarshal(parcel, optionsOut);
|
||||
}
|
||||
|
||||
void SyncPolicyFuzz(uint32_t base)
|
||||
{
|
||||
SyncPolicy syncPolicyIn { base, base };
|
||||
MessageParcel parcel;
|
||||
ITypesUtil::Marshal(parcel, syncPolicyIn);
|
||||
SyncPolicy syncPolicyOut;
|
||||
ITypesUtil::Unmarshal(parcel, syncPolicyOut);
|
||||
}
|
||||
|
||||
void ChangeNotificationFuzz(const std::string &strBase, bool boolBase)
|
||||
{
|
||||
Entry insert, update, del;
|
||||
insert.key = strBase;
|
||||
update.key = strBase;
|
||||
del.key = strBase;
|
||||
insert.value = strBase;
|
||||
update.value = strBase;
|
||||
del.value = strBase;
|
||||
std::vector<Entry> inserts, updates, deleteds;
|
||||
inserts.push_back(insert);
|
||||
updates.push_back(update);
|
||||
deleteds.push_back(del);
|
||||
|
||||
ChangeNotification changeIn(std::move(inserts), std::move(updates), std::move(deleteds), strBase, boolBase);
|
||||
MessageParcel parcel;
|
||||
ITypesUtil::Marshal(parcel, changeIn);
|
||||
std::vector<Entry> empty;
|
||||
ChangeNotification changeOut(std::move(empty), {}, {}, "", !boolBase);
|
||||
ITypesUtil::Unmarshal(parcel, changeOut);
|
||||
}
|
||||
|
||||
void IntFuzz(size_t valBase)
|
||||
{
|
||||
MessageParcel parcel;
|
||||
int32_t int32In = static_cast<int32_t>(valBase);
|
||||
ITypesUtil::Marshal(parcel, int32In);
|
||||
int32_t int32Out;
|
||||
ITypesUtil::Unmarshal(parcel, int32Out);
|
||||
|
||||
uint32_t uint32In = static_cast<uint32_t>(valBase);
|
||||
ITypesUtil::Marshal(parcel, uint32In);
|
||||
uint32_t uint32Out;
|
||||
ITypesUtil::Unmarshal(parcel, uint32Out);
|
||||
|
||||
uint64_t uint64In = static_cast<uint64_t>(valBase);
|
||||
ITypesUtil::Marshal(parcel, uint64In);
|
||||
uint64_t uint64Out;
|
||||
ITypesUtil::Unmarshal(parcel, uint64Out);
|
||||
}
|
||||
|
||||
void StringFuzz(const std::string &strBase)
|
||||
{
|
||||
MessageParcel parcel;
|
||||
std::string strIn = strBase;
|
||||
ITypesUtil::Marshal(parcel, strIn);
|
||||
std::string strOut;
|
||||
ITypesUtil::Unmarshal(parcel, strOut);
|
||||
}
|
||||
|
||||
void GetTotalSizeFuzz(const std::string &strBase, uint32_t size)
|
||||
{
|
||||
Entry entry;
|
||||
entry.key = strBase;
|
||||
entry.value = strBase;
|
||||
std::vector<Entry> VecEntryIn(size, entry);
|
||||
std::vector<Key> VecKeyIn(size, Key { strBase });
|
||||
ITypesUtil::GetTotalSize(VecEntryIn);
|
||||
ITypesUtil::GetTotalSize(VecKeyIn);
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
bool fuzzBool = ((size % 2) == 0);
|
||||
uint32_t fuzzUInt32 = static_cast<uint32_t>(size);
|
||||
std::string fuzzStr(reinterpret_cast<const char *>(data), size);
|
||||
std::vector<uint8_t> fuzzVec(fuzzStr.begin(), fuzzStr.end());
|
||||
|
||||
OHOS::ClientDevFuzz(fuzzStr);
|
||||
OHOS::EntryFuzz(fuzzStr);
|
||||
OHOS::BlobFuzz(fuzzStr);
|
||||
OHOS::VecFuzz(fuzzVec);
|
||||
OHOS::OptionsFuzz(fuzzStr);
|
||||
OHOS::SyncPolicyFuzz(fuzzUInt32);
|
||||
OHOS::ChangeNotificationFuzz(fuzzStr, fuzzBool);
|
||||
OHOS::IntFuzz(size);
|
||||
OHOS::StringFuzz(fuzzStr);
|
||||
OHOS::GetTotalSizeFuzz(fuzzStr, fuzzUInt32);
|
||||
return 0;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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 TYPESUTIL_FUZZER_H
|
||||
#define TYPESUTIL_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "TypesUtil_fuzzer"
|
||||
|
||||
#endif // TYPESUTIL_FUZZER_H
|
||||
|
Loading…
Reference in New Issue
Block a user