From fd9ca3a6c5819edf93da510f8f8f91587f0a215e Mon Sep 17 00:00:00 2001 From: Pengfei Xu Date: Thu, 4 Jul 2024 21:27:35 +0800 Subject: [PATCH] runtests.py: correctly parse the command line without being affected by quotes and so on Reported-by: Haoliang Zhu Co-developed-by: Yi Sun Signed-off-by: Pengfei Xu --- BM/runtests.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/BM/runtests.py b/BM/runtests.py index 5812367..eaeb026 100755 --- a/BM/runtests.py +++ b/BM/runtests.py @@ -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 @@ -59,6 +60,14 @@ 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 = [] @@ -67,10 +76,10 @@ def create_runnables_from_file(ftests): # Handle empty lines and comments. if not line.strip() 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.strip()) + runnable = Runnable("exec-test", *cmd_line) tests.append(runnable) return tests