Skip to content

Commit 92203c3

Browse files
authored
Merge pull request #4951 from supperthomas/add_kernel_irq_utest
[utest][kernel_irq] add the utest of irq
2 parents 88dd2b0 + b4a46f8 commit 92203c3

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

examples/utest/testcases/kernel/Kconfig

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ config UTEST_MEMHEAP_TC
55
default y
66
depends on RT_USING_MEMHEAP
77

8+
config UTEST_IRQ_TC
9+
bool "IRQ test"
10+
default n
11+
812
config UTEST_SEMAPHORE_TC
913
bool "semaphore test"
1014
default n

examples/utest/testcases/kernel/SConscript

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ src = Split('''
88
if GetDepend(['UTEST_MEMHEAP_TC']):
99
src += ['memheap_tc.c']
1010

11+
if GetDepend(['UTEST_IRQ_TC']):
12+
src += ['irq_tc.c']
13+
1114
if GetDepend(['UTEST_SEMAPHORE_TC']):
1215
src += ['semaphore_tc.c']
1316

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-08-15 supperthomas add irq_test
9+
*/
10+
11+
#include <rtthread.h>
12+
#include "utest.h"
13+
#include "rthw.h"
14+
15+
#define UTEST_NAME "irq_tc"
16+
static uint32_t irq_count = 0;
17+
static uint32_t max_get_nest_count = 0;
18+
19+
static void irq_callback()
20+
{
21+
if(rt_interrupt_get_nest() > max_get_nest_count)
22+
{
23+
max_get_nest_count = rt_interrupt_get_nest();
24+
}
25+
irq_count ++;
26+
}
27+
28+
static void irq_test(void)
29+
{
30+
irq_count = 0;
31+
rt_interrupt_enter_sethook(irq_callback);
32+
rt_interrupt_leave_sethook(irq_callback);
33+
rt_thread_mdelay(2);
34+
LOG_D("%s test irq_test! irq_count %d max_get_nest_count %d\n", UTEST_NAME, irq_count, max_get_nest_count);
35+
uassert_int_not_equal(0, irq_count);
36+
uassert_int_not_equal(0, max_get_nest_count);
37+
rt_interrupt_enter_sethook(RT_NULL);
38+
rt_interrupt_leave_sethook(RT_NULL);
39+
LOG_D("irq_test OK!\n");
40+
}
41+
42+
static rt_err_t utest_tc_init(void)
43+
{
44+
irq_count = 0;
45+
max_get_nest_count = 0;
46+
return RT_EOK;
47+
}
48+
49+
static rt_err_t utest_tc_cleanup(void)
50+
{
51+
return RT_EOK;
52+
}
53+
54+
static void interrupt_test(void)
55+
{
56+
rt_base_t level;
57+
uint32_t i = 1000;
58+
59+
rt_interrupt_enter_sethook(irq_callback);
60+
rt_interrupt_leave_sethook(irq_callback);
61+
irq_count = 0;
62+
level = rt_hw_interrupt_disable();
63+
while(i)
64+
{
65+
i --;
66+
}
67+
uassert_int_equal(0, irq_count);
68+
rt_hw_interrupt_enable(level);
69+
rt_interrupt_enter_sethook(RT_NULL);
70+
rt_interrupt_leave_sethook(RT_NULL);
71+
72+
}
73+
static void testcase(void)
74+
{
75+
UTEST_UNIT_RUN(irq_test);
76+
UTEST_UNIT_RUN(interrupt_test);
77+
}
78+
UTEST_TC_EXPORT(testcase, "testcases.kernel.irq_tc", utest_tc_init, utest_tc_cleanup, 10);

0 commit comments

Comments
 (0)