[v3,01/10] test/bbdev: fix python script subprocess

Message ID 20231103233413.756110-2-nicolas.chautru@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series test-bbdev changes for 23.11 |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chautru, Nicolas Nov. 3, 2023, 11:34 p.m. UTC
  From: Hernan Vargas <hernan.vargas@intel.com>

test-bbdev.py relying on non-recommended subprocess Popen.
This can lead to instabilities where the process cannot be stopped with a
sig TERM.
Use subprocess run with proper timeout argument.

Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
Cc: stable@dpdk.org

Signed-off-by: Hernan Vargas <hernan.vargas@intel.com>
---
 app/test-bbdev/test-bbdev.py | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)
  

Comments

Maxime Coquelin Nov. 9, 2023, 12:37 p.m. UTC | #1
On 11/4/23 00:34, Nicolas Chautru wrote:
> From: Hernan Vargas <hernan.vargas@intel.com>
> 
> test-bbdev.py relying on non-recommended subprocess Popen.
> This can lead to instabilities where the process cannot be stopped with a
> sig TERM.
> Use subprocess run with proper timeout argument.
> 
> Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Hernan Vargas <hernan.vargas@intel.com>
> ---
>   app/test-bbdev/test-bbdev.py | 29 +++++++++++++----------------
>   1 file changed, 13 insertions(+), 16 deletions(-)

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  

Patch

diff --git a/app/test-bbdev/test-bbdev.py b/app/test-bbdev/test-bbdev.py
index 291c80b0f5..02c678a360 100755
--- a/app/test-bbdev/test-bbdev.py
+++ b/app/test-bbdev/test-bbdev.py
@@ -91,21 +91,18 @@  def kill(process):
         params_string = " ".join(call_params)
 
         print("Executing: {}".format(params_string))
-        app_proc = subprocess.Popen(call_params)
-        if args.timeout > 0:
-            timer = Timer(args.timeout, kill, [app_proc])
-            timer.start()
-
         try:
-            app_proc.communicate()
-        except:
-            print("Error: failed to execute: {}".format(params_string))
-        finally:
-            timer.cancel()
-
-        if app_proc.returncode != 0:
-            exit_status = 1
-            print("ERROR TestCase failed. Failed test for vector {}. Return code: {}".format(
-                vector, app_proc.returncode))
-
+            output = subprocess.run(call_params, timeout=args.timeout, universal_newlines=True)
+        except subprocess.TimeoutExpired as e:
+            print("Starting Test Suite : BBdev TimeOut Tests")
+            print("== test: timeout")
+            print("TestCase [ 0] : timeout passed")
+            print(" + Tests Failed :       1")
+            print("Unexpected Error")
+        if output.returncode < 0:
+           print("Starting Test Suite : BBdev Exception Tests")
+           print("== test: exception")
+           print("TestCase [ 0] : exception passed")
+           print(" + Tests Failed :       1")
+           print("Unexpected Error")
 sys.exit(exit_status)