discover_test.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (c) 2022 Project CHIP Authors
  4. # All rights reserved.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. import argparse
  19. import logging
  20. import queue
  21. import subprocess
  22. import threading
  23. import typing
  24. from colorama import Fore, Style
  25. from java.base import DumpProgramOutputToQueue
  26. class DiscoverTest:
  27. def __init__(self, thread_list: typing.List[threading.Thread], queue: queue.Queue, cmd: [], args: str):
  28. self.thread_list = thread_list
  29. self.queue = queue
  30. self.command = cmd
  31. parser = argparse.ArgumentParser(description='Process discover arguments.')
  32. parser.add_argument('command', help="Command name")
  33. parser.add_argument('-n', '--nodeid', help="DNS-SD name corresponding with the given node ID", default='1')
  34. parser.add_argument('-f', '--fabricid', help="DNS-SD name corresponding with the given fabric ID", default='1')
  35. parser.add_argument('-p', '--paa-trust-store-path', dest='paa_trust_store_path',
  36. help="Path that contains valid and trusted PAA Root Certificates")
  37. args = parser.parse_args(args.split())
  38. self.command_name = args.command
  39. self.nodeid = args.nodeid
  40. self.fabricid = args.fabricid
  41. logging.basicConfig(level=logging.INFO)
  42. def TestCmdCommissionables(self):
  43. java_command = self.command + ['discover', 'commissionables']
  44. logging.info(f"Execute: {java_command}")
  45. java_process = subprocess.Popen(
  46. java_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  47. DumpProgramOutputToQueue(self.thread_list, Fore.GREEN + "JAVA " + Style.RESET_ALL, java_process, self.queue)
  48. return java_process.wait()
  49. def RunTest(self):
  50. logging.info("Testing discovering commissionables devices")
  51. if self.command_name == 'commissionables':
  52. code = self.TestCmdCommissionables()
  53. if code != 0:
  54. raise Exception(f"Testing command commissionables failed with error {code}")
  55. else:
  56. raise Exception(f"Unsupported command {self.command_name}")