All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] support/testing: wpa_supplicant: new runtime test
@ 2026-08-18 22:41 Julien Olivain via buildroot
  2026-08-27 21:09 ` Julien Olivain via buildroot
  0 siblings, 1 reply; 2+ messages in thread
From: Julien Olivain via buildroot @ 2026-08-18 22:41 UTC (permalink / raw)
  To: buildroot; +Cc: Julien Olivain

Signed-off-by: Julien Olivain <ju.o@free.fr>
---
Patch tested in:
https://gitlab.com/jolivain/buildroot/-/jobs/15968993900
---
 DEVELOPERS                                    |   2 +
 .../tests/package/test_wpa_supplicant.py      | 121 ++++++++++++++++++
 .../linux-mac80211-hwsim.fragment             |   3 +
 .../rootfs-overlay/etc/hostapd.conf           |  14 ++
 .../rootfs-overlay/etc/wpa_supplicant.conf    |  13 ++
 5 files changed, 153 insertions(+)
 create mode 100644 support/testing/tests/package/test_wpa_supplicant.py
 create mode 100644 support/testing/tests/package/test_wpa_supplicant/linux-mac80211-hwsim.fragment
 create mode 100644 support/testing/tests/package/test_wpa_supplicant/rootfs-overlay/etc/hostapd.conf
 create mode 100644 support/testing/tests/package/test_wpa_supplicant/rootfs-overlay/etc/wpa_supplicant.conf

diff --git a/DEVELOPERS b/DEVELOPERS
index 98c9ee55d3..91b5d3cf89 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -2061,6 +2061,8 @@ F:	support/testing/tests/package/test_weston/
 F:	support/testing/tests/package/test_wget.py
 F:	support/testing/tests/package/test_which.py
 F:	support/testing/tests/package/test_wine.py
+F:	support/testing/tests/package/test_wpa_supplicant.py
+F:	support/testing/tests/package/test_wpa_supplicant/
 F:	support/testing/tests/package/test_xfsprogs.py
 F:	support/testing/tests/package/test_xfsprogs/
 F:	support/testing/tests/package/test_xvisor.py
diff --git a/support/testing/tests/package/test_wpa_supplicant.py b/support/testing/tests/package/test_wpa_supplicant.py
new file mode 100644
index 0000000000..ba6cef3fef
--- /dev/null
+++ b/support/testing/tests/package/test_wpa_supplicant.py
@@ -0,0 +1,121 @@
+import os
+import time
+
+import infra.basetest
+
+
+class TestWPASupplicant(infra.basetest.BRTest):
+    test_dir = "tests/package/test_wpa_supplicant"
+    # This test uses the mac80211_hwsim kernel test driver. See:
+    # https://docs.kernel.org/networking/mac80211_hwsim/mac80211_hwsim.html
+    kern_frag = \
+        infra.filepath(f"{test_dir}/linux-mac80211-hwsim.fragment")
+    rootfs_overlay = \
+        infra.filepath(f"{test_dir}/rootfs-overlay")
+    config = \
+        f"""
+        BR2_aarch64=y
+        BR2_TOOLCHAIN_EXTERNAL=y
+        BR2_LINUX_KERNEL=y
+        BR2_LINUX_KERNEL_CUSTOM_VERSION=y
+        BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.18.44"
+        BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+        BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
+        BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{kern_frag}"
+        BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
+        BR2_PACKAGE_HOSTAPD=y
+        BR2_PACKAGE_IPROUTE2=y
+        BR2_PACKAGE_IW=y
+        BR2_PACKAGE_WPA_SUPPLICANT=y
+        BR2_PACKAGE_WPA_SUPPLICANT_CLI=y
+        BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
+        BR2_TARGET_ROOTFS_EXT2=y
+        BR2_TARGET_ROOTFS_EXT2_4=y
+        BR2_TARGET_ROOTFS_EXT2_SIZE="256M"
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    def test_run(self):
+        disk = os.path.join(self.builddir, "images", "rootfs.ext4")
+        kern = os.path.join(self.builddir, "images", "Image")
+        bootargs = ["root=/dev/vda"]
+        qemu_opts = ["-M", "virt", "-cpu", "cortex-a57", "-m", "512M",
+                     "-drive", f"file={disk},if=virtio,format=raw"]
+        self.emulator.boot(arch="aarch64",
+                           kernel=kern,
+                           kernel_cmdline=bootargs,
+                           options=qemu_opts)
+        self.emulator.login()
+
+        # We check the program can run.
+        self.assertRunOk("wpa_supplicant -v")
+
+        # We define a network namespace to isolate our
+        # access point components.
+        ns = "ap-ns"
+
+        # We create the network namespace.
+        self.assertRunOk(f"ip netns add {ns}")
+
+        # We isolate our wireless network device in our namespace.
+        self.assertRunOk(f"iw phy phy0 set netns name {ns}")
+
+        # We define the command prefix to execute commands inside
+        # our network namespace.
+        ns_exec = f"ip netns exec {ns}"
+
+        # We start the hostapd daemon.
+        cmd = [
+            ns_exec,
+            "hostapd",
+            "-B",
+            "-f /var/log/hostapd.log",
+            "/etc/hostapd.conf"
+        ]
+        self.assertRunOk(" ".join(cmd))
+
+        # We wait for the wlan0 interface to come up.
+        for attempt in range(10):
+            time.sleep(3)
+
+            cmd = ns_exec
+            cmd += " cat /sys/class/net/wlan0/operstate"
+            out, ret = self.emulator.run(cmd)
+            self.assertEqual(ret, 0)
+            if out[0] == "up":
+                break
+        else:
+            self.fail("Timeout while waiting for wlan0 to be up.")
+
+        # We start the wpa_supplicant client process.
+        cmd = [
+            "wpa_supplicant",
+            "-B",
+            "-f /var/log/wpa_supplicant.log",
+            "-i wlan1",
+            "-c /etc/wpa_supplicant.conf"
+        ]
+        self.assertRunOk(" ".join(cmd))
+
+        # We wait for the wlan1 interface to come up.
+        for attempt in range(10):
+            time.sleep(3)
+
+            cmd = "cat /sys/class/net/wlan1/operstate"
+            out, ret = self.emulator.run(cmd)
+            self.assertEqual(ret, 0)
+            if out[0] == "up":
+                break
+        else:
+            self.fail("Timeout while waiting for wlan1 to be up.")
+
+        # We set an IP address on the wlan0 hostapd side.
+        cmd = ns_exec
+        cmd += " ip addr add dev wlan0 192.168.1.111/24"
+        self.assertRunOk(cmd)
+
+        # We set an IP address on the wlan1 wpa_supplicant side.
+        self.assertRunOk("ip addr add dev wlan1 192.168.1.222/24")
+
+        # We check we can ping the hostapd wlan0 IP address.
+        self.assertRunOk("ping -c 3 -i 0.2 -W 2 192.168.1.111")
diff --git a/support/testing/tests/package/test_wpa_supplicant/linux-mac80211-hwsim.fragment b/support/testing/tests/package/test_wpa_supplicant/linux-mac80211-hwsim.fragment
new file mode 100644
index 0000000000..30aee1e9a0
--- /dev/null
+++ b/support/testing/tests/package/test_wpa_supplicant/linux-mac80211-hwsim.fragment
@@ -0,0 +1,3 @@
+CONFIG_CFG80211=y
+CONFIG_MAC80211=y
+CONFIG_MAC80211_HWSIM=y
diff --git a/support/testing/tests/package/test_wpa_supplicant/rootfs-overlay/etc/hostapd.conf b/support/testing/tests/package/test_wpa_supplicant/rootfs-overlay/etc/hostapd.conf
new file mode 100644
index 0000000000..b7c3c1a446
--- /dev/null
+++ b/support/testing/tests/package/test_wpa_supplicant/rootfs-overlay/etc/hostapd.conf
@@ -0,0 +1,14 @@
+# Config example taken from kernel
+# Documentation/networking/mac80211_hwsim/hostapd.conf
+
+interface=wlan0
+driver=nl80211
+
+hw_mode=g
+channel=1
+ssid=mac80211 test
+
+wpa=2
+wpa_key_mgmt=WPA-PSK
+wpa_pairwise=CCMP
+wpa_passphrase=12345678
diff --git a/support/testing/tests/package/test_wpa_supplicant/rootfs-overlay/etc/wpa_supplicant.conf b/support/testing/tests/package/test_wpa_supplicant/rootfs-overlay/etc/wpa_supplicant.conf
new file mode 100644
index 0000000000..3914a03046
--- /dev/null
+++ b/support/testing/tests/package/test_wpa_supplicant/rootfs-overlay/etc/wpa_supplicant.conf
@@ -0,0 +1,13 @@
+# Config example taken from kernel
+# Documentation/networking/mac80211_hwsim/wpa_supplicant.conf
+
+ctrl_interface=/var/run/wpa_supplicant
+
+network={
+	ssid="mac80211 test"
+	psk="12345678"
+	key_mgmt=WPA-PSK
+	proto=WPA2
+	pairwise=CCMP
+	group=CCMP
+}
-- 
2.55.0

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-27 21:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 22:41 [Buildroot] [PATCH 1/1] support/testing: wpa_supplicant: new runtime test Julien Olivain via buildroot
2026-08-27 21:09 ` Julien Olivain via buildroot

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.