fixeria has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/28649 )
Change subject: fsm: fix state_chg(): pass microseconds to osmo_timer_schedule() ......................................................................
fsm: fix state_chg(): pass microseconds to osmo_timer_schedule()
As was demonstrated in [1], osmo_fsm_inst_state_chg_ms() is broken. The problem is in state_chg(): this function is passing *milli*seconds to osmo_timer_schedule(), while it expects *micro*seconds.
Change-Id: Ib0b6c3bdb56e4279df9e5ba7db16841645c452aa Related: [1] I5a35730a8448292b075aefafed897353678250f9 Fixes: I35b330e460e80bb67376c77e997e464439ac5397 Fixes: OS#5622 --- M src/fsm.c M tests/fsm/fsm_test.c M tests/fsm/fsm_test.err 3 files changed, 9 insertions(+), 8 deletions(-)
Approvals: Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve dexter: Looks good to me, approved
diff --git a/src/fsm.c b/src/fsm.c index 8b0b27b..b51c5cb 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -685,8 +685,11 @@ if (!keep_timer || (keep_timer && !osmo_timer_pending(&fi->timer))) { fi->T = T; - if (timeout_ms) - osmo_timer_schedule(&fi->timer, timeout_ms / 1000, timeout_ms % 1000); + if (timeout_ms) { + osmo_timer_schedule(&fi->timer, + /* seconds */ (timeout_ms / 1000), + /* microseconds */ (timeout_ms % 1000) * 1000); + } }
/* Call 'onenter' last, user might terminate FSM from there */ diff --git a/tests/fsm/fsm_test.c b/tests/fsm/fsm_test.c index ec31dd2..6fa0ae7 100644 --- a/tests/fsm/fsm_test.c +++ b/tests/fsm/fsm_test.c @@ -441,15 +441,13 @@ OSMO_ASSERT(timeout_fired == -1);
fake_time_passes(0, 350000); /* +350ms, 1s 100ms total */ - /* OSMO_ASSERT(timeout_fired == -1); */ - - /* FIXME: the timeout expires here, earlier than expected */ + OSMO_ASSERT(timeout_fired == -1);
fake_time_passes(0, 200000); /* +200ms, 1s 300ms total */ - /* OSMO_ASSERT(timeout_fired == -1); */ + OSMO_ASSERT(timeout_fired == -1);
fake_time_passes(0, 37000); /* +37ms, 1s 337ms total */ - /* OSMO_ASSERT(timeout_fired == 4242); */ + OSMO_ASSERT(timeout_fired == 4242);
osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REQUEST, NULL);
diff --git a/tests/fsm/fsm_test.err b/tests/fsm/fsm_test.err index f140d2e..51bf5da 100644 --- a/tests/fsm/fsm_test.err +++ b/tests/fsm/fsm_test.err @@ -137,9 +137,9 @@ Total time passed: 0.500000 s Total time passed: 0.750000 s Total time passed: 1.100000 s -Test_FSM{ONE}: Timeout of T4242 Total time passed: 1.300000 s Total time passed: 1.337000 s +Test_FSM{ONE}: Timeout of T4242 Test_FSM{ONE}: Terminating (cause = OSMO_FSM_TERM_REQUEST) Test_FSM{ONE}: Freeing instance Test_FSM{ONE}: Deallocated