[Buildroot] [git commit] support/testing: add ghostscript runtime test
Thomas Petazzoni
thomas.petazzoni at bootlin.com
Sun Feb 11 21:49:37 UTC 2024
commit: https://git.buildroot.net/buildroot/commit/?id=72c4c5740d52220669b519f6b76d80b748dc012a
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/master
Signed-off-by: Julien Olivain <ju.o at free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
---
DEVELOPERS | 2 +
support/testing/tests/package/test_ghostscript.py | 48 ++++++++++++++++++++++
.../rootfs-overlay/root/document.ps | 9 ++++
3 files changed, 59 insertions(+)
diff --git a/DEVELOPERS b/DEVELOPERS
index 8234d578cf..caf8a5fb37 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1782,6 +1782,8 @@ F: support/testing/tests/package/test_fluidsynth.py
F: support/testing/tests/package/test_fluidsynth/
F: support/testing/tests/package/test_fping.py
F: support/testing/tests/package/test_gawk.py
+F: support/testing/tests/package/test_ghostscript.py
+F: support/testing/tests/package/test_ghostscript/
F: support/testing/tests/package/test_glslsandbox_player.py
F: support/testing/tests/package/test_glslsandbox_player/
F: support/testing/tests/package/test_gnupg2.py
diff --git a/support/testing/tests/package/test_ghostscript.py b/support/testing/tests/package/test_ghostscript.py
new file mode 100644
index 0000000000..3c6c16ef2c
--- /dev/null
+++ b/support/testing/tests/package/test_ghostscript.py
@@ -0,0 +1,48 @@
+import os
+
+import infra.basetest
+
+
+class TestGhostscript(infra.basetest.BRTest):
+ rootfs_overlay = \
+ infra.filepath("tests/package/test_ghostscript/rootfs-overlay")
+ config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+ f"""
+ BR2_PACKAGE_GHOSTSCRIPT=y
+ BR2_PACKAGE_TESSERACT_OCR=y
+ BR2_PACKAGE_TESSERACT_OCR_LANG_ENG=y
+ BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
+ 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()
+
+ # Check the program can execute.
+ self.assertRunOk("gs --version")
+
+ doc_basename = "document"
+ ps_file = doc_basename + ".ps"
+ pgm_file = doc_basename + ".pgm"
+ txt_file = doc_basename + ".txt"
+
+ # Render a basic PostScript file to an image file.
+ cmd = "gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pgmraw -r150"
+ cmd += f" -dTextAlphaBits=4 -sOutputFile='{pgm_file}' {ps_file}"
+ self.assertRunOk(cmd)
+
+ # Run text recognition on the image file.
+ cmd = f"tesseract {pgm_file} {doc_basename}"
+ self.assertRunOk(cmd, timeout=30)
+
+ # Check we extracted the expected string from the input
+ # PostScript file.
+ cmd = f"cat {txt_file}"
+ out, ret = self.emulator.run(cmd)
+ self.assertEqual(ret, 0)
+ self.assertEqual(out[0], "Hello Buildroot!")
diff --git a/support/testing/tests/package/test_ghostscript/rootfs-overlay/root/document.ps b/support/testing/tests/package/test_ghostscript/rootfs-overlay/root/document.ps
new file mode 100644
index 0000000000..5ca2b3581f
--- /dev/null
+++ b/support/testing/tests/package/test_ghostscript/rootfs-overlay/root/document.ps
@@ -0,0 +1,9 @@
+%!PS
+% See: PostScript: Language Reference, third edition
+% Example 5.1, page 314
+% https://www.adobe.com/jp/print/postscript/pdfs/PLRM.pdf
+/Helvetica findfont
+16 scalefont setfont
+54 720 moveto
+(Hello Buildroot!) show
+showpage
More information about the buildroot
mailing list