mirror of
https://github.com/espressif/openthread.git
synced 2026-07-31 08:07:47 +00:00
[fuzz] advance alarm time to cover timer handlers (#3710)
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define MAX_ITERATIONS 100
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -41,6 +43,7 @@
|
||||
#include "common/code_utils.hpp"
|
||||
|
||||
extern "C" void FuzzerPlatformInit(void);
|
||||
extern "C" void FuzzerPlatformProcess(otInstance *aInstance);
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
@@ -66,9 +69,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
|
||||
otPlatUartReceived(buf, (uint16_t)size);
|
||||
|
||||
while (otTaskletsArePending(instance))
|
||||
for (int i = 0; i < MAX_ITERATIONS; i++)
|
||||
{
|
||||
otTaskletsProcess(instance);
|
||||
while (otTaskletsArePending(instance))
|
||||
{
|
||||
otTaskletsProcess(instance);
|
||||
}
|
||||
|
||||
FuzzerPlatformProcess(instance);
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <openthread/platform/alarm-micro.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
#include <openthread/platform/diag.h>
|
||||
#include <openthread/platform/logging.h>
|
||||
@@ -37,6 +38,15 @@
|
||||
#include <openthread/platform/settings.h>
|
||||
#include <openthread/platform/uart.h>
|
||||
|
||||
typedef struct AlarmState
|
||||
{
|
||||
uint32_t fire;
|
||||
bool isRunning;
|
||||
} AlarmState;
|
||||
|
||||
static uint32_t sAlarmNow;
|
||||
static AlarmState sAlarmMilli;
|
||||
static AlarmState sAlarmMicro;
|
||||
static uint32_t sRandomState = 1;
|
||||
static uint8_t sRadioTransmitPsdu[OT_RADIO_FRAME_MAX_SIZE];
|
||||
static otRadioFrame sRadioTransmitFrame = {.mPsdu = sRadioTransmitPsdu};
|
||||
@@ -44,40 +54,83 @@ static otRadioFrame sRadioTransmitFrame = {.mPsdu = sRadioTransmitPsdu};
|
||||
void FuzzerPlatformInit(void)
|
||||
{
|
||||
sRandomState = 1;
|
||||
sAlarmNow = 0;
|
||||
memset(&sAlarmMilli, 0, sizeof(sAlarmMilli));
|
||||
memset(&sAlarmMicro, 0, sizeof(sAlarmMicro));
|
||||
}
|
||||
|
||||
void FuzzerPlatformProcess(otInstance *aInstance)
|
||||
{
|
||||
if (sAlarmMilli.isRunning || sAlarmMicro.isRunning)
|
||||
{
|
||||
uint32_t fire = UINT32_MAX;
|
||||
|
||||
if (sAlarmMilli.isRunning && fire > sAlarmMilli.fire)
|
||||
{
|
||||
fire = sAlarmMilli.fire;
|
||||
}
|
||||
|
||||
if (sAlarmMicro.isRunning && fire > sAlarmMicro.fire)
|
||||
{
|
||||
fire = sAlarmMicro.fire;
|
||||
}
|
||||
|
||||
sAlarmNow = fire;
|
||||
|
||||
if (sAlarmMilli.isRunning && sAlarmNow >= sAlarmMilli.fire)
|
||||
{
|
||||
sAlarmMilli.isRunning = false;
|
||||
otPlatAlarmMilliFired(aInstance);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER
|
||||
if (sAlarmMicro.isRunning && sAlarmNow >= sAlarmMicro.fire)
|
||||
{
|
||||
sAlarmMicro.isRunning = false;
|
||||
otPlatAlarmMicroFired(aInstance);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t otPlatAlarmMilliGetNow(void)
|
||||
{
|
||||
return 0;
|
||||
return sAlarmNow / 1000;
|
||||
}
|
||||
|
||||
void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aT0);
|
||||
OT_UNUSED_VARIABLE(aDt);
|
||||
|
||||
sAlarmMilli.fire = (aT0 + aDt) * 1000;
|
||||
sAlarmMilli.isRunning = true;
|
||||
}
|
||||
|
||||
void otPlatAlarmMilliStop(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
sAlarmMilli.isRunning = false;
|
||||
}
|
||||
|
||||
uint32_t otPlatAlarmMicroGetNow(void)
|
||||
{
|
||||
return 0;
|
||||
return sAlarmNow;
|
||||
}
|
||||
|
||||
void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aT0);
|
||||
OT_UNUSED_VARIABLE(aDt);
|
||||
|
||||
sAlarmMicro.fire = aT0 + aDt;
|
||||
sAlarmMicro.isRunning = true;
|
||||
}
|
||||
|
||||
void otPlatAlarmMicroStop(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
sAlarmMicro.isRunning = false;
|
||||
}
|
||||
|
||||
bool otDiagIsEnabled(void)
|
||||
|
||||
Reference in New Issue
Block a user