test_ghostscript.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import os
  2. import infra.basetest
  3. class TestGhostscript(infra.basetest.BRTest):
  4. rootfs_overlay = \
  5. infra.filepath("tests/package/test_ghostscript/rootfs-overlay")
  6. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  7. f"""
  8. BR2_PACKAGE_GHOSTSCRIPT=y
  9. BR2_PACKAGE_TESSERACT_OCR=y
  10. BR2_PACKAGE_TESSERACT_OCR_LANG_ENG=y
  11. BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
  12. BR2_TARGET_ROOTFS_CPIO=y
  13. # BR2_TARGET_ROOTFS_TAR is not set
  14. """
  15. def test_run(self):
  16. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  17. self.emulator.boot(arch="armv5",
  18. kernel="builtin",
  19. options=["-initrd", cpio_file])
  20. self.emulator.login()
  21. # Check the program can execute.
  22. self.assertRunOk("gs --version")
  23. doc_basename = "document"
  24. ps_file = doc_basename + ".ps"
  25. pgm_file = doc_basename + ".pgm"
  26. txt_file = doc_basename + ".txt"
  27. # Render a basic PostScript file to an image file.
  28. cmd = "gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pgmraw -r150"
  29. cmd += f" -dTextAlphaBits=4 -sOutputFile='{pgm_file}' {ps_file}"
  30. self.assertRunOk(cmd)
  31. # Run text recognition on the image file.
  32. cmd = f"tesseract {pgm_file} {doc_basename}"
  33. self.assertRunOk(cmd, timeout=30)
  34. # Check we extracted the expected string from the input
  35. # PostScript file.
  36. cmd = f"cat {txt_file}"
  37. out, ret = self.emulator.run(cmd)
  38. self.assertEqual(ret, 0)
  39. self.assertEqual(out[0], "Hello Buildroot!")