[LTP] [PATCH v1 23/31] testcases: sysfs: Add sys_net04

Li Wang li.wang@linux.dev
Wed Aug 19 04:27:55 CEST 2026


> Maybe we can add a polling mechanism with a timeout to wait for
> the operstate to transition.
> 
> --- a/testcases/kernel/sysfs/class/net/sys_net04.c
> +++ b/testcases/kernel/sysfs/class/net/sys_net04.c
> @@ -153,6 +153,12 @@ static void check_tun_vs_tap_type(void)
>         TST_SYSFS_EXP_EQ_LI(6, "/sys/class/net/" IFNAME_TAP "/addr_len");
>  }
> 
> +static int check_operstate(struct netdev_state *st, const char *expected_state)
> +{
> +       read_state(st);
> +       return strcmp(st->operstate, expected_state);
> +}
> +
>  static void run(void)
>  {
>         struct netdev_state s0, s1, s2;
> @@ -161,12 +167,14 @@ static void run(void)
>         check_state(&s0, 1, "up", "tun attached and up");
> 
>         SAFE_CLOSE(tun_fd);
> +       TST_RETRY_FUNC(check_operstate(&s1, "down"), !);

Using TST_RETVAL_EQ0 is easier to read:

  TST_RETRY_FUNC(check_operstate(&s1, "down"), TST_RETVAL_EQ0);

>         read_state(&s1);
>         check_state(&s1, 0, "down", "tun detached");
>         check_state_delta(&s0, &s1, 0, 1, "detach transition");
> 
>         tun_fd = open_tun(IFNAME_TUN, IFF_TUN | IFF_NO_PI);
>         read_state(&s2);
> +       TST_RETRY_FUNC(check_operstate(&s2, "up"), !);

  TST_RETRY_FUNC(check_operstate(&s2, "up"), TST_RETVAL_EQ0);

>         check_state(&s2, 1, "up", "tun reattached");
>         check_state_delta(&s1, &s2, 1, 0, "reattach transition");


-- 
Regards,
Li Wang


More information about the ltp mailing list