From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 22/31] testcases: sysfs: Add sys_net03
Date: Thu, 27 Aug 2026 13:21:48 +0200 [thread overview]
Message-ID: <20260827112157.1748734-23-chrubis@suse.cz> (raw)
In-Reply-To: <20260827112157.1748734-1-chrubis@suse.cz>
A test for /sys/class/net/*/* files.
Similar to sys_net02 but checks bridge related files after briding a
virtual ethernet interface.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
runtest/sysfs | 1 +
testcases/kernel/sysfs/class/net/.gitignore | 1 +
testcases/kernel/sysfs/class/net/sys_net03.c | 145 +++++++++++++++++++
3 files changed, 147 insertions(+)
create mode 100644 testcases/kernel/sysfs/class/net/sys_net03.c
diff --git a/runtest/sysfs b/runtest/sysfs
index fee8a0b2b..b2cc0005c 100644
--- a/runtest/sysfs
+++ b/runtest/sysfs
@@ -17,3 +17,4 @@ sys_rtc01 sys_rtc01
sys_thermal01 sys_thermal01
sys_net01 sys_net01
sys_net02 sys_net02
+sys_net03 sys_net03
diff --git a/testcases/kernel/sysfs/class/net/.gitignore b/testcases/kernel/sysfs/class/net/.gitignore
index b70d02158..8c3782a3b 100644
--- a/testcases/kernel/sysfs/class/net/.gitignore
+++ b/testcases/kernel/sysfs/class/net/.gitignore
@@ -1,2 +1,3 @@
/sys_net01
/sys_net02
+/sys_net03
diff --git a/testcases/kernel/sysfs/class/net/sys_net03.c b/testcases/kernel/sysfs/class/net/sys_net03.c
new file mode 100644
index 000000000..eb8c484f4
--- /dev/null
+++ b/testcases/kernel/sysfs/class/net/sys_net03.c
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * Verifies that bridge port sysfs attributes correctly appear, hold sane
+ * values, and disappear again as a network device is enslaved to and
+ * released from a bridge.
+ *
+ * The test creates a bridge and a veth pair, then:
+ *
+ * - verifies /sys/class/net/<bridge>/brif/ is empty and
+ * /sys/class/net/<port>/brport does not exist before enslaving
+ * - enslaves one end of the veth pair to the bridge
+ * - verifies /sys/class/net/<bridge>/brif/<port> appears and
+ * /sys/class/net/<port>/brport/{state,priority,path_cost} hold sane values
+ * - verifies /sys/class/net/<bridge>/bridge/{stp_state,forward_delay} hold
+ * sane values
+ * - releases the port from the bridge
+ * - verifies /sys/class/net/<bridge>/brif/ is empty and
+ * /sys/class/net/<port>/brport does not exist again
+ *
+ * This needs root to create the bridge and veth devices.
+ */
+
+#include <limits.h>
+#include <string.h>
+#include <dirent.h>
+#include <unistd.h>
+
+#include "tst_test.h"
+#include "tst_netdevice.h"
+#include "tst_sysfs_assert.h"
+#include "tst_path_defs.h"
+
+#define BRNAME "ltp_br0"
+#define IFNAME1 "ltp_vethb1"
+#define IFNAME2 "ltp_vethb2"
+
+#define BR_PATH PATH_CLASS_NET "/" BRNAME
+#define PORT_PATH PATH_CLASS_NET "/" IFNAME1
+
+static int bridge_created;
+static int veth_created;
+
+static int count_dir_entries(const char *path)
+{
+ DIR *d;
+ struct dirent *ent;
+ int count = 0;
+
+ d = TST_SYSFS_TRY_OPENDIR(path);
+
+ while ((ent = SAFE_READDIR(d))) {
+ if (ent->d_name[0] == '.')
+ continue;
+
+ count++;
+ }
+
+ SAFE_CLOSEDIR(d);
+
+ return count;
+}
+
+static void setup(void)
+{
+ NETDEV_ADD_DEVICE(BRNAME, "bridge");
+ bridge_created = 1;
+
+ CREATE_VETH_PAIR(IFNAME1, IFNAME2);
+ veth_created = 1;
+
+ NETDEV_SET_STATE(BRNAME, 1);
+ NETDEV_SET_STATE(IFNAME1, 1);
+ NETDEV_SET_STATE(IFNAME2, 1);
+}
+
+static void check_not_enslaved(const char *desc)
+{
+ int nports = count_dir_entries(BR_PATH "/brif");
+
+ tst_res(TINFO, "%s", desc);
+
+ TST_EXP_EQ_LI(nports, 0);
+
+ if (access(PORT_PATH "/brport", F_OK))
+ tst_res(TPASS, PORT_PATH "/brport does not exist");
+ else
+ tst_res(TFAIL, PORT_PATH "/brport unexpectedly exists");
+}
+
+static void check_enslaved(void)
+{
+ int nports = count_dir_entries(BR_PATH "/brif");
+
+ tst_res(TINFO, "port enslaved to bridge");
+
+ TST_EXP_EQ_LI(nports, 1);
+
+ if (!access(BR_PATH "/brif/" IFNAME1, F_OK))
+ tst_res(TPASS, BR_PATH "/brif/" IFNAME1 " exists");
+ else
+ tst_res(TFAIL, BR_PATH "/brif/" IFNAME1 " does not exist");
+
+ TST_SYSFS_ASSERT_RANGELL(0, 4, PORT_PATH "/brport/state");
+ TST_SYSFS_ASSERT_RANGELL(0, 255, PORT_PATH "/brport/priority");
+ TST_SYSFS_ASSERT_RANGELL(1, LONG_MAX, PORT_PATH "/brport/path_cost");
+
+ TST_SYSFS_ASSERT_RANGELL(0, 2, BR_PATH "/bridge/stp_state");
+ TST_SYSFS_ASSERT_RANGELL(1, LONG_MAX, BR_PATH "/bridge/forward_delay");
+}
+
+static void run(void)
+{
+ check_not_enslaved("before enslaving");
+
+ NETDEV_SET_MASTER(IFNAME1, BRNAME);
+ check_enslaved();
+
+ NETDEV_SET_MASTER(IFNAME1, NULL);
+ check_not_enslaved("after releasing");
+}
+
+static void cleanup(void)
+{
+ if (veth_created)
+ NETDEV_REMOVE_DEVICE(IFNAME1);
+
+ if (bridge_created)
+ NETDEV_REMOVE_DEVICE(BRNAME);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_root = 1,
+ .needs_kconfigs = (const char *const[]){
+ "CONFIG_VETH",
+ "CONFIG_BRIDGE",
+ NULL
+ },
+};
--
2.54.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-08-27 11:28 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 11:21 [LTP] [PATCH v3 00/31] Add sysfs sanity tests Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 01/31] lib: Add tst_sysfs_assert Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 02/31] testcases: sysfs: Add sys_power01 Cyril Hrubis
2026-08-27 14:04 ` [LTP] lib: Add tst_sysfs_assert linuxtestproject.agent
2026-08-27 11:21 ` [LTP] [PATCH v4 03/31] testcases: sysfs: Add sys_kernel01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 04/31] testcases: sysfs: Add sys_clocksource01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 05/31] testcases: sysfs: Add sys_node01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 06/31] testcases: sysfs: Add sys_cpu_topology01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 07/31] testcases: sysfs: Add sys_cpu_topology02 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 08/31] testcases: sysfs: Add sys_cpu_vulnerabilities01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 09/31] testcases: sysfs: Add sys_cpu_smt01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 10/31] testcases: sysfs: Add sys_cpu_cache01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 11/31] testcases: sysfs: Add sys_clockevents01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 12/31] testcases: sysfs: Add sys_ata01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 13/31] testcases: sysfs: Add sys_bdi01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 14/31] testcases: sysfs: sys_hwmon01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 15/31] testcases: sysfs: sys_leds01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 16/31] testcases: sysfs: Add sys_wakeup01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 17/31] testcases: sysfs: Add sys_rtc01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 18/31] testcases: sysfs: Add sys_thermal01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 19/31] tst_netdevice: Add two more helper macros Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 20/31] testcases: sysfs: Add sys_net01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 21/31] testcases: sysfs: Add sys_net02 Cyril Hrubis
2026-08-27 11:21 ` Cyril Hrubis [this message]
2026-08-27 11:21 ` [LTP] [PATCH v4 23/31] testcases: sysfs: Add sys_net04 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 24/31] testcases: sysfs: Add sys_block_loop01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 25/31] testcases: sysfs: Add sys_block_queue01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 26/31] testcases: sysfs: Add sys_block_size01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 27/31] testcases: sysfs: Add sys_hugepages01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 28/31] testcases: sysfs: Add sys_hugepages02 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 29/31] testcases: sysfs: Add sys_ksm01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 30/31] testcases: sysfs: Add sys_mm_swap01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 31/31] testcases: sysfs: Add sys_thp01 Cyril Hrubis
2026-08-28 8:32 ` [LTP] [PATCH v3 00/31] Add sysfs sanity tests Li Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260827112157.1748734-23-chrubis@suse.cz \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.