Skip to content

Conversation

@dnicoara
Copy link
Contributor

@dnicoara dnicoara commented Dec 3, 2025

Manage DataModel::Provider lifecycle in DeviceControllerFactory

  • On Shutdown call InteractionModelEngine::SetDataModelProvider with
    nullptr
  • Cache DataModel::Provider within DeviceControllerFactory to allow it
    it reinitialize.

Summary

InteractionModelEngine is a global singleton and does not get re-instantiated for each test. DataModelProvider delegate is never cleaned up during Shutdown, thus the pointer leaks across tests. During a second test InteractionModelEngine::SetDataModelProvider() will attempt to call Shutdown on the existing pointer. If DataModelProvider is local to the test this will crash as the old DataModelProvider would have been deleted.

Testing

CI

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

@CLAassistant
Copy link

CLAassistant commented Dec 3, 2025

CLA assistant check
All committers have signed the CLA.

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 correctly addresses a dangling pointer issue in the InteractionModelEngine singleton by ensuring the DataModelProvider is properly shut down and reset. This is a crucial fix for ensuring hermetic behavior in unit tests. The added test case effectively validates this fix.

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

PR #42272: Size comparison from 078ba11 to f404cad

Full report (21 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, psoc6, qpg, realtek, stm32)
platform target config section 078ba11 f404cad change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1106714 1106714 0 0.0
RAM 178954 178954 0 0.0
bl702 lighting-app bl702+eth FLASH 661534 661534 0 0.0
RAM 135025 135025 0 0.0
bl702+wifi FLASH 837384 837384 0 0.0
RAM 124485 124485 0 0.0
bl706+mfd+rpc+littlefs FLASH 1071032 1071032 0 0.0
RAM 117341 117341 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 903852 903852 0 0.0
RAM 105932 105932 0 0.0
lighting-app bl702l+mfd+littlefs FLASH 983778 983778 0 0.0
RAM 109844 109844 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 771448 771448 0 0.0
RAM 103392 103392 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 784260 784260 0 0.0
RAM 108712 108712 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 729280 729280 0 0.0
RAM 97452 97452 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 713728 713728 0 0.0
RAM 97660 97660 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 555260 555260 0 0.0
RAM 205472 205472 0 0.0
lock CC3235SF_LAUNCHXL FLASH 589200 589200 0 0.0
RAM 205720 205720 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1683388 1683388 0 0.0
RAM 214148 214148 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1597724 1597724 0 0.0
RAM 211316 211316 0 0.0
light cy8ckit_062s2_43012 FLASH 1461236 1461236 0 0.0
RAM 197800 197800 0 0.0
lock cy8ckit_062s2_43012 FLASH 1495188 1495188 0 0.0
RAM 225672 225672 0 0.0
qpg lighting-app qpg6200+debug FLASH 839400 839400 0 0.0
RAM 127952 127952 0 0.0
lock-app qpg6200+debug FLASH 776656 776656 0 0.0
RAM 118920 118920 0 0.0
realtek light-switch-app rtl8777g FLASH 709864 709864 0 0.0
RAM 107188 107188 0 0.0
lighting-app rtl8777g FLASH 758560 758560 0 0.0
RAM 127320 127320 0 0.0
stm32 light STM32WB5MM-DK FLASH 470908 470908 0 0.0
RAM 141392 141392 0 0.0

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

PR #42272: Size comparison from 078ba11 to 73b6449

Full report (34 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nxp, psoc6, qpg, realtek, stm32, telink)
platform target config section 078ba11 73b6449 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1106714 1106714 0 0.0
RAM 178954 178954 0 0.0
bl702 lighting-app bl702+eth FLASH 661534 661534 0 0.0
RAM 135025 135025 0 0.0
bl702+wifi FLASH 837384 837384 0 0.0
RAM 124485 124485 0 0.0
bl706+mfd+rpc+littlefs FLASH 1071032 1071032 0 0.0
RAM 117341 117341 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 903852 903852 0 0.0
RAM 105932 105932 0 0.0
lighting-app bl702l+mfd+littlefs FLASH 983778 983778 0 0.0
RAM 109844 109844 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 771448 771448 0 0.0
RAM 103392 103392 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 784260 784260 0 0.0
RAM 108712 108712 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 729280 729280 0 0.0
RAM 97452 97452 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 713728 713728 0 0.0
RAM 97660 97660 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 555260 555260 0 0.0
RAM 205472 205472 0 0.0
lock CC3235SF_LAUNCHXL FLASH 589200 589200 0 0.0
RAM 205720 205720 0 0.0
efr32 lock-app BRD4187C FLASH 965420 965420 0 0.0
RAM 123776 123776 0 0.0
BRD4338a FLASH 760240 760240 0 0.0
RAM 254388 254388 0 0.0
window-app BRD4187C FLASH 1061072 1061072 0 0.0
RAM 120004 120004 0 0.0
esp32 all-clusters-app c3devkit DRAM 102764 102804 40 0.0
FLASH 1839692 1840120 428 0.0
IRAM 93540 93540 0 0.0
nxp contact mcxw71+release FLASH 695840 695840 0 0.0
RAM 61744 61744 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1683388 1683620 232 0.0
RAM 214148 214188 40 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1597724 1597956 232 0.0
RAM 211316 211356 40 0.0
light cy8ckit_062s2_43012 FLASH 1461236 1461236 0 0.0
RAM 197800 197800 0 0.0
lock cy8ckit_062s2_43012 FLASH 1495188 1495188 0 0.0
RAM 225672 225672 0 0.0
qpg lighting-app qpg6200+debug FLASH 839400 839784 384 0.0
RAM 127952 127976 24 0.0
lock-app qpg6200+debug FLASH 776656 776656 0 0.0
RAM 118920 118920 0 0.0
realtek light-switch-app rtl8777g FLASH 709864 709864 0 0.0
RAM 107188 107188 0 0.0
lighting-app rtl8777g FLASH 758560 758560 0 0.0
RAM 127320 127320 0 0.0
stm32 light STM32WB5MM-DK FLASH 470908 470908 0 0.0
RAM 141392 141392 0 0.0
telink bridge-app tl7218x FLASH 704394 704394 0 0.0
RAM 90760 90760 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 790742 790742 0 0.0
RAM 41176 41176 0 0.0
light-app-ota-shell-factory-data tl7218x FLASH 782054 782054 0 0.0
RAM 93860 93860 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 710538 710538 0 0.0
RAM 52232 52232 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 746370 746370 0 0.0
RAM 71256 71256 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 721050 721050 0 0.0
RAM 34956 34956 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 602946 602946 0 0.0
RAM 117320 117320 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 815562 815566 4 0.0
RAM 92248 92248 0 0.0

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

PR #42272: Size comparison from 078ba11 to 97c267e

Full report (34 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nxp, psoc6, qpg, realtek, stm32, telink)
platform target config section 078ba11 97c267e change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1106714 1106718 4 0.0
RAM 178954 178954 0 0.0
bl702 lighting-app bl702+eth FLASH 661534 661538 4 0.0
RAM 135025 135025 0 0.0
bl702+wifi FLASH 837384 837388 4 0.0
RAM 124485 124485 0 0.0
bl706+mfd+rpc+littlefs FLASH 1071032 1071032 0 0.0
RAM 117341 117341 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 903852 903852 0 0.0
RAM 105932 105932 0 0.0
lighting-app bl702l+mfd+littlefs FLASH 983778 983778 0 0.0
RAM 109844 109844 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 771448 771448 0 0.0
RAM 103392 103392 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 784260 784260 0 0.0
RAM 108712 108712 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 729280 729280 0 0.0
RAM 97452 97452 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 713728 713728 0 0.0
RAM 97660 97660 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 555260 555260 0 0.0
RAM 205472 205472 0 0.0
lock CC3235SF_LAUNCHXL FLASH 589200 589200 0 0.0
RAM 205720 205720 0 0.0
efr32 lock-app BRD4187C FLASH 965420 965420 0 0.0
RAM 123776 123776 0 0.0
BRD4338a FLASH 760240 760240 0 0.0
RAM 254388 254388 0 0.0
window-app BRD4187C FLASH 1061072 1061072 0 0.0
RAM 120004 120004 0 0.0
esp32 all-clusters-app c3devkit DRAM 102764 102804 40 0.0
FLASH 1839692 1840122 430 0.0
IRAM 93540 93540 0 0.0
nxp contact mcxw71+release FLASH 695840 695840 0 0.0
RAM 61744 61744 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1683388 1683620 232 0.0
RAM 214148 214188 40 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1597724 1597956 232 0.0
RAM 211316 211356 40 0.0
light cy8ckit_062s2_43012 FLASH 1461236 1461236 0 0.0
RAM 197800 197800 0 0.0
lock cy8ckit_062s2_43012 FLASH 1495188 1495188 0 0.0
RAM 225672 225672 0 0.0
qpg lighting-app qpg6200+debug FLASH 839400 839784 384 0.0
RAM 127952 127976 24 0.0
lock-app qpg6200+debug FLASH 776656 776656 0 0.0
RAM 118920 118920 0 0.0
realtek light-switch-app rtl8777g FLASH 709864 709864 0 0.0
RAM 107188 107188 0 0.0
lighting-app rtl8777g FLASH 758560 758560 0 0.0
RAM 127320 127320 0 0.0
stm32 light STM32WB5MM-DK FLASH 470908 470908 0 0.0
RAM 141392 141392 0 0.0
telink bridge-app tl7218x FLASH 704394 704394 0 0.0
RAM 90760 90760 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 790742 790742 0 0.0
RAM 41176 41176 0 0.0
light-app-ota-shell-factory-data tl7218x FLASH 782054 782054 0 0.0
RAM 93860 93860 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 710538 710538 0 0.0
RAM 52232 52232 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 746370 746370 0 0.0
RAM 71256 71256 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 721050 721050 0 0.0
RAM 34956 34956 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 602946 602952 6 0.0
RAM 117320 117320 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 815562 815566 4 0.0
RAM 92248 92248 0 0.0

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

PR #42272: Size comparison from 078ba11 to 7594633

Full report (35 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
platform target config section 078ba11 7594633 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1106714 1106718 4 0.0
RAM 178954 178954 0 0.0
bl702 lighting-app bl702+eth FLASH 661534 661538 4 0.0
RAM 135025 135025 0 0.0
bl702+wifi FLASH 837384 837388 4 0.0
RAM 124485 124485 0 0.0
bl706+mfd+rpc+littlefs FLASH 1071032 1071032 0 0.0
RAM 117341 117341 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 903852 903852 0 0.0
RAM 105932 105932 0 0.0
lighting-app bl702l+mfd+littlefs FLASH 983778 983778 0 0.0
RAM 109844 109844 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 771448 771448 0 0.0
RAM 103392 103392 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 784260 784260 0 0.0
RAM 108712 108712 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 729280 729280 0 0.0
RAM 97452 97452 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 713728 713728 0 0.0
RAM 97660 97660 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 555260 555260 0 0.0
RAM 205472 205472 0 0.0
lock CC3235SF_LAUNCHXL FLASH 589200 589200 0 0.0
RAM 205720 205720 0 0.0
efr32 lock-app BRD4187C FLASH 965420 965420 0 0.0
RAM 123776 123776 0 0.0
BRD4338a FLASH 760240 760240 0 0.0
RAM 254388 254388 0 0.0
window-app BRD4187C FLASH 1061072 1061072 0 0.0
RAM 120004 120004 0 0.0
esp32 all-clusters-app c3devkit DRAM 102764 102804 40 0.0
FLASH 1839692 1840122 430 0.0
IRAM 93540 93540 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 937472 937940 468 0.0
RAM 161692 161720 28 0.0
nxp contact mcxw71+release FLASH 695840 695840 0 0.0
RAM 61744 61744 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1683388 1683620 232 0.0
RAM 214148 214188 40 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1597724 1597956 232 0.0
RAM 211316 211356 40 0.0
light cy8ckit_062s2_43012 FLASH 1461236 1461236 0 0.0
RAM 197800 197800 0 0.0
lock cy8ckit_062s2_43012 FLASH 1495188 1495188 0 0.0
RAM 225672 225672 0 0.0
qpg lighting-app qpg6200+debug FLASH 839400 839784 384 0.0
RAM 127952 127976 24 0.0
lock-app qpg6200+debug FLASH 776656 776656 0 0.0
RAM 118920 118920 0 0.0
realtek light-switch-app rtl8777g FLASH 709864 709864 0 0.0
RAM 107188 107188 0 0.0
lighting-app rtl8777g FLASH 758560 758560 0 0.0
RAM 127320 127320 0 0.0
stm32 light STM32WB5MM-DK FLASH 470908 470908 0 0.0
RAM 141392 141392 0 0.0
telink bridge-app tl7218x FLASH 704394 704394 0 0.0
RAM 90760 90760 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 790742 790742 0 0.0
RAM 41176 41176 0 0.0
light-app-ota-shell-factory-data tl7218x FLASH 782054 782054 0 0.0
RAM 93860 93860 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 710538 710538 0 0.0
RAM 52232 52232 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 746370 746370 0 0.0
RAM 71256 71256 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 721050 721050 0 0.0
RAM 34956 34956 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 602946 602952 6 0.0
RAM 117320 117320 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 815562 815566 4 0.0
RAM 92248 92248 0 0.0

// mpFabricTable = nullptr;
// mpExchangeMgr = nullptr;

if (mDataModelProvider)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please see discussion in #42149

Since IME startup is not what starts the data model provider, it's weird to have shutdown shutting it down.... We need to figure out whether the startup needs to move or whether the clearing of the data model provider needs to happen in the same scope as the setting (i.e. in the relevant test scope) as needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack. Thank you for the reference to the discussion.

This naive approach was based on InteractionModelEngine::SetDataModelProvider calling Shutdown on the old DataModel::Provider.

I reached out offline to @andy31415 for guidance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think we all agree the current semantics are bad.... If this is blocking something, we could land it as a stopgap, but long-term we really don't want shutdown shutting down things that init/startup did not start up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is currently blocking testing with code-driven data model provider, which in turn blocks the use of code-driven data model provider.

That said, this can't land as-is for the same reasons you mentioned. Will need to wait for additional discussions with @andy31415 to clarify intended use.

... but long-term we really don't want shutdown shutting down things that init/startup did not start up.

Would you mind clarifying what you mean by this? As far as I can see InteractionModelEngine::SetDataModelProvider does initialize the DataModel::Provider (via call to Startup).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I guess you mean InteractionModelEngine::Init/Shutdown ... fair enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess for my uses, calling SetDataModelProvider with a nullptr may unblock work.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the controller factory, if init sets to non-null, shutdown can set to null ... we should generally be symmetric.

@dnicoara dnicoara marked this pull request as draft December 5, 2025 22:42
@dnicoara dnicoara changed the title Ensure hermetic testing behavior during InteractionModelEngine shutdown Manage DataModel::Provider lifecycle in DeviceControllerFactory Dec 5, 2025
@github-actions
Copy link

github-actions bot commented Dec 5, 2025

PR #42272: Size comparison from ba864e9 to fb240d3

Full report (5 builds for cc32xx, realtek, stm32)
platform target config section ba864e9 fb240d3 change % change
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 554588 554588 0 0.0
RAM 205472 205472 0 0.0
lock CC3235SF_LAUNCHXL FLASH 588528 588528 0 0.0
RAM 205720 205720 0 0.0
realtek light-switch-app rtl8777g FLASH 708688 708688 0 0.0
RAM 107188 107188 0 0.0
lighting-app rtl8777g FLASH 757392 757392 0 0.0
RAM 127320 127320 0 0.0
stm32 light STM32WB5MM-DK FLASH 470244 470244 0 0.0
RAM 141392 141392 0 0.0

* On Shutdown call InteractionModelEngine::SetDataModelProvider with
  nullptr
* Cache DataModel::Provider within DeviceControllerFactory to allow it
  it reinitialize.
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.

5 participants