Skip to content

Commit 2ac66bc

Browse files
jukkarkartben
authored andcommitted
tests: net: if: Add tests for operational state change time
Make sure that the operational state change time is updated correctly. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
1 parent 262e777 commit 2ac66bc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/net/iface/src/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ static void *iface_setup(void)
328328
struct net_if_mcast_addr *maddr;
329329
struct net_if_addr *ifaddr;
330330
const struct device *dev;
331+
int64_t oper_state_change_time = -1LL, later_time = -1LL;
331332
bool status;
332333
int idx, ret;
333334

@@ -336,6 +337,12 @@ static void *iface_setup(void)
336337

337338
net_if_foreach(iface_cb, NULL);
338339

340+
/* Make sure the operational state change time is set properly */
341+
ret = net_if_oper_state_change_time(iface1, &oper_state_change_time);
342+
zassert_equal(ret, 0, "Cannot get oper state change time");
343+
zassert_equal(oper_state_change_time, 0,
344+
"Invalid oper state change time");
345+
339346
idx = net_if_get_by_iface(iface1);
340347
((struct net_if_test *)
341348
net_if_get_device(iface1)->data)->idx = idx;
@@ -381,6 +388,11 @@ static void *iface_setup(void)
381388
dev->state->init_res = 0;
382389
device_ok = true;
383390

391+
/* We need to sleep a bit to let the interface
392+
* operational state change time to be set.
393+
*/
394+
k_sleep(K_MSEC(10));
395+
384396
ret = net_if_up(iface1);
385397
zassert_equal(ret, 0, "Interface 1 is not up (%d)", ret);
386398

@@ -463,6 +475,14 @@ static void *iface_setup(void)
463475
net_if_up(iface3);
464476
net_if_up(iface4);
465477

478+
ret = net_if_oper_state_change_time(iface1, &later_time);
479+
zassert_equal(ret, 0, "Cannot get oper state change time");
480+
zassert_not_equal(later_time, 0,
481+
"Invalid oper state change time");
482+
zassert_true(later_time >= oper_state_change_time,
483+
"Invalid oper state change time %" PRId64 " vs %" PRId64,
484+
later_time, oper_state_change_time);
485+
466486
/* The interface might receive data which might fail the checks
467487
* in the iface sending function, so we need to reset the failure
468488
* flag.

0 commit comments

Comments
 (0)