test_tree.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import json
  2. import os
  3. import xml.etree.ElementTree as ET
  4. import infra.basetest
  5. class TestTree(infra.basetest.BRTest):
  6. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  7. """
  8. BR2_PACKAGE_TREE=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. self.assertRunOk("tree --version")
  19. # Simple invocations on a path.
  20. self.assertRunOk("tree /usr")
  21. self.assertRunOk("tree -d /usr")
  22. self.assertRunOk("tree -dx /")
  23. # Check we see the /usr/bin/tree file in the output.
  24. out, ret = self.emulator.run("tree -f /usr")
  25. self.assertEqual(ret, 0)
  26. self.assertIn("/usr/bin/tree", "\n".join(out))
  27. # Check we can parse the JSON output and the summary report.
  28. out, ret = self.emulator.run("tree -J /usr")
  29. self.assertEqual(ret, 0)
  30. json_str = "\n".join(out)
  31. json_data = json.loads(json_str)
  32. # Report is the last element.
  33. json_report = json_data[-1]
  34. self.assertEqual(json_report["type"], "report")
  35. self.assertGreater(json_report["directories"], 0)
  36. self.assertGreater(json_report["files"], 0)
  37. # Check we can parse the XML output and the summary report.
  38. out, ret = self.emulator.run("tree -X /usr")
  39. self.assertEqual(ret, 0)
  40. xml_str = "\n".join(out)
  41. xml_root = ET.fromstring(xml_str)
  42. self.assertEqual(xml_root.tag, "tree")
  43. xml_report = xml_root.find("report")
  44. self.assertGreater(int(xml_report.find("directories").text), 0)
  45. self.assertGreater(int(xml_report.find("files").text), 0)