diff --git a/tests/kernel/sys_irq/direct_irq/CMakeLists.txt b/tests/kernel/sys_irq/direct_irq/CMakeLists.txt new file mode 100644 index 000000000000000..d753f28ebcfd63f --- /dev/null +++ b/tests/kernel/sys_irq/direct_irq/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Bjarki Arge Andreasen +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(test_sys_irq_direct_irq) + +target_sources(app PRIVATE src/test.c) diff --git a/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpuapp.conf b/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpuapp.conf new file mode 100644 index 000000000000000..7a1e00780f0b537 --- /dev/null +++ b/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -0,0 +1,6 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_GEN_ISR_TABLES=n +CONFIG_GEN_IRQ_VECTOR_TABLE=n +CONFIG_BOARD_ENABLE_CPUNET=y diff --git a/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpuapp.overlay new file mode 100644 index 000000000000000..e88a458735c7cee --- /dev/null +++ b/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + aliases { + test-intd0 = &spi1; + test-intd1 = &spi2; + }; +}; + +&spi1 { + status = "reserved"; +}; + +&spi2 { + status = "reserved"; +}; diff --git a/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpunet.conf b/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpunet.conf new file mode 100644 index 000000000000000..a82dda984c4c788 --- /dev/null +++ b/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpunet.conf @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_GEN_ISR_TABLES=n +CONFIG_GEN_IRQ_VECTOR_TABLE=n diff --git a/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpunet.overlay b/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpunet.overlay new file mode 100644 index 000000000000000..becaea525977d44 --- /dev/null +++ b/tests/kernel/sys_irq/direct_irq/boards/nrf5340dk_nrf5340_cpunet.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + aliases { + test-intd0 = &timer1; + test-intd1 = &timer2; + }; +}; + +&timer1 { + status = "reserved"; +}; + +&timer2 { + status = "reserved"; +}; diff --git a/tests/kernel/sys_irq/direct_irq/prj.conf b/tests/kernel/sys_irq/direct_irq/prj.conf new file mode 100644 index 000000000000000..a2d149408998b46 --- /dev/null +++ b/tests/kernel/sys_irq/direct_irq/prj.conf @@ -0,0 +1,7 @@ +# Copyright (c) 2024 Bjarki Arge Andreasen +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_ZTEST=y +CONFIG_ZTEST_FAIL_FAST=y +CONFIG_INTC=y +CONFIG_SYS_IRQ=y diff --git a/tests/kernel/sys_irq/direct_irq/src/test.c b/tests/kernel/sys_irq/direct_irq/src/test.c new file mode 100644 index 000000000000000..37c29d8b5d5f50c --- /dev/null +++ b/tests/kernel/sys_irq/direct_irq/src/test.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2024 Bjarki Arge Andreasen + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#define TEST_IRQ_MAX_DELAY K_MSEC(10) + +#define INTD0_NODE DT_ALIAS(test_intd0) +#define INTD1_NODE DT_ALIAS(test_intd1) + +#define INTD0_SYS_IRQN SYS_DT_IRQN(INTD0_NODE) +#define INTD1_SYS_IRQN SYS_DT_IRQN(INTD1_NODE) + +#define INTD0_IRQ_FLAGS SYS_DT_IRQ_FLAGS(INTD0_NODE) +#define INTD1_IRQ_FLAGS SYS_DT_IRQ_FLAGS(INTD1_NODE) + +BUILD_ASSERT(INTD0_SYS_IRQN != INTD1_SYS_IRQN, "INTDs must not share INTL"); +BUILD_ASSERT(DT_NODE_HAS_STATUS(INTD0_NODE, reserved), "INTD0 must have status reserved"); +BUILD_ASSERT(DT_NODE_HAS_STATUS(INTD1_NODE, reserved), "INTD1 must have status reserved"); + +static K_SEM_DEFINE(irq0_sem, 0, 1); +static K_SEM_DEFINE(irq1_sem, 0, 1); + +INTC_DT_DEFINE_IRQ_VECTOR(INTD0_NODE) +{ + k_sem_give(&irq0_sem); + return 1; +} + +INTC_DT_DEFINE_IRQ_VECTOR(INTD1_NODE) +{ + k_sem_give(&irq1_sem); + return 1; +} + +ZTEST(sys_irq_direct_irq, test__trigger_irq_while_disabled__no_irq) +{ + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); +} + +ZTEST(sys_irq_direct_irq, test__trigger_irq_while_enabled__irq) +{ + zassert_ok(sys_irq_enable(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_enable(INTD1_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), 0); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), 0); +} + +ZTEST(sys_irq_irq, test__disable_disabled_irq__retval_0) +{ + zassert_equal(sys_irq_disable(INTD0_SYS_IRQN), 0); + zassert_equal(sys_irq_disable(INTD1_SYS_IRQN), 0); +} + +ZTEST(sys_irq_direct_irq, test__disable_enabled_irq__retval_1) +{ + zassert_ok(sys_irq_enable(INTD0_SYS_IRQN)); + zassert_ok(sys_irq_enable(INTD1_SYS_IRQN)); + zassert_equal(sys_irq_disable(INTD0_SYS_IRQN), 1); + zassert_equal(sys_irq_disable(INTD1_SYS_IRQN), 1); +} + +ZTEST(sys_irq_direct_irq, test__clear_cleared_irq__retval_0) +{ + zassert_equal(sys_irq_clear(INTD0_SYS_IRQN), 0); + zassert_equal(sys_irq_clear(INTD1_SYS_IRQN), 0); +} + +ZTEST(sys_irq_direct_irq, test__clear_triggered_irq__retval_1) +{ + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_equal(sys_irq_clear(INTD0_SYS_IRQN), 1); + zassert_equal(sys_irq_clear(INTD1_SYS_IRQN), 1); +} + +void *test_init(void) +{ + zassert_ok(sys_irq_configure(INTD0_SYS_IRQN, INTD0_IRQ_FLAGS)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_configure(INTD1_SYS_IRQN, INTD1_IRQ_FLAGS)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + return NULL; +} + +void test_before(void *f) +{ + ARG_UNUSED(f); + + zassert(sys_irq_disable(INTD0_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_disable(INTD1_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_clear(INTD0_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_clear(INTD1_SYS_IRQN) > -1, "retval must be positive"); + k_sem_reset(&irq0_sem); + k_sem_reset(&irq1_sem); +} + +ZTEST_SUITE(sys_irq_direct_irq, NULL, test_init, test_before, NULL, NULL); diff --git a/tests/kernel/sys_irq/direct_irq/testcase.yaml b/tests/kernel/sys_irq/direct_irq/testcase.yaml new file mode 100644 index 000000000000000..c2b6abf73713b1a --- /dev/null +++ b/tests/kernel/sys_irq/direct_irq/testcase.yaml @@ -0,0 +1,11 @@ +tests: + kernel.sys_irq.direct_irq: + platform_allow: + - nrf5340dk/nrf5340/cpuapp + - nrf5340dk/nrf5340/cpunet + kernel.sys_irq.direct_irq.lto: + extra_configs: + - CONFIG_LTO=y + platform_allow: + - nrf5340dk/nrf5340/cpuapp + - nrf5340dk/nrf5340/cpunet diff --git a/tests/kernel/sys_irq/dynamic_irq/CMakeLists.txt b/tests/kernel/sys_irq/dynamic_irq/CMakeLists.txt new file mode 100644 index 000000000000000..5c80b5db563bfbd --- /dev/null +++ b/tests/kernel/sys_irq/dynamic_irq/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Bjarki Arge Andreasen +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(test_sys_irq_dynamic_irq) + +target_sources(app PRIVATE src/test.c) diff --git a/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpuapp.conf b/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpuapp.conf new file mode 100644 index 000000000000000..7a1e00780f0b537 --- /dev/null +++ b/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -0,0 +1,6 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_GEN_ISR_TABLES=n +CONFIG_GEN_IRQ_VECTOR_TABLE=n +CONFIG_BOARD_ENABLE_CPUNET=y diff --git a/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpuapp.overlay new file mode 100644 index 000000000000000..e88a458735c7cee --- /dev/null +++ b/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + aliases { + test-intd0 = &spi1; + test-intd1 = &spi2; + }; +}; + +&spi1 { + status = "reserved"; +}; + +&spi2 { + status = "reserved"; +}; diff --git a/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpunet.conf b/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpunet.conf new file mode 100644 index 000000000000000..a82dda984c4c788 --- /dev/null +++ b/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpunet.conf @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_GEN_ISR_TABLES=n +CONFIG_GEN_IRQ_VECTOR_TABLE=n diff --git a/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpunet.overlay b/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpunet.overlay new file mode 100644 index 000000000000000..becaea525977d44 --- /dev/null +++ b/tests/kernel/sys_irq/dynamic_irq/boards/nrf5340dk_nrf5340_cpunet.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + aliases { + test-intd0 = &timer1; + test-intd1 = &timer2; + }; +}; + +&timer1 { + status = "reserved"; +}; + +&timer2 { + status = "reserved"; +}; diff --git a/tests/kernel/sys_irq/dynamic_irq/prj.conf b/tests/kernel/sys_irq/dynamic_irq/prj.conf new file mode 100644 index 000000000000000..65e1af594268b8f --- /dev/null +++ b/tests/kernel/sys_irq/dynamic_irq/prj.conf @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Bjarki Arge Andreasen +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_ZTEST=y +CONFIG_ZTEST_FAIL_FAST=y +CONFIG_INTC=y +CONFIG_SYS_IRQ=y +CONFIG_SYS_IRQ_DYNAMIC=y diff --git a/tests/kernel/sys_irq/dynamic_irq/src/test.c b/tests/kernel/sys_irq/dynamic_irq/src/test.c new file mode 100644 index 000000000000000..d8e6b7a8d3f150f --- /dev/null +++ b/tests/kernel/sys_irq/dynamic_irq/src/test.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2024 Bjarki Arge Andreasen + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#define TEST_IRQ_MAX_DELAY K_MSEC(10) + +#define INTD0_NODE DT_ALIAS(test_intd0) +#define INTD1_NODE DT_ALIAS(test_intd1) + +#define INTD0_SYS_IRQN SYS_DT_IRQN(INTD0_NODE) +#define INTD1_SYS_IRQN SYS_DT_IRQN(INTD1_NODE) + +#define INTD0_IRQ_FLAGS SYS_DT_IRQ_FLAGS(INTD0_NODE) +#define INTD1_IRQ_FLAGS SYS_DT_IRQ_FLAGS(INTD1_NODE) + +BUILD_ASSERT(INTD0_SYS_IRQN != INTD1_SYS_IRQN, "INTDs must not share INTL"); +BUILD_ASSERT(DT_NODE_HAS_STATUS(INTD0_NODE, reserved), "INTD0 must have status reserved"); +BUILD_ASSERT(DT_NODE_HAS_STATUS(INTD1_NODE, reserved), "INTD1 must have status reserved"); + +static K_SEM_DEFINE(irq0_sem, 0, 1); +static K_SEM_DEFINE(irq1_sem, 0, 1); + +static uint32_t irq0_data; +static uint32_t irq1_data; +static struct sys_irq irq0; +static struct sys_irq irq1; + +static int irq0_handler(const void *data) +{ + zassert_equal(data, &irq0_data); + k_sem_give(&irq0_sem); + return SYS_IRQ_HANDLED; +} + +static int irq1_handler(const void *data) +{ + zassert_equal(data, &irq1_data); + k_sem_give(&irq1_sem); + return SYS_IRQ_HANDLED; +} + +ZTEST(sys_irq_irq, test__enable_then_req_then_trigger__irq) +{ + zassert_ok(sys_irq_enable(INTD0_SYS_IRQN)); + zassert_ok(sys_irq_enable(INTD1_SYS_IRQN)); + zassert_ok(sys_irq_request(INTD0_SYS_IRQN, &irq0, irq0_handler, &irq0_data)); + zassert_ok(sys_irq_request(INTD1_SYS_IRQN, &irq1, irq1_handler, &irq1_data)); + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), 0); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), 0); +} + +ZTEST(sys_irq_irq, test__req_then_trigger__no_irq) +{ + zassert_ok(sys_irq_request(INTD0_SYS_IRQN, &irq0, irq0_handler, &irq0_data)); + zassert_ok(sys_irq_request(INTD1_SYS_IRQN, &irq1, irq1_handler, &irq1_data)); + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); +} + +ZTEST(sys_irq_irq, test__trigger_then_req__no_irq) +{ + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_ok(sys_irq_request(INTD0_SYS_IRQN, &irq0, irq0_handler, &irq0_data)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_request(INTD1_SYS_IRQN, &irq1, irq1_handler, &irq1_data)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); +} + +ZTEST(sys_irq_irq, test__trigger_then_req_then_enable__no_irq) +{ + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_ok(sys_irq_request(INTD0_SYS_IRQN, &irq0, irq0_handler, &irq0_data)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_request(INTD1_SYS_IRQN, &irq1, irq1_handler, &irq1_data)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_enable(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), 0); + zassert_ok(sys_irq_enable(INTD1_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), 0); +} + +void *test_init(void) +{ + zassert_ok(sys_irq_configure(INTD0_SYS_IRQN, INTD0_IRQ_FLAGS)); + zassert_ok(sys_irq_configure(INTD1_SYS_IRQN, INTD1_IRQ_FLAGS)); + return NULL; +} + +void test_before(void *f) +{ + ARG_UNUSED(f); + + k_sem_reset(&irq0_sem); + k_sem_reset(&irq1_sem); +} + +void test_after(void *f) +{ + ARG_UNUSED(f); + + zassert(sys_irq_disable(INTD0_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_disable(INTD1_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_clear(INTD0_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_clear(INTD1_SYS_IRQN) > -1, "retval must be positive"); + zassert_ok(sys_irq_release(INTD0_SYS_IRQN, &irq0)); + zassert_ok(sys_irq_release(INTD1_SYS_IRQN, &irq1)); +} + +ZTEST_SUITE(sys_irq_dynamic_irq, NULL, test_init, test_before, test_after, NULL); diff --git a/tests/kernel/sys_irq/dynamic_irq/testcase.yaml b/tests/kernel/sys_irq/dynamic_irq/testcase.yaml new file mode 100644 index 000000000000000..928f419b2dccba1 --- /dev/null +++ b/tests/kernel/sys_irq/dynamic_irq/testcase.yaml @@ -0,0 +1,11 @@ +tests: + kernel.sys_irq.dynamic_irq: + platform_allow: + - nrf5340dk/nrf5340/cpuapp + - nrf5340dk/nrf5340/cpunet + kernel.sys_irq.dynamic_irq.lto: + extra_configs: + - CONFIG_LTO=y + platform_allow: + - nrf5340dk/nrf5340/cpuapp + - nrf5340dk/nrf5340/cpunet diff --git a/tests/kernel/sys_irq/irq/CMakeLists.txt b/tests/kernel/sys_irq/irq/CMakeLists.txt new file mode 100644 index 000000000000000..d78e303a5a10635 --- /dev/null +++ b/tests/kernel/sys_irq/irq/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Bjarki Arge Andreasen +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(test_sys_irq_irq) + +target_sources(app PRIVATE src/test.c) diff --git a/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpuapp.conf b/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpuapp.conf new file mode 100644 index 000000000000000..7a1e00780f0b537 --- /dev/null +++ b/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -0,0 +1,6 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_GEN_ISR_TABLES=n +CONFIG_GEN_IRQ_VECTOR_TABLE=n +CONFIG_BOARD_ENABLE_CPUNET=y diff --git a/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpuapp.overlay new file mode 100644 index 000000000000000..e88a458735c7cee --- /dev/null +++ b/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + aliases { + test-intd0 = &spi1; + test-intd1 = &spi2; + }; +}; + +&spi1 { + status = "reserved"; +}; + +&spi2 { + status = "reserved"; +}; diff --git a/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpunet.conf b/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpunet.conf new file mode 100644 index 000000000000000..a82dda984c4c788 --- /dev/null +++ b/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpunet.conf @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_GEN_ISR_TABLES=n +CONFIG_GEN_IRQ_VECTOR_TABLE=n diff --git a/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpunet.overlay b/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpunet.overlay new file mode 100644 index 000000000000000..becaea525977d44 --- /dev/null +++ b/tests/kernel/sys_irq/irq/boards/nrf5340dk_nrf5340_cpunet.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + aliases { + test-intd0 = &timer1; + test-intd1 = &timer2; + }; +}; + +&timer1 { + status = "reserved"; +}; + +&timer2 { + status = "reserved"; +}; diff --git a/tests/kernel/sys_irq/irq/prj.conf b/tests/kernel/sys_irq/irq/prj.conf new file mode 100644 index 000000000000000..a2d149408998b46 --- /dev/null +++ b/tests/kernel/sys_irq/irq/prj.conf @@ -0,0 +1,7 @@ +# Copyright (c) 2024 Bjarki Arge Andreasen +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_ZTEST=y +CONFIG_ZTEST_FAIL_FAST=y +CONFIG_INTC=y +CONFIG_SYS_IRQ=y diff --git a/tests/kernel/sys_irq/irq/src/test.c b/tests/kernel/sys_irq/irq/src/test.c new file mode 100644 index 000000000000000..209937744ab8b3b --- /dev/null +++ b/tests/kernel/sys_irq/irq/src/test.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2024 Bjarki Arge Andreasen + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#define TEST_IRQ_MAX_DELAY K_MSEC(10) + +#define INTD0_NODE DT_ALIAS(test_intd0) +#define INTD1_NODE DT_ALIAS(test_intd1) + +#define INTD0_SYS_IRQN SYS_DT_IRQN(INTD0_NODE) +#define INTD1_SYS_IRQN SYS_DT_IRQN(INTD1_NODE) + +#define INTD0_IRQ_FLAGS SYS_DT_IRQ_FLAGS(INTD0_NODE) +#define INTD1_IRQ_FLAGS SYS_DT_IRQ_FLAGS(INTD1_NODE) + +BUILD_ASSERT(INTD0_SYS_IRQN != INTD1_SYS_IRQN, "INTDs must not share INTL"); +BUILD_ASSERT(DT_NODE_HAS_STATUS(INTD0_NODE, reserved), "INTD0 must have status reserved"); +BUILD_ASSERT(DT_NODE_HAS_STATUS(INTD1_NODE, reserved), "INTD1 must have status reserved"); + +static K_SEM_DEFINE(irq0_sem, 0, 1); +static K_SEM_DEFINE(irq1_sem, 0, 1); + +static uint32_t irq0_data; +static uint32_t irq1_data; + +static int irq0_handler(const void *data) +{ + zassert_equal(data, &irq0_data); + k_sem_give(&irq0_sem); + return SYS_IRQ_HANDLED; +} + +static int irq1_handler(const void *data) +{ + zassert_equal(data, &irq1_data); + k_sem_give(&irq1_sem); + return SYS_IRQ_HANDLED; +} + +SYS_DT_DEFINE_IRQ_HANDLER(INTD0_NODE, irq0_handler, &irq0_data); +SYS_DT_DEFINE_IRQ_HANDLER(INTD1_NODE, irq1_handler, &irq1_data); + +ZTEST(sys_irq_irq, test__trigger_irq_while_disabled__no_irq) +{ + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); +} + +ZTEST(sys_irq_irq, test__trigger_irq_while_enabled__irq) +{ + zassert_ok(sys_irq_enable(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_enable(INTD1_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), 0); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), 0); +} + +ZTEST(sys_irq_irq, test__disable_disabled_irq__retval_0) +{ + zassert_equal(sys_irq_disable(INTD0_SYS_IRQN), 0); + zassert_equal(sys_irq_disable(INTD1_SYS_IRQN), 0); +} + +ZTEST(sys_irq_irq, test__disable_enabled_irq__retval_1) +{ + zassert_ok(sys_irq_enable(INTD0_SYS_IRQN)); + zassert_ok(sys_irq_enable(INTD1_SYS_IRQN)); + zassert_equal(sys_irq_disable(INTD0_SYS_IRQN), 1); + zassert_equal(sys_irq_disable(INTD1_SYS_IRQN), 1); +} + +ZTEST(sys_irq_irq, test__clear_cleared_irq__retval_0) +{ + zassert_equal(sys_irq_clear(INTD0_SYS_IRQN), 0); + zassert_equal(sys_irq_clear(INTD1_SYS_IRQN), 0); +} + +ZTEST(sys_irq_irq, test__clear_triggered_irq__retval_1) +{ + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_equal(sys_irq_clear(INTD0_SYS_IRQN), 1); + zassert_equal(sys_irq_clear(INTD1_SYS_IRQN), 1); +} + +void *test_init(void) +{ + zassert_ok(sys_irq_configure(INTD0_SYS_IRQN, INTD0_IRQ_FLAGS)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_configure(INTD1_SYS_IRQN, INTD1_IRQ_FLAGS)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + zassert_ok(sys_irq_trigger(INTD1_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + return NULL; +} + +void test_before(void *f) +{ + ARG_UNUSED(f); + + zassert(sys_irq_disable(INTD0_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_disable(INTD1_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_clear(INTD0_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_clear(INTD1_SYS_IRQN) > -1, "retval must be positive"); + k_sem_reset(&irq0_sem); + k_sem_reset(&irq1_sem); +} + +ZTEST_SUITE(sys_irq_irq, NULL, test_init, test_before, NULL, NULL); diff --git a/tests/kernel/sys_irq/irq/testcase.yaml b/tests/kernel/sys_irq/irq/testcase.yaml new file mode 100644 index 000000000000000..92e0e8681e9beb7 --- /dev/null +++ b/tests/kernel/sys_irq/irq/testcase.yaml @@ -0,0 +1,11 @@ +tests: + kernel.sys_irq.irq: + platform_allow: + - nrf5340dk/nrf5340/cpuapp + - nrf5340dk/nrf5340/cpunet + kernel.sys_irq.irq.lto: + extra_configs: + - CONFIG_LTO=y + platform_allow: + - nrf5340dk/nrf5340/cpuapp + - nrf5340dk/nrf5340/cpunet diff --git a/tests/kernel/sys_irq/shared_irq/CMakeLists.txt b/tests/kernel/sys_irq/shared_irq/CMakeLists.txt new file mode 100644 index 000000000000000..d33ba5b7d75fa40 --- /dev/null +++ b/tests/kernel/sys_irq/shared_irq/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Bjarki Arge Andreasen +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(test_sys_irq_shared_irq) + +target_sources(app PRIVATE src/test.c) diff --git a/tests/kernel/sys_irq/shared_irq/boards/nrf5340dk_nrf5340_cpuapp.conf b/tests/kernel/sys_irq/shared_irq/boards/nrf5340dk_nrf5340_cpuapp.conf new file mode 100644 index 000000000000000..a82dda984c4c788 --- /dev/null +++ b/tests/kernel/sys_irq/shared_irq/boards/nrf5340dk_nrf5340_cpuapp.conf @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_GEN_ISR_TABLES=n +CONFIG_GEN_IRQ_VECTOR_TABLE=n diff --git a/tests/kernel/sys_irq/shared_irq/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/kernel/sys_irq/shared_irq/boards/nrf5340dk_nrf5340_cpuapp.overlay new file mode 100644 index 000000000000000..4a349d438aa04e2 --- /dev/null +++ b/tests/kernel/sys_irq/shared_irq/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + aliases { + test-intd0 = &spi1; + test-intd1 = &i2c1; + }; +}; + +&spi1 { + status = "reserved"; +}; + +&i2c1 { + status = "reserved"; +}; diff --git a/tests/kernel/sys_irq/shared_irq/prj.conf b/tests/kernel/sys_irq/shared_irq/prj.conf new file mode 100644 index 000000000000000..a2d149408998b46 --- /dev/null +++ b/tests/kernel/sys_irq/shared_irq/prj.conf @@ -0,0 +1,7 @@ +# Copyright (c) 2024 Bjarki Arge Andreasen +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_ZTEST=y +CONFIG_ZTEST_FAIL_FAST=y +CONFIG_INTC=y +CONFIG_SYS_IRQ=y diff --git a/tests/kernel/sys_irq/shared_irq/src/test.c b/tests/kernel/sys_irq/shared_irq/src/test.c new file mode 100644 index 000000000000000..0084b8ed552e8a7 --- /dev/null +++ b/tests/kernel/sys_irq/shared_irq/src/test.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024 Bjarki Arge Andreasen + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#define TEST_IRQ_MAX_DELAY K_MSEC(10) + +#define INTD0_NODE DT_ALIAS(test_intd0) +#define INTD1_NODE DT_ALIAS(test_intd1) + +#define INTD0_SYS_IRQN SYS_DT_IRQN(INTD0_NODE) +#define INTD1_SYS_IRQN SYS_DT_IRQN(INTD1_NODE) + +#define INTD0_IRQ_FLAGS SYS_DT_IRQ_FLAGS(INTD0_NODE) +#define INTD1_IRQ_FLAGS SYS_DT_IRQ_FLAGS(INTD1_NODE) + +BUILD_ASSERT(INTD0_SYS_IRQN == INTD1_SYS_IRQN, "INTDs must share INTL"); +BUILD_ASSERT(INTD0_IRQ_FLAGS == INTD1_IRQ_FLAGS, "INTDs must share configuration flags"); +BUILD_ASSERT(DT_NODE_HAS_STATUS(INTD0_NODE, reserved), "INTD0 must have status reserved"); +BUILD_ASSERT(DT_NODE_HAS_STATUS(INTD1_NODE, reserved), "INTD1 must have status reserved"); + +static K_SEM_DEFINE(irq0_sem, 0, 1); +static K_SEM_DEFINE(irq1_sem, 0, 1); + +static uint32_t irq0_data; +static uint32_t irq1_data; + +static int irq0_handler(const void *data) +{ + zassert_equal(data, &irq0_data); + k_sem_give(&irq0_sem); + return *((const uint32_t *)data); +} + +static int irq1_handler(const void *data) +{ + zassert_equal(data, &irq1_data); + k_sem_give(&irq1_sem); + return *((const uint32_t *)data); +} + +SYS_DT_DEFINE_IRQ_HANDLER(INTD0_NODE, irq0_handler, &irq0_data); +SYS_DT_DEFINE_IRQ_HANDLER(INTD1_NODE, irq1_handler, &irq1_data); + +ZTEST(sys_irq_shared_irq, test__trigger_irq_intd0_origin__intd0_handles_irq) +{ + irq0_data = SYS_IRQ_HANDLED; + zassert_ok(sys_irq_enable(INTD0_SYS_IRQN)); + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), 0); +} + +ZTEST(sys_irq_shared_irq, test__trigger_irq_intd1_origin__intd1_handles_irq) +{ + irq1_data = SYS_IRQ_HANDLED; + zassert_ok(sys_irq_enable(INTD0_SYS_IRQN)); + zassert_ok(sys_irq_trigger(INTD0_SYS_IRQN)); + zassert_equal(k_sem_take(&irq1_sem, TEST_IRQ_MAX_DELAY), 0); +} + +void *test_init(void) +{ + zassert_ok(sys_irq_configure(INTD0_SYS_IRQN, INTD0_IRQ_FLAGS)); + zassert_equal(k_sem_take(&irq0_sem, TEST_IRQ_MAX_DELAY), -EAGAIN); + return NULL; +} + +void test_before(void *f) +{ + ARG_UNUSED(f); + + zassert(sys_irq_disable(INTD0_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_disable(INTD1_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_clear(INTD0_SYS_IRQN) > -1, "retval must be positive"); + zassert(sys_irq_clear(INTD1_SYS_IRQN) > -1, "retval must be positive"); + k_sem_reset(&irq0_sem); + k_sem_reset(&irq1_sem); + irq0_data = SYS_IRQ_NONE; + irq1_data = SYS_IRQ_NONE; +} + +ZTEST_SUITE(sys_irq_shared_irq, NULL, test_init, test_before, NULL, NULL); diff --git a/tests/kernel/sys_irq/shared_irq/testcase.yaml b/tests/kernel/sys_irq/shared_irq/testcase.yaml new file mode 100644 index 000000000000000..d76837c916bb031 --- /dev/null +++ b/tests/kernel/sys_irq/shared_irq/testcase.yaml @@ -0,0 +1,9 @@ +tests: + kernel.sys_irq.shared_irq: + platform_allow: + - nrf5340dk/nrf5340/cpuapp + kernel.sys_irq.shared_irq.lto: + extra_configs: + - CONFIG_LTO=y + platform_allow: + - nrf5340dk/nrf5340/cpuapp