All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
	"Cleber Rosa" <crosa@redhat.com>
Subject: [PULL 02/18] tests/acceptance: Introduce tesseract_ocr() helper
Date: Mon,  8 Feb 2021 14:36:55 +0100	[thread overview]
Message-ID: <20210208133711.2596075-3-philmd@redhat.com> (raw)
In-Reply-To: <20210208133711.2596075-1-philmd@redhat.com>

From: Philippe Mathieu-Daudé <f4bug@amsat.org>

We are going to reuse the tesseract OCR code.
Create a new tesseract_ocr() helper and use it.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20201021105035.2477784-5-f4bug@amsat.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 tests/acceptance/machine_m68k_nextcube.py | 21 +++++----------------
 tests/acceptance/tesseract_utils.py       | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/tests/acceptance/machine_m68k_nextcube.py b/tests/acceptance/machine_m68k_nextcube.py
index 3c7400c43e4..09e2745cc52 100644
--- a/tests/acceptance/machine_m68k_nextcube.py
+++ b/tests/acceptance/machine_m68k_nextcube.py
@@ -7,13 +7,11 @@
 
 import os
 import time
-import logging
 
 from avocado_qemu import Test
 from avocado import skipUnless
-from avocado.utils import process
 
-from tesseract_utils import tesseract_available
+from tesseract_utils import tesseract_available, tesseract_ocr
 
 PIL_AVAILABLE = True
 try:
@@ -61,12 +59,8 @@ def test_bootrom_framebuffer_size(self):
     def test_bootrom_framebuffer_ocr_with_tesseract_v3(self):
         screenshot_path = os.path.join(self.workdir, "dump.ppm")
         self.check_bootrom_framebuffer(screenshot_path)
-
-        console_logger = logging.getLogger('console')
-        text = process.run("tesseract %s stdout" % screenshot_path).stdout_text
-        for line in text.split('\n'):
-            if len(line):
-                console_logger.debug(line)
+        lines = tesseract_ocr(screenshot_path, tesseract_version=3)
+        text = '\n'.join(lines)
         self.assertIn('Backplane', text)
         self.assertIn('Ethernet address', text)
 
@@ -77,13 +71,8 @@ def test_bootrom_framebuffer_ocr_with_tesseract_v3(self):
     def test_bootrom_framebuffer_ocr_with_tesseract_v4(self):
         screenshot_path = os.path.join(self.workdir, "dump.ppm")
         self.check_bootrom_framebuffer(screenshot_path)
-
-        console_logger = logging.getLogger('console')
-        proc = process.run("tesseract --oem 1 %s stdout" % screenshot_path)
-        text = proc.stdout_text
-        for line in text.split('\n'):
-            if len(line):
-                console_logger.debug(line)
+        lines = tesseract_ocr(screenshot_path, tesseract_version=4)
+        text = '\n'.join(lines)
         self.assertIn('Testing the FPU, SCC', text)
         self.assertIn('System test failed. Error code', text)
         self.assertIn('Boot command', text)
diff --git a/tests/acceptance/tesseract_utils.py b/tests/acceptance/tesseract_utils.py
index acd6e8c2faa..72cd9ab7989 100644
--- a/tests/acceptance/tesseract_utils.py
+++ b/tests/acceptance/tesseract_utils.py
@@ -6,7 +6,9 @@
 # later. See the COPYING file in the top-level directory.
 
 import re
+import logging
 
+from avocado.utils import process
 from avocado.utils.path import find_command, CmdNotFoundError
 
 def tesseract_available(expected_version):
@@ -26,3 +28,19 @@ def tesseract_available(expected_version):
         return False
     # now this is guaranteed to be a digit
     return int(match.groups()[0]) == expected_version
+
+
+def tesseract_ocr(image_path, tesseract_args='', tesseract_version=3):
+    console_logger = logging.getLogger('tesseract')
+    console_logger.debug(image_path)
+    if tesseract_version == 4:
+        tesseract_args += ' --oem 1'
+    proc = process.run("tesseract {} {} stdout".format(tesseract_args,
+                                                       image_path))
+    lines = []
+    for line in proc.stdout_text.split('\n'):
+        sline = line.strip()
+        if len(sline):
+            console_logger.debug(sline)
+            lines += [sline]
+    return lines
-- 
2.26.2



  parent reply	other threads:[~2021-02-08 19:28 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-08 13:36 [PULL 00/18] Integration testing patches for 2021-02-08 Philippe Mathieu-Daudé
2021-02-08 13:36 ` [PULL 01/18] tests/acceptance: Extract tesseract_available() helper in new namespace Philippe Mathieu-Daudé
2021-02-08 13:36 ` Philippe Mathieu-Daudé [this message]
2021-02-08 13:36 ` [PULL 03/18] tests/acceptance: Extract do_test_arm_orangepi_armbian_uboot() method Philippe Mathieu-Daudé
2021-02-08 13:36 ` [PULL 04/18] tests/acceptance: Test U-Boot/Linux from Armbian 20.08 on Orange Pi PC Philippe Mathieu-Daudé
2021-02-08 13:36 ` [PULL 05/18] tests/acceptance: Move the pseries test to a separate file Philippe Mathieu-Daudé
2021-02-08 13:36 ` [PULL 06/18] tests/acceptance: Test the mpc8544ds machine Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 07/18] tests/acceptance: Add a test for the virtex-ml507 ppc machine Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 08/18] tests/acceptance: Increase the timeout in the replay tests Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 09/18] tests/acceptance: Re-enable the microblaze test Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 10/18] tests/acceptance/boot_linux: fix typo on cloudinit error message Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 11/18] tests/acceptance/boot_linux: rename misleading cloudinit method Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 12/18] tests/acceptance/virtiofs_submounts: use workdir property Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 13/18] tests/acceptance/virtiofs_submounts: do not ask for ssh key password Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 14/18] tests/acceptance/virtiofs_submounts: use a virtio-net device instead Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 15/18] tests/acceptance/virtiofs_submounts: standardize port as integer Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 16/18] tests/acceptance/virtiofs_submounts: required space between IP and port Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 17/18] Acceptance tests: clarify ssh connection failure reason Philippe Mathieu-Daudé
2021-02-08 13:37 ` [PULL 18/18] Acceptance Tests: remove unnecessary tag from documentation example Philippe Mathieu-Daudé
2021-02-08 20:06 ` [PULL 00/18] Integration testing patches for 2021-02-08 Peter Maydell
2021-02-08 20:21   ` Philippe Mathieu-Daudé
2021-02-09 10:04     ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210208133711.2596075-3-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=crosa@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=qemu-devel@nongnu.org \
    --cc=wainersm@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.