Skip to content

Commit

Permalink
Use the PathsFinder module in scripts/tests/run_test_suite.py instead…
Browse files Browse the repository at this point in the history
… of having duplicated code (#25368)
  • Loading branch information
vivien-apple authored and pull[bot] committed Aug 24, 2023
1 parent d9a9c12 commit 1157112
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions scripts/tests/run_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@
import logging
import os
import sys
import tempfile
import time
import typing
from dataclasses import dataclass, field
from pathlib import Path

import chiptest
import click
import coloredlogs
from chiptest.accessories import AppsRegister
from chiptest.glob_matcher import GlobMatcher
from chiptest.test_definition import TestRunTime, TestTag
from diskcache import Cache

cache = Cache(os.path.join(tempfile.gettempdir(), 'yaml_runner_cache'))
from yaml.paths_finder import PathsFinder

DEFAULT_CHIP_ROOT = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..'))
Expand All @@ -44,25 +40,6 @@ class ManualHandling(enum.Enum):
ONLY = enum.auto()


def FindBinaryPath(name: str):
binary_path = cache.get(name)
if binary_path:
if Path(binary_path).is_file():
return binary_path
else:
del cache[name]

for path in Path(DEFAULT_CHIP_ROOT).rglob(name):
if not path.is_file():
continue
if path.name != name:
continue
cache[name] = str(path)
return str(path)

return 'NOT_FOUND_IN_OUTPUT_' + name


# Supported log levels, mapping string values required for argument
# parsing into logging constants
__LOG_LEVELS__ = {
Expand Down Expand Up @@ -169,7 +146,8 @@ def main(context, dry_run, log_level, target, target_glob, target_skip_glob,

if chip_tool is None and not runtime == TestRunTime.CHIP_REPL_PYTHON:
# non yaml tests REQUIRE chip-tool. Yaml tests should not require chip-tool
chip_tool = FindBinaryPath('chip-tool')
paths_finder = PathsFinder()
chip_tool = paths_finder.get('chip-tool')

if include_tags:
include_tags = set([TestTag.__members__[t] for t in include_tags])
Expand Down Expand Up @@ -292,29 +270,31 @@ def cmd_run(context, iterations, all_clusters_app, lock_app, ota_provider_app, o
tv_app, bridge_app, chip_repl_yaml_tester, chip_tool_with_python, pics_file, keep_going, test_timeout_seconds):
runner = chiptest.runner.Runner()

paths_finder = PathsFinder()

if all_clusters_app is None:
all_clusters_app = FindBinaryPath('chip-all-clusters-app')
all_clusters_app = paths_finder.get('chip-all-clusters-app')

if lock_app is None:
lock_app = FindBinaryPath('chip-lock-app')
lock_app = paths_finder.get('chip-lock-app')

if ota_provider_app is None:
ota_provider_app = FindBinaryPath('chip-ota-provider-app')
ota_provider_app = paths_finder.get('chip-ota-provider-app')

if ota_requestor_app is None:
ota_requestor_app = FindBinaryPath('chip-ota-requestor-app')
ota_requestor_app = paths_finder.get('chip-ota-requestor-app')

if tv_app is None:
tv_app = FindBinaryPath('chip-tv-app')
tv_app = paths_finder.get('chip-tv-app')

if bridge_app is None:
bridge_app = FindBinaryPath('chip-bridge-app')
bridge_app = paths_finder.get('chip-bridge-app')

if chip_repl_yaml_tester is None:
chip_repl_yaml_tester = FindBinaryPath('yamltest_with_chip_repl_tester.py')
chip_repl_yaml_tester = paths_finder.get('yamltest_with_chip_repl_tester.py')

if chip_tool_with_python is None:
chip_tool_with_python = FindBinaryPath('chiptool.py')
chip_tool_with_python = paths_finder.get('chiptool.py')

# Command execution requires an array
paths = chiptest.ApplicationPaths(
Expand Down

0 comments on commit 1157112

Please sign in to comment.