[LTP] [PATCH v1 23/31] testcases: sysfs: Add sys_net04
Li Wang
li.wang@linux.dev
Wed Aug 19 04:13:12 CEST 2026
> +static void run(void)
> +{
> + struct netdev_state s0, s1, s2;
> +
> + read_state(&s0);
> + check_state(&s0, 1, "up", "tun attached and up");
> +
> + SAFE_CLOSE(tun_fd);
Here I got intermittent fails in local test:
sys_net_common.h:32: TFAIL: st->operstate (up) != operstate (down)
The possible reason is kernel asynchronous update race condition.
The test reads operstate immediately after closing the FD, catching
the stale "up" state before the kernel's background workqueue has
time to update it to "down".
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"), !);
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"), !);
check_state(&s2, 1, "up", "tun reattached");
check_state_delta(&s1, &s2, 1, 0, "reattach transition");
> + 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);
> + check_state(&s2, 1, "up", "tun reattached");
Here also fail:
sys_net_common.h:32: TFAIL: st->operstate (down) != operstate (up)
> + check_state_delta(&s1, &s2, 1, 0, "reattach transition");
> +
> + check_mtu_valid(68);
> + check_mtu_valid(1500);
> + check_mtu_valid(9000);
> + check_mtu_valid(65535);
> + check_mtu_invalid("-1");
> + check_mtu_invalid("0");
> + check_mtu_invalid("67");
> + check_mtu_invalid("70000");
> +
> + check_tun_flags();
> + check_owner_group();
> + check_tun_vs_tap_type();
> +}
--
Regards,
Li Wang
More information about the ltp
mailing list