From 067a35f2fb718a10d3fb556b56d909a680e1b3c9 Mon Sep 17 00:00:00 2001 From: Emil Lindqvist Date: Wed, 20 Nov 2024 09:16:29 +0100 Subject: [PATCH 001/261] display: stm32: implement display_get_framebuffer API This commit implements the display_get_framebuffer API function in the STM32 LTDC display driver Signed-off-by: Emil Lindqvist --- drivers/display/display_stm32_ltdc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/display/display_stm32_ltdc.c b/drivers/display/display_stm32_ltdc.c index 3c6a2085def475..068c9e9eb0c7b9 100644 --- a/drivers/display/display_stm32_ltdc.c +++ b/drivers/display/display_stm32_ltdc.c @@ -249,6 +249,13 @@ static int stm32_ltdc_read(const struct device *dev, const uint16_t x, return 0; } +static void *stm32_ltdc_get_framebuffer(const struct device *dev) +{ + struct display_stm32_ltdc_data *data = dev->data; + + return ((void *)data->front_buf); +} + static int stm32_ltdc_display_blanking_off(const struct device *dev) { const struct display_stm32_ltdc_config *config = dev->config; @@ -462,6 +469,7 @@ static int stm32_ltdc_pm_action(const struct device *dev, static const struct display_driver_api stm32_ltdc_display_api = { .write = stm32_ltdc_write, .read = stm32_ltdc_read, + .get_framebuffer = stm32_ltdc_get_framebuffer, .get_capabilities = stm32_ltdc_get_capabilities, .set_pixel_format = stm32_ltdc_set_pixel_format, .set_orientation = stm32_ltdc_set_orientation, From 45ebd390cfd632055f11a8ac5be0c40e0d333a0c Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Wed, 20 Nov 2024 17:25:30 +0800 Subject: [PATCH 002/261] arch: riscv: reg: include required header Include `zephyr/sys/util.h` for the `STRINGIFY()` macro. Signed-off-by: Yong Cong Sin --- include/zephyr/arch/riscv/reg.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/zephyr/arch/riscv/reg.h b/include/zephyr/arch/riscv/reg.h index 6d3b2d88b1755b..2c0650f0498f18 100644 --- a/include/zephyr/arch/riscv/reg.h +++ b/include/zephyr/arch/riscv/reg.h @@ -7,6 +7,8 @@ #ifndef ZEPHYR_INCLUDE_ZEPHYR_ARCH_RISCV_REG_H_ #define ZEPHYR_INCLUDE_ZEPHYR_ARCH_RISCV_REG_H_ +#include + #define reg_read(reg) \ ({ \ register unsigned long __rv; \ From c2802618df89b4f7b820b47ba6f0f024c8caa0a6 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 20 Nov 2024 09:35:42 +0200 Subject: [PATCH 003/261] tests: net: socket: tcp: Add min_flash to the test config Add minimum flash requirement to the tests. This will effectively exclude nrf5340dk/nrf5340/cpuapp/ns as it does not have enough flash for the application. Fixes #81608 Signed-off-by: Jukka Rissanen --- tests/net/socket/tcp/testcase.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/net/socket/tcp/testcase.yaml b/tests/net/socket/tcp/testcase.yaml index 1bf87a17e9e7ac..a7593ffcdd36b0 100644 --- a/tests/net/socket/tcp/testcase.yaml +++ b/tests/net/socket/tcp/testcase.yaml @@ -1,6 +1,7 @@ common: depends_on: netif min_ram: 32 + min_flash: 194 tags: - net - socket From ca46c7c816c0fd9e5b56b0f9f7cac067320b8540 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 18 Nov 2024 13:30:16 +0100 Subject: [PATCH 004/261] boards nrfbsim: Enable UART(E) peripherals for nrf54l15bsim The HW models now support this peripheral for this target. Let's enable it. Signed-off-by: Alberto Escolar Piedras --- .../nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp.dts | 21 ++++++++++++++----- .../nrf54l15bsim_nrf54l15_cpuapp.yaml | 1 - 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp.dts b/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp.dts index fbfe0f0dc65121..cc1de29bd8a7e8 100644 --- a/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp.dts +++ b/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp.dts @@ -8,6 +8,7 @@ #include #include +#include <../boards/nordic/nrf54l15dk/nrf54l15dk_nrf54l_05_10_15-pinctrl.dtsi> / { model = "Nordic NRF54L15 BSIM NRF54L15 Application"; @@ -15,6 +16,7 @@ chosen { zephyr,entropy = &rng; + zephyr,bt-c2h-uart = &uart20; zephyr,flash-controller = &rram_controller; zephyr,flash = &cpuapp_rram; }; @@ -28,19 +30,15 @@ /delete-node/ memory@2002f000; peripheral@50000000 { /delete-node/ spi@4a000; - /delete-node/ uart@4a000; /delete-node/ vpr@4c000; /delete-node/ mailbox@0; /delete-node/ interrupt-controller@f0000000; /delete-node/ i2c@c6000; /delete-node/ spi@c6000; - /delete-node/ uart@c6000; /delete-node/ i2c@c7000; /delete-node/ spi@c7000; - /delete-node/ uart@c7000; /delete-node/ i2c@c8000; /delete-node/ spi@c8000; - /delete-node/ uart@c8000; /delete-node/ pwm@d2000; /delete-node/ pwm@d3000; /delete-node/ pwm@d4000; @@ -51,7 +49,6 @@ /delete-node/ qdec@e1000; /delete-node/ i2c@104000; /delete-node/ spi@104000; - /delete-node/ uart@104000; /delete-node/ watchdog@108000; /delete-node/ watchdog@109000; }; @@ -86,6 +83,20 @@ }; }; +&uart20 { + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&uart20_default>; + pinctrl-1 = <&uart20_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&uart30 { + current-speed = <115200>; + pinctrl-0 = <&uart30_default>; + pinctrl-1 = <&uart30_sleep>; + pinctrl-names = "default", "sleep"; +}; &gpio0 { status = "okay"; diff --git a/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp.yaml b/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp.yaml index 6bbf4542660245..e09184de96d581 100644 --- a/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp.yaml +++ b/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp.yaml @@ -13,5 +13,4 @@ supported: testing: ignore_tags: - modem - - uart - bsim_skip_CI From 890f13426e8715a593b39a5c3c3f5d02704f6c69 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 18 Nov 2024 13:44:48 +0100 Subject: [PATCH 005/261] doc boards nrfbsim: Mention the UARTE as supported for nrf54l15 Include in the list of supported peripherals the UARTE for the simulated nrf54l15 Signed-off-by: Alberto Escolar Piedras --- boards/native/nrf_bsim/doc/nrf54l15bsim.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/boards/native/nrf_bsim/doc/nrf54l15bsim.rst b/boards/native/nrf_bsim/doc/nrf54l15bsim.rst index eaabaf1cc4de1b..ae8b29d2aecff4 100644 --- a/boards/native/nrf_bsim/doc/nrf54l15bsim.rst +++ b/boards/native/nrf_bsim/doc/nrf54l15bsim.rst @@ -52,6 +52,7 @@ This boards include models of some of the nRF54L15 SOC peripherals: * RTC (Real Time Counter) * TEMP (Temperature sensor) * TIMER +* UARTE (UART with Easy DMA) * UICR (User Information Configuration Registers) and will use the same drivers as the nrf54l15dk targets for these. From dd2f4117e3a0e327e60d6d6a2c9146a9d1d886a3 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 18 Nov 2024 15:56:03 +0100 Subject: [PATCH 006/261] tests uart_async_api: Enable in nrf54l15bsim//cpuapp Enable this test in the simulated nrf54l15 by providing an appropriate overlay. Signed-off-by: Alberto Escolar Piedras --- .../uart_async_api/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay | 3 +++ tests/drivers/uart/uart_async_api/testcase.yaml | 1 + 2 files changed, 4 insertions(+) create mode 100644 tests/drivers/uart/uart_async_api/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay diff --git a/tests/drivers/uart/uart_async_api/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay b/tests/drivers/uart/uart_async_api/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000000..10b8825014f97d --- /dev/null +++ b/tests/drivers/uart/uart_async_api/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay @@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include "nrf54l15dk_nrf54l15_cpuapp.overlay" diff --git a/tests/drivers/uart/uart_async_api/testcase.yaml b/tests/drivers/uart/uart_async_api/testcase.yaml index 15974269c3946a..24f7b3008ace4a 100644 --- a/tests/drivers/uart/uart_async_api/testcase.yaml +++ b/tests/drivers/uart/uart_async_api/testcase.yaml @@ -30,6 +30,7 @@ tests: - nrf52840dk/nrf52840 - nrf52_bsim - nrf5340bsim/nrf5340/cpuapp + - nrf54l15bsim/nrf54l15/cpuapp filter: CONFIG_SERIAL_SUPPORT_ASYNC harness: ztest harness_config: From eec736355c2245ce268696a8c5923e86e5f49774 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 18 Nov 2024 17:16:43 +0100 Subject: [PATCH 007/261] tests uart_mix_fifo_poll: Enable for nrf54l15bsim Enable this test in the simulated nrf54l15 and provide an appropriate overlay. Signed-off-by: Alberto Escolar Piedras --- .../boards/nrf54l15bsim_nrf54l15_cpuapp.overlay | 3 +++ tests/drivers/uart/uart_mix_fifo_poll/testcase.yaml | 1 + 2 files changed, 4 insertions(+) create mode 100644 tests/drivers/uart/uart_mix_fifo_poll/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000000..10b8825014f97d --- /dev/null +++ b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay @@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include "nrf54l15dk_nrf54l15_cpuapp.overlay" diff --git a/tests/drivers/uart/uart_mix_fifo_poll/testcase.yaml b/tests/drivers/uart/uart_mix_fifo_poll/testcase.yaml index 91470dc990be45..13f1d52d4d566c 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/testcase.yaml +++ b/tests/drivers/uart/uart_mix_fifo_poll/testcase.yaml @@ -10,6 +10,7 @@ common: - nrf5340dk/nrf5340/cpuapp - nrf5340bsim/nrf5340/cpuapp - nrf54l15dk/nrf54l15/cpuapp + - nrf54l15bsim/nrf54l15/cpuapp - nrf54h20dk/nrf54h20/cpuapp - nrf54h20dk/nrf54h20/cpurad - nrf52_bsim From 9c386cab935f65c2e700e6a89bf6d2e5bb48fd2d Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 18 Nov 2024 17:25:38 +0100 Subject: [PATCH 008/261] tests uart_pm: Enable for nrf54l15bsim Enable this test in the simulated nrf5340 and provide an appropriate overlay. Signed-off-by: Alberto Escolar Piedras --- .../uart/uart_pm/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay | 3 +++ tests/drivers/uart/uart_pm/testcase.yaml | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 tests/drivers/uart/uart_pm/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay diff --git a/tests/drivers/uart/uart_pm/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay b/tests/drivers/uart/uart_pm/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000000..10b8825014f97d --- /dev/null +++ b/tests/drivers/uart/uart_pm/boards/nrf54l15bsim_nrf54l15_cpuapp.overlay @@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include "nrf54l15dk_nrf54l15_cpuapp.overlay" diff --git a/tests/drivers/uart/uart_pm/testcase.yaml b/tests/drivers/uart/uart_pm/testcase.yaml index f9a7a8f902cf39..29c336441c611f 100644 --- a/tests/drivers/uart/uart_pm/testcase.yaml +++ b/tests/drivers/uart/uart_pm/testcase.yaml @@ -6,6 +6,7 @@ common: platform_allow: - nrf52840dk/nrf52840 - nrf54l15dk/nrf54l15/cpuapp + - nrf54l15bsim/nrf54l15/cpuapp - nrf54h20dk/nrf54h20/cpuapp - nrf52_bsim - nrf5340bsim/nrf5340/cpuapp @@ -29,6 +30,7 @@ tests: extra_args: DTC_OVERLAY_FILE="boards/nrf52840dk_nrf52840.overlay;nrf_rx_disable.overlay" platform_exclude: - nrf54l15dk/nrf54l15/cpuapp + - nrf54l15bsim/nrf54l15/cpuapp - nrf54h20dk/nrf54h20/cpuapp drivers.uart.pm.enhanced_poll: From 4558056f81fe7387e6c291e3321dc880f1858ee2 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 18 Nov 2024 17:28:03 +0100 Subject: [PATCH 009/261] tests/bsim: Also runtime test the UART drivers for the nrf54l15 To increase coverage. Note that we call twister separatedly for this target, due to the 54l15 overlays using UARTE20 which is indexed in simulation as "2", but as the nrf52833 does not have 3 instances. So "-uart2_loopback" is not a valid option for a 52833 executable. Signed-off-by: Alberto Escolar Piedras --- tests/bsim/ci.uart.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/bsim/ci.uart.sh b/tests/bsim/ci.uart.sh index 86c5282fa921cf..70d296d23dfa15 100755 --- a/tests/bsim/ci.uart.sh +++ b/tests/bsim/ci.uart.sh @@ -12,10 +12,16 @@ cd ${ZEPHYR_BASE} set -uex echo "UART: Single device tests" +echo " nRF52833 & 5340:" ${ZEPHYR_BASE}/scripts/twister -T tests/drivers/uart/ --force-color --inline-logs -v -M \ -p nrf52_bsim -p nrf5340bsim/nrf5340/cpuapp --fixture gpio_loopback \ -- -uart0_loopback -uart1_loopback +echo " nRF54L15:" +${ZEPHYR_BASE}/scripts/twister -T tests/drivers/uart/ --force-color --inline-logs -v -M \ + -p nrf54l15bsim/nrf54l15/cpuapp --fixture gpio_loopback \ + -- -uart2_loopback + echo "UART: Multi device tests" WORK_DIR=${ZEPHYR_BASE}/bsim_uart nice tests/bsim/drivers/uart/compile.sh RESULTS_FILE=${ZEPHYR_BASE}/bsim_out/bsim_results.uart.52.xml \ From 3063f18942d1e2f2511795ef39241d90bd2f8d98 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 19 Nov 2024 21:19:33 +0200 Subject: [PATCH 010/261] Bluetooth: Host: Remove unnecessary hci_driver.h includes None of these files actually use anything from the hci_driver.h header file. Signed-off-by: Johan Hedberg --- drivers/bluetooth/hci/h4_ifx_cyw43xxx.c | 1 - samples/bluetooth/hci_uart_3wire/src/main.c | 1 - samples/bluetooth/hci_uart_async/src/hci_uart_async.c | 1 - subsys/bluetooth/host/att.c | 1 - subsys/bluetooth/host/classic/l2cap_br.c | 1 - subsys/bluetooth/host/classic/rfcomm.c | 1 - subsys/bluetooth/host/gatt.c | 1 - subsys/bluetooth/host/id.c | 1 - subsys/bluetooth/host/l2cap.c | 1 - .../include/zephyr/drivers/bluetooth/hci_driver.h | 11 ----------- 10 files changed, 20 deletions(-) delete mode 100644 tests/bluetooth/host/conn/mocks/zephyr/include/zephyr/drivers/bluetooth/hci_driver.h diff --git a/drivers/bluetooth/hci/h4_ifx_cyw43xxx.c b/drivers/bluetooth/hci/h4_ifx_cyw43xxx.c index 6c3b132ed30ecd..ae98a8e51e2d6d 100644 --- a/drivers/bluetooth/hci/h4_ifx_cyw43xxx.c +++ b/drivers/bluetooth/hci/h4_ifx_cyw43xxx.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include diff --git a/samples/bluetooth/hci_uart_3wire/src/main.c b/samples/bluetooth/hci_uart_3wire/src/main.c index ce0e993dab04a1..5454b0cd9c7c60 100644 --- a/samples/bluetooth/hci_uart_3wire/src/main.c +++ b/samples/bluetooth/hci_uart_3wire/src/main.c @@ -28,7 +28,6 @@ #include #include #include -#include #define LOG_MODULE_NAME hci_uart_3wire LOG_MODULE_REGISTER(LOG_MODULE_NAME); diff --git a/samples/bluetooth/hci_uart_async/src/hci_uart_async.c b/samples/bluetooth/hci_uart_async/src/hci_uart_async.c index 011d9206622468..936c47f76d7f36 100644 --- a/samples/bluetooth/hci_uart_async/src/hci_uart_async.c +++ b/samples/bluetooth/hci_uart_async/src/hci_uart_async.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index c9872aebc67896..26b3c3f542b6c7 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -19,7 +19,6 @@ #include #include #include -#include #include "common/bt_str.h" diff --git a/subsys/bluetooth/host/classic/l2cap_br.c b/subsys/bluetooth/host/classic/l2cap_br.c index d1e558a7b3d664..0ebfdce8560b0b 100644 --- a/subsys/bluetooth/host/classic/l2cap_br.c +++ b/subsys/bluetooth/host/classic/l2cap_br.c @@ -17,7 +17,6 @@ #include #include #include -#include #include "host/buf_view.h" #include "host/hci_core.h" diff --git a/subsys/bluetooth/host/classic/rfcomm.c b/subsys/bluetooth/host/classic/rfcomm.c index f8742bff3678a8..4e088209cd6b24 100644 --- a/subsys/bluetooth/host/classic/rfcomm.c +++ b/subsys/bluetooth/host/classic/rfcomm.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index 926337dd76133c..f03cbcec3950ea 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -37,7 +37,6 @@ #include #include #include -#include #include "common/bt_str.h" diff --git a/subsys/bluetooth/host/id.c b/subsys/bluetooth/host/id.c index 3a6fdf3ee28aa1..67f691dfa799b5 100644 --- a/subsys/bluetooth/host/id.c +++ b/subsys/bluetooth/host/id.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include "hci_core.h" diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index d280db5363cd07..8830d05d58ab38 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -23,7 +23,6 @@ #include #include #include -#include #define LOG_DBG_ENABLED IS_ENABLED(CONFIG_BT_L2CAP_LOG_LEVEL_DBG) diff --git a/tests/bluetooth/host/conn/mocks/zephyr/include/zephyr/drivers/bluetooth/hci_driver.h b/tests/bluetooth/host/conn/mocks/zephyr/include/zephyr/drivers/bluetooth/hci_driver.h deleted file mode 100644 index 68285925d81b72..00000000000000 --- a/tests/bluetooth/host/conn/mocks/zephyr/include/zephyr/drivers/bluetooth/hci_driver.h +++ /dev/null @@ -1,11 +0,0 @@ -/* Stub for Bluetooth HCI driver API used to hide real hci_driver.h. */ - -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_HCI_DRIVER_H_ -#define ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_HCI_DRIVER_H_ - -#endif /* ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_HCI_DRIVER_H_ */ From 30d1d0e526d3763044d289dde2549bf0671d9fbd Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 19 Nov 2024 21:20:10 +0200 Subject: [PATCH 011/261] Bluetooth: Host: Remove deprecated HCI driver API Remove the deprecated HCI driver API which was provided by the hci_driver.h header file. The deprecation happened in Zephyr 3.7, so the API can now be removed for Zephyr 4.1. Signed-off-by: Johan Hedberg --- .../bluetooth/api/hci_drivers.rst | 2 +- include/zephyr/drivers/bluetooth/hci_driver.h | 242 ------------------ subsys/bluetooth/controller/hci/hci.c | 2 +- subsys/bluetooth/host/conn.c | 2 +- subsys/bluetooth/host/hci_common.c | 2 +- subsys/bluetooth/host/hci_core.c | 114 ++------- subsys/bluetooth/host/hci_core.h | 7 - subsys/bluetooth/host/hci_ecc.c | 20 -- subsys/bluetooth/host/hci_raw.c | 70 +---- subsys/bluetooth/host/hci_raw_internal.h | 7 - subsys/usb/device/class/bluetooth.c | 2 +- subsys/usb/device_next/class/bt_hci.c | 2 +- 12 files changed, 43 insertions(+), 429 deletions(-) delete mode 100644 include/zephyr/drivers/bluetooth/hci_driver.h diff --git a/doc/connectivity/bluetooth/api/hci_drivers.rst b/doc/connectivity/bluetooth/api/hci_drivers.rst index 9b01981d67a0d7..fd70691f2a89bd 100644 --- a/doc/connectivity/bluetooth/api/hci_drivers.rst +++ b/doc/connectivity/bluetooth/api/hci_drivers.rst @@ -8,4 +8,4 @@ HCI Drivers API Reference ************* -.. doxygengroup:: bt_hci_driver +.. doxygengroup:: bt_hci_api diff --git a/include/zephyr/drivers/bluetooth/hci_driver.h b/include/zephyr/drivers/bluetooth/hci_driver.h deleted file mode 100644 index c2eae9d90cb93d..00000000000000 --- a/include/zephyr/drivers/bluetooth/hci_driver.h +++ /dev/null @@ -1,242 +0,0 @@ -/** @file - * @brief Bluetooth HCI driver API. - */ - -/* - * Copyright (c) 2015-2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_HCI_DRIVER_H_ -#define ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_HCI_DRIVER_H_ - -/** - * @brief HCI drivers - * - * @deprecated This is the old HCI driver API. Drivers should use @ref bt_hci_api instead. - * - * @defgroup bt_hci_driver HCI drivers - * @ingroup bluetooth - * @{ - */ - -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -enum { - /* The host should never send HCI_Reset */ - BT_QUIRK_NO_RESET = BIT(0), - /* The controller does not auto-initiate a DLE procedure when the - * initial connection data length parameters are not equal to the - * default data length parameters. Therefore the host should initiate - * the DLE procedure after connection establishment. */ - BT_QUIRK_NO_AUTO_DLE = BIT(1), -}; - -/** - * @brief Receive data from the controller/HCI driver. - * - * This is the main function through which the HCI driver provides the - * host with data from the controller. The buffer needs to have its type - * set with the help of bt_buf_set_type() before calling this API. - * - * @param buf Network buffer containing data from the controller. - * - * @return 0 on success or negative error number on failure. - * - * @deprecated Use the new HCI driver interface instead: @ref bt_hci_api - */ -__deprecated int bt_recv(struct net_buf *buf); - -/** Possible values for the 'bus' member of the bt_hci_driver struct */ -enum bt_hci_driver_bus { - BT_HCI_DRIVER_BUS_VIRTUAL = 0, - BT_HCI_DRIVER_BUS_USB = 1, - BT_HCI_DRIVER_BUS_PCCARD = 2, - BT_HCI_DRIVER_BUS_UART = 3, - BT_HCI_DRIVER_BUS_RS232 = 4, - BT_HCI_DRIVER_BUS_PCI = 5, - BT_HCI_DRIVER_BUS_SDIO = 6, - BT_HCI_DRIVER_BUS_SPI = 7, - BT_HCI_DRIVER_BUS_I2C = 8, - BT_HCI_DRIVER_BUS_IPM = 9, -}; - -#if defined(CONFIG_BT_HCI_SETUP) || defined(__DOXYGEN__) -struct bt_hci_setup_params { - /** The public identity address to give to the controller. This field is used when the - * driver selects @kconfig{CONFIG_BT_HCI_SET_PUBLIC_ADDR} to indicate that it supports - * setting the controller's public address. - */ - bt_addr_t public_addr; -}; -#endif - -/** - * @brief Abstraction which represents the HCI transport to the controller. - * - * This struct is used to represent the HCI transport to the Bluetooth - * controller. - */ -struct bt_hci_driver { - /** Name of the driver */ - const char *name; - - /** Bus of the transport (BT_HCI_DRIVER_BUS_*) */ - enum bt_hci_driver_bus bus; - - /** Specific controller quirks. These are set by the HCI driver - * and acted upon by the host. They can either be statically - * set at buildtime, or set at runtime before the HCI driver's - * open() callback returns. - */ - uint32_t quirks; - - /** - * @brief Open the HCI transport. - * - * Opens the HCI transport for operation. This function must not - * return until the transport is ready for operation, meaning it - * is safe to start calling the send() handler. - * - * @return 0 on success or negative error number on failure. - */ - int (*open)(void); - - /** - * @brief Close the HCI transport. - * - * Closes the HCI transport. This function must not return until the - * transport is closed. - * - * @return 0 on success or negative error number on failure. - */ - int (*close)(void); - - /** - * @brief Send HCI buffer to controller. - * - * Send an HCI command or ACL data to the controller. The exact - * type of the data can be checked with the help of bt_buf_get_type(). - * - * @note This function must only be called from a cooperative thread. - * - * @param buf Buffer containing data to be sent to the controller. - * - * @return 0 on success or negative error number on failure. - */ - int (*send)(struct net_buf *buf); - -#if defined(CONFIG_BT_HCI_SETUP) || defined(__DOXYGEN__) - /** - * @brief HCI vendor-specific setup - * - * Executes vendor-specific commands sequence to initialize - * BT Controller before BT Host executes Reset sequence. - * - * @note @kconfig{CONFIG_BT_HCI_SETUP} must be selected for this - * field to be available. - * - * @return 0 on success or negative error number on failure. - */ - int (*setup)(const struct bt_hci_setup_params *params); -#endif /* defined(CONFIG_BT_HCI_SETUP) || defined(__DOXYGEN__)*/ -}; - -/** - * @brief Register a new HCI driver to the Bluetooth stack. - * - * This needs to be called before any application code runs. The bt_enable() - * API will fail if there is no driver registered. - * - * @param drv A bt_hci_driver struct representing the driver. - * - * @return 0 on success or negative error number on failure. - * - * @deprecated Use the new HCI driver interface instead: @ref bt_hci_api - */ -__deprecated int bt_hci_driver_register(const struct bt_hci_driver *drv); - -/** - * @brief Setup the HCI transport, which usually means to reset the - * Bluetooth IC. - * - * @note A weak version of this function is included in the H4 driver, so - * defining it is optional per board. - * - * @param dev The device structure for the bus connecting to the IC - * - * @return 0 on success, negative error value on failure - */ -int bt_hci_transport_setup(const struct device *dev); - -/** - * @brief Teardown the HCI transport. - * - * @note A weak version of this function is included in the IPC driver, so - * defining it is optional. NRF5340 includes support to put network core - * in reset state. - * - * @param dev The device structure for the bus connecting to the IC - * - * @return 0 on success, negative error value on failure - */ -int bt_hci_transport_teardown(const struct device *dev); - -/** Allocate an HCI event buffer. - * - * This function allocates a new buffer for an HCI event. It is given the - * event code and the total length of the parameters. Upon successful return - * the buffer is ready to have the parameters encoded into it. - * - * @param evt Event OpCode. - * @param len Length of event parameters. - * - * @return Newly allocated buffer. - */ -struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len); - -/** Allocate an HCI Command Complete event buffer. - * - * This function allocates a new buffer for HCI Command Complete event. - * It is given the OpCode (encoded e.g. using the BT_OP macro) and the total - * length of the parameters. Upon successful return the buffer is ready to have - * the parameters encoded into it. - * - * @param op Command OpCode. - * @param plen Length of command parameters. - * - * @return Newly allocated buffer. - */ -struct net_buf *bt_hci_cmd_complete_create(uint16_t op, uint8_t plen); - -/** Allocate an HCI Command Status event buffer. - * - * This function allocates a new buffer for HCI Command Status event. - * It is given the OpCode (encoded e.g. using the BT_OP macro) and the status - * code. Upon successful return the buffer is ready to have the parameters - * encoded into it. - * - * @param op Command OpCode. - * @param status Status code. - * - * @return Newly allocated buffer. - */ -struct net_buf *bt_hci_cmd_status_create(uint16_t op, uint8_t status); - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ - -#endif /* ZEPHYR_INCLUDE_DRIVERS_BLUETOOTH_HCI_DRIVER_H_ */ diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 8fffa01a3feafb..059b94d933d767 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index f77710b3e08d05..ec5cdeb3f67e78 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include "common/assert.h" diff --git a/subsys/bluetooth/host/hci_common.c b/subsys/bluetooth/host/hci_common.c index a050b4915e979a..1f382075d05f07 100644 --- a/subsys/bluetooth/host/hci_common.c +++ b/subsys/bluetooth/host/hci_common.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include "common/assert.h" struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len) diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 88eac980f0103d..a2f72d3a70773f 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -30,11 +30,7 @@ #include #include #include -#if DT_HAS_CHOSEN(zephyr_bt_hci) #include -#else -#include -#endif #include "common/bt_str.h" #include "common/assert.h" @@ -70,9 +66,20 @@ #include LOG_MODULE_REGISTER(bt_hci_core); -#define BT_HCI_DEV DT_CHOSEN(zephyr_bt_hci) -#define BT_HCI_BUS BT_DT_HCI_BUS_GET(BT_HCI_DEV) -#define BT_HCI_NAME BT_DT_HCI_NAME_GET(BT_HCI_DEV) +#if DT_HAS_CHOSEN(zephyr_bt_hci) +#define BT_HCI_NODE DT_CHOSEN(zephyr_bt_hci) +#define BT_HCI_DEV DEVICE_DT_GET(BT_HCI_NODE) +#define BT_HCI_BUS BT_DT_HCI_BUS_GET(BT_HCI_NODE) +#define BT_HCI_NAME BT_DT_HCI_NAME_GET(BT_HCI_NODE) +#define BT_HCI_QUIRKS BT_DT_HCI_QUIRKS_GET(BT_HCI_NODE) +#else +/* The zephyr,bt-hci chosen property is mandatory, except for unit tests */ +BUILD_ASSERT(IS_ENABLED(CONFIG_ZTEST), "Missing DT chosen property for HCI"); +#define BT_HCI_DEV NULL +#define BT_HCI_BUS 0 +#define BT_HCI_NAME "" +#define BT_HCI_QUIRKS 0 +#endif void bt_tx_irq_raise(void); @@ -96,9 +103,7 @@ struct bt_dev bt_dev = { #if defined(CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC) .appearance = CONFIG_BT_DEVICE_APPEARANCE, #endif -#if DT_HAS_CHOSEN(zephyr_bt_hci) - .hci = DEVICE_DT_GET(BT_HCI_DEV), -#endif + .hci = BT_HCI_DEV, }; static bt_ready_cb_t ready_cb; @@ -126,28 +131,16 @@ static struct cmd_data cmd_data[CONFIG_BT_BUF_CMD_TX_COUNT]; #define cmd(buf) (&cmd_data[net_buf_id(buf)]) #define acl(buf) ((struct acl_data *)net_buf_user_data(buf)) -#if DT_HAS_CHOSEN(zephyr_bt_hci) static bool drv_quirk_no_reset(void) { - return ((BT_DT_HCI_QUIRKS_GET(DT_CHOSEN(zephyr_bt_hci)) & BT_HCI_QUIRK_NO_RESET) != 0); + return ((BT_HCI_QUIRKS & BT_HCI_QUIRK_NO_RESET) != 0); } bool bt_drv_quirk_no_auto_dle(void) { - return ((BT_DT_HCI_QUIRKS_GET(DT_CHOSEN(zephyr_bt_hci)) & BT_HCI_QUIRK_NO_AUTO_DLE) != 0); -} -#else -static bool drv_quirk_no_reset(void) -{ - return ((bt_dev.drv->quirks & BT_QUIRK_NO_RESET) != 0); + return ((BT_HCI_QUIRKS & BT_HCI_QUIRK_NO_AUTO_DLE) != 0); } -bool bt_drv_quirk_no_auto_dle(void) -{ - return ((bt_dev.drv->quirks & BT_QUIRK_NO_AUTO_DLE) != 0); -} -#endif - void bt_hci_cmd_state_set_init(struct net_buf *buf, struct bt_hci_cmd_state_set *state, atomic_t *target, int bit, bool val) @@ -4008,19 +4001,10 @@ static int hci_init(void) } #endif /* defined(CONFIG_BT_HCI_SET_PUBLIC_ADDR) */ -#if DT_HAS_CHOSEN(zephyr_bt_hci) err = bt_hci_setup(bt_dev.hci, &setup_params); if (err && err != -ENOSYS) { return err; } -#else - if (bt_dev.drv->setup) { - err = bt_dev.drv->setup(&setup_params); - if (err) { - return err; - } - } -#endif #endif /* defined(CONFIG_BT_HCI_SETUP) */ err = common_init(); @@ -4075,11 +4059,7 @@ int bt_send(struct net_buf *buf) return bt_hci_ecc_send(buf); } -#if DT_HAS_CHOSEN(zephyr_bt_hci) return bt_hci_send(bt_dev.hci, buf); -#else - return bt_dev.drv->send(buf); -#endif } static const struct event_handler prio_events[] = { @@ -4181,14 +4161,9 @@ static int bt_recv_unsafe(struct net_buf *buf) } } -#if DT_HAS_CHOSEN(zephyr_bt_hci) int bt_hci_recv(const struct device *dev, struct net_buf *buf) { ARG_UNUSED(dev); -#else -int bt_recv(struct net_buf *buf) -{ -#endif int err; k_sched_lock(); @@ -4198,29 +4173,6 @@ int bt_recv(struct net_buf *buf) return err; } -/* Old-style HCI driver registration */ -#if !DT_HAS_CHOSEN(zephyr_bt_hci) -int bt_hci_driver_register(const struct bt_hci_driver *drv) -{ - if (bt_dev.drv) { - return -EALREADY; - } - - if (!drv->open || !drv->send) { - return -EINVAL; - } - - bt_dev.drv = drv; - - LOG_DBG("Registered %s", drv->name ? drv->name : ""); - - bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, drv->bus, - BT_ADDR_ANY, drv->name ? drv->name : "bt0"); - - return 0; -} -#endif /* !DT_HAS_CHOSEN(zephyr_bt_hci) */ - void bt_finalize_init(void) { atomic_set_bit(bt_dev.flags, BT_DEV_READY); @@ -4349,19 +4301,17 @@ int bt_enable(bt_ready_cb_t cb) { int err; -#if DT_HAS_CHOSEN(zephyr_bt_hci) + if (IS_ENABLED(CONFIG_ZTEST) && bt_dev.hci == NULL) { + LOG_ERR("No DT chosen property for HCI"); + return -ENODEV; + } + if (!device_is_ready(bt_dev.hci)) { LOG_ERR("HCI driver is not ready"); return -ENODEV; } bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, BT_HCI_BUS, BT_ADDR_ANY, BT_HCI_NAME); -#else /* !DT_HAS_CHONSEN(zephyr_bt_hci) */ - if (!bt_dev.drv) { - LOG_ERR("No HCI driver registered"); - return -ENODEV; - } -#endif atomic_clear_bit(bt_dev.flags, BT_DEV_DISABLE); @@ -4403,11 +4353,7 @@ int bt_enable(bt_ready_cb_t cb) k_thread_name_set(&bt_workq.thread, "BT RX WQ"); #endif -#if DT_HAS_CHOSEN(zephyr_bt_hci) err = bt_hci_open(bt_dev.hci, bt_hci_recv); -#else - err = bt_dev.drv->open(); -#endif if (err) { LOG_ERR("HCI driver open failed (%d)", err); return err; @@ -4427,17 +4373,6 @@ int bt_disable(void) { int err; -#if !DT_HAS_CHOSEN(zephyr_bt_hci) - if (!bt_dev.drv) { - LOG_ERR("No HCI driver registered"); - return -ENODEV; - } - - if (!bt_dev.drv->close) { - return -ENOTSUP; - } -#endif - if (atomic_test_and_set_bit(bt_dev.flags, BT_DEV_DISABLE)) { return -EALREADY; } @@ -4465,16 +4400,13 @@ int bt_disable(void) disconnected_handles_reset(); #endif /* CONFIG_BT_CONN */ -#if DT_HAS_CHOSEN(zephyr_bt_hci) err = bt_hci_close(bt_dev.hci); if (err == -ENOSYS) { atomic_clear_bit(bt_dev.flags, BT_DEV_DISABLE); atomic_set_bit(bt_dev.flags, BT_DEV_READY); return -ENOTSUP; } -#else - err = bt_dev.drv->close(); -#endif + if (err) { LOG_ERR("HCI driver close failed (%d)", err); diff --git a/subsys/bluetooth/host/hci_core.h b/subsys/bluetooth/host/hci_core.h index fb7a69539fd7bb..ac2bf9d2970212 100644 --- a/subsys/bluetooth/host/hci_core.h +++ b/subsys/bluetooth/host/hci_core.h @@ -403,12 +403,7 @@ struct bt_dev { /* Queue for outgoing HCI commands */ struct k_fifo cmd_tx_queue; -#if DT_HAS_CHOSEN(zephyr_bt_hci) const struct device *hci; -#else - /* Registered HCI driver */ - const struct bt_hci_driver *drv; -#endif #if defined(CONFIG_BT_PRIVACY) /* Local Identity Resolving Key */ @@ -443,9 +438,7 @@ extern sys_slist_t bt_auth_info_cbs; enum bt_security_err bt_security_err_get(uint8_t hci_err); #endif /* CONFIG_BT_SMP || CONFIG_BT_CLASSIC */ -#if DT_HAS_CHOSEN(zephyr_bt_hci) int bt_hci_recv(const struct device *dev, struct net_buf *buf); -#endif /* Data type to store state related with command to be updated * when command completes successfully. diff --git a/subsys/bluetooth/host/hci_ecc.c b/subsys/bluetooth/host/hci_ecc.c index 39fc7ef47a2f5c..017ed6b354ad56 100644 --- a/subsys/bluetooth/host/hci_ecc.c +++ b/subsys/bluetooth/host/hci_ecc.c @@ -27,11 +27,7 @@ #include #include #include -#if DT_HAS_CHOSEN(zephyr_bt_hci) #include -#else -#include -#endif #include "common/bt_str.h" @@ -102,11 +98,7 @@ static void send_cmd_status(uint16_t opcode, uint8_t status) evt->opcode = sys_cpu_to_le16(opcode); evt->status = status; -#if DT_HAS_CHOSEN(zephyr_bt_hci) bt_hci_recv(bt_dev.hci, buf); -#else - bt_recv(buf); -#endif } #if defined(CONFIG_BT_USE_PSA_API) @@ -217,11 +209,7 @@ static void emulate_le_p256_public_key_cmd(void) atomic_clear_bit(flags, PENDING_PUB_KEY); -#if DT_HAS_CHOSEN(zephyr_bt_hci) bt_hci_recv(bt_dev.hci, buf); -#else - bt_recv(buf); -#endif } static void emulate_le_generate_dhkey(void) @@ -303,11 +291,7 @@ static void emulate_le_generate_dhkey(void) atomic_clear_bit(flags, PENDING_DHKEY); -#if DT_HAS_CHOSEN(zephyr_bt_hci) bt_hci_recv(bt_dev.hci, buf); -#else - bt_recv(buf); -#endif } static void ecc_process(struct k_work *work) @@ -432,11 +416,7 @@ int bt_hci_ecc_send(struct net_buf *buf) } } -#if DT_HAS_CHOSEN(zephyr_bt_hci) return bt_hci_send(bt_dev.hci, buf); -#else - return bt_dev.drv->send(buf); -#endif } void bt_hci_ecc_supported_commands(uint8_t *supported_commands) diff --git a/subsys/bluetooth/host/hci_raw.c b/subsys/bluetooth/host/hci_raw.c index 984c8607ee6539..0f0b93e99e686a 100644 --- a/subsys/bluetooth/host/hci_raw.c +++ b/subsys/bluetooth/host/hci_raw.c @@ -11,11 +11,7 @@ #include #include -#if DT_HAS_CHOSEN(zephyr_bt_hci) #include -#else -#include -#endif #include #include #include @@ -53,40 +49,25 @@ NET_BUF_POOL_FIXED_DEFINE(hci_iso_pool, CONFIG_BT_ISO_TX_BUF_COUNT, sizeof(struct bt_buf_data), NULL); #endif /* CONFIG_BT_ISO */ -#define BT_HCI_DEV DT_CHOSEN(zephyr_bt_hci) -#define BT_HCI_BUS BT_DT_HCI_BUS_GET(BT_HCI_DEV) -#define BT_HCI_NAME BT_DT_HCI_NAME_GET(BT_HCI_DEV) - -struct bt_dev_raw bt_dev = { #if DT_HAS_CHOSEN(zephyr_bt_hci) - .hci = DEVICE_DT_GET(BT_HCI_DEV), +#define BT_HCI_NODE DT_CHOSEN(zephyr_bt_hci) +#define BT_HCI_DEV DEVICE_DT_GET(BT_HCI_NODE) +#define BT_HCI_BUS BT_DT_HCI_BUS_GET(BT_HCI_NODE) +#define BT_HCI_NAME BT_DT_HCI_NAME_GET(BT_HCI_NODE) +#else +/* The zephyr,bt-hci chosen property is mandatory, except for unit tests */ +BUILD_ASSERT(IS_ENABLED(CONFIG_ZTEST), "Missing DT chosen property for HCI"); +#define BT_HCI_DEV NULL +#define BT_HCI_BUS 0 +#define BT_HCI_NAME "" #endif + +struct bt_dev_raw bt_dev = { + .hci = BT_HCI_DEV, }; struct bt_hci_raw_cmd_ext *cmd_ext; static size_t cmd_ext_size; -#if !DT_HAS_CHOSEN(zephyr_bt_hci) -int bt_hci_driver_register(const struct bt_hci_driver *drv) -{ - if (bt_dev.drv) { - return -EALREADY; - } - - if (!drv->open || !drv->send) { - return -EINVAL; - } - - bt_dev.drv = drv; - - LOG_DBG("Registered %s", drv->name ? drv->name : ""); - - bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, drv->bus, - BT_ADDR_ANY, drv->name ? drv->name : "bt0"); - - return 0; -} -#endif - struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout) { struct net_buf *buf; @@ -191,14 +172,10 @@ struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeou return bt_buf_get_rx(BT_BUF_EVT, timeout); } -#if DT_HAS_CHOSEN(zephyr_bt_hci) int bt_hci_recv(const struct device *dev, struct net_buf *buf) { ARG_UNUSED(dev); -#else -int bt_recv(struct net_buf *buf) -{ -#endif + LOG_DBG("buf %p len %u", buf, buf->len); bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len); @@ -243,11 +220,7 @@ static void bt_cmd_complete_ext(uint16_t op, uint8_t status) cc = net_buf_add(buf, sizeof(*cc)); cc->status = status; -#if DT_HAS_CHOSEN(zephyr_bt_hci) bt_hci_recv(bt_dev.hci, buf); -#else - bt_recv(buf); -#endif } static uint8_t bt_send_ext(struct net_buf *buf) @@ -327,11 +300,7 @@ int bt_send(struct net_buf *buf) return bt_hci_ecc_send(buf); } -#if DT_HAS_CHOSEN(zephyr_bt_hci) return bt_hci_send(bt_dev.hci, buf); -#else - return bt_dev.drv->send(buf); -#endif } int bt_hci_raw_set_mode(uint8_t mode) @@ -375,7 +344,6 @@ int bt_enable_raw(struct k_fifo *rx_queue) raw_rx = rx_queue; -#if DT_HAS_CHOSEN(zephyr_bt_hci) if (!device_is_ready(bt_dev.hci)) { LOG_ERR("HCI driver is not ready"); return -ENODEV; @@ -384,16 +352,6 @@ int bt_enable_raw(struct k_fifo *rx_queue) bt_monitor_new_index(BT_MONITOR_TYPE_PRIMARY, BT_HCI_BUS, BT_ADDR_ANY, BT_HCI_NAME); err = bt_hci_open(bt_dev.hci, bt_hci_recv); -#else - const struct bt_hci_driver *drv = bt_dev.drv; - - if (!drv) { - LOG_ERR("No HCI driver registered"); - return -ENODEV; - } - - err = drv->open(); -#endif if (err) { LOG_ERR("HCI driver open failed (%d)", err); return err; diff --git a/subsys/bluetooth/host/hci_raw_internal.h b/subsys/bluetooth/host/hci_raw_internal.h index 6f1d711eedfcc9..d652cc0ceabcac 100644 --- a/subsys/bluetooth/host/hci_raw_internal.h +++ b/subsys/bluetooth/host/hci_raw_internal.h @@ -14,17 +14,10 @@ extern "C" { #endif struct bt_dev_raw { -#if DT_HAS_CHOSEN(zephyr_bt_hci) const struct device *hci; -#else - /* Registered HCI driver */ - const struct bt_hci_driver *drv; -#endif }; -#if DT_HAS_CHOSEN(zephyr_bt_hci) int bt_hci_recv(const struct device *dev, struct net_buf *buf); -#endif extern struct bt_dev_raw bt_dev; diff --git a/subsys/usb/device/class/bluetooth.c b/subsys/usb/device/class/bluetooth.c index 942a1076156823..8acd749d8195db 100644 --- a/subsys/usb/device/class/bluetooth.c +++ b/subsys/usb/device/class/bluetooth.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/usb/device_next/class/bt_hci.c b/subsys/usb/device_next/class/bt_hci.c index 52eddc4e25b617..baca59db2b8c60 100644 --- a/subsys/usb/device_next/class/bt_hci.c +++ b/subsys/usb/device_next/class/bt_hci.c @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include From da713a2b86c00b1d3167e35a75debf16db5d0931 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 21 Nov 2024 23:03:22 +0200 Subject: [PATCH 012/261] doc: release-notes-4.1: Mention removal of deprecated HCI API Mention the removed deprecated Bluetooth HCI driver API. Signed-off-by: Johan Hedberg --- doc/releases/release-notes-4.1.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/releases/release-notes-4.1.rst b/doc/releases/release-notes-4.1.rst index dff3f100c2c51d..b19ad21b0e7a46 100644 --- a/doc/releases/release-notes-4.1.rst +++ b/doc/releases/release-notes-4.1.rst @@ -27,6 +27,9 @@ API Changes Removed APIs in this release ============================ + * The deprecated Bluetooth HCI driver API has been removed. It has been replaced by a + :c:group:`new API` that follows the normal Zephyr driver model. + Deprecated in this release ========================== From 932e8708b194500a7468ab9d206861eeaaccb3f7 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Fri, 22 Nov 2024 07:10:17 -0500 Subject: [PATCH 013/261] tests: posix: single_process: correct typo and filter What looks to be a copy-paste typo was not caught in code review. Change .rwlocks to nothing and move the filter to the common area. Signed-off-by: Chris Friedt --- tests/posix/single_process/testcase.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/posix/single_process/testcase.yaml b/tests/posix/single_process/testcase.yaml index a8f8a54c1406c9..ce226e9dc9daa2 100644 --- a/tests/posix/single_process/testcase.yaml +++ b/tests/posix/single_process/testcase.yaml @@ -7,10 +7,10 @@ common: platform_key: - arch - simulation + min_flash: 64 + min_ram: 32 tests: - portability.single_process.rwlocks: - min_flash: 64 - min_ram: 32 + portability.single_process: {} portability.posix.single_process.minimal: extra_configs: - CONFIG_MINIMAL_LIBC=y From ae5609aef246811728bf7a1c973e8663e4ae85a3 Mon Sep 17 00:00:00 2001 From: Andrej Butok Date: Wed, 20 Nov 2024 12:11:00 +0100 Subject: [PATCH 014/261] samples: smp_svr: Move bluetooth tag to bt_tests Move "bluetooth" tag and harness from the common section of the smp_svr sample.yaml file to "bluetooth" specific test cases. Signed-off-by: Andrej Butok --- samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml b/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml index 058a5c581e87b8..a4342cab66ed46 100644 --- a/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml +++ b/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml @@ -3,10 +3,10 @@ sample: name: smp svr common: sysbuild: true - harness: bluetooth - tags: bluetooth tests: sample.mcumgr.smp_svr.bt: + harness: bluetooth + tags: bluetooth extra_args: EXTRA_CONF_FILE="overlay-bt.conf" platform_allow: - nrf52dk/nrf52832 @@ -17,6 +17,8 @@ tests: - nrf52dk/nrf52832 - nrf52840dk/nrf52840 sample.mcumgr.smp_svr.bt_static_svc: + harness: bluetooth + tags: bluetooth extra_args: EXTRA_CONF_FILE="overlay-bt.conf" extra_configs: - CONFIG_MCUMGR_TRANSPORT_BT_DYNAMIC_SVC_REGISTRATION=n From 50f23500b8c62a7fca4d35f0b4ec9434ceab5fed Mon Sep 17 00:00:00 2001 From: Chen Xingyu Date: Wed, 20 Nov 2024 10:37:50 +0800 Subject: [PATCH 015/261] net: Fix warning of `size_t` formatting with `%.*s` This addresses the following warning building with `CONFIG_64BIT=y`: error: field precision specifier '.*' expects argument of type 'int', but argument X has type 'size_t' {aka 'long unsigned int'} Signed-off-by: Chen Xingyu --- subsys/net/lib/dns/resolve.c | 4 ++-- subsys/net/lib/wifi_credentials/wifi_credentials_shell.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/subsys/net/lib/dns/resolve.c b/subsys/net/lib/dns/resolve.c index 5b9402768da316..0e28439e5ca8bb 100644 --- a/subsys/net/lib/dns/resolve.c +++ b/subsys/net/lib/dns/resolve.c @@ -424,7 +424,7 @@ static int dns_resolve_init_locked(struct dns_resolve_context *ctx, if (!ret) { if (servers[i] != NULL && servers[i][0] != '\0') { NET_DBG("Invalid server address %.*s", - server_len, servers[i]); + (int)server_len, servers[i]); } continue; @@ -432,7 +432,7 @@ static int dns_resolve_init_locked(struct dns_resolve_context *ctx, dns_postprocess_server(ctx, idx); - NET_DBG("[%d] %.*s%s%s%s%s", i, server_len, servers[i], + NET_DBG("[%d] %.*s%s%s%s%s", i, (int)server_len, servers[i], IS_ENABLED(CONFIG_MDNS_RESOLVER) ? (ctx->servers[i].is_mdns ? " mDNS" : "") : "", IS_ENABLED(CONFIG_LLMNR_RESOLVER) ? diff --git a/subsys/net/lib/wifi_credentials/wifi_credentials_shell.c b/subsys/net/lib/wifi_credentials/wifi_credentials_shell.c index 33731315f368d9..c9652ba390cb57 100644 --- a/subsys/net/lib/wifi_credentials/wifi_credentials_shell.c +++ b/subsys/net/lib/wifi_credentials/wifi_credentials_shell.c @@ -34,20 +34,20 @@ static void print_network_info(void *cb_arg, const char *ssid, size_t ssid_len) shell_error(sh, "An error occurred when trying to load credentials for network \"%.*s\"" ". err: %d", - ssid_len, ssid, ret); + (int)ssid_len, ssid, ret); return; } shell_fprintf(sh, SHELL_VT100_COLOR_DEFAULT, - " network ssid: \"%.*s\", ssid_len: %d, type: %s", ssid_len, ssid, ssid_len, - wifi_security_txt(creds.header.type)); + " network ssid: \"%.*s\", ssid_len: %d, type: %s", (int)ssid_len, ssid, + ssid_len, wifi_security_txt(creds.header.type)); if (creds.header.type == WIFI_SECURITY_TYPE_PSK || creds.header.type == WIFI_SECURITY_TYPE_PSK_SHA256 || creds.header.type == WIFI_SECURITY_TYPE_SAE || creds.header.type == WIFI_SECURITY_TYPE_WPA_PSK) { shell_fprintf(sh, SHELL_VT100_COLOR_DEFAULT, - ", password: \"%.*s\", password_len: %d", creds.password_len, + ", password: \"%.*s\", password_len: %d", (int)creds.password_len, creds.password, creds.password_len); } From bb94c63fa2447af60d449fc1234c0cbb288168d5 Mon Sep 17 00:00:00 2001 From: Chen Xingyu Date: Wed, 20 Nov 2024 10:39:37 +0800 Subject: [PATCH 016/261] samples: subsys: ipc: Fix warning of `size_t` formatting with `%.*s` This addresses the following warning building with `CONFIG_64BIT=y`: error: field precision specifier '.*' expects argument of type 'int', but argument X has type 'size_t' {aka 'long unsigned int'} Signed-off-by: Chen Xingyu --- samples/subsys/ipc/openamp_rsc_table/src/main_remote.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/subsys/ipc/openamp_rsc_table/src/main_remote.c b/samples/subsys/ipc/openamp_rsc_table/src/main_remote.c index c8d12092ace05a..a28e017e9be7aa 100644 --- a/samples/subsys/ipc/openamp_rsc_table/src/main_remote.c +++ b/samples/subsys/ipc/openamp_rsc_table/src/main_remote.c @@ -299,7 +299,7 @@ void app_rpmsg_tty(void *arg1, void *arg2, void *arg3) k_sem_take(&data_tty_sem, K_FOREVER); if (tty_msg.len) { LOG_INF("[Linux TTY] incoming msg: %.*s", - tty_msg.len, (char *)tty_msg.data); + (int)tty_msg.len, (char *)tty_msg.data); snprintf(tx_buff, 13, "TTY 0x%04x: ", tty_ept.addr); memcpy(&tx_buff[12], tty_msg.data, tty_msg.len); rpmsg_send(&tty_ept, tx_buff, tty_msg.len + 12); From 1dd6d0db6785626b143d53e559d708725075ac9c Mon Sep 17 00:00:00 2001 From: Chen Xingyu Date: Wed, 20 Nov 2024 10:40:16 +0800 Subject: [PATCH 017/261] tests: subsys: mgmt: Fix warning of `size_t` formatting with `%.*s` This addresses the following warning building with `CONFIG_64BIT=y`: error: field precision specifier '.*' expects argument of type 'int', but argument X has type 'size_t' {aka 'long unsigned int'} Signed-off-by: Chen Xingyu --- tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c b/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c index b1d3d79b30a18c..1556beeb148ea2 100644 --- a/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c +++ b/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c @@ -71,7 +71,7 @@ ZTEST(zcbor_bulk, test_correct) zassert_equal(sizeof("world") - 1, world.len, "Expected length %d", sizeof("world") - 1); zassert_equal(0, memcmp(world.value, "world", world.len), - "Expected \"world\", got %.*s", world.len, world.value); + "Expected \"world\", got %.*s", (int)world.len, world.value); zassert_true(bool_val, "Expected bool val == true"); } @@ -112,7 +112,7 @@ ZTEST(zcbor_bulk, test_correct_out_of_order) zassert_equal(sizeof("world") - 1, world.len, "Expected length %d", sizeof("world") - 1); zassert_equal(0, memcmp(world.value, "world", world.len), - "Expected \"world\", got %.*s", world.len, world.value); + "Expected \"world\", got %.*s", (int)world.len, world.value); zassert_true(bool_val, "Expected bool val == true"); } @@ -222,7 +222,7 @@ ZTEST(zcbor_bulk, test_bad_type_2) zassert_equal(sizeof("world") - 1, world.len, "Expected length %d", sizeof("world") - 1); zassert_equal(0, memcmp(world.value, "world", world.len), - "Expected \"world\", got %.*s", world.len, world.value); + "Expected \"world\", got %.*s", (int)world.len, world.value); zassert_false(bool_val, "Expected bool val unmodified"); } @@ -298,7 +298,7 @@ ZTEST(zcbor_bulk, test_duplicate) zassert_equal(sizeof("world") - 1, world.len, "Expected length %d", sizeof("world") - 1); zassert_equal(0, memcmp(world.value, "world", world.len), - "Expected \"world\", got %.*s", world.len, world.value); + "Expected \"world\", got %.*s", (int)world.len, world.value); zassert_false(bool_val, "Expected bool val unmodified"); } @@ -377,7 +377,7 @@ ZTEST(zcbor_bulk, test_map_in_map_correct) zassert_equal(sizeof("world") - 1, world.len, "Expected length %d", sizeof("world") - 1); zassert_equal(0, memcmp(world.value, "world", world.len), - "Expected \"world\", got %.*s", world.len, world.value); + "Expected \"world\", got %.*s", (int)world.len, world.value); zassert_true(bool_val, "Expected bool_val == true"); /* Map within map */ From b4893c46ce572d588498a2cba235db16a7ebfdbe Mon Sep 17 00:00:00 2001 From: Benedikt Schmidt Date: Mon, 11 Nov 2024 09:14:26 +0100 Subject: [PATCH 018/261] drivers: fpga: use defaults in iCE40 binding Replace the DT_INST_PROP_OR statements with defaults in the devicetree binding of the iCE40. Signed-off-by: Benedikt Schmidt --- drivers/fpga/fpga_ice40.c | 12 ++++-------- dts/bindings/fpga/lattice,ice40-fpga.yaml | 17 +++++++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/fpga/fpga_ice40.c b/drivers/fpga/fpga_ice40.c index 22eba12e002109..bc251e5c3b1df1 100644 --- a/drivers/fpga/fpga_ice40.c +++ b/drivers/fpga/fpga_ice40.c @@ -549,17 +549,13 @@ static int fpga_ice40_init(const struct device *dev) #define FPGA_ICE40_BUS_FREQ(inst) DT_INST_PROP(inst, spi_max_frequency) -#define FPGA_ICE40_CONFIG_DELAY_US(inst) \ - DT_INST_PROP_OR(inst, config_delay_us, FPGA_ICE40_CONFIG_DELAY_US_MIN) +#define FPGA_ICE40_CONFIG_DELAY_US(inst) DT_INST_PROP(inst, config_delay_us) -#define FPGA_ICE40_CRESET_DELAY_US(inst) \ - DT_INST_PROP_OR(inst, creset_delay_us, FPGA_ICE40_CRESET_DELAY_US_MIN) +#define FPGA_ICE40_CRESET_DELAY_US(inst) DT_INST_PROP(inst, creset_delay_us) -#define FPGA_ICE40_LEADING_CLOCKS(inst) \ - DT_INST_PROP_OR(inst, leading_clocks, FPGA_ICE40_LEADING_CLOCKS_MIN) +#define FPGA_ICE40_LEADING_CLOCKS(inst) DT_INST_PROP(inst, leading_clocks) -#define FPGA_ICE40_TRAILING_CLOCKS(inst) \ - DT_INST_PROP_OR(inst, trailing_clocks, FPGA_ICE40_TRAILING_CLOCKS_MIN) +#define FPGA_ICE40_TRAILING_CLOCKS(inst) DT_INST_PROP(inst, trailing_clocks) #define FPGA_ICE40_MHZ_DELAY_COUNT(inst) DT_INST_PROP_OR(inst, mhz_delay_count, 0) diff --git a/dts/bindings/fpga/lattice,ice40-fpga.yaml b/dts/bindings/fpga/lattice,ice40-fpga.yaml index 2e8cb010d271c0..6355092f600902 100644 --- a/dts/bindings/fpga/lattice,ice40-fpga.yaml +++ b/dts/bindings/fpga/lattice,ice40-fpga.yaml @@ -69,25 +69,26 @@ properties: mhz-delay-count = <0>; creset-delay-us: type: int + default: 1 description: | Delay (in microseconds) between asserting CRESET_B and releasing CRESET_B. - Example usage / default: - creset-delay-us = <1>; + The datasheet specifies a minimum of 200ns, therefore the default is set + to 1us. config-delay-us: type: int + default: 1200 description: | Delay (in microseconds) after releasing CRESET_B to clear internal configuration memory. - Example usage / default: - config-delay-us = <1200>; + The datasheet specifies a minimum of 1200us, which is the default. leading-clocks: type: int + default: 8 description: | Prior to sending the bitstream, issue this number of leading clocks with SPI_CS pulled high. - Example usage / default: - leading-clocks = <8>; + The datasheet specifies 8 dummy cycles, which is the default. trailing-clocks: type: int + default: 49 description: | After sending the bitstream, issue this number of trailing clocks with SPI_CS pulled high. - Example usage / default: - trailing-clocks = <49>; + The datasheet specifies 49 dummy cycles, which is the default. From 585fb2a61bd1b489753e5efb777e7bcfdb0caf0b Mon Sep 17 00:00:00 2001 From: Filip Kokosinski Date: Tue, 12 Nov 2024 14:21:25 +0100 Subject: [PATCH 019/261] boards/arduino/portenta_h7: enable USART1 on M4 Right now, USART1 is enabled on the M7 target variant by default, leaving M4 without a UART to use; this is the way this port was originally contributed. Since then, USB was enabled on M7, changing the console backend from USART1 to USB CDC ACM; the M4 target was left unchanged. This commit enabled USART1 on the M4 variant and disabled it on the M7 variant, so that the M4 variant can use it as its console backend. Note that, for the M4 variant, USART1 has been assigned to `zephyr,console` and `zephyr,shell-uart` since this port was contributed, even though USART1 was always disabled on M4. Signed-off-by: Filip Kokosinski --- .../portenta_h7/arduino_portenta_h7_stm32h747xx_m4.dts | 2 +- .../arduino_portenta_h7_stm32h747xx_m4_defconfig | 10 ++++------ .../portenta_h7/arduino_portenta_h7_stm32h747xx_m7.dts | 4 ++-- .../arduino_portenta_h7_stm32h747xx_m7_defconfig | 6 +----- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m4.dts b/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m4.dts index 12190a28715b35..3e1352834819d6 100644 --- a/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m4.dts +++ b/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m4.dts @@ -28,5 +28,5 @@ }; &usart1 { - status = "disabled"; + status = "okay"; }; diff --git a/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m4_defconfig b/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m4_defconfig index 8a931846ae78ac..768c0b2c03dcef 100644 --- a/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m4_defconfig +++ b/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m4_defconfig @@ -10,9 +10,7 @@ CONFIG_ARM_MPU=y # Enable HW stack protection CONFIG_HW_STACK_PROTECTION=y -# Enable uart driver -# CONFIG_SERIAL=y - -# By default CONSOLE is assigned to m7 -# CONFIG_CONSOLE=y -# CONFIG_UART_CONSOLE=y +# On M4, USART1 is used as the UART console backend by default +CONFIG_SERIAL=y +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y diff --git a/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m7.dts b/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m7.dts index 4b43bb6cbd4f82..30b5b06db27205 100644 --- a/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m7.dts +++ b/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m7.dts @@ -80,9 +80,9 @@ clock-frequency = ; }; - +/* USART1 is enabled on M4 by default */ &usart1 { - status = "okay"; + status = "disabled"; }; &i2c1 { diff --git a/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m7_defconfig b/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m7_defconfig index ff4b2954d027c6..06d55f8db39ac0 100644 --- a/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m7_defconfig +++ b/boards/arduino/portenta_h7/arduino_portenta_h7_stm32h747xx_m7_defconfig @@ -16,12 +16,8 @@ CONFIG_HW_STACK_PROTECTION=y # Use zephyr,code-partition as flash offset CONFIG_USE_DT_CODE_PARTITION=y -# Disable following to assign serial ports to m4 core - -# Enable uart driver +# On M7, USB CDC ACM is used as the UART console backend by default CONFIG_SERIAL=y - -# Enable console CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y CONFIG_UART_LINE_CTRL=y From 4fe6d476832dc3972bf95260851da6ce73728880 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 24 Oct 2024 09:57:09 +0200 Subject: [PATCH 020/261] boards: arduino_nicla_vision: fix hardware information The board shares many features with other Arduinos based on STM32H747 (like the HSE in bypass mode). Once https://github.com/zephyrproject-rtos/zephyr/pull/76542 is merged, PF1550 support should be added too to allow switching IO voltage from 3v3 to 1v8 Signed-off-by: Martino Facchin --- .../arduino_nicla_vision_stm32h747xx_m7.dts | 41 +++++++++++++++---- boards/arduino/nicla_vision/board_gpio_hse.c | 30 ++++++++++++++ 2 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 boards/arduino/nicla_vision/board_gpio_hse.c diff --git a/boards/arduino/nicla_vision/arduino_nicla_vision_stm32h747xx_m7.dts b/boards/arduino/nicla_vision/arduino_nicla_vision_stm32h747xx_m7.dts index 1fe8d2f9610990..0028128f8e2310 100644 --- a/boards/arduino/nicla_vision/arduino_nicla_vision_stm32h747xx_m7.dts +++ b/boards/arduino/nicla_vision/arduino_nicla_vision_stm32h747xx_m7.dts @@ -25,14 +25,6 @@ zephyr,camera = &dcmi; }; - sdram1: sdram@c0000000 { - compatible = "zephyr,memory-region", "mmio-sram"; - device_type = "memory"; - reg = <0xc0000000 DT_SIZE_M(8)>; - zephyr,memory-region = "SDRAM1"; - zephyr,memory-attr = <( DT_MEM_ARM(ATTR_MPU_RAM) )>; - }; - aliases { led0 = &red_led; led1 = &green_led; @@ -46,10 +38,12 @@ &clk_hse { status = "okay"; + hse-bypass; clock-frequency = ; }; &clk_lse { + lse-bypass; status = "okay"; }; @@ -164,6 +158,37 @@ }; }; +&quadspi { + pinctrl-0 = <&quadspi_clk_pf10 &quadspi_bk1_ncs_pg6 + &quadspi_bk1_io0_pd11 &quadspi_bk1_io1_pf9 + &quadspi_bk1_io2_pe2 &quadspi_bk1_io3_pd13>; + pinctrl-names = "default"; + status = "okay"; + + n25q128a1: qspi-nor-flash@90000000 { + compatible = "st,stm32-qspi-nor"; + reg = <0x90000000 DT_SIZE_M(16)>; /* 128 Mbits */ + qspi-max-frequency = <72000000>; + status = "okay"; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + slot1_partition: partition@0 { + label = "image-1"; + reg = <0x00000000 DT_SIZE_M(1)>; + }; + + storage_partition: partition@100000 { + label = "storage"; + reg = <0x00100000 DT_SIZE_M(15)>; + }; + }; + }; +}; + &rng { status = "okay"; }; diff --git a/boards/arduino/nicla_vision/board_gpio_hse.c b/boards/arduino/nicla_vision/board_gpio_hse.c new file mode 100644 index 00000000000000..caeca006ad5e95 --- /dev/null +++ b/boards/arduino/nicla_vision/board_gpio_hse.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 DNDG srl + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +static int board_gpio_hse(void) +{ + /* The external oscillator that drives the HSE clock should be enabled + * by setting the GPIOH1 pin. This function is registered at priority + * RE_KERNEL_1 to be executed before the standard STM clock + * setup code. + */ + + LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOH); + + LL_GPIO_SetPinMode(GPIOH, LL_GPIO_PIN_1, LL_GPIO_MODE_OUTPUT); + LL_GPIO_SetPinSpeed(GPIOH, LL_GPIO_PIN_1, LL_GPIO_SPEED_FREQ_LOW); + LL_GPIO_SetPinOutputType(GPIOH, LL_GPIO_PIN_1, LL_GPIO_OUTPUT_PUSHPULL); + LL_GPIO_SetPinPull(GPIOH, LL_GPIO_PIN_1, LL_GPIO_PULL_UP); + LL_GPIO_SetOutputPin(GPIOH, LL_GPIO_PIN_1); + + return 0; +} + +SYS_INIT(board_gpio_hse, PRE_KERNEL_1, 0); From 81bb231fd07971156d487d6603920a5576fd71ad Mon Sep 17 00:00:00 2001 From: Dominik Kilian Date: Wed, 23 Oct 2024 14:28:19 +0200 Subject: [PATCH 021/261] ipc: icbmsg: Reduce block alignment to 32-bits The ICBMsg backend divides its memory into blocks. Each block is aligned to data cache alignment. Is it not required, since adjacent blocks has the same data flow direction (either read-only or write-only). This commit changes it to 32-bits making wasted memory significantly reduced. Signed-off-by: Dominik Kilian --- subsys/ipc/ipc_service/backends/ipc_icbmsg.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/subsys/ipc/ipc_service/backends/ipc_icbmsg.c b/subsys/ipc/ipc_service/backends/ipc_icbmsg.c index 395931d9cd4676..7e985aa76deb0e 100644 --- a/subsys/ipc/ipc_service/backends/ipc_icbmsg.c +++ b/subsys/ipc/ipc_service/backends/ipc_icbmsg.c @@ -1296,6 +1296,11 @@ const static struct ipc_service_backend backend_ops = { .release_rx_buffer = release_rx_buffer, }; +/** + * Required block alignment. + */ +#define BLOCK_ALIGNMENT sizeof(uint32_t) + /** * Number of bytes per each ICMsg message. It is used to calculate size of ICMsg area. */ @@ -1309,10 +1314,10 @@ const static struct ipc_service_backend backend_ops = { (PBUF_HEADER_OVERHEAD(GET_CACHE_ALIGNMENT(i)) + 2 * BYTES_PER_ICMSG_MESSAGE) /** - * Returns required block alignment for instance "i". + * Returns required data cache alignment for instance "i". */ #define GET_CACHE_ALIGNMENT(i) \ - MAX(sizeof(uint32_t), DT_INST_PROP_OR(i, dcache_alignment, 0)) + MAX(BLOCK_ALIGNMENT, DT_INST_PROP_OR(i, dcache_alignment, 0)) /** * Calculates minimum size required for ICMsg region for specific number of local @@ -1320,9 +1325,9 @@ const static struct ipc_service_backend backend_ops = { * because it can hold data message for each local block and release message * for each remote block. */ -#define GET_ICMSG_MIN_SIZE(i, local_blocks, remote_blocks) \ +#define GET_ICMSG_MIN_SIZE(i, local_blocks, remote_blocks) ROUND_UP( \ (ICMSG_BUFFER_OVERHEAD(i) + BYTES_PER_ICMSG_MESSAGE * \ - (local_blocks + remote_blocks)) + (local_blocks + remote_blocks)), GET_CACHE_ALIGNMENT(i)) /** * Calculate aligned block size by evenly dividing remaining space after removing @@ -1330,7 +1335,7 @@ const static struct ipc_service_backend backend_ops = { */ #define GET_BLOCK_SIZE(i, total_size, local_blocks, remote_blocks) ROUND_DOWN( \ ((total_size) - GET_ICMSG_MIN_SIZE(i, (local_blocks), (remote_blocks))) / \ - (local_blocks), GET_CACHE_ALIGNMENT(i)) + (local_blocks), BLOCK_ALIGNMENT) /** * Calculate offset where area for blocks starts which is just after the ICMsg. @@ -1435,11 +1440,11 @@ const static struct ipc_service_backend backend_ops = { }; \ BUILD_ASSERT(IS_POWER_OF_TWO(GET_CACHE_ALIGNMENT(i)), \ "This module supports only power of two cache alignment"); \ - BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, tx, rx) >= GET_CACHE_ALIGNMENT(i)) && \ + BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, tx, rx) >= BLOCK_ALIGNMENT) && \ (GET_BLOCK_SIZE_INST(i, tx, rx) < \ GET_MEM_SIZE_INST(i, tx)), \ "TX region is too small for provided number of blocks"); \ - BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, rx, tx) >= GET_CACHE_ALIGNMENT(i)) && \ + BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, rx, tx) >= BLOCK_ALIGNMENT) && \ (GET_BLOCK_SIZE_INST(i, rx, tx) < \ GET_MEM_SIZE_INST(i, rx)), \ "RX region is too small for provided number of blocks"); \ From 18a2a63a25b38788050ec307a60b15817a28733c Mon Sep 17 00:00:00 2001 From: Lucien Zhao Date: Sun, 1 Sep 2024 23:17:32 +0800 Subject: [PATCH 022/261] dts: arm: nxp: rt118x: add flexpwm instances add 4 flexpwm instances update clock driver to adapt flexpwm clock structure Signed-off-by: Lucien Zhao --- .../clock_control_mcux_ccm_rev2.c | 8 +- dts/arm/nxp/nxp_rt118x.dtsi | 185 ++++++++++++++++++ 2 files changed, 192 insertions(+), 1 deletion(-) diff --git a/drivers/clock_control/clock_control_mcux_ccm_rev2.c b/drivers/clock_control/clock_control_mcux_ccm_rev2.c index 703c9f1c7af5ba..f0059a962405dd 100644 --- a/drivers/clock_control/clock_control_mcux_ccm_rev2.c +++ b/drivers/clock_control/clock_control_mcux_ccm_rev2.c @@ -111,10 +111,16 @@ static int mcux_ccm_get_subsys_rate(const struct device *dev, #endif #ifdef CONFIG_PWM_MCUX +#if defined(CONFIG_SOC_SERIES_IMXRT118X) + case IMX_CCM_PWM_CLK: + clock_root = kCLOCK_Root_Bus_Aon; + break; +#else case IMX_CCM_PWM_CLK: clock_root = kCLOCK_Root_Bus; break; -#endif +#endif /* CONFIG_SOC_SERIES_IMXRT118X */ +#endif /* CONFIG_PWM_MCUX */ #ifdef CONFIG_CAN_MCUX_FLEXCAN case IMX_CCM_CAN1_CLK: diff --git a/dts/arm/nxp/nxp_rt118x.dtsi b/dts/arm/nxp/nxp_rt118x.dtsi index 0e511bac5dee95..db58d532d182ad 100644 --- a/dts/arm/nxp/nxp_rt118x.dtsi +++ b/dts/arm/nxp/nxp_rt118x.dtsi @@ -8,6 +8,7 @@ #include #include #include +#include / { cpus { @@ -663,6 +664,190 @@ resolution = <32>; status = "disabled"; }; + + flexpwm1: flexpwm@2650000 { + compatible = "nxp,flexpwm"; + reg = <0x2650000 0x4000>; + interrupts = <23 0>; + + flexpwm1_pwm0: flexpwm1_pwm0 { + compatible = "nxp,imx-pwm"; + index = <0>; + interrupts = <24 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm1_pwm1: flexpwm1_pwm1 { + compatible = "nxp,imx-pwm"; + index = <1>; + interrupts = <25 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm1_pwm2: flexpwm1_pwm2 { + compatible = "nxp,imx-pwm"; + index = <2>; + interrupts = <26 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm1_pwm3: flexpwm1_pwm3 { + compatible = "nxp,imx-pwm"; + index = <3>; + interrupts = <27 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + }; + + flexpwm2: flexpwm@2660000 { + compatible = "nxp,flexpwm"; + reg = <0x2660000 0x4000>; + interrupts = <170 0>; + + flexpwm2_pwm0: flexpwm2_pwm0 { + compatible = "nxp,imx-pwm"; + index = <0>; + interrupts = <171 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm2_pwm1: flexpwm2_pwm1 { + compatible = "nxp,imx-pwm"; + index = <1>; + interrupts = <172 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm2_pwm2: flexpwm2_pwm2 { + compatible = "nxp,imx-pwm"; + index = <2>; + interrupts = <173 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm2_pwm3: flexpwm2_pwm3 { + compatible = "nxp,imx-pwm"; + index = <3>; + interrupts = <174 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + }; + + flexpwm3: flexpwm@2670000 { + compatible = "nxp,flexpwm"; + reg = <0x2670000 0x4000>; + interrupts = <175 0>; + + flexpwm3_pwm0: flexpwm3_pwm0 { + compatible = "nxp,imx-pwm"; + index = <0>; + interrupts = <176 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm3_pwm1: flexpwm3_pwm1 { + compatible = "nxp,imx-pwm"; + index = <1>; + interrupts = <177 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm3_pwm2: flexpwm3_pwm2 { + compatible = "nxp,imx-pwm"; + index = <2>; + interrupts = <178 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm3_pwm3: flexpwm3_pwm3 { + compatible = "nxp,imx-pwm"; + index = <3>; + interrupts = <179 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + }; + + flexpwm4: flexpwm@2680000 { + compatible = "nxp,flexpwm"; + reg = <0x2680000 0x4000>; + interrupts = <180 0>; + + flexpwm4_pwm0: flexpwm4_pwm0 { + compatible = "nxp,imx-pwm"; + index = <0>; + interrupts = <181 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm4_pwm1: flexpwm4_pwm1 { + compatible = "nxp,imx-pwm"; + index = <1>; + interrupts = <182 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm4_pwm2: flexpwm4_pwm2 { + compatible = "nxp,imx-pwm"; + index = <2>; + interrupts = <183 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + + flexpwm4_pwm3: flexpwm4_pwm3 { + compatible = "nxp,imx-pwm"; + index = <3>; + interrupts = <184 0>; + #pwm-cells = <3>; + clocks = <&ccm IMX_CCM_PWM_CLK 0 0>; + nxp,prescaler = <128>; + status = "disabled"; + }; + }; }; &flexspi { From 74d1f60fafa1d1970a94a0b4043826e1f5e0fd76 Mon Sep 17 00:00:00 2001 From: Lucien Zhao Date: Sun, 1 Sep 2024 23:21:56 +0800 Subject: [PATCH 023/261] boards: mimxrt1180_evk: Enable PWM for RT1180 EVK Enables PWM for RT1180 EVK. Tested with sample led_pwm Signed-off-by: Lucien Zhao --- boards/nxp/mimxrt1180_evk/doc/index.rst | 2 ++ .../nxp/mimxrt1180_evk/mimxrt1180_evk-pinctrl.dtsi | 8 ++++++++ boards/nxp/mimxrt1180_evk/mimxrt1180_evk.dtsi | 14 ++++++++++++++ .../mimxrt1180_evk_mimxrt1189_cm33.yaml | 1 + .../mimxrt1180_evk_mimxrt1189_cm7.yaml | 1 + 5 files changed, 26 insertions(+) diff --git a/boards/nxp/mimxrt1180_evk/doc/index.rst b/boards/nxp/mimxrt1180_evk/doc/index.rst index c8f1147d0b014a..012cb9407ada5b 100644 --- a/boards/nxp/mimxrt1180_evk/doc/index.rst +++ b/boards/nxp/mimxrt1180_evk/doc/index.rst @@ -114,6 +114,8 @@ configuration supports the following hardware features: +-----------+------------+-------------------------------------+ | FLEXSPI | on-chip | flash programming | +-----------+------------+-------------------------------------+ +| PWM | on-chip | pwm | ++-----------+------------+-------------------------------------+ The default configuration can be found in the defconfig file: :zephyr_file:`boards/nxp/mimxrt1180_evk/mimxrt1180_evk_mimxrt1189_cm33_defconfig` diff --git a/boards/nxp/mimxrt1180_evk/mimxrt1180_evk-pinctrl.dtsi b/boards/nxp/mimxrt1180_evk/mimxrt1180_evk-pinctrl.dtsi index 81ac3b1eb210e7..29687171a5073c 100644 --- a/boards/nxp/mimxrt1180_evk/mimxrt1180_evk-pinctrl.dtsi +++ b/boards/nxp/mimxrt1180_evk/mimxrt1180_evk-pinctrl.dtsi @@ -129,4 +129,12 @@ input-enable; }; }; + + pinmux_flexpwm2: pinmux_flexpwm2 { + group0 { + pinmux = <&iomuxc_gpio_ad_27_flexpwm2_pwm1_b>; + drive-strength = "high"; + slew-rate = "fast"; + }; + }; }; diff --git a/boards/nxp/mimxrt1180_evk/mimxrt1180_evk.dtsi b/boards/nxp/mimxrt1180_evk/mimxrt1180_evk.dtsi index 725b5439e996c8..3f71d74a762b55 100644 --- a/boards/nxp/mimxrt1180_evk/mimxrt1180_evk.dtsi +++ b/boards/nxp/mimxrt1180_evk/mimxrt1180_evk.dtsi @@ -11,6 +11,7 @@ aliases { led0 = &green_led; sw0 = &user_button; + pwm-led0 = &green_pwm_led; }; leds { @@ -29,6 +30,13 @@ zephyr,code = ; }; }; + + pwmleds { + compatible = "pwm-leds"; + green_pwm_led: green_pwm_led { + pwms = <&flexpwm2_pwm1 1 PWM_MSEC(20) PWM_POLARITY_NORMAL>; + }; + }; }; &lpuart1 { @@ -125,3 +133,9 @@ max-bitrate = <5000000>; }; }; + +&flexpwm2_pwm1 { + status = "okay"; + pinctrl-0 = <&pinmux_flexpwm2>; + pinctrl-names = "default"; +}; diff --git a/boards/nxp/mimxrt1180_evk/mimxrt1180_evk_mimxrt1189_cm33.yaml b/boards/nxp/mimxrt1180_evk/mimxrt1180_evk_mimxrt1189_cm33.yaml index add9a84abc6a92..639b19be76818c 100644 --- a/boards/nxp/mimxrt1180_evk/mimxrt1180_evk_mimxrt1189_cm33.yaml +++ b/boards/nxp/mimxrt1180_evk/mimxrt1180_evk_mimxrt1189_cm33.yaml @@ -22,4 +22,5 @@ supported: - adc - netif:eth - can + - pwm vendor: nxp diff --git a/boards/nxp/mimxrt1180_evk/mimxrt1180_evk_mimxrt1189_cm7.yaml b/boards/nxp/mimxrt1180_evk/mimxrt1180_evk_mimxrt1189_cm7.yaml index 4323dc8ac974b1..e69b1ca1feee1f 100644 --- a/boards/nxp/mimxrt1180_evk/mimxrt1180_evk_mimxrt1189_cm7.yaml +++ b/boards/nxp/mimxrt1180_evk/mimxrt1180_evk_mimxrt1189_cm7.yaml @@ -21,4 +21,5 @@ supported: - counter - adc - can + - pwm vendor: nxp From a72244f2d0644a261cc6318ec07a4f597dffac57 Mon Sep 17 00:00:00 2001 From: Dmitrii Golovanov Date: Thu, 17 Oct 2024 09:02:35 +0200 Subject: [PATCH 024/261] twister: ztest: harness: Fix missed TestCase statuses Fix a problem of Ztest suite names not taken into account by Twister to identify a TestCase, so in some situations a Ztest test's status was not assigned to the proper TestCase and it remains 'None' whereas the actual status value lost, eventually the resulting total execution counters not correct. The issue was observed in these situations: * Ztest application with multiple test suites having same test names. * Ztest suite is 'skipped' entirely on execution with all its tests. The proposed solution extends Twister test case name for Ztest to include Ztest suite name, so the resulting identifier looks like: `..` The above naming scheme now requires ztest_suite_name part to be provided for `--sub-test` command line option. Testcase identifiers in twister.json and testplan.json will also include ztest_suite_name component. The Twister Ztest(Test) Harness is improved to track all state changes known from the test application's log for Ztest suites and test cases, so now it parses log output from a Ztest application more scurpulously. Regular expressions to match log records are extended and optimized to compile them only once and, in some cases, fixed (suite summary). Signed-off-by: Dmitrii Golovanov --- .../pylib/twister/twisterlib/environment.py | 24 ++- scripts/pylib/twister/twisterlib/harness.py | 159 ++++++++++++++---- scripts/pylib/twister/twisterlib/runner.py | 11 +- scripts/pylib/twister/twisterlib/testsuite.py | 12 +- scripts/tests/twister/test_harness.py | 39 ++++- scripts/tests/twister/test_runner.py | 16 +- scripts/tests/twister/test_testplan.py | 5 +- scripts/tests/twister/test_testsuite.py | 2 +- scripts/tests/twister_blackbox/test_config.py | 7 +- .../tests/dummy/agnostic/group2/src/main.c | 7 + scripts/tests/twister_blackbox/test_filter.py | 16 +- .../tests/twister_blackbox/test_platform.py | 4 +- .../tests/twister_blackbox/test_printouts.py | 28 +-- scripts/tests/twister_blackbox/test_report.py | 6 +- scripts/tests/twister_blackbox/test_runner.py | 4 +- .../tests/twister_blackbox/test_shuffle.py | 10 +- .../tests/twister_blackbox/test_testlist.py | 3 +- .../tests/twister_blackbox/test_testplan.py | 11 +- 18 files changed, 254 insertions(+), 110 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index 2b330caf2ab334..9f41d24b541aae 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # vim: set syntax=python ts=4 : # -# Copyright (c) 2018 Intel Corporation +# Copyright (c) 2018-2024 Intel Corporation # Copyright 2022 NXP # Copyright (c) 2024 Arm Limited (or its affiliates). All rights reserved. # @@ -149,7 +149,8 @@ def add_parse_arguments(parser = None): test_plan_report_xor.add_argument("--list-tests", action="store_true", help="""List of all sub-test functions recursively found in all --testsuite-root arguments. Note different sub-tests can share - the same section name and come from different directories. + the same test scenario identifier (section.subsection) + and come from different directories. The output is flattened and reports --sub-test names only, not their directories. For instance net.socket.getaddrinfo_ok and net.socket.fd_set belong to different directories. @@ -239,17 +240,22 @@ def add_parse_arguments(parser = None): test_xor_subtest.add_argument( "-s", "--test", "--scenario", action="append", type = norm_path, - help="Run only the specified testsuite scenario. These are named by " - "") + help="""Run only the specified test suite scenario. These are named by + 'path/relative/to/Zephyr/base/section.subsection_in_testcase_yaml', + or just 'section.subsection' identifier. With '--testsuite-root' option + the scenario will be found faster. + """) test_xor_subtest.add_argument( "--sub-test", action="append", - help="""Recursively find sub-test functions and run the entire - test section where they were found, including all sibling test + help="""Recursively find sub-test functions (test cases) and run the entire + test scenario (section.subsection) where they were found, including all sibling test functions. Sub-tests are named by: - section.name.in.testcase.yaml.function_name_without_test_prefix - Example: In kernel.fifo.fifo_loop: 'kernel.fifo' is a section name - and 'fifo_loop' is a name of a function found in main.c without test prefix. + 'section.subsection_in_testcase_yaml.ztest_suite.ztest_without_test_prefix'. + Example_1: 'kernel.fifo.fifo_api_1cpu.fifo_loop' where 'kernel.fifo' is a test scenario + name (section.subsection) and 'fifo_api_1cpu.fifo_loop' is + a Ztest suite_name.test_name identificator. + Example_2: 'debug.coredump.logging_backend' is a standalone test scenario name. """) parser.add_argument( diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index 2629cdfb83fafa..cd2655e927f93c 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -31,7 +31,6 @@ _WINDOWS = platform.system() == 'Windows' -result_re = re.compile(r".*(PASS|FAIL|SKIP) - (test_)?(\S*) in (\d*[.,]?\d*) seconds") class Harness: GCOV_START = "GCOV_COVERAGE_DUMP_START" GCOV_END = "GCOV_COVERAGE_DUMP_END" @@ -59,12 +58,19 @@ def __init__(self): self.ztest = False self.detected_suite_names = [] self.run_id = None + self.started_suites = {} + self.started_cases = {} self.matched_run_id = False self.run_id_exists = False self.instance: TestInstance | None = None self.testcase_output = "" self._match = False + + @property + def trace(self) -> bool: + return self.instance.handler.options.verbose > 2 + @property def status(self) -> TwisterStatus: return self._status @@ -710,42 +716,124 @@ def _check_result(self, line): class Test(Harness): __test__ = False # for pytest to skip this class when collects tests - RUN_PASSED = "PROJECT EXECUTION SUCCESSFUL" - RUN_FAILED = "PROJECT EXECUTION FAILED" - test_suite_start_pattern = r"Running TESTSUITE (?P.*)" - ZTEST_START_PATTERN = r"START - (test_)?([a-zA-Z0-9_-]+)" - def handle(self, line): - test_suite_match = re.search(self.test_suite_start_pattern, line) - if test_suite_match: - suite_name = test_suite_match.group("suite_name") + test_suite_start_pattern = re.compile(r"Running TESTSUITE (?P\S*)") + test_suite_end_pattern = re.compile(r"TESTSUITE (?P\S*)\s+(?Psucceeded|failed)") + test_case_start_pattern = re.compile(r"START - (test_)?([a-zA-Z0-9_-]+)") + test_case_end_pattern = re.compile(r".*(PASS|FAIL|SKIP) - (test_)?(\S*) in (\d*[.,]?\d*) seconds") + test_suite_summary_pattern = re.compile(r"SUITE (?P\S*) - .* \[(?P\S*)\]: .* duration = (\d*[.,]?\d*) seconds") + test_case_summary_pattern = re.compile(r" - (PASS|FAIL|SKIP) - \[([^\.]*).(test_)?(\S*)\] duration = (\d*[.,]?\d*) seconds") + + + def get_testcase(self, tc_name, phase, ts_name=None): + """ Search a Ztest case among detected in the test image binary + expecting the same test names as already known from the ELF. + Track suites and cases unexpectedly found in the log. + """ + ts_names = self.started_suites.keys() + if ts_name: + if ts_name not in self.instance.testsuite.ztest_suite_names: + logger.warning(f"On {phase}: unexpected Ztest suite '{ts_name}' " + f"not present among: {self.instance.testsuite.ztest_suite_names}") + if ts_name not in self.detected_suite_names: + if self.trace: + logger.debug(f"On {phase}: detected new Ztest suite '{ts_name}'") + self.detected_suite_names.append(ts_name) + ts_names = [ ts_name ] if ts_name in ts_names else [] + + # Firstly try to match the test case ID to the first running Ztest suite with this test name. + for ts_name_ in ts_names: + if self.started_suites[ts_name_]['count'] < (0 if phase == 'TS_SUM' else 1): + continue + tc_fq_id = "{}.{}.{}".format(self.id, ts_name_, tc_name) + if tc := self.instance.get_case_by_name(tc_fq_id): + if self.trace: + logger.debug(f"On {phase}: Ztest case '{tc_name}' matched to '{tc_fq_id}") + return tc + logger.debug(f"On {phase}: Ztest case '{tc_name}' is not known in {self.started_suites} running suite(s).") + tc_id = "{}.{}".format(self.id, tc_name) + return self.instance.get_case_or_create(tc_id) + + def start_suite(self, suite_name): + if suite_name not in self.detected_suite_names: self.detected_suite_names.append(suite_name) + if suite_name not in self.instance.testsuite.ztest_suite_names: + logger.warning(f"Unexpected Ztest suite '{suite_name}'") + if suite_name in self.started_suites: + if self.started_suites[suite_name]['count'] > 0: + logger.warning(f"Already STARTED '{suite_name}':{self.started_suites[suite_name]}") + elif self.trace: + logger.debug(f"START suite '{suite_name}'") + self.started_suites[suite_name]['count'] += 1 + self.started_suites[suite_name]['repeat'] += 1 + else: + self.started_suites[suite_name] = { 'count': 1, 'repeat': 0 } + + def end_suite(self, suite_name, phase='', suite_status=None): + if suite_name in self.started_suites: + if phase == 'TS_SUM' and self.started_suites[suite_name]['count'] == 0: + return + if self.started_suites[suite_name]['count'] < 1: + logger.error(f"Already ENDED {phase} suite '{suite_name}':{self.started_suites[suite_name]}") + elif self.trace: + logger.debug(f"END {phase} suite '{suite_name}':{self.started_suites[suite_name]}") + self.started_suites[suite_name]['count'] -= 1 + elif suite_status == 'SKIP': + self.start_suite(suite_name) # register skipped suites at their summary end + self.started_suites[suite_name]['count'] -= 1 + else: + logger.warning(f"END {phase} suite '{suite_name}' without START detected") - testcase_match = re.search(self.ZTEST_START_PATTERN, line) - if testcase_match: - name = "{}.{}".format(self.id, testcase_match.group(2)) - tc = self.instance.get_case_or_create(name) + def start_case(self, tc_name): + if tc_name in self.started_cases: + if self.started_cases[tc_name]['count'] > 0: + logger.warning(f"Already STARTED '{tc_name}':{self.started_cases[tc_name]}") + self.started_cases[tc_name]['count'] += 1 + else: + self.started_cases[tc_name] = { 'count': 1 } + + def end_case(self, tc_name, phase=''): + if tc_name in self.started_cases: + if phase == 'TS_SUM' and self.started_cases[tc_name]['count'] == 0: + return + if self.started_cases[tc_name]['count'] < 1: + logger.error(f"Already ENDED {phase} case '{tc_name}':{self.started_cases[tc_name]}") + elif self.trace: + logger.debug(f"END {phase} case '{tc_name}':{self.started_cases[tc_name]}") + self.started_cases[tc_name]['count'] -= 1 + elif phase != 'TS_SUM': + logger.warning(f"END {phase} case '{tc_name}' without START detected") + + + def handle(self, line): + testcase_match = None + if self._match: + self.testcase_output += line + "\n" + + if test_suite_start_match := re.search(self.test_suite_start_pattern, line): + self.start_suite(test_suite_start_match.group("suite_name")) + elif test_suite_end_match := re.search(self.test_suite_end_pattern, line): + suite_name=test_suite_end_match.group("suite_name") + self.end_suite(suite_name, 'TS_END') + elif testcase_match := re.search(self.test_case_start_pattern, line): + tc_name = testcase_match.group(2) + tc = self.get_testcase(tc_name, 'TC_START') + self.start_case(tc.name) # Mark the test as started, if something happens here, it is mostly # due to this tests, for example timeout. This should in this case # be marked as failed and not blocked (not run). tc.status = TwisterStatus.STARTED - - if testcase_match or self._match: - self.testcase_output += line + "\n" - self._match = True - - result_match = result_re.match(line) + if not self._match: + self.testcase_output += line + "\n" + self._match = True # some testcases are skipped based on predicates and do not show up # during test execution, however they are listed in the summary. Parse # the summary for status and use that status instead. - - summary_re = re.compile(r"- (PASS|FAIL|SKIP) - \[([^\.]*).(test_)?(\S*)\] duration = (\d*[.,]?\d*) seconds") - summary_match = summary_re.match(line) - - if result_match: + elif result_match := self.test_case_end_pattern.match(line): matched_status = result_match.group(1) - name = "{}.{}".format(self.id, result_match.group(3)) - tc = self.instance.get_case_or_create(name) + tc_name = result_match.group(3) + tc = self.get_testcase(tc_name, 'TC_END') + self.end_case(tc.name) tc.status = TwisterStatus[matched_status] if tc.status == TwisterStatus.SKIP: tc.reason = "ztest skip" @@ -755,15 +843,22 @@ def handle(self, line): self.testcase_output = "" self._match = False self.ztest = True - elif summary_match: - matched_status = summary_match.group(1) - self.detected_suite_names.append(summary_match.group(2)) - name = "{}.{}".format(self.id, summary_match.group(4)) - tc = self.instance.get_case_or_create(name) + elif test_suite_summary_match := self.test_suite_summary_pattern.match(line): + suite_name=test_suite_summary_match.group("suite_name") + suite_status=test_suite_summary_match.group("suite_status") + self._match = False + self.ztest = True + self.end_suite(suite_name, 'TS_SUM', suite_status=suite_status) + elif test_case_summary_match := self.test_case_summary_pattern.match(line): + matched_status = test_case_summary_match.group(1) + suite_name = test_case_summary_match.group(2) + tc_name = test_case_summary_match.group(4) + tc = self.get_testcase(tc_name, 'TS_SUM', suite_name) + self.end_case(tc.name, 'TS_SUM') tc.status = TwisterStatus[matched_status] if tc.status == TwisterStatus.SKIP: tc.reason = "ztest skip" - tc.duration = float(summary_match.group(5)) + tc.duration = float(test_case_summary_match.group(5)) if tc.status == TwisterStatus.FAIL: tc.output = self.testcase_output self.testcase_output = "" diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index 128bc598ed9c4d..83ca94f9fb5f24 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -1,6 +1,6 @@ # vim: set syntax=python ts=4 : # -# Copyright (c) 20180-2022 Intel Corporation +# Copyright (c) 2018-2024 Intel Corporation # Copyright 2022 NXP # SPDX-License-Identifier: Apache-2.0 @@ -1108,13 +1108,16 @@ def determine_testcases(self, results): matches = new_ztest_unit_test_regex.findall(sym.name) if matches: for m in matches: - # new_ztest_suite = m[0] # not used for now + new_ztest_suite = m[0] + if new_ztest_suite not in self.instance.testsuite.ztest_suite_names: + logger.warning(f"Unexpected Ztest suite '{new_ztest_suite}' " + f"not present in: {self.instance.testsuite.ztest_suite_names}") test_func_name = m[1].replace("test_", "", 1) - testcase_id = f"{yaml_testsuite_name}.{test_func_name}" + testcase_id = f"{yaml_testsuite_name}.{new_ztest_suite}.{test_func_name}" detected_cases.append(testcase_id) if detected_cases: - logger.debug(f"{', '.join(detected_cases)} in {elf_file}") + logger.debug(f"Detected Ztest cases: [{', '.join(detected_cases)}] in {elf_file}") tc_keeper = {tc.name: {'status': tc.status, 'reason': tc.reason} for tc in self.instance.testcases} self.instance.testcases.clear() self.instance.testsuite.testcases.clear() diff --git a/scripts/pylib/twister/twisterlib/testsuite.py b/scripts/pylib/twister/twisterlib/testsuite.py index 3522c5bb218e0b..01b91f4b876d8d 100644 --- a/scripts/pylib/twister/twisterlib/testsuite.py +++ b/scripts/pylib/twister/twisterlib/testsuite.py @@ -1,6 +1,6 @@ # vim: set syntax=python ts=4 : # -# Copyright (c) 2018-2022 Intel Corporation +# Copyright (c) 2018-2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 from enum import Enum @@ -248,14 +248,16 @@ def _find_ztest_testcases(search_area, testcase_regex): testcase_regex_matches = \ [m for m in testcase_regex.finditer(search_area)] testcase_names = \ - [m.group("testcase_name") for m in testcase_regex_matches] - testcase_names = [name.decode("UTF-8") for name in testcase_names] + [(m.group("suite_name") if m.groupdict().get("suite_name") else b'', m.group("testcase_name")) \ + for m in testcase_regex_matches] + testcase_names = [(ts_name.decode("UTF-8"), tc_name.decode("UTF-8")) for ts_name, tc_name in testcase_names] warnings = None for testcase_name in testcase_names: - if not testcase_name.startswith("test_"): + if not testcase_name[1].startswith("test_"): warnings = "Found a test that does not start with test_" testcase_names = \ - [tc_name.replace("test_", "", 1) for tc_name in testcase_names] + [(ts_name + '.' if ts_name else '') + f"{tc_name.replace('test_', '', 1)}" \ + for (ts_name, tc_name) in testcase_names] return testcase_names, warnings diff --git a/scripts/tests/twister/test_harness.py b/scripts/tests/twister/test_harness.py index c0a135fb24105e..7e0fca79677ab3 100644 --- a/scripts/tests/twister/test_harness.py +++ b/scripts/tests/twister/test_harness.py @@ -597,31 +597,48 @@ def test_get_harness(name): "", "Running TESTSUITE suite_name", ["suite_name"], + { 'suite_name': { 'count': 1, 'repeat': 0 } }, + {}, TwisterStatus.NONE, True, TwisterStatus.NONE, ), - ("", "START - test_testcase", [], TwisterStatus.STARTED, True, TwisterStatus.NONE), ( - "", + "On TC_START: Ztest case 'testcase' is not known in {} running suite(s)", + "START - test_testcase", + [], + {}, + { 'test_id.testcase': { 'count': 1 } }, + TwisterStatus.STARTED, + True, + TwisterStatus.NONE + ), + ( + "On TC_END: Ztest case 'example' is not known in {} running suite(s)", "PASS - test_example in 0 seconds", [], + {}, + {}, TwisterStatus.PASS, True, TwisterStatus.NONE, ), ( - "", + "On TC_END: Ztest case 'example' is not known in {} running suite(s)", "SKIP - test_example in 0 seconds", [], + {}, + {}, TwisterStatus.SKIP, True, TwisterStatus.NONE, ), ( - "", + "On TC_END: Ztest case 'example' is not known in {} running suite(s)", "FAIL - test_example in 0 seconds", [], + {}, + {}, TwisterStatus.FAIL, True, TwisterStatus.NONE, @@ -630,6 +647,8 @@ def test_get_harness(name): "not a ztest and no state for test_id", "START - test_testcase", [], + {}, + { 'test_id.testcase': { 'count': 1 } }, TwisterStatus.PASS, False, TwisterStatus.PASS, @@ -638,6 +657,8 @@ def test_get_harness(name): "not a ztest and no state for test_id", "START - test_testcase", [], + {}, + { 'test_id.testcase': { 'count': 1 } }, TwisterStatus.FAIL, False, TwisterStatus.FAIL, @@ -646,12 +667,14 @@ def test_get_harness(name): @pytest.mark.parametrize( - "exp_out, line, exp_suite_name, exp_status, ztest, state", + "exp_out, line, exp_suite_name, exp_started_suites, exp_started_cases, exp_status, ztest, state", TEST_DATA_7, ids=["testsuite", "testcase", "pass", "skip", "failed", "ztest pass", "ztest fail"], ) def test_test_handle( - tmp_path, caplog, exp_out, line, exp_suite_name, exp_status, ztest, state + tmp_path, caplog, exp_out, line, + exp_suite_name, exp_started_suites, exp_started_cases, + exp_status, ztest, state ): # Arrange line = line @@ -662,6 +685,7 @@ def test_test_handle( mock_testsuite = mock.Mock(id="id", testcases=[]) mock_testsuite.name = "mock_testsuite" mock_testsuite.harness_config = {} + mock_testsuite.ztest_suite_names = [] outdir = tmp_path / "gtest_out" outdir.mkdir() @@ -681,6 +705,9 @@ def test_test_handle( # Assert assert test_obj.detected_suite_names == exp_suite_name + assert test_obj.started_suites == exp_started_suites + assert test_obj.started_cases == exp_started_cases + assert exp_out in caplog.text if not "Running" in line and exp_out == "": assert test_obj.instance.testcases[0].status == exp_status diff --git a/scripts/tests/twister/test_runner.py b/scripts/tests/twister/test_runner.py index 3ab7de2fb935f4..24e5e4fb779985 100644 --- a/scripts/tests/twister/test_runner.py +++ b/scripts/tests/twister/test_runner.py @@ -1562,11 +1562,14 @@ def mock_determine_testcases(res): TESTDATA_7 = [ ( [ - 'z_ztest_unit_test__dummy_suite_name__dummy_test_name', - 'z_ztest_unit_test__dummy_suite_name__test_dummy_name', + 'z_ztest_unit_test__dummy_suite1_name__dummy_test_name1', + 'z_ztest_unit_test__dummy_suite2_name__test_dummy_name2', 'no match' ], - ['dummy_id.dummy_name', 'dummy_id.dummy_name'] + [ + ('dummy_id.dummy_suite1_name.dummy_name1'), + ('dummy_id.dummy_suite2_name.dummy_name2') + ] ), ( ['no match'], @@ -1599,6 +1602,7 @@ def test_projectbuilder_determine_testcases( instance_mock = mock.Mock() instance_mock.testcases = [] instance_mock.testsuite.id = 'dummy_id' + instance_mock.testsuite.ztest_suite_names = [] env_mock = mock.Mock() pb = ProjectBuilder(instance_mock, env_mock, mocked_jobserver) @@ -2137,13 +2141,11 @@ def test_projectbuilder_cmake(): instance_mock = mock.Mock() instance_mock.handler = 'dummy handler' instance_mock.build_dir = os.path.join('build', 'dir') - instance_mock.platform.name = 'frdm_k64f' env_mock = mock.Mock() pb = ProjectBuilder(instance_mock, env_mock, mocked_jobserver) pb.build_dir = 'build_dir' - pb.testsuite.platform = instance_mock.platform - pb.testsuite.extra_args = ['some', 'platform:frdm_k64f:args'] + pb.testsuite.extra_args = ['some', 'args'] pb.testsuite.extra_conf_files = ['some', 'files1'] pb.testsuite.extra_overlay_confs = ['some', 'files2'] pb.testsuite.extra_dtc_overlay_files = ['some', 'files3'] @@ -2156,7 +2158,7 @@ def test_projectbuilder_cmake(): assert res == cmake_res_mock pb.cmake_assemble_args.assert_called_once_with( - ['some', 'args'], + pb.testsuite.extra_args, pb.instance.handler, pb.testsuite.extra_conf_files, pb.testsuite.extra_overlay_confs, diff --git a/scripts/tests/twister/test_testplan.py b/scripts/tests/twister/test_testplan.py index eea3d3e9abefb0..b00d69ab06113d 100644 --- a/scripts/tests/twister/test_testplan.py +++ b/scripts/tests/twister/test_testplan.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (c) 2020 Intel Corporation +# Copyright (c) 2020-2024 Intel Corporation # # SPDX-License-Identifier: Apache-2.0 @@ -85,7 +85,8 @@ def test_get_all_testsuites_short(class_testplan, all_testsuites_dict): 'test_b.check_1', 'test_b.check_2', 'test_c.check_1', 'test_c.check_2', 'test_d.check_1.unit_1a', 'test_d.check_1.unit_1b', - 'test_e.check_1.1a', 'test_e.check_1.1b', + 'test_e.check_1.feature5.1a', + 'test_e.check_1.feature5.1b', 'test_config.main'] assert sorted(plan.get_all_tests()) == sorted(expected_tests) diff --git a/scripts/tests/twister/test_testsuite.py b/scripts/tests/twister/test_testsuite.py index e297b6b6d9cd6c..8d20902a5ebaf1 100644 --- a/scripts/tests/twister/test_testsuite.py +++ b/scripts/tests/twister/test_testsuite.py @@ -165,7 +165,7 @@ def test_scanpathresults_dunders(original, provided, expected): ), ScanPathResult( warnings=None, - matches=['1a', '1b'], + matches=['feature5.1a', 'feature5.1b'], has_registered_test_suites=False, has_run_registered_test_suites=True, has_test_main=False, diff --git a/scripts/tests/twister_blackbox/test_config.py b/scripts/tests/twister_blackbox/test_config.py index c05d18cdaa780a..2cad497055f5b5 100644 --- a/scripts/tests/twister_blackbox/test_config.py +++ b/scripts/tests/twister_blackbox/test_config.py @@ -13,6 +13,7 @@ import sys import json +# pylint: disable=no-name-in-module from conftest import ZEPHYR_BASE, TEST_DATA, testsuite_filename_mock from twisterlib.testplan import TestPlan @@ -55,13 +56,13 @@ def test_alt_config_root(self, out_path): assert str(sys_exit.value) == '0' - assert len(filtered_j) == 3 + assert len(filtered_j) == 4 @pytest.mark.parametrize( 'level, expected_tests', [ - ('smoke', 5), - ('acceptance', 6), + ('smoke', 6), + ('acceptance', 7), ], ids=['smoke', 'acceptance'] ) diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic/group2/src/main.c b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic/group2/src/main.c index 55c375965aeb94..798fd9756a8c15 100644 --- a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic/group2/src/main.c +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic/group2/src/main.c @@ -9,6 +9,8 @@ ZTEST_SUITE(a2_tests, NULL, NULL, NULL, NULL, NULL); +ZTEST_SUITE(a3_tests, NULL, NULL, NULL, NULL, NULL); + /** * @brief Test Asserts * @@ -34,3 +36,8 @@ ZTEST(a2_tests, test_assert2) zassert_equal(1, 1, "1 was not equal to 1"); zassert_equal_ptr(NULL, NULL, "NULL was not equal to NULL"); } + +ZTEST(a3_tests, test_assert1) +{ + zassert_true(1, "1 was false"); +} diff --git a/scripts/tests/twister_blackbox/test_filter.py b/scripts/tests/twister_blackbox/test_filter.py index 90ea95e6430751..d8dfd3575e4073 100644 --- a/scripts/tests/twister_blackbox/test_filter.py +++ b/scripts/tests/twister_blackbox/test_filter.py @@ -14,6 +14,7 @@ import json import re +# pylint: disable=no-name-in-module from conftest import ZEPHYR_BASE, TEST_DATA, testsuite_filename_mock from twisterlib.testplan import TestPlan @@ -83,11 +84,12 @@ def teardown_class(cls): @pytest.mark.parametrize( 'tag, expected_test_count', [ - ('device', 5), # dummy.agnostic.group1.subgroup1.assert - # dummy.agnostic.group1.subgroup2.assert - # dummy.agnostic.group2.assert1 - # dummy.agnostic.group2.assert2 - # dummy.agnostic.group2.assert3 + ('device', 6), # dummy.agnostic.group1.subgroup1.a1_1_tests.assert + # dummy.agnostic.group1.subgroup2.a2_2_tests.assert + # dummy.agnostic.group2.a2_tests.assert1 + # dummy.agnostic.group2.a2_tests.assert2 + # dummy.agnostic.group2.a2_tests.assert3 + # dummy.agnostic.group2.a3_tests.assert1 ('agnostic', 1) # dummy.device.group.assert ], ids=['no device', 'no agnostic'] @@ -144,7 +146,7 @@ def test_enable_slow(self, out_path): assert str(sys_exit.value) == '0' - assert len(filtered_j) == 5 + assert len(filtered_j) == 6 @mock.patch.object(TestPlan, 'TESTSUITE_FILENAME', testsuite_filename_mock) def test_enable_slow_only(self, out_path): @@ -172,7 +174,7 @@ def test_enable_slow_only(self, out_path): assert str(sys_exit.value) == '0' - assert len(filtered_j) == 3 + assert len(filtered_j) == 4 @pytest.mark.parametrize( 'arch, expected', diff --git a/scripts/tests/twister_blackbox/test_platform.py b/scripts/tests/twister_blackbox/test_platform.py index 83fe07b274b9c2..2e97fa293487c1 100644 --- a/scripts/tests/twister_blackbox/test_platform.py +++ b/scripts/tests/twister_blackbox/test_platform.py @@ -36,7 +36,7 @@ class TestPlatform: 'built_configurations': 2, 'failed_configurations': 0, 'errored_configurations': 0, - 'executed_test_cases': 8, + 'executed_test_cases': 10, 'skipped_test_cases': 2, 'platform_count': 2, 'executed_on_platform': 4, @@ -129,7 +129,7 @@ def test_force_platform(self, out_path): assert str(sys_exit.value) == '0' - assert len(filtered_j) == 12 + assert len(filtered_j) == 14 def test_platform(self, out_path): path = os.path.join(TEST_DATA, 'tests', 'dummy') diff --git a/scripts/tests/twister_blackbox/test_printouts.py b/scripts/tests/twister_blackbox/test_printouts.py index 3f65549b8ea9c0..853797354f44cd 100644 --- a/scripts/tests/twister_blackbox/test_printouts.py +++ b/scripts/tests/twister_blackbox/test_printouts.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (c) 2023 Intel Corporation +# Copyright (c) 2023-2024 Intel Corporation # # SPDX-License-Identifier: Apache-2.0 """ @@ -41,17 +41,18 @@ class TestPrintOuts: ( os.path.join(TEST_DATA, 'tests', 'dummy', 'agnostic'), [ - 'dummy.agnostic.group1.subgroup1.assert', - 'dummy.agnostic.group1.subgroup2.assert', - 'dummy.agnostic.group2.assert1', - 'dummy.agnostic.group2.assert2', - 'dummy.agnostic.group2.assert3' + 'dummy.agnostic.group1.subgroup1.a1_1_tests.assert', + 'dummy.agnostic.group1.subgroup2.a1_2_tests.assert', + 'dummy.agnostic.group2.a2_tests.assert1', + 'dummy.agnostic.group2.a2_tests.assert2', + 'dummy.agnostic.group2.a3_tests.assert1', + 'dummy.agnostic.group2.a2_tests.assert3' ] ), ( os.path.join(TEST_DATA, 'tests', 'dummy', 'device'), [ - 'dummy.device.group.assert' + 'dummy.device.group.d_tests.assert' ] ), ] @@ -64,11 +65,12 @@ class TestPrintOuts: '└── Tests\n' \ ' └── dummy\n' \ ' └── agnostic\n' \ - ' ├── dummy.agnostic.group1.subgroup1.assert\n' \ - ' ├── dummy.agnostic.group1.subgroup2.assert\n' \ - ' ├── dummy.agnostic.group2.assert1\n' \ - ' ├── dummy.agnostic.group2.assert2\n' \ - ' └── dummy.agnostic.group2.assert3\n' + ' ├── dummy.agnostic.group1.subgroup1.a1_1_tests.assert\n' \ + ' ├── dummy.agnostic.group1.subgroup2.a1_2_tests.assert\n' \ + ' ├── dummy.agnostic.group2.a2_tests.assert1\n' \ + ' ├── dummy.agnostic.group2.a2_tests.assert2\n' \ + ' ├── dummy.agnostic.group2.a2_tests.assert3\n' \ + ' └── dummy.agnostic.group2.a3_tests.assert1\n' ), ( os.path.join(TEST_DATA, 'tests', 'dummy', 'device'), @@ -77,7 +79,7 @@ class TestPrintOuts: '└── Tests\n' ' └── dummy\n' ' └── device\n' - ' └── dummy.device.group.assert\n' + ' └── dummy.device.group.d_tests.assert\n' ), ] diff --git a/scripts/tests/twister_blackbox/test_report.py b/scripts/tests/twister_blackbox/test_report.py index 2db1006bc5aa92..3a145fd59b37cf 100644 --- a/scripts/tests/twister_blackbox/test_report.py +++ b/scripts/tests/twister_blackbox/test_report.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (c) 2023 Intel Corporation +# Copyright (c) 2023-2024 Intel Corporation # # SPDX-License-Identifier: Apache-2.0 """ @@ -350,12 +350,12 @@ def test_log_file(self, capfd, test_path, test_platforms, out_path, file_name): ( os.path.join(TEST_DATA, 'tests', 'dummy'), ['--detailed-skipped-report'], - {'qemu_x86/atom': 5, 'intel_adl_crb/alder_lake': 1} + {'qemu_x86/atom': 6, 'intel_adl_crb/alder_lake': 1} ), ( os.path.join(TEST_DATA, 'tests', 'dummy'), ['--detailed-skipped-report', '--report-filtered'], - {'qemu_x86/atom': 6, 'intel_adl_crb/alder_lake': 6} + {'qemu_x86/atom': 7, 'intel_adl_crb/alder_lake': 7} ), ], ids=['dummy tests', 'dummy tests with filtered'] diff --git a/scripts/tests/twister_blackbox/test_runner.py b/scripts/tests/twister_blackbox/test_runner.py index a4a253fbff7a80..41eea8987b619f 100644 --- a/scripts/tests/twister_blackbox/test_runner.py +++ b/scripts/tests/twister_blackbox/test_runner.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (c) 2023 Intel Corporation +# Copyright (c) 2023-2024 Intel Corporation # # SPDX-License-Identifier: Apache-2.0 """ @@ -54,7 +54,7 @@ class TestRunner: 'built_configurations': 0, 'failed_configurations': 0, 'errored_configurations': 0, - 'executed_test_cases': 8, + 'executed_test_cases': 10, 'skipped_test_cases': 0, 'platform_count': 2, 'executed_on_platform': 4, diff --git a/scripts/tests/twister_blackbox/test_shuffle.py b/scripts/tests/twister_blackbox/test_shuffle.py index ade1267b482271..412d97a619bf93 100644 --- a/scripts/tests/twister_blackbox/test_shuffle.py +++ b/scripts/tests/twister_blackbox/test_shuffle.py @@ -10,10 +10,10 @@ import mock import os import pytest -import re import sys import json +# pylint: disable=no-name-in-module from conftest import ZEPHYR_BASE, TEST_DATA, testsuite_filename_mock from twisterlib.testplan import TestPlan @@ -65,14 +65,8 @@ def test_shuffle_tests(self, out_path, seed, ratio, expected_order): with open(os.path.join(out_path, 'testplan.json')) as f: j = json.load(f) - filtered_j = [ - (ts['platform'], ts['name'], tc['identifier']) \ - for ts in j['testsuites'] \ - for tc in ts['testcases'] if 'reason' not in tc - ] - testcases = [re.sub(r'\.assert[^\.]*?$', '', j[2]) for j in filtered_j] - testsuites = list(dict.fromkeys(testcases)) + testsuites = [os.path.basename(ts['name']) for ts in j['testsuites']] assert testsuites == expected_order diff --git a/scripts/tests/twister_blackbox/test_testlist.py b/scripts/tests/twister_blackbox/test_testlist.py index 1ef93f072b6b50..ad8eaeddfaf557 100644 --- a/scripts/tests/twister_blackbox/test_testlist.py +++ b/scripts/tests/twister_blackbox/test_testlist.py @@ -13,6 +13,7 @@ import sys import json +# pylint: disable=no-name-in-module from conftest import ZEPHYR_BASE, TEST_DATA, testsuite_filename_mock, clear_log_in_test from twisterlib.testplan import TestPlan @@ -71,4 +72,4 @@ def test_save_tests(self, out_path): for tc in ts['testcases'] if 'reason' not in tc ] - assert len(filtered_j) == 5 + assert len(filtered_j) == 6 diff --git a/scripts/tests/twister_blackbox/test_testplan.py b/scripts/tests/twister_blackbox/test_testplan.py index 915653a33e15e0..8834e03ead039c 100644 --- a/scripts/tests/twister_blackbox/test_testplan.py +++ b/scripts/tests/twister_blackbox/test_testplan.py @@ -13,6 +13,7 @@ import sys import json +# pylint: disable=no-name-in-module from conftest import ZEPHYR_BASE, TEST_DATA, testsuite_filename_mock from twisterlib.testplan import TestPlan from twisterlib.error import TwisterRuntimeError @@ -20,7 +21,7 @@ class TestTestPlan: TESTDATA_1 = [ - ('dummy.agnostic.group2.assert1', SystemExit, 3), + ('dummy.agnostic.group2.a2_tests.assert1', SystemExit, 4), ( os.path.join('scripts', 'tests', 'twister_blackbox', 'test_data', 'tests', 'dummy', 'agnostic', 'group1', 'subgroup1', @@ -30,12 +31,12 @@ class TestTestPlan: ), ] TESTDATA_2 = [ - ('buildable', 6), - ('runnable', 4), + ('buildable', 7), + ('runnable', 5), ] TESTDATA_3 = [ (True, 1), - (False, 6), + (False, 7), ] @classmethod @@ -52,7 +53,7 @@ def teardown_class(cls): @pytest.mark.parametrize( 'test, expected_exception, expected_subtest_count', TESTDATA_1, - ids=['valid', 'invalid'] + ids=['valid', 'not found'] ) @mock.patch.object(TestPlan, 'TESTSUITE_FILENAME', testsuite_filename_mock) def test_subtest(self, out_path, test, expected_exception, expected_subtest_count): From 18451bca44df36e479ae4eec27b7eeb39c0b05e9 Mon Sep 17 00:00:00 2001 From: Dmitrii Golovanov Date: Sat, 19 Oct 2024 18:51:29 +0200 Subject: [PATCH 025/261] doc: twister: Update test naming and application diagram Update Test Application diagram as well as Test Scenario and Test Case naming conventions to make them more clear and aligned to Ztest suite name included as a part of Test Case name. Signed-off-by: Dmitrii Golovanov --- .../test/figures/twister_test_project.svg | 2 +- doc/develop/test/twister.rst | 65 ++++++++++--------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/doc/develop/test/figures/twister_test_project.svg b/doc/develop/test/figures/twister_test_project.svg index f21a45c2971ae1..75440d6bda601f 100644 --- a/doc/develop/test/figures/twister_test_project.svg +++ b/doc/develop/test/figures/twister_test_project.svg @@ -1,4 +1,4 @@ -
Test Framework (ZTEST)
Test Framework (ZTEST)
Test Suite (ZTEST_SUITE)
Test Suite (ZTEST_SUITE)
+ suite_name = "foo_bar_feature_aspect"
+ suite_name = "foo_bar_feature_aspect"

Test (ZTEST*)
Test (ZTEST*)
+ test_name = "test_buzz_and_blink"
+ test_name = "test_buzz_and_blink"

Test Scenario
(name_section.name_subsection)
Test Scenario...

+ tags:
+ levels: 
+ filter:
+ required_*:
+ arch_*:
+ platform_*: 
+ extra_*:
+ harness:
+ harness_config:

+ tags:...
Test Scenario
(name_section.name_subsection)
Test Scenario...

+ tags:
+ levels: 
+ filter:
+ required_*:
+ arch_*:
+ platform_*: 
+ extra_*:
+ harness:
+ harness_config:

+ tags:...
tests:
tests:
Test Scenario
(name_section.name_subsection)
Test Scenario...

+ tags:
+ levels: 
+ filter:
+ required_*:
+ arch_*:
+ platform_*: 
+ extra_*:

+ harness:
+ harness_config:

+ tags:...
CMakeList.txt
CMakeList.txt
+ project(foo-bar-feature)

+ project(foo-bar-feature)
./src (Test Project Implementation)
./src (Test Project Implementation)
prj.conf
prj.conf
+ Kconfig:
+ Kconfig:
Test Application binary
Test Application binary
Twister
Twister
Test Instance
Test Instance
+ outdir
+ outdir
+ testsuite:
+ testsuite:
+ platform:
+ platform:
+ testcases: []
+ testcases: []
+ status:
+ status:
+ reason:
+ reason:
+ execution_time:
+ execution_time:
+ retries:
+ retries:

Test Suite (test specification)
Test Suite (test specification)
+ yamlfile
+ yamlfile
+ id
+ id
+ testcases: []
+ testcases: []
+ ztest_suite_names: []
+ ztest_suite_names: []
+ name
+ name

Test Case
Test Case
+ testsuite:
+ testsuite:
+ status:
+ status:
+ reason:
+ reason:
+ output:
+ output:
+ duration:
+ duration:
+ name:
+ name:

Legend:
Legend:
Test Instance (Test Application) 
Test Instance (Test Application) 
Execution time-specific Test properties
Execution time-specific Test properties
Elementary Test
Elementary Test
tests/foo/bar/feature/name_section.name_subsection
tests/foo/bar/feature/name_section.name_subsection
name_section.name_subsection.buzz_and_blink
name_section.name_subsection.buzz_and_blink
Zephyr Test Application Project (tests/foo/bar/feature)
Zephyr Test Application Project (tests/foo/bar/feature)
Test Configuration (testcase.yaml)
Test Configuration (testcase.yaml)
build & run
build & run
Twister parameters:

--arch
--platform
--level

... etc. 
Twister parameters...
select
select
ELF symbols and application log parsing
ELF symbols and application log parsing
Text is not SVG - cannot display
\ No newline at end of file +
Zephyr Test Framework (Ztest)
Zephyr Test Framework (Ztest)
Ztest Test Suite (ZTEST_SUITE)
Ztest Test Suite (ZTEST_SUITE)
+ suite_name = "foo_bar_aspect"
+ suite_name = "foo_bar_aspect"

Ztest Test (ZTEST*)
Ztest Test (ZTEST*)
+ test_name = "test_buzz_and_blink"
+ test_name = "test_buzz_and_blink"

Test Scenario
(name_section.name_subsection)
Test Scenario...

+ tags:
+ levels: 
+ filter:
+ required_*:
+ arch_*:
+ platform_*: 
+ extra_*:
+ harness:
+ harness_config:

+ tags:...
Test Scenario
(name_section.name_subsection)
Test Scenario...

+ tags:
+ levels: 
+ filter:
+ required_*:
+ arch_*:
+ platform_*: 
+ extra_*:
+ harness:
+ harness_config:

+ tags:...
tests:
tests:
Test Scenario
(section_name.subsection_name)
Test Scenario...

+ tags:
+ levels: 
+ filter:
+ required_*:
+ arch_*:
+ platform_*: 
+ extra_*:

+ harness:
+ harness_config:

+ tags:...
CMakeList.txt
CMakeList.txt
+ project(foo-bar-feature)

+ project(foo-bar-feature)
./src (Test Project Implementation)
./src (Test Project Implementation)
prj.conf
prj.conf
+ Kconfig:
+ Kconfig:
Test Application binary
Test Application binary
Twister
Twister
Test Instance
Test Instance
+ outdir
+ outdir
+ testsuite:
+ testsuite:
+ platform:
+ platform:
+ testcases: []
+ testcases: []
+ status:
+ status:
+ reason:
+ reason:
+ execution_time:
+ execution_time:
+ retries:
+ retries:

Test Suite (test specification)
Test Suite (test specification)
+ yamlfile
+ yamlfile
+ testcases: []
+ testcases: []
+ id
+ id
+ name
+ name
+ ztest_suite_names: []
+ ztest_suite_names: []

Test Case
Test Case
+ testsuite:
+ testsuite:
+ status:
+ status:
+ reason:
+ reason:
+ output:
+ output:
+ duration:
+ duration:
+ name:
+ name:

Legend:
Legend:
Test Instance (Test Application) 
Test Instance (Test Application) 
Execution time-specific Test properties
Execution time-specific Test properties
Elementary Test
Elementary Test
tests/foo/bar/feature/section_name.subsection_name
tests/foo/bar/feature/section_name.subsection_name
section_name.subsection_name.foo_bar_aspect.buzz_and_blink
section_name.subsection_name.foo_bar_aspect.buzz_and_blink
Zephyr Test Application Project (tests/foo/bar/feature)
Zephyr Test Application Project (tests/foo/bar/feature)
Test Configuration (testcase.yaml)
Test Configuration (testcase.yaml)
build & run
build & run
Twister parameters:

--arch
--platform
--level

... etc. 
Twister parameters...
select
select
ELF symbols and application log parsing
ELF symbols and application log parsing
section_name.subsection_name
section_name.subsection_name
Text is not SVG - cannot display
\ No newline at end of file diff --git a/doc/develop/test/twister.rst b/doc/develop/test/twister.rst index 685c70ab886576..8d943279a3dc69 100644 --- a/doc/develop/test/twister.rst +++ b/doc/develop/test/twister.rst @@ -223,57 +223,60 @@ Tests Tests are detected by the presence of a ``testcase.yaml`` or a ``sample.yaml`` files in the application's project directory. This test application -configuration file may contain one or more entries in the tests section each -identifying a test scenario. +configuration file may contain one or more entries in the ``tests:`` section each +identifying a Test Scenario. .. _twister_test_project_diagram: .. figure:: figures/twister_test_project.svg - :alt: Twister and a Test applications' project. + :alt: Twister and a Test application project. :figclass: align-center - Twister and a Test applications' project. + Twister and a Test application project. Test application configurations are written using the YAML syntax and share the same structure as samples. -A test scenario is a set of conditions or variables, defined in test scenario -entry, under which a set of test suites will be executed. Can be used -interchangeably with test scenario entry. +A Test Scenario is a set of conditions and variables defined in a Test Scenario +entry, under which a set of Test Suites will be built and executed. -A test suite is a collection of test cases that are intended to be used to test -a software program to ensure it meets certain requirements. The test cases in a -test suite are often related or meant to be executed together. +A Test Suite is a collection of Test Cases which are intended to be used to test +a software program to ensure it meets certain requirements. The Test Cases in a +Test Suite are either related or meant to be executed together. -The name of each test scenario needs to be unique in the context of the overall +The name of each Test Scenario needs to be unique in the context of the overall test application and has to follow basic rules: -#. The format of the test scenario identifier shall be a string without any spaces or +#. The format of the Test Scenario identifier shall be a string without any spaces or special characters (allowed characters: alphanumeric and [\_=]) consisting - of multiple sections delimited with a dot (.). + of multiple sections delimited with a dot (``.``). -#. Each test scenario identifier shall start with a section followed by a - subsection separated by a dot. For example, a test scenario that covers - semaphores in the kernel shall start with ``kernel.semaphore``. +#. Each Test Scenario identifier shall start with a section name followed by a + subsection names delimited with a dot (``.``). For example, a test scenario + that covers semaphores in the kernel shall start with ``kernel.semaphore``. -#. All test scenario identifiers within a ``testcase.yaml`` file need to be unique. For - example a ``testcase.yaml`` file covering semaphores in the kernel can have: +#. All Test Scenario identifiers within a ``testcase.yaml`` file need to be unique. + For example a ``testcase.yaml`` file covering semaphores in the kernel can have: * ``kernel.semaphore``: For general semaphore tests * ``kernel.semaphore.stress``: Stress testing semaphores in the kernel. -#. Depending on the nature of the test, an identifier can consist of at least - two sections: +#. The full canonical name of a Test Suite is: + ``/`` - * Ztest tests: The individual test cases in the ztest testsuite will be - concatenated by dot (``.``) to the identifier in the ``testcase.yaml`` file - generating unique identifiers for every test case in the suite. +#. Depending on the Test Suite implementation, its Test Case identifiers consist + of **at least three sections** delimited with a dot (``.``): - * Standalone tests and samples: This type of test should at least have 3 - sections concatnated by dot (``.``) in the test scenario identifier in the - ``testcase.yaml`` (or ``sample.yaml``) file. - The last section of the name shall signify the test case itself. + * **Ztest tests**: + a Test Scenario identifier from the corresponding ``testcase.yaml`` file, + a Ztest suite name, and a Ztest test name: + ``..`` + + * **Standalone tests and samples**: + a Test Scenario identifier from the corresponding ``testcase.yaml`` (or + ``sample.yaml``) file where the last section signifies the standalone + Test Case name, for example: ``debug.coredump.logging_backend``. The following is an example test configuration with a few options that are @@ -316,12 +319,10 @@ related to the sample and what is being demonstrated: tags: tests min_ram: 16 -The full canonical name for each test scenario is:``/`` - -A test scenario entry is a a block or entry starting with test scenario -identifier in the YAML files. +A Test Scenario entry in the ``tests:`` YAML dictionary has its Test Scenario +identifier as a key. -Each test scenario entry in the test application configuration can define the +Each Test Scenario entry in the Test Application configuration can define the following key/value pairs: .. _test_config_args: From e11aecaed5aff6334a77b296de259b763a08e0ca Mon Sep 17 00:00:00 2001 From: Dmitrii Golovanov Date: Fri, 1 Nov 2024 12:07:02 +0100 Subject: [PATCH 026/261] twister: fix Ztest C++ test names extraction from ELF Fix Ztest test function name extraction from ELF symbols for C++ compiled binaries where symbol names need additional 'demangling' to match with corresponding test names. The `c++filt` utility (part of binutils) is called for demangling when it is needed. Twister test suite extension and adjustment. Signed-off-by: Dmitrii Golovanov --- scripts/pylib/twister/twisterlib/runner.py | 41 +++++++++++----- scripts/tests/twister/test_runner.py | 25 ++++++++-- .../test_data/test_config.yaml | 5 +- .../group1/subgroup1/CMakeLists.txt | 8 ++++ .../agnostic_cpp/group1/subgroup1/prj.conf | 1 + .../group1/subgroup1/src/main.cpp | 28 +++++++++++ .../group1/subgroup1/test_data.yaml | 10 ++++ .../group1/subgroup2/CMakeLists.txt | 8 ++++ .../agnostic_cpp/group1/subgroup2/prj.conf | 1 + .../group1/subgroup2/src/main.cpp | 27 +++++++++++ .../group1/subgroup2/test_data.yaml | 11 +++++ .../dummy/agnostic_cpp/group2/CMakeLists.txt | 8 ++++ .../tests/dummy/agnostic_cpp/group2/prj.conf | 1 + .../dummy/agnostic_cpp/group2/src/main.cpp | 48 +++++++++++++++++++ .../dummy/agnostic_cpp/group2/src/submain.cpp | 28 +++++++++++ .../dummy/agnostic_cpp/group2/test_data.yaml | 9 ++++ scripts/tests/twister_blackbox/test_filter.py | 15 +++--- .../tests/twister_blackbox/test_platform.py | 24 +++++++++- scripts/tests/twister_blackbox/test_report.py | 4 +- scripts/tests/twister_blackbox/test_runner.py | 2 +- .../tests/twister_blackbox/test_shuffle.py | 19 ++++---- 21 files changed, 288 insertions(+), 35 deletions(-) create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/CMakeLists.txt create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/prj.conf create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/src/main.cpp create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/test_data.yaml create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/CMakeLists.txt create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/prj.conf create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/src/main.cpp create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/test_data.yaml create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/CMakeLists.txt create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/prj.conf create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/src/main.cpp create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/src/submain.cpp create mode 100644 scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/test_data.yaml diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index 83ca94f9fb5f24..172add5367edf0 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -814,6 +814,10 @@ def __init__(self, instance: TestInstance, env: TwisterEnv, jobserver, **kwargs) self.env = env self.duts = None + @property + def trace(self) -> bool: + return self.options.verbose > 2 + def log_info(self, filename, inline_logs, log_testcases=False): filename = os.path.abspath(os.path.realpath(filename)) if inline_logs: @@ -1087,6 +1091,18 @@ def process(self, pipeline, done, message, lock, results): self.instance.reason = reason self.instance.add_missing_case_status(TwisterStatus.BLOCK, reason) + def demangle(self, symbol_name): + if symbol_name[:2] == '_Z': + try: + cpp_filt = subprocess.run('c++filt', input=symbol_name, text=True, check=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if self.trace: + logger.debug(f"Demangle: '{symbol_name}'==>'{cpp_filt.stdout}'") + return cpp_filt.stdout.strip() + except Exception as e: + logger.error(f"Failed to demangle '{symbol_name}': {e}") + return symbol_name + def determine_testcases(self, results): yaml_testsuite_name = self.instance.testsuite.id logger.debug(f"Determine test cases for test suite: {yaml_testsuite_name}") @@ -1102,19 +1118,22 @@ def determine_testcases(self, results): for sym in section.iter_symbols(): # It is only meant for new ztest fx because only new ztest fx exposes test functions # precisely. - + m_ = new_ztest_unit_test_regex.search(sym.name) + if not m_: + continue + # Demangle C++ symbols + m_ = new_ztest_unit_test_regex.search(self.demangle(sym.name)) + if not m_: + continue # The 1st capture group is new ztest suite name. # The 2nd capture group is new ztest unit test name. - matches = new_ztest_unit_test_regex.findall(sym.name) - if matches: - for m in matches: - new_ztest_suite = m[0] - if new_ztest_suite not in self.instance.testsuite.ztest_suite_names: - logger.warning(f"Unexpected Ztest suite '{new_ztest_suite}' " - f"not present in: {self.instance.testsuite.ztest_suite_names}") - test_func_name = m[1].replace("test_", "", 1) - testcase_id = f"{yaml_testsuite_name}.{new_ztest_suite}.{test_func_name}" - detected_cases.append(testcase_id) + new_ztest_suite = m_[1] + if new_ztest_suite not in self.instance.testsuite.ztest_suite_names: + logger.warning(f"Unexpected Ztest suite '{new_ztest_suite}' " + f"not present in: {self.instance.testsuite.ztest_suite_names}") + test_func_name = m_[2].replace("test_", "", 1) + testcase_id = f"{yaml_testsuite_name}.{new_ztest_suite}.{test_func_name}" + detected_cases.append(testcase_id) if detected_cases: logger.debug(f"Detected Ztest cases: [{', '.join(detected_cases)}] in {elf_file}") diff --git a/scripts/tests/twister/test_runner.py b/scripts/tests/twister/test_runner.py index 24e5e4fb779985..29459d585498dd 100644 --- a/scripts/tests/twister/test_runner.py +++ b/scripts/tests/twister/test_runner.py @@ -56,6 +56,7 @@ def mocked_instance(tmp_path): def mocked_env(): env = mock.Mock() options = mock.Mock() + options.verbose = 2 env.options = options return env @@ -1571,6 +1572,24 @@ def mock_determine_testcases(res): ('dummy_id.dummy_suite2_name.dummy_name2') ] ), + ( + [ + 'z_ztest_unit_test__dummy_suite2_name__test_dummy_name2', + 'z_ztest_unit_test__bad_suite3_name_no_test', + '_ZN12_GLOBAL__N_1L54z_ztest_unit_test__dummy_suite3_name__test_dummy_name4E', + '_ZN12_GLOBAL__N_1L54z_ztest_unit_test__dummy_suite3_name__test_bad_name1E', + '_ZN12_GLOBAL__N_1L51z_ztest_unit_test_dummy_suite3_name__test_bad_name2E', + '_ZN12_GLOBAL__N_1L54z_ztest_unit_test__dummy_suite3_name__test_dummy_name5E', + '_ZN15foobarnamespaceL54z_ztest_unit_test__dummy_suite3_name__test_dummy_name6E', + ], + [ + ('dummy_id.dummy_suite2_name.dummy_name2'), + ('dummy_id.dummy_suite3_name.dummy_name4'), + ('dummy_id.dummy_suite3_name.bad_name1E'), + ('dummy_id.dummy_suite3_name.dummy_name5'), + ('dummy_id.dummy_suite3_name.dummy_name6'), + ] + ), ( ['no match'], [] @@ -1580,10 +1599,11 @@ def mock_determine_testcases(res): @pytest.mark.parametrize( 'symbols_names, added_tcs', TESTDATA_7, - ids=['two hits, one miss', 'nothing'] + ids=['two hits, one miss', 'demangle', 'nothing'] ) def test_projectbuilder_determine_testcases( mocked_jobserver, + mocked_env, symbols_names, added_tcs ): @@ -1603,9 +1623,8 @@ def test_projectbuilder_determine_testcases( instance_mock.testcases = [] instance_mock.testsuite.id = 'dummy_id' instance_mock.testsuite.ztest_suite_names = [] - env_mock = mock.Mock() - pb = ProjectBuilder(instance_mock, env_mock, mocked_jobserver) + pb = ProjectBuilder(instance_mock, mocked_env, mocked_jobserver) with mock.patch('twisterlib.runner.ELFFile', elf_mock), \ mock.patch('builtins.open', mock.mock_open()): diff --git a/scripts/tests/twister_blackbox/test_data/test_config.yaml b/scripts/tests/twister_blackbox/test_data/test_config.yaml index d7e4828350cf9a..6bfe24a4e819e6 100644 --- a/scripts/tests/twister_blackbox/test_data/test_config.yaml +++ b/scripts/tests/twister_blackbox/test_data/test_config.yaml @@ -6,9 +6,10 @@ levels: description: > A plan to be used verifying basic features adds: - - dummy.agnostic.* + - dummy.agnostic\..* - name: acceptance description: > More coverage adds: - - dummy.* + - dummy.agnostic\..* + - dummy.device\..* diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/CMakeLists.txt b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/CMakeLists.txt new file mode 100644 index 00000000000000..3ffe630f1ad989 --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(integration) + +FILE(GLOB app_sources src/*.cpp) +target_sources(app PRIVATE ${app_sources}) diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/prj.conf b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/prj.conf new file mode 100644 index 00000000000000..9467c2926896dd --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/prj.conf @@ -0,0 +1 @@ +CONFIG_ZTEST=y diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/src/main.cpp b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/src/main.cpp new file mode 100644 index 00000000000000..b37d02646cfcbc --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/src/main.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023-2024 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + + +// global namespace + +ZTEST_SUITE(a1_1_tests, NULL, NULL, NULL, NULL, NULL); + +/** + * @brief Test Asserts + * + * This test verifies various assert macros provided by ztest. + * + */ +ZTEST(a1_1_tests, test_assert) +{ + zassert_true(1, "1 was false"); + zassert_false(0, "0 was true"); + zassert_is_null(NULL, "NULL was not NULL"); + zassert_not_null("foo", "\"foo\" was NULL"); + zassert_equal(1, 1, "1 was not equal to 1"); + zassert_equal_ptr(NULL, NULL, "NULL was not equal to NULL"); +} diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/test_data.yaml b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/test_data.yaml new file mode 100644 index 00000000000000..7d8a6420541446 --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup1/test_data.yaml @@ -0,0 +1,10 @@ +tests: + dummy.agnostic_cpp.group1.subgroup1: + platform_allow: + - native_sim + integration_platforms: + - native_sim + tags: + - agnostic + - cpp + - subgrouped diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/CMakeLists.txt b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/CMakeLists.txt new file mode 100644 index 00000000000000..3ffe630f1ad989 --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(integration) + +FILE(GLOB app_sources src/*.cpp) +target_sources(app PRIVATE ${app_sources}) diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/prj.conf b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/prj.conf new file mode 100644 index 00000000000000..9467c2926896dd --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/prj.conf @@ -0,0 +1 @@ +CONFIG_ZTEST=y diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/src/main.cpp b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/src/main.cpp new file mode 100644 index 00000000000000..0ac835a959c042 --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/src/main.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023-2024 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +// global namespace + +ZTEST_SUITE(a1_2_tests, NULL, NULL, NULL, NULL, NULL); + +/** + * @brief Test Asserts + * + * This test verifies various assert macros provided by ztest. + * + */ +ZTEST(a1_2_tests, test_assert) +{ + zassert_true(1, "1 was false"); + zassert_false(0, "0 was true"); + zassert_is_null(NULL, "NULL was not NULL"); + zassert_not_null("foo", "\"foo\" was NULL"); + zassert_equal(1, 1, "1 was not equal to 1"); + zassert_equal_ptr(NULL, NULL, "NULL was not equal to NULL"); +} diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/test_data.yaml b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/test_data.yaml new file mode 100644 index 00000000000000..f0146d3e193448 --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group1/subgroup2/test_data.yaml @@ -0,0 +1,11 @@ +tests: + dummy.agnostic_cpp.group1.subgroup2: + build_only: true + platform_allow: + - native_sim + integration_platforms: + - native_sim + tags: + - agnostic + - cpp + - subgrouped diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/CMakeLists.txt b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/CMakeLists.txt new file mode 100644 index 00000000000000..3ffe630f1ad989 --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(integration) + +FILE(GLOB app_sources src/*.cpp) +target_sources(app PRIVATE ${app_sources}) diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/prj.conf b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/prj.conf new file mode 100644 index 00000000000000..9467c2926896dd --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/prj.conf @@ -0,0 +1 @@ +CONFIG_ZTEST=y diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/src/main.cpp b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/src/main.cpp new file mode 100644 index 00000000000000..1c86457e76a0d6 --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/src/main.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023-2024 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + + +namespace +{ + +ZTEST_SUITE(a2_tests, NULL, NULL, NULL, NULL, NULL); + +ZTEST_SUITE(a3_tests, NULL, NULL, NULL, NULL, NULL); + +/** + * @brief Test Asserts + * + * This test verifies various assert macros provided by ztest. + * + */ +ZTEST(a2_tests, test_assert1) +{ + zassert_true(1, "1 was false"); + zassert_false(0, "0 was true"); + zassert_is_null(NULL, "NULL was not NULL"); + zassert_not_null("foo", "\"foo\" was NULL"); + zassert_equal(1, 1, "1 was not equal to 1"); + zassert_equal_ptr(NULL, NULL, "NULL was not equal to NULL"); +} + +ZTEST(a2_tests, test_assert2) +{ + zassert_true(1, "1 was false"); + zassert_false(0, "0 was true"); + zassert_is_null(NULL, "NULL was not NULL"); + zassert_not_null("foo", "\"foo\" was NULL"); + zassert_equal(1, 1, "1 was not equal to 1"); + zassert_equal_ptr(NULL, NULL, "NULL was not equal to NULL"); +} + +ZTEST(a3_tests, test_assert1) +{ + zassert_true(1, "1 was false"); +} + +} // namsespace diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/src/submain.cpp b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/src/submain.cpp new file mode 100644 index 00000000000000..bf9c90536b2d20 --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/src/submain.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023-2024 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +namespace foo_namespace +{ + +/** + * @brief Test Asserts + * + * This test verifies various assert macros provided by ztest. + * + */ +ZTEST(a2_tests, test_assert3) +{ + zassert_true(1, "1 was false"); + zassert_false(0, "0 was true"); + zassert_is_null(NULL, "NULL was not NULL"); + zassert_not_null("foo", "\"foo\" was NULL"); + zassert_equal(1, 1, "1 was not equal to 1"); + zassert_equal_ptr(NULL, NULL, "NULL was not equal to NULL"); +} + +} // foo_namespace diff --git a/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/test_data.yaml b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/test_data.yaml new file mode 100644 index 00000000000000..1a93b591460f6e --- /dev/null +++ b/scripts/tests/twister_blackbox/test_data/tests/dummy/agnostic_cpp/group2/test_data.yaml @@ -0,0 +1,9 @@ +tests: + dummy.agnostic_cpp.group2: + platform_allow: + - native_sim + integration_platforms: + - native_sim + tags: + - agnostic + - cpp diff --git a/scripts/tests/twister_blackbox/test_filter.py b/scripts/tests/twister_blackbox/test_filter.py index d8dfd3575e4073..3558296d40b110 100644 --- a/scripts/tests/twister_blackbox/test_filter.py +++ b/scripts/tests/twister_blackbox/test_filter.py @@ -82,24 +82,27 @@ def teardown_class(cls): pass @pytest.mark.parametrize( - 'tag, expected_test_count', + 'tags, expected_test_count', [ - ('device', 6), # dummy.agnostic.group1.subgroup1.a1_1_tests.assert + (['device', 'cpp'], 6), + # dummy.agnostic.group1.subgroup1.a1_1_tests.assert # dummy.agnostic.group1.subgroup2.a2_2_tests.assert # dummy.agnostic.group2.a2_tests.assert1 # dummy.agnostic.group2.a2_tests.assert2 # dummy.agnostic.group2.a2_tests.assert3 # dummy.agnostic.group2.a3_tests.assert1 - ('agnostic', 1) # dummy.device.group.assert + (['agnostic'], 1) # dummy.device.group.assert ], - ids=['no device', 'no agnostic'] + ids=['no device, no cpp', 'no agnostic'] ) @mock.patch.object(TestPlan, 'TESTSUITE_FILENAME', testsuite_filename_mock) - def test_exclude_tag(self, out_path, tag, expected_test_count): + def test_exclude_tag(self, out_path, tags, expected_test_count): test_platforms = ['qemu_x86', 'intel_adl_crb'] path = os.path.join(TEST_DATA, 'tests', 'dummy') args = ['-i', '--outdir', out_path, '-T', path, '-y'] + \ - ['--exclude-tag', tag] + \ + [val for pair in zip( + ['--exclude-tag'] * len(tags), tags + ) for val in pair] + \ [val for pair in zip( ['-p'] * len(test_platforms), test_platforms ) for val in pair] diff --git a/scripts/tests/twister_blackbox/test_platform.py b/scripts/tests/twister_blackbox/test_platform.py index 2e97fa293487c1..0c644dcff5aee5 100644 --- a/scripts/tests/twister_blackbox/test_platform.py +++ b/scripts/tests/twister_blackbox/test_platform.py @@ -64,6 +64,27 @@ class TestPlatform: 'only_built': 0 } ), + ( + os.path.join(TEST_DATA, 'tests', 'dummy', 'agnostic_cpp'), + ['native_sim'], + { + 'selected_test_scenarios': 3, + 'selected_test_instances': 3, + 'executed_test_instances': 3, + 'skipped_configurations': 0, + 'skipped_by_static_filter': 0, + 'skipped_at_runtime': 0, + 'passed_configurations': 2, + 'built_configurations': 1, + 'failed_configurations': 0, + 'errored_configurations': 0, + 'executed_test_cases': 5, + 'skipped_test_cases': 0, + 'platform_count': 1, + 'executed_on_platform': 2, + 'only_built': 1 + } + ), ] @classmethod @@ -129,7 +150,7 @@ def test_force_platform(self, out_path): assert str(sys_exit.value) == '0' - assert len(filtered_j) == 14 + assert len(filtered_j) == 26 def test_platform(self, out_path): path = os.path.join(TEST_DATA, 'tests', 'dummy') @@ -250,6 +271,7 @@ def test_exclude_platform(self, capfd, out_path, test_path, test_platforms, expe ids=[ 'emulation_only tests/dummy/agnostic', 'emulation_only tests/dummy/device', + 'native_sim_only tests/dummy/agnostic_cpp', ] ) def test_emulation_only(self, capfd, out_path, test_path, test_platforms, expected): diff --git a/scripts/tests/twister_blackbox/test_report.py b/scripts/tests/twister_blackbox/test_report.py index 3a145fd59b37cf..bac6ddbbbfa0b8 100644 --- a/scripts/tests/twister_blackbox/test_report.py +++ b/scripts/tests/twister_blackbox/test_report.py @@ -355,7 +355,7 @@ def test_log_file(self, capfd, test_path, test_platforms, out_path, file_name): ( os.path.join(TEST_DATA, 'tests', 'dummy'), ['--detailed-skipped-report', '--report-filtered'], - {'qemu_x86/atom': 7, 'intel_adl_crb/alder_lake': 7} + {'qemu_x86/atom': 13, 'intel_adl_crb/alder_lake': 13} ), ], ids=['dummy tests', 'dummy tests with filtered'] @@ -392,7 +392,7 @@ def test_detailed_skipped_report(self, out_path, test_path, flags, expected_test 'test_path, report_filtered, expected_filtered_count', [ (os.path.join(TEST_DATA, 'tests', 'dummy'), False, 0), - (os.path.join(TEST_DATA, 'tests', 'dummy'), True, 4), + (os.path.join(TEST_DATA, 'tests', 'dummy'), True, 10), ], ids=['no filtered', 'with filtered'] ) diff --git a/scripts/tests/twister_blackbox/test_runner.py b/scripts/tests/twister_blackbox/test_runner.py index 41eea8987b619f..e1b6a194703337 100644 --- a/scripts/tests/twister_blackbox/test_runner.py +++ b/scripts/tests/twister_blackbox/test_runner.py @@ -591,7 +591,7 @@ def test_tag(self, capfd, out_path, test_path, test_platforms, tags, expected): sys.stderr.write(err) for line in expected: - assert re.search(line, err) + assert re.search(line, err), f"no expected:'{line}' in '{err}'" assert str(sys_exit.value) == '0' diff --git a/scripts/tests/twister_blackbox/test_shuffle.py b/scripts/tests/twister_blackbox/test_shuffle.py index 412d97a619bf93..f45724b7b55e7a 100644 --- a/scripts/tests/twister_blackbox/test_shuffle.py +++ b/scripts/tests/twister_blackbox/test_shuffle.py @@ -33,20 +33,21 @@ def teardown_class(cls): @pytest.mark.parametrize( 'seed, ratio, expected_order', [ - ('123', '1/2', ['dummy.agnostic.group1.subgroup1', 'dummy.agnostic.group1.subgroup2']), - ('123', '2/2', ['dummy.agnostic.group2', 'dummy.device.group']), - ('321', '1/2', ['dummy.agnostic.group1.subgroup1', 'dummy.agnostic.group2']), - ('321', '2/2', ['dummy.device.group', 'dummy.agnostic.group1.subgroup2']), - ('123', '1/3', ['dummy.agnostic.group1.subgroup1', 'dummy.agnostic.group1.subgroup2']), + ('123', '1/2', ['dummy.device.group', 'dummy.agnostic.group1.subgroup2']), + ('123', '2/2', ['dummy.agnostic.group2', 'dummy.agnostic.group1.subgroup1']), + ('321', '1/2', ['dummy.agnostic.group2', 'dummy.agnostic.group1.subgroup2']), + ('321', '2/2', ['dummy.device.group', 'dummy.agnostic.group1.subgroup1']), + ('123', '1/3', ['dummy.device.group', 'dummy.agnostic.group1.subgroup2']), ('123', '2/3', ['dummy.agnostic.group2']), - ('123', '3/3', ['dummy.device.group']), - ('321', '1/3', ['dummy.agnostic.group1.subgroup1', 'dummy.agnostic.group2']), + ('123', '3/3', ['dummy.agnostic.group1.subgroup1']), + ('321', '1/3', ['dummy.agnostic.group2', 'dummy.agnostic.group1.subgroup2']), ('321', '2/3', ['dummy.device.group']), - ('321', '3/3', ['dummy.agnostic.group1.subgroup2']) + ('321', '3/3', ['dummy.agnostic.group1.subgroup1']) ], ids=['first half, 123', 'second half, 123', 'first half, 321', 'second half, 321', 'first third, 123', 'middle third, 123', 'last third, 123', - 'first third, 321', 'middle third, 321', 'last third, 321'] + 'first third, 321', 'middle third, 321', 'last third, 321' +] ) @mock.patch.object(TestPlan, 'TESTSUITE_FILENAME', testsuite_filename_mock) def test_shuffle_tests(self, out_path, seed, ratio, expected_order): From c14b022beab8097ed7b79daed02dbf899fc8a490 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 21 Nov 2024 11:31:30 -0500 Subject: [PATCH 027/261] ci: twister: add --no-detailed-test-id Switch to short test identifier in reporting. Part of a series of changes to improve reporting and remove duplication and clutter when running twister. Signed-off-by: Anas Nashif --- .github/workflows/clang.yaml | 4 ++-- .github/workflows/twister-prep.yaml | 2 +- .github/workflows/twister.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/clang.yaml b/.github/workflows/clang.yaml index 4221babe2e5f6f..0d97ecc8abcade 100644 --- a/.github/workflows/clang.yaml +++ b/.github/workflows/clang.yaml @@ -107,13 +107,13 @@ jobs: export ZEPHYR_TOOLCHAIN_VARIANT=llvm # check if we need to run a full twister or not based on files changed - python3 ./scripts/ci/test_plan.py --platform ${{ matrix.platform }} -c origin/${BASE_REF}.. + python3 ./scripts/ci/test_plan.py --no-detailed-test-id --platform ${{ matrix.platform }} -c origin/${BASE_REF}.. # We can limit scope to just what has changed if [ -s testplan.json ]; then echo "report_needed=1" >> $GITHUB_OUTPUT # Full twister but with options based on changes - ./scripts/twister --force-color --inline-logs -M -N -v --load-tests testplan.json --retry-failed 2 + ./scripts/twister --no-detailed-test-id --force-color --inline-logs -M -N -v --load-tests testplan.json --retry-failed 2 else # if nothing is run, skip reporting step echo "report_needed=0" >> $GITHUB_OUTPUT diff --git a/.github/workflows/twister-prep.yaml b/.github/workflows/twister-prep.yaml index 9a1e183ad28806..49840b1d063c3d 100644 --- a/.github/workflows/twister-prep.yaml +++ b/.github/workflows/twister-prep.yaml @@ -83,7 +83,7 @@ jobs: run: | export ZEPHYR_BASE=${PWD} export ZEPHYR_TOOLCHAIN_VARIANT=zephyr - python3 ./scripts/ci/test_plan.py -c origin/${BASE_REF}.. --pull-request -t $TESTS_PER_BUILDER + python3 ./scripts/ci/test_plan.py -c origin/${BASE_REF}.. --no-detailed-test-id --pull-request -t $TESTS_PER_BUILDER if [ -s .testplan ]; then cat .testplan >> $GITHUB_ENV else diff --git a/.github/workflows/twister.yaml b/.github/workflows/twister.yaml index 1d863c7c690801..5cd8b2e59f39a6 100644 --- a/.github/workflows/twister.yaml +++ b/.github/workflows/twister.yaml @@ -44,7 +44,7 @@ jobs: CCACHE_IGNOREOPTIONS: '-specs=* --specs=*' BSIM_OUT_PATH: /opt/bsim/ BSIM_COMPONENTS_PATH: /opt/bsim/components - TWISTER_COMMON: ' --force-color --inline-logs -v -N -M --retry-failed 3 --timeout-multiplier 2 ' + TWISTER_COMMON: '--no-detailed-test-id --force-color --inline-logs -v -N -M --retry-failed 3 --timeout-multiplier 2 ' DAILY_OPTIONS: ' -M --build-only --all --show-footprint' PR_OPTIONS: ' --clobber-output --integration' PUSH_OPTIONS: ' --clobber-output -M --show-footprint --report-filtered' From 1f17c761e5e78856ccde9a9f84b9f81974364374 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 22 Nov 2024 11:29:14 -0500 Subject: [PATCH 028/261] ci: test_plan: call with --no-detailed-test-id add --no-detailed-test-id to call of test_plan. Was missed in previous commit. Signed-off-by: Anas Nashif --- .github/workflows/twister.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/twister.yaml b/.github/workflows/twister.yaml index 5cd8b2e59f39a6..01be87ffabdf09 100644 --- a/.github/workflows/twister.yaml +++ b/.github/workflows/twister.yaml @@ -148,7 +148,7 @@ jobs: rm -f testplan.json export ZEPHYR_BASE=${PWD} export ZEPHYR_TOOLCHAIN_VARIANT=zephyr - python3 ./scripts/ci/test_plan.py -c origin/${BASE_REF}.. --pull-request + python3 ./scripts/ci/test_plan.py -c origin/${BASE_REF}.. --pull-request --no-detailed-test-id ./scripts/twister --subset ${{matrix.subset}}/${{ strategy.job-total }} --load-tests testplan.json ${TWISTER_COMMON} ${PR_OPTIONS} if [ "${{matrix.subset}}" = "1" -a ${{needs.twister-build-prep.outputs.fullrun}} = 'True' ]; then ./scripts/zephyr_module.py --twister-out module_tests.args From aae018be873236a136264c8b65de1397c58cbeb5 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 20 Nov 2024 19:39:56 +0100 Subject: [PATCH 029/261] scripts: west_commands: runners: Remove obsolete pylint ignores These ignores were added with an older version of pylint and are either removed or ignored by default. Signed-off-by: Pieter De Gendt --- scripts/west_commands/runners/intel_cyclonev.py | 1 - scripts/west_commands/runners/uf2.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/west_commands/runners/intel_cyclonev.py b/scripts/west_commands/runners/intel_cyclonev.py index c14e20b967f93c..764ebd7420b499 100644 --- a/scripts/west_commands/runners/intel_cyclonev.py +++ b/scripts/west_commands/runners/intel_cyclonev.py @@ -174,7 +174,6 @@ def print_gdbserver_message(self): self.logger.info('OpenOCD GDB server running on port ' f'{self.gdb_port}{thread_msg}') - # pylint: disable=R0201 def to_num(self, number): dev_match = re.search(r"^\d*\+dev", number) dev_version = not dev_match is None diff --git a/scripts/west_commands/runners/uf2.py b/scripts/west_commands/runners/uf2.py index 87db248c7bf307..0db4f0b9b44189 100644 --- a/scripts/west_commands/runners/uf2.py +++ b/scripts/west_commands/runners/uf2.py @@ -10,7 +10,7 @@ from runners.core import ZephyrBinaryRunner, RunnerCaps try: - import psutil # pylint: disable=unused-import + import psutil MISSING_PSUTIL = False except ImportError: # This can happen when building the documentation for the From 25be1501abb11eefa223575c7c148e51adaeccc9 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 20 Nov 2024 19:45:12 +0100 Subject: [PATCH 030/261] scripts: west_commands: runners: Fix pylint unbound issues Variables are possibly unbound, initialize to None. Signed-off-by: Pieter De Gendt --- scripts/west_commands/runners/intel_cyclonev.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/west_commands/runners/intel_cyclonev.py b/scripts/west_commands/runners/intel_cyclonev.py index 764ebd7420b499..490beca4da8333 100644 --- a/scripts/west_commands/runners/intel_cyclonev.py +++ b/scripts/west_commands/runners/intel_cyclonev.py @@ -34,6 +34,10 @@ def __init__(self, cfg, pre_init=None, reset_halt_cmd=DEFAULT_OPENOCD_RESET_HALT support = path.join(cfg.board_dir, 'support') + gdb_commands = None + gdb_commands2 = None + gdb_commands_deb = None + if not config: default = path.join(support, 'openocd.cfg') default2 = path.join(support, 'download_all.gdb') From e8294b45904f71387a521863abd336173345d1f1 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 20 Nov 2024 09:01:24 +0100 Subject: [PATCH 031/261] scripts: west_commands: runners: Fix assert-false (B011) Prefer AssertionError instead of assert False. See https://docs.astral.sh/ruff/rules/assert-false/ Signed-off-by: Pieter De Gendt --- scripts/west_commands/runners/native.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/west_commands/runners/native.py b/scripts/west_commands/runners/native.py index 2cbcf60d3ab971..17add87fbc5419 100644 --- a/scripts/west_commands/runners/native.py +++ b/scripts/west_commands/runners/native.py @@ -60,7 +60,7 @@ def do_run(self, command: str, **kwargs): elif command == 'debugserver': self.do_debugserver(**kwargs) else: - assert False + raise AssertionError def do_flash(self, **kwargs): cmd = [self.cfg.exe_file] From a48e37608f7190a8da51f61d4b7e71b13118a11b Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 20 Nov 2024 17:06:37 +0100 Subject: [PATCH 032/261] scripts: west_commands: runners: Ignore missing abstract decorator (B027) The empty function is intentional. https://docs.astral.sh/ruff/rules/empty-method-without-abstract-decorator/ Signed-off-by: Pieter De Gendt --- scripts/west_commands/runners/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/west_commands/runners/core.py b/scripts/west_commands/runners/core.py index 69491f1990df02..588e381e254a0d 100644 --- a/scripts/west_commands/runners/core.py +++ b/scripts/west_commands/runners/core.py @@ -624,7 +624,7 @@ def add_parser(cls, parser): def do_add_parser(cls, parser): '''Hook for adding runner-specific options.''' - @classmethod + @classmethod # noqa: B027 def args_from_previous_runner(cls, previous_runner, args: argparse.Namespace): '''Update arguments from a previously created runner. From ddbba0ef4c8951e7bb210d84f0b2e201b6174842 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 20 Nov 2024 09:11:16 +0100 Subject: [PATCH 033/261] scripts: west_commands: runners: Fix mixed-spaces-and-tabs (E101) Use spaces for indentation. See https://docs.astral.sh/ruff/rules/mixed-spaces-and-tabs/ Signed-off-by: Pieter De Gendt --- scripts/west_commands/runners/bossac.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/west_commands/runners/bossac.py b/scripts/west_commands/runners/bossac.py index fcbd6fdf92be4e..ff4478f1e1ffd7 100644 --- a/scripts/west_commands/runners/bossac.py +++ b/scripts/west_commands/runners/bossac.py @@ -102,8 +102,7 @@ def get_chosen_code_partition_node(self): b = pathlib.Path(self.cfg.build_dir) edt_pickle = b / 'zephyr' / 'edt.pickle' if not edt_pickle.is_file(): - error_msg = "can't load devicetree; expected to find:" \ - + str(edt_pickle) + error_msg = "can't load devicetree; expected to find:" + str(edt_pickle) raise RuntimeError(error_msg) From 133665e55a707e6eb58425298779e3b3d680d319 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 20 Nov 2024 09:12:46 +0100 Subject: [PATCH 034/261] scripts: west_commands: runners: Fix unused-import (F401) Removed unused import. See https://docs.astral.sh/ruff/rules/unused-import/ Signed-off-by: Pieter De Gendt --- scripts/west_commands/runners/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/west_commands/runners/__init__.py b/scripts/west_commands/runners/__init__.py index a4fbe843782e9b..000cdf1dc03ba1 100644 --- a/scripts/west_commands/runners/__init__.py +++ b/scripts/west_commands/runners/__init__.py @@ -5,7 +5,7 @@ import importlib import logging -from runners.core import ZephyrBinaryRunner, MissingProgram +from runners.core import ZephyrBinaryRunner _logger = logging.getLogger('runners') From d397b0133890923d16547d10aba0bb7140684ad8 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 20 Nov 2024 09:15:57 +0100 Subject: [PATCH 035/261] scripts: west_commands: runners: Fix collapsible-if (SIM102) Combine multiple nested if statements. See https://docs.astral.sh/ruff/rules/collapsible-if/ Signed-off-by: Pieter De Gendt --- scripts/west_commands/runners/nrf_common.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/west_commands/runners/nrf_common.py b/scripts/west_commands/runners/nrf_common.py index 220bd204249a7f..b97cc5ef4a17ea 100644 --- a/scripts/west_commands/runners/nrf_common.py +++ b/scripts/west_commands/runners/nrf_common.py @@ -264,15 +264,15 @@ def flush(self, force=False): 'must be recovered.\n' ' To fix, run "west flash --recover" instead.\n' + family_help) - if cpe.returncode == ErrVerify: - # If there are data in the UICR region it is likely that the - # verify failed du to the UICR not been erased before, so giving + if cpe.returncode == ErrVerify and self.hex_get_uicrs(): + # If there is data in the UICR region it is likely that the + # verify failed due to the UICR not been erased before, so giving # a warning here will hopefully enhance UX. - if self.hex_get_uicrs(): - self.logger.warning( - 'The hex file contains data placed in the UICR, which ' - 'may require a full erase before reprogramming. Run ' - 'west flash again with --erase, or --recover.') + self.logger.warning( + 'The hex file contains data placed in the UICR, which ' + 'may require a full erase before reprogramming. Run ' + 'west flash again with --erase, or --recover.' + ) raise From 2e39674344850cfce0e09b76255fc6a7835f9601 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 20 Nov 2024 09:18:43 +0100 Subject: [PATCH 036/261] scripts: west_commands: runners: Fix needless-bool (SIM103) Return the result instead of the if statements. See https://docs.astral.sh/ruff/rules/needless-bool/ Signed-off-by: Pieter De Gendt --- scripts/west_commands/runners/mdb.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/west_commands/runners/mdb.py b/scripts/west_commands/runners/mdb.py index 6dbffa30dbd9bd..da040df9d8271b 100644 --- a/scripts/west_commands/runners/mdb.py +++ b/scripts/west_commands/runners/mdb.py @@ -27,12 +27,10 @@ def is_flash_cmd_need_exit_immediately(mdb_runner): if is_simulation_run(mdb_runner): # for nsim, we can't run and quit immediately return False - elif is_hostlink_used(mdb_runner): - # if hostlink is used we can't run and quit immediately, as we still need MDB process - # attached to process hostlink IO - return False - else: - return True + + # if hostlink is used we can't run and quit immediately, as we still need MDB process + # attached to process hostlink IO + return not is_hostlink_used(mdb_runner) def smp_core_order(mdb_runner, id): if is_simulation_run(mdb_runner): From dbaf01ef289bae01a2f31428e05f8fb5093af5d1 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 20 Nov 2024 09:24:05 +0100 Subject: [PATCH 037/261] scripts: west_commands: runners: Ignore open file without ctx (SIM115) Add noqa to a complex statement with multiple open/close statements. See https://docs.astral.sh/ruff/rules/open-file-with-context-handler/ Signed-off-by: Pieter De Gendt --- scripts/west_commands/runners/canopen_program.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/west_commands/runners/canopen_program.py b/scripts/west_commands/runners/canopen_program.py index 2fb8ba42b0170c..de670bb53e91b4 100644 --- a/scripts/west_commands/runners/canopen_program.py +++ b/scripts/west_commands/runners/canopen_program.py @@ -278,7 +278,7 @@ def download(self, bin_file): self.logger.info('Downloading program: %s', bin_file) try: size = os.path.getsize(bin_file) - infile = open(bin_file, 'rb') + infile = open(bin_file, 'rb') # noqa: SIM115 outfile = self.data_sdo.open('wb', buffering=self.download_buffer_size, size=size, block_transfer=self.block_transfer) From fc5286fe2542a9d0165698ef01485fbc6ee4c24b Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 20 Nov 2024 09:26:48 +0100 Subject: [PATCH 038/261] scripts: west_commands: runners: Fix useless-object-inheritance (UP004) Remove object inheritance. See https://docs.astral.sh/ruff/rules/useless-object-inheritance/ Signed-off-by: Pieter De Gendt --- scripts/west_commands/runners/canopen_program.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/west_commands/runners/canopen_program.py b/scripts/west_commands/runners/canopen_program.py index de670bb53e91b4..6183631cca0cca 100644 --- a/scripts/west_commands/runners/canopen_program.py +++ b/scripts/west_commands/runners/canopen_program.py @@ -185,7 +185,7 @@ def flash(self, **kwargs): self.downloader.disconnect() -class CANopenProgramDownloader(object): +class CANopenProgramDownloader: '''CANopen program downloader''' def __init__(self, logger, node_id, can_context=DEFAULT_CAN_CONTEXT, program_number=DEFAULT_PROGRAM_NUMBER, From d562731096996e50b61da4e50506a1cb182154ce Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 20 Nov 2024 09:28:27 +0100 Subject: [PATCH 039/261] scripts: west_commands: runners: Fix redundant-open-modes (UP015) Don't pass default open mode. See https://docs.astral.sh/ruff/rules/redundant-open-modes/ Signed-off-by: Pieter De Gendt --- scripts/west_commands/runners/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/west_commands/runners/core.py b/scripts/west_commands/runners/core.py index 588e381e254a0d..b4ccc2eb5367c2 100644 --- a/scripts/west_commands/runners/core.py +++ b/scripts/west_commands/runners/core.py @@ -190,7 +190,7 @@ def _parse(self): opt_value = re.compile(f'^(?P