Skip to content

Commit

Permalink
Add matter_yamlclusters with a set of default clusters for running so…
Browse files Browse the repository at this point in the history
…me of the yaml tests
  • Loading branch information
vivien-apple committed Jan 24, 2023
1 parent 044297d commit 0005dfc
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scripts/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import("$dir_pw_build/python_dist.gni")
# out/obj/matter_yamltests_distribution/ <- source files here
# out/obj/matter_yamltests_distribution._build_wheel/matter_yamltests-0.0.1-py3-none-any.whl
pw_python_distribution("matter_yamltests_distribution") {
packages = [ "${chip_root}/scripts/py_matter_yamltests:matter_yamltests" ]
packages = [
"${chip_root}/scripts/py_matter_yamltests:matter_yamltests",
"${chip_root}/scripts/py_matter_yamlclusters:matter_yamlclusters",
]
generate_setup_cfg = {
common_config_file = "common_setup.cfg"
include_default_pyproject_file = true
Expand Down
41 changes: 41 additions & 0 deletions scripts/py_matter_yamlclusters/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2023 Project CHIP Authors
#
# 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("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

import("//build_overrides/pigweed.gni")
import("$dir_pw_build/python.gni")

pw_python_package("matter_yamlclusters") {
setup = [
"setup.py",
"setup.cfg",
"pyproject.toml",
]

sources = [
"matter_yamlclusters/__init__.py",
"matter_yamlclusters/clusters.py",
"matter_yamlclusters/cluster/delay_commands.py",
"matter_yamlclusters/cluster/log_commands.py",
"matter_yamlclusters/cluster/system_commands.py",
]

python_deps = [ "${chip_root}/scripts/py_matter_yamltests:matter_yamltests" ]

# TODO: at a future time consider enabling all (* or missing) here to get
# pylint checking these files
static_analysis = []
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Copyright (c) 2023 Project CHIP Authors
#
# 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 sys
import time

from matter_yamltests.test_cluster import TestCluster


class DelayCommands(TestCluster):
name = 'DelayCommands'

async def WaitForMs(self, request):
duration_in_ms = 0

for argument in request.arguments['values']:
if argument['name'] == 'ms':
duration_in_ms = argument['value']

sys.stdout.flush()
time.sleep(duration_in_ms / 1000)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) 2023 Project CHIP Authors
#
# 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.

from matter_yamltests.test_cluster import TestCluster


class LogCommands(TestCluster):
name = 'LogCommands'

async def UserPrompt(self, request):
pass

async def Log(self, request):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#
# Copyright (c) 2023 Project CHIP Authors
#
# 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 sys
import xmlrpc.client

from matter_yamltests.test_cluster import TestCluster

DEFAULT_KEY = 'default'
IP = '127.0.0.1'
PORT = 9000

if sys.platform == 'linux':
IP = '10.10.10.5'


def make_url():
return 'http://' + IP + ':' + str(PORT) + '/'


def get_register_key(request):
if request.arguments:
values = request.arguments['values']
for item in values:
name = item['name']
value = item['value']
if name == 'registerKey':
return value

return DEFAULT_KEY


def get_options(request):
options = []

if request.arguments:
values = request.arguments['values']
for item in values:
name = item['name']
value = item['value']

if name == 'discriminator':
options.append('--discriminator')
options.append(str(value))
elif name == 'port':
options.append('--secured-device-port')
options.append(str(value))
elif name == 'kvs':
options.append('--KVS')
options.append(str(value))
elif name == 'minCommissioningTimeout':
options.append('--min_commissioning_timeout')
options.append(str(value))
elif name == 'filepath':
options.append('--filepath')
options.append(str(value))
elif name == 'otaDownloadPath':
options.append('--otaDownloadPath')
options.append(str(value))
elif name == 'registerKey':
pass
else:
raise KeyError(f'Unknown key: {name}')

return options


class SystemCommands(TestCluster):
name = 'SystemCommands'

async def Start(self, request):
register_key = get_register_key(request)
options = get_options(request)

with xmlrpc.client.ServerProxy(make_url(), allow_none=True) as proxy:
proxy.start(register_key, options)

async def Stop(self, request):
register_key = get_register_key(request)

with xmlrpc.client.ServerProxy(make_url(), allow_none=True) as proxy:
proxy.stop(register_key)

async def Reboot(self, request):
register_key = get_register_key(request)

with xmlrpc.client.ServerProxy(make_url(), allow_none=True) as proxy:
proxy.reboot(register_key)

async def FactoryReset(self, request):
register_key = get_register_key(request)

with xmlrpc.client.ServerProxy(make_url(), allow_none=True) as proxy:
proxy.factoryReset(register_key)
26 changes: 26 additions & 0 deletions scripts/py_matter_yamlclusters/matter_yamlclusters/clusters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) 2023 Project CHIP Authors
#
# 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.

from matter_yamlclusters.cluster.delay_commands import DelayCommands
from matter_yamlclusters.cluster.log_commands import LogCommands
from matter_yamlclusters.cluster.system_commands import SystemCommands


def get_default_clusters():
return [
DelayCommands(),
LogCommands(),
SystemCommands()
]
17 changes: 17 additions & 0 deletions scripts/py_matter_yamlclusters/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2023 Project CHIP Authors
#
# 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.

[build-system]
requires = ['setuptools', 'wheel']
build-backend = 'setuptools.build_meta'
24 changes: 24 additions & 0 deletions scripts/py_matter_yamlclusters/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2023 Project CHIP Authors
#
# 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.

[metadata]
name = matter_yamlclusters
version = 0.0.1
author = Project CHIP Authors
description = Implement YAML test clusters

[options]
packages = find:

zip_safe = False
20 changes: 20 additions & 0 deletions scripts/py_matter_yamlclusters/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2023 Project CHIP Authors
#
# 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.


"""The matter_yamlclusters package."""

import setuptools # type: ignore

setuptools.setup() # Package definition in setup.cfg

0 comments on commit 0005dfc

Please sign in to comment.