Commit graph

49 commits

Author SHA1 Message Date
Luca Burelli
a90870da4c cmake: yaml: improve escaping of strings with backslashes and quotes
Switching the intermediate file format from JSON to YAML has a very
significant benefit: the file is now loaded via yaml_load(), which
internally calls Python to parse the file into the JSON format that
CMake expects. This means that the file contents are now automatically
escaped properly for JSON; it is a huge improvement over the previous
implementation, which was escaping everything given as input to
to_yaml().

With the removal of the now-redundant call in to_yaml(), escaping is
applied exactly once per value or list, when it is passed to yaml_set().
This allows to convert the logic in zephyr_string(ESCAPE ...) to a more
robust "escape everything" approach.

These changes fix the handling of strings with backslashes and different
types of quotes passed either directly or via generator expression. The
existing tests are updated to cover these cases.

Two other small changes are made in this commit:

- a small check in internal_yaml_list_append() is removed, as the same
  issue is already detected by the caller yaml_set() logic.

- the to_yaml() function is modified to initialize the YAML output
  variable at the top level, which is the expected behavior. This
  resulted in genex temp files sometimes having duplicate lines.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-04-10 10:11:47 +02:00
Luca Burelli
4a50fbf804 cmake: yaml: properly store strings
Store strings in YAML as single-quoted entries to avoid issues with
special characters. This also fixes a quirk with the current test
suite where the quotes in the expected value are filtered out by the
YAML import.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-04-10 10:11:47 +02:00
Samuel Chee
5b7d1e4129 boards: arm: mps2: add pinctrl support for mps2 board
Migrates mps2 targets away from the pinmux driver to
the new pinctrl driver.

Signed-off-by: Samuel Chee <samche01@arm.com>
Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2025-04-07 15:18:10 +02:00
Anas Nashif
5c8cf1c18c tests: fix various test ids and use existing scheme
Fix IDs and match them to what we have in the MAINTAINERS file.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-04-07 11:22:36 +02:00
Alberto Escolar Piedras
a8b44fd1d1 dts: zephyr,native-posix-cpu changed to zephyr,native-sim-cpu
The old binding remains until 4.4 but is deprecated.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-12 02:27:36 +01:00
Alberto Escolar Piedras
cb53e40ff9 drivers uart_native_posix: rename to native_pty and support N instances
Rename the driver from uart_native_posix to uart_native_pty.
Including renaming the DTS compatible, and kconfig options, deprecating
the old ones.

And refactor the driver, generalizing it, so we can have any number of
instances.
Note that, unfortunately generalizing to N instances cannot be done
without a degree of backwards compatibility breakage: This driver was
born with all its configuration and selection of the instances based on
kconfig.
When the driver was made to use DT, it was done in a way that required
both DT and kconfig needing to manually coherently enable the 2nd UART.
This has now been fixed, which it means only DT is used to decide how
many instances are avaliable, and UART_NATIVE_POSIX_PORT_1_ENABLE is
just ignored.

Including:
* Deprecate UART_NATIVE_WAIT_PTS_READY_ENABLE: the options is always on
  now as it has no practical drawbacks.
* Deprecate UART_NATIVE_POSIX_PORT_1_ENABLE: DTS intanciation defines it
  being available now.
* Rename a few functions and in general shorten pseudo-tty/pseudo-
  terminal to PTY instead of PTTY.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-11 18:54:02 +01:00
Alberto Escolar Piedras
ab7a6de5bb drivers/counter/counter_native_sim: Rename from counter_native_posix
Including renaming the DTS binding and kconfig options
deprecating the old one.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-10 06:52:37 +01:00
Alberto Escolar Piedras
4338122248 drivers entropy: fake_entropy_native_posix rename to _native_sim
Rename the driver files, binding and kconfig options, while deprecating
the old binding and kconfig options.

Uses in tree are replaced.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-08 03:38:13 +01:00
Wilfried Chauveau
c0139fad06 drivers: gpio: mmio32: update gpio_mmio32 to behave like other divers
The current implementation requires SoCs/Boards to manualy instantiate
the preripherals and initilize them.

The change lets Zephyr rely on the device tree setup to instantiate &
initialize the relevant gpio peripheral.

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
2025-02-14 10:42:02 +01:00
Torsten Rasmussen
0828d0b0ef cmake: support array of maps in yaml module
This commit introduce support for maps in a yaml list.

The yaml_set() function has been extended with the following signature:
> yaml_set(NAME <name> KEY <key>...
>          [APPEND] LIST MAP <map1> MAP <map2> MAP ...
> )

where a `MAP <map>` has the form:
`MAP "<key1>: <value1>, <key2>: <value2>, ...`

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-02-10 15:56:52 +00:00
Luca Burelli
3741a0b744 tests: yaml: add test for generator expressions
Add tests to the YAML suite for generator expressions. The test checks
that generator expressions are handled as expected at different stages:

 - immediately after yaml_save(), the file must contain only non-genex
   entries;
 - at a later time, after the target has been built, the file must
   contain all the expanded genex values.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-01-30 14:10:53 +01:00
Luca Burelli
e8e8597dbd tests: yaml: test the API in CMake script mode as well
To verify proper functionality, the YAML module test suite is now run
twice: once in the regular CMake project mode and once in the CMake
script mode.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-01-30 14:10:53 +01:00
Luca Burelli
d5ac588280 tests: yaml: add test for APPEND LIST operation
This test verifies that the APPEND LIST operation in yaml_set() works as
expected.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-01-30 14:10:53 +01:00
Luca Burelli
5d4e63faa6 tests: yaml: refactor to remove unused variables
This introductory commit removes the ignored 'actual' variable from the
'yaml_set()' calls in the tests to make the code cleaner. Also, a badly
indented block is fixed in the 'message()' macro.

No functional change is introduced by this commit.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-01-30 14:10:53 +01:00
Benjamin Cabé
6fddb19463 Revert "cmake: support array of maps in yaml module"
This reverts commit f24f5288f3.
as it's part of a series of commits causing issues on Windows

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-01-29 09:27:31 +01:00
Torsten Rasmussen
f24f5288f3 cmake: support array of maps in yaml module
This commit introduce support for maps in a yaml list.

The yaml_set() function has been extended with the following signature:
> yaml_set(NAME <name> KEY <key>...
>          [APPEND] LIST MAP <map1> MAP <map2> MAP ...
> )

where a `MAP <map>` has the form:
`MAP "<key1>: <value1>, <key2>: <value2>, ...`

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-01-27 13:24:23 +01:00
Samuel Chee
8d6d4de79d boards: arm: mps2: Add support for mps2/an383
Added new mps2 board an383 to enable testing with ARM FVP.
Qualifier to build/run is mps2/an383

Signed-off-by: Samuel Chee <samche01@arm.com>
2025-01-20 11:15:32 +01:00
Jamie McCrae
5442687488 tests: cmake: snippets: Exclude sysbuild
Prevents sysbuild from being used as this adds a local snippet root
which should only be used (and tested) by application

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2024-12-27 07:18:13 +01:00
Jamie McCrae
06fd7389bd tests: cmake: Add sysbuild snippets test
Adds a new test that ensures sysbuild snippets work and are
applied correctly

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2024-12-27 07:18:13 +01:00
Luca Burelli
d492c849a3 tests: cmake: run zephyr_get() tests in script mode
Re-run the zephyr_get() testsuite in script mode after the project
mode testsuite has been executed. This is to ensure that the
zephyr_get() function works correctly in script mode as well.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-12-26 09:31:11 +01:00
Torsten Rasmussen
4e29a35b22 cmake: use GLOBAL property instead TARGET properties for scoping
Targets are not available in script mode.
To support the Zephyr scoping feature used by snippets and yaml module
then this commit moves from using custom targets to use GLOBAL
properties for scopes.

A scope property is prefixed with `<scope>:<property>` to avoid naming
collisions.
A `scope:<scope-name>` global property is used to track created scopes.
Tracking valid scopes ensure that properties are only set on known
scopes and thus catches typos / naming errors.

Add zephyr_scope_exists() and zephyr_get_scoped() to abstract the
implementation details of the scoped property retrieval and refactor
current code to use them.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-12-26 09:31:11 +01:00
Gerard Marull-Paretas
d4a67e321b samples, tests: remove usage of space-separated lists
Convert them to native YAML lists. Support for space-separated
lists was deprecated in Twister a long time ago.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2024-12-04 14:14:53 -05:00
Torsten Rasmussen
f3151571ba tests: add twister tests for CMake board and SoC extension
This commit adds new tests for verifying the functionality of the board
and SoC extension feature.

It does so by defining:
- A new CPU cluster on an existing SoC
- Two new board variants on top of an existing board

The new board variants are defined on top of the existing `native_sim`
board, so that the following native_sim board targets are available for
the test.
Existing board targets:
- native_sim/native
- native_sim/native/64

Extended board targets:
- native_sim/native/one
- native_sim/native/64/two

The new CPU cluster is defined for the existing `an521` SoC.
Existing CPU Clusters on an521:
- cpu0
- cpu1

New CPU Cluster:
- cputest

For SoC tests the mps2 board is used.
This means that for testing, the following board targets using the an521
SoC are:
- mps2/an521/cpu0
- mps2/an521/cpu1
- mps2/an521/cputest

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-26 17:14:06 +02:00
Torsten Rasmussen
d128a078f6 cmake: change test message overwrite to macro
Fixes: #79052

The yaml CMake tests overwrites `message()` in order to verify correct
error handling. This was original done in a function and then using
a return call when an expected error has been raised.
Using a function() means the `return()` only returns the `message()`
and thus wrongly continue processing rest of the yaml file.

Change `message()` to macro so the return call correctly returns from
the calling yaml functions.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-09-30 17:12:23 +01:00
Alberto Escolar Piedras
d50a306400 tests/cmake/snippets: Don't test on native_posix
native_posix is now deprecated.
Building these tests in both native_sim and native_posix does not
improve coverage for the tests or subsystem but doubles CI time.
As anyhow native_posix will be removed all together in
2 releases, let's remove it already for these.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-09-25 04:04:36 -04:00
Torsten Rasmussen
3382e28737 tests: cmake: add test cases for CMake YAML module
This commit provides a basic set of tests for Zephyr's CMake YAML
module.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-08-23 08:02:11 -04:00
Anas Nashif
569dbd8e0f tests: cmake: fix test identifier
cmake is part of the build system area.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-07-18 06:47:57 -04:00
Jordan Yates
243eb36b18 everywhere: reindent .overlay files with tabs
`checkpatch.pl` requires that dts sources are indented with tabs,
fix all the spaces that slipped in while checkpatch wasn't watching.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-26 15:59:44 +02:00
Jordan Yates
629858f572 tests: cmake: app_version: test app_version.h
Test the basic `app_version.h` file generation.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-24 08:28:54 -04:00
Jamie McCrae
da3007e559 tests: cmake: overlays: Add soc_folder_overlay test
Adds a testcase for the new ``socs`` folder, with overlays

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2024-04-29 15:08:35 +01:00
Jamie McCrae
1ed6d89d13 tests: cmake: overlays: Add soc_folder_kconfig test
Adds a testcase for the new ``socs`` folder using Kconfig fragments

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2024-04-29 15:08:35 +01:00
Alberto Escolar Piedras
548739cf8c tests/cmake/*: Switch to native_sim
Switch from native_posix to native_sim as test platform

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-11-27 16:06:42 +00:00
Anas Nashif
345735d0a8 tests: remove CONFIG_ZTEST_NEW_API in all tests
Remove all usage of CONFIG_ZTEST_NEW_API from tests and sample as this
is now enabled by default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Anas Nashif
a2ed99687b tests: group all build system tests under build_system
Consistent naming of components related to build system.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-11 14:19:40 +03:00
Grzegorz Swiderski
199cc7f91b cmake: Fix scope pollution in zephyr_get(... MERGE)
Clear the output variable with an empty string, before appending to it.
Unsetting the variable locally is insufficient, because its value from
the parent scope or cache can still creep into the final result.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2023-08-16 15:01:57 +02:00
Grzegorz Swiderski
7f4b1abb39 cmake: Don't lose global sysbuild value with zephyr_get(... MERGE)
According to the doc comment:

  If using MERGE then SYSBUILD GLOBAL will get both the local and global
  sysbuild scope variables (in that order, if both exist).

This stopped working in commit 8460d91e32,
when support for `zephyr_get(... VAR <multiple-variables>)` was added.

Instead of returning both values, the local sysbuild scope value would
clobber the global one. Fix this by splitting the internal `sysbuild`
scope into `sysbuild_local` and `sysbuild_global`, in that order.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2023-08-16 15:01:57 +02:00
Grzegorz Swiderski
5ef7229a8c tests: cmake: Add zephyr_get
As `zephyr_get()` grows in complexity and significance, it must continue
working as expected. Unfortunately, it has a few minor bugs already, but
they will be taken care of in the next few commits. Before that, though,
let's go ahead and add a test suite for this function.

For now, some tests will pass by using incorrect values, annotated with
the `# BUG` comments; they will be removed in later patches. The purpose
of having them now is to make it easier to see what's about to be fixed.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2023-08-16 15:01:57 +02:00
Jordan Yates
15b003877f tests: cmake: snippets: test DTS_EXTRA_CPPFLAGS
Add tests for the `DTS_EXTRA_CPPFLAGS` append option in snippets.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-08-02 16:27:11 +02:00
Anas Nashif
bc72b13c88 tests: cmake: fix identifier
config_dir is part of cmake testsuite.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-08-01 13:24:09 -04:00
Stephanos Ioannidis
f1a18022be tests: snippets: Rework the snippet test
This commit reworks the snippet test to more comprehensively test the
different processing modes of snippets.

The following testcases have been added:

1. Initial state with no snippet applied
2. Applying `foo` snippet from the default application snippet root
3. Applying `bar` snippet from an extra snippet root
4. Sequentially applying `foo` and `bar` snippets to test the snippet
   processing order
5. Sequentially applying `bar` and `foo` snippets to test the snippet
   processing order.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-05-25 21:51:26 +02:00
Torsten Rasmussen
1561a0705f snippets: support for EXTRA_DTC_OVERLAY_FILE and EXTRA_CONF_FILE
This commit adds change snippets to use the new EXTRA_DTC_OVERLAY_FILE
and EXTRA_CONF_FILE Zephyr build system variables instead of
DTC_OVERLAY_FILE and OVERLAY_CONFIG.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-05-25 13:31:53 +00:00
Torsten Rasmussen
a88502783b cmake: align Zephyr module variable to EXTRA_ZEPHYR_MODULES
Align Zephyr modules with other user facing variables where settings
can be defined or extended, meaning Zephyr modules now supports:
ZEPHYR_MODULES and EXTRA_ZEPHYR_MODULES.

Support for ZEPHYR_EXTRA_MODULES is kept foir backward compatibility.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-05-23 16:40:21 +02:00
Gerard Marull-Paretas
93b63df762 samples, tests: convert string-based twister lists to YAML lists
Twister now supports using YAML lists for all fields that were written
as space-separated lists. Used twister_to_list.py script. Some artifacts
on string length are due to how ruamel dumps content.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-10 09:52:37 +02:00
Martí Bolívar
a7aafcbbdc tests: add snippet test suite
Add an initial test suite for the basic SNIPPET_ROOT, SNIPPET, and
'append' features in snippet.yml.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2023-03-26 16:12:41 +02:00
Tristan Honscheid
1eb0452fcb 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>
2023-03-01 16:52:01 -05:00
Fabio Baltieri
7db1d17ee3 yamllint: fix all yamllint line-length errors
Fix all line-length errors detected by yamllint:

yamllint -f parsable -c .yamllint $( find -regex '.*\.y[a]*ml' ) | \
  grep '(line-length)'

Using a limit is set to 100 columns, not touching the commandlines in
GitHub workflows (at least for now).

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-01-04 01:16:45 +09:00
Fabio Baltieri
bd4cdde4b0 yamllint: fix all yamllint colons, commas and empty-lines errors
Fix all colons and commas errors detected by yamllint:

yamllint -f parsable -c .yamllint $( find -regex '.*\.y[a]*ml' ) | \
  grep '(brackets)'

yamllint -f parsable -c .yamllint $( find -regex '.*\.y[a]*ml' ) | \
  grep '(commas)'

yamllint -f parsable -c .yamllint $( find -regex '.*\.y[a]*ml' ) | \
  grep '(empty-lines)'

Default config is no space before, one space after, max 2 empty lines.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-01-04 01:16:45 +09:00
Gregory Shue
cfcf630184 build: Overlay build vars expand ${ZEPHYR_<module>_MODULE_DIR}
Support referencing module directories by name in CONF_FILE,
OVERLAY_CONFIG, and DTC_OVERLAY_FILE so that projects can reference
overlay files in arbitrary modules.

Verified by passing all the following tests:
  ./scripts/twister -T tests/cmake/overlays/

Fixes #41830

Signed-off-by: Gregory Shue <gregory.shue@legrand.us>
2022-10-13 12:04:38 +02:00
Torsten Rasmussen
1198087440 cmake: APPLICATION_CONFIG_DIR support implemented
With this commit a dedicated APPLICATION_CONFIG_DIR is added to the
Zephyr build system.

Currently, the APPLICATION_SOURCE_DIR is identical also the base
location of configuration files.

This is very practical for simple samples, but also has it limitations
for more complex setups.

Introducing a dedicated APPLICATION_CONFIG_DIR allows users more
customization options in Zephyr build system.
Especially in terms of custom build configuration files unknown to
Zephyr itself.

For example, instead of all configuration files being located directly
in the application source folder, a project might prefer to organize
their configuration files on a per board basis, for example:
<app>/boards/custom_board_A/prj.conf
<app>/boards/custom_board_A/app.overlay
<app>/boards/custom_board_A/custom_file.mine
<app>/boards/custom_board_B/prj.conf
<app>/boards/custom_board_B/app.overlay
<app>/boards/custom_board_B/custom_file.mine
...

instead of n-files located in the root of the sample.

If the user / sample specifies APPLICATION_CONFIG_DIR, then this folder
will always be used instead of the default configuration folder.

As part of this extension the behaviour of
`-DCONF_FILE=<relative-path>/prj_<build>.conf` and additional Kconfig
fragments automatic sourcing has been aligned with the default behavior
of `prj.conf`.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-11-10 08:25:36 -05:00