Add logging and testing for FSM deallocation

osmo_fsm_inst_alloc() logs allocation but osmo_fsm_inst_free() is
silent. Fix this by adding log message for deallocation to make FSM
lifecycle tracking easier. Also make sure it's covered by test suite.

Change-Id: I7e5b55a1fff8e36cf61c7fb61d3e79c1f00e29d2
This commit is contained in:
Max 2016-11-02 10:37:58 +01:00 committed by Harald Welte
parent e9e5f8e4e9
commit 3de97e1926
2 changed files with 6 additions and 4 deletions

View File

@ -233,6 +233,7 @@ struct osmo_fsm_inst *osmo_fsm_inst_alloc_child(struct osmo_fsm *fsm,
*/
void osmo_fsm_inst_free(struct osmo_fsm_inst *fi)
{
LOGPFSM(fi, "Deallocated\n");
osmo_timer_del(&fi->timer);
llist_del(&fi->list);
talloc_free(fi);

View File

@ -89,7 +89,7 @@ static struct osmo_fsm fsm = {
.log_subsys = DMAIN,
};
static int foo(void)
static struct osmo_fsm_inst *foo(void)
{
struct osmo_fsm_inst *fi;
@ -115,7 +115,7 @@ static int foo(void)
OSMO_ASSERT(fi->state == ST_TWO);
return 0;
return fi;
}
static const struct log_info_cat default_categories[] = {
@ -134,6 +134,7 @@ static const struct log_info log_info = {
int main(int argc, char **argv)
{
struct log_target *stderr_target;
struct osmo_fsm_inst *finst;
osmo_fsm_log_addr(false);
@ -145,12 +146,12 @@ int main(int argc, char **argv)
g_ctx = NULL;
osmo_fsm_register(&fsm);
foo();
finst = foo();
while (1) {
osmo_select_main(0);
}
osmo_fsm_inst_free(finst);
osmo_fsm_unregister(&fsm);
exit(0);
}