Skip to content

Commit 754a938

Browse files
Add some documentation about matter idl tools that we have for validating data (#30198)
* Add some documentation about matter idl tooling * Restyle * Add zigbee only note, because that caught me a bit * Restyle * Add quotes on cmdline examples * clearer docs a bit * Add an external data model for the data model md (make sphinx happy) * make build succeed * Some better orphan markers to let sphinx process these files without a TOC entry. I was unsure how to make a proper toc here * fix spelling --------- Co-authored-by: Andrei Litvin <andreilitvin@google.com>
1 parent efc5fb8 commit 754a938

File tree

7 files changed

+105
-3
lines changed

7 files changed

+105
-3
lines changed

data_model/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
orphan: true
3+
---
4+
15
## Contents
26

37
This folder contains a machine-readable representation of matter clusters.

docs/conf.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
"examples/thermostat/nxp/linux-se05x/README.md",
3333
"examples/common/m5stack-tft/repo",
3434
"docs/guides/README.md",
35-
"scripts/tools/memory/memdf/README.md",
36-
"scripts/tools/memory/platform/README.md",
37-
"scripts/tools/memory/README-GitHub-CI.md",
3835
]
3936

4037

@@ -67,6 +64,7 @@
6764

6865
external_content_contents = [
6966
(MATTER_BASE / "docs", "[!_R]*"),
67+
(MATTER_BASE, "data_model/**/*.md"),
7068
(MATTER_BASE, "README.md"),
7169
(MATTER_BASE, "examples/**/*.md"),
7270
(MATTER_BASE, "examples/**/*.png"),
@@ -82,5 +80,6 @@
8280
"README", # cannot detect README.md
8381
"scripts/",
8482
"examples/android/",
83+
"data_model/",
8584
]
8685
external_content_link_extensions = [".md", ".png", ".jpg", ".svg"]

docs/guides/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ ti/ti_platform_overview
5555

5656
- [Access Control](./access-control-guide.md)
5757
- [IP Commissioning](./ip_commissioning.md)
58+
- [Matter IDL tooling and validation](./matter_idl_tooling.md)
5859

5960
## Setup Guides
6061

docs/guides/matter_idl_tooling.md

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# The `.matter` IDL file format
2+
3+
The matter IDL file format is designed to be a human-readable representation of
4+
data structures, cluster definitions and endpoint composition.
5+
6+
Since it is designed to be easy for both machine and humans to read, it is the
7+
basis of some tools to make validating zap-based cluster definitions easier.
8+
9+
More details on the format in
10+
[matter_idl/README.md](../../scripts/py_matter_idl/matter_idl/README.md).
11+
12+
## Parsing CSA XML Data definitions
13+
14+
The SDK contains a copy of CSA XML data definitions in `data_model/clusters`.
15+
16+
The files there are updated by running a scraper against the official matter
17+
specification and are a good source of truth for actual definitions. Update
18+
information available in [data_model/README.md](../../data_model/README.md).
19+
20+
NOTE: scraper is a work in progress, XML data may be incomplete or have errors
21+
still.
22+
23+
The script `./scripts/py_matter_idl/matter_idl/data_model_xml_parser.py` has the
24+
ability to parse one or more CSA data model XML files and output their content
25+
in `.matter` format. For example:
26+
27+
```sh
28+
./scripts/py_matter_idl/matter_idl/data_model_xml_parser.py data_model/clusters/BooleanState.xml
29+
```
30+
31+
The tool supports several options that are useful for development:
32+
33+
| Argument(s) | Description |
34+
| ----------------------- | ----------------------------------------------------------------------------------- |
35+
| `-o/--output PATH` | Output the matter file into a path instead of STDOUT. |
36+
| `--compare PATH` | Also read another `.matter` file for compare. MUST be used with `--compare-output`. |
37+
| `--compare-output PATH` | Output the subset of `--compare` clusters that matches XML into PATH. |
38+
39+
Using `--compare` AND `--compare-output` produce output that is easier to
40+
compare as opposed to using existing zap-generated matter files because it
41+
strips out comments and it also alpha-sorts elements so that diffs are
42+
human-readable.
43+
44+
### Comparing a `.matter` file against the spec
45+
46+
Combining arguments to the tool allows getting a diff between SDK and
47+
specification:
48+
49+
- `data_model/clusters/*.xml` are assumed to be the official specification
50+
definitions
51+
- `src/controller/data_model/controller-clusters.matter` contains _all_
52+
clusters defined in the SDK
53+
54+
As such one can run compares such as:
55+
56+
```sh
57+
./scripts/py_matter_idl/matter_idl/data_model_xml_parser.py \
58+
-o out/spec.matter \
59+
--compare-output out/sdk.matter \
60+
--compare src/controller/data_model/controller-clusters.matter \
61+
data_model/clusters/DoorLock.xml \
62+
&& diff out/{spec,sdk}.matter
63+
```
64+
65+
NOTE: due to specification data scraper still being in development, the diff
66+
should be human-validated (e.g. for tool errors or Zigbee-only markers in the
67+
spec).
68+
69+
## Linting `.matter` files for devices
70+
71+
For device validation, `./scripts/idl_lint.py` provides the ability to validate
72+
a matter file for some basic conformance logic. These rules are expressed in
73+
`scripts/rules.matterlint`.
74+
75+
The rules generally are:
76+
77+
- pre-loaded from silabs XML files (validates that mandatory attributes are
78+
present)
79+
- Hard-coded rules (e.g. mandatory clusters and attributes on specific
80+
endpoints)
81+
82+
Usage:
83+
84+
```sh
85+
./scripts/idl_lint.py ./examples/window-app/common/window-app.matter
86+
```

scripts/tools/memory/README-GitHub-CI.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
orphan: true
3+
---
4+
15
# Scripts for GitHub CI
26

37
A set of `gh_*.py` scripts work together to produce size comparisons for PRs.

scripts/tools/memory/memdf/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
orphan: true
3+
---
4+
15
This package contains routines to to collect, aggregate, and report memory
26
usage, using Pandas `DataFrame` as the primary representation.
37

scripts/tools/memory/platform/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
orphan: true
3+
---
4+
15
A config file is a Python (nested) dictionary used by
26
`memdf.util.config.Config`.
37

0 commit comments

Comments
 (0)