diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 11541859a24299..2a3ae2b39426ef 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -471,7 +471,7 @@ jobs: --app-args "--discriminator 3840 --interface-id -1" \ --tool-path out/linux-x64-java-matter-controller \ --tool-cluster "pairing" \ - --tool-args "--nodeid 1 --setup-payload 20202021 --discriminator 3840 -t 1000" \ + --tool-args "onnetwork-long --nodeid 1 --setup-payload 20202021 --discriminator 3840 -t 1000" \ --factoryreset \ ' - name: Uploading core files diff --git a/scripts/tests/java/commissioning_test.py b/scripts/tests/java/commissioning_test.py index afd132c575b4e7..ba991b8390271b 100755 --- a/scripts/tests/java/commissioning_test.py +++ b/scripts/tests/java/commissioning_test.py @@ -26,7 +26,7 @@ import subprocess import threading import typing -from optparse import OptionParser +import argparse from colorama import Fore, Style from java.base import DumpProgramOutputToQueue @@ -37,77 +37,30 @@ def __init__(self, thread_list: typing.List[threading.Thread], queue: queue.Queu self.queue = queue self.command = cmd - optParser = OptionParser() - optParser.add_option( - "-t", - "--timeout", - action="store", - dest="testTimeout", - default='200', - type='str', - help="The program will return with timeout after specified seconds.", - metavar="", - ) - optParser.add_option( - "-a", - "--address", - action="store", - dest="deviceAddress", - default='', - type='str', - help="Address of the device", - metavar="", - ) - optParser.add_option( - "--setup-payload", - action="store", - dest="setupPayload", - default='', - type='str', - help="Setup Payload (manual pairing code or QR code content)", - metavar="" - ) - optParser.add_option( - "--nodeid", - action="store", - dest="nodeid", - default='1', - type='str', - help="The Node ID issued to the device", - metavar="" - ) - optParser.add_option( - "--discriminator", - action="store", - dest="discriminator", - default='3840', - type='str', - help="Discriminator of the device", - metavar="" - ) - optParser.add_option( - "-p", - "--paa-trust-store-path", - action="store", - dest="paaTrustStorePath", - default='', - type='str', - help="Path that contains valid and trusted PAA Root Certificates.", - metavar="" - ) + parser = argparse.ArgumentParser(description='Process pairing arguments.') - (options, remainingArgs) = optParser.parse_args(args.split()) + parser.add_argument('command', help="Command name") + parser.add_argument('-t', '--timeout', help="The program will return with timeout after specified seconds", default='200') + parser.add_argument('-a', '--address', help="Address of the device") + parser.add_argument('-s', '--setup-payload', dest='setup_payload', + help="Setup Payload (manual pairing code or QR code content)") + parser.add_argument('-n', '--nodeid', help="The Node ID issued to the device", default='1') + parser.add_argument('-d', '--discriminator', help="Discriminator of the device", default='3840') + parser.add_argument('-p', '--paa-trust-store-path', dest='paa_trust_store_path', + help="Path that contains valid and trusted PAA Root Certificates") - self.nodeid = options.nodeid - self.setupPayload = options.setupPayload - self.discriminator = options.discriminator - self.testTimeout = options.testTimeout + args = parser.parse_args(args.split()) + + self.command_name = args.command + self.nodeid = args.nodeid + self.setup_payload = args.setup_payload + self.discriminator = args.discriminator + self.timeout = args.timeout logging.basicConfig(level=logging.INFO) def TestOnnetworkLong(self, nodeid, setuppin, discriminator, timeout): java_command = self.command + ['pairing', 'onnetwork-long', nodeid, setuppin, discriminator, timeout] - print(java_command) logging.info(f"Execute: {java_command}") java_process = subprocess.Popen( java_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -116,10 +69,11 @@ def TestOnnetworkLong(self, nodeid, setuppin, discriminator, timeout): def RunTest(self): logging.info("Testing onnetwork-long pairing") - java_exit_code = self.TestOnnetworkLong(self.nodeid, self.setupPayload, self.discriminator, self.testTimeout) - if java_exit_code != 0: - logging.error("Testing onnetwork-long pairing failed with error %r" % java_exit_code) - return java_exit_code + if self.command_name == 'onnetwork-long': + java_exit_code = self.TestOnnetworkLong(self.nodeid, self.setup_payload, self.discriminator, self.timeout) + if java_exit_code != 0: + logging.error("Testing onnetwork-long pairing failed with error %r" % java_exit_code) + return java_exit_code # Testing complete without errors return 0