tests: kernel: interrupt: Reorganise tests
This commit re-organises the kernel interrupt tests for consistency. In addition, it removes any references to the `irq_offload` feature, which is no longer used by this test. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
This commit is contained in:
parent
9f6d9573fd
commit
66a53dd5cd
6 changed files with 126 additions and 102 deletions
|
@ -1,4 +1,3 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_IRQ_OFFLOAD=y
|
||||
CONFIG_DYNAMIC_INTERRUPTS=y
|
||||
CONFIG_MP_NUM_CPUS=1
|
||||
|
|
58
tests/kernel/interrupt/src/dynamic_isr.c
Normal file
58
tests/kernel/interrupt/src/dynamic_isr.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
|
||||
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
|
||||
}
|
|
@ -4,15 +4,17 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <irq_offload.h>
|
||||
#include <kernel_structs.h>
|
||||
#ifndef INTERRUPT_UTIL_H_
|
||||
#define INTERRUPT_UTIL_H_
|
||||
|
||||
#include <ztest.h>
|
||||
|
||||
#define MS_TO_US(ms) (K_MSEC(ms) * USEC_PER_MSEC)
|
||||
|
||||
#if defined(CONFIG_CPU_CORTEX_M)
|
||||
#include <arch/arm/aarch32/cortex_m/cmsis.h>
|
||||
|
||||
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_ */
|
|
@ -6,60 +6,10 @@
|
|||
|
||||
#include <ztest.h>
|
||||
|
||||
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,
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "interrupt.h"
|
||||
|
||||
#include <ztest.h>
|
||||
#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);
|
||||
}
|
||||
|
|
53
tests/kernel/interrupt/src/prevent_irq.c
Normal file
53
tests/kernel/interrupt/src/prevent_irq.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue