[PATCH] libosmocore[master]: fsm_test: terminate the main loop instead of exit on timeout

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Mon Apr 9 00:51:11 UTC 2018


Review at  https://gerrit.osmocom.org/7679

fsm_test: terminate the main loop instead of exit on timeout

In fsm_test.c, we have FSM instance cleanup after the select main loop, but we
exit(0) in the timer cb; hence the final code is never called.

Rather clean up the instance and hence also test that, by using a global flag
to exit the main loop upon timeout.

Adjust expected stderr output.

BTW, in a subsequent commit, I want to move the fsm instance id testing to
below the main loop, to more clearly group the tested bits.

Change-Id: Ia47811ffcc1bd68d2630c86be7ab98fc1f338773
---
M tests/fsm/fsm_test.c
M tests/fsm/fsm_test.err
2 files changed, 7 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/79/7679/1

diff --git a/tests/fsm/fsm_test.c b/tests/fsm/fsm_test.c
index d7b08ae..ef7bfe3 100644
--- a/tests/fsm/fsm_test.c
+++ b/tests/fsm/fsm_test.c
@@ -60,13 +60,17 @@
 	}
 }
 
+static bool main_loop_run = true;
+
 static int test_fsm_tmr_cb(struct osmo_fsm_inst *fi)
 {
 	OSMO_ASSERT(fi->T == 2342);
 	OSMO_ASSERT(fi->state == ST_TWO);
 	LOGP(DMAIN, LOGL_INFO, "Timer\n");
 
-	exit(0);
+	main_loop_run = false;
+
+	return 0;
 }
 
 static struct osmo_fsm_state test_fsm_states[] = {
@@ -201,7 +205,7 @@
 	OSMO_ASSERT(osmo_fsm_inst_find_by_name(&fsm, "Test_FSM(another_id)") == finst);
 	OSMO_ASSERT(osmo_fsm_inst_update_id(finst, "my_id") == 0);
 
-	while (1) {
+	while (main_loop_run) {
 		osmo_select_main(0);
 	}
 	osmo_fsm_inst_free(finst);
diff --git a/tests/fsm/fsm_test.err b/tests/fsm/fsm_test.err
index 153963f..facc9f7 100644
--- a/tests/fsm/fsm_test.err
+++ b/tests/fsm/fsm_test.err
@@ -8,4 +8,5 @@
 Test_FSM(my_id){ONE}: state_chg to TWO
 Test_FSM(my_id){TWO}: Timeout of T2342
 Timer
+Test_FSM(my_id){TWO}: Deallocated
 
\ No newline at end of file

-- 
To view, visit https://gerrit.osmocom.org/7679
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia47811ffcc1bd68d2630c86be7ab98fc1f338773
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list