Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2345VOR
rt-thread
提交
31914146
R
rt-thread
项目概览
2345VOR
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
31914146
编写于
8月 20, 2021
作者:
W
WaterFishJ
提交者:
GitHub
8月 20, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'RT-Thread:master' into master
上级
26db04e7
05098bd5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
166 addition
and
41 deletion
+166
-41
components/utilities/utest/utest.c
components/utilities/utest/utest.c
+40
-0
examples/utest/testcases/kernel/Kconfig
examples/utest/testcases/kernel/Kconfig
+4
-0
examples/utest/testcases/kernel/SConscript
examples/utest/testcases/kernel/SConscript
+3
-0
examples/utest/testcases/kernel/irq_tc.c
examples/utest/testcases/kernel/irq_tc.c
+78
-0
src/timer.c
src/timer.c
+41
-41
未找到文件。
components/utilities/utest/utest.c
浏览文件 @
31914146
...
...
@@ -46,12 +46,17 @@ static rt_uint8_t utest_log_lv = UTEST_LOG_ALL;
static
utest_tc_export_t
tc_table
=
RT_NULL
;
static
rt_size_t
tc_num
;
static
rt_uint32_t
tc_loop
;
static
rt_uint8_t
*
tc_fail_list
;
static
struct
utest
local_utest
=
{
UTEST_PASSED
,
0
,
0
};
#if defined(__ICCARM__) || defined(__ICCRX__)
/* for IAR compiler */
#pragma section="UtestTcTab"
#endif
#define TC_FAIL_LIST_SIZE (RT_ALIGN(tc_num, 8) / 8)
#define TC_FAIL_LIST_MARK_FAILED(index) (tc_fail_list[RT_ALIGN(index, 8) / 8] |= (1UL << (index % 8)))
#define TC_FAIL_LIST_IS_FAILED(index) (tc_fail_list[RT_ALIGN(index, 8) / 8] & (1UL << (index % 8)))
void
utest_log_lv_set
(
rt_uint8_t
lv
)
{
if
(
lv
==
UTEST_LOG_ALL
||
lv
==
UTEST_LOG_ASSERT
)
...
...
@@ -80,6 +85,14 @@ int utest_init(void)
LOG_I
(
"utest is initialize success."
);
LOG_I
(
"total utest testcase num: (%d)"
,
tc_num
);
if
(
tc_num
>
0
)
{
tc_fail_list
=
rt_malloc
(
TC_FAIL_LIST_SIZE
);
if
(
!
tc_fail_list
)
{
LOG_E
(
"no memory, tc_fail_list init failed!"
);
}
}
return
tc_num
;
}
INIT_COMPONENT_EXPORT
(
utest_init
);
...
...
@@ -147,6 +160,8 @@ static void utest_run(const char *utest_name)
rt_size_t
i
;
rt_uint32_t
index
;
rt_bool_t
is_find
;
rt_uint32_t
tc_fail_num
=
0
;
rt_uint32_t
tc_run_num
=
0
;
rt_thread_mdelay
(
1000
);
...
...
@@ -154,6 +169,14 @@ static void utest_run(const char *utest_name)
{
i
=
0
;
is_find
=
RT_FALSE
;
tc_fail_num
=
0
;
tc_run_num
=
0
;
if
(
tc_fail_list
)
{
memset
(
tc_fail_list
,
0
,
TC_FAIL_LIST_SIZE
);
}
LOG_I
(
"[==========] [ utest ] loop %d/%d"
,
index
+
1
,
tc_loop
);
LOG_I
(
"[==========] [ utest ] started"
);
while
(
i
<
tc_num
)
...
...
@@ -192,6 +215,8 @@ static void utest_run(const char *utest_name)
}
else
{
TC_FAIL_LIST_MARK_FAILED
(
i
);
tc_fail_num
++
;
LOG_E
(
"[ FAILED ] [ result ] testcase (%s)"
,
tc_table
[
i
].
name
);
}
}
...
...
@@ -212,6 +237,7 @@ static void utest_run(const char *utest_name)
__tc_continue:
LOG_I
(
"[----------] [ testcase ] (%s) finished"
,
tc_table
[
i
].
name
);
tc_run_num
++
;
i
++
;
}
...
...
@@ -223,6 +249,20 @@ static void utest_run(const char *utest_name)
}
LOG_I
(
"[==========] [ utest ] finished"
);
LOG_I
(
"[==========] [ utest ] %d tests from %d testcase ran."
,
tc_run_num
,
tc_num
);
LOG_I
(
"[ PASSED ] [ result ] %d tests."
,
tc_run_num
-
tc_fail_num
);
if
(
tc_fail_list
&&
(
tc_fail_num
>
0
))
{
LOG_E
(
"[ FAILED ] [ result ] %d tests, listed below:"
,
tc_fail_num
);
for
(
i
=
0
;
i
<
tc_num
;
i
++
)
{
if
(
TC_FAIL_LIST_IS_FAILED
(
i
))
{
LOG_E
(
"[ FAILED ] [ result ] %s"
,
tc_table
[
i
].
name
);
}
}
}
}
}
...
...
examples/utest/testcases/kernel/Kconfig
浏览文件 @
31914146
...
...
@@ -5,6 +5,10 @@ config UTEST_MEMHEAP_TC
default y
depends on RT_USING_MEMHEAP
config UTEST_IRQ_TC
bool "IRQ test"
default n
config UTEST_SEMAPHORE_TC
bool "semaphore test"
default n
...
...
examples/utest/testcases/kernel/SConscript
浏览文件 @
31914146
...
...
@@ -8,6 +8,9 @@ src = Split('''
if
GetDepend
([
'UTEST_MEMHEAP_TC'
]):
src
+=
[
'memheap_tc.c'
]
if
GetDepend
([
'UTEST_IRQ_TC'
]):
src
+=
[
'irq_tc.c'
]
if
GetDepend
([
'UTEST_SEMAPHORE_TC'
]):
src
+=
[
'semaphore_tc.c'
]
...
...
examples/utest/testcases/kernel/irq_tc.c
0 → 100644
浏览文件 @
31914146
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-15 supperthomas add irq_test
*/
#include <rtthread.h>
#include "utest.h"
#include "rthw.h"
#define UTEST_NAME "irq_tc"
static
uint32_t
irq_count
=
0
;
static
uint32_t
max_get_nest_count
=
0
;
static
void
irq_callback
()
{
if
(
rt_interrupt_get_nest
()
>
max_get_nest_count
)
{
max_get_nest_count
=
rt_interrupt_get_nest
();
}
irq_count
++
;
}
static
void
irq_test
(
void
)
{
irq_count
=
0
;
rt_interrupt_enter_sethook
(
irq_callback
);
rt_interrupt_leave_sethook
(
irq_callback
);
rt_thread_mdelay
(
2
);
LOG_D
(
"%s test irq_test! irq_count %d max_get_nest_count %d
\n
"
,
UTEST_NAME
,
irq_count
,
max_get_nest_count
);
uassert_int_not_equal
(
0
,
irq_count
);
uassert_int_not_equal
(
0
,
max_get_nest_count
);
rt_interrupt_enter_sethook
(
RT_NULL
);
rt_interrupt_leave_sethook
(
RT_NULL
);
LOG_D
(
"irq_test OK!
\n
"
);
}
static
rt_err_t
utest_tc_init
(
void
)
{
irq_count
=
0
;
max_get_nest_count
=
0
;
return
RT_EOK
;
}
static
rt_err_t
utest_tc_cleanup
(
void
)
{
return
RT_EOK
;
}
static
void
interrupt_test
(
void
)
{
rt_base_t
level
;
uint32_t
i
=
1000
;
rt_interrupt_enter_sethook
(
irq_callback
);
rt_interrupt_leave_sethook
(
irq_callback
);
irq_count
=
0
;
level
=
rt_hw_interrupt_disable
();
while
(
i
)
{
i
--
;
}
uassert_int_equal
(
0
,
irq_count
);
rt_hw_interrupt_enable
(
level
);
rt_interrupt_enter_sethook
(
RT_NULL
);
rt_interrupt_leave_sethook
(
RT_NULL
);
}
static
void
testcase
(
void
)
{
UTEST_UNIT_RUN
(
irq_test
);
UTEST_UNIT_RUN
(
interrupt_test
);
}
UTEST_TC_EXPORT
(
testcase
,
"testcases.kernel.irq_tc"
,
utest_tc_init
,
utest_tc_cleanup
,
10
);
src/timer.c
浏览文件 @
31914146
...
...
@@ -23,7 +23,7 @@
#include <rthw.h>
/* hard timer list */
static
rt_list_t
rt
_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
];
static
rt_list_t
_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
];
#ifdef RT_USING_TIMER_SOFT
...
...
@@ -39,12 +39,12 @@ static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL];
#endif
/* RT_TIMER_THREAD_PRIO */
/* soft timer status */
static
rt_uint8_t
soft_timer_status
=
RT_SOFT_TIMER_IDLE
;
static
rt_uint8_t
_
soft_timer_status
=
RT_SOFT_TIMER_IDLE
;
/* soft timer list */
static
rt_list_t
rt
_soft_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
];
static
struct
rt_thread
timer_thread
;
static
rt_list_t
_soft_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
];
static
struct
rt_thread
_
timer_thread
;
ALIGN
(
RT_ALIGN_SIZE
)
static
rt_uint8_t
timer_thread_stack
[
RT_TIMER_THREAD_STACK_SIZE
];
static
rt_uint8_t
_
timer_thread_stack
[
RT_TIMER_THREAD_STACK_SIZE
];
#endif
/* RT_USING_TIMER_SOFT */
#ifdef RT_USING_HOOK
...
...
@@ -98,7 +98,7 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer))
* @param time the tick of timer
* @param flag the flag of timer
*/
static
void
_
rt_
timer_init
(
rt_timer_t
timer
,
static
void
_timer_init
(
rt_timer_t
timer
,
void
(
*
timeout
)(
void
*
parameter
),
void
*
parameter
,
rt_tick_t
time
,
...
...
@@ -132,7 +132,7 @@ static void _rt_timer_init(rt_timer_t timer,
*
* @return rt_tick_t the point of timer
*/
static
rt_tick_t
rt
_timer_list_next_timeout
(
rt_list_t
timer_list
[])
static
rt_tick_t
_timer_list_next_timeout
(
rt_list_t
timer_list
[])
{
struct
rt_timer
*
timer
;
register
rt_base_t
level
;
...
...
@@ -159,7 +159,7 @@ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[])
*
* @param timer the point of timer
*/
rt_inline
void
_
rt_
timer_remove
(
rt_timer_t
timer
)
rt_inline
void
_timer_remove
(
rt_timer_t
timer
)
{
int
i
;
...
...
@@ -176,7 +176,7 @@ rt_inline void _rt_timer_remove(rt_timer_t timer)
* @param timer
* @return int the count
*/
static
int
rt
_timer_count_height
(
struct
rt_timer
*
timer
)
static
int
_timer_count_height
(
struct
rt_timer
*
timer
)
{
int
i
,
cnt
=
0
;
...
...
@@ -203,7 +203,7 @@ void rt_timer_dump(rt_list_t timer_heads[])
struct
rt_timer
*
timer
=
rt_list_entry
(
list
,
struct
rt_timer
,
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]);
rt_kprintf
(
"%d"
,
rt
_timer_count_height
(
timer
));
rt_kprintf
(
"%d"
,
_timer_count_height
(
timer
));
}
rt_kprintf
(
"
\n
"
);
}
...
...
@@ -238,7 +238,7 @@ void rt_timer_init(rt_timer_t timer,
/* timer object initialization */
rt_object_init
(
&
(
timer
->
parent
),
RT_Object_Class_Timer
,
name
);
_
rt_
timer_init
(
timer
,
timeout
,
parameter
,
time
,
flag
);
_timer_init
(
timer
,
timeout
,
parameter
,
time
,
flag
);
}
RTM_EXPORT
(
rt_timer_init
);
...
...
@@ -260,7 +260,7 @@ rt_err_t rt_timer_detach(rt_timer_t timer)
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
_
rt_
timer_remove
(
timer
);
_timer_remove
(
timer
);
/* stop timer */
timer
->
parent
.
flag
&=
~
RT_TIMER_FLAG_ACTIVATED
;
...
...
@@ -300,7 +300,7 @@ rt_timer_t rt_timer_create(const char *name,
return
RT_NULL
;
}
_
rt_
timer_init
(
timer
,
timeout
,
parameter
,
time
,
flag
);
_timer_init
(
timer
,
timeout
,
parameter
,
time
,
flag
);
return
timer
;
}
...
...
@@ -325,7 +325,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer)
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
_
rt_
timer_remove
(
timer
);
_timer_remove
(
timer
);
/* stop timer */
timer
->
parent
.
flag
&=
~
RT_TIMER_FLAG_ACTIVATED
;
...
...
@@ -362,7 +362,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
/* stop timer firstly */
level
=
rt_hw_interrupt_disable
();
/* remove timer from list */
_
rt_
timer_remove
(
timer
);
_timer_remove
(
timer
);
/* change status of timer */
timer
->
parent
.
flag
&=
~
RT_TIMER_FLAG_ACTIVATED
;
...
...
@@ -379,13 +379,13 @@ rt_err_t rt_timer_start(rt_timer_t timer)
if
(
timer
->
parent
.
flag
&
RT_TIMER_FLAG_SOFT_TIMER
)
{
/* insert timer to soft timer list */
timer_list
=
rt
_soft_timer_list
;
timer_list
=
_soft_timer_list
;
}
else
#endif
/* RT_USING_TIMER_SOFT */
{
/* insert timer to system timer list */
timer_list
=
rt
_timer_list
;
timer_list
=
_timer_list
;
}
row_head
[
0
]
=
&
timer_list
[
0
];
...
...
@@ -448,11 +448,11 @@ rt_err_t rt_timer_start(rt_timer_t timer)
if
(
timer
->
parent
.
flag
&
RT_TIMER_FLAG_SOFT_TIMER
)
{
/* check whether timer thread is ready */
if
((
soft_timer_status
==
RT_SOFT_TIMER_IDLE
)
&&
((
timer_thread
.
stat
&
RT_THREAD_STAT_MASK
)
==
RT_THREAD_SUSPEND
))
if
((
_
soft_timer_status
==
RT_SOFT_TIMER_IDLE
)
&&
((
_
timer_thread
.
stat
&
RT_THREAD_STAT_MASK
)
==
RT_THREAD_SUSPEND
))
{
/* resume timer thread to check soft timer */
rt_thread_resume
(
&
timer_thread
);
rt_thread_resume
(
&
_
timer_thread
);
rt_schedule
();
}
}
...
...
@@ -485,7 +485,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
_
rt_
timer_remove
(
timer
);
_timer_remove
(
timer
);
/* change status */
timer
->
parent
.
flag
&=
~
RT_TIMER_FLAG_ACTIVATED
;
...
...
@@ -576,9 +576,9 @@ void rt_timer_check(void)
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
while
(
!
rt_list_isempty
(
&
rt
_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]))
while
(
!
rt_list_isempty
(
&
_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]))
{
t
=
rt_list_entry
(
rt
_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
].
next
,
t
=
rt_list_entry
(
_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
].
next
,
struct
rt_timer
,
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]);
/*
...
...
@@ -590,7 +590,7 @@ void rt_timer_check(void)
RT_OBJECT_HOOK_CALL
(
rt_timer_enter_hook
,
(
t
));
/* remove timer from timer list firstly */
_
rt_
timer_remove
(
t
);
_timer_remove
(
t
);
if
(
!
(
t
->
parent
.
flag
&
RT_TIMER_FLAG_PERIODIC
))
{
t
->
parent
.
flag
&=
~
RT_TIMER_FLAG_ACTIVATED
;
...
...
@@ -636,7 +636,7 @@ void rt_timer_check(void)
*/
rt_tick_t
rt_timer_next_timeout_tick
(
void
)
{
return
rt_timer_list_next_timeout
(
rt
_timer_list
);
return
_timer_list_next_timeout
(
_timer_list
);
}
#ifdef RT_USING_TIMER_SOFT
...
...
@@ -658,9 +658,9 @@ void rt_soft_timer_check(void)
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
while
(
!
rt_list_isempty
(
&
rt
_soft_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]))
while
(
!
rt_list_isempty
(
&
_soft_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]))
{
t
=
rt_list_entry
(
rt
_soft_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
].
next
,
t
=
rt_list_entry
(
_soft_timer_list
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
].
next
,
struct
rt_timer
,
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]);
current_tick
=
rt_tick_get
();
...
...
@@ -674,7 +674,7 @@ void rt_soft_timer_check(void)
RT_OBJECT_HOOK_CALL
(
rt_timer_enter_hook
,
(
t
));
/* remove timer from timer list firstly */
_
rt_
timer_remove
(
t
);
_timer_remove
(
t
);
if
(
!
(
t
->
parent
.
flag
&
RT_TIMER_FLAG_PERIODIC
))
{
t
->
parent
.
flag
&=
~
RT_TIMER_FLAG_ACTIVATED
;
...
...
@@ -682,7 +682,7 @@ void rt_soft_timer_check(void)
/* add timer to temporary list */
rt_list_insert_after
(
&
list
,
&
(
t
->
row
[
RT_TIMER_SKIP_LIST_LEVEL
-
1
]));
soft_timer_status
=
RT_SOFT_TIMER_BUSY
;
_
soft_timer_status
=
RT_SOFT_TIMER_BUSY
;
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
...
...
@@ -695,7 +695,7 @@ void rt_soft_timer_check(void)
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
soft_timer_status
=
RT_SOFT_TIMER_IDLE
;
_
soft_timer_status
=
RT_SOFT_TIMER_IDLE
;
/* Check whether the timer object is detached or started again */
if
(
rt_list_isempty
(
&
list
))
{
...
...
@@ -723,14 +723,14 @@ void rt_soft_timer_check(void)
*
* @param parameter
*/
static
void
rt_thread_timer
_entry
(
void
*
parameter
)
static
void
_timer_thread
_entry
(
void
*
parameter
)
{
rt_tick_t
next_timeout
;
while
(
1
)
{
/* get the next timeout tick */
next_timeout
=
rt_timer_list_next_timeout
(
rt
_soft_timer_list
);
next_timeout
=
_timer_list_next_timeout
(
_soft_timer_list
);
if
(
next_timeout
==
RT_TICK_MAX
)
{
/* no software timer exist, suspend self. */
...
...
@@ -767,9 +767,9 @@ void rt_system_timer_init(void)
{
int
i
;
for
(
i
=
0
;
i
<
sizeof
(
rt_timer_list
)
/
sizeof
(
rt
_timer_list
[
0
]);
i
++
)
for
(
i
=
0
;
i
<
sizeof
(
_timer_list
)
/
sizeof
(
_timer_list
[
0
]);
i
++
)
{
rt_list_init
(
rt
_timer_list
+
i
);
rt_list_init
(
_timer_list
+
i
);
}
}
...
...
@@ -784,24 +784,24 @@ void rt_system_timer_thread_init(void)
int
i
;
for
(
i
=
0
;
i
<
sizeof
(
rt_soft_timer_list
)
/
sizeof
(
rt
_soft_timer_list
[
0
]);
i
<
sizeof
(
_soft_timer_list
)
/
sizeof
(
_soft_timer_list
[
0
]);
i
++
)
{
rt_list_init
(
rt
_soft_timer_list
+
i
);
rt_list_init
(
_soft_timer_list
+
i
);
}
/* start software timer thread */
rt_thread_init
(
&
timer_thread
,
rt_thread_init
(
&
_
timer_thread
,
"timer"
,
rt_thread_timer
_entry
,
_timer_thread
_entry
,
RT_NULL
,
&
timer_thread_stack
[
0
],
sizeof
(
timer_thread_stack
),
&
_
timer_thread_stack
[
0
],
sizeof
(
_
timer_thread_stack
),
RT_TIMER_THREAD_PRIO
,
10
);
/* startup */
rt_thread_startup
(
&
timer_thread
);
rt_thread_startup
(
&
_
timer_thread
);
#endif
/* RT_USING_TIMER_SOFT */
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录