Skip to content

Commit

Permalink
tests: interrupt: add testcase for functions in the sw_isr_table
Browse files Browse the repository at this point in the history
Validate the following functions in the sw_isr_table:
- z_get_sw_isr_table_idx
- z_get_sw_isr_device_from_irq
- z_get_sw_isr_irq_from_device

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
  • Loading branch information
ycsin committed Sep 29, 2023
1 parent 0ba16ec commit c455987
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/kernel/interrupt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ target_sources_ifdef(CONFIG_SHARED_INTERRUPTS app PRIVATE src/static_shared_irq.
if (CONFIG_SHARED_INTERRUPTS)
target_sources_ifdef(CONFIG_DYNAMIC_INTERRUPTS app PRIVATE src/dynamic_shared_irq.c)
endif()

if (CONFIG_MULTI_LEVEL_INTERRUPTS)
target_sources_ifdef(CONFIG_DYNAMIC_INTERRUPTS app PRIVATE src/sw_isr_table.c)
endif()
54 changes: 54 additions & 0 deletions tests/kernel/interrupt/src/sw_isr_table.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2023 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/ztest.h>

extern const struct _irq_parent_entry _lvl2_irq_list[];

/**
* @brief Test sw_isr_table function
*
* @details Validates that:
* - z_get_sw_isr_device_from_irq() returns the parent interrupt controller for an IRQN
* - z_get_sw_isr_irq_from_device() returns the IRQN of a parent interrupt controller
* - z_get_sw_isr_table_idx() returns the corresponding SW ISR table index for an IRQN
*/
ZTEST(interrupt_feature, test_sw_isr_irq_parent_table)
{
const struct device *parent_dev;
unsigned int parent_irq;
unsigned int parent_isr_offset;
const struct device *test_dev;
unsigned int test_irq;
unsigned int test_isr_offset;

for (size_t i = 0; i < CONFIG_NUM_2ND_LEVEL_AGGREGATORS; i++) {
parent_dev = _lvl2_irq_list[i].dev;
parent_irq = _lvl2_irq_list[i].irq;
parent_isr_offset = _lvl2_irq_list[i].offset;

for (unsigned int local_irq = 0;
local_irq < BIT_MASK(CONFIG_2ND_LEVEL_INTERRUPT_BITS); local_irq++) {
test_irq = irq_to_level_2(local_irq) | parent_irq;
test_dev = z_get_sw_isr_device_from_irq(test_irq);
zassert_equal_ptr(parent_dev, test_dev, "expected dev: %p, got: %p",
parent_dev, test_dev);
}

test_irq = z_get_sw_isr_irq_from_device(parent_dev);
zassert_equal(parent_irq, test_irq, "expected offset: %d, got: %d", parent_irq,
test_irq);

for (unsigned int local_irq = 0;
local_irq < BIT_MASK(CONFIG_2ND_LEVEL_INTERRUPT_BITS); local_irq++) {
test_irq = irq_to_level_2(local_irq) | parent_irq;
test_isr_offset = z_get_sw_isr_table_idx(test_irq);
zassert_equal(parent_isr_offset + local_irq, test_isr_offset,
"expected offset: %d, got: %d", parent_isr_offset + local_irq,
test_isr_offset);
}
}
}

0 comments on commit c455987

Please sign in to comment.