2022-06-09 12:59:38 -04:00
|
|
|
# vim: set syntax=python ts=4 :
|
|
|
|
#
|
|
|
|
# Copyright (c) 2018-2022 Intel Corporation
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2023-11-11 14:52:21 +10:00
|
|
|
import copy
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
import warnings
|
2025-02-13 13:03:42 +01:00
|
|
|
from typing import Any
|
2024-11-27 10:37:51 +00:00
|
|
|
|
|
|
|
import scl
|
2022-06-23 17:40:57 -04:00
|
|
|
from twisterlib.error import ConfigurationError
|
2022-06-09 12:59:38 -04:00
|
|
|
|
2024-11-27 10:37:51 +00:00
|
|
|
|
2025-02-13 13:03:42 +01:00
|
|
|
def extract_fields_from_arg_list(
|
|
|
|
target_fields: set, arg_list: str | list
|
|
|
|
) -> tuple[dict[str, list[str]], list[str]]:
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
"""
|
|
|
|
Given a list of "FIELD=VALUE" args, extract values of args with a
|
|
|
|
given field name and return the remaining args separately.
|
|
|
|
"""
|
2025-02-13 13:03:42 +01:00
|
|
|
extracted_fields: dict[str, list[str]] = {f: list() for f in target_fields}
|
|
|
|
other_fields: list[str] = []
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
|
2023-05-08 13:55:56 +02:00
|
|
|
if isinstance(arg_list, str):
|
|
|
|
args = arg_list.strip().split()
|
|
|
|
else:
|
|
|
|
args = arg_list
|
|
|
|
|
|
|
|
for field in args:
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
try:
|
|
|
|
name, val = field.split("=", 1)
|
|
|
|
except ValueError:
|
|
|
|
# Can't parse this. Just pass it through
|
|
|
|
other_fields.append(field)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if name in target_fields:
|
|
|
|
extracted_fields[name].append(val.strip('\'"'))
|
|
|
|
else:
|
|
|
|
# Move to other_fields
|
|
|
|
other_fields.append(field)
|
|
|
|
|
2024-07-30 14:33:54 +01:00
|
|
|
return extracted_fields, other_fields
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
|
2025-02-13 13:03:42 +01:00
|
|
|
|
2022-06-09 12:59:38 -04:00
|
|
|
class TwisterConfigParser:
|
|
|
|
"""Class to read testsuite yaml files with semantic checking
|
|
|
|
"""
|
|
|
|
|
2025-02-13 13:03:42 +01:00
|
|
|
testsuite_valid_keys: dict[str, dict[str, Any]] = {
|
|
|
|
"tags": {"type": "set", "required": False},
|
|
|
|
"type": {"type": "str", "default": "integration"},
|
|
|
|
"extra_args": {"type": "list"},
|
|
|
|
"extra_configs": {"type": "list"},
|
|
|
|
"extra_conf_files": {"type": "list", "default": []},
|
|
|
|
"extra_overlay_confs": {"type": "list", "default": []},
|
|
|
|
"extra_dtc_overlay_files": {"type": "list", "default": []},
|
|
|
|
"required_snippets": {"type": "list"},
|
|
|
|
"build_only": {"type": "bool", "default": False},
|
|
|
|
"build_on_all": {"type": "bool", "default": False},
|
|
|
|
"skip": {"type": "bool", "default": False},
|
|
|
|
"slow": {"type": "bool", "default": False},
|
|
|
|
"timeout": {"type": "int", "default": 60},
|
|
|
|
"min_ram": {"type": "int", "default": 16},
|
|
|
|
"modules": {"type": "list", "default": []},
|
|
|
|
"depends_on": {"type": "set"},
|
|
|
|
"min_flash": {"type": "int", "default": 32},
|
|
|
|
"arch_allow": {"type": "set"},
|
|
|
|
"arch_exclude": {"type": "set"},
|
|
|
|
"vendor_allow": {"type": "set"},
|
|
|
|
"vendor_exclude": {"type": "set"},
|
|
|
|
"extra_sections": {"type": "list", "default": []},
|
|
|
|
"integration_platforms": {"type": "list", "default": []},
|
|
|
|
"integration_toolchains": {"type": "list", "default": []},
|
|
|
|
"ignore_faults": {"type": "bool", "default": False},
|
|
|
|
"ignore_qemu_crash": {"type": "bool", "default": False},
|
|
|
|
"testcases": {"type": "list", "default": []},
|
|
|
|
"platform_type": {"type": "list", "default": []},
|
|
|
|
"platform_exclude": {"type": "set"},
|
|
|
|
"platform_allow": {"type": "set"},
|
|
|
|
"platform_key": {"type": "list", "default": []},
|
|
|
|
"simulation_exclude": {"type": "list", "default": []},
|
|
|
|
"toolchain_exclude": {"type": "set"},
|
|
|
|
"toolchain_allow": {"type": "set"},
|
|
|
|
"filter": {"type": "str"},
|
|
|
|
"levels": {"type": "list", "default": []},
|
|
|
|
"harness": {"type": "str", "default": "test"},
|
|
|
|
"harness_config": {"type": "map", "default": {}},
|
|
|
|
"seed": {"type": "int", "default": 0},
|
|
|
|
"sysbuild": {"type": "bool", "default": False}
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self, filename: str, schema: dict[str, Any]) -> None:
|
2022-06-09 12:59:38 -04:00
|
|
|
"""Instantiate a new TwisterConfigParser object
|
|
|
|
|
|
|
|
@param filename Source .yaml file to read
|
|
|
|
"""
|
|
|
|
self.schema = schema
|
|
|
|
self.filename = filename
|
2025-02-13 13:03:42 +01:00
|
|
|
self.data: dict[str, Any] = {}
|
|
|
|
self.scenarios: dict[str, Any] = {}
|
|
|
|
self.common: dict[str, Any] = {}
|
2022-06-09 12:59:38 -04:00
|
|
|
|
2025-02-13 13:03:42 +01:00
|
|
|
def load(self) -> dict[str, Any]:
|
2024-08-09 17:17:40 -04:00
|
|
|
data = scl.yaml_load_verify(self.filename, self.schema)
|
|
|
|
self.data = data
|
2022-06-09 12:59:38 -04:00
|
|
|
|
|
|
|
if 'tests' in self.data:
|
|
|
|
self.scenarios = self.data['tests']
|
|
|
|
if 'common' in self.data:
|
|
|
|
self.common = self.data['common']
|
2024-08-09 17:17:40 -04:00
|
|
|
return data
|
2022-06-09 12:59:38 -04:00
|
|
|
|
2025-02-13 13:03:42 +01:00
|
|
|
def _cast_value(self, value: Any, typestr: str) -> Any:
|
2022-06-09 12:59:38 -04:00
|
|
|
if typestr == "str":
|
2024-12-02 10:28:15 +01:00
|
|
|
return value.strip()
|
2022-06-09 12:59:38 -04:00
|
|
|
|
|
|
|
elif typestr == "float":
|
|
|
|
return float(value)
|
|
|
|
|
|
|
|
elif typestr == "int":
|
|
|
|
return int(value)
|
|
|
|
|
|
|
|
elif typestr == "bool":
|
|
|
|
return value
|
|
|
|
|
2023-05-08 12:21:45 +02:00
|
|
|
elif typestr.startswith("list"):
|
|
|
|
if isinstance(value, list):
|
|
|
|
return value
|
|
|
|
elif isinstance(value, str):
|
2024-12-02 10:28:15 +01:00
|
|
|
value = value.strip()
|
|
|
|
return [value] if value else list()
|
2022-06-09 12:59:38 -04:00
|
|
|
else:
|
2023-05-08 12:21:45 +02:00
|
|
|
raise ValueError
|
|
|
|
|
|
|
|
elif typestr.startswith("set"):
|
|
|
|
if isinstance(value, list):
|
|
|
|
return set(value)
|
|
|
|
elif isinstance(value, str):
|
2024-12-02 10:28:15 +01:00
|
|
|
value = value.strip()
|
|
|
|
return {value} if value else set()
|
2022-06-09 12:59:38 -04:00
|
|
|
else:
|
2023-05-08 12:21:45 +02:00
|
|
|
raise ValueError
|
2022-06-09 12:59:38 -04:00
|
|
|
|
|
|
|
elif typestr.startswith("map"):
|
|
|
|
return value
|
|
|
|
else:
|
2024-11-27 16:57:32 +00:00
|
|
|
raise ConfigurationError(self.filename, f"unknown type '{value}'")
|
2022-06-09 12:59:38 -04:00
|
|
|
|
2025-02-13 13:03:42 +01:00
|
|
|
def get_scenario(self, name: str) -> dict[str, Any]:
|
2022-06-09 12:59:38 -04:00
|
|
|
"""Get a dictionary representing the keys/values within a scenario
|
|
|
|
|
|
|
|
@param name The scenario in the .yaml file to retrieve data from
|
|
|
|
@return A dictionary containing the scenario key-value pairs with
|
|
|
|
type conversion and default values filled in per valid_keys
|
|
|
|
"""
|
|
|
|
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
# "CONF_FILE", "OVERLAY_CONFIG", and "DTC_OVERLAY_FILE" fields from each
|
|
|
|
# of the extra_args lines
|
2025-02-13 13:03:42 +01:00
|
|
|
extracted_common: dict = {}
|
|
|
|
extracted_testsuite: dict = {}
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
|
2025-02-13 13:03:42 +01:00
|
|
|
d: dict[str, Any] = {}
|
2022-06-09 12:59:38 -04:00
|
|
|
for k, v in self.common.items():
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
if k == "extra_args":
|
|
|
|
# Pull out these fields and leave the rest
|
|
|
|
extracted_common, d[k] = extract_fields_from_arg_list(
|
2023-05-08 13:55:56 +02:00
|
|
|
{"CONF_FILE", "OVERLAY_CONFIG", "DTC_OVERLAY_FILE"}, v
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
)
|
|
|
|
else:
|
2023-11-11 14:52:21 +10:00
|
|
|
# Copy common value to avoid mutating it with test specific values below
|
|
|
|
d[k] = copy.copy(v)
|
2022-06-09 12:59:38 -04:00
|
|
|
|
|
|
|
for k, v in self.scenarios[name].items():
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
if k == "extra_args":
|
|
|
|
# Pull out these fields and leave the rest
|
|
|
|
extracted_testsuite, v = extract_fields_from_arg_list(
|
2023-05-08 13:55:56 +02:00
|
|
|
{"CONF_FILE", "OVERLAY_CONFIG", "DTC_OVERLAY_FILE"}, v
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
)
|
2022-06-09 12:59:38 -04:00
|
|
|
if k in d:
|
2023-05-11 09:29:15 +02:00
|
|
|
if k == "filter":
|
2024-11-27 16:57:32 +00:00
|
|
|
d[k] = f"({d[k]}) and ({v})"
|
2023-05-11 09:29:15 +02:00
|
|
|
elif k not in ("extra_conf_files", "extra_overlay_confs",
|
|
|
|
"extra_dtc_overlay_files"):
|
|
|
|
if isinstance(d[k], str) and isinstance(v, list):
|
2024-12-02 10:28:15 +01:00
|
|
|
d[k] = [d[k]] + v
|
2023-05-11 09:29:15 +02:00
|
|
|
elif isinstance(d[k], list) and isinstance(v, str):
|
2024-12-02 10:28:15 +01:00
|
|
|
d[k] += [v]
|
2023-05-11 09:29:15 +02:00
|
|
|
elif isinstance(d[k], list) and isinstance(v, list):
|
|
|
|
d[k] += v
|
|
|
|
elif isinstance(d[k], str) and isinstance(v, str):
|
2024-12-02 10:28:15 +01:00
|
|
|
# overwrite if type is string, otherwise merge into a list
|
|
|
|
type = self.testsuite_valid_keys[k]["type"]
|
|
|
|
if type == "str":
|
|
|
|
d[k] = v
|
|
|
|
elif type in ("list", "set"):
|
|
|
|
d[k] = [d[k], v]
|
|
|
|
else:
|
|
|
|
raise ValueError
|
2022-06-09 12:59:38 -04:00
|
|
|
else:
|
2023-05-11 09:29:15 +02:00
|
|
|
# replace value if not str/list (e.g. integer)
|
|
|
|
d[k] = v
|
2022-06-09 12:59:38 -04:00
|
|
|
else:
|
|
|
|
d[k] = v
|
|
|
|
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
# Compile conf files in to a single list. The order to apply them is:
|
|
|
|
# (1) CONF_FILEs extracted from common['extra_args']
|
|
|
|
# (2) common['extra_conf_files']
|
|
|
|
# (3) CONF_FILES extracted from scenarios[name]['extra_args']
|
|
|
|
# (4) scenarios[name]['extra_conf_files']
|
|
|
|
d["extra_conf_files"] = \
|
|
|
|
extracted_common.get("CONF_FILE", []) + \
|
|
|
|
self.common.get("extra_conf_files", []) + \
|
|
|
|
extracted_testsuite.get("CONF_FILE", []) + \
|
|
|
|
self.scenarios[name].get("extra_conf_files", [])
|
|
|
|
|
|
|
|
# Repeat the above for overlay confs and DTC overlay files
|
|
|
|
d["extra_overlay_confs"] = \
|
|
|
|
extracted_common.get("OVERLAY_CONFIG", []) + \
|
|
|
|
self.common.get("extra_overlay_confs", []) + \
|
|
|
|
extracted_testsuite.get("OVERLAY_CONFIG", []) + \
|
|
|
|
self.scenarios[name].get("extra_overlay_confs", [])
|
|
|
|
|
|
|
|
d["extra_dtc_overlay_files"] = \
|
|
|
|
extracted_common.get("DTC_OVERLAY_FILE", []) + \
|
|
|
|
self.common.get("extra_dtc_overlay_files", []) + \
|
|
|
|
extracted_testsuite.get("DTC_OVERLAY_FILE", []) + \
|
|
|
|
self.scenarios[name].get("extra_dtc_overlay_files", [])
|
|
|
|
|
|
|
|
if any({len(x) > 0 for x in extracted_common.values()}) or \
|
2025-02-13 13:03:42 +01:00
|
|
|
any({len(x) > 0 for x in extracted_testsuite.values()}):
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
warnings.warn(
|
|
|
|
"Do not specify CONF_FILE, OVERLAY_CONFIG, or DTC_OVERLAY_FILE "
|
|
|
|
"in extra_args. This feature is deprecated and will soon "
|
|
|
|
"result in an error. Use extra_conf_files, extra_overlay_confs "
|
|
|
|
"or extra_dtc_overlay_files YAML fields instead",
|
2024-11-27 13:47:46 +00:00
|
|
|
DeprecationWarning,
|
|
|
|
stacklevel=2
|
twister: Fields for Kconfig and DT overlay files in testcase.yaml
This is an implementation of issue #48334 and adds support for
specifying additional config and device tree overlays through fields in
the testcase.yaml file, which is more readable than having to cram these
in to `extra_args`.
Consider this example which shows the original and new ways to add
config and DT overlays:
```
common:
extra_args: "CONF_FILE=a.conf;b.conf
DTC_OVERLAY_FILE=w.overlay;x.overlay OVERLAY_CONFIG=e.conf
UNRELATED=abc"
tests:
utilities.base64:
extra_conf_files:
- "c.conf"
- "d.conf"
extra_overlay_confs:
- "extra_overlay.conf"
extra_dtc_overlay_files:
- "y.overlay"
- "z.overlay"
extra_configs:
- CONFIG_SAMPLE=y
tags: base64
type: unit
```
The new fields are `extra_conf_files`, `extra_overlay_confs,
`extra_dtc_overlay_files`. Files specified in these sections are appended
to any `CONF_FILE`, `OVERLAY_CONFIG`, or `DTC_OVERLAY_FILE` fields in
`extra_args`, causing the following args being passed in to
`self.run_cmake` at `runner.py:850`:
```
['-DUNRELATED=abc',
'-DCONF_FILE=a.conf;b.conf;c.conf;d.conf',
'-DDTC_OVERLAY_FILE=w.overlay;x.overlay;y.overlay;z.overlay',
'-DOVERLAY_CONFIG=e.conf extra_overlay.conf '
'<build_dir>/twister/testsuite_extra.conf']
```
These fields can be used in the common or scenario-specific YAML
sections and will be merged in order of least to most specific:
1. config files extracted from common's extra_args
2. files listed in common's {extra_conf_files or extra_overlay_confs
or extra_dtc_overlay_files}
3. config files extracted from test scenario's extra_args
4. files listed in test scenario's {extra_conf_files or
extra_overlay_confs or extra_dtc_overlay_files}
Specifying these files in extra_args now triggers a deprecation warning,
as the direct YAML fields are preferred for readability. They will still
function for now but support will be dropped in the future. One
testcase.yaml
(`zephyr/tests/cmake/overlays/var_expansions/testcase.yaml`) is
converted to use the new fields. A follow-up PR will convert the
remaining files to the new format.
Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-08-09 16:51:17 -06:00
|
|
|
)
|
|
|
|
|
2022-06-28 09:58:09 -04:00
|
|
|
for k, kinfo in self.testsuite_valid_keys.items():
|
2022-06-09 12:59:38 -04:00
|
|
|
if k not in d:
|
2024-11-27 11:20:46 +00:00
|
|
|
required = kinfo.get("required", False)
|
2022-06-09 12:59:38 -04:00
|
|
|
|
|
|
|
if required:
|
|
|
|
raise ConfigurationError(
|
|
|
|
self.filename,
|
2024-11-27 16:57:32 +00:00
|
|
|
f"missing required value for '{k}' in test '{name}'"
|
|
|
|
)
|
2022-06-09 12:59:38 -04:00
|
|
|
else:
|
|
|
|
if "default" in kinfo:
|
|
|
|
default = kinfo["default"]
|
|
|
|
else:
|
|
|
|
default = self._cast_value("", kinfo["type"])
|
|
|
|
d[k] = default
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
d[k] = self._cast_value(d[k], kinfo["type"])
|
|
|
|
except ValueError:
|
|
|
|
raise ConfigurationError(
|
2024-11-27 16:57:32 +00:00
|
|
|
self.filename,
|
|
|
|
f"bad {kinfo['type']} value '{d[k]}' for key '{k}' in name '{name}'"
|
2024-11-27 13:00:44 +00:00
|
|
|
) from None
|
2022-06-09 12:59:38 -04:00
|
|
|
|
|
|
|
return d
|