darwinframeworktool.py 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env -S python3 -B
  2. # Copyright (c) 2023 Project CHIP Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import relative_importer # isort: split # noqa: F401
  16. import sys
  17. from typing import List
  18. import click
  19. from paths_finder import PathsFinder
  20. from runner import CONTEXT_SETTINGS, darwinframeworktool
  21. from tests_tool import send_raw_command, send_yaml_command
  22. _DEFAULT_EXTENSIONS_DIR = 'scripts/tests/yaml/extensions'
  23. _DEFAULT_PICS_FILE = 'src/app/tests/suites/certification/ci-pics-values'
  24. _DEFAULT_SPECIFICATIONS_DIR = 'src/app/zap-templates/zcl/data-model/chip/*.xml'
  25. def darwinframeworktool_runner_options(f):
  26. f = click.option('--server_path', type=click.Path(exists=True), default=None,
  27. help='Path to an websocket server to run at launch.')(f)
  28. f = click.option('--server_name', type=str, default='darwin-framework-tool',
  29. help='Name of a websocket server to run at launch.')(f)
  30. f = click.option('--server_arguments', type=str, default='interactive server',
  31. help='Optional arguments to pass to the websocket server at launch.')(f)
  32. f = click.option('--show_adapter_logs', type=bool, default=False, show_default=True,
  33. help='Show additional logs provided by the adapter.')(f)
  34. f = click.option('--delay-in-ms', '--delayInMs', type=int, default=0, show_default=True,
  35. help='Add a delay between each test suite steps.')(f)
  36. f = click.option('--continueOnFailure', type=bool, default=False, show_default=True,
  37. help='Do not stop running the test suite on first error.')(f)
  38. f = click.option('--specifications_paths', type=click.Path(), show_default=True, default=_DEFAULT_SPECIFICATIONS_DIR,
  39. help='Path to a set of files containing clusters definitions.')(f)
  40. f = click.option('--PICS', type=click.Path(exists=True), show_default=True, default=_DEFAULT_PICS_FILE,
  41. help='Path to the PICS file to use.')(f)
  42. f = click.option('--additional_pseudo_clusters_directory', type=click.Path(), show_default=True, default=_DEFAULT_EXTENSIONS_DIR,
  43. help='Path to a directory containing additional pseudo clusters.')(f)
  44. return f
  45. CONTEXT_SETTINGS['ignore_unknown_options'] = True
  46. CONTEXT_SETTINGS['default_map']['darwinframeworktool']['use_test_harness_log_format'] = True
  47. def maybe_update_stop_on_error(ctx):
  48. if ctx.params['continueonfailure']:
  49. ctx.params['stop_on_error'] = False
  50. del ctx.params['continueonfailure']
  51. @click.command(context_settings=CONTEXT_SETTINGS)
  52. @click.argument('commands', nargs=-1)
  53. @darwinframeworktool_runner_options
  54. @click.pass_context
  55. def darwinframeworktool_py(ctx, commands: List[str], server_path: str, server_name: str, server_arguments: str, show_adapter_logs: bool, delay_in_ms: int, continueonfailure: bool, specifications_paths: str, pics: str, additional_pseudo_clusters_directory: str):
  56. success = False
  57. server_arguments = ctx.params['server_arguments']
  58. maybe_update_stop_on_error(ctx)
  59. if len(commands) > 1 and commands[0] == 'tests':
  60. success = send_yaml_command(darwinframeworktool, commands[1], server_path, server_arguments, show_adapter_logs, specifications_paths, pics,
  61. additional_pseudo_clusters_directory, commands[2:])
  62. else:
  63. if server_path is None and server_name:
  64. paths_finder = PathsFinder()
  65. server_path = paths_finder.get(server_name)
  66. success = send_raw_command(' '.join(commands), server_path, server_arguments)
  67. sys.exit(0 if success else 1)
  68. if __name__ == '__main__':
  69. darwinframeworktool_py()