diff --git a/tests/kernel/interrupt/prj.conf b/tests/kernel/interrupt/prj.conf index c3bf4666f6a..673e4724372 100644 --- a/tests/kernel/interrupt/prj.conf +++ b/tests/kernel/interrupt/prj.conf @@ -1,4 +1,3 @@ CONFIG_ZTEST=y -CONFIG_IRQ_OFFLOAD=y CONFIG_DYNAMIC_INTERRUPTS=y CONFIG_MP_NUM_CPUS=1 diff --git a/tests/kernel/interrupt/src/dynamic_isr.c b/tests/kernel/interrupt/src/dynamic_isr.c new file mode 100644 index 00000000000..31b4eb63592 --- /dev/null +++ b/tests/kernel/interrupt/src/dynamic_isr.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +extern void z_irq_spurious(void *unused); + +/* Simple whitebox test of dynamic interrupt handlers as implemented + * by the GEN_SW_ISR feature. + */ +#if (defined(CONFIG_DYNAMIC_INTERRUPTS) \ + && defined(CONFIG_GEN_SW_ISR_TABLE)) +#define DYNTEST 1 +#endif + +#ifdef DYNTEST +static void dyn_isr(void *arg) +{ + ARG_UNUSED(arg); +} + +extern struct _isr_table_entry __sw_isr_table _sw_isr_table[]; + +static void do_isr_dynamic(void) +{ + int i; + void *argval; + + for (i = 0; i < (CONFIG_NUM_IRQS - CONFIG_GEN_IRQ_START_VECTOR); i++) { + if (_sw_isr_table[i].isr == z_irq_spurious) { + break; + } + } + + zassert_true(_sw_isr_table[i].isr == z_irq_spurious, + "could not find slot for dynamic isr"); + + argval = &i; + arch_irq_connect_dynamic(i + CONFIG_GEN_IRQ_START_VECTOR, 0, dyn_isr, + argval, 0); + + zassert_true(_sw_isr_table[i].isr == dyn_isr && + _sw_isr_table[i].arg == argval, + "dynamic isr did not install successfully"); +} +#endif /* DYNTEST */ + +void test_isr_dynamic(void) +{ +#ifdef DYNTEST + do_isr_dynamic(); +#else + ztest_test_skip(); +#endif +} diff --git a/tests/kernel/interrupt/src/interrupt.h b/tests/kernel/interrupt/src/interrupt_util.h similarity index 81% rename from tests/kernel/interrupt/src/interrupt.h rename to tests/kernel/interrupt/src/interrupt_util.h index 00e00bb99a9..11e39992e00 100644 --- a/tests/kernel/interrupt/src/interrupt.h +++ b/tests/kernel/interrupt/src/interrupt_util.h @@ -4,15 +4,17 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include -#include +#ifndef INTERRUPT_UTIL_H_ +#define INTERRUPT_UTIL_H_ +#include + +#define MS_TO_US(ms) (K_MSEC(ms) * USEC_PER_MSEC) #if defined(CONFIG_CPU_CORTEX_M) #include -static u32_t get_available_nvic_line(u32_t initial_offset) +static inline u32_t get_available_nvic_line(u32_t initial_offset) { int i; @@ -44,7 +46,7 @@ static u32_t get_available_nvic_line(u32_t initial_offset) return i; } -static void trigger_irq(int irq) +static inline void trigger_irq(int irq) { printk("Triggering irq : %d\n", irq); #if defined(CONFIG_SOC_TI_LM3S6965_QEMU) || defined(CONFIG_CPU_CORTEX_M0) \ @@ -56,7 +58,7 @@ static void trigger_irq(int irq) } #elif defined(CONFIG_RISCV) -static void trigger_irq(int irq) +static inline void trigger_irq(int irq) { u32_t mip; @@ -67,7 +69,7 @@ static void trigger_irq(int irq) } #elif defined(CONFIG_CPU_ARCV2) -static void trigger_irq(int irq) +static inline void trigger_irq(int irq) { printk("Triggering irq : %d\n", irq); z_arc_v2_aux_reg_write(_ARC_V2_AUX_IRQ_HINT, irq); @@ -76,3 +78,5 @@ static void trigger_irq(int irq) /* for not supported architecture */ #define NO_TRIGGER_FROM_SW #endif + +#endif /* INTERRUPT_UTIL_H_ */ diff --git a/tests/kernel/interrupt/src/main.c b/tests/kernel/interrupt/src/main.c index cd56d626764..6f396f3ee2c 100644 --- a/tests/kernel/interrupt/src/main.c +++ b/tests/kernel/interrupt/src/main.c @@ -6,60 +6,10 @@ #include +extern void test_isr_dynamic(void); extern void test_nested_isr(void); extern void test_prevent_interruption(void); -extern void z_irq_spurious(void *unused); - -/* Simple whitebox test of dynamic interrupt handlers as implemented - * by the GEN_SW_ISR feature. - */ -#if (defined(CONFIG_DYNAMIC_INTERRUPTS) \ - && defined(CONFIG_GEN_SW_ISR_TABLE)) -#define DYNTEST 1 -#endif - -#ifdef DYNTEST -static void dyn_isr(void *arg) -{ - ARG_UNUSED(arg); -} - -extern struct _isr_table_entry __sw_isr_table _sw_isr_table[]; - -static void do_isr_dynamic(void) -{ - int i; - void *argval; - - for (i = 0; i < (CONFIG_NUM_IRQS - CONFIG_GEN_IRQ_START_VECTOR); i++) { - if (_sw_isr_table[i].isr == z_irq_spurious) { - break; - } - } - - zassert_true(_sw_isr_table[i].isr == z_irq_spurious, - "could not find slot for dynamic isr"); - - argval = &i; - arch_irq_connect_dynamic(i + CONFIG_GEN_IRQ_START_VECTOR, 0, dyn_isr, - argval, 0); - - zassert_true(_sw_isr_table[i].isr == dyn_isr && - _sw_isr_table[i].arg == argval, - "dynamic isr did not install successfully"); -} -#endif /* DYNTEST */ - -void test_isr_dynamic(void) -{ -#ifdef DYNTEST - do_isr_dynamic(); -#else - ztest_test_skip(); -#endif -} - void test_main(void) { ztest_test_suite(interrupt_feature, diff --git a/tests/kernel/interrupt/src/nested_irq.c b/tests/kernel/interrupt/src/nested_irq.c index b4f1a8a5fdf..ad5ca366298 100644 --- a/tests/kernel/interrupt/src/nested_irq.c +++ b/tests/kernel/interrupt/src/nested_irq.c @@ -3,11 +3,12 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include "interrupt.h" + +#include +#include "interrupt_util.h" #define DURATION 5 struct k_timer timer; -struct k_timer irqlock_timer; /* This tests uses two IRQ lines, selected within the range of IRQ lines * available on the target SOC the test executes on (and starting from @@ -34,11 +35,8 @@ u32_t irq_line_1; #define ISR1_PRIO 0 #endif /* CONFIG_CPU_CORTEX_M */ -#define MS_TO_US(ms) (K_MSEC(ms) * USEC_PER_MSEC) volatile u32_t new_val; u32_t old_val = 0xDEAD; -volatile u32_t check_lock_new; -u32_t check_lock_old = 0xBEEF; void isr1(void *param) { @@ -130,41 +128,3 @@ void test_nested_isr(void) ztest_test_skip(); } #endif /* NO_TRIGGER_FROM_SW */ - -static void timer_handler(struct k_timer *timer) -{ - ARG_UNUSED(timer); - check_lock_new = 0xBEEF; - printk("timer fired\n"); -} - -void test_prevent_interruption(void) -{ - int key; - - printk("locking interrupts\n"); - key = irq_lock(); - - check_lock_new = 0; - - k_timer_init(&irqlock_timer, timer_handler, NULL); - - /* Start the timer and busy-wait for a bit with IRQs locked. The - * timer ought to have fired during this time if interrupts weren't - * locked -- but since they are, check_lock_new isn't updated. - */ - k_timer_start(&irqlock_timer, DURATION, K_NO_WAIT); - k_busy_wait(MS_TO_US(1000)); - zassert_not_equal(check_lock_new, check_lock_old, - "Interrupt locking didn't work properly"); - - printk("unlocking interrupts\n"); - irq_unlock(key); - - k_busy_wait(MS_TO_US(1000)); - - zassert_equal(check_lock_new, check_lock_old, - "timer should have fired"); - - k_timer_stop(&irqlock_timer); -} diff --git a/tests/kernel/interrupt/src/prevent_irq.c b/tests/kernel/interrupt/src/prevent_irq.c new file mode 100644 index 00000000000..8793b10db1a --- /dev/null +++ b/tests/kernel/interrupt/src/prevent_irq.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "interrupt_util.h" + +#define DURATION 5 + +static struct k_timer irqlock_timer; + +volatile u32_t check_lock_new; +u32_t check_lock_old = 0xBEEF; + +static void timer_handler(struct k_timer *timer) +{ + ARG_UNUSED(timer); + check_lock_new = 0xBEEF; + printk("timer fired\n"); +} + +void test_prevent_interruption(void) +{ + int key; + + printk("locking interrupts\n"); + key = irq_lock(); + + check_lock_new = 0; + + k_timer_init(&irqlock_timer, timer_handler, NULL); + + /* Start the timer and busy-wait for a bit with IRQs locked. The + * timer ought to have fired during this time if interrupts weren't + * locked -- but since they are, check_lock_new isn't updated. + */ + k_timer_start(&irqlock_timer, DURATION, K_NO_WAIT); + k_busy_wait(MS_TO_US(1000)); + zassert_not_equal(check_lock_new, check_lock_old, + "Interrupt locking didn't work properly"); + + printk("unlocking interrupts\n"); + irq_unlock(key); + + k_busy_wait(MS_TO_US(1000)); + + zassert_equal(check_lock_new, check_lock_old, + "timer should have fired"); + + k_timer_stop(&irqlock_timer); +}