mirror of
https://github.com/espressif/openthread.git
synced 2026-07-28 14:47:46 +00:00
[test] simplify unit test platform implementation (#6966)
This commit simplifies `test_platform` module which defines the platform APIs used by unit tests. It removes the unused global variables and the function pointer mechanism to override platform APIs. Instead the platform APIs in `test_platform` are defined as `OT_TOOL_WEAK` allowing individual tests to override any of the default implementation with their own version (e.g. `test_timer` provides its own alarm platform APIs).
This commit is contained in:
+25
-10
@@ -48,13 +48,15 @@ uint32_t sPlatDt;
|
||||
bool sTimerOn;
|
||||
uint32_t sCallCount[kCallCountIndexMax];
|
||||
|
||||
void testTimerAlarmStop(otInstance *)
|
||||
extern "C" {
|
||||
|
||||
void otPlatAlarmMilliStop(otInstance *)
|
||||
{
|
||||
sTimerOn = false;
|
||||
sCallCount[kCallCountIndexAlarmStop]++;
|
||||
}
|
||||
|
||||
void testTimerAlarmStartAt(otInstance *, uint32_t aT0, uint32_t aDt)
|
||||
void otPlatAlarmMilliStartAt(otInstance *, uint32_t aT0, uint32_t aDt)
|
||||
{
|
||||
sTimerOn = true;
|
||||
sCallCount[kCallCountIndexAlarmStart]++;
|
||||
@@ -62,18 +64,34 @@ void testTimerAlarmStartAt(otInstance *, uint32_t aT0, uint32_t aDt)
|
||||
sPlatDt = aDt;
|
||||
}
|
||||
|
||||
uint32_t testTimerAlarmGetNow(void)
|
||||
uint32_t otPlatAlarmMilliGetNow(void)
|
||||
{
|
||||
return sNow;
|
||||
}
|
||||
|
||||
void InitTestTimer(void)
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
|
||||
void otPlatAlarmMicroStop(otInstance *)
|
||||
{
|
||||
g_testPlatAlarmStop = testTimerAlarmStop;
|
||||
g_testPlatAlarmStartAt = testTimerAlarmStartAt;
|
||||
g_testPlatAlarmGetNow = testTimerAlarmGetNow;
|
||||
sTimerOn = false;
|
||||
sCallCount[kCallCountIndexAlarmStop]++;
|
||||
}
|
||||
|
||||
void otPlatAlarmMicroStartAt(otInstance *, uint32_t aT0, uint32_t aDt)
|
||||
{
|
||||
sTimerOn = true;
|
||||
sCallCount[kCallCountIndexAlarmStart]++;
|
||||
sPlatT0 = aT0;
|
||||
sPlatDt = aDt;
|
||||
}
|
||||
|
||||
uint32_t otPlatAlarmMicroGetNow(void)
|
||||
{
|
||||
return sNow;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // extern "C"
|
||||
|
||||
void InitCounters(void)
|
||||
{
|
||||
memset(sCallCount, 0, sizeof(sCallCount));
|
||||
@@ -137,7 +155,6 @@ template <typename TimerType> int TestOneTimer(void)
|
||||
// Test one Timer basic operation.
|
||||
|
||||
TestTimer<TimerType>::RemoveAll(*instance);
|
||||
InitTestTimer();
|
||||
InitCounters();
|
||||
|
||||
printf("TestOneTimer() ");
|
||||
@@ -263,7 +280,6 @@ template <typename TimerType> int TestTwoTimers(void)
|
||||
TestTimer<TimerType> timer2(*instance);
|
||||
|
||||
TestTimer<TimerType>::RemoveAll(*instance);
|
||||
InitTestTimer();
|
||||
printf("TestTwoTimers() ");
|
||||
|
||||
// Test when second timer stars at the fire time of first timer (before alarm callback).
|
||||
@@ -496,7 +512,6 @@ template <typename TimerType> static void TenTimers(uint32_t aTimeShift)
|
||||
// Start the Ten timers.
|
||||
|
||||
TestTimer<TimerType>::RemoveAll(*instance);
|
||||
InitTestTimer();
|
||||
InitCounters();
|
||||
|
||||
for (i = 0; i < kNumTimers; i++)
|
||||
|
||||
Reference in New Issue
Block a user