Skip to content

Commit

Permalink
runtests.py: correctly parse the command line without being affected …
Browse files Browse the repository at this point in the history
…by quotes and so on

Reported-by: Haoliang Zhu <[email protected]>
Co-developed-by: Yi Sun <[email protected]>
Signed-off-by: Pengfei Xu <[email protected]>
  • Loading branch information
xupengfe committed Jul 4, 2024
1 parent c4f27dd commit 3f7b925
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions BM/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import argparse
import os
import shlex
from avocado.core.job import Job
from avocado.core.nrunner.runnable import Runnable
from avocado.core.suite import TestSuite
Expand Down Expand Up @@ -59,18 +60,27 @@ def dependency_check(ftests):
except subprocess.CalledProcessError:
print(f"Warning: {reason_info}")

def parse_cmd_line(cmd: str) -> list[str]:
cmd_str = shlex.split(cmd)
try:
return list(cmd_str)
except Exception as e:
print(f"Error while parsing cmd:{cmd} with err {e}")
return []

# Read the tests file and create Runnable objects.
def create_runnables_from_file(ftests):
tests = []
with open(ftests, 'r') as file:
for line in file:
# Handle empty lines and comments.
if not line.strip() or line.startswith('#'):
line_str = line.strip()
if not line_str or line.startswith('#'):
continue

# Split command line parameters.
parts = line.strip().split()
# Create a Runnable object.
runnable = Runnable("exec-test", parts[0], *parts[1:])
cmd_line = parse_cmd_line(line_str)
runnable = Runnable("exec-test", *cmd_line)
tests.append(runnable)
return tests

Expand Down

0 comments on commit 3f7b925

Please sign in to comment.