libosmocore/tests/fsm
Neels Hofmeyr b1bbe24c09 fsm: refuse state chg and events after term
Refuse state changes and event dispatch for FSM instances that are already
terminating.

It is assumed that refusing state changes and events after FSM termination is
seen as the sane expected behavior, hence this change in behavior is merged
without being configurable.

There is no fallout in current Osmocom code trees. fsm_dealloc_test needs a
changed expected output, since it is explicitly creating complex FSM structures
that terminate. Currently no other C test in Osmocom code needs adjusting.

Rationale:

Where multiple FSM instances are collaborating (like in osmo-bsc or osmo-msc),
a terminating FSM instance often causes events to be dispatched back to itself,
or causes state changes in FSM instances that are already terminating. That is
hard to avoid, since each FSM instance could be a cause of failure, and wants
to notify all the others of that, which in turn often choose to terminate.

Another use case: any function that dispatches events or state changes to more
than one FSM instance must be sure that after the first event dispatch, the
second FSM instance is in fact still allocated. Furthermore, if the second FSM
instance *has* terminated from the first dispatch, this often means that no
more actions should be taken. That could be done by an explicit check for
fsm->proc.terminating, but a more general solution is to do this check
internally in fsm.c.

In practice, I need this to avoid a crash in libosmo-mgcp-client, when an
on_success() event dispatch causes the MGCP endpoint FSM to deallocate. The
earlier dealloc-in-main-loop patch fixed part of it, but not all.

Change-Id: Ia81a0892f710db86bd977462730b69f0dcc78f8c
2019-10-29 17:28:30 +01:00
..
fsm_dealloc_test.c add osmo_fsm_set_dealloc_ctx(), to help with use-after-free 2019-10-29 16:46:04 +01:00
fsm_dealloc_test.err fsm: refuse state chg and events after term 2019-10-29 17:28:30 +01:00
fsm_test.c log: fsm: allow logging the timeout on state change 2019-02-26 20:57:58 +00:00
fsm_test.err log: fsm: allow logging the timeout on state change 2019-02-26 20:57:58 +00:00
fsm_test.ok osmo_fsm_inst_state_chg(): set T also for zero timeout 2019-01-29 10:25:26 +00:00