rusefi/unit_tests/test-framework/global_execution_queue.cpp

85 lines
2.0 KiB
C++
Raw Normal View History

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
*/
#include "pch.h"
#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();
}
void TestExecutor::scheduleForLater(const char *msg, scheduling_s *scheduling, int delayUs, action_s action) {
if (debugSignalExecutor) {
printf("scheduleTask %d\r\n", delayUs);
}
if (m_mockExecutor) {
m_mockExecutor->scheduleForLater(msg, scheduling, delayUs, action);
return;
}
scheduleByTimestamp("test", scheduling, getTimeNowUs() + delayUs, action);
}
int TestExecutor::executeAll(efitick_t now) {
return schedulingQueue.executeAll(now);
}
void TestExecutor::clear() {
schedulingQueue.clear();
}
int TestExecutor::size() {
return schedulingQueue.size();
}
scheduling_s* TestExecutor::getHead() {
return schedulingQueue.getHead();
}
scheduling_s* TestExecutor::getForUnitTest(int index) {
2019-12-02 21:20:47 -08:00
return schedulingQueue.getElementAtIndexForUnitText(index);
}
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) {
printf("scheduleByTime %d\r\n", timeUs);
2018-12-08 15:11:28 -08:00
}
if (m_mockExecutor) {
m_mockExecutor->scheduleByTimestamp("test", scheduling, timeUs, action);
return;
}
schedulingQueue.insertTask(scheduling, timeUs, action);
2018-12-08 15:11:28 -08:00
}
void TestExecutor::scheduleByTimestampNt(const char *msg, scheduling_s* scheduling, efitick_t timeNt, action_s action) {
if (m_mockExecutor) {
m_mockExecutor->scheduleByTimestampNt(msg, scheduling, timeNt, action);
return;
}
scheduleByTimestamp("test", scheduling, NT2US(timeNt), action);
}
void TestExecutor::cancel(scheduling_s* s) {
if (m_mockExecutor) {
m_mockExecutor->cancel(s);
return;
}
schedulingQueue.remove(s);
}
void TestExecutor::setMockExecutor(ExecutorInterface* exec) {
m_mockExecutor = exec;
}