unit tests run in US with a loss of precision from NT #6450

only: follow-up
This commit is contained in:
rusefi 2024-05-03 10:53:22 -04:00
parent 526445547b
commit 85f8598932
6 changed files with 19 additions and 26 deletions

View File

@ -62,7 +62,7 @@ void EventQueue::tryReturnScheduling(scheduling_s* sched) {
/**
* @return true if inserted into the head of the list
*/
bool EventQueue::insertTask(scheduling_s *scheduling, efitick_t timeX, action_s action) {
bool EventQueue::insertTask(scheduling_s *scheduling, efitick_t timeNt, action_s action) {
ScopePerf perf(PE::EventQueueInsertTask);
if (!scheduling) {
@ -84,17 +84,17 @@ bool EventQueue::insertTask(scheduling_s *scheduling, efitick_t timeX, action_s
if (scheduling->action) {
#if EFI_UNIT_TEST
if (verboseMode) {
printf("Already scheduled was %d\r\n", (int)scheduling->getMomentRaw());
printf("Already scheduled now %d\r\n", (int)timeX);
printf("Already scheduled was %d\r\n", (int)scheduling->getMomentNt());
printf("Already scheduled now %d\r\n", (int)timeNt);
}
#endif /* EFI_UNIT_TEST */
return false;
}
scheduling->setMomentX(timeX);
scheduling->setMomentNt(timeNt);
scheduling->action = action;
if (!m_head || timeX < m_head->getMomentNt()) {
if (!m_head || timeNt < m_head->getMomentNt()) {
// here we insert into head of the linked list
LL_PREPEND2(m_head, scheduling, nextScheduling_s);
assertListIsSorted();
@ -102,7 +102,7 @@ bool EventQueue::insertTask(scheduling_s *scheduling, efitick_t timeX, action_s
} else {
// here we know we are not in the head of the list, let's find the position - linear search
scheduling_s *insertPosition = m_head;
while (insertPosition->nextScheduling_s != NULL && insertPosition->nextScheduling_s->getMomentNt() < timeX) {
while (insertPosition->nextScheduling_s != NULL && insertPosition->nextScheduling_s->getMomentNt() < timeNt) {
insertPosition = insertPosition->nextScheduling_s;
}
@ -323,7 +323,7 @@ void EventQueue::clear(void) {
m_head = x->nextScheduling_s;
// Reset this element
x->setMomentX(0);
x->setMomentNt(0);
x->nextScheduling_s = nullptr;
x->action = {};
}

View File

@ -22,6 +22,6 @@ void * action_s::getArgument() const {
#if EFI_UNIT_TEST
efitick_t scheduling_s::getMomentUs() const {
return NT2US(momentX);
return NT2US(momentNt);
}
#endif

View File

@ -62,20 +62,15 @@ private:
#pragma pack(push, 4)
struct scheduling_s {
efitick_t getMomentNt() const {
return momentX;
return momentNt;
}
#if EFI_UNIT_TEST
efitick_t getMomentUs() const;
// todo: get rid of this 'I am not sure what's the proper type' method once we are done cleaning things up in unit tests
efitick_t getMomentRaw() const {
return momentX;
}
#endif
void setMomentX(efitick_t p_moment) {
momentX = p_moment;
void setMomentNt(efitick_t p_moment) {
momentNt = p_moment;
}
#if EFI_SIMULATOR
@ -92,10 +87,8 @@ struct scheduling_s {
/**
* timestamp represented as 64-bit value of ticks since MCU start
*/
// actually looks like this is ALWAYS or sometimes us these days?
// todo: make private with explicit getter/setter?
private:
volatile efitick_t momentX = 0;
volatile efitick_t momentNt = 0;
};
#pragma pack(pop)

View File

@ -96,8 +96,8 @@ public:
const AngleBasedEvent* assertTriggerEvent(const char *msg, int index, AngleBasedEvent *expected, void *callback, angle_t enginePhase);
void assertEvent(const char *msg, int index, void *callback, efitimeus_t momentUs, InjectionEvent *event);
void assertInjectorUpEvent(const char *msg, int eventIndex, efitimeus_t momentX, long injectorIndex);
void assertInjectorDownEvent(const char *msg, int eventIndex, efitimeus_t momentX, long injectorIndex);
void assertInjectorUpEvent(const char *msg, int eventIndex, efitimeus_t momentUs, long injectorIndex);
void assertInjectorDownEvent(const char *msg, int eventIndex, efitimeus_t momentUs, long injectorIndex);
// todo: open question if this is worth a helper method or should be inlined?
void assertRpm(int expectedRpm, const char *msg = "RPM");

View File

@ -96,10 +96,10 @@ TEST(EventQueue, complex) {
eq.insertTask(&s2, 11, callback);
ASSERT_EQ(4, eq.size());
ASSERT_EQ(10, eq.getHead()->getMomentRaw());
ASSERT_EQ(10, eq.getHead()->nextScheduling_s->getMomentRaw());
ASSERT_EQ(11, eq.getHead()->nextScheduling_s->nextScheduling_s->getMomentRaw());
ASSERT_EQ(12, eq.getHead()->nextScheduling_s->nextScheduling_s->nextScheduling_s->getMomentRaw());
ASSERT_EQ(10, eq.getHead()->getMomentNt());
ASSERT_EQ(10, eq.getHead()->nextScheduling_s->getMomentNt());
ASSERT_EQ(11, eq.getHead()->nextScheduling_s->nextScheduling_s->getMomentNt());
ASSERT_EQ(12, eq.getHead()->nextScheduling_s->nextScheduling_s->nextScheduling_s->getMomentNt());
callbackCounter = 0;
eq.executeAll(10);

View File

@ -299,7 +299,7 @@ TEST(HPFP, Schedule) {
// Since we have a mock scheduler, lets insert the correct timestamp in the scheduling
// struct.
hpfp.m_event.scheduling.setMomentX(nt1);
hpfp.m_event.scheduling.setMomentNt(nt1);
HpfpController::pinTurnOn(&hpfp);