[fuzz] advance time before fuzz input enable to more services (#8243)

This commit is contained in:
Jonathan Hui
2022-10-06 08:54:00 -07:00
committed by GitHub
parent 4f57b8d461
commit 10de4c4f13
4 changed files with 80 additions and 49 deletions
+20 -11
View File
@@ -26,8 +26,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#define MAX_ITERATIONS 100
#include <stddef.h>
#include <openthread/instance.h>
@@ -38,9 +36,26 @@
#include <openthread/tasklet.h>
#include <openthread/thread.h>
#include <openthread/thread_ftd.h>
#include <openthread/platform/alarm-milli.h>
#include "fuzzer_platform.h"
#include "common/code_utils.hpp"
#include "common/time.hpp"
void AdvanceTime(otInstance *aInstance, uint32_t aDuration)
{
uint32_t time = otPlatAlarmMilliGetNow() + aDuration;
while (ot::TimeMilli(otPlatAlarmMilliGetNow()) <= ot::TimeMilli(time))
{
while (otTaskletsArePending(aInstance))
{
otTaskletsProcess(aInstance);
}
FuzzerPlatformProcess(aInstance);
}
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
@@ -62,6 +77,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
otSrpServerSetEnabled(instance, true);
IgnoreError(otThreadBecomeLeader(instance));
AdvanceTime(instance, 10000);
settings.mLinkSecurityEnabled = (data[0] & 0x1) != 0;
settings.mPriority = OT_MESSAGE_PRIORITY_NORMAL;
@@ -77,15 +94,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
VerifyOrExit(!FuzzerPlatformResetWasRequested());
for (int i = 0; i < MAX_ITERATIONS; i++)
{
while (otTaskletsArePending(instance))
{
otTaskletsProcess(instance);
}
FuzzerPlatformProcess(instance);
}
AdvanceTime(instance, 10000);
exit: