Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/utest/smp/smp_thread_preemption_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,37 @@
* @note Create multiple threads, low-priority threads run first,
* high-priority threads preempt low-priority threads, and
* print the current status of each core in the thread's entry function.
*
* Test Case Name: [smp_thread_preemptions]
*
* Test Objectives:
* - Test the thread preemption logic under the SMP architecture
*
* Test Scenarios:
* - A high-priority thread thigh and a low-priority thread tlow are created. Since tlow is created
* - prior to thigh, it prints the thread list information first and then waits for the finish_flag
* - bit. Once thigh becomes ready, it preempts tlow, prints the thread list, and then sets the
* - finish_flag bit. After that, tlow exits the busy-wait loop.
*
* Verification Metrics:
* - First, the message "Low priority thread is running" will be displayed, followed immediately by
* - a thread_list information list. Subsequently, the message "High priority thread is running" will
* - appear, and in the thread_list that follows, the tlow thread can be observed in the ready state.
*
* Dependencies:
* - Enable RT_USING_SMP, set RT_THREAD_PRIORITY_MAX = 256.
*
* Expected Results:
* - You will see the message "[ PASSED ] [ result ] testcase (core.smp_thread_preemptions)", and observe
* - the tlow thread in the ready state in the thread_list printed by the thigh thread.
Comment on lines +27 to +42
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] 🟡 Documentation Issue: Comment Formatting / 文档问题:注释格式

English: The multi-line comments starting with "- " on lines 27-30 and 33-35 are inconsistent with the rest of the documentation block. Standard documentation style would not have the leading "- " on continuation lines, or should consistently use bullet points throughout.

中文:第27-30行和第33-35行以 "- " 开头的多行注释与文档块的其余部分不一致。标准文档风格不应在续行上有前导 "- ",或应始终使用项目符号。

Suggested Format / 建议格式:

 * Test Scenarios:
 * A high-priority thread thigh and a low-priority thread tlow are created. Since tlow is created
 * prior to thigh, it prints the thread list information first and then waits for the finish_flag
 * bit. Once thigh becomes ready, it preempts tlow, prints the thread list, and then sets the
 * finish_flag bit. After that, tlow exits the busy-wait loop.
Suggested change
* - A high-priority thread thigh and a low-priority thread tlow are created. Since tlow is created
* - prior to thigh, it prints the thread list information first and then waits for the finish_flag
* - bit. Once thigh becomes ready, it preempts tlow, prints the thread list, and then sets the
* - finish_flag bit. After that, tlow exits the busy-wait loop.
*
* Verification Metrics:
* - First, the message "Low priority thread is running" will be displayed, followed immediately by
* - a thread_list information list. Subsequently, the message "High priority thread is running" will
* - appear, and in the thread_list that follows, the tlow thread can be observed in the ready state.
*
* Dependencies:
* - Enable RT_USING_SMP, set RT_THREAD_PRIORITY_MAX = 256.
*
* Expected Results:
* - You will see the message "[ PASSED ] [ result ] testcase (core.smp_thread_preemptions)", and observe
* - the tlow thread in the ready state in the thread_list printed by the thigh thread.
* A high-priority thread thigh and a low-priority thread tlow are created. Since tlow is created
* prior to thigh, it prints the thread list information first and then waits for the finish_flag
* bit. Once thigh becomes ready, it preempts tlow, prints the thread list, and then sets the
* finish_flag bit. After that, tlow exits the busy-wait loop.
*
* Verification Metrics:
* First, the message "Low priority thread is running" will be displayed, followed immediately by
* a thread_list information list. Subsequently, the message "High priority thread is running" will
* appear, and in the thread_list that follows, the tlow thread can be observed in the ready state.
*
* Dependencies:
* Enable RT_USING_SMP, set RT_THREAD_PRIORITY_MAX = 256.
*
* Expected Results:
* You will see the message "[ PASSED ] [ result ] testcase (core.smp_thread_preemptions)", and observe
* the tlow thread in the ready state in the thread_list printed by the thigh thread.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#10895 的例子中是用的这种格式

*/
Comment on lines +20 to 43
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 PR Title Format / PR 标题格式

English: The PR title should follow RT-Thread format: [module][subsystem] Description in lowercase.

Current title: "Modify the logic of utest-smp_thread_preemptions and add comments"

Based on the modified file src/utest/smp/smp_thread_preemption_tc.c, the suggested title format should be:

Suggested title: [utest][smp] Add synchronization flag to thread preemption test

or

[utest][smp] Improve thread preemption test with finish_flag and documentation

中文:PR 标题应遵循 RT-Thread 格式:小写的 [模块][子系统] 描述

当前标题:"Modify the logic of utest-smp_thread_preemptions and add comments"

基于修改的文件 src/utest/smp/smp_thread_preemption_tc.c,建议的标题格式应为:

建议标题[utest][smp] Add synchronization flag to thread preemption test

[utest][smp] Improve thread preemption test with finish_flag and documentation

Copilot generated this review using guidance from repository custom instructions.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改


#define THREAD_PRIORITY_HIGH 21
#define THREAD_PRIORITY_LOW 30
#define THREAD_STACK_SIZE UTEST_THR_STACK_SIZE

static rt_thread_t threads[2];
static volatile rt_uint8_t finish_flag = 0;
static struct rt_spinlock lock;

/* High Priority Thread */
Expand All @@ -35,6 +59,7 @@ static void thread_high_entry(void *parameter)
extern long list_thread(void);
list_thread();
rt_spin_unlock(&lock);
finish_flag = 1;
}

/* Low Priority Thread */
Expand All @@ -46,6 +71,7 @@ static void thread_low_entry(void *parameter)
extern long list_thread(void);
list_thread();
rt_spin_unlock(&lock);
while (!finish_flag);
}

static void thread_preemptions_tc(void)
Expand All @@ -72,6 +98,7 @@ static void thread_preemptions_tc(void)
static rt_err_t utest_tc_init(void)
{
rt_spin_lock_init(&lock);
finish_flag = 0;
return RT_EOK;
}

Expand Down