2018-12-08 15:11:28 -08:00
|
|
|
/*
|
|
|
|
* global_execution_queue.cpp
|
|
|
|
*
|
|
|
|
* @date Dec 8, 2018
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2018-12-08 15:11:28 -08:00
|
|
|
*/
|
|
|
|
|
2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2019-01-08 21:53:54 -08:00
|
|
|
#include "global_execution_queue.h"
|
2018-12-08 15:11:28 -08:00
|
|
|
|
|
|
|
bool_t debugSignalExecutor = false;
|
|
|
|
|
2020-07-31 14:41:29 -07:00
|
|
|
TestExecutor::~TestExecutor() {
|
|
|
|
// Flush the queue and reset all scheduling_s at the end of a test's execution
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2020-01-06 21:41:18 -08:00
|
|
|
void TestExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) {
|
2019-01-09 04:57:43 -08:00
|
|
|
if (debugSignalExecutor) {
|
|
|
|
printf("scheduleTask %d\r\n", delayUs);
|
|
|
|
}
|
2020-05-14 04:44:32 -07:00
|
|
|
|
|
|
|
if (m_mockExecutor) {
|
|
|
|
m_mockExecutor->scheduleForLater(scheduling, delayUs, action);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-14 13:03:00 -07:00
|
|
|
scheduleByTimestamp("test", scheduling, getTimeNowUs() + delayUs, action);
|
2019-01-09 04:57:43 -08:00
|
|
|
}
|
|
|
|
|
2019-01-09 16:52:01 -08:00
|
|
|
int TestExecutor::executeAll(efitime_t now) {
|
|
|
|
return schedulingQueue.executeAll(now);
|
|
|
|
}
|
2019-01-09 07:17:35 -08:00
|
|
|
|
|
|
|
void TestExecutor::clear() {
|
|
|
|
schedulingQueue.clear();
|
2019-01-08 21:53:54 -08:00
|
|
|
}
|
|
|
|
|
2019-01-09 07:36:35 -08:00
|
|
|
int TestExecutor::size() {
|
|
|
|
return schedulingQueue.size();
|
|
|
|
}
|
|
|
|
|
2020-07-20 09:45:26 -07:00
|
|
|
scheduling_s* TestExecutor::getHead() {
|
|
|
|
return schedulingQueue.getHead();
|
|
|
|
}
|
|
|
|
|
2019-01-09 13:42:34 -08:00
|
|
|
scheduling_s* TestExecutor::getForUnitTest(int index) {
|
2019-12-02 21:20:47 -08:00
|
|
|
return schedulingQueue.getElementAtIndexForUnitText(index);
|
2019-01-09 13:42:34 -08:00
|
|
|
}
|
|
|
|
|
2021-07-14 13:03:00 -07:00
|
|
|
void TestExecutor::scheduleByTimestamp(const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) {
|
2018-12-08 15:11:28 -08:00
|
|
|
if (debugSignalExecutor) {
|
2019-01-09 04:57:43 -08:00
|
|
|
printf("scheduleByTime %d\r\n", timeUs);
|
2018-12-08 15:11:28 -08:00
|
|
|
}
|
2020-05-14 04:44:32 -07:00
|
|
|
|
|
|
|
if (m_mockExecutor) {
|
2021-07-14 13:03:00 -07:00
|
|
|
m_mockExecutor->scheduleByTimestamp("test", scheduling, timeUs, action);
|
2020-05-14 04:44:32 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-06 21:41:18 -08:00
|
|
|
schedulingQueue.insertTask(scheduling, timeUs, action);
|
2018-12-08 15:11:28 -08:00
|
|
|
}
|
2020-01-09 12:45:13 -08:00
|
|
|
|
2021-07-14 13:03:00 -07:00
|
|
|
void TestExecutor::scheduleByTimestampNt(const char *msg, scheduling_s* scheduling, efitick_t timeNt, action_s action) {
|
2020-05-14 04:44:32 -07:00
|
|
|
if (m_mockExecutor) {
|
2021-07-14 13:03:00 -07:00
|
|
|
m_mockExecutor->scheduleByTimestampNt(msg, scheduling, timeNt, action);
|
2020-05-14 04:44:32 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-14 13:03:00 -07:00
|
|
|
scheduleByTimestamp("test", scheduling, NT2US(timeNt), action);
|
2020-01-09 12:45:13 -08:00
|
|
|
}
|
2020-05-14 04:44:32 -07:00
|
|
|
|
2021-08-27 01:30:06 -07:00
|
|
|
void TestExecutor::cancel(scheduling_s* s) {
|
|
|
|
if (m_mockExecutor) {
|
|
|
|
m_mockExecutor->cancel(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
schedulingQueue.remove(s);
|
|
|
|
}
|
|
|
|
|
2020-05-14 04:44:32 -07:00
|
|
|
void TestExecutor::setMockExecutor(ExecutorInterface* exec) {
|
|
|
|
m_mockExecutor = exec;
|
|
|
|
}
|