[libcamera-devel,v2,1/2] tests: v4l2_compat: Prettify failure output

Message ID 20200711054555.495244-1-paul.elder@ideasonboard.com
State Accepted
Commit ce32ca491884c4755e3cae0c7a6453a1f4933da2
Headers show
Series
  • [libcamera-devel,v2,1/2] tests: v4l2_compat: Prettify failure output
Related show

Commit Message

Paul Elder July 11, 2020, 5:45 a.m. UTC
When a test is being run on a video device, there is output like so:

Testing /dev/video0 with uvcvideo driver...

and when it succeeds, "success" is appended:

Testing /dev/video0 with uvcvideo driver... success

On failure, however, the output of v4l2-compliance is printed before
"failure" is printed, resulting in the first line of the v4l2-compliance
output to be printed on the same line as the message:

Testing /dev/video2 with uvcvideo driver... v4l2-compliance SHA: not available, 64 bits
<v4l2-compliance output>
failure

Refactor the code to make "failure" print before the output of the test,
to prettify the output upon failure..

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

---
Changes in v2:
- refactor code instead of just moving the print failure statement
---
 test/v4l2_compat/v4l2_compat_test.py | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

Comments

Laurent Pinchart July 11, 2020, 1:15 p.m. UTC | #1
Hi Paul,

Thank you for the patch.

On Sat, Jul 11, 2020 at 02:45:54PM +0900, Paul Elder wrote:
> When a test is being run on a video device, there is output like so:
> 
> Testing /dev/video0 with uvcvideo driver...
> 
> and when it succeeds, "success" is appended:
> 
> Testing /dev/video0 with uvcvideo driver... success
> 
> On failure, however, the output of v4l2-compliance is printed before
> "failure" is printed, resulting in the first line of the v4l2-compliance
> output to be printed on the same line as the message:
> 
> Testing /dev/video2 with uvcvideo driver... v4l2-compliance SHA: not available, 64 bits
> <v4l2-compliance output>
> failure
> 
> Refactor the code to make "failure" print before the output of the test,
> to prettify the output upon failure..
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
> Changes in v2:
> - refactor code instead of just moving the print failure statement
> ---
>  test/v4l2_compat/v4l2_compat_test.py | 22 ++++++++--------------
>  1 file changed, 8 insertions(+), 14 deletions(-)
> 
> diff --git a/test/v4l2_compat/v4l2_compat_test.py b/test/v4l2_compat/v4l2_compat_test.py
> index 99b3d5a..8aca222 100755
> --- a/test/v4l2_compat/v4l2_compat_test.py
> +++ b/test/v4l2_compat/v4l2_compat_test.py
> @@ -54,32 +54,25 @@ def extract_result(result):
>      return ret
>  
>  
> -def print_output_arr(output_arr):
> -    print('\n'.join(output_arr))
> -
> -
>  def test_v4l2_compliance(v4l2_compliance, v4l2_compat, device, base_driver):
>      ret, output = run_with_stdout(v4l2_compliance, '-s', '-d', device, env={'LD_PRELOAD': v4l2_compat})
>      if ret < 0:
> -        print_output_arr(output)
> -        print(f'Test for {device} terminated due to signal {signal.Signals(-ret).name}')
> -        return TestFail
> +        output.append(f'Test for {device} terminated due to signal {signal.Signals(-ret).name}')
> +        return TestFail, output
>  
>      result = extract_result(output[-2])
>      if result['failed'] == 0:
> -        return TestPass
> +        return TestPass, None
>  
>      # vimc will fail s_fmt because it only supports framesizes that are
>      # multiples of 3
>      if base_driver == 'vimc' and result['failed'] == 1:
>          failures = grep('fail', output)
>          if re.search('S_FMT cannot handle an invalid format', failures[0]) is None:
> -            print_output_arr(output)
> -            return TestFail
> -        return TestPass
> +            return TestFail, output
> +        return TestPass, None
>  
> -    print_output_arr(output)
> -    return TestFail
> +    return TestFail, output
>  
>  
>  def main(argv):
> @@ -132,10 +125,11 @@ def main(argv):
>              continue
>  
>          print(f'Testing {device} with {driver} driver... ', end='')
> -        ret = test_v4l2_compliance(v4l2_compliance, v4l2_compat, device, driver)
> +        ret, msg = test_v4l2_compliance(v4l2_compliance, v4l2_compat, device, driver)
>          if ret == TestFail:
>              failed.append(device)
>              print('failed')
> +            print('\n'.join(msg))
>          else:
>              print('success')
>          drivers_tested[driver] = True

Patch

diff --git a/test/v4l2_compat/v4l2_compat_test.py b/test/v4l2_compat/v4l2_compat_test.py
index 99b3d5a..8aca222 100755
--- a/test/v4l2_compat/v4l2_compat_test.py
+++ b/test/v4l2_compat/v4l2_compat_test.py
@@ -54,32 +54,25 @@  def extract_result(result):
     return ret
 
 
-def print_output_arr(output_arr):
-    print('\n'.join(output_arr))
-
-
 def test_v4l2_compliance(v4l2_compliance, v4l2_compat, device, base_driver):
     ret, output = run_with_stdout(v4l2_compliance, '-s', '-d', device, env={'LD_PRELOAD': v4l2_compat})
     if ret < 0:
-        print_output_arr(output)
-        print(f'Test for {device} terminated due to signal {signal.Signals(-ret).name}')
-        return TestFail
+        output.append(f'Test for {device} terminated due to signal {signal.Signals(-ret).name}')
+        return TestFail, output
 
     result = extract_result(output[-2])
     if result['failed'] == 0:
-        return TestPass
+        return TestPass, None
 
     # vimc will fail s_fmt because it only supports framesizes that are
     # multiples of 3
     if base_driver == 'vimc' and result['failed'] == 1:
         failures = grep('fail', output)
         if re.search('S_FMT cannot handle an invalid format', failures[0]) is None:
-            print_output_arr(output)
-            return TestFail
-        return TestPass
+            return TestFail, output
+        return TestPass, None
 
-    print_output_arr(output)
-    return TestFail
+    return TestFail, output
 
 
 def main(argv):
@@ -132,10 +125,11 @@  def main(argv):
             continue
 
         print(f'Testing {device} with {driver} driver... ', end='')
-        ret = test_v4l2_compliance(v4l2_compliance, v4l2_compat, device, driver)
+        ret, msg = test_v4l2_compliance(v4l2_compliance, v4l2_compat, device, driver)
         if ret == TestFail:
             failed.append(device)
             print('failed')
+            print('\n'.join(msg))
         else:
             print('success')
         drivers_tested[driver] = True