Files
buildroot/support/testing/tests/package/test_mdnsd.py
Romain Naour 45636d67c9 support/testing: TestMdnsd: improve test reliability
The mdnsd runtime test can randomly fail on slow runners.

It's hard to reproduce locally (only one failure after a few attempts)
but we can reproduce it easily by removing the while loop entirely.

It turns out that mdnsd is started by S50mdnsd before the
emulator.login() change the system date:

  [BRTEST# date -s @1788032864
  Sat Aug 29 19:47:44 UTC 2026

Since the minimal rootfs.cpio generated	for TestMdnsd doesn't have any
ntp client installed, it start with "January 1, 1970".

The date change may cause some issue to the mdnsd daemon which blocks
any response from mquery command.

When the problem occurs, "mquery -T _http._tcp" reply is empty:

  # mquery -T _http._tcp
  Querying _http._tcp.local. for PTR (12) ... press Ctrl-C to stop

To workaround the issue, restart mdnsd manually.

Fixes:
https://gitlab.com/buildroot.org/buildroot/-/jobs/16185948555

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Signed-off-by: Julien Olivain <ju.o@free.fr>
2026-09-01 21:31:01 +02:00

46 lines
1.6 KiB
Python

import os
import infra.basetest
class TestMdnsd(infra.basetest.BRTest):
config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
"""
BR2_PACKAGE_MDNSD=y
BR2_PACKAGE_MDNSD_MQUERY=y
BR2_PACKAGE_MDNSD_HTTP_SERVICE=y
BR2_SYSTEM_DHCP="eth0"
BR2_TARGET_ROOTFS_CPIO=y
# BR2_TARGET_ROOTFS_TAR is not set
"""
def test_run(self):
img = os.path.join(self.builddir, "images", "rootfs.cpio")
self.emulator.boot(arch="armv5",
kernel="builtin",
options=["-initrd", img,
"-net", "nic,model=rtl8139",
"-net", "user"])
self.emulator.login()
# Restart mdnsd after setting the date in emulator.login() setup.
cmd = "/etc/init.d/S50mdnsd restart"
self.assertRunOk(cmd, timeout=30)
# We check the program can execute.
self.assertRunOk("mdnsd -v")
# The responder is started at boot by /etc/init.d/S50mdnsd and
# advertises the bundled _http._tcp service from /etc/mdns.d/.
self.assertRunOk("pidof mdnsd")
# mdnsd only answers on multicast capable interfaces that are
# up, so wait for eth0 to get its DHCP address before querying.
cmd = "while ! ifconfig eth0 | grep -q 'inet addr'; do sleep 1; done"
self.assertRunOk(cmd, timeout=30)
# mquery sends a multicast query for the advertised service;
# output is one "+ NAME (IP)" line per instance
cmd = "mquery -T _http._tcp |grep -F buildroot._http._tcp.local"
self.assertRunOk(cmd, timeout=30)