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

Add tests for Matter plugin #3

Merged
merged 33 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e9b88ce
Update format to pass lint-pylint check
MonicaisHer Jan 3, 2024
2a72dd0
Add matter plugin unit test
MonicaisHer Jan 3, 2024
11bcf3b
Correct plugin properties names
MonicaisHer Jan 9, 2024
d4f6935
Fix bootstrap path
MonicaisHer Jan 9, 2024
c944a99
Add matter hello world snap for spread test
MonicaisHer Jan 10, 2024
68f1b73
Build hello world snap based on Matter lighting app
MonicaisHer Jan 11, 2024
95eb444
Overwrite the original main.app
MonicaisHer Jan 12, 2024
67cad0f
Update app name for spread test
MonicaisHer Jan 12, 2024
eebead2
Correct bootstrap path in unit test, fix typo in readme
MonicaisHer Jan 12, 2024
63f096c
Remove obsolete file
MonicaisHer Jan 12, 2024
1b2da56
Update comments
MonicaisHer Jan 12, 2024
698debd
Build lighting app from gn_build_example.sh
MonicaisHer Jan 16, 2024
ac0f29f
Update member type
MonicaisHer Jan 16, 2024
1e5909b
Fix pyright errors
MonicaisHer Jan 16, 2024
4751257
Use specific commit for matter sdk
MonicaisHer Jan 17, 2024
e139b7f
working code
MonicaisHer Jan 17, 2024
bb1a3d4
Add craft parts matter plugin test
MonicaisHer Jan 18, 2024
5702233
Update craft parts matter plugin test
MonicaisHer Jan 19, 2024
62c6d51
Test app initialization, remove hello-world snap
MonicaisHer Jan 22, 2024
648e712
Use matter commit with ptpython version fix
MonicaisHer Jan 22, 2024
32688df
Update unit test and spread test
MonicaisHer Jan 22, 2024
b9ede83
Store plugin environment, source environment in override-build
MonicaisHer Jan 22, 2024
664b81d
Remove hello-world snap related code
MonicaisHer Jan 22, 2024
1a274ac
Remove snapcraft part related environment variables
MonicaisHer Jan 22, 2024
a609bc2
Rename the plugin to matter sdk
MonicaisHer Jan 22, 2024
6d50ff8
Remove snapcraft part related env vars in plugin
MonicaisHer Jan 22, 2024
2a1cfe9
Update plugin keyword's name and file names
MonicaisHer Jan 23, 2024
1894129
Seperate pull and build commands, source only environment differences
MonicaisHer Jan 24, 2024
7d07d4c
Export environment variable PATH, improve formatting
MonicaisHer Jan 25, 2024
25973ab
Export zap and pigweed environment variables
MonicaisHer Jan 25, 2024
b50c90a
Export zap environment variable
MonicaisHer Jan 25, 2024
3a51c1a
Fix tox linter
MonicaisHer Jan 25, 2024
d63e5c0
Improve formatting
MonicaisHer Jan 25, 2024
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
52 changes: 25 additions & 27 deletions snapcraft/parts/plugins/matter_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,41 +117,40 @@ def get_build_commands(self) -> List[str]:
if self.snap_arch == "arm64":
commands.extend(
[
f"wget --no-verbose https://github.com/project-chip/zap/releases/download/"
"wget --no-verbose https://github.com/project-chip/zap/releases/download/"
f"{options.matter_zap_version}/zap-linux-{self.snap_arch}.zip",
f"unzip -o zap-linux-{self.snap_arch}.zip",
"echo 'export ZAP_INSTALL_PATH=$PWD'",
]
)

# Clone Matter repository if not present
commands.extend(
[
"if [ ! -d matter ]; then",
f" git clone --depth 1 -b {options.matter_sdk_version} {MATTER_REPO} matter;",
"else",
" echo 'Matter repository already exists, skip clone';",
"fi",
"cd matter;",
]
)
commands.extend([
"if [ ! -d matter ]; then",
f" git clone {MATTER_REPO} matter",
" cd matter",
" git config advice.detachedHead false",
f" git checkout {options.matter_sdk_version};",
"else",
" echo 'Matter repository already exists, skip clone'",
" cd matter;",
"fi",
])

# Checkout submodules for Linux platform
commands.extend(["scripts/checkout_submodules.py --shallow --platform linux"])

"""
The project writes its data to /tmp which isn't persisted.
# The project writes its data to /tmp which isn't persisted.

Setting TMPDIR env var when running the app isn't sufficient as
chip_[config,counter,factory,kvs].ini still get written under /tmp.
The chip-tool currently has no way of overriding the default paths to
storage and security config files.
# Setting TMPDIR env var when running the app isn't sufficient as
# chip_[config,counter,factory,kvs].ini still get written under /tmp.
# The chip-tool currently has no way of overriding the default paths to
# storage and security config files.

Snap does not allow bind mounting a persistent directory on /tmp,
so we need to replace it in the source with another path, e.g. /mnt.
See the top-level layout definition which bind mounts a persisted
directory within the confined snap space on /mnt.
"""
# Snap does not allow bind mounting a persistent directory on /tmp,
# so we need to replace it in the source with another path, e.g. /mnt.
# See the top-level layout definition which bind mounts a persisted
# directory within the confined snap space on /mnt.

# Replace storage paths
commands.extend(
Expand All @@ -161,12 +160,11 @@ def get_build_commands(self) -> List[str]:
]
)

"""
Bootstrapping script for building Matter SDK with minimal "build" requirements
and setting up the environment.
"""
# Bootstrapping script for building Matter SDK with minimal "build" requirements
# and setting up the environment.

commands.extend(
["set +u && source setup/bootstrap.sh --platform build && set -u"]
["set +u && source scripts/setup/bootstrap.sh --platform build && set -u"]
)

commands.extend(["echo 'Built Matter SDK'"])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# matter_hello

A new Matter project.

## Getting Started

This project is a starting point for a simple application based on [Matter SDK](https://github.com/project-chip/connectedhomeip).

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
*
* Copyright (c) 2020 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.
*/

#include "LightingAppCommandDelegate.h"
#include "LightingManager.h"
#include <AppMain.h>

#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/ConcreteAttributePath.h>
#include <app/server/Server.h>
#include <lib/support/logging/CHIPLogging.h>

#if defined(CHIP_IMGUI_ENABLED) && CHIP_IMGUI_ENABLED
#include <imgui_ui/ui.h>
#include <imgui_ui/windows/light.h>
#include <imgui_ui/windows/occupancy_sensing.h>
#include <imgui_ui/windows/qrcode.h>

#include <iostream>

#endif

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;

namespace {

constexpr char kChipEventFifoPathPrefix[] = "/tmp/chip_lighting_fifo_";
NamedPipeCommands sChipNamedPipeCommands;
LightingAppCommandDelegate sLightingAppCommandDelegate;
} // namespace

void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
uint8_t * value)
{
if (attributePath.mClusterId == OnOff::Id && attributePath.mAttributeId == OnOff::Attributes::OnOff::Id)
{
LightingMgr().InitiateAction(*value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION);
}
}

void emberAfOnOffClusterInitCallback(EndpointId endpoint)
{
// TODO: implement any additional Cluster Server init actions
}

void ApplicationInit()
{
std::string path = kChipEventFifoPathPrefix + std::to_string(getpid());

if (sChipNamedPipeCommands.Start(path, &sLightingAppCommandDelegate) != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Failed to start CHIP NamedPipeCommands");
sChipNamedPipeCommands.Stop();
}
}

void ApplicationShutdown()
{
if (sChipNamedPipeCommands.Stop() != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Failed to stop CHIP NamedPipeCommands");
}
}

int main(int argc, char * argv[])
{
std::cout << "hello world" << std::endl;

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: matter-hello
version: "1.0"
summary: simple matter application
description: build an example lighting application using the Matter SDK and say "hello world"
base: core22
confinement: strict

apps:
matter-hello:
command: bin/lighting-app

parts:
lighting-hello:
plugin: matter
matter-sdk-version: "1536ca2" # use this commit with ptpython version fix; needs to be updated once sdk have a stable release
matter-zap-version: "v2023.11.13"
source: app
override-build: |
craftctl default
cd $CRAFT_PART_BUILD/matter

# Overwrite the main application file so that it prints "hello world"
cp -v $CRAFT_PART_BUILD/main.cpp examples/lighting-app/linux/main.cpp

# Build the lighting app
scripts/examples/gn_build_example.sh examples/lighting-app/linux/ ./out/build

ldd out/build/chip-lighting-app

mkdir -p $CRAFT_PART_INSTALL/bin
cp out/build/chip-lighting-app $CRAFT_PART_INSTALL/bin/lighting-app



Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ environment:
SNAP/colcon_ros2_humble: colcon-ros2-humble-hello
SNAP/colcon_ros2_wrapper: colcon-ros2-wrapper
SNAP/flutter: flutter-hello
SNAP/matter: matter-hello
SNAP/python: python-hello

prepare: |
Expand Down
37 changes: 37 additions & 0 deletions tests/spread/plugins/craft-parts/matter/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: matter-lighting
summary: Matter plugin test
description: An lighting application to test the matter plugin.
version: "1.0"

base: core22

grade: stable
build-base: core22
confinement: strict

layout:
/mnt:
bind: $SNAP_COMMON/mnt

apps:
matter-lighting:
daemon: simple
command: bin/lighting-app
install-mode: disable

parts:
matter-lighting:
plugin: matter
matter-sdk-version: "1536ca2" # use this commit with ptpython version fix; needs to be updated once sdk have a stable release
matter-zap-version: "v2023.11.13"
override-build: |
craftctl default
cd $CRAFT_PART_BUILD/matter

scripts/examples/gn_build_example.sh examples/lighting-app/linux/ ./out/build

ldd out/build/chip-lighting-app

mkdir -p $CRAFT_PART_INSTALL/bin
cp out/build/chip-lighting-app $CRAFT_PART_INSTALL/bin/lighting-app

40 changes: 40 additions & 0 deletions tests/spread/plugins/craft-parts/matter/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
summary: Craft Parts matter plugin test
manual: true
kill-timeout: 180m

systems:
- ubuntu-22.04-64

prepare: |
#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
. "$TOOLS_DIR/snapcraft-yaml.sh"
set_base "$SNAP/snap/snapcraft.yaml"

restore: |
cd "$SNAP"
snapcraft clean
rm -f ./*.snap

#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
. "$TOOLS_DIR/snapcraft-yaml.sh"
restore_yaml "snap/snapcraft.yaml"

execute: |
cd "$SNAP"

# Build and install the snap
snapcraft
snap install "${SNAP}"*.snap --dangerous

snap start matter-lighting

# Check if storage path replacement from /tmp to SNAP_COMMON/mnt works
if [ -e /tmp/chip_* ]; then
echo "Error: /tmp/chip_* should not exist."
exit 1
fi

if [ ! -e "${SNAP_COMMON/mnt/chip_*}" ]; then
echo "Error: $SNAP_COMMON/mnt/chip_* does not exist."
exit 1
fi
Loading
Loading