diff mbox series

[1/1] support/testing: new wget runtime test

Message ID 20241212202447.42524-1-ju.o@free.fr
State New
Headers show
Series [1/1] support/testing: new wget runtime test | expand

Commit Message

Julien Olivain Dec. 12, 2024, 8:24 p.m. UTC
Signed-off-by: Julien Olivain <ju.o@free.fr>
---
Patch tested in:
https://gitlab.com/jolivain/buildroot/-/jobs/8627864865
---
 DEVELOPERS                                 |  1 +
 support/testing/tests/package/test_wget.py | 57 ++++++++++++++++++++++
 2 files changed, 58 insertions(+)
 create mode 100644 support/testing/tests/package/test_wget.py
diff mbox series

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index 047dc4a88f..b2fea6e0b1 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -2001,6 +2001,7 @@  F:	support/testing/tests/package/test_usbutils/
 F:	support/testing/tests/package/test_vorbis_tools.py
 F:	support/testing/tests/package/test_weston.py
 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_xfsprogs.py
diff --git a/support/testing/tests/package/test_wget.py b/support/testing/tests/package/test_wget.py
new file mode 100644
index 0000000000..c121cbd21c
--- /dev/null
+++ b/support/testing/tests/package/test_wget.py
@@ -0,0 +1,57 @@ 
+import os
+
+import infra.basetest
+
+
+class TestWget(infra.basetest.BRTest):
+    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+        """
+        BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
+        BR2_PACKAGE_WGET=y
+        BR2_PACKAGE_THTTPD=y
+        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()
+
+        msg = "Hello Buildroot!"
+        fname = "file.txt"
+        url = f"http://localhost/{fname}"
+
+        # We check the program can execute. This also checks we have
+        # the GNU wget version, rather than the BusyBox version which
+        # does not know the --version option.
+        self.assertRunOk("wget --version")
+
+        # We create a simple file to serve.
+        self.assertRunOk(f"echo '{msg}' > /var/www/data/{fname}")
+
+        # We try to download that file, using our local httpd server.
+        self.assertRunOk(f"wget --progress=dot {url}")
+
+        # We check the downloaded file contains our initial message.
+        out, ret = self.emulator.run(f"cat {fname}")
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[0], msg)
+
+        # We download again the file without saving it, but printing
+        # it on stdout this time.
+        out, ret = self.emulator.run(f"wget -q -O - {url}")
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[0], msg)
+
+        # We download one last time, showing the server response. We
+        # check we can see the OK status and our thttpd server
+        # identification.
+        cmd = f"wget --no-verbose --server-response -O /dev/null {url}"
+        out, ret = self.emulator.run(cmd)
+        self.assertEqual(ret, 0)
+        out_str = "\n".join(out)
+        self.assertIn("HTTP/1.1 200 OK", out_str)
+        self.assertIn("Server: thttpd/", out_str)