Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wwsmg1
rt-thread
提交
f6ac38a1
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,发现更多精彩内容 >>
提交
f6ac38a1
编写于
8月 09, 2022
作者:
G
guozhanxin
提交者:
mysterywolf
8月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[utestcases] add timeslice_test
上级
7750358b
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
100 addition
and
0 deletion
+100
-0
examples/utest/testcases/kernel/thread_tc.c
examples/utest/testcases/kernel/thread_tc.c
+100
-0
未找到文件。
examples/utest/testcases/kernel/thread_tc.c
浏览文件 @
f6ac38a1
...
...
@@ -455,6 +455,104 @@ static void test_delay_until(void)
uassert_int_equal
(
delta
,
10
);
}
static
rt_thread_t
tidA
,
tidB1
,
tidB2
;
static
uint32_t
timeslice_cntA
,
timeslice_cntB1
,
timeslice_cntB2
;
static
void
test_timeslice_threadA_entry
(
void
*
parameter
)
{
while
(
1
)
{
rt_thread_delay
(
2
);
timeslice_cntA
++
;
if
(
timeslice_cntA
>
10
)
return
;
}
}
static
void
test_timeslice_threadB1_entry
(
void
*
parameter
)
{
while
(
1
)
{
timeslice_cntB1
++
;
if
(
timeslice_cntA
>
10
)
return
;
}
}
static
void
test_timeslice_threadB2_entry
(
void
*
parameter
)
{
while
(
1
)
{
timeslice_cntB2
++
;
if
(
timeslice_cntA
>
10
)
return
;
}
}
void
test_timeslice
(
void
)
{
rt_err_t
ret_startup
=
-
RT_ERROR
;
uint32_t
diff
;
timeslice_cntA
=
0
;
timeslice_cntB1
=
0
;
timeslice_cntB2
=
0
;
tidA
=
rt_thread_create
(
"timeslice"
,
test_timeslice_threadA_entry
,
RT_NULL
,
2048
,
__current_thread
->
current_priority
+
1
,
10
);
if
(
!
tidA
)
{
LOG_E
(
"rt_thread_create failed!"
);
return
;
}
rt_thread_control
(
tidA
,
RT_THREAD_CTRL_BIND_CPU
,
(
void
*
)
1
);
ret_startup
=
rt_thread_startup
(
tidA
);
if
(
ret_startup
!=
RT_EOK
)
{
LOG_E
(
"rt_thread_startup failed!"
);
uassert_false
(
1
);
return
;
}
tidB1
=
rt_thread_create
(
"timeslice"
,
test_timeslice_threadB1_entry
,
RT_NULL
,
2048
,
__current_thread
->
current_priority
+
2
,
2
);
if
(
!
tidB1
)
{
LOG_E
(
"rt_thread_create failed!"
);
return
;
}
rt_thread_control
(
tidB1
,
RT_THREAD_CTRL_BIND_CPU
,
(
void
*
)
1
);
ret_startup
=
rt_thread_startup
(
tidB1
);
if
(
ret_startup
!=
RT_EOK
)
{
LOG_E
(
"rt_thread_startup failed!"
);
uassert_false
(
1
);
return
;
}
tidB2
=
rt_thread_create
(
"timeslice"
,
test_timeslice_threadB2_entry
,
RT_NULL
,
2048
,
__current_thread
->
current_priority
+
2
,
2
);
if
(
!
tidB2
)
{
LOG_E
(
"rt_thread_create failed!"
);
return
;
}
rt_thread_control
(
tidB2
,
RT_THREAD_CTRL_BIND_CPU
,
(
void
*
)
1
);
ret_startup
=
rt_thread_startup
(
tidB2
);
if
(
ret_startup
!=
RT_EOK
)
{
LOG_E
(
"rt_thread_startup failed!"
);
uassert_false
(
1
);
return
;
}
do
{
rt_thread_delay
(
2
*
20
);
}
while
(
timeslice_cntA
<=
10
);
rt_kprintf
(
"A:%d,B1:%d,B2:%d
\n
"
,
timeslice_cntA
,
timeslice_cntB1
,
timeslice_cntB2
);
diff
=
abs
(
timeslice_cntB1
-
timeslice_cntB2
);
uassert_true
(
diff
*
100
/
timeslice_cntB1
<
30
);
uassert_true
(
timeslice_cntA
==
11
);
}
#ifndef RT_USING_SMP
static
volatile
rt_uint32_t
yield_count
;
...
...
@@ -634,6 +732,8 @@ static void testcase(void)
UTEST_UNIT_RUN
(
test_thread_priority
);
/* delay_until */
UTEST_UNIT_RUN
(
test_delay_until
);
/* timeslice */
UTEST_UNIT_RUN
(
test_timeslice
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录