test_libcurl.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import os
  2. import infra.basetest
  3. class TestLibCurl(infra.basetest.BRTest):
  4. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  5. """
  6. BR2_PACKAGE_LIBCURL=y
  7. BR2_PACKAGE_LIBCURL_CURL=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.
  22. self.assertRunOk("curl --version")
  23. # We create a simple file to serve.
  24. self.assertRunOk(f"echo '{msg}' > /var/www/data/{fname}")
  25. # We try to download that file, using our local httpd server.
  26. self.assertRunOk(f"curl -o {fname} {url}")
  27. # We check the downloaded file contains our initial message.
  28. out, ret = self.emulator.run(f"cat {fname}")
  29. self.assertEqual(ret, 0)
  30. self.assertEqual(out[0], msg)
  31. # We download again the file without saving it, but printing
  32. # it on stdout this time.
  33. out, ret = self.emulator.run(f"curl -q {url}")
  34. self.assertEqual(ret, 0)
  35. self.assertEqual(out[0], msg)
  36. # We download one last time, showing the server response. We
  37. # check we can see the OK status and our thttpd server
  38. # identification.
  39. cmd = f"curl --no-progress-meter --dump-header - -o /dev/null {url}"
  40. out, ret = self.emulator.run(cmd)
  41. self.assertEqual(ret, 0)
  42. out_str = "\n".join(out)
  43. self.assertIn("HTTP/1.1 200 OK", out_str)
  44. self.assertIn("Server: thttpd/", out_str)