[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:
Abtin Keshavarzian
2021-08-30 12:07:17 -07:00
committed by GitHub
parent 03ec5af7b4
commit 57ade714a6
4 changed files with 130 additions and 394 deletions
+25 -10
View File
@@ -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++)