Skip to content

Commit 5c335ce

Browse files
author
Andrew Boie
committed
tests: gen_isr_table: actually run the IRQ
So far, only implemented on ARM. It's not possible to do this on Nios II and RISC-V. Change-Id: I84c8d99cd163dff46de4bc4a7ae40768daf8e4ce Signed-off-by: Andrew Boie <[email protected]>
1 parent bd69c3b commit 5c335ce

File tree

2 files changed

+74
-15
lines changed

2 files changed

+74
-15
lines changed
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
# Nothing yet
2-
1+
# Need to turn optimization off. Otherwise compiler may generate
2+
# incorrect code, not knowing that trigger_irq() affects the value
3+
# of trigger_check, even if declared volatile.
4+
# A memory barrier does not help, we need an 'instruction barrier' but
5+
# GCC doesn't support this; we need to tell the compiler not to reorder
6+
# memory accesses to trigger_check around calls to trigger_irq.
7+
CONFIG_COMPILER_OPT="-O0"

tests/kernel/gen_isr_table/src/main.c

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,85 @@ extern uint32_t _irq_vector_table[];
1515
#define HAS_DIRECT_IRQS
1616
#endif
1717

18+
#define ISR1_OFFSET 0
19+
#define ISR2_OFFSET 1
20+
#define ISR3_OFFSET 2
21+
#define ISR4_OFFSET 3
22+
23+
#define IRQ_LINE(offset) (CONFIG_NUM_IRQS - ((offset) + 1))
24+
#define TABLE_INDEX(offset) (IRQ_TABLE_SIZE - ((offset) + 1))
25+
26+
#define ISR3_ARG 0xb01dface
27+
#define ISR4_ARG 0xca55e77e
28+
static volatile int trigger_check[4];
29+
30+
#if defined(CONFIG_ARM)
31+
#include <arch/arm/cortex_m/cmsis.h>
32+
33+
void trigger_irq(int irq)
34+
{
35+
#if defined(CONFIG_SOC_TI_LM3S6965_QEMU)
36+
/* QEMU does not simulate the STIR register: this is a workaround */
37+
NVIC_SetPendingIRQ(irq);
38+
#else
39+
NVIC->STIR = irq;
40+
#endif
41+
}
42+
#else
43+
/* So far, Nios II and Risc V do not support this */
44+
#define NO_TRIGGER_FROM_SW
45+
#endif
46+
1847
#ifdef HAS_DIRECT_IRQS
1948
ISR_DIRECT_DECLARE(isr1)
2049
{
21-
printk("isr1\n");
50+
printk("isr1 ran\n");
51+
trigger_check[ISR1_OFFSET]++;
2252
return 0;
2353
}
2454

2555
ISR_DIRECT_DECLARE(isr2)
2656
{
27-
printk("isr2\n");
57+
printk("isr2 ran\n");
58+
trigger_check[ISR2_OFFSET]++;
2859
return 1;
2960
}
3061
#endif
3162

3263
void isr3(void *param)
3364
{
34-
printk("isr3 %p\n", param);
65+
printk("isr3 ran with parameter %p\n", param);
66+
trigger_check[ISR3_OFFSET]++;
3567
}
3668

3769

3870
void isr4(void *param)
3971
{
40-
printk("isr4 %p\n", param);
72+
printk("isr4 ran with parameter %p\n", param);
73+
trigger_check[ISR4_OFFSET]++;
4174
}
4275

43-
#define ISR1_OFFSET 0
44-
#define ISR2_OFFSET 1
45-
#define ISR3_OFFSET 2
46-
#define ISR4_OFFSET 3
76+
int test_irq(int offset)
77+
{
78+
#ifndef NO_TRIGGER_FROM_SW
79+
TC_PRINT("triggering irq %d\n", IRQ_LINE(offset));
80+
trigger_irq(IRQ_LINE(offset));
81+
if (trigger_check[offset] != 1) {
82+
TC_PRINT("interrupt %d didn't run once, ran %d times\n",
83+
IRQ_LINE(offset),
84+
trigger_check[offset]);
85+
return -1;
86+
}
87+
#else
88+
/* This arch doesn't support triggering interrupts from software */
89+
ARG_UNUSED(offset);
90+
#endif
91+
return 0;
92+
}
4793

48-
#define IRQ_LINE(offset) (CONFIG_NUM_IRQS - ((offset) + 1))
49-
#define TABLE_INDEX(offset) (IRQ_TABLE_SIZE - ((offset) + 1))
5094

51-
#define ISR3_ARG 0xb01dface
52-
#define ISR4_ARG 0xca55e77e
5395

54-
#ifdef CONFIG_GEN_IRQ_VECTOR_TABLE
96+
#ifdef HAS_DIRECT_IRQS
5597
static int check_vector(void *isr, int offset)
5698
{
5799
TC_PRINT("Checking _irq_vector_table entry %d for irq %d\n",
@@ -61,6 +103,11 @@ static int check_vector(void *isr, int offset)
61103
TC_PRINT("bad entry %d in vector table\n", TABLE_INDEX(offset));
62104
return -1;
63105
}
106+
107+
if (test_irq(offset)) {
108+
return -1;
109+
}
110+
64111
return 0;
65112
}
66113
#endif
@@ -94,6 +141,9 @@ static int check_sw_isr(void *isr, uint32_t arg, int offset)
94141
}
95142
#endif
96143

144+
if (test_irq(offset)) {
145+
return -1;
146+
}
97147
return 0;
98148
}
99149
#endif
@@ -109,6 +159,8 @@ void main(void)
109159
#ifdef HAS_DIRECT_IRQS
110160
IRQ_DIRECT_CONNECT(IRQ_LINE(ISR1_OFFSET), 0, isr1, 0);
111161
IRQ_DIRECT_CONNECT(IRQ_LINE(ISR2_OFFSET), 0, isr2, 0);
162+
irq_enable(IRQ_LINE(ISR1_OFFSET));
163+
irq_enable(IRQ_LINE(ISR2_OFFSET));
112164
TC_PRINT("isr1 isr=%p irq=%d\n", isr1, IRQ_LINE(ISR1_OFFSET));
113165
TC_PRINT("isr2 isr=%p irq=%d\n", isr2, IRQ_LINE(ISR2_OFFSET));
114166

@@ -126,6 +178,8 @@ void main(void)
126178
#ifdef CONFIG_GEN_SW_ISR_TABLE
127179
IRQ_CONNECT(IRQ_LINE(ISR3_OFFSET), 1, isr3, ISR3_ARG, 0);
128180
IRQ_CONNECT(IRQ_LINE(ISR4_OFFSET), 2, isr4, ISR4_ARG, 0);
181+
irq_enable(IRQ_LINE(ISR3_OFFSET));
182+
irq_enable(IRQ_LINE(ISR4_OFFSET));
129183
TC_PRINT("isr3 isr=%p irq=%d param=%p\n", isr3, IRQ_LINE(ISR3_OFFSET),
130184
(void *)ISR3_ARG);
131185
TC_PRINT("isr4 isr=%p irq=%d param=%p\n", isr4, IRQ_LINE(ISR4_OFFSET),

0 commit comments

Comments
 (0)