Skip to content

Commit

Permalink
[CI] Add testing for discovering commissionables devices
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Dec 9, 2022
1 parent 9988e81 commit 9589758
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,15 @@ jobs:
- name: Run 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 "--nodeid 1 --fabricid 1" \
--factoryreset \
'
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 \
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/java/commissioning_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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]
print(java_command)
logging.info(f"Execute: {java_command}")
Expand All @@ -116,7 +116,7 @@ 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)
java_exit_code = self.TestCmdOnnetworkLong(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
Expand Down
94 changes: 94 additions & 0 deletions scripts/tests/java/discover_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/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.
#

# Discovery test.
import logging
import os
import sys
import asyncio
import queue
import subprocess
import threading
import typing
from optparse import OptionParser
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

optParser = OptionParser()
optParser.add_option(
"--nodeid",
action="store",
dest="nodeid",
default='1',
type='str',
help="DNS-SD name corresponding with the given node ID",
metavar="<nodeid>"
)
optParser.add_option(
"--fabricid",
action="store",
dest="fabricid",
default='1',
type='str',
help="DNS-SD name corresponding with the given fabric ID",
metavar="<nodeid>"
)
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="<paa-trust-store-path>"
)

(options, remainingArgs) = optParser.parse_args(args.split())

self.nodeid = options.nodeid
self.fabricid = options.fabricid

logging.basicConfig(level=logging.INFO)

def TestCmdCommissionables(self):
java_command = self.command + ['discover', 'commissionables']
print(java_command)
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")
java_exit_code = self.TestCmdCommissionables()
if java_exit_code != 0:
logging.error("Testing command commissionables failed with error %r" % java_exit_code)
return java_exit_code

# Testing complete without errors
return 0
9 changes: 9 additions & 0 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 @@ -89,6 +90,14 @@ def main(app: str, app_args: str, tool_path: str, tool_cluster: str, tool_args:
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)
elif tool_cluster == 'discover':
logging.info("Testing discover cluster")

test = DiscoverTest(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)

Expand Down

0 comments on commit 9589758

Please sign in to comment.