From 0fd0a4e28ad88cc3bdd8a8697ec02b7b7a3f4e6c Mon Sep 17 00:00:00 2001 From: hiltonlima <116589806+hiltonlima@users.noreply.github.com> Date: Fri, 15 Mar 2024 16:37:48 -0300 Subject: [PATCH] Move SDK informations to Matter program folder (#78) * Move sdk info to matter program folder * fix fetch sdk stuff script * rename matterSettings fix matter module load in version.py * Fix sdk fetch scripts * Fix import references * Update comments * Read matter sdk sha only if exists * Flake8 fixes * Black fixes * Isort fixes * Isort fixes * Isort fixes --- app/core/config.py | 10 --- app/test_engine/test_collection_discovery.py | 1 + .../test_read_test_harness_backend_version.py | 14 +++- app/version.py | 20 ++++- scripts/pull-chip-tool-image.sh | 22 ------ test_collections/matter/config.py | 34 +++++++++ .../matter/scripts/update-paa-certs.sh | 76 +++++++++++++++++++ .../matter/scripts/update-sample-apps.sh | 29 +++++++ .../scripts/fetch_sdk_tests_and_runner.sh | 13 ++-- .../sdk_tests/support/chip/chip_server.py | 4 +- .../matter/sdk_tests/support/sdk_container.py | 6 +- .../support/tests/chip/test_chip_server.py | 32 ++++---- .../support/tests/test_sdk_container.py | 5 +- .../yaml_tests/test_matter_yaml_runner.py | 20 ++--- .../support/yaml_tests/matter_yaml_runner.py | 4 +- test_collections/matter/setup.sh | 61 +++++++++++++++ 16 files changed, 270 insertions(+), 81 deletions(-) delete mode 100755 scripts/pull-chip-tool-image.sh create mode 100644 test_collections/matter/config.py create mode 100755 test_collections/matter/scripts/update-paa-certs.sh create mode 100755 test_collections/matter/scripts/update-sample-apps.sh create mode 100755 test_collections/matter/setup.sh diff --git a/app/core/config.py b/app/core/config.py index a4056c3..4e44bd4 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -107,16 +107,6 @@ def get_emails_enabled(cls, v: bool, values: Dict[str, Any]) -> bool: NOTIFIER_TO: str = "xiole.chip.test@gmail.com" NOTIFIER_SUBJECT: str = "CHIP Tool Crash Log" - # Test Engine Config - CHIP_TOOL_TRACE: bool = True - SDK_CONTAINER_NAME: str = "th-sdk" - - # SDK Docker Image - SDK_DOCKER_IMAGE: str = "connectedhomeip/chip-cert-bins" - SDK_DOCKER_TAG: str = "9f6d627e0262e1d023986291948bb4e845be803e" - # SDK SHA: used to fetch test YAML from SDK. - SDK_SHA: str = "9f6d627e0262e1d023986291948bb4e845be803e" - class Config: case_sensitive = True diff --git a/app/test_engine/test_collection_discovery.py b/app/test_engine/test_collection_discovery.py index 3068923..3e239fb 100644 --- a/app/test_engine/test_collection_discovery.py +++ b/app/test_engine/test_collection_discovery.py @@ -158,6 +158,7 @@ def __find_classes_of_type(module_name: str, classtype: Type[T]) -> List[Type[T] except Exception: logger.error(traceback.format_exc()) + continue for _, obj in getmembers(submodule): if isclass(obj) and issubclass(obj, classtype): diff --git a/app/tests/version/test_read_test_harness_backend_version.py b/app/tests/version/test_read_test_harness_backend_version.py index 76741d5..d55e9ab 100644 --- a/app/tests/version/test_read_test_harness_backend_version.py +++ b/app/tests/version/test_read_test_harness_backend_version.py @@ -20,10 +20,10 @@ import pytest from app import utils -from app.core.config import settings from app.version import ( SHA_FILEPATH, VERSION_FILEPATH, + read_matter_sdk_sha, read_test_harness_backend_version, ) @@ -56,8 +56,10 @@ def test_read_test_harness_backend_version() -> None: backend_version = read_test_harness_backend_version() assert backend_version.version == expected_version_value assert backend_version.sha == expected_sha_value - assert backend_version.sdk_sha == settings.SDK_SHA[:7] assert backend_version.db_revision == expected_db_revision + matter_sdk_sha = read_matter_sdk_sha() + if matter_sdk_sha is not None: + assert backend_version.sdk_sha == matter_sdk_sha mock_utils.assert_called_once() @@ -73,7 +75,9 @@ def test_read_test_harness_backend_version_with_empty_files() -> None: backend_version = read_test_harness_backend_version() assert backend_version.version == expected_version_value assert backend_version.sha == expected_sha_value - assert backend_version.sdk_sha == settings.SDK_SHA[:7] + matter_sdk_sha = read_matter_sdk_sha() + if matter_sdk_sha is not None: + assert backend_version.sdk_sha == matter_sdk_sha @pytest.mark.serial @@ -88,4 +92,6 @@ def test_read_test_harness_backend_version_with_missing_files() -> None: backend_version = read_test_harness_backend_version() assert backend_version.version == expected_version_value assert backend_version.sha == expected_sha_value - assert backend_version.sdk_sha == settings.SDK_SHA[:7] + matter_sdk_sha = read_matter_sdk_sha() + if matter_sdk_sha is not None: + assert backend_version.sdk_sha == matter_sdk_sha diff --git a/app/version.py b/app/version.py index 79712c8..b1f7122 100644 --- a/app/version.py +++ b/app/version.py @@ -13,16 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import importlib from pathlib import Path +from typing import Optional from loguru import logger from app import utils -from app.core.config import settings from app.schemas.test_harness_backend_version import TestHarnessBackendVersion VERSION_FILENAME = ".version_information" SHA_FILENAME = ".sha_information" +MATTER_CONFIG_MODULE = "test_collections.matter.config" ROOT_PATH = Path(__file__).parent.parent @@ -37,13 +39,12 @@ def read_test_harness_backend_version() -> TestHarnessBackendVersion: version_value = utils.read_information_from_file(VERSION_FILEPATH) sha_value = utils.read_information_from_file(SHA_FILEPATH) db_revision = utils.get_db_revision() - - # Retrieve short SDK SHA from settings (The information is kept in config.py file) - sdk_sha_value = settings.SDK_SHA[:7] + sdk_sha_value = read_matter_sdk_sha() or "" logger.info(f"Test Engine version is {version_value}") logger.info(f"Test Engine SHA is {sha_value}") logger.info(f"Test Engine SDK SHA is {sdk_sha_value}") + return TestHarnessBackendVersion( version=version_value, sha=sha_value, @@ -52,4 +53,15 @@ def read_test_harness_backend_version() -> TestHarnessBackendVersion: ) +def read_matter_sdk_sha() -> Optional[str]: + """ + Retrieve short SDK SHA from settings (The information is kept in config.py file) + """ + if importlib.find_loader(MATTER_CONFIG_MODULE) is None: + return None + + matter_config_module = importlib.import_module(MATTER_CONFIG_MODULE) + return matter_config_module.matter_settings.SDK_SHA[:7] + + version_information = read_test_harness_backend_version() diff --git a/scripts/pull-chip-tool-image.sh b/scripts/pull-chip-tool-image.sh deleted file mode 100755 index 2e97b29..0000000 --- a/scripts/pull-chip-tool-image.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -e -set -x -set -e - - # - # 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. - - -DOCKER_TAG=`python -c "from app.core.config import settings; print(f'{settings.SDK_DOCKER_IMAGE}:{settings.SDK_DOCKER_TAG}')"` -docker pull $DOCKER_TAG \ No newline at end of file diff --git a/test_collections/matter/config.py b/test_collections/matter/config.py new file mode 100644 index 0000000..0f3ad08 --- /dev/null +++ b/test_collections/matter/config.py @@ -0,0 +1,34 @@ +# +# Copyright (c) 2024 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 pydantic import BaseSettings + + +class MatterSettings(BaseSettings): + # Test Engine Config + CHIP_TOOL_TRACE: bool = True + SDK_CONTAINER_NAME: str = "th-sdk" + + # SDK Docker Image + SDK_DOCKER_IMAGE: str = "connectedhomeip/chip-cert-bins" + SDK_DOCKER_TAG: str = "9f6d627e0262e1d023986291948bb4e845be803e" + # SDK SHA: used to fetch test YAML from SDK. + SDK_SHA: str = "9f6d627e0262e1d023986291948bb4e845be803e" + + class Config: + case_sensitive = True + + +matter_settings = MatterSettings() diff --git a/test_collections/matter/scripts/update-paa-certs.sh b/test_collections/matter/scripts/update-paa-certs.sh new file mode 100755 index 0000000..8107cb3 --- /dev/null +++ b/test_collections/matter/scripts/update-paa-certs.sh @@ -0,0 +1,76 @@ +#!/bin/bash -e + + # + # 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. +set -x +set -e + + +# Usage: ./test_collections/matter/scripts/update-paa-certs.sh +# +# Will copy PAA certificates from SDK repository +# +# Environment variables can be used to override behaviour +# - SDK_PATH (When set, SDK_SHA is ignored) +# - SDK_SHA + +# Paths +MATTER_PROGRAM_DIR=$(realpath $(dirname "$0")/..) +TMP_SDK_FOLDER="sdk-sparse" +TMP_SDK_PATH="/tmp/$TMP_SDK_FOLDER" +SDK_CERT_PATH="credentials/development/paa-root-certs" +SDK_CERT_DEVELOPMENT_PATH="credentials/development" +CERT_PATH="/var/paa-root-certs" +DEVELOPMENT_PATH="/var/credentials/development" + +# If SDK path is not present, then do local checkout +if [ -z "$SDK_PATH" ] +then + + # If SDK SHA is not present, then fetch from Matter program config file + if [ -z "$SDK_SHA" ] + then + cd $MATTER_PROGRAM_DIR + SDK_SHA=$(cat $MATTER_PROGRAM_DIR/config.py | grep SDK_SHA | cut -d'"' -f 2 | cut -d"'" -f 2) + fi + + # Checkout SDK sparsely + rm -rf $TMP_SDK_PATH + cd /tmp + git clone --filter=blob:none --no-checkout --depth 1 --sparse https://github.com/project-chip/connectedhomeip.git $TMP_SDK_FOLDER + cd $TMP_SDK_FOLDER + git sparse-checkout init + git sparse-checkout set $SDK_CERT_PATH $SDK_CERT_DEVELOPMENT_PATH + git checkout -q $SDK_SHA + SDK_PATH="$TMP_SDK_PATH" +fi + +# Create folder if missing (owned by user) +if [ ! -d "$CERT_PATH" ] +then + sudo mkdir -p $CERT_PATH + sudo chown $USER:$USER $CERT_PATH +fi + +# Create folder if missing (owned by user) +if [ ! -d "$DEVELOPMENT_PATH" ] +then + sudo mkdir -p $DEVELOPMENT_PATH + sudo chown $USER:$USER $DEVELOPMENT_PATH +fi + +# Copy certs from SDK +cp "$SDK_PATH/$SDK_CERT_PATH/"* $CERT_PATH/ +cp -R "$SDK_PATH/$SDK_CERT_DEVELOPMENT_PATH/"** $DEVELOPMENT_PATH/ diff --git a/test_collections/matter/scripts/update-sample-apps.sh b/test_collections/matter/scripts/update-sample-apps.sh new file mode 100755 index 0000000..4934623 --- /dev/null +++ b/test_collections/matter/scripts/update-sample-apps.sh @@ -0,0 +1,29 @@ +#! /usr/bin/env bash + + # + # 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. +MATTER_PROGRAM_DIR=$(realpath $(dirname "$0")/..) + +printf "\n\n**********" +printf "\n*** Update Matter Sample Apps ***\n" + +# We are fetching SDK docker image and tag name from backend +# This is done to minimize the places the SDK version is tracked. +SDK_DOCKER_IMAGE=$(cat $MATTER_PROGRAM_DIR/config.py | grep SDK_DOCKER_IMAGE | cut -d'"' -f 2 | cut -d"'" -f 2) +SDK_DOCKER_TAG=$(cat $MATTER_PROGRAM_DIR/config.py | grep SDK_DOCKER_TAG | cut -d'"' -f 2 | cut -d"'" -f 2) +sudo docker pull $SDK_DOCKER_IMAGE:$SDK_DOCKER_TAG + +sudo docker run -t -v ~/apps:/apps $SDK_DOCKER_IMAGE:$SDK_DOCKER_TAG bash -c "rm -v /apps/*; cp -v * /apps/;" +sudo chown -R `whoami` ~/apps diff --git a/test_collections/matter/sdk_tests/scripts/fetch_sdk_tests_and_runner.sh b/test_collections/matter/sdk_tests/scripts/fetch_sdk_tests_and_runner.sh index 7ed9bcc..5012f35 100755 --- a/test_collections/matter/sdk_tests/scripts/fetch_sdk_tests_and_runner.sh +++ b/test_collections/matter/sdk_tests/scripts/fetch_sdk_tests_and_runner.sh @@ -1,6 +1,5 @@ #!/bin/bash -e -set -x -set -e + # # Copyright (c) 2023 Project CHIP Authors # @@ -20,9 +19,11 @@ set -e # # When an SDK path is supplied, the SDK_SHA from .env is ignored. # Otherwise a temporary checkout of matter sdk will be made. +set -x +set -e # Paths -ROOT_DIR=$(realpath $(dirname "$0")/../..) +MATTER_PROGRAM_DIR=$(realpath $(dirname "$0")/../..) TMP_SDK_FOLDER="sdk-sparse" TMP_SDK_PATH="/tmp/$TMP_SDK_FOLDER" @@ -35,7 +36,7 @@ SDK_EXAMPLE_CHIP_TOOL_PATH="examples/chip-tool" SDK_EXAMPLE_PLACEHOLDER_PATH="examples/placeholder" SDK_DATA_MODEL_PATH="src/app/zap-templates/zcl/data-model/chip" -TEST_COLLECTIONS_SDK_CHECKOUT_PATH="$ROOT_DIR/sdk_tests/sdk_checkout" +TEST_COLLECTIONS_SDK_CHECKOUT_PATH="$MATTER_PROGRAM_DIR/sdk_tests/sdk_checkout" # YAML Files YAML_TEST_COLLECTION_PATH="$TEST_COLLECTIONS_SDK_CHECKOUT_PATH/yaml_tests" @@ -75,8 +76,8 @@ then echo "Using custom SDK path: ${SDK_PATH}. Update required" SDK_CHECKOUT_VERSION="custom-sdk" else - # Get configured SDK_SHA (will default to value in app/core/config.py) - SDK_SHA=`LOGGING_LEVEL=critical python3 -c "from app.core.config import settings; print(settings.SDK_SHA)"` + # Get configured SDK_SHA (will default to value in test_collection/matter/config.py) + SDK_SHA=$(cat $MATTER_PROGRAM_DIR/config.py | grep SDK_SHA | cut -d'"' -f 2 | cut -d"'" -f 2) if [[ $FORCE_UPDATE -eq 1 ]] then echo "Update is forced." diff --git a/test_collections/matter/sdk_tests/support/chip/chip_server.py b/test_collections/matter/sdk_tests/support/chip/chip_server.py index 8333f3c..bd27147 100644 --- a/test_collections/matter/sdk_tests/support/chip/chip_server.py +++ b/test_collections/matter/sdk_tests/support/chip/chip_server.py @@ -23,10 +23,10 @@ import loguru -from app.core.config import settings from app.singleton import Singleton from app.test_engine.logger import CHIPTOOL_LEVEL from app.test_engine.logger import test_engine_logger as logger +from test_collections.matter.config import matter_settings from ..sdk_container import DOCKER_LOGS_PATH, DOCKER_PAA_CERTS_PATH, SDKContainer @@ -128,7 +128,7 @@ async def start( else: raise UnsupportedChipServerType(f"Unsupported server type: {server_type}") - if settings.CHIP_TOOL_TRACE: + if matter_settings.CHIP_TOOL_TRACE: topic = "CHIP_WEBSOCKET_SERVER" command.append(self.trace_file_params(topic)) diff --git a/test_collections/matter/sdk_tests/support/sdk_container.py b/test_collections/matter/sdk_tests/support/sdk_container.py index 50ae205..59d50ae 100644 --- a/test_collections/matter/sdk_tests/support/sdk_container.py +++ b/test_collections/matter/sdk_tests/support/sdk_container.py @@ -22,10 +22,10 @@ from docker.models.containers import Container from app.container_manager import container_manager -from app.core.config import settings from app.schemas.pics import PICS, PICSError from app.singleton import Singleton from app.test_engine.logger import test_engine_logger as logger +from test_collections.matter.config import matter_settings from .exec_run_in_container import ExecResultExtended, exec_run_in_container from .pics import set_pics_command @@ -79,8 +79,8 @@ class SDKContainer(metaclass=Singleton): Create an instance by calling initializer. When ready to use, ... """ - container_name = settings.SDK_CONTAINER_NAME - image_tag = f"{settings.SDK_DOCKER_IMAGE}:{settings.SDK_DOCKER_TAG}" + container_name = matter_settings.SDK_CONTAINER_NAME + image_tag = f"{matter_settings.SDK_DOCKER_IMAGE}:{matter_settings.SDK_DOCKER_TAG}" run_parameters = { "privileged": True, "detach": True, diff --git a/test_collections/matter/sdk_tests/support/tests/chip/test_chip_server.py b/test_collections/matter/sdk_tests/support/tests/chip/test_chip_server.py index 2ef414a..3f6b41e 100644 --- a/test_collections/matter/sdk_tests/support/tests/chip/test_chip_server.py +++ b/test_collections/matter/sdk_tests/support/tests/chip/test_chip_server.py @@ -21,7 +21,7 @@ import pytest -from app.core.config import settings +from test_collections.matter.config import matter_settings from ...chip.chip_server import ( CHIP_APP_EXE, @@ -76,9 +76,9 @@ async def test_start_unsupported_server_type() -> None: @pytest.mark.asyncio async def test_start_waiting_failure() -> None: - original_trace_setting_value = settings.CHIP_TOOL_TRACE + original_trace_setting_value = matter_settings.CHIP_TOOL_TRACE if original_trace_setting_value is True: - settings.CHIP_TOOL_TRACE = False + matter_settings.CHIP_TOOL_TRACE = False chip_server: ChipServer = ChipServer() sdk_container: SDKContainer = SDKContainer() @@ -109,14 +109,14 @@ async def test_start_waiting_failure() -> None: # clean up: chip_server._ChipServer__server_logs = None chip_server._ChipServer__chip_server_id = None - settings.CHIP_TOOL_TRACE = original_trace_setting_value + matter_settings.CHIP_TOOL_TRACE = original_trace_setting_value @pytest.mark.asyncio async def test_start_chip_tool() -> None: - original_trace_setting_value = settings.CHIP_TOOL_TRACE + original_trace_setting_value = matter_settings.CHIP_TOOL_TRACE if original_trace_setting_value is True: - settings.CHIP_TOOL_TRACE = False + matter_settings.CHIP_TOOL_TRACE = False chip_server: ChipServer = ChipServer() sdk_container: SDKContainer = SDKContainer() @@ -146,14 +146,14 @@ async def test_start_chip_tool() -> None: chip_server._ChipServer__server_logs = None chip_server._ChipServer__chip_server_id = None chip_server._ChipServer__server_started = False - settings.CHIP_TOOL_TRACE = original_trace_setting_value + matter_settings.CHIP_TOOL_TRACE = original_trace_setting_value @pytest.mark.asyncio async def test_start_chip_tool_using_paa_certs() -> None: - original_trace_setting_value = settings.CHIP_TOOL_TRACE + original_trace_setting_value = matter_settings.CHIP_TOOL_TRACE if original_trace_setting_value is True: - settings.CHIP_TOOL_TRACE = False + matter_settings.CHIP_TOOL_TRACE = False chip_server: ChipServer = ChipServer() sdk_container: SDKContainer = SDKContainer() @@ -187,14 +187,14 @@ async def test_start_chip_tool_using_paa_certs() -> None: chip_server._ChipServer__server_logs = None chip_server._ChipServer__chip_server_id = None chip_server._ChipServer__server_started = False - settings.CHIP_TOOL_TRACE = original_trace_setting_value + matter_settings.CHIP_TOOL_TRACE = original_trace_setting_value @pytest.mark.asyncio async def test_start_chip_app() -> None: - original_trace_setting_value = settings.CHIP_TOOL_TRACE + original_trace_setting_value = matter_settings.CHIP_TOOL_TRACE if original_trace_setting_value is True: - settings.CHIP_TOOL_TRACE = False + matter_settings.CHIP_TOOL_TRACE = False chip_server: ChipServer = ChipServer() sdk_container: SDKContainer = SDKContainer() @@ -224,14 +224,14 @@ async def test_start_chip_app() -> None: chip_server._ChipServer__server_logs = None chip_server._ChipServer__chip_server_id = None chip_server._ChipServer__server_started = False - settings.CHIP_TOOL_TRACE = original_trace_setting_value + matter_settings.CHIP_TOOL_TRACE = original_trace_setting_value @pytest.mark.asyncio async def test_start_chip_app_using_paa_certs() -> None: - original_trace_setting_value = settings.CHIP_TOOL_TRACE + original_trace_setting_value = matter_settings.CHIP_TOOL_TRACE if original_trace_setting_value is True: - settings.CHIP_TOOL_TRACE = False + matter_settings.CHIP_TOOL_TRACE = False chip_server: ChipServer = ChipServer() sdk_container: SDKContainer = SDKContainer() @@ -264,4 +264,4 @@ async def test_start_chip_app_using_paa_certs() -> None: chip_server._ChipServer__server_logs = None chip_server._ChipServer__chip_server_id = None chip_server._ChipServer__server_started = False - settings.CHIP_TOOL_TRACE = original_trace_setting_value + matter_settings.CHIP_TOOL_TRACE = original_trace_setting_value diff --git a/test_collections/matter/sdk_tests/support/tests/test_sdk_container.py b/test_collections/matter/sdk_tests/support/tests/test_sdk_container.py index ef6ba19..abe7a89 100644 --- a/test_collections/matter/sdk_tests/support/tests/test_sdk_container.py +++ b/test_collections/matter/sdk_tests/support/tests/test_sdk_container.py @@ -22,8 +22,8 @@ import pytest from app.container_manager import container_manager -from app.core.config import settings from app.tests.utils.docker import make_fake_container +from test_collections.matter.config import matter_settings from ..exec_run_in_container import ExecResultExtended from ..sdk_container import SDKContainer, SDKContainerNotRunning @@ -34,7 +34,8 @@ async def test_start() -> None: sdk_container: SDKContainer = SDKContainer() # Values to verify - docker_image = f"{settings.SDK_DOCKER_IMAGE}:{settings.SDK_DOCKER_TAG}" + docker_image = f"{matter_settings.SDK_DOCKER_IMAGE}:\ +{matter_settings.SDK_DOCKER_TAG}" with mock.patch.object( target=sdk_container, attribute="is_running", return_value=False diff --git a/test_collections/matter/sdk_tests/support/tests/yaml_tests/test_matter_yaml_runner.py b/test_collections/matter/sdk_tests/support/tests/yaml_tests/test_matter_yaml_runner.py index 8d88527..5e5ccc9 100644 --- a/test_collections/matter/sdk_tests/support/tests/yaml_tests/test_matter_yaml_runner.py +++ b/test_collections/matter/sdk_tests/support/tests/yaml_tests/test_matter_yaml_runner.py @@ -26,9 +26,9 @@ from matter_yamltests.runner import TestRunnerConfig from matter_yamltests.websocket_runner import WebSocketRunner, WebSocketRunnerConfig -from app.core.config import settings from app.schemas.pics import PICSError from app.tests.utils.test_pics_data import create_random_pics +from test_collections.matter.config import matter_settings from ...chip.chip_server import ChipServer, ChipServerType from ...pics import PICS_FILE_PATH, SHELL_OPTION, SHELL_PATH @@ -346,9 +346,9 @@ async def test_run_test_with_nodeID_and_cluster_parameters() -> None: @pytest.mark.asyncio async def test_pairing_on_network_command_params() -> None: - original_trace_setting_value = settings.CHIP_TOOL_TRACE + original_trace_setting_value = matter_settings.CHIP_TOOL_TRACE if original_trace_setting_value is True: - settings.CHIP_TOOL_TRACE = False + matter_settings.CHIP_TOOL_TRACE = False # Attributes runner: MatterYAMLRunner = MatterYAMLRunner() @@ -373,15 +373,15 @@ async def test_pairing_on_network_command_params() -> None: mock_send_websocket_command.assert_awaited_once_with(expected_command) # clean up: - settings.CHIP_TOOL_TRACE = original_trace_setting_value + matter_settings.CHIP_TOOL_TRACE = original_trace_setting_value chip_server._ChipServer__node_id = None @pytest.mark.asyncio async def test_pairing_ble_wifi_command_params() -> None: - original_trace_setting_value = settings.CHIP_TOOL_TRACE + original_trace_setting_value = matter_settings.CHIP_TOOL_TRACE if original_trace_setting_value is True: - settings.CHIP_TOOL_TRACE = False + matter_settings.CHIP_TOOL_TRACE = False # Attributes runner: MatterYAMLRunner = MatterYAMLRunner() @@ -412,15 +412,15 @@ async def test_pairing_ble_wifi_command_params() -> None: mock_send_websocket_command.assert_awaited_once_with(expected_command) # clean up: - settings.CHIP_TOOL_TRACE = original_trace_setting_value + matter_settings.CHIP_TOOL_TRACE = original_trace_setting_value chip_server._ChipServer__node_id = None @pytest.mark.asyncio async def test_pairing_ble_thread_command_params() -> None: - original_trace_setting_value = settings.CHIP_TOOL_TRACE + original_trace_setting_value = matter_settings.CHIP_TOOL_TRACE if original_trace_setting_value is True: - settings.CHIP_TOOL_TRACE = False + matter_settings.CHIP_TOOL_TRACE = False # Attributes runner: MatterYAMLRunner = MatterYAMLRunner() @@ -450,5 +450,5 @@ async def test_pairing_ble_thread_command_params() -> None: mock_send_websocket_command.assert_awaited_once_with(expected_command) # clean up: - settings.CHIP_TOOL_TRACE = original_trace_setting_value + matter_settings.CHIP_TOOL_TRACE = original_trace_setting_value chip_server._ChipServer__node_id = None diff --git a/test_collections/matter/sdk_tests/support/yaml_tests/matter_yaml_runner.py b/test_collections/matter/sdk_tests/support/yaml_tests/matter_yaml_runner.py index 19f8646..7709f02 100644 --- a/test_collections/matter/sdk_tests/support/yaml_tests/matter_yaml_runner.py +++ b/test_collections/matter/sdk_tests/support/yaml_tests/matter_yaml_runner.py @@ -35,11 +35,11 @@ from matter_yamltests.websocket_runner import WebSocketRunner, WebSocketRunnerConfig from app.container_manager.backend_container import backend_container -from app.core.config import settings from app.schemas.pics import PICS, PICSError from app.singleton import Singleton from app.test_engine.logger import CHIP_LOG_FORMAT, CHIPTOOL_LEVEL from app.test_engine.logger import test_engine_logger as logger +from test_collections.matter.config import matter_settings from ..chip.chip_server import ChipServer, ChipServerType from ..paths import SDK_CHECKOUT_PATH @@ -165,7 +165,7 @@ async def send_websocket_command(self, cmd: str) -> Union[str, bytes, bytearray] async def pairing(self, mode: str, *params: str) -> bool: command = [PAIRING_CMD, mode] + list(params) - if settings.CHIP_TOOL_TRACE: + if matter_settings.CHIP_TOOL_TRACE: topic = f"PAIRING_{mode}" command.append(self.chip_server.trace_file_params(topic)) diff --git a/test_collections/matter/setup.sh b/test_collections/matter/setup.sh new file mode 100755 index 0000000..a748a5f --- /dev/null +++ b/test_collections/matter/setup.sh @@ -0,0 +1,61 @@ +#! /usr/bin/env bash + + # + # Copyright (c) 2024 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. +set -e +MATTER_PROGRAM_DIR=$(dirname "$0") + +printf "\n\n**********" +printf "\n*** Installing Matter Dependencies ***\n" +# TODO Comment on what dependency is required for: +packagelist=( + "apt-transport-https (=2.4.11)" + "avahi-utils (>=0.8-5ubuntu5.2)" # Matter uses Avahi + "ca-certificates (=20230311ubuntu0.22.04.1)" + "figlet (=2.2.5-3)" + "g++ (=4:11.2.0-1ubuntu1)" + "gcc (=4:11.2.0-1ubuntu1)" + "generate-ninja (=0.0~git20220118.0725d78-1)" + "libavahi-client-dev (=0.8-5ubuntu5.2)" + "libcairo2-dev (=1.16.0-5ubuntu2)" + "libdbus-1-dev (=1.12.20-2ubuntu4.1)" + "libgirepository1.0-dev (=1.72.0-1)" + "libglib2.0-dev (=2.72.4-0ubuntu2.2)" + "libreadline-dev (=8.1.2-1)" + "libssl-dev (>=3.0.2-0ubuntu1.14)" # Apparently with each update, previous versions of the library are removed + "net-tools (=1.60+git20181103.0eebece-1ubuntu5)" + "ninja-build (=1.10.1-1)" + "npm (=8.5.1~ds-1)" + "pkg-config (=0.29.2-1ubuntu3)" + "software-properties-common (=0.99.22.9)" + "toilet (=0.3-1.4)" + "unzip (>=6.0-26ubuntu3.1)" +) + +SAVEIFS=$IFS +IFS=$(echo -en "\r") +for package in ${packagelist[@]}; do + echo "# Instaling package: ${package[@]}" + sudo DEBIAN_FRONTEND=noninteractive sudo apt satisfy ${package[@]} -y --allow-downgrades +done +IFS=$SAVEIFS + +printf "\n\n**********" +printf "\n*** Fetching sample apps ***\n" +$MATTER_PROGRAM_DIR/scripts/update-sample-apps.sh + +printf "\n\n**********" +printf "\n*** Fetching PAA Certs from SDK ***\n" +$MATTER_PROGRAM_DIR/scripts/update-paa-certs.sh