Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
混口饭吃,
rt-thread
提交
714fee00
R
rt-thread
项目概览
混口饭吃,
/
rt-thread
与 Fork 源项目一致
Fork自
Mr_Pangza / 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,发现更多精彩内容 >>
未验证
提交
714fee00
编写于
9月 09, 2021
作者:
G
guo
提交者:
GitHub
9月 09, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5032 from liukangcc/utest
[UPDATE] mailbox testcase.
上级
5a74bf33
bf94a69a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
381 addition
and
1 deletion
+381
-1
examples/utest/configs/kernel/ipc.conf
examples/utest/configs/kernel/ipc.conf
+3
-1
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/mailbox_tc.c
examples/utest/testcases/kernel/mailbox_tc.c
+371
-0
未找到文件。
examples/utest/configs/kernel/ipc.conf
浏览文件 @
714fee00
...
...
@@ -3,9 +3,11 @@ CONFIG_UTEST_EVENT_TC=y
CONFIG_UTEST_MESSAGEQUEUE_TC
=
y
CONFIG_UTEST_SIGNAL_TC
=
y
CONFIG_UTEST_MUTEX_TC
=
y
CONFIG_UTEST_MAILBOX_TC
=
y
# dependencies
CONFIG_RT_USING_SEMAPHORE
=
y
CONFIG_RT_USING_EVENT
=
y
CONFIG_RT_USING_MESSAGEQUEUE
=
y
CONFIG_RT_USING_SIGNALS
=
y
CONFIG_RT_USING_MUTEX
=
y
\ No newline at end of file
CONFIG_RT_USING_MUTEX
=
y
CONFIG_RT_USING_MAILBOX
=
y
examples/utest/testcases/kernel/Kconfig
浏览文件 @
714fee00
...
...
@@ -35,4 +35,8 @@ config UTEST_MUTEX_TC
bool "mutex test"
default n
config UTEST_MAILBOX_TC
bool "mailbox test"
default n
endmenu
examples/utest/testcases/kernel/SConscript
浏览文件 @
714fee00
...
...
@@ -29,6 +29,9 @@ if GetDepend(['UTEST_SIGNAL_TC']):
if
GetDepend
([
'UTEST_MUTEX_TC'
]):
src
+=
[
'mutex_tc.c'
]
if
GetDepend
([
'UTEST_MAILBOX_TC'
]):
src
+=
[
'mailbox_tc.c'
]
CPPPATH
=
[
cwd
]
group
=
DefineGroup
(
'utestcases'
,
src
,
depend
=
[],
CPPPATH
=
CPPPATH
)
...
...
examples/utest/testcases/kernel/mailbox_tc.c
0 → 100644
浏览文件 @
714fee00
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-09-08 liukang the first version
*/
#include <rtthread.h>
#include "utest.h"
#include <stdlib.h>
static
struct
rt_mailbox
test_static_mb
;
static
char
mb_pool
[
128
];
static
rt_mailbox_t
test_dynamic_mb
;
static
uint8_t
static_mb_recv_thread_finish
,
static_mb_send_thread_finish
;
static
uint8_t
dynamic_mb_recv_thread_finish
,
dynamic_mb_send_thread_finish
;
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
rt_thread_t
mb_send
=
RT_NULL
;
static
rt_thread_t
mb_recv
=
RT_NULL
;
static
rt_uint8_t
mb_send_str1
[]
=
"this is first mail!"
;
static
rt_uint8_t
mb_send_str2
[]
=
"this is second mail!"
;
static
rt_uint8_t
mb_send_str3
[]
=
"this is thirdy mail!"
;
static
rt_uint8_t
*
mb_recv_str1
;
static
rt_uint8_t
*
mb_recv_str2
;
static
rt_uint8_t
*
mb_recv_str3
;
static
void
test_mailbox_init
(
void
)
{
rt_err_t
result
;
result
=
rt_mb_init
(
&
test_static_mb
,
"mbt"
,
&
mb_pool
[
0
],
sizeof
(
mb_pool
)
/
4
,
RT_IPC_FLAG_FIFO
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
result
=
rt_mb_detach
(
&
test_static_mb
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
result
=
rt_mb_init
(
&
test_static_mb
,
"mbt"
,
&
mb_pool
[
0
],
sizeof
(
mb_pool
)
/
4
,
RT_IPC_FLAG_PRIO
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
result
=
rt_mb_detach
(
&
test_static_mb
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
static
void
test_mailbox_deatch
(
void
)
{
rt_err_t
result
;
result
=
rt_mb_init
(
&
test_static_mb
,
"mbt"
,
&
mb_pool
[
0
],
sizeof
(
mb_pool
)
/
4
,
RT_IPC_FLAG_FIFO
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
result
=
rt_mb_detach
(
&
test_static_mb
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
result
=
rt_mb_init
(
&
test_static_mb
,
"mbt"
,
&
mb_pool
[
0
],
sizeof
(
mb_pool
)
/
4
,
RT_IPC_FLAG_PRIO
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
result
=
rt_mb_detach
(
&
test_static_mb
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
static
void
test_mailbox_create
(
void
)
{
rt_err_t
result
;
test_dynamic_mb
=
rt_mb_create
(
"test_dynamic_mb"
,
sizeof
(
mb_pool
)
/
4
,
RT_IPC_FLAG_FIFO
);
if
(
test_dynamic_mb
==
RT_NULL
)
{
uassert_false
(
1
);
}
result
=
rt_mb_delete
(
test_dynamic_mb
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
test_dynamic_mb
=
rt_mb_create
(
"test_dynamic_mb"
,
sizeof
(
mb_pool
)
/
4
,
RT_IPC_FLAG_PRIO
);
if
(
test_dynamic_mb
==
RT_NULL
)
{
uassert_false
(
1
);
}
result
=
rt_mb_delete
(
test_dynamic_mb
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
static
void
test_mailbox_delete
(
void
)
{
rt_err_t
result
;
test_dynamic_mb
=
rt_mb_create
(
"test_dynamic_mb"
,
sizeof
(
mb_pool
)
/
4
,
RT_IPC_FLAG_FIFO
);
if
(
test_dynamic_mb
==
RT_NULL
)
{
uassert_false
(
1
);
}
result
=
rt_mb_delete
(
test_dynamic_mb
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
test_dynamic_mb
=
rt_mb_create
(
"test_dynamic_mb"
,
sizeof
(
mb_pool
)
/
4
,
RT_IPC_FLAG_PRIO
);
if
(
test_dynamic_mb
==
RT_NULL
)
{
uassert_false
(
1
);
}
result
=
rt_mb_delete
(
test_dynamic_mb
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
static
void
thread2_send_static_mb
(
void
*
arg
)
{
rt_err_t
res
=
RT_EOK
;
res
=
rt_mb_send
(
&
test_static_mb
,
(
rt_ubase_t
)
&
mb_send_str1
);
if
(
res
!=
RT_EOK
)
{
uassert_false
(
1
);
}
rt_thread_mdelay
(
100
);
res
=
rt_mb_send_wait
(
&
test_static_mb
,
(
rt_ubase_t
)
&
mb_send_str2
,
10
);
if
(
res
!=
RT_EOK
)
{
uassert_false
(
1
);
}
rt_thread_mdelay
(
100
);
res
=
rt_mb_urgent
(
&
test_static_mb
,
(
rt_ubase_t
)
&
mb_send_str3
);
if
(
res
!=
RT_EOK
)
{
uassert_false
(
1
);
}
static_mb_send_thread_finish
=
1
;
}
static
void
thread1_recv_static_mb
(
void
*
arg
)
{
rt_err_t
result
=
RT_EOK
;
result
=
rt_mb_recv
(
&
test_static_mb
,
(
rt_ubase_t
*
)
&
mb_recv_str1
,
RT_WAITING_FOREVER
);
if
(
result
!=
RT_EOK
||
strcmp
(
mb_recv_str1
,
mb_send_str1
)
!=
0
)
{
uassert_false
(
1
);
}
result
=
rt_mb_recv
(
&
test_static_mb
,
(
rt_ubase_t
*
)
&
mb_recv_str2
,
RT_WAITING_FOREVER
);
if
(
result
!=
RT_EOK
||
strcmp
(
mb_recv_str2
,
mb_send_str2
)
!=
0
)
{
uassert_false
(
1
);
}
result
=
rt_mb_recv
(
&
test_static_mb
,
(
rt_ubase_t
*
)
&
mb_recv_str3
,
RT_WAITING_FOREVER
);
if
(
result
!=
RT_EOK
||
strcmp
(
mb_recv_str3
,
mb_send_str3
)
!=
0
)
{
uassert_false
(
1
);
}
static_mb_recv_thread_finish
=
1
;
}
static
void
test_static_mailbox_send_recv
(
void
)
{
rt_err_t
result
;
result
=
rt_mb_init
(
&
test_static_mb
,
"mbt"
,
&
mb_pool
[
0
],
sizeof
(
mb_pool
)
/
4
,
RT_IPC_FLAG_FIFO
);
if
(
result
!=
RT_EOK
)
{
uassert_false
(
1
);
}
rt_thread_init
(
&
thread1
,
"thread1"
,
thread1_recv_static_mb
,
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_mb
,
RT_NULL
,
&
thread2_stack
[
0
],
sizeof
(
thread2_stack
),
THREAD_PRIORITY
,
THREAD_TIMESLICE
);
rt_thread_startup
(
&
thread2
);
while
(
static_mb_recv_thread_finish
!=
1
||
static_mb_send_thread_finish
!=
1
)
{
rt_thread_delay
(
1
);
}
if
(
rt_mb_detach
(
&
test_static_mb
)
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
static
void
thread4_send_dynamic_mb
(
void
*
arg
)
{
rt_err_t
res
=
RT_EOK
;
res
=
rt_mb_send
(
test_dynamic_mb
,
(
rt_ubase_t
)
&
mb_send_str1
);
if
(
res
!=
RT_EOK
)
{
uassert_false
(
1
);
}
rt_thread_mdelay
(
100
);
res
=
rt_mb_send_wait
(
test_dynamic_mb
,
(
rt_ubase_t
)
&
mb_send_str2
,
10
);
if
(
res
!=
RT_EOK
)
{
uassert_false
(
1
);
}
rt_thread_mdelay
(
100
);
res
=
rt_mb_urgent
(
test_dynamic_mb
,
(
rt_ubase_t
)
&
mb_send_str3
);
if
(
res
!=
RT_EOK
)
{
uassert_false
(
1
);
}
dynamic_mb_send_thread_finish
=
1
;
}
static
void
thread3_recv_dynamic_mb
(
void
*
arg
)
{
rt_err_t
result
=
RT_EOK
;
result
=
rt_mb_recv
(
test_dynamic_mb
,
(
rt_ubase_t
*
)
&
mb_recv_str1
,
RT_WAITING_FOREVER
);
if
(
result
!=
RT_EOK
||
strcmp
(
mb_recv_str1
,
mb_send_str1
)
!=
0
)
{
uassert_false
(
1
);
}
result
=
rt_mb_recv
(
test_dynamic_mb
,
(
rt_ubase_t
*
)
&
mb_recv_str2
,
RT_WAITING_FOREVER
);
if
(
result
!=
RT_EOK
||
strcmp
(
mb_recv_str2
,
mb_send_str2
)
!=
0
)
{
uassert_false
(
1
);
}
result
=
rt_mb_recv
(
test_dynamic_mb
,
(
rt_ubase_t
*
)
&
mb_recv_str3
,
RT_WAITING_FOREVER
);
if
(
result
!=
RT_EOK
||
strcmp
(
mb_recv_str3
,
mb_send_str3
)
!=
0
)
{
uassert_false
(
1
);
}
dynamic_mb_recv_thread_finish
=
1
;
}
static
void
test_dynamic_mailbox_send_recv
(
void
)
{
test_dynamic_mb
=
rt_mb_create
(
"mbt"
,
sizeof
(
mb_pool
)
/
4
,
RT_IPC_FLAG_FIFO
);
if
(
test_dynamic_mb
==
RT_NULL
)
{
uassert_false
(
1
);
}
mb_recv
=
rt_thread_create
(
"mb_recv_thread"
,
thread3_recv_dynamic_mb
,
RT_NULL
,
1024
,
THREAD_PRIORITY
-
1
,
THREAD_TIMESLICE
);
if
(
mb_recv
==
RT_NULL
)
{
uassert_false
(
1
);
}
rt_thread_startup
(
mb_recv
);
mb_send
=
rt_thread_create
(
"mb_send_thread"
,
thread4_send_dynamic_mb
,
RT_NULL
,
1024
,
THREAD_PRIORITY
-
1
,
THREAD_TIMESLICE
);
if
(
mb_send
==
RT_NULL
)
{
uassert_false
(
1
);
}
rt_thread_startup
(
mb_send
);
while
(
dynamic_mb_recv_thread_finish
!=
1
||
dynamic_mb_send_thread_finish
!=
1
)
{
rt_thread_delay
(
1
);
}
if
(
rt_mb_delete
(
test_dynamic_mb
)
!=
RT_EOK
)
{
uassert_false
(
1
);
}
uassert_true
(
1
);
}
static
rt_err_t
utest_tc_init
(
void
)
{
return
RT_EOK
;
}
static
rt_err_t
utest_tc_cleanup
(
void
)
{
return
RT_EOK
;
}
static
void
testcase
(
void
)
{
UTEST_UNIT_RUN
(
test_mailbox_init
);
UTEST_UNIT_RUN
(
test_mailbox_deatch
);
UTEST_UNIT_RUN
(
test_mailbox_create
);
UTEST_UNIT_RUN
(
test_mailbox_delete
);
UTEST_UNIT_RUN
(
test_static_mailbox_send_recv
);
UTEST_UNIT_RUN
(
test_dynamic_mailbox_send_recv
);
}
UTEST_TC_EXPORT
(
testcase
,
"src.ipc.mailbox_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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录