Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] support/testing: add unbound runtime test
@ 2024-08-15 13:56 Julien Olivain
  2024-10-26 16:40 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 3+ messages in thread
From: Julien Olivain @ 2024-08-15 13:56 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/7592103034
---
 DEVELOPERS                                    |  2 +
 support/testing/tests/package/test_unbound.py | 79 +++++++++++++++++++
 .../rootfs-overlay/etc/unbound/unbound.conf   | 17 ++++
 3 files changed, 98 insertions(+)
 create mode 100644 support/testing/tests/package/test_unbound.py
 create mode 100644 support/testing/tests/package/test_unbound/rootfs-overlay/etc/unbound/unbound.conf

diff --git a/DEVELOPERS b/DEVELOPERS
index d7d0af3543..f4cf7a27b0 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1967,6 +1967,8 @@ F:	support/testing/tests/package/test_tesseract_ocr.py
 F:	support/testing/tests/package/test_thttpd.py
 F:	support/testing/tests/package/test_trace_cmd.py
 F:	support/testing/tests/package/test_trace_cmd/
+F:	support/testing/tests/package/test_unbound.py
+F:	support/testing/tests/package/test_unbound/
 F:	support/testing/tests/package/test_usbutils.py
 F:	support/testing/tests/package/test_usbutils/
 F:	support/testing/tests/package/test_vorbis_tools.py
diff --git a/support/testing/tests/package/test_unbound.py b/support/testing/tests/package/test_unbound.py
new file mode 100644
index 0000000000..c92719badc
--- /dev/null
+++ b/support/testing/tests/package/test_unbound.py
@@ -0,0 +1,79 @@
+import os
+
+import infra.basetest
+
+
+class TestUnbound(infra.basetest.BRTest):
+    rootfs_overlay = \
+        infra.filepath("tests/package/test_unbound/rootfs-overlay")
+    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+        f"""
+        BR2_PACKAGE_UNBOUND=y
+        BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
+        BR2_TARGET_ROOTFS_CPIO=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    def test_run(self):
+        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
+        self.emulator.boot(arch="armv5",
+                           kernel="builtin",
+                           options=["-initrd", cpio_file])
+        self.emulator.login()
+
+        # Check the program can execute.
+        self.assertRunOk("unbound -V")
+
+        # Verify that the configuration checker validates our file.
+        self.assertRunOk("unbound-checkconf")
+
+        # Our test configuration enabled the unbound remote
+        # control. The unbound server is supposed to be started by the
+        # sysv initscript. We should see the already running server.
+        out, ret = self.emulator.run("unbound-control status")
+        self.assertEqual(ret, 0)
+        self.assertRegex("\n".join(out), r"unbound \(pid \d+\) is running")
+
+        # We check the "unbound-host" program is working with a simple
+        # query. Note: this local query succeed even if the unbound
+        # server is not running. We are only testing this program
+        # here. The server side will be tested with the BusyBox
+        # "nslookup" applet.
+        out, ret = self.emulator.run("unbound-host -t A localhost.")
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[0], "localhost. has address 127.0.0.1")
+
+        # We test few other "unbound-control" commands.
+        self.assertRunOk("unbound-control stats")
+        self.assertRunOk("unbound-control list_local_zones")
+
+        # We check we see our test IPv4 address record.
+        cmd = "nslookup -type=A somehost.buildroot.test."
+        out, ret = self.emulator.run(cmd)
+        self.assertEqual(ret, 0)
+        self.assertIn("Address: 10.20.30.40", out)
+
+        # We also check we see our reverse record.
+        cmd = "nslookup 10.20.30.40"
+        out, ret = self.emulator.run(cmd)
+        self.assertEqual(ret, 0)
+        expected = "40.30.20.10.in-addr.arpa\tname = somehost.buildroot.test"
+        self.assertIn(expected, out)
+
+        # We check we see our test text record.
+        cmd = "nslookup -type=TXT sometext.buildroot.test."
+        out, ret = self.emulator.run(cmd)
+        self.assertEqual(ret, 0)
+        expected = "sometext.buildroot.test\ttext = \"Hello Buildroot TXT\""
+        self.assertIn(expected, out)
+
+        # We add a new record with unbound-control.
+        record_data = "someotherhost.buildroot.test. IN A 10.99.99.99"
+        cmd = f"unbound-control local_data \"{record_data}\""
+        self.assertRunOk(cmd)
+
+        # We check we see our new IPv4 address record.
+        cmd = "nslookup -type=A someotherhost.buildroot.test."
+        out, ret = self.emulator.run(cmd)
+        self.assertEqual(ret, 0)
+        self.assertIn("Address: 10.99.99.99", out)
diff --git a/support/testing/tests/package/test_unbound/rootfs-overlay/etc/unbound/unbound.conf b/support/testing/tests/package/test_unbound/rootfs-overlay/etc/unbound/unbound.conf
new file mode 100644
index 0000000000..4f8202d127
--- /dev/null
+++ b/support/testing/tests/package/test_unbound/rootfs-overlay/etc/unbound/unbound.conf
@@ -0,0 +1,17 @@
+#
+# Unbound configuration file for Buildroot runtime test.
+#
+
+server:
+	do-ip6: no
+	local-zone: "test." nodefault
+	local-zone: "10.in-addr.arpa." nodefault
+	private-domain: "buildroot.test"
+	local-zone: "buildroot.test" static
+	local-data: "somehost.buildroot.test. IN A 10.20.30.40"
+	local-data: 'sometext.buildroot.test. TXT "Hello Buildroot TXT"'
+	local-data-ptr: "10.20.30.40 somehost.buildroot.test"
+
+remote-control:
+	control-enable: yes
+	control-use-cert: no
-- 
2.46.0

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

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

end of thread, other threads:[~2024-11-12 12:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-15 13:56 [Buildroot] [PATCH 1/1] support/testing: add unbound runtime test Julien Olivain
2024-10-26 16:40 ` Thomas Petazzoni via buildroot
2024-11-12 12:34   ` Peter Korsgaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox