Skip to content

[Tests] Add unit tests for Thermostat Server Presets functionality#43585

Draft
lboue wants to merge 11 commits intoproject-chip:masterfrom
lboue:test/thermostat-preset-coverage
Draft

[Tests] Add unit tests for Thermostat Server Presets functionality#43585
lboue wants to merge 11 commits intoproject-chip:masterfrom
lboue:test/thermostat-preset-coverage

Conversation

@lboue
Copy link
Contributor

@lboue lboue commented Mar 13, 2026

Summary

Add unit tests for Thermostat Server Presets functionality

Related issues

#43586

Testing

  • added unit test coverage in TestThermostatServerPresets.cpp
  • validated local app test build with source scripts/activate.sh && gn gen out/pr43585_fix && ninja -C out/pr43585_fix src/app/tests:tests -j2
  • verified the GN test target fix for Thermostat server sources/headers resolves the CI Include not allowed and orphan GN issues

Readability checklist

The checklist below will help the reviewer finish PR review in time and keep the
code readable:

  • PR title is
    descriptive
  • Apply the
    “When in Rome…”
    rule (coding style)
  • PR size is short
  • Try to avoid "squashing" and "force-update" in commit history
  • CI time didn't increase

See: Pull Request Guidelines

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds unit tests for the Thermostat Server's presets functionality. The changes include a new test file, test stubs for ZAP-generated code, and build file updates. The new test correctly verifies that SetActivePreset calls the appropriate delegate method. My main feedback is to improve the test implementation by adhering to the project's best practices for accessing private members, specifically avoiding the use of #define private public and instead using a TestAccess helper class as recommended by the unit testing guide.

@github-actions
Copy link

github-actions bot commented Mar 15, 2026

PR #43585: Size comparison from 2403f0a to 28ef21c

Full report (32 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, nxp, psoc6, qpg, realtek, stm32, telink)
platform target config section 2403f0a 28ef21c change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1090298 1090298 0 0.0
RAM 144778 144778 0 0.0
bl616 lighting-app bl616+thread FLASH 1100804 1100804 0 0.0
RAM 104216 104216 0 0.0
bl616+wifi+shell FLASH 1587676 1587676 0 0.0
RAM 98080 98080 0 0.0
bl702 lighting-app bl702+eth FLASH 1053234 1053234 0 0.0
RAM 108381 108381 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 891244 891244 0 0.0
RAM 105756 105756 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 780076 780076 0 0.0
RAM 103332 103332 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 787104 787104 0 0.0
RAM 108516 108516 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 733332 733332 0 0.0
RAM 97324 97324 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 716752 716752 0 0.0
RAM 97484 97484 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 558650 558650 0 0.0
RAM 204504 204504 0 0.0
lock CC3235SF_LAUNCHXL FLASH 591814 591814 0 0.0
RAM 204744 204744 0 0.0
efr32 lock-app BRD4187C FLASH 971764 971764 0 0.0
RAM 125828 125828 0 0.0
BRD4338a FLASH 769948 769948 0 0.0
RAM 236552 236552 0 0.0
window-app BRD4187C FLASH 1075368 1075360 -8 -0.0
RAM 126440 126440 0 0.0
nxp contact mcxw71+release FLASH 736456 736456 0 0.0
RAM 66944 66944 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1709172 1709172 0 0.0
RAM 213948 213948 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1607868 1607868 0 0.0
RAM 210820 210820 0 0.0
light cy8ckit_062s2_43012 FLASH 1471620 1471620 0 0.0
RAM 196996 196996 0 0.0
lock cy8ckit_062s2_43012 FLASH 1497756 1497756 0 0.0
RAM 224740 224740 0 0.0
qpg lighting-app qpg6200+debug FLASH 841228 841228 0 0.0
RAM 127788 127788 0 0.0
lock-app qpg6200+debug FLASH 779920 779920 0 0.0
RAM 118736 118736 0 0.0
realtek light-switch-app rtl8777g FLASH 721176 721176 0 0.0
RAM 113456 113456 0 0.0
lighting-app rtl8777g FLASH 768912 768912 0 0.0
RAM 114696 114696 0 0.0
stm32 light STM32WB5MM-DK FLASH 479728 479728 0 0.0
RAM 141324 141324 0 0.0
telink bridge-app tl7218x FLASH 729288 729310 22 0.0
RAM 95772 95772 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 853768 853790 22 0.0
RAM 44188 44188 0 0.0
tl7218x FLASH 845178 845200 22 0.0
RAM 99576 99576 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 726100 726122 22 0.0
RAM 55752 55752 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 788668 788690 22 0.0
RAM 74928 74928 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 726094 726116 22 0.0
RAM 33232 33232 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 617176 617198 22 0.0
RAM 118244 118244 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 843948 843974 26 0.0
RAM 97284 97284 0 0.0

@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.13%. Comparing base (fa956ce) to head (2457ccf).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
...thermostat-server/thermostat-server-test-stubs.cpp 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #43585      +/-   ##
==========================================
+ Coverage   54.07%   54.13%   +0.05%     
==========================================
  Files        1548     1551       +3     
  Lines      106709   106957     +248     
  Branches    13308    13308              
==========================================
+ Hits        57704    57898     +194     
- Misses      49005    49059      +54     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Fix Thermostat server test builds where no Thermostat endpoint is configured (e.g. nRF native_posix unit-test config), which caused: error: too many initializers for 'Delegate* [0]'.

- add kThermostatStorageEndpointCount as a storage-safe count (max(1, kThermostatEndpointCount))

- use it for gDelegateTable in thermostat-server.cpp

- use it for mAtomicWriteSessions in thermostat-server.h

- keep runtime behavior unchanged (kThermostatEndpointCount still drives endpoint logic)

Validated with: source scripts/activate.sh && gn gen out/pr43585_fix && ninja -C out/pr43585_fix src/app/tests:tests -j2
@lboue
Copy link
Contributor Author

lboue commented Mar 15, 2026

Fixed the nRF CI failure in Run unit tests for Zephyr native_posix_64 platform.

Root cause: this test config builds Thermostat sources with kThermostatEndpointCount == 0, so gDelegateTable[kThermostatEndpointCount] = { nullptr }; became a zero-length array with an initializer and failed with:
error: too many initializers for 'Delegate* [0]'.

Fix: introduced a storage-safe count (kThermostatStorageEndpointCount = max(1, kThermostatEndpointCount)) and used it for fixed-size backing arrays (gDelegateTable and mAtomicWriteSessions), while keeping runtime endpoint logic based on kThermostatEndpointCount.

Validated locally with:
source activate.sh && gn gen out/pr43585_fix && ninja -C out/pr43585_fix src/app/tests:tests -j2

@github-actions
Copy link

github-actions bot commented Mar 15, 2026

PR #43585: Size comparison from 2403f0a to 2457ccf

Full report (21 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, cc32xx, nrfconnect, psoc6, qpg, realtek, stm32)
platform target config section 2403f0a 2457ccf change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1090298 1090298 0 0.0
RAM 144778 144778 0 0.0
bl616 lighting-app bl616+thread FLASH 1100804 1100804 0 0.0
RAM 104216 104216 0 0.0
bl616+wifi+shell FLASH 1587676 1587676 0 0.0
RAM 98080 98080 0 0.0
bl702 lighting-app bl702+eth FLASH 1053234 1053234 0 0.0
RAM 108381 108381 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 891244 891244 0 0.0
RAM 105756 105756 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 780076 780076 0 0.0
RAM 103332 103332 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 787104 787104 0 0.0
RAM 108516 108516 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 733332 733332 0 0.0
RAM 97324 97324 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 716752 716752 0 0.0
RAM 97484 97484 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 558650 558650 0 0.0
RAM 204504 204504 0 0.0
lock CC3235SF_LAUNCHXL FLASH 591814 591814 0 0.0
RAM 204744 204744 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 858144 858144 0 0.0
RAM 162019 162019 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1709172 1709172 0 0.0
RAM 213948 213948 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1607868 1607868 0 0.0
RAM 210820 210820 0 0.0
light cy8ckit_062s2_43012 FLASH 1471620 1471620 0 0.0
RAM 196996 196996 0 0.0
lock cy8ckit_062s2_43012 FLASH 1497756 1497756 0 0.0
RAM 224740 224740 0 0.0
qpg lighting-app qpg6200+debug FLASH 841228 841228 0 0.0
RAM 127788 127788 0 0.0
lock-app qpg6200+debug FLASH 779920 779920 0 0.0
RAM 118736 118736 0 0.0
realtek light-switch-app rtl8777g FLASH 721176 721176 0 0.0
RAM 113456 113456 0 0.0
lighting-app rtl8777g FLASH 768912 768912 0 0.0
RAM 114696 114696 0 0.0
stm32 light STM32WB5MM-DK FLASH 479728 479728 0 0.0
RAM 141324 141324 0 0.0

@github-actions
Copy link

PR #43585: Size comparison from 2403f0a to 4fb4165

Full report (5 builds for cc32xx, realtek, stm32)
platform target config section 2403f0a 4fb4165 change % change
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 558650 558650 0 0.0
RAM 204504 204504 0 0.0
lock CC3235SF_LAUNCHXL FLASH 591814 591814 0 0.0
RAM 204744 204744 0 0.0
realtek light-switch-app rtl8777g FLASH 721176 721176 0 0.0
RAM 113456 113456 0 0.0
lighting-app rtl8777g FLASH 768912 768912 0 0.0
RAM 114696 114696 0 0.0
stm32 light STM32WB5MM-DK FLASH 479728 479728 0 0.0
RAM 141324 141324 0 0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants