diff mbox series

tests/functional: Fix bad usage of has_cmd

Message ID 20240910075820.51346-1-thuth@redhat.com (mailing list archive)
State New, archived
Headers show
Series tests/functional: Fix bad usage of has_cmd | expand

Commit Message

Thomas Huth Sept. 10, 2024, 7:58 a.m. UTC
has_cmd returns a tuple, not a boolean value. This fixes a crash when
e.g. "tesseract" is not available in the test_m68k_nextcube test.

Reported-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/functional/qemu_test/cmd.py       | 6 +++---
 tests/functional/qemu_test/tesseract.py | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

Comments

Daniel P. Berrangé Sept. 10, 2024, 8:15 a.m. UTC | #1
On Tue, Sep 10, 2024 at 09:58:20AM +0200, Thomas Huth wrote:
> has_cmd returns a tuple, not a boolean value. This fixes a crash when
> e.g. "tesseract" is not available in the test_m68k_nextcube test.
> 
> Reported-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  tests/functional/qemu_test/cmd.py       | 6 +++---
>  tests/functional/qemu_test/tesseract.py | 3 ++-
>  2 files changed, 5 insertions(+), 4 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
Philippe Mathieu-Daudé Sept. 10, 2024, 11:14 a.m. UTC | #2
On 10/9/24 09:58, Thomas Huth wrote:
> has_cmd returns a tuple, not a boolean value. This fixes a crash when
> e.g. "tesseract" is not available in the test_m68k_nextcube test.
> 
> Reported-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   tests/functional/qemu_test/cmd.py       | 6 +++---
>   tests/functional/qemu_test/tesseract.py | 3 ++-
>   2 files changed, 5 insertions(+), 4 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Richard Henderson Sept. 10, 2024, 5:55 p.m. UTC | #3
On 9/10/24 00:58, Thomas Huth wrote:
> has_cmd returns a tuple, not a boolean value. This fixes a crash when
> e.g. "tesseract" is not available in the test_m68k_nextcube test.
> 
> Reported-by: Richard Henderson<richard.henderson@linaro.org>
> Signed-off-by: Thomas Huth<thuth@redhat.com>
> ---
>   tests/functional/qemu_test/cmd.py       | 6 +++---
>   tests/functional/qemu_test/tesseract.py | 3 ++-
>   2 files changed, 5 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
diff mbox series

Patch

diff --git a/tests/functional/qemu_test/cmd.py b/tests/functional/qemu_test/cmd.py
index 3acd617324..cbabb1ceed 100644
--- a/tests/functional/qemu_test/cmd.py
+++ b/tests/functional/qemu_test/cmd.py
@@ -187,7 +187,7 @@  def get_qemu_img(test):
     qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
     if os.path.exists(qemu_img):
         return qemu_img
-    if has_cmd('qemu-img'):
+    (has_system_qemu_img, errmsg) = has_cmd('qemu-img')
+    if has_system_qemu_img:
         return 'qemu-img'
-    test.skipTest('Could not find "qemu-img", which is required to '
-                  'create temporary images')
+    test.skipTest(errmsg)
diff --git a/tests/functional/qemu_test/tesseract.py b/tests/functional/qemu_test/tesseract.py
index c4087b7c11..db441027b9 100644
--- a/tests/functional/qemu_test/tesseract.py
+++ b/tests/functional/qemu_test/tesseract.py
@@ -11,7 +11,8 @@ 
 from . import has_cmd, run_cmd
 
 def tesseract_available(expected_version):
-    if not has_cmd('tesseract'):
+    (has_tesseract, _) = has_cmd('tesseract')
+    if not has_tesseract:
         return False
     (stdout, stderr, ret) = run_cmd([ 'tesseract', '--version'])
     if ret: