Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wwsmg1
rt-thread
提交
1656d7f8
R
rt-thread
项目概览
wwsmg1
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
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,发现更多精彩内容 >>
未验证
提交
1656d7f8
编写于
8月 19, 2021
作者:
G
guo
提交者:
GitHub
8月 19, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4944 from liukangcc/master
【add】event testcase
上级
a98860d1
f8c12d0f
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
354 addition
and
1 deletion
+354
-1
examples/utest/configs/kernel/ipc.conf
examples/utest/configs/kernel/ipc.conf
+2
-1
examples/utest/testcases/kernel/Kconfig
examples/utest/testcases/kernel/Kconfig
+5
-0
examples/utest/testcases/kernel/SConscript
examples/utest/testcases/kernel/SConscript
+3
-0
examples/utest/testcases/kernel/event_tc.c
examples/utest/testcases/kernel/event_tc.c
+344
-0
未找到文件。
examples/utest/configs/kernel/ipc.conf
浏览文件 @
1656d7f8
CONFIG_UTEST_SEMAPHORE_TC
=
y
CONFIG_UTEST_SEMAPHORE_TC
=
y
CONFIG_UTEST_EVENT_TC
=
y
# dependencies
# dependencies
CONFIG_RT_USING_SEMAPHORE
=
y
CONFIG_RT_USING_SEMAPHORE
=
y
CONFIG_RT_USING_EVENT
=
y
examples/utest/testcases/kernel/Kconfig
浏览文件 @
1656d7f8
...
@@ -10,4 +10,9 @@ config UTEST_SEMAPHORE_TC
...
@@ -10,4 +10,9 @@ config UTEST_SEMAPHORE_TC
default n
default n
depends on RT_USING_SEMAPHORE
depends on RT_USING_SEMAPHORE
config UTEST_EVENT_TC
bool "event test"
default n
depends on RT_USING_EVENT
endmenu
endmenu
examples/utest/testcases/kernel/SConscript
浏览文件 @
1656d7f8
...
@@ -11,6 +11,9 @@ if GetDepend(['UTEST_MEMHEAP_TC']):
...
@@ -11,6 +11,9 @@ if GetDepend(['UTEST_MEMHEAP_TC']):
if
GetDepend
([
'UTEST_SEMAPHORE_TC'
]):
if
GetDepend
([
'UTEST_SEMAPHORE_TC'
]):
src
+=
[
'semaphore_tc.c'
]
src
+=
[
'semaphore_tc.c'
]
if
GetDepend
([
'UTEST_EVENT_TC'
]):
src
+=
[
'event_tc.c'
]
CPPPATH
=
[
cwd
]
CPPPATH
=
[
cwd
]
group
=
DefineGroup
(
'utestcases'
,
src
,
depend
=
[],
CPPPATH
=
CPPPATH
)
group
=
DefineGroup
(
'utestcases'
,
src
,
depend
=
[],
CPPPATH
=
CPPPATH
)
...
...
examples/utest/testcases/kernel/event_tc.c
0 → 100644
浏览文件 @
1656d7f8
/*
* Copyright (c) 2006-2019, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-15 liukang the first version
*/
#include <rtthread.h>
#include "utest.h"
#include <stdlib.h>
#define EVENT_FLAG3 (1 << 3)
#define EVENT_FLAG5 (1 << 5)
static
struct
rt_event
static_event
=
{
0
};
#ifdef RT_USING_HEAP
static
rt_event_t
dynamic_event
=
RT_NULL
;
static
rt_uint32_t
dynamic_event_recv_thread_finish
=
0
,
dynamic_event_send_thread_finish
=
0
;
ALIGN
(
RT_ALIGN_SIZE
)
static
char
thread3_stack
[
1024
];
static
struct
rt_thread
thread3
;
ALIGN
(
RT_ALIGN_SIZE
)
static
char
thread4_stack
[
1024
];
static
struct
rt_thread
thread4
;
#endif
/* RT_USING_HEAP */
static
rt_uint32_t
recv_event_times1
=
0
,
recv_event_times2
=
0
;
static
rt_uint32_t
static_event_recv_thread_finish
=
0
,
static_event_send_thread_finish
=
0
;
ALIGN
(
RT_ALIGN_SIZE
)
static
char
thread1_stack
[
1024
];
static
struct
rt_thread
thread1
;
ALIGN
(
RT_ALIGN_SIZE
)
static
char
thread2_stack
[
1024
];
static
struct
rt_thread
thread2
;
#define THREAD_PRIORITY 9
#define THREAD_TIMESLICE 5
static
void
test_event_init
(
void
)
{
rt_err_t
result
;
result
=
rt_event_init
(
&
static_event
,
"event"
,
RT_IPC_FLAG_PRIO
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
result
=
rt_event_detach
(
&
static_event
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
result
=
rt_event_init
(
&
static_event
,
"event"
,
RT_IPC_FLAG_FIFO
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
result
=
rt_event_detach
(
&
static_event
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
static
void
test_event_detach
(
void
)
{
rt_err_t
result
=
RT_EOK
;
result
=
rt_event_init
(
&
static_event
,
"event"
,
RT_IPC_FLAG_PRIO
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
result
=
rt_event_detach
(
&
static_event
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
static
void
thread1_recv_static_event
(
void
*
param
)
{
rt_uint32_t
e
;
if
(
rt_event_recv
(
&
static_event
,
(
EVENT_FLAG3
|
EVENT_FLAG5
),
RT_EVENT_FLAG_OR
|
RT_EVENT_FLAG_CLEAR
,
RT_WAITING_FOREVER
,
&
e
)
!=
RT_EOK
)
{
return
;
}
recv_event_times1
=
e
;
rt_thread_mdelay
(
50
);
if
(
rt_event_recv
(
&
static_event
,
(
EVENT_FLAG3
|
EVENT_FLAG5
),
RT_EVENT_FLAG_AND
|
RT_EVENT_FLAG_CLEAR
,
RT_WAITING_FOREVER
,
&
e
)
!=
RT_EOK
)
{
return
;
}
recv_event_times2
=
e
;
static_event_recv_thread_finish
=
1
;
}
static
void
thread2_send_static_event
(
void
*
param
)
{
rt_event_send
(
&
static_event
,
EVENT_FLAG3
);
rt_thread_mdelay
(
10
);
rt_event_send
(
&
static_event
,
EVENT_FLAG5
);
rt_thread_mdelay
(
10
);
rt_event_send
(
&
static_event
,
EVENT_FLAG3
);
static_event_send_thread_finish
=
1
;
}
static
void
test_static_event_send_recv
(
void
)
{
rt_err_t
result
=
RT_EOK
;
result
=
rt_event_init
(
&
static_event
,
"event"
,
RT_IPC_FLAG_PRIO
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
rt_thread_init
(
&
thread1
,
"thread1"
,
thread1_recv_static_event
,
RT_NULL
,
&
thread1_stack
[
0
],
sizeof
(
thread1_stack
),
THREAD_PRIORITY
-
1
,
THREAD_TIMESLICE
);
rt_thread_startup
(
&
thread1
);
rt_thread_init
(
&
thread2
,
"thread2"
,
thread2_send_static_event
,
RT_NULL
,
&
thread2_stack
[
0
],
sizeof
(
thread2_stack
),
THREAD_PRIORITY
,
THREAD_TIMESLICE
);
rt_thread_startup
(
&
thread2
);
while
(
static_event_recv_thread_finish
!=
1
||
static_event_send_thread_finish
!=
1
)
{
rt_thread_delay
(
1
);
}
if
(
recv_event_times1
==
EVENT_FLAG3
&&
recv_event_times2
==
(
EVENT_FLAG3
|
EVENT_FLAG5
))
{
if
(
rt_event_detach
(
&
static_event
)
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
else
{
if
(
rt_event_detach
(
&
static_event
)
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_false
(
1
);
}
return
;
}
#ifdef RT_USING_HEAP
static
void
test_event_create
(
void
)
{
rt_err_t
result
=
RT_EOK
;
dynamic_event
=
rt_event_create
(
"dynamic_event"
,
RT_IPC_FLAG_FIFO
);
if
(
dynamic_event
==
RT_NULL
)
{
uassert_false
(
1
);
}
result
=
rt_event_delete
(
dynamic_event
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
static
void
test_event_delete
(
void
)
{
rt_err_t
result
;
dynamic_event
=
rt_event_create
(
"dynamic_event"
,
RT_IPC_FLAG_FIFO
);
if
(
dynamic_event
==
RT_NULL
)
{
uassert_false
(
1
);
}
result
=
rt_event_delete
(
dynamic_event
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
static
void
thread3_recv_dynamic_event
(
void
*
param
)
{
rt_uint32_t
e
;
if
(
rt_event_recv
(
dynamic_event
,
(
EVENT_FLAG3
|
EVENT_FLAG5
),
RT_EVENT_FLAG_OR
|
RT_EVENT_FLAG_CLEAR
,
RT_WAITING_FOREVER
,
&
e
)
!=
RT_EOK
)
{
return
;
}
recv_event_times1
=
e
;
rt_thread_mdelay
(
50
);
if
(
rt_event_recv
(
dynamic_event
,
(
EVENT_FLAG3
|
EVENT_FLAG5
),
RT_EVENT_FLAG_AND
|
RT_EVENT_FLAG_CLEAR
,
RT_WAITING_FOREVER
,
&
e
)
!=
RT_EOK
)
{
return
;
}
recv_event_times2
=
e
;
dynamic_event_recv_thread_finish
=
1
;
}
static
void
thread4_send_dynamic_event
(
void
*
param
)
{
rt_event_send
(
dynamic_event
,
EVENT_FLAG3
);
rt_thread_mdelay
(
10
);
rt_event_send
(
dynamic_event
,
EVENT_FLAG5
);
rt_thread_mdelay
(
10
);
rt_event_send
(
dynamic_event
,
EVENT_FLAG3
);
dynamic_event_send_thread_finish
=
1
;
}
static
void
test_dynamic_event_send_recv
(
void
)
{
dynamic_event
=
rt_event_create
(
"dynamic_event"
,
RT_IPC_FLAG_PRIO
);
if
(
dynamic_event
==
RT_NULL
)
{
uassert_false
(
1
);
}
rt_thread_init
(
&
thread3
,
"thread3"
,
thread3_recv_dynamic_event
,
RT_NULL
,
&
thread3_stack
[
0
],
sizeof
(
thread3_stack
),
THREAD_PRIORITY
-
1
,
THREAD_TIMESLICE
);
rt_thread_startup
(
&
thread3
);
rt_thread_init
(
&
thread4
,
"thread4"
,
thread4_send_dynamic_event
,
RT_NULL
,
&
thread4_stack
[
0
],
sizeof
(
thread4_stack
),
THREAD_PRIORITY
,
THREAD_TIMESLICE
);
rt_thread_startup
(
&
thread4
);
while
(
dynamic_event_recv_thread_finish
!=
1
||
dynamic_event_send_thread_finish
!=
1
)
{
rt_thread_delay
(
1
);
}
if
(
recv_event_times1
==
EVENT_FLAG3
&&
recv_event_times2
==
(
EVENT_FLAG3
|
EVENT_FLAG5
))
{
if
(
rt_event_delete
(
dynamic_event
)
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
else
{
if
(
rt_event_delete
(
dynamic_event
)
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_false
(
1
);
}
return
;
}
#endif
static
rt_err_t
utest_tc_init
(
void
)
{
static_event_recv_thread_finish
=
0
;
static_event_send_thread_finish
=
0
;
#ifdef RT_USING_HEAP
dynamic_event_recv_thread_finish
=
0
;
dynamic_event_send_thread_finish
=
0
;
#endif
return
RT_EOK
;
}
static
rt_err_t
utest_tc_cleanup
(
void
)
{
return
RT_EOK
;
}
static
void
testcase
(
void
)
{
UTEST_UNIT_RUN
(
test_event_init
);
UTEST_UNIT_RUN
(
test_event_detach
);
UTEST_UNIT_RUN
(
test_static_event_send_recv
);
#ifdef RT_USING_HEAP
UTEST_UNIT_RUN
(
test_event_create
);
UTEST_UNIT_RUN
(
test_event_delete
);
UTEST_UNIT_RUN
(
test_dynamic_event_send_recv
);
#endif
}
UTEST_TC_EXPORT
(
testcase
,
"src.ipc.event_tc"
,
utest_tc_init
,
utest_tc_cleanup
,
60
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录