[Buildroot] [PATCH v4 2/2] support/testing: add runtime test for mpd
Andreas Ziegler
br025 at umbiko.net
Sat Sep 5 04:02:53 UTC 2026
The test determines if mpd was started by the init system by querying
mpd status via the built-in protocol and evaluating the result.
Signed-off-by: Andreas Ziegler <br025 at umbiko.net>
---
Changes v2 -> v3:
simplify test to be used without test data
remove mpd.conf rootfs overlay
DEVELOPERS | 2 +
support/testing/tests/package/test_mpd.py | 49 +++++++++++++++++++
.../tests/package/test_mpd/busybox.fragment | 4 ++
.../test_mpd/rootfs-overlay/root/test_mpd.sh | 35 +++++++++++++
4 files changed, 90 insertions(+)
create mode 100644 support/testing/tests/package/test_mpd.py
create mode 100644 support/testing/tests/package/test_mpd/busybox.fragment
create mode 100755 support/testing/tests/package/test_mpd/rootfs-overlay/root/test_mpd.sh
diff --git a/DEVELOPERS b/DEVELOPERS
index 53104cc60b..409e8fcaaa 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -205,6 +205,8 @@ F: package/qt6/qt6opcua/
N: Andreas Ziegler <br025 at umbiko.net>
F: package/mpd/
+F: support/testing/tests/package/test_mpd
+F: support/testing/tests/package/test_mpd.py
N: Andrey Smirnov <andrew.smirnov at gmail.com>
F: package/python-decorator/
diff --git a/support/testing/tests/package/test_mpd.py b/support/testing/tests/package/test_mpd.py
new file mode 100644
index 0000000000..4ce297c2b8
--- /dev/null
+++ b/support/testing/tests/package/test_mpd.py
@@ -0,0 +1,49 @@
+#!/bin/python
+
+import os
+import infra.basetest
+
+class TestMpd(infra.basetest.BRTest):
+
+ rootfs_overlay = \
+ infra.filepath("tests/package/test_mpd/rootfs-overlay")
+ busybox_fragment = \
+ infra.filepath("tests/package/test_mpd/busybox.fragment")
+
+ # use a custom configuration
+ config = \
+ """
+ BR2_x86_64=y
+ BR2_x86_x86_64_v2=y
+ BR2_TOOLCHAIN_EXTERNAL=y
+ BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_64_GLIBC_BLEEDING_EDGE=y
+ BR2_TARGET_GENERIC_GETTY_PORT="ttyS0"
+ BR2_ROOTFS_OVERLAY="{}"
+ BR2_LINUX_KERNEL=y
+ BR2_LINUX_KERNEL_LATEST_VERSION=y
+ BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+ BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/x86_64/linux.config"
+ BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
+ BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF=y
+ BR2_PACKAGE_BUSYBOX_CONFIG_FRAGMENT_FILES="{}"
+ BR2_PACKAGE_MPD=y
+ BR2_TARGET_ROOTFS_INITRAMFS=y
+ # BR2_TARGET_ROOTFS_TAR is not set
+ """.format(rootfs_overlay, busybox_fragment)
+
+ def test_run(self):
+ cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
+ kern = os.path.join(self.builddir, "images", "bzImage")
+ self.emulator.boot(arch="x86_64",
+ kernel=kern,
+ kernel_cmdline=["console=ttyS0"],
+ options=[
+ "-M", "q35",
+ "-cpu", "Westmere",
+ "-smp", "2",
+ "-initrd", cpio_file,
+ ])
+
+ self.emulator.login()
+
+ self.assertRunOk("/root/test_mpd.sh", timeout=30)
diff --git a/support/testing/tests/package/test_mpd/busybox.fragment b/support/testing/tests/package/test_mpd/busybox.fragment
new file mode 100644
index 0000000000..0c92d86c49
--- /dev/null
+++ b/support/testing/tests/package/test_mpd/busybox.fragment
@@ -0,0 +1,4 @@
+#
+# Networking Utilities
+#
+CONFIG_NC=y
diff --git a/support/testing/tests/package/test_mpd/rootfs-overlay/root/test_mpd.sh b/support/testing/tests/package/test_mpd/rootfs-overlay/root/test_mpd.sh
new file mode 100755
index 0000000000..4cc6895602
--- /dev/null
+++ b/support/testing/tests/package/test_mpd/rootfs-overlay/root/test_mpd.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+mpd_command() {
+ mpd_result=""
+ mpd_state=""
+ printf "Execute %s" "$1"
+ while IFS= read -r line; do
+ case $line in
+ OK) mpd_result=$line ;;
+ OK\ MPD*) mpd_protocol=${line##* } ;;
+ state:*) mpd_state=${line##*: } ;;
+ ACK\ \[[0-9]*@[0-9]*\]*) mpd_error=${line##*\} } ;;
+ esac
+ done <<- EOF
+ $( ( echo "$1"; echo "close" ) | nc localhost 6600 )
+EOF
+
+ if [ "$mpd_result" != "OK" ]; then
+ printf "\nmpd protocol error: %s\n" "$mpd_error"
+ return 1
+ else
+ printf " [OK]\n"
+ fi
+
+ export mpd_protocol
+ export mpd_state
+}
+
+test_mpd() {
+ mpd_command "status" || return 1
+ printf "MPD protocol version: %s\n" "$mpd_protocol"
+}
+
+# run main function if invoked from a subshell
+[ "$0" = "-sh" ] || test_mpd
--
2.53.0
More information about the buildroot
mailing list