Files
behavior-tree/core/tests/proof_regression_test.cpp

9 lines
2.0 KiB
C++

#include "workflow_fixture.hpp"
#include <stdexcept>
struct ThrowWire: GoalDriver {unsigned sends=0,cancels=0;bool ready(Skill)const override{return true;}void send(const GoalRequest&)override{++sends;throw std::runtime_error("after-send exception");}void cancel(const std::string&)override{++cancels;}std::vector<GoalEvent> drain_events()override{return {};}};
int main(){
ThrowWire wire;ActiveGoalRegistry registry(wire,Fixture::test_root()+"/throw.journal");GoalRequest q;q.robot_id="r";q.trace={"t","s","run",1,1,1,1};auto id=registry.start(q,SteadyTime{});registry.request_cancel(*id,SteadyTime{});registry.pump(SteadyTime{}+Milliseconds(9000));assert(wire.cancels>=1);std::cout<<"send-throw sends="<<wire.sends<<" cancels="<<wire.cancels<<" locked="<<registry.robot_locked("r")<<"\n";
Fixture f("clock");auto runner=f.runner();assert(f.execute(runner)==TickStatus::SUCCESS);auto before=f.driver.now;runner.halt(SteadyTime{});runner.update_safety({true,true,Holding::EMPTY,1,1000000000});auto status=runner.settle(SteadyTime{},1);assert(status==TickStatus::INTERVENTION_REQUIRED);assert(!runner.empty_verified(1));std::cout<<"clock rollback from="<<before<<" to=1 settle_success="<<(status==TickStatus::SUCCESS)<<" empty_verified="<<runner.empty_verified(1)<<"\n";
Fixture e("expiry");auto er=e.runner();er.update_safety({true,true,Holding::EMPTY,1000000,9000000000});assert(er.tick(Stage::PREFLIGHT,SteadyTime{},1000000)==TickStatus::RUNNING);assert(er.tick(Stage::PREFLIGHT,SteadyTime{}+Milliseconds(1),2000000)==TickStatus::SUCCESS);e.driver.now=2000000000;er.update_safety({true,true,Holding::EMPTY,e.driver.now,e.driver.now+1000000000});bool proof=er.empty_verified(e.driver.now);auto nav=er.tick(Stage::NAVIGATE_OBSERVE,SteadyTime{}+Milliseconds(2),e.driver.now);assert(e.count(Skill::NAVIGATE)==0);assert(nav==TickStatus::RUNNING);std::cout<<"expired preflight empty_verified="<<proof<<" nav_count="<<e.count(Skill::NAVIGATE)<<" status_running="<<(nav==TickStatus::RUNNING)<<"\n";
}