From d18b4721b47d85b0d9e623ddbb5d741787fcf0aa Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sun, 21 Jul 2024 10:29:52 +0900 Subject: [PATCH] tests: kernel: gen_isr_table: add INTERRUPT_ID tests Adds tests for isr reordering enabled by CONFIG_ISR_TABLE_USE_INTERRUPT_ID. Signed-off-by: TOKITA Hiroshi --- tests/kernel/gen_isr_table/src/main.c | 104 ++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/tests/kernel/gen_isr_table/src/main.c b/tests/kernel/gen_isr_table/src/main.c index df6847c4afa865c..9a248a3a1167ae0 100644 --- a/tests/kernel/gen_isr_table/src/main.c +++ b/tests/kernel/gen_isr_table/src/main.c @@ -568,4 +568,108 @@ ZTEST(gen_isr_table, test_multi_level_bit_masks_l3) #endif /* CONFIG_MULTI_LEVEL_INTERRUPTS */ +#ifdef CONFIG_ISR_TABLE_USE_INTERRUPT_ID + +/** + * @ingroup kernel_interrupt_tests + * @brief test to validate ISRs reordering when ISR_TABLE_USE_INTERRUPT_ID enabled + * + * @details Verify that the index of the table to which the relocation is to be + * performed can be obtained by referencing __intr_id_table using the number + * specified in the IRQ element of IRQ_CONNECT or IRQ_DIRECT_CONNECT as an index. + */ +ZTEST(gen_isr_table, test_query_irq_by_interrupt_id) +{ +#ifdef ISR1_OFFSET + zassert_equal((uintptr_t)isr1, _irq_vector_table[__intr_id_table[IRQ_LINE(ISR1_OFFSET)]]); +#endif +#ifdef ISR2_OFFSET + zassert_equal((uintptr_t)isr2, _irq_vector_table[__intr_id_table[IRQ_LINE(ISR2_OFFSET)]]); +#endif +#ifdef ISR3_OFFSET + zassert_equal(isr3, _sw_isr_table[__intr_id_table[IRQ_LINE(ISR3_OFFSET)]].isr); + zassert_equal((void *)ISR3_ARG, _sw_isr_table[__intr_id_table[IRQ_LINE(ISR3_OFFSET)]].arg); +#endif +#ifdef ISR4_OFFSET + zassert_equal(isr4, _sw_isr_table[__intr_id_table[IRQ_LINE(ISR4_OFFSET)]].isr); + zassert_equal((void *)ISR4_ARG, _sw_isr_table[__intr_id_table[IRQ_LINE(ISR4_OFFSET)]].arg); +#endif +} + +/** + * @ingroup kernel_interrupt_tests + * @brief test to validate table structure when ISR_TABLE_USE_INTERRUPT_ID enabled + * + * @details If ISR_TABLE_USE_INTERRUPT_ID is enabled, the table will be rearranged. + * This test verifiy that the following is true: + * + * - If ISRs declared with IRQ_DIRECT_CONNECT are present, they are stored in + * _irq_vector_table in order starting from interrupt number 0. + * - The _sw_isr_table is populated with empty entries equal to the number of + * IRQ_DIRECT_CONNECTs at the beginning, followed by the ISRs declared with + * IRQ_CONNECT. + * - There are no duplicate entries in _irq_vector_table and _sw_isr_table. + * - There must not be a valid element in both _irq_vector_table and + * _sw_isr_table at the same ordinal position. + */ +ZTEST(gen_isr_table, test_interrupt_id_reordering) +{ + int vt_count = 0; + int swt_count = 0; + bool vt_continue = true; + bool swt_continue = true; + int vt_check_count = 0; + int swt_check_count = 0; + + for (int i = 0; i < CONFIG_NUM_IRQS; i++) { + if (_irq_vector_table[i] != (uintptr_t)&_isr_wrapper) { + zassert_true(vt_continue, "vt are not consecutively ordered. %d", i); + vt_count++; + } else { + vt_continue = false; + } + } + + for (int i = vt_count; i < CONFIG_NUM_IRQS; i++) { + if (_sw_isr_table[i].isr != z_irq_spurious) { + zassert_true(swt_continue, "swt are not consecutively ordered. %d", i); + swt_count++; + } else { + swt_continue = false; + } + } + + for (int j = 0; j <= CONFIG_MAX_INTERRUPT_ID; j++) { + int found_count = 0; + + if (__intr_id_table[j] == INVALID_INTR_ID) { + continue; + } + + for (int i = 0; i < CONFIG_NUM_IRQS; i++) { + if ((_irq_vector_table[i] != (uintptr_t)(&_isr_wrapper)) && + (_irq_vector_table[i] == _irq_vector_table[__intr_id_table[j]])) { + zassert_equal(_sw_isr_table[i].isr, z_irq_spurious, + "There are entries in both vt and swt."); + vt_check_count++; + found_count++; + } else if ((_sw_isr_table[i].isr != z_irq_spurious) && + (_sw_isr_table[i].isr == + _sw_isr_table[__intr_id_table[j]].isr)) { + zassert_equal(_irq_vector_table[i], (uintptr_t)(&_isr_wrapper), + "There are entries in both vt and swt."); + swt_check_count++; + found_count++; + } + } + + zassert_equal(1, found_count, "Unexpected count=%d, %d", found_count, j); + } + + zassert_equal(vt_count, vt_check_count); + zassert_equal(swt_count, swt_check_count); +} + +#endif /* CONFIG_ISR_TABLE_USE_INTERRUPT_ID */ + ZTEST_SUITE(gen_isr_table, NULL, gen_isr_table_setup, NULL, NULL, NULL);