Skip to content

Commit

Permalink
tests: kernel: gen_isr_table: add INTERRUPT_ID tests
Browse files Browse the repository at this point in the history
Adds tests for isr reordering enabled by
CONFIG_ISR_TABLE_USE_INTERRUPT_ID.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
  • Loading branch information
soburi committed Jul 22, 2024
1 parent fb72e86 commit d18b472
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions tests/kernel/gen_isr_table/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit d18b472

Please sign in to comment.