diff --git a/src/fsm.c b/src/fsm.c index 8b0b27beb..b51c5cbf6 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -685,8 +685,11 @@ static int state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, 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 ec31dd2e5..6fa0ae718 100644 --- a/tests/fsm/fsm_test.c +++ b/tests/fsm/fsm_test.c @@ -441,15 +441,13 @@ static void test_state_chg_Tms(void) 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 f140d2e75..51bf5da3d 100644 --- a/tests/fsm/fsm_test.err +++ b/tests/fsm/fsm_test.err @@ -137,9 +137,9 @@ Test_FSM{NULL}: State change to ONE (T4242, 1337ms) 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