rusefi/unit_tests/test-framework/test_executor.cpp

61 lines
1.4 KiB
C++
Raw Normal View History

2018-12-08 15:11:28 -08:00
/*
2024-04-30 13:07:05 -07:00
* test_executor.cpp
2018-12-08 15:11:28 -08:00
*
* @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"
2024-04-30 13:05:13 -07:00
#include "test_executor.h"
2018-12-08 15:11:28 -08:00
2024-04-26 02:02:49 -07:00
bool debugSignalExecutor = false;
2018-12-08 15:11:28 -08:00
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();
}
int TestExecutor::executeAll(efitimeus_t nowUs) {
return schedulingQueue.executeAll(US2NT(nowUs));
}
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);
}
2024-07-11 17:03:13 -07:00
void TestExecutor::schedule(const char *msg, scheduling_s* scheduling, efitick_t timeNt, action_s action) {
if (m_mockExecutor) {
2024-07-11 17:03:13 -07:00
m_mockExecutor->schedule(msg, scheduling, timeNt, action);
return;
}
2024-04-30 13:22:05 -07:00
// by the way we have loss of precision while converting NT to integer US
2024-07-15 06:59:06 -07:00
// technical debt: looks like our unit tests were all created with us precision?
efitimeus_t timeUs = NT2US(timeNt);
schedulingQueue.insertTask(scheduling, US2NT(timeUs), action);
}
void TestExecutor::cancel(scheduling_s* s) {
if (m_mockExecutor) {
m_mockExecutor->cancel(s);
return;
}
schedulingQueue.remove(s);
}
2024-07-11 17:03:13 -07:00
void TestExecutor::setMockExecutor(Scheduler* exec) {
m_mockExecutor = exec;
}