mirror of https://gerrit.osmocom.org/libosmocore
tests/fsm: also test .onenter and .onleave callbacks
Extend the existing testing coverage to check per-state enter/leave callbacks. An interesting behavior can be seen from the test output: when allocating an FSM instance, the .onenter callback is not being called for the initial FSM state (ST_NULL). Likewise, the .onleave callback is not being called when free()ing an FSM instance. Change-Id: I22edcf91375a09854f0dab1e2e02e034629310f7
This commit is contained in:
parent
1cfce70c8f
commit
477d99f7c9
|
@ -41,6 +41,18 @@ static const struct value_string test_fsm_event_names[] = {
|
||||||
{ 0, NULL }
|
{ 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void test_fsm_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
|
||||||
|
{
|
||||||
|
LOGPFSM(fi, "%s() prev_state=%s\n",
|
||||||
|
__func__, osmo_fsm_state_name(fi->fsm, prev_state));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_fsm_onleave(struct osmo_fsm_inst *fi, uint32_t next_state)
|
||||||
|
{
|
||||||
|
LOGPFSM(fi, "%s() next_state=%s\n",
|
||||||
|
__func__, osmo_fsm_state_name(fi->fsm, next_state));
|
||||||
|
}
|
||||||
|
|
||||||
static void test_fsm_null(struct osmo_fsm_inst *fi, uint32_t event, void *data)
|
static void test_fsm_null(struct osmo_fsm_inst *fi, uint32_t event, void *data)
|
||||||
{
|
{
|
||||||
switch (event) {
|
switch (event) {
|
||||||
|
@ -86,17 +98,23 @@ static struct osmo_fsm_state test_fsm_states[] = {
|
||||||
.out_state_mask = (1 << ST_ONE),
|
.out_state_mask = (1 << ST_ONE),
|
||||||
.name = "NULL",
|
.name = "NULL",
|
||||||
.action = test_fsm_null,
|
.action = test_fsm_null,
|
||||||
|
.onenter = test_fsm_onenter,
|
||||||
|
.onleave = test_fsm_onleave,
|
||||||
},
|
},
|
||||||
[ST_ONE]= {
|
[ST_ONE]= {
|
||||||
.in_event_mask = (1 << EV_B),
|
.in_event_mask = (1 << EV_B),
|
||||||
.out_state_mask = (1 << ST_TWO),
|
.out_state_mask = (1 << ST_TWO),
|
||||||
.name = "ONE",
|
.name = "ONE",
|
||||||
.action= test_fsm_one,
|
.action= test_fsm_one,
|
||||||
|
.onenter = test_fsm_onenter,
|
||||||
|
.onleave = test_fsm_onleave,
|
||||||
},
|
},
|
||||||
[ST_TWO]= {
|
[ST_TWO]= {
|
||||||
.in_event_mask = 0,
|
.in_event_mask = 0,
|
||||||
.name = "TWO",
|
.name = "TWO",
|
||||||
.action = NULL,
|
.action = NULL,
|
||||||
|
.onenter = test_fsm_onenter,
|
||||||
|
.onleave = test_fsm_onleave,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,13 @@ Test_FSM(my_id){NULL}: Allocated
|
||||||
Test_FSM(my_id){NULL}: Received Event EV_B
|
Test_FSM(my_id){NULL}: Received Event EV_B
|
||||||
Test_FSM(my_id){NULL}: Event EV_B not permitted
|
Test_FSM(my_id){NULL}: Event EV_B not permitted
|
||||||
Test_FSM(my_id){NULL}: Received Event EV_A
|
Test_FSM(my_id){NULL}: Received Event EV_A
|
||||||
|
Test_FSM(my_id){NULL}: test_fsm_onleave() next_state=ONE
|
||||||
Test_FSM(my_id){NULL}: State change to ONE (no timeout)
|
Test_FSM(my_id){NULL}: State change to ONE (no timeout)
|
||||||
|
Test_FSM(my_id){ONE}: test_fsm_onenter() prev_state=NULL
|
||||||
Test_FSM(my_id){ONE}: Received Event EV_B
|
Test_FSM(my_id){ONE}: Received Event EV_B
|
||||||
|
Test_FSM(my_id){ONE}: test_fsm_onleave() next_state=TWO
|
||||||
Test_FSM(my_id){ONE}: State change to TWO (T2342, 1s)
|
Test_FSM(my_id){ONE}: State change to TWO (T2342, 1s)
|
||||||
|
Test_FSM(my_id){TWO}: test_fsm_onenter() prev_state=ONE
|
||||||
Test_FSM(my_id){TWO}: Timeout of T2342
|
Test_FSM(my_id){TWO}: Timeout of T2342
|
||||||
Timer
|
Timer
|
||||||
Test_FSM(my_id){TWO}: Deallocated
|
Test_FSM(my_id){TWO}: Deallocated
|
||||||
|
@ -83,16 +87,24 @@ Test_FSM(arbitrary_id){NULL}: Deallocated
|
||||||
|
|
||||||
--- test_state_chg_keep_timer()
|
--- test_state_chg_keep_timer()
|
||||||
Test_FSM{NULL}: Allocated
|
Test_FSM{NULL}: Allocated
|
||||||
|
Test_FSM{NULL}: test_fsm_onleave() next_state=ONE
|
||||||
Test_FSM{NULL}: State change to ONE (no timeout)
|
Test_FSM{NULL}: State change to ONE (no timeout)
|
||||||
|
Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL
|
||||||
|
Test_FSM{ONE}: test_fsm_onleave() next_state=TWO
|
||||||
Test_FSM{ONE}: State change to TWO (no timeout)
|
Test_FSM{ONE}: State change to TWO (no timeout)
|
||||||
|
Test_FSM{TWO}: test_fsm_onenter() prev_state=ONE
|
||||||
Test_FSM{TWO}: Terminating (cause = OSMO_FSM_TERM_REQUEST)
|
Test_FSM{TWO}: Terminating (cause = OSMO_FSM_TERM_REQUEST)
|
||||||
Test_FSM{TWO}: Freeing instance
|
Test_FSM{TWO}: Freeing instance
|
||||||
Test_FSM{TWO}: Deallocated
|
Test_FSM{TWO}: Deallocated
|
||||||
Total time passed: 0.000000 s
|
Total time passed: 0.000000 s
|
||||||
Test_FSM{NULL}: Allocated
|
Test_FSM{NULL}: Allocated
|
||||||
|
Test_FSM{NULL}: test_fsm_onleave() next_state=ONE
|
||||||
Test_FSM{NULL}: State change to ONE (T10, 10s)
|
Test_FSM{NULL}: State change to ONE (T10, 10s)
|
||||||
|
Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL
|
||||||
Total time passed: 2.000342 s
|
Total time passed: 2.000342 s
|
||||||
|
Test_FSM{ONE}: test_fsm_onleave() next_state=TWO
|
||||||
Test_FSM{ONE}: State change to TWO (keeping T10, 7.999s remaining)
|
Test_FSM{ONE}: State change to TWO (keeping T10, 7.999s remaining)
|
||||||
|
Test_FSM{TWO}: test_fsm_onenter() prev_state=ONE
|
||||||
Total time passed: 2.000342 s
|
Total time passed: 2.000342 s
|
||||||
Total time passed: 9.999999 s
|
Total time passed: 9.999999 s
|
||||||
Total time passed: 10.000000 s
|
Total time passed: 10.000000 s
|
||||||
|
@ -104,14 +116,22 @@ Test_FSM{TWO}: Deallocated
|
||||||
|
|
||||||
--- test_state_chg_T()
|
--- test_state_chg_T()
|
||||||
Test_FSM{NULL}: Allocated
|
Test_FSM{NULL}: Allocated
|
||||||
|
Test_FSM{NULL}: test_fsm_onleave() next_state=ONE
|
||||||
Test_FSM{NULL}: State change to ONE (T42, 23s)
|
Test_FSM{NULL}: State change to ONE (T42, 23s)
|
||||||
|
Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL
|
||||||
|
Test_FSM{ONE}: test_fsm_onleave() next_state=TWO
|
||||||
Test_FSM{ONE}: State change to TWO (no timeout)
|
Test_FSM{ONE}: State change to TWO (no timeout)
|
||||||
|
Test_FSM{TWO}: test_fsm_onenter() prev_state=ONE
|
||||||
Test_FSM{TWO}: Terminating (cause = OSMO_FSM_TERM_REQUEST)
|
Test_FSM{TWO}: Terminating (cause = OSMO_FSM_TERM_REQUEST)
|
||||||
Test_FSM{TWO}: Freeing instance
|
Test_FSM{TWO}: Freeing instance
|
||||||
Test_FSM{TWO}: Deallocated
|
Test_FSM{TWO}: Deallocated
|
||||||
Test_FSM{NULL}: Allocated
|
Test_FSM{NULL}: Allocated
|
||||||
|
Test_FSM{NULL}: test_fsm_onleave() next_state=ONE
|
||||||
Test_FSM{NULL}: State change to ONE (T42, 23s)
|
Test_FSM{NULL}: State change to ONE (T42, 23s)
|
||||||
|
Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL
|
||||||
|
Test_FSM{ONE}: test_fsm_onleave() next_state=TWO
|
||||||
Test_FSM{ONE}: State change to TWO (no timeout)
|
Test_FSM{ONE}: State change to TWO (no timeout)
|
||||||
|
Test_FSM{TWO}: test_fsm_onenter() prev_state=ONE
|
||||||
Test_FSM{TWO}: Terminating (cause = OSMO_FSM_TERM_REQUEST)
|
Test_FSM{TWO}: Terminating (cause = OSMO_FSM_TERM_REQUEST)
|
||||||
Test_FSM{TWO}: Freeing instance
|
Test_FSM{TWO}: Freeing instance
|
||||||
Test_FSM{TWO}: Deallocated
|
Test_FSM{TWO}: Deallocated
|
||||||
|
@ -120,7 +140,9 @@ Test_FSM{TWO}: Deallocated
|
||||||
--- test_state_chg_Ts()
|
--- test_state_chg_Ts()
|
||||||
Total time passed: 0.000000 s
|
Total time passed: 0.000000 s
|
||||||
Test_FSM{NULL}: Allocated
|
Test_FSM{NULL}: Allocated
|
||||||
|
Test_FSM{NULL}: test_fsm_onleave() next_state=ONE
|
||||||
Test_FSM{NULL}: State change to ONE (T4242, 8s)
|
Test_FSM{NULL}: State change to ONE (T4242, 8s)
|
||||||
|
Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL
|
||||||
Total time passed: 3.000000 s
|
Total time passed: 3.000000 s
|
||||||
Total time passed: 5.500000 s
|
Total time passed: 5.500000 s
|
||||||
Total time passed: 8.000000 s
|
Total time passed: 8.000000 s
|
||||||
|
@ -133,7 +155,9 @@ Test_FSM{ONE}: Deallocated
|
||||||
--- test_state_chg_Tms()
|
--- test_state_chg_Tms()
|
||||||
Total time passed: 0.000000 s
|
Total time passed: 0.000000 s
|
||||||
Test_FSM{NULL}: Allocated
|
Test_FSM{NULL}: Allocated
|
||||||
|
Test_FSM{NULL}: test_fsm_onleave() next_state=ONE
|
||||||
Test_FSM{NULL}: State change to ONE (T4242, 1337ms)
|
Test_FSM{NULL}: State change to ONE (T4242, 1337ms)
|
||||||
|
Test_FSM{ONE}: test_fsm_onenter() prev_state=NULL
|
||||||
Total time passed: 0.500000 s
|
Total time passed: 0.500000 s
|
||||||
Total time passed: 0.750000 s
|
Total time passed: 0.750000 s
|
||||||
Total time passed: 1.100000 s
|
Total time passed: 1.100000 s
|
||||||
|
|
Loading…
Reference in New Issue