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

Valve cluster: refactor to make unit-testable #35631

Draft
wants to merge 35 commits into
base: master
Choose a base branch
from

Conversation

cecille
Copy link
Contributor

@cecille cecille commented Sep 17, 2024

Refactor of Valve to enable unit testing of the cluster logic per the proposal in https://project-chip.github.io/connectedhomeip-doc/cluster_and_device_type_dev/unit_testing_clusters.html.

Unit tests are in TestValveConfigurationAndControl

General outline

  • Server implementation receives TLV, calls into the cluster logic for all read/write/command operations. Server is only responsible for encode / decode, error translation and installing itself into the registry. Uses AttributeAccessInterface and CommandHandlerInterface

  • Cluster logic

    • handles all reads / writes and commands
    • no TLV parsing (handled by server)
    • no interaction with the ember layer (handled by the matter context)
    • no interaction with the hardware (handled by the delegate)
    • Uses a subclass for all attribute reads / writes that handles storage and attribute reporting. Data members are private to force the logic to go through the setters to properly trigger reporting and storage
  • Matter context handles attribute reporting (and will handle event logging once I implement it). This can be mocked for testing.

  • Timers and clocks are injected by the test at the system layer (not the matter context) because there is a single clock for the entire system.

  • App owns all the resources - delegate, matter context, logic and server and initializes them as part of the app startup

  • one of each is instantiated once for each endpoint

Open questions on the general design:

  • should the cluster logic return IM layer errors directly
  • should the cluster logic use the codegen'd data types for the attributes
  • is there a way to get rid of some of the boilerplate?
  • should the cluster logic handle the global attributes or some of the global attributes?
  • Should Setter calls on the cluster logic (ex SetValveFault) be piped through the delegate or should we let the app report these to the logic directly?
  • One server per endpoint? Or pooled?

Open questions for the valve:

  • should the cluster logic periodically reach out to the delegate to get updates on state / level for async opens? Should it allow the delegate to also report back? Both?

Remaining:

  • event generation

  • AutoCloseTime handling

  • handling of async opens / closes

  • set functions for things like valve fault

  • command handling for > EP1 seems to be broken, still need to fix that.

Copy link

semanticdiff-com bot commented Sep 17, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  src/python_testing/TC_VALCC_3_1.py  52% smaller
  src/python_testing/TC_VALCC_3_2.py  18% smaller
  src/python_testing/TC_VALCC_3_3.py  18% smaller
  src/python_testing/TC_VALCC_2_1.py  15% smaller
  src/python_testing/TC_VALCC_4_1.py  15% smaller
  src/python_testing/TC_VALCC_4_2.py  15% smaller
  src/python_testing/TC_VALCC_4_5.py  15% smaller
  src/python_testing/TC_VALCC_4_3.py  11% smaller
  src/python_testing/TC_VALCC_3_4.py  4% smaller
  src/python_testing/TC_VALCC_4_4.py  3% smaller
  examples/valve/controller/README.md Unsupported file format
  examples/valve/controller/__init__.py  0% smaller
  examples/valve/linux/.gn Unsupported file format
  examples/valve/linux/BUILD.gn Unsupported file format
  examples/valve/linux/args.gni Unsupported file format
  examples/valve/linux/build_overrides  0% smaller
  examples/valve/linux/include/CHIPProjectAppConfig.h Unsupported file format
  examples/valve/linux/main.cpp Unsupported file format
  examples/valve/linux/third_party/connectedhomeip  0% smaller
  examples/valve/valve-common/BUILD.gn Unsupported file format
  examples/valve/valve-common/valve-app.matter Unsupported file format
  examples/valve/valve-common/valve-app.zap Unsupported file format
  src/app/chip_data_model.gni Unsupported file format
  src/app/cluster-building-blocks/QuieterReporting.h Unsupported file format
  src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.cpp Unsupported file format
  src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.h Unsupported file format
  src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-delegate.h Unsupported file format
  src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-matter-context.cpp Unsupported file format
  src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-matter-context.h Unsupported file format
  src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server-disco.cpp Unsupported file format
  src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server-disco.h Unsupported file format
  src/app/tests/BUILD.gn Unsupported file format
  src/app/tests/TestValveConfigurationAndControl.cpp Unsupported file format
  src/lib/core/DataModelTypes.h Unsupported file format
  src/lib/support/DefaultStorageKeyAllocator.h Unsupported file format
  src/python_testing/matter_testing_infrastructure/chip/testing/matter_testing.py  0% smaller
  src/python_testing/matter_testing_infrastructure/chip/testing/taglist_and_topology_test.py  0% smaller

Copy link

github-actions bot commented Sep 17, 2024

PR #35631: Size comparison from 85b2fd3 to 83d5b79

Full report (82 builds for bl602, bl702, bl702l, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
platform target config section 85b2fd3 83d5b79 change % change
bl602 lighting-app bl602 FLASH 1278192 1278192 0 0.0
RAM 95824 95824 0 0.0
bl602+mfd FLASH 1292302 1292302 0 0.0
RAM 95968 95968 0 0.0
bl602+rpc FLASH 1317156 1317156 0 0.0
RAM 104248 104248 0 0.0
bl702 lighting-app bl702 FLASH 943868 943868 0 0.0
RAM 15145 15145 0 0.0
bl702+mfd FLASH 946268 946268 0 0.0
RAM 15305 15305 0 0.0
bl702+rpc FLASH 1039188 1039188 0 0.0
RAM 24173 24173 0 0.0
bl706-eth FLASH 646064 646064 0 0.0
RAM 25233 25233 0 0.0
bl706-wifi FLASH 894076 894076 0 0.0
RAM 14477 14477 0 0.0
bl702l lighting-app bl702l FLASH 960528 960528 0 0.0
RAM 16804 16804 0 0.0
bl702l+mfd FLASH 963150 963150 0 0.0
RAM 16964 16964 0 0.0
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 677269 677269 0 0.0
RAM 78492 78492 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 697121 697121 0 0.0
RAM 81124 81124 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 697121 697121 0 0.0
RAM 81124 81124 0 0.0
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 654049 654049 0 0.0
RAM 73560 73560 0 0.0
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 613461 613461 0 0.0
RAM 71452 71452 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 633089 633089 0 0.0
RAM 74004 74004 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 633089 633089 0 0.0
RAM 74004 74004 0 0.0
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 632589 632589 0 0.0
RAM 74500 74500 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 652297 652297 0 0.0
RAM 77052 77052 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 652297 652297 0 0.0
RAM 77052 77052 0 0.0
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 608005 608005 0 0.0
RAM 68588 68588 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 627857 627857 0 0.0
RAM 71220 71220 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 627857 627857 0 0.0
RAM 71220 71220 0 0.0
efr32 lighting-app BRD4187C FLASH 932500 932500 0 0.0
RAM 135056 135056 0 0.0
lock-app BRD2605a FLASH 739960 739952 -8 -0.0
RAM 231212 231212 0 0.0
BRD4338a FLASH 740608 740600 -8 -0.0
RAM 231244 231244 0 0.0
window-app BRD4187C FLASH 1015544 1015536 -8 -0.0
RAM 126996 126996 0 0.0
esp32 all-clusters-app c3devkit DRAM 94152 94152 0 0.0
FLASH 1539520 1539498 -22 -0.0
IRAM 82538 82538 0 0.0
m5stack DRAM 115096 115096 0 0.0
FLASH 1549862 1549862 0 0.0
IRAM 117039 117039 0 0.0
linux air-purifier-app debug unknown 4688 4688 0 0.0
FLASH 2771259 2771259 0 0.0
RAM 128944 128944 0 0.0
all-clusters-app debug unknown 5456 5456 0 0.0
FLASH 6082752 6083014 262 0.0
RAM 514288 514288 0 0.0
all-clusters-minimal-app debug unknown 5352 5352 0 0.0
FLASH 5406808 5406808 0 0.0
RAM 240640 240640 0 0.0
bridge-app debug unknown 5336 5336 0 0.0
FLASH 4740320 4740320 0 0.0
RAM 217840 217840 0 0.0
chip-tool debug unknown 5888 5888 0 0.0
FLASH 12676380 12676380 0 0.0
RAM 562282 562282 0 0.0
chip-tool-ipv6only arm64 unknown 20384 20384 0 0.0
FLASH 11341636 11341636 0 0.0
RAM 612384 612384 0 0.0
fabric-admin debug unknown 5720 5720 0 0.0
FLASH 10979263 10979263 0 0.0
RAM 561322 561322 0 0.0
fabric-bridge-app debug unknown 4568 4568 0 0.0
FLASH 4563058 4563058 0 0.0
RAM 204456 204456 0 0.0
lighting-app debug+rpc+ui unknown 5984 5984 0 0.0
FLASH 5676641 5676641 0 0.0
RAM 228128 228128 0 0.0
lock-app debug unknown 5272 5272 0 0.0
FLASH 4789600 4789600 0 0.0
RAM 203928 203928 0 0.0
ota-provider-app debug unknown 4648 4648 0 0.0
FLASH 4422786 4422786 0 0.0
RAM 197632 197632 0 0.0
ota-requestor-app debug unknown 4584 4584 0 0.0
FLASH 4561532 4561532 0 0.0
RAM 202200 202200 0 0.0
shell debug unknown 4216 4216 0 0.0
FLASH 3107917 3108173 256 0.0
RAM 159448 159448 0 0.0
thermostat-no-ble arm64 unknown 9336 9336 0 0.0
FLASH 4333292 4333292 0 0.0
RAM 242256 242256 0 0.0
tv-app debug unknown 5552 5552 0 0.0
FLASH 6022277 6022277 0 0.0
RAM 587088 587088 0 0.0
tv-casting-app debug unknown 5208 5208 0 0.0
FLASH 10883837 10883837 0 0.0
RAM 650256 650256 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 915128 915112 -16 -0.0
RAM 142259 142259 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 886444 886420 -24 -0.0
RAM 140398 140398 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 846476 846476 0 0.0
RAM 141077 141077 0 0.0
nxp contact k32w0+release FLASH 580520 580520 0 0.0
RAM 70720 70720 0 0.0
k32w1+release FLASH 593352 593352 0 0.0
RAM 62896 62896 0 0.0
mcxw71+release FLASH 593104 593104 0 0.0
RAM 62896 62896 0 0.0
light k32w0+release FLASH 616332 616332 0 0.0
RAM 70184 70184 0 0.0
k32w1+release FLASH 679608 679608 0 0.0
RAM 48512 48512 0 0.0
mcxw71+release FLASH 679608 679608 0 0.0
RAM 48512 48512 0 0.0
lock k32w1+release FLASH 701904 701904 0 0.0
RAM 67036 67036 0 0.0
mcxw71+release FLASH 701928 701928 0 0.0
RAM 67036 67036 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1646932 1646916 -16 -0.0
RAM 210952 210952 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1550556 1550556 0 0.0
RAM 207664 207664 0 0.0
light cy8ckit_062s2_43012 FLASH 1466484 1466484 0 0.0
RAM 200672 200672 0 0.0
lock cy8ckit_062s2_43012 FLASH 1462988 1462988 0 0.0
RAM 225024 225024 0 0.0
qpg lighting-app qpg6105+debug FLASH 659104 659104 0 0.0
RAM 105212 105212 0 0.0
lock-app qpg6105+debug FLASH 616996 616996 0 0.0
RAM 99688 99688 0 0.0
stm32 light STM32WB5MM-DK FLASH 480576 480576 0 0.0
RAM 144668 144668 0 0.0
telink air-quality-sensor-app tlsr9528a_retention FLASH 621702 621702 0 0.0
RAM 50964 50964 0 0.0
all-clusters-app tlsr9118bdk40d FLASH 688204 688182 -22 -0.0
RAM 148388 148388 0 0.0
all-clusters-minimal-app tlsr9528a FLASH 779886 779886 0 0.0
RAM 110756 110756 0 0.0
bridge-app tlsr9258a FLASH 680722 680722 0 0.0
RAM 91620 91620 0 0.0
contact-sensor-app tlsr9528a_retention FLASH 621466 621466 0 0.0
RAM 50916 50916 0 0.0
light-switch-app-ota-shell-factory-data tlsr9528a FLASH 707398 707398 0 0.0
RAM 74256 74256 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 624620 624620 0 0.0
RAM 144292 144292 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 810028 810028 0 0.0
RAM 99424 99424 0 0.0
lock-app-dfu tlsr9528a FLASH 655218 655218 0 0.0
RAM 66976 66976 0 0.0
ota-requestor-app tlsr9258a FLASH 696698 696698 0 0.0
RAM 91212 91212 0 0.0
pump-app-usb tlsr9518adk80d FLASH 633054 633054 0 0.0
RAM 55792 55792 0 0.0
pump-controller-app tlsr9518adk80d FLASH 610244 610244 0 0.0
RAM 53036 53036 0 0.0
shell tlsr9518adk80d FLASH 467170 467170 0 0.0
RAM 68668 68668 0 0.0
smoke_co_alarm-app tlsr9528a_retention FLASH 628430 628430 0 0.0
RAM 52636 52636 0 0.0
temperature-measurement-app-mars-ota tlsr9518adk80d FLASH 652380 652380 0 0.0
RAM 56584 56584 0 0.0
thermostat tlsr9518adk80d FLASH 636974 636974 0 0.0
RAM 53428 53428 0 0.0
window-covering tlsr9118bdk40d FLASH 523150 523150 0 0.0
RAM 97268 97268 0 0.0
tizen all-clusters-app arm unknown 4852 4852 0 0.0
FLASH 1724856 1724836 -20 -0.0
RAM 89524 89524 0 0.0
chip-tool-ubsan arm unknown 10284 10284 0 0.0
FLASH 17532082 17532082 0 0.0
RAM 7609764 7609764 0 0.0

Copy link

github-actions bot commented Sep 19, 2024

PR #35631: Size comparison from 85b2fd3 to 100a967

Increases above 0.2%:

platform target config section 85b2fd3 100a967 change % change
linux air-purifier-app debug RAM 128944 129424 480 0.4
all-clusters-minimal-app debug RAM 240640 241136 496 0.2
bridge-app debug RAM 217840 218304 464 0.2
fabric-bridge-app debug RAM 204456 204888 432 0.2
lock-app debug RAM 203928 204376 448 0.2
ota-provider-app debug RAM 197632 198112 480 0.2
ota-requestor-app debug RAM 202200 202680 480 0.2
thermostat-no-ble arm64 unknown 9336 9392 56 0.6
tizen all-clusters-app arm unknown 4852 4876 24 0.5
Full report (82 builds for bl602, bl702, bl702l, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
platform target config section 85b2fd3 100a967 change % change
bl602 lighting-app bl602 FLASH 1278192 1280006 1814 0.1
RAM 95824 95848 24 0.0
bl602+mfd FLASH 1292302 1294128 1826 0.1
RAM 95968 95992 24 0.0
bl602+rpc FLASH 1317156 1319218 2062 0.2
RAM 104248 104272 24 0.0
bl702 lighting-app bl702 FLASH 943868 944122 254 0.0
RAM 15145 15145 0 0.0
bl702+mfd FLASH 946268 946522 254 0.0
RAM 15305 15305 0 0.0
bl702+rpc FLASH 1039188 1039442 254 0.0
RAM 24173 24173 0 0.0
bl706-eth FLASH 646064 646318 254 0.0
RAM 25233 25233 0 0.0
bl706-wifi FLASH 894076 894398 322 0.0
RAM 14477 14477 0 0.0
bl702l lighting-app bl702l FLASH 960528 960782 254 0.0
RAM 16804 16804 0 0.0
bl702l+mfd FLASH 963150 963404 254 0.0
RAM 16964 16964 0 0.0
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 677269 677629 360 0.1
RAM 78492 78516 24 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 697121 697481 360 0.1
RAM 81124 81148 24 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 697121 697481 360 0.1
RAM 81124 81148 24 0.0
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 654049 654409 360 0.1
RAM 73560 73584 24 0.0
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 613461 613669 208 0.0
RAM 71452 71468 16 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 633089 633297 208 0.0
RAM 74004 74020 16 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 633089 633297 208 0.0
RAM 74004 74020 16 0.0
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 632589 632925 336 0.1
RAM 74500 74516 16 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 652297 652633 336 0.1
RAM 77052 77068 16 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 652297 652633 336 0.1
RAM 77052 77068 16 0.0
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 608005 608333 328 0.1
RAM 68588 68604 16 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 627857 628193 336 0.1
RAM 71220 71236 16 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 627857 628193 336 0.1
RAM 71220 71236 16 0.0
efr32 lighting-app BRD4187C FLASH 932500 932732 232 0.0
RAM 135056 135080 24 0.0
lock-app BRD2605a FLASH 739960 740512 552 0.1
RAM 231212 231220 8 0.0
BRD4338a FLASH 740608 741160 552 0.1
RAM 231244 231252 8 0.0
window-app BRD4187C FLASH 1015544 1016072 528 0.1
RAM 126996 127004 8 0.0
esp32 all-clusters-app c3devkit DRAM 94152 94080 -72 -0.1
FLASH 1539520 1537360 -2160 -0.1
IRAM 82538 82538 0 0.0
m5stack DRAM 115096 115032 -64 -0.1
FLASH 1549862 1547818 -2044 -0.1
IRAM 117039 117039 0 0.0
linux air-purifier-app debug unknown 4688 4688 0 0.0
FLASH 2771259 2764229 -7030 -0.3
RAM 128944 129424 480 0.4
all-clusters-app debug unknown 5456 5456 0 0.0
FLASH 6082752 6066630 -16122 -0.3
RAM 514288 507360 -6928 -1.3
all-clusters-minimal-app debug unknown 5352 5352 0 0.0
FLASH 5406808 5399700 -7108 -0.1
RAM 240640 241136 496 0.2
bridge-app debug unknown 5336 5336 0 0.0
FLASH 4740320 4733256 -7064 -0.1
RAM 217840 218304 464 0.2
chip-tool debug unknown 5888 5888 0 0.0
FLASH 12676380 12544588 -131792 -1.0
RAM 562282 555058 -7224 -1.3
chip-tool-ipv6only arm64 unknown 20384 20400 16 0.1
FLASH 11341636 11243028 -98608 -0.9
RAM 612384 605144 -7240 -1.2
fabric-admin debug unknown 5720 5720 0 0.0
FLASH 10979263 10903033 -76230 -0.7
RAM 561322 554234 -7088 -1.3
fabric-bridge-app debug unknown 4568 4568 0 0.0
FLASH 4563058 4555916 -7142 -0.2
RAM 204456 204888 432 0.2
lighting-app debug+rpc+ui unknown 5984 5984 0 0.0
FLASH 5676641 5669489 -7152 -0.1
RAM 228128 228560 432 0.2
lock-app debug unknown 5272 5272 0 0.0
FLASH 4789600 4782460 -7140 -0.1
RAM 203928 204376 448 0.2
ota-provider-app debug unknown 4648 4648 0 0.0
FLASH 4422786 4415644 -7142 -0.2
RAM 197632 198112 480 0.2
ota-requestor-app debug unknown 4584 4584 0 0.0
FLASH 4561532 4554392 -7140 -0.2
RAM 202200 202680 480 0.2
shell debug unknown 4216 4216 0 0.0
FLASH 3107917 3095181 -12736 -0.4
RAM 159448 159184 -264 -0.2
thermostat-no-ble arm64 unknown 9336 9392 56 0.6
FLASH 4333292 4326868 -6424 -0.1
RAM 242256 242664 408 0.2
tv-app debug unknown 5552 5552 0 0.0
FLASH 6022277 6011589 -10688 -0.2
RAM 587088 580896 -6192 -1.1
tv-casting-app debug unknown 5208 5208 0 0.0
FLASH 10883837 10739453 -144384 -1.3
RAM 650256 642976 -7280 -1.1
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 915128 913292 -1836 -0.2
RAM 142259 142199 -60 -0.0
nrf7002dk_nrf5340_cpuapp FLASH 886444 884964 -1480 -0.2
RAM 140398 140338 -60 -0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 846476 846820 344 0.0
RAM 141077 141093 16 0.0
nxp contact k32w0+release FLASH 580520 581760 1240 0.2
RAM 70720 70776 56 0.1
k32w1+release FLASH 593352 594240 888 0.1
RAM 62896 62952 56 0.1
mcxw71+release FLASH 593104 593992 888 0.1
RAM 62896 62952 56 0.1
light k32w0+release FLASH 616332 617652 1320 0.2
RAM 70184 70248 64 0.1
k32w1+release FLASH 679608 680880 1272 0.2
RAM 48512 48584 72 0.1
mcxw71+release FLASH 679608 680896 1288 0.2
RAM 48512 48584 72 0.1
lock k32w1+release FLASH 701904 702856 952 0.1
RAM 67036 67084 48 0.1
mcxw71+release FLASH 701928 702880 952 0.1
RAM 67036 67084 48 0.1
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1646932 1645108 -1824 -0.1
RAM 210952 210888 -64 -0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1550556 1551124 568 0.0
RAM 207664 207688 24 0.0
light cy8ckit_062s2_43012 FLASH 1466484 1466940 456 0.0
RAM 200672 200696 24 0.0
lock cy8ckit_062s2_43012 FLASH 1462988 1463572 584 0.0
RAM 225024 225048 24 0.0
qpg lighting-app qpg6105+debug FLASH 659104 659384 280 0.0
RAM 105212 105236 24 0.0
lock-app qpg6105+debug FLASH 616996 617268 272 0.0
RAM 99688 99704 16 0.0
stm32 light STM32WB5MM-DK FLASH 480576 480920 344 0.1
RAM 144668 144692 24 0.0
telink air-quality-sensor-app tlsr9528a_retention FLASH 621702 621958 256 0.0
RAM 50964 50988 24 0.0
all-clusters-app tlsr9118bdk40d FLASH 688204 687178 -1026 -0.1
RAM 148388 148328 -60 -0.0
all-clusters-minimal-app tlsr9528a FLASH 779886 780144 258 0.0
RAM 110756 110780 24 0.0
bridge-app tlsr9258a FLASH 680722 680980 258 0.0
RAM 91620 91644 24 0.0
contact-sensor-app tlsr9528a_retention FLASH 621466 621722 256 0.0
RAM 50916 50940 24 0.0
light-switch-app-ota-shell-factory-data tlsr9528a FLASH 707398 707630 232 0.0
RAM 74256 74280 24 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 624620 624878 258 0.0
RAM 144292 144316 24 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 810028 810286 258 0.0
RAM 99424 99448 24 0.0
lock-app-dfu tlsr9528a FLASH 655218 655476 258 0.0
RAM 66976 67000 24 0.0
ota-requestor-app tlsr9258a FLASH 696698 696956 258 0.0
RAM 91212 91236 24 0.0
pump-app-usb tlsr9518adk80d FLASH 633054 633312 258 0.0
RAM 55792 55816 24 0.0
pump-controller-app tlsr9518adk80d FLASH 610244 610502 258 0.0
RAM 53036 53060 24 0.0
shell tlsr9518adk80d FLASH 467170 467192 22 0.0
RAM 68668 68668 0 0.0
smoke_co_alarm-app tlsr9528a_retention FLASH 628430 628688 258 0.0
RAM 52636 52660 24 0.0
temperature-measurement-app-mars-ota tlsr9518adk80d FLASH 652380 652638 258 0.0
RAM 56584 56608 24 0.0
thermostat tlsr9518adk80d FLASH 636974 637232 258 0.0
RAM 53428 53452 24 0.0
window-covering tlsr9118bdk40d FLASH 523150 523408 258 0.0
RAM 97268 97284 16 0.0
tizen all-clusters-app arm unknown 4852 4876 24 0.5
FLASH 1724856 1721852 -3004 -0.2
RAM 89524 89084 -440 -0.5
chip-tool-ubsan arm unknown 10284 10276 -8 -0.1
FLASH 17532082 17345394 -186688 -1.1
RAM 7609764 7556552 -53212 -0.7


struct ClusterInitParameters
{
DataModel::Nullable<ValveStateEnum> currentState = DataModel::NullNullable;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these = needed? Nullable should default to null/missing I believe.

DataModel::Nullable<Percent> currentLevel = DataModel::NullNullable;
BitMask<ValveFaultBitmap> valveFault = 0u;
uint8_t levelStep = 1u;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be nice to make this fluent initializable, so I can write:

Init(ClusterInitParameters().withValveFault(10).withLevelStep(100))

public:
explicit ClusterStateAttributes(MatterContext & matterContext) : mMatterContext(matterContext) {};
void Init(ClusterInitParameters initialState);
const ClusterState & GetState() { return mState; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const ClusterState & GetState() { return mState; }
const ClusterState & GetState() const { return mState; }

CHIP_ERROR SetValveFault(const BitMask<ValveFaultBitmap> & valveFault);
CHIP_ERROR SetLevelStep(const uint8_t levelStep);

System::Clock::Milliseconds64 GetNextReportTimeForRemainingDuration();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a comment explaining use: it seems not immediately obvious what this time represents and its usage.

class ClusterStateAttributes
{
public:
explicit ClusterStateAttributes(MatterContext & matterContext) : mMatterContext(matterContext) {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we describe the lifetime requirements of the MatterContext? It seems we take a reference, so we have to ensure this context is valid for the duration of this object existance.

{
mState.defaultOpenDuration.SetNonNull(defaultOpenDuration);
}
mMatterContext.GetDefaultOpenLevel(mState.defaultOpenLevel);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to also return CHIP_ERROR that needs to be handled

if (mMatterContext.GetDefaultOpenDuration(defaultOpenDuration) == CHIP_NO_ERROR)
{
mState.defaultOpenDuration.SetNonNull(defaultOpenDuration);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of error, the error seems to be thrown away. I think we should log instead of silently ignoring the error.

Comment on lines +69 to +75
bool dirty = openDuration != mState.openDuration;
mState.openDuration = openDuration;
if (dirty)
{
mMatterContext.MarkDirty(Attributes::OpenDuration::Id);
}
return CHIP_NO_ERROR;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool dirty = openDuration != mState.openDuration;
mState.openDuration = openDuration;
if (dirty)
{
mMatterContext.MarkDirty(Attributes::OpenDuration::Id);
}
return CHIP_NO_ERROR;
ReturnErrorCodeIf(openDuration == mState.openDuration, CHIP_NO_ERROR);
mState.openDuration = openDuration;
mMatterContext.MarkDirty(Attributes::OpenDuration::Id);
return CHIP_NO_ERROR;

I think this pattern could be applied everywher: it seems if we get passed in a NOOP we can early-return.

Copy link
Contributor

@tcarmelveilleux tcarmelveilleux Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on that pattern.

Also, would be great to have a AttributeValue<T> class that can has a SetValue(const T& val, TheInterfaceThatHasMarkDirty *) which then we could have:

return mOpenDuration.SetValue(openDuration, mMatterContext)

{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mConformance.supportsDefaultOpenLevel, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
if (defaultOpenLevel < 1 || defaultOpenLevel > 100)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is level always a percentage? Would it make sense to name things Percent as a suffix then?

Unit tests included, also tested on an example app with mfg tags
If the valve can be opened before the command is complete or before
the next read is done, the test will fail because it expects
the transitioning phase to happen.

In the spec:
When the movement is complete, the device SHALL set the CurrentState attribute
to the Open value.

^ this can happen before the end of the command.
This way we can ensure the open duration is writeable.
Also add a cleanup step.
Self-select the valve tests off the device information
rather than the PICS. This makes it easier to run the tests
since you can just run them all unconditionally and they
will run if required.
@github-actions github-actions bot added the matter-1.4-te2-script-change Script changes before end of Matter 1.4 TE2 label Sep 30, 2024
Copy link

github-actions bot commented Sep 30, 2024

PR #35631: Size comparison from f509f67 to eb2dcbf

Full report (22 builds for cc13x4_26x4, cc32xx, nrfconnect, nxp, qpg, stm32, tizen)
platform target config section f509f67 eb2dcbf change % change
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 829380 829452 72 0.0
RAM 123300 123300 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 814424 814480 56 0.0
RAM 125172 125172 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 760420 760964 544 0.1
RAM 113664 113664 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 744656 745200 544 0.1
RAM 113856 113856 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 616202 616682 480 0.1
RAM 205396 205396 0 0.0
lock CC3235SF_LAUNCHXL FLASH 656258 656730 472 0.1
RAM 205548 205548 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 913440 913936 496 0.1
RAM 142199 142199 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 885020 884960 -60 -0.0
RAM 140338 140338 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 846948 847468 520 0.1
RAM 141093 141093 0 0.0
nxp contact k32w0+release FLASH 581760 581864 104 0.0
RAM 70776 70784 8 0.0
k32w1+release FLASH 595664 596144 480 0.1
RAM 62992 62992 0 0.0
mcxw71+release FLASH 595416 595904 488 0.1
RAM 62992 62992 0 0.0
light k32w0+release FLASH 617812 618372 560 0.1
RAM 70248 70256 8 0.0
k32w1+release FLASH 681624 682160 536 0.1
RAM 48632 48632 0 0.0
mcxw71+release FLASH 681640 682176 536 0.1
RAM 48632 48632 0 0.0
lock k32w1+release FLASH 703944 704488 544 0.1
RAM 67132 67132 0 0.0
mcxw71+release FLASH 703968 704512 544 0.1
RAM 67132 67132 0 0.0
qpg lighting-app qpg6105+debug FLASH 659512 660048 536 0.1
RAM 105236 105236 0 0.0
lock-app qpg6105+debug FLASH 617476 618020 544 0.1
RAM 99704 99704 0 0.0
stm32 light STM32WB5MM-DK FLASH 481072 481608 536 0.1
RAM 144692 144692 0 0.0
tizen all-clusters-app arm unknown 4904 4904 0 0.0
FLASH 1724244 1725152 908 0.1
RAM 89076 89076 0 0.0
chip-tool-ubsan arm unknown 10344 10348 4 0.0
FLASH 17357954 17362010 4056 0.0
RAM 7562996 7564628 1632 0.0

Copy link

github-actions bot commented Sep 30, 2024

PR #35631: Size comparison from f509f67 to 3e30568

Full report (20 builds for cc13x4_26x4, cc32xx, nrfconnect, nxp, qpg, stm32, tizen)
platform target config section f509f67 3e30568 change % change
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 829380 829452 72 0.0
RAM 123300 123300 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 814424 814480 56 0.0
RAM 125172 125172 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 760420 760964 544 0.1
RAM 113664 113664 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 744656 745200 544 0.1
RAM 113856 113856 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 616202 616682 480 0.1
RAM 205396 205396 0 0.0
lock CC3235SF_LAUNCHXL FLASH 656258 656730 472 0.1
RAM 205548 205548 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 913440 913936 496 0.1
RAM 142199 142199 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 885020 884960 -60 -0.0
RAM 140338 140338 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 846948 847468 520 0.1
RAM 141093 141093 0 0.0
nxp contact k32w1+release FLASH 595664 596144 480 0.1
RAM 62992 62992 0 0.0
mcxw71+release FLASH 595416 595904 488 0.1
RAM 62992 62992 0 0.0
light k32w1+release FLASH 681624 682160 536 0.1
RAM 48632 48632 0 0.0
mcxw71+release FLASH 681640 682176 536 0.1
RAM 48632 48632 0 0.0
lock k32w1+release FLASH 703944 704488 544 0.1
RAM 67132 67132 0 0.0
mcxw71+release FLASH 703968 704512 544 0.1
RAM 67132 67132 0 0.0
qpg lighting-app qpg6105+debug FLASH 659512 660048 536 0.1
RAM 105236 105236 0 0.0
lock-app qpg6105+debug FLASH 617476 618020 544 0.1
RAM 99704 99704 0 0.0
stm32 light STM32WB5MM-DK FLASH 481072 481608 536 0.1
RAM 144692 144692 0 0.0
tizen all-clusters-app arm unknown 4904 4904 0 0.0
FLASH 1724244 1725152 908 0.1
RAM 89076 89076 0 0.0
chip-tool-ubsan arm unknown 10344 10348 4 0.0
FLASH 17357954 17362010 4056 0.0
RAM 7562996 7564628 1632 0.0

@mergify mergify bot added the conflict label Oct 9, 2024
await devCtrl.CommissionOnNetwork(nodeId=1, setupPinCode=20202021, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=3840)
```

### Interacting with teh valve app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Interacting with teh valve app
### Interacting with the valve app

class NonLevelValveEndpoint
{
public:
NonLevelValveEndpoint(EndpointId endpoint) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we inject the kvsStorage here

}

private:
const ClusterConformance kConformance = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ignores generated code

Copy link
Contributor Author

@cecille cecille Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but that's not an oversight, it's hoping to be forward looking. ie, the hope is that we can move away from statically generated conformances for clusters.

Generally though, the question of where to set the conformance is a valid one - @andy31415 - with your work on the IM layer, where would you prefer to set the conformance at the cluster, or have this come from the IM layer?

I think the clusters still need to understand their conformance, even if it is not static, because they need to be able to call into the delegates correctly and understand the responses. But should the cluster logic be responsible for this type of error handling, or should the cluster logic assume that if the IM layer is asking to ex. read or write an arrtibute, that it is allowed?

{
inline bool HasFeature(Feature feature) const { return featureMap & to_underlying(feature); }
uint32_t featureMap;
bool supportsDefaultOpenLevel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feature map and all following bool supports should be a bitfield
maybe something like this

union {
    struct {
        bool supportsDefaultOpenLevel: 1;
        bool supportsValveFault: 1;
        bool supportsLevelStep: 1;
    };
    uint32_t featureMap;
};

I'm not sure that it is portable tho. Maybe Using bitflag and enum type would be best

/** @brief
* Interface to allow interaction with interaction model and ember layers. Can be faked for unit testing.
*/
class MatterContext
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea that there could be a Base MatterContext that is common to all clusters (like MarkDirty) That would mean what you have here would need to be a little more generic to accept EndpointId and ClusterId, but it could later allow for things like that to funnel into one central command MatterContext that is shared everywhere to reduce boiler plate

~MockedMatterContext() { gSystemLayerAndClock.Clear(); }

private:
// Won't handle double-marking an attribute, so don't do that in tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, not sure I follow this comment. This does supposed double-marking an attribute you would see it come up twice in this vector

Comment on lines +44 to +48
CHIP_ERROR TranslateErrorToIMStatus(CHIP_ERROR err)
{
if (err == CHIP_NO_ERROR)
{
return err;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't feel like it belongs in this cluster.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to eventually use https://github.com/project-chip/connectedhomeip/blob/master/src/app/data-model-provider/ActionReturnStatus.h#L44

Beyond that though, translating a CHIP_ERROR to another CHIP_ERROR feels odd.

Comment on lines +68 to +79
CHIP_ERROR EncodeRead(AttributeValueEncoder & aEncoder, const F & getter)
{
T ret;
CHIP_ERROR err = getter(ret);
if (err == CHIP_NO_ERROR)
{
err = aEncoder.Encode(ret);
}

// TODO: Should the logic return these directly? I didn't want to mix the IM layer into there, but this is annoying.
return TranslateErrorToIMStatus(err);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really feels like the translate to IM status could be combined, adn also all the getters could return values rather than CHIP_ERROR. Overall, the presence of the attribute should be determinable before we get here.

@mergify mergify bot removed the conflict label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

5 participants