Skip to content

Commit b447f92

Browse files
authored
Merge pull request #346 from horw/feat/soc_filtered_targets
Target Set Selection Support (soc_filtered_targets)
2 parents 8b64c3b + 8c40e11 commit b447f92

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

docs/usages/markers.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,50 @@ Another way to override ``supported_targets`` and ``preview_targets`` is by usin
152152
- - esp32s3
153153
- psram
154154

155+
SOC Related Targets
156+
-------------------
157+
158+
If you need to retrieve targets filtered by a specific SOC attribute, you can use the ``soc_filtered_targets`` function.
159+
160+
This function processes both ``supported_targets`` and ``preview_targets``, applies the specified filter, and returns a list of targets that match the given SOC statement.
161+
162+
**Function Signature**
163+
164+
.. code:: python
165+
166+
def soc_filtered_targets(soc_statement: str, targets: ValidTargets = 'all') -> list[str]:
167+
"""Filters targets based on a given SOC (System on Chip) statement."""
168+
169+
**Valid Target Categories**
170+
171+
The ``targets`` parameter determines which target sets should be considered:
172+
173+
- ``"supported_targets"``: Includes only officially supported targets.
174+
- ``"preview_targets"``: Includes only preview (experimental) targets.
175+
- ``"all"`` (default): Includes both supported and preview targets.
176+
177+
**Example:**
178+
179+
Filter all targets that support ULP:
180+
181+
.. code:: python
182+
183+
from pytest_embedded_idf.utils import soc_filtered_targets
184+
185+
@idf_parametrize('target', soc_filtered_targets('SOC_ULP_SUPPORTED != 1'), indirect=['target'])
186+
def test_all_targets_which_support_ulp(case_tester) -> None:
187+
pass
188+
189+
Filter only **supported** targets that support ULP:
190+
191+
.. code:: python
192+
193+
from pytest_embedded_idf.utils import soc_filtered_targets
194+
195+
@idf_parametrize('target', soc_filtered_targets('SOC_ULP_SUPPORTED != 1', targets="supported_targets"), indirect=['target'])
196+
def test_only_supported_targets_which_support_ulp(case_tester) -> None:
197+
pass
198+
155199
Markers
156200
-------
157201

pytest-embedded-idf/pytest_embedded_idf/utils.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,31 @@ def decorator(func):
9393
return decorator
9494

9595

96-
def soc_filtered_targets(soc_statement: str) -> t.List[str]:
96+
ValidTargets = t.Literal['supported_targets', 'preview_targets', 'all']
97+
98+
99+
def soc_filtered_targets(soc_statement: str, targets: ValidTargets = 'all') -> t.List[str]:
100+
"""Filters targets based on a given SOC (System on Chip) statement.
101+
102+
Args:
103+
soc_statement (str): A boolean expression used to filter targets.
104+
targets (ValidTargets, optional): Specifies which target set to filter.
105+
- "supported_targets": Filters only supported targets.
106+
- "preview_targets": Filters only preview targets.
107+
- "all": Filters both supported and preview targets.
108+
Defaults to "all".
109+
110+
Returns:
111+
List[str]: A list of targets that satisfy the given SOC statement.
112+
"""
113+
target_list = []
114+
target_list.extend(supported_targets.get()) if targets in ['all', 'supported_targets'] else []
115+
target_list.extend(preview_targets.get()) if targets in ['all', 'preview_targets'] else []
116+
97117
stm = parse_bool_expr(soc_statement)
118+
98119
result = []
99-
for target in [*supported_targets.get(), *preview_targets.get()]:
120+
for target in target_list:
100121
if stm.get_value(target, ''):
101122
result.append(target)
102123
return result

pytest-embedded-idf/tests/test_idf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,9 @@ def test_soc_filtered_targets(testdir, copy_mock_esp_idf, monkeypatch): # noqa:
11671167
'esp32h2',
11681168
'esp32c5',
11691169
]
1170+
assert soc_filtered_targets('SOC_A == 1', 'all') == ['esp32c3', 'esp32s3', 'esp32c6', 'esp32c5']
1171+
assert soc_filtered_targets('SOC_A == 1', targets='supported_targets') == ['esp32c3', 'esp32s3', 'esp32c6']
1172+
assert soc_filtered_targets('SOC_A == 1', targets='preview_targets') == ['esp32c5']
11701173

11711174

11721175
def test_skip_if_soc_target_in_args(testdir, copy_mock_esp_idf, monkeypatch): # noqa: ARG001

0 commit comments

Comments
 (0)