|
14 | 14 | # See the License for the specific language governing permissions and
|
15 | 15 | # limitations under the License.
|
16 | 16 |
|
| 17 | +import argparse |
17 | 18 | import logging
|
18 | 19 | import os
|
19 | 20 | import signal
|
20 | 21 | import subprocess
|
21 | 22 | import sys
|
22 | 23 | import time
|
23 | 24 |
|
24 |
| -DEFAULT_CHIP_ROOT = os.path.abspath( |
25 |
| - os.path.join(os.path.dirname(__file__), '..', '..')) |
| 25 | +DEFAULT_CHIP_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) |
| 26 | + |
| 27 | +DEFAULT_ALL_CLUSTERS = os.path.join( |
| 28 | + DEFAULT_CHIP_ROOT, |
| 29 | + 'out', |
| 30 | + 'linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test', |
| 31 | + 'chip-all-clusters-app') |
| 32 | +DEFAULT_TEST_RUNNER = os.path.join(DEFAULT_CHIP_ROOT, 'scripts', 'tests', 'run_python_test.py') |
| 33 | +DEFAULT_TEST_SCRIPT = os.path.join(DEFAULT_CHIP_ROOT, 'src', 'python_testing', 'TestTimeSyncTrustedTimeSource.py') |
26 | 34 |
|
27 | 35 |
|
28 | 36 | class TestDriver:
|
29 |
| - def __init__(self): |
30 |
| - self.app_path = os.path.abspath(os.path.join(DEFAULT_CHIP_ROOT, 'out', |
31 |
| - 'linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test', 'chip-all-clusters-app')) |
32 |
| - self.run_python_test_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'run_python_test.py')) |
| 37 | + def __init__(self, all_clusters: str, test_runner: str, test_script: str): |
| 38 | + self.app_path = all_clusters |
| 39 | + self.run_python_test_path = test_runner |
| 40 | + self.script_path = test_script |
33 | 41 |
|
34 |
| - self.script_path = os.path.abspath(os.path.join( |
35 |
| - DEFAULT_CHIP_ROOT, 'src', 'python_testing', 'TestTimeSyncTrustedTimeSource.py')) |
36 | 42 | if not os.path.exists(self.app_path):
|
37 |
| - msg = 'chip-all-clusters-app not found' |
38 |
| - logging.error(msg) |
39 |
| - raise FileNotFoundError(msg) |
| 43 | + logging.error('%s not found', self.app_path) |
| 44 | + raise FileNotFoundError(self.app_path) |
40 | 45 | if not os.path.exists(self.run_python_test_path):
|
41 |
| - msg = 'run_python_test.py script not found' |
42 |
| - logging.error(msg) |
43 |
| - raise FileNotFoundError(msg) |
| 46 | + logging.error('%s not found', self.run_python_test_path) |
| 47 | + raise FileNotFoundError(self.run_python_test_path) |
44 | 48 | if not os.path.exists(self.script_path):
|
45 |
| - msg = 'TestTimeSyncTrustedTimeSource.py script not found' |
46 |
| - logging.error(msg) |
47 |
| - raise FileNotFoundError(msg) |
| 49 | + logging.error('%s not found', self.script_path) |
| 50 | + raise FileNotFoundError(self.script_path) |
48 | 51 |
|
49 | 52 | def get_base_run_python_cmd(self, run_python_test_path, app_path, app_args, script_path, script_args):
|
50 | 53 | return f'{str(run_python_test_path)} --app {str(app_path)} --app-args "{app_args}" --script {str(script_path)} --script-args "{script_args}"'
|
@@ -78,7 +81,17 @@ def main():
|
78 | 81 | base_script_args = '--storage-path admin_storage.json --discriminator 1234 --passcode 20202021'
|
79 | 82 | script_args = base_script_args + ' --commissioning-method on-network --commission-only'
|
80 | 83 |
|
81 |
| - driver = TestDriver() |
| 84 | + parser = argparse.ArgumentParser('TimeSyncTrustedTimeSource runner', formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 85 | + parser.add_argument('--all-clusters', default=DEFAULT_ALL_CLUSTERS, help="All clusters application.") |
| 86 | + parser.add_argument('--test-runner', default=DEFAULT_TEST_RUNNER, help="the run_python_test.py script.") |
| 87 | + parser.add_argument('--test-script', default=DEFAULT_TEST_SCRIPT, help="The path to the TimeSyncTrustedTimeSource test.") |
| 88 | + args = parser.parse_args() |
| 89 | + |
| 90 | + driver = TestDriver( |
| 91 | + all_clusters=args.all_clusters, |
| 92 | + test_runner=args.test_runner, |
| 93 | + test_script=args.test_script, |
| 94 | + ) |
82 | 95 | ret = driver.run_test_section(app_args, script_args, factory_reset_all=True)
|
83 | 96 | if ret != 0:
|
84 | 97 | return ret
|
|
0 commit comments