-
Notifications
You must be signed in to change notification settings - Fork 5.4k
testcase: add system performance testcase #10452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+942
−0
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ead4f50
add sys pref frameworks
rcitach 125d601
add context switch test code
rcitach b91c5c6
add irq latency test code
rcitach 18f37c3
add thread sem test code
rcitach 0e9f195
add thread event test code
rcitach 1719383
add thread mbox test code
rcitach cedd901
add thread mq test code
rcitach ebe4341
Adding a Test Documentation Note
rcitach a2e682b
Modification of text description
rcitach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| menu "System Performance Testcase" | ||
|
|
||
| config UTEST_SYS_PERF_TC | ||
| bool "system performance test" | ||
| default n | ||
|
|
||
| config UTEST_SYS_PERF_TC_COUNT | ||
| int "Test the number of cycles" | ||
| default 1000 | ||
| depends on UTEST_SYS_PERF_TC | ||
|
|
||
| config UTEST_HWTIMER_DEV_NAME | ||
| string "Hardware timer device name" | ||
| default "timer0" | ||
| depends on RT_USING_HWTIMER && UTEST_SYS_PERF_TC | ||
| help | ||
| Specify the hardware timer device name used for context switch testing (e.g., timer0). | ||
|
|
||
| config UTEST_SYS_IRQ_LATENCY | ||
| bool "system IRQ LATENCY test" | ||
| default n | ||
| depends on RT_USING_HWTIMER && UTEST_SYS_PERF_TC | ||
|
|
||
| endmenu | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # testcases 说明 | ||
|
|
||
| ## 一、测试用例说明 | ||
|
|
||
| | 文件 | 说明 | | ||
| |--------|--------| | ||
| | context_switch.c | 上下文切换测试代码 | | ||
| | irq_latency.c | 中断延时测试代码 | | ||
| | rt_perf_thread_event.c | 线程事件性能测试 | | ||
| | rt_perf_thread_mbox.c | 线程邮箱性能测试 | | ||
| | rt_perf_thread_mq.c | 线程消息队列性能测试 | | ||
| | rt_perf_thread_sem.c | 线程信号量性能测试 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| Import('rtconfig') | ||
| from building import * | ||
|
|
||
| cwd = GetCurrentDir() | ||
| src = Glob('*.c') | ||
| CPPPATH = [cwd] | ||
|
|
||
| group = DefineGroup('utestcases', src, depend = ['UTEST_SYS_PERF_TC'], CPPPATH = CPPPATH) | ||
|
|
||
| Return('group') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /* | ||
| * Copyright (c) 2006-2025, RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2025-07-03 rcitach test case for context_switch | ||
| */ | ||
|
|
||
| #include <rtthread.h> | ||
| #include <rthw.h> | ||
| #include <rtdevice.h> | ||
| #include <utest.h> | ||
| #include <utest_assert.h> | ||
| #include <perf_tc.h> | ||
|
|
||
| static rt_sem_t sem1, sem2; | ||
| static rt_sem_t complete_sem = RT_NULL; | ||
|
|
||
| static void local_modify_time(rt_perf_t *perf) | ||
| { | ||
| if(perf) | ||
| perf->real_time = perf->real_time - perf->tmp_time; | ||
| } | ||
|
|
||
| static void perf_thread_event1(void *parameter) | ||
| { | ||
| while (1) | ||
| { | ||
| rt_sem_take(sem1, RT_WAITING_FOREVER); | ||
| rt_sem_release(sem2); | ||
| } | ||
| } | ||
|
|
||
| static void perf_thread_event2(void *parameter) | ||
| { | ||
| rt_perf_t *perf = (rt_perf_t *)parameter; | ||
|
|
||
| for (rt_uint32_t i = 0; i < UTEST_SYS_PERF_TC_COUNT; i++) | ||
| { | ||
| perf->tmp_time = 0; | ||
| rt_perf_start(perf); | ||
| rt_sem_take(sem2, RT_WAITING_FOREVER); | ||
| rt_sem_release(sem2); | ||
| rt_perf_stop(perf); | ||
|
|
||
| rt_mutex_take(perf->lock,RT_WAITING_FOREVER); | ||
| perf->count -= 1; | ||
| perf->tmp_time = perf->real_time; | ||
| rt_mutex_release(perf->lock); | ||
|
|
||
| rt_perf_start(perf); | ||
| rt_sem_take(sem2, RT_WAITING_FOREVER); | ||
| rt_sem_release(sem1); | ||
| rt_perf_stop(perf); | ||
| } | ||
| rt_sem_release(complete_sem); | ||
| } | ||
|
|
||
| rt_err_t context_switch_test(rt_perf_t *perf) | ||
| { | ||
| rt_thread_t thread1 = RT_NULL; | ||
| rt_thread_t thread2 = RT_NULL; | ||
|
|
||
| # if __STDC_VERSION__ >= 199901L | ||
| rt_strcpy(perf->name,__func__); | ||
| #else | ||
| rt_strcpy(perf->name,"context_switch_test"); | ||
| #endif | ||
|
|
||
| perf->local_modify = local_modify_time; | ||
| sem1 = rt_sem_create("sem1", 1, RT_IPC_FLAG_FIFO); | ||
| sem2 = rt_sem_create("sem2", 0, RT_IPC_FLAG_FIFO); | ||
| complete_sem = rt_sem_create("complete_sem", 0, RT_IPC_FLAG_FIFO); | ||
|
|
||
| thread1 = rt_thread_create("perf_thread_event1", perf_thread_event1, perf, | ||
| THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); | ||
| if (thread1 == RT_NULL) | ||
| { | ||
| LOG_E("perf_thread_event1 create failed."); | ||
| return -RT_ERROR; | ||
| } | ||
|
|
||
| thread2 = rt_thread_create("perf_thread_event2", perf_thread_event2, perf, | ||
| THREAD_STACK_SIZE, THREAD_PRIORITY + 1, THREAD_TIMESLICE); | ||
| if (thread2 == RT_NULL) | ||
| { | ||
| LOG_E("perf_thread_event2 create failed."); | ||
| return -RT_ERROR; | ||
| } | ||
|
|
||
| rt_thread_startup(thread1); | ||
| rt_thread_startup(thread2); | ||
|
|
||
| rt_sem_take(complete_sem, RT_WAITING_FOREVER); | ||
|
|
||
| rt_perf_dump(perf); | ||
| rt_thread_delete(thread1); | ||
| rt_sem_delete(complete_sem); | ||
| rt_sem_delete(sem1); | ||
| rt_sem_delete(sem2); | ||
|
|
||
| return RT_EOK; | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Copyright (c) 2006-2025, RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2025-07-03 rcitach test case for irq latency | ||
| */ | ||
|
|
||
| #include <rtthread.h> | ||
| #include <rtdevice.h> | ||
| #include <utest.h> | ||
| #include <utest_assert.h> | ||
| #include <perf_tc.h> | ||
|
|
||
| static rt_device_t hw_dev = RT_NULL; | ||
| static rt_sem_t complete_sem = RT_NULL; | ||
| static rt_hwtimerval_t timeout = {0}; | ||
| static rt_perf_t *perf_local = RT_NULL; | ||
|
|
||
| static void modify_time(rt_perf_t *perf) | ||
| { | ||
| if(perf) | ||
| perf->real_time = perf->real_time - perf->tmp_time; | ||
| } | ||
|
|
||
| static rt_err_t timer_callback(rt_device_t dev, rt_size_t size) | ||
| { | ||
| rt_perf_stop(perf_local); | ||
| if (perf_local->count >= UTEST_SYS_PERF_TC_COUNT) | ||
| { | ||
| rt_sem_release(complete_sem); | ||
| return RT_EOK; | ||
| } | ||
| rt_perf_start_impl(perf_local, &timeout); | ||
| return RT_EOK; | ||
| } | ||
|
|
||
| rt_err_t rt_perf_irq_latency(rt_perf_t *perf) | ||
| { | ||
| # if __STDC_VERSION__ >= 199901L | ||
| rt_strcpy(perf->name,__func__); | ||
| #else | ||
| rt_strcpy(perf->name,"rt_perf_irq_latency"); | ||
| #endif | ||
| int ret = RT_EOK; | ||
| rt_hwtimer_mode_t mode = HWTIMER_MODE_PERIOD; | ||
|
|
||
| perf_local = perf; | ||
| hw_dev = rt_device_find(UTEST_HWTIMER_DEV_NAME); | ||
| if (hw_dev == RT_NULL) | ||
| { | ||
| ret = RT_ERROR; | ||
| LOG_E("hwtimer sample run failed! can't find %s device!", UTEST_HWTIMER_DEV_NAME); | ||
| return ret; | ||
| } | ||
|
|
||
| complete_sem = rt_sem_create("complete", 0, RT_IPC_FLAG_FIFO); | ||
| timeout.sec = 0; | ||
| timeout.usec = 50; /* No modification is necessary here, use the fixed value */ | ||
|
|
||
| rt_mutex_take(perf->lock,RT_WAITING_FOREVER); | ||
| perf_local->tmp_time = (rt_uint32_t)(timeout.sec * 1000000u + timeout.usec); | ||
| perf_local->local_modify = modify_time; | ||
| rt_mutex_release(perf->lock); | ||
|
|
||
| rt_device_set_rx_indicate(hw_dev, timer_callback); | ||
| rt_device_control(hw_dev, HWTIMER_CTRL_MODE_SET, (void *)&mode); | ||
|
|
||
| rt_perf_start_impl(perf_local, &timeout); | ||
|
|
||
| rt_sem_take(complete_sem, RT_WAITING_FOREVER); | ||
| rt_perf_dump(perf_local); | ||
| rt_sem_delete(complete_sem); | ||
| rt_device_close(hw_dev); | ||
|
|
||
| return RT_EOK; | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.