Skip to content

Commit 35b13e1

Browse files
gbarkadiuszkartben
authored andcommitted
Twister: Add power measurements support for Twister.
Add support for powerShield of stm32l562e_dk board. Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
1 parent 27ddc76 commit 35b13e1

File tree

11 files changed

+1006
-1
lines changed

11 files changed

+1006
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright: (c) 2025, Intel Corporation
2+
# Author: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
3+
4+
import string
5+
from abc import ABC, abstractmethod
6+
7+
8+
class PowerMonitor(ABC):
9+
@abstractmethod
10+
def init(self, device_id: string):
11+
"""
12+
Abstract method to initialize the power monitor.
13+
14+
Agr:
15+
string: Address of the power monitor
16+
17+
Return:
18+
bool: True of False.
19+
"""
20+
21+
@abstractmethod
22+
def measure(self, duration: int):
23+
"""
24+
Abstract method to measure current with specified measurement time.
25+
26+
Args:
27+
duration (int): The duration of the measurement in seconds.
28+
"""
29+
30+
@abstractmethod
31+
def get_data(self, duration: int) -> list[float]:
32+
"""
33+
Measure current with specified measurement time.
34+
35+
Args:
36+
duration (int): The duration of the measurement in seconds.
37+
38+
Returns:
39+
List[float]: An array of measured current values in amperes.
40+
"""
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright: (c) 2025, Intel Corporation
2+
import json
3+
import logging
4+
5+
import pytest
6+
from twister_harness import DeviceAdapter
7+
8+
9+
def pytest_addoption(parser):
10+
parser.addoption('--testdata')
11+
12+
13+
@pytest.fixture
14+
def probe_class(request, probe_path):
15+
path = probe_path # Get path of power device
16+
if request.param == 'stm_powershield':
17+
from stm32l562e_dk.PowerShield import PowerShield
18+
19+
probe = PowerShield() # Instantiate the power monitor probe
20+
probe.connect(path)
21+
probe.init()
22+
23+
yield probe
24+
25+
if request.param == 'stm_powershield':
26+
probe.disconnect()
27+
28+
29+
@pytest.fixture(name='probe_path', scope='session')
30+
def fixture_probe_path(request, dut: DeviceAdapter):
31+
for fixture in dut.device_config.fixtures:
32+
if fixture.startswith('pm_probe'):
33+
probe_port = fixture.split(':')[1]
34+
return probe_port
35+
36+
37+
@pytest.fixture(name='test_data', scope='session')
38+
def fixture_test_data(request):
39+
# Get test data from the configuration and parse it into a dictionary
40+
measurements = request.config.getoption("--testdata")
41+
measurements = measurements.replace("'", '"') # Ensure the data is properly formatted as JSON
42+
measurements_dict = json.loads(measurements)
43+
44+
# Data validation
45+
required_keys = [
46+
'elements_to_trim',
47+
'min_peak_distance',
48+
'min_peak_height',
49+
'peak_padding',
50+
'measurement_duration',
51+
'num_of_transitions',
52+
'expected_rms_values',
53+
'tolerance_percentage',
54+
]
55+
56+
for key in required_keys:
57+
if key not in measurements_dict:
58+
logging.error(f"Missing required test data key: {key}")
59+
pytest.fail(f"Missing required test data key: {key}")
60+
61+
return measurements_dict

0 commit comments

Comments
 (0)