diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 6e5b650bc19133..04bbef6ff50b39 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -462,7 +462,19 @@ jobs: --target linux-x64-java-matter-controller \ build \ " - - name: Run Tests + - name: Run Discover Tests + timeout-minutes: 65 + run: | + scripts/run_in_build_env.sh \ + './scripts/tests/run_java_test.py \ + --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app \ + --app-args "--discriminator 3840 --interface-id -1" \ + --tool-path out/linux-x64-java-matter-controller \ + --tool-cluster "discover" \ + --tool-args "commissionables" \ + --factoryreset \ + ' + - name: Run Pairing Tests timeout-minutes: 65 run: | scripts/run_in_build_env.sh \ diff --git a/scripts/tests/java/commissioning_test.py b/scripts/tests/java/commissioning_test.py index ba991b8390271b..3985c08b9a5383 100755 --- a/scripts/tests/java/commissioning_test.py +++ b/scripts/tests/java/commissioning_test.py @@ -17,7 +17,6 @@ # limitations under the License. # -# Commissioning test. import logging import os import sys @@ -59,7 +58,7 @@ def __init__(self, thread_list: typing.List[threading.Thread], queue: queue.Queu logging.basicConfig(level=logging.INFO) - def TestOnnetworkLong(self, nodeid, setuppin, discriminator, timeout): + def TestCmdOnnetworkLong(self, nodeid, setuppin, discriminator, timeout): java_command = self.command + ['pairing', 'onnetwork-long', nodeid, setuppin, discriminator, timeout] logging.info(f"Execute: {java_command}") java_process = subprocess.Popen( @@ -70,10 +69,8 @@ def TestOnnetworkLong(self, nodeid, setuppin, discriminator, timeout): def RunTest(self): logging.info("Testing onnetwork-long pairing") 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 + code = self.TestCmdOnnetworkLong(self.nodeid, self.setup_payload, self.discriminator, self.timeout) + if code != 0: + raise Exception(f"Testing onnetwork-long pairing failed with error {code}") + else: + raise Exception(f"Unsupported command {self.command_name}") diff --git a/scripts/tests/java/discover_test.py b/scripts/tests/java/discover_test.py new file mode 100755 index 00000000000000..81d493fba8750e --- /dev/null +++ b/scripts/tests/java/discover_test.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +# +# Copyright (c) 2022 Project CHIP Authors +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import logging +import os +import sys +import asyncio +import queue +import subprocess +import threading +import typing +import argparse +from colorama import Fore, Style +from java.base import DumpProgramOutputToQueue + + +class DiscoverTest: + def __init__(self, thread_list: typing.List[threading.Thread], queue: queue.Queue, cmd: [], args: str): + self.thread_list = thread_list + self.queue = queue + self.command = cmd + + parser = argparse.ArgumentParser(description='Process discover arguments.') + + parser.add_argument('command', help="Command name") + parser.add_argument('-n', '--nodeid', help="DNS-SD name corresponding with the given node ID", default='1') + parser.add_argument('-f', '--fabricid', help="DNS-SD name corresponding with the given fabric ID", default='1') + parser.add_argument('-p', '--paa-trust-store-path', dest='paa_trust_store_path', + help="Path that contains valid and trusted PAA Root Certificates") + + args = parser.parse_args(args.split()) + + self.command_name = args.command + self.nodeid = args.nodeid + self.fabricid = args.fabricid + + logging.basicConfig(level=logging.INFO) + + def TestCmdCommissionables(self): + java_command = self.command + ['discover', 'commissionables'] + logging.info(f"Execute: {java_command}") + java_process = subprocess.Popen( + java_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + DumpProgramOutputToQueue(self.thread_list, Fore.GREEN + "JAVA " + Style.RESET_ALL, java_process, self.queue) + return java_process.wait() + + def RunTest(self): + logging.info("Testing discovering commissionables devices") + + if self.command_name == 'commissionables': + code = self.TestCmdCommissionables() + if code != 0: + raise Exception(f"Testing command commissionables failed with error {code}") + else: + raise Exception(f"Unsupported command {self.command_name}") diff --git a/scripts/tests/run_java_test.py b/scripts/tests/run_java_test.py index 4ca163a7eb4790..060355f8b93a26 100755 --- a/scripts/tests/run_java_test.py +++ b/scripts/tests/run_java_test.py @@ -28,6 +28,7 @@ import sys from java.base import DumpProgramOutputToQueue from java.commissioning_test import CommissioningTest +from java.discover_test import DiscoverTest from colorama import Fore, Style @@ -87,10 +88,20 @@ def main(app: str, app_args: str, tool_path: str, tool_cluster: str, tool_args: logging.info("Testing pairing cluster") test = CommissioningTest(log_cooking_threads, log_queue, command, tool_args) - controller_exit_code = test.RunTest() - - if controller_exit_code != 0: - logging.error("Test script exited with error %r" % test_script_exit_code) + try: + test.RunTest() + except Exception as e: + logging.error(e) + sys.exit(1) + elif tool_cluster == 'discover': + logging.info("Testing discover cluster") + + test = DiscoverTest(log_cooking_threads, log_queue, command, tool_args) + try: + test.RunTest() + except Exception as e: + logging.error(e) + sys.exit(1) app_exit_code = 0 if app_process: @@ -103,11 +114,8 @@ def main(app: str, app_args: str, tool_path: str, tool_cluster: str, tool_args: for thread in log_cooking_threads: thread.join() - if controller_exit_code != 0: - sys.exit(controller_exit_code) - else: - # We expect both app and controller should exit with 0 - sys.exit(app_exit_code) + # We expect app should exit with 0 + sys.exit(app_exit_code) if __name__ == '__main__':