Skip to content

Commit c14a370

Browse files
Allow to specify run delay between app and test script (project-chip#35216)
* Allow to specify run delay between app and test script * Restyled by prettier-markdown * Explain the use case of the delay --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 63da540 commit c14a370

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

docs/testing/python.md

+10
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,19 @@ markers must be present.
635635

636636
- `test-runner-run/<run_identifier>/script-args`: Specifies the arguments to
637637
be passed to the test script.
638+
638639
- Example:
639640
`--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto`
640641

642+
- `test-runner-run/<run_identifier>/script-start-delay`: Specifies the number
643+
of seconds to wait before starting the test script. This parameter can be
644+
used to allow the application to initialize itself properly before the test
645+
script will try to commission it (e.g. in case if the application needs to
646+
be commissioned to some other controller first). By default, the delay is 0
647+
seconds.
648+
649+
- Example: `10`
650+
641651
This structured format ensures that all necessary configurations are clearly
642652
defined and easily understood, allowing for consistent and reliable test
643653
execution.

scripts/tests/run_python_test.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,14 @@ def DumpProgramOutputToQueue(thread_list: typing.List[threading.Thread], tag: st
8787
'mobile-device-test.py'), help='Test script to use.')
8888
@click.option("--script-args", type=str, default='',
8989
help='Script arguments, can use placeholders like {SCRIPT_BASE_NAME}.')
90+
@click.option("--script-start-delay", type=int, default=0,
91+
help='Delay in seconds before starting the script.')
9092
@click.option("--script-gdb", is_flag=True,
9193
help='Run script through gdb')
9294
@click.option("--quiet", is_flag=True, help="Do not print output from passing tests. Use this flag in CI to keep github log sizes manageable.")
9395
@click.option("--load-from-env", default=None, help="YAML file that contains values for environment variables.")
94-
def main(app: str, factoryreset: bool, factoryreset_app_only: bool, app_args: str, script: str, script_args: str, script_gdb: bool, quiet: bool, load_from_env):
96+
def main(app: str, factoryreset: bool, factoryreset_app_only: bool, app_args: str,
97+
script: str, script_args: str, script_start_delay: int, script_gdb: bool, quiet: bool, load_from_env):
9598
if load_from_env:
9699
reader = MetadataReader(load_from_env)
97100
runs = reader.parse_script(script)
@@ -103,6 +106,7 @@ def main(app: str, factoryreset: bool, factoryreset_app_only: bool, app_args: st
103106
app=app,
104107
app_args=app_args,
105108
script_args=script_args,
109+
script_start_delay=script_start_delay,
106110
factoryreset=factoryreset,
107111
factoryreset_app_only=factoryreset_app_only,
108112
script_gdb=script_gdb,
@@ -117,10 +121,11 @@ def main(app: str, factoryreset: bool, factoryreset_app_only: bool, app_args: st
117121
for run in runs:
118122
print(f"Executing {run.py_script_path.split('/')[-1]} {run.run}")
119123
main_impl(run.app, run.factoryreset, run.factoryreset_app_only, run.app_args,
120-
run.py_script_path, run.script_args, run.script_gdb, run.quiet)
124+
run.py_script_path, run.script_args, run.script_start_delay, run.script_gdb, run.quiet)
121125

122126

123-
def main_impl(app: str, factoryreset: bool, factoryreset_app_only: bool, app_args: str, script: str, script_args: str, script_gdb: bool, quiet: bool):
127+
def main_impl(app: str, factoryreset: bool, factoryreset_app_only: bool, app_args: str,
128+
script: str, script_args: str, script_start_delay: int, script_gdb: bool, quiet: bool):
124129

125130
app_args = app_args.replace('{SCRIPT_BASE_NAME}', os.path.splitext(os.path.basename(script))[0])
126131
script_args = script_args.replace('{SCRIPT_BASE_NAME}', os.path.splitext(os.path.basename(script))[0])
@@ -175,6 +180,8 @@ def main_impl(app: str, factoryreset: bool, factoryreset_app_only: bool, app_arg
175180
DumpProgramOutputToQueue(
176181
log_cooking_threads, Fore.GREEN + "APP " + Style.RESET_ALL, app_process, stream_output, log_queue)
177182

183+
time.sleep(script_start_delay)
184+
178185
script_command = [script, "--paa-trust-store-path", os.path.join(DEFAULT_CHIP_ROOT, MATTER_DEVELOPMENT_PAA_ROOT_CERTS),
179186
'--log-format', '%(message)s', "--app-pid", str(app_pid)] + shlex.split(script_args)
180187

src/python_testing/matter_testing_infrastructure/metadata_parser/metadata.py

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Metadata:
3333
app: str
3434
app_args: str
3535
script_args: str
36+
script_start_delay: int = 0
3637
factoryreset: bool = False
3738
factoryreset_app_only: bool = False
3839
script_gdb: bool = False
@@ -60,6 +61,9 @@ def copy_from_dict(self, attr_dict: Dict[str, Any]) -> None:
6061
if "script-args" in attr_dict:
6162
self.script_args = attr_dict["script-args"]
6263

64+
if "script-start-delay" in attr_dict:
65+
self.script_start_delay = int(attr_dict["script-start-delay"])
66+
6367
if "py_script_path" in attr_dict:
6468
self.py_script_path = attr_dict["py_script_path"]
6569

@@ -187,6 +191,7 @@ def parse_script(self, py_script_path: str) -> List[Metadata]:
187191
app=attr.get("app", ""),
188192
app_args=attr.get("app_args", ""),
189193
script_args=attr.get("script_args", ""),
194+
script_start_delay=int(attr.get("script_start_delay", 0)),
190195
factoryreset=bool(attr.get("factoryreset", False)),
191196
factoryreset_app_only=bool(attr.get("factoryreset_app_only", False)),
192197
script_gdb=bool(attr.get("script_gdb", False)),

0 commit comments

Comments
 (0)