Skip to content

POC for a new harness designed for power measurement purposes.#85130

Merged
kartben merged 4 commits into
zephyrproject-rtos:mainfrom
gbarkadiusz:topic/power_management_harness
Mar 31, 2025
Merged

POC for a new harness designed for power measurement purposes.#85130
kartben merged 4 commits into
zephyrproject-rtos:mainfrom
gbarkadiusz:topic/power_management_harness

Conversation

@gbarkadiusz

@gbarkadiusz gbarkadiusz commented Feb 4, 2025

Copy link
Copy Markdown
Contributor

POC of Power twister harness.

This pr adds support for power measurements for twister and three example tests.
pm.states: Verifies the transition to all available power states on stm32l562e_dk.

During the test, pytest detects each step and calculates the RMS (Root Mean Square) current for every detected state. The test then compares the calculated RMS values against the expected values, which have been determined manually through experimental observation

pm.residency_time: Tests the residency time of each power state.
This test evaluates the residency time of different power states on the stm32l562e_dk board.

pm.wakeup_timer: Tests the RTC alarm’s ability to wake the CPU from the lowest power state.

Each test calculates RMS current values for each detected state and compares them to expected values, which were manually set based on experimental data.

Setup
image
image

To reproduce.:

  • Configure the stm32l562e_dk board according to the instructions provided above.
  • Connect both USB ports of the board to your host system. The board will appear as two separate targets:
    Power Monitor: e.g., /dev/ttyACM0 or /dev/serial/by-id/usb-STMicroelectronics_PowerShield__Virtual_ComPort_in_FS_Mode__FFFFFFFEFFFF-if00
    Target: e.g., /dev/ttyACM1 or /dev/serial/by-id/usb-STMicroelectronics_STLINK-V3_004##############39-if02
  • Run twister commend:
twister --device-testing --device-serial /dev/ttyACM1 -p stm32l562e_dk -T tests/subsys/pm/power_residency_time/ --west-flash="--dev-id=004800483137510D33333639" --west-runner=pyocd -vv  -ll DEBUG -xCONFIG_BOOT_DELAY=500 --pm-probe=stm_powershield --pm-probe-port=/dev/serial/by-id/usb-S
TMicroelectronics_PowerShield__Virtual_ComPort_in_FS_Mode__FFFFFFFEFFFF-if00

@gbarkadiusz gbarkadiusz added the DNM This PR should not be merged (Do Not Merge) label Feb 4, 2025
@gbarkadiusz gbarkadiusz force-pushed the topic/power_management_harness branch 2 times, most recently from 679de9e to c474ca5 Compare February 4, 2025 14:12
Comment on lines +13 to +14
pytest_args: [--probe=stm_powershield,
--probe-port=<path_to>/STMicroelectronics_PowerShield__Virtual_ComPort]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These two args (--probe and --probe-port ) should be provided via the command line, as they vary, as opposed to the pytest_dut_scope: session and the properties in test_expected_values.yaml file which are "portable"/"fixed" regardless of the probe and port used :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be possible to move

-  name: "wakeup_timer"
     measurement_time: 2
     num_of_transitions: 1
     rms: [0.26, 140]

to

harness_config:
  measurements:
    - name: "wakeup_timer"
      measurement_time: 2
      num_of_transitions: 1
      rms: [0.26, 140]

instead of the separate file? not sure what having the commands in a separate file acheives :)

@gbarkadiusz gbarkadiusz force-pushed the topic/power_management_harness branch 4 times, most recently from 4109da0 to 1424b32 Compare February 17, 2025 15:21
@gbarkadiusz

Copy link
Copy Markdown
Contributor Author

@bjarki-andreasen Please take another look. I'm not sure that moving --probe and --probe-port to the Twister parameter is a good approach. They're more closely related to the harness's parameters rather than Twister's, so I suggest leaving them in the harness_config section.

@bjarki-andreasen

bjarki-andreasen commented Feb 17, 2025

Copy link
Copy Markdown
Contributor

@bjarki-andreasen Please take another look. I'm not sure that moving --probe and --probe-port to the Twister parameter is a good approach. They're more closely related to the harness's parameters rather than Twister's, so I suggest leaving them in the harness_config section.

Would you argue the same for the --serial option and its parameters? The probe and probe-port are instances of actual hardware right? If i ran the same test locally, would I not need to change the port to match my setup?

@gbarkadiusz gbarkadiusz force-pushed the topic/power_management_harness branch 2 times, most recently from 380d8c0 to 91fa4eb Compare February 18, 2025 12:24
@gbarkadiusz

Copy link
Copy Markdown
Contributor Author

@bjarki-andreasen Please take another look. I'm not sure that moving --probe and --probe-port to the Twister parameter is a good approach. They're more closely related to the harness's parameters rather than Twister's, so I suggest leaving them in the harness_config section.

Would you argue the same for the --serial option and its parameters? The probe and probe-port are instances of actual hardware right? If i ran the same test locally, would I not need to change the port to match my setup?

Yes, you need to change the port to match your setup.
Regarding the twister parameters. You right, so I've applied your suggestions, There's the example twister's command with these two parameters --pm-probe and --pm-probe-port.

twister --device-testing --device-serial /dev/ttyACM1 -p stm32l562e_dk -T tests/subsys/pm/power_residency_time/ --west-flash="--dev-id=004800483137510D33333639" --west-runner=pyocd -vv  -ll DEBUG -xCONFIG_BOOT_DELAY=500 --pm-probe=stm_powershield --pm-probe-port=/dev/serial/by-id/usb-S
TMicroelectronics_PowerShield__Virtual_ComPort_in_FS_Mode__FFFFFFFEFFFF-if00

@bjarki-andreasen , @nashif Please take a look.

@gbarkadiusz gbarkadiusz force-pushed the topic/power_management_harness branch 7 times, most recently from f202877 to c0e83bd Compare February 18, 2025 13:47
@gbarkadiusz gbarkadiusz marked this pull request as ready for review February 18, 2025 13:51
@gbarkadiusz gbarkadiusz removed the DNM This PR should not be merged (Do Not Merge) label Feb 18, 2025
@gbarkadiusz gbarkadiusz force-pushed the topic/power_management_harness branch from 01c20fa to 3aeb382 Compare March 13, 2025 13:34
@gbarkadiusz

gbarkadiusz commented Mar 13, 2025

Copy link
Copy Markdown
Contributor Author

@PerMac I've changed the code according to your suggestions, please take a look again.
Now, the proper command to run the test is:

twister --device-testing --device-serial /dev/ttyACM1 -p stm32l562e_dk -T tests/subsys/pm/power_states/ --west-flash="--dev-id=004800483137510D33333639" --west-runner=pyocd -vv  -X pm_probe:/dev/serial/by-id/usb-STMicroelectronics_PowerShield__Virtual_ComPort_in_FS_Mode__FFFFFFFEFFFF-if00

Comment thread scripts/pm/stm32l562e_dk/PowerShield.py Outdated
Comment thread scripts/pm/abstract/PowerMonitor.py
Comment thread scripts/pm/stm32l562e_dk/PowerShieldConfig.py Outdated
Comment thread scripts/pm/stm32l562e_dk/PowerShield.py Outdated
Comment thread scripts/pm/stm32l562e_dk/PowerShield.py
Comment thread tests/subsys/pm/power_residency_time/testcase.yaml Outdated
Comment thread scripts/pylib/power-twister-harness/test_power.py Outdated
Comment thread scripts/pylib/power-twister-harness/test_power.py Outdated
Comment thread scripts/pm/abstract/PowerMonitor.py
Comment thread scripts/pylib/power-twister-harness/test_power.py Outdated
@gbarkadiusz gbarkadiusz force-pushed the topic/power_management_harness branch 5 times, most recently from 9ea235c to d93e39e Compare March 18, 2025 13:38

@PerMac PerMac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In pytest, using yield in a fixture is generally preferred when you need to perform setup and teardown actions. The yield statement allows you to define a teardown step that will be executed after the test completes, ensuring proper cleanup.

Here's why using yield is beneficial in your case:

Explicit Teardown: By using yield, you can explicitly define the teardown process within the fixture, making it clear and maintainable.
Resource Management: It ensures that resources like serial connections are properly closed, avoiding potential issues with resource leaks.
Using del for cleanup is not recommended because:

Unpredictable Timing: The del method is called when an object is garbage collected, which can be unpredictable and may not happen immediately after the test.
Resource Leaks: If the garbage collector does not run promptly, resources may remain open longer than necessary.

Comment thread scripts/pylib/power-twister-harness/conftest.py Outdated
Comment thread scripts/pylib/power-twister-harness/stm32l562e_dk/PowerShield.py Outdated
Comment thread scripts/pylib/power-twister-harness/stm32l562e_dk/SerialHandler.py Outdated
Comment thread scripts/pylib/power-twister-harness/stm32l562e_dk/PowerShieldConfig.py Outdated
Comment thread scripts/pylib/power-twister-harness/test_power.py Outdated
Comment thread scripts/pylib/power-twister-harness/test_power.py Outdated
Comment thread scripts/pylib/power-twister-harness/test_power.py Outdated
Comment thread scripts/pylib/power-twister-harness/test_power.py Outdated
Comment thread scripts/pylib/power-twister-harness/test_power.py Outdated
@gbarkadiusz gbarkadiusz force-pushed the topic/power_management_harness branch 2 times, most recently from 8c1760f to 206b8f6 Compare March 25, 2025 12:46
Add support for powerShield of stm32l562e_dk board.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
@gbarkadiusz gbarkadiusz force-pushed the topic/power_management_harness branch from 206b8f6 to 648a9c8 Compare March 25, 2025 12:52
@gbarkadiusz

Copy link
Copy Markdown
Contributor Author

@PerMac Thank you for your feedback, I've applied your suggestions, please take a look.
@nashif @bjarki-andreasen @nordic-piks FYI.

@PerMac PerMac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All my comments were addressed

Comment thread scripts/pylib/power-twister-harness/conftest.py
@gbarkadiusz

Copy link
Copy Markdown
Contributor Author

All my comments were addressed

If so, please resolve all your conversations, Thank you.

@nashif nashif left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey, the second commit:

CI: Add power_states, power_wakeup_timer and power_residency_time tests

This is not related to CI, please split this into 3 commits with more details in the commit body explaining what is being tested, for example:

tests: power_states: tests blah blah

This test verified foo bar using the power harness using the STM32XYZ board.....

Do the same for the other tests.

@gbarkadiusz gbarkadiusz force-pushed the topic/power_management_harness branch from 648a9c8 to 09738a8 Compare March 27, 2025 14:01
@gbarkadiusz gbarkadiusz requested a review from nashif March 27, 2025 14:02
…tates

During the test, pytest detects each step and calculates
the RMS (Root Mean Square) current for every detected state.
The test then compares the calculated RMS values
against the expected values.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
…tate

This test evaluates the residency time of different power states
on the stm32l562e_dk board and calculates the
RMS (Root Mean Square) current for every detected state.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
As above, the test verify the ability to wake up CPU
from the lowest power state. The test has been
prepared for stm32l562e_dk board.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
@gbarkadiusz gbarkadiusz force-pushed the topic/power_management_harness branch from 09738a8 to b500c13 Compare March 27, 2025 14:09
@kartben kartben added the Release Notes Required Release notes required for this change label Mar 31, 2025
@kartben kartben merged commit 9a4104d into zephyrproject-rtos:main Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Power Management area: Twister Twister Release Notes Required Release notes required for this change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants