From 4585e6755dd569ab620c711f20a3d45d4ad87216 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 16 Apr 2017 17:23:56 +0200 Subject: osmo_fsm: Lookup functions to find FSM Instance by name or ID Introduce two lookup helper functions to resolve a fsm_instance based on the FSM and name or ID. Also, add related test cases. Change-Id: I707f3ed2795c28a924e64adc612d378c21baa815 --- tests/fsm/fsm_test.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests/fsm/fsm_test.c') diff --git a/tests/fsm/fsm_test.c b/tests/fsm/fsm_test.c index 7a644213..c3ab91c2 100644 --- a/tests/fsm/fsm_test.c +++ b/tests/fsm/fsm_test.c @@ -94,7 +94,7 @@ static struct osmo_fsm_inst *foo(void) struct osmo_fsm_inst *fi; LOGP(DMAIN, LOGL_INFO, "Checking FSM allocation\n"); - fi = osmo_fsm_inst_alloc(&fsm, g_ctx, NULL, LOGL_DEBUG, NULL); + fi = osmo_fsm_inst_alloc(&fsm, g_ctx, NULL, LOGL_DEBUG, "my_id"); OSMO_ASSERT(fi); OSMO_ASSERT(fi->fsm == &fsm); OSMO_ASSERT(!strncmp(osmo_fsm_inst_name(fi), fsm.name, strlen(fsm.name))); @@ -143,10 +143,16 @@ int main(int argc, char **argv) log_add_target(stderr_target); log_set_print_filename(stderr_target, 0); + g_ctx = NULL; + OSMO_ASSERT(osmo_fsm_find_by_name(fsm.name) == NULL); osmo_fsm_register(&fsm); + OSMO_ASSERT(osmo_fsm_find_by_name(fsm.name) == &fsm); + OSMO_ASSERT(osmo_fsm_inst_find_by_name(&fsm, "my_id") == NULL); finst = foo(); + OSMO_ASSERT(osmo_fsm_inst_find_by_id(&fsm, "my_id") == finst); + OSMO_ASSERT(osmo_fsm_inst_find_by_name(&fsm, "Test FSM(my_id)") == finst); while (1) { osmo_select_main(0); -- cgit v1.2.3