mirror of
https://gitee.com/openharmony/distributeddatamgr_kv_store
synced 2024-11-26 19:51:20 +00:00
update test/fuzztest/taskscheduler_fuzzer/taskscheduler_fuzzer.cpp.
Signed-off-by: suoqilong <suoqilong@huawei.com>
This commit is contained in:
parent
2cb021720a
commit
819e1a7bb9
@ -21,28 +21,23 @@
|
||||
#include "task_scheduler.h"
|
||||
|
||||
namespace OHOS {
|
||||
static constexpr int MIN_DELAY_TIME = 0;
|
||||
static constexpr int MAX_DELAY_TIME = 5;
|
||||
static constexpr int MIN_INTERVAL_TIME = 0;
|
||||
static constexpr int MAX_INTERVAL_TIME = 3;
|
||||
void AtFuzz(const uint8_t *data)
|
||||
void AtFuzz(int time)
|
||||
{
|
||||
TaskScheduler taskScheduler;
|
||||
int time = static_cast<int>(*data) % (MAX_DELAY_TIME - MIN_DELAY_TIME + 1) + MIN_DELAY_TIME;
|
||||
std::chrono::steady_clock::time_point tp = std::chrono::steady_clock::now() +
|
||||
std::chrono::duration<int>(time);
|
||||
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(const uint8_t *data)
|
||||
void EveryFUZZ(int time)
|
||||
{
|
||||
TaskScheduler taskScheduler;
|
||||
int time = static_cast<int>(*data) % (MAX_DELAY_TIME - MIN_DELAY_TIME + 1) + MIN_DELAY_TIME;
|
||||
std::chrono::duration<int> delay(time);
|
||||
time = static_cast<int>(*data) % (MAX_INTERVAL_TIME - MIN_INTERVAL_TIME + 1) + MIN_INTERVAL_TIME;
|
||||
std::chrono::duration<int> interval(time);
|
||||
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, []() { });
|
||||
@ -52,11 +47,10 @@ void EveryFUZZ(const uint8_t *data)
|
||||
taskScheduler.Clean();
|
||||
}
|
||||
|
||||
void ResetFuzz(const uint8_t *data)
|
||||
void ResetFuzz(int time)
|
||||
{
|
||||
TaskScheduler taskScheduler;
|
||||
int time = static_cast<int>(*data) % (MAX_INTERVAL_TIME - MIN_INTERVAL_TIME + 1) + MIN_INTERVAL_TIME;
|
||||
std::chrono::duration<int> interval(time);
|
||||
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, []() {});
|
||||
@ -67,8 +61,9 @@ void ResetFuzz(const uint8_t *data)
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::AtFuzz(data);
|
||||
OHOS::EveryFUZZ(data);
|
||||
OHOS::ResetFuzz(data);
|
||||
int time = static_cast<int>(*data);
|
||||
OHOS::AtFuzz(time);
|
||||
OHOS::EveryFUZZ(time);
|
||||
OHOS::ResetFuzz(time);
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user