Unit test ErrDisengageIdler: make sure it never sets error while disengaging

pull/190/head
D.R.racer 2022-07-20 16:05:07 +02:00 committed by DRracer
parent 4e44447762
commit 3c3e625f39
5 changed files with 22 additions and 3 deletions

View File

@ -113,7 +113,8 @@ void FailedLoadToFinda(uint8_t slot, logic::LoadFilament &lf) {
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRDisengagingIdler));
// Stage 3 - disengaging idler in error mode
REQUIRE(WhileTopState(lf, ProgressCode::ERRDisengagingIdler, idlerEngageDisengageMaxSteps));
SimulateErrDisengagingIdler(lf, ErrorCode::FINDA_DIDNT_SWITCH_ON);
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRWaitingForUser));
}

View File

@ -1,3 +1,4 @@
#include "catch2/catch.hpp"
#include "main_loop_stub.h"
#include "homing.h"
@ -162,3 +163,17 @@ void SetFSensorStateAndDebounce(bool press) {
main_loop();
}
}
void SimulateErrDisengagingIdler(logic::CommandBase &cb, ErrorCode deferredEC) {
REQUIRE(WhileCondition(
cb, [&](uint32_t) {
if (cb.TopLevelState() == ProgressCode::ERRDisengagingIdler) {
REQUIRE(cb.Error() == ErrorCode::RUNNING); // ensure the error gets never set while disengaging the idler
return true;
} else {
REQUIRE(cb.Error() == deferredEC);
return false;
}
},
idlerEngageDisengageMaxSteps));
}

View File

@ -41,3 +41,5 @@ static constexpr uint32_t idlerEngageDisengageMaxSteps = 40000UL;
static constexpr uint32_t selectorMoveMaxSteps = 40000UL;
void HomeIdlerAndSelector();
void SimulateErrDisengagingIdler(logic::CommandBase &cb, ErrorCode deferredEC);

View File

@ -193,7 +193,8 @@ void ToolChangeFailLoadToFinda(logic::ToolChange &tc, uint8_t fromSlot, uint8_t
// should end up in error disengage idler
REQUIRE(VerifyState(tc, mg::FilamentLoadState::InSelector, toSlot, toSlot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRDisengagingIdler));
REQUIRE(WhileTopState(tc, ProgressCode::ERRDisengagingIdler, 5000));
SimulateErrDisengagingIdler(tc, ErrorCode::FINDA_DIDNT_SWITCH_ON);
}
void ToolChangeFailLoadToFindaLeftBtn(logic::ToolChange &tc, uint8_t toSlot) {

View File

@ -150,7 +150,7 @@ void FindaDidntTriggerCommonSetup(uint8_t slot, logic::UnloadFilament &uf) {
REQUIRE(VerifyState(uf, mg::FilamentLoadState::InSelector, slot, slot, true, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRDisengagingIdler));
// Stage 2 - idler should get disengaged
REQUIRE(WhileTopState(uf, ProgressCode::ERRDisengagingIdler, idlerEngageDisengageMaxSteps));
SimulateErrDisengagingIdler(uf, ErrorCode::FINDA_DIDNT_SWITCH_OFF);
// we still think we have filament loaded at this stage
// idler should have been disengaged