test_wget.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import os
  2. import infra.basetest
  3. class TestWget(infra.basetest.BRTest):
  4. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  5. """
  6. BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
  7. BR2_PACKAGE_WGET=y
  8. BR2_PACKAGE_THTTPD=y
  9. BR2_TARGET_ROOTFS_CPIO=y
  10. # BR2_TARGET_ROOTFS_TAR is not set
  11. """
  12. def test_run(self):
  13. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  14. self.emulator.boot(arch="armv5",
  15. kernel="builtin",
  16. options=["-initrd", cpio_file])
  17. self.emulator.login()
  18. msg = "Hello Buildroot!"
  19. fname = "file.txt"
  20. url = f"http://localhost/{fname}"
  21. # We check the program can execute. This also checks we have
  22. # the GNU wget version, rather than the BusyBox version which
  23. # does not know the --version option.
  24. self.assertRunOk("wget --version")
  25. # We create a simple file to serve.
  26. self.assertRunOk(f"echo '{msg}' > /var/www/data/{fname}")
  27. # We try to download that file, using our local httpd server.
  28. self.assertRunOk(f"wget --progress=dot {url}")
  29. # We check the downloaded file contains our initial message.
  30. out, ret = self.emulator.run(f"cat {fname}")
  31. self.assertEqual(ret, 0)
  32. self.assertEqual(out[0], msg)
  33. # We download again the file without saving it, but printing
  34. # it on stdout this time.
  35. out, ret = self.emulator.run(f"wget -q -O - {url}")
  36. self.assertEqual(ret, 0)
  37. self.assertEqual(out[0], msg)
  38. # We download one last time, showing the server response. We
  39. # check we can see the OK status and our thttpd server
  40. # identification.
  41. cmd = f"wget --no-verbose --server-response -O /dev/null {url}"
  42. out, ret = self.emulator.run(cmd)
  43. self.assertEqual(ret, 0)
  44. out_str = "\n".join(out)
  45. self.assertIn("HTTP/1.1 200 OK", out_str)
  46. self.assertIn("Server: thttpd/", out_str)