Skip to content

Commit

Permalink
[test] Add --dry-run option to run_test_suite.py (project-chip#21137)
Browse files Browse the repository at this point in the history
  • Loading branch information
turon authored and isiu-apple committed Sep 16, 2022
1 parent 2d9845e commit 070b07b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
22 changes: 14 additions & 8 deletions scripts/tests/chiptest/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class TestDefinition:
target: TestTarget
is_manual: bool

def Run(self, runner, apps_register, paths: ApplicationPaths, pics_file: str, timeout_seconds: typing.Optional[int]):
def Run(self, runner, apps_register, paths: ApplicationPaths, pics_file: str, timeout_seconds: typing.Optional[int], dry_run=False):
"""
Executes the given test case using the provided runner for execution.
"""
Expand Down Expand Up @@ -264,14 +264,20 @@ def Run(self, runner, apps_register, paths: ApplicationPaths, pics_file: str, ti
app = apps_register.get('default')
app.start()
pairing_cmd = tool_cmd + ['pairing', 'code', TEST_NODE_ID, app.setupCode]
runner.RunSubprocess(pairing_cmd,
name='PAIR', dependencies=[apps_register])

test_cmd = tool_cmd + ['tests', self.run_name] + ['--PICS', pics_file]
runner.RunSubprocess(
test_cmd,
name='TEST', dependencies=[apps_register],
timeout_seconds=timeout_seconds)

if dry_run:
logging.info(" ".join(pairing_cmd))
logging.info(" ".join(test_cmd))

else:
runner.RunSubprocess(pairing_cmd,
name='PAIR', dependencies=[apps_register])

runner.RunSubprocess(
test_cmd,
name='TEST', dependencies=[apps_register],
timeout_seconds=timeout_seconds)

except Exception:
logging.error("!!!!!!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!!!!!!")
Expand Down
15 changes: 12 additions & 3 deletions scripts/tests/run_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class RunContext:
tests: typing.List[chiptest.TestDefinition]
in_unshare: bool
chip_tool: str
dry_run: bool


@click.group(chain=True)
Expand All @@ -70,6 +71,11 @@ class RunContext:
default='info',
type=click.Choice(__LOG_LEVELS__.keys(), case_sensitive=False),
help='Determines the verbosity of script output.')
@click.option(
'--dry-run',
default=False,
is_flag=True,
help='Only print out shell commands that would be executed')
@click.option(
'--target',
default=['all'],
Expand Down Expand Up @@ -106,7 +112,7 @@ class RunContext:
'--chip-tool',
help='Binary path of chip tool app to use to run the test')
@click.pass_context
def main(context, log_level, target, target_glob, target_skip_glob,
def main(context, dry_run, log_level, target, target_glob, target_skip_glob,
no_log_timestamps, root, internal_inside_unshare, chip_tool):
# Ensures somewhat pretty logging of what is going on
log_fmt = '%(asctime)s.%(msecs)03d %(levelname)-7s %(message)s'
Expand Down Expand Up @@ -151,7 +157,7 @@ def main(context, log_level, target, target_glob, target_skip_glob,

context.obj = RunContext(root=root, tests=tests,
in_unshare=internal_inside_unshare,
chip_tool=chip_tool)
chip_tool=chip_tool, dry_run=dry_run)


@main.command(
Expand Down Expand Up @@ -245,7 +251,10 @@ def cmd_run(context, iterations, all_clusters_app, lock_app, ota_provider_app, o
for test in context.obj.tests:
test_start = time.monotonic()
try:
test.Run(runner, apps_register, paths, pics_file, test_timeout_seconds)
if context.obj.dry_run:
logging.info("Would run test %s:" % test.name)

test.Run(runner, apps_register, paths, pics_file, test_timeout_seconds, context.obj.dry_run)
test_end = time.monotonic()
logging.info('%-20s - Completed in %0.2f seconds' %
(test.name, (test_end - test_start)))
Expand Down

0 comments on commit 070b07b

Please sign in to comment.