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
This commit is contained in:
Vadim Yanitskiy 2022-07-19 06:20:55 +07:00
parent d2964a94c2
commit 76bdbd4b2b
3 changed files with 9 additions and 8 deletions

View File

@ -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 */

View File

@ -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);

View File

@ -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