Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Add testing for discovering commissionables devices #24007

Merged
merged 4 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
15 changes: 6 additions & 9 deletions scripts/tests/java/commissioning_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# limitations under the License.
#

# Commissioning test.
import logging
import os
import sys
Expand Down Expand Up @@ -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(
Expand All @@ -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}")
71 changes: 71 additions & 0 deletions scripts/tests/java/discover_test.py
Original file line number Diff line number Diff line change
@@ -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}")
26 changes: 17 additions & 9 deletions scripts/tests/run_java_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand All @@ -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__':
Expand Down