Skip to content

Commit

Permalink
test/bbdev: fix Python script subprocess
Browse files Browse the repository at this point in the history
[ upstream commit 262c9d13f7c998fdca526b28871f37b47fbbb464 ]

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: f714a18 ("app/testbbdev: add test application for bbdev")

Signed-off-by: Hernan Vargas <hernan.vargas@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
  • Loading branch information
Hernanlv authored and bluca committed Nov 15, 2023
1 parent 2d5c287 commit f1b0814
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions app/test-bbdev/test-bbdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f1b0814

Please sign in to comment.