Skip to content

Commit 070e295

Browse files
committed
Merge branch 'master' of https://github.com/Kurngsy/rt-thread
2 parents 3f2c97d + 573c548 commit 070e295

File tree

4 files changed

+117
-18
lines changed

4 files changed

+117
-18
lines changed

src/object.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,9 @@ void rt_object_init(struct rt_object *object,
399399
if(obj_name_len > RT_NAME_MAX - 1)
400400
{
401401
LOG_E("Object name %s exceeds RT_NAME_MAX=%d, consider increasing RT_NAME_MAX.", name, RT_NAME_MAX);
402-
RT_ASSERT(obj_name_len <= RT_NAME_MAX - 1);
403402
}
404-
rt_memcpy(object->name, name, obj_name_len);
405-
object->name[obj_name_len] = '\0';
403+
rt_strncpy(object->name, name, RT_NAME_MAX - 1);
404+
object->name[RT_NAME_MAX - 1] = '\0';
406405
}
407406
else
408407
{
@@ -515,10 +514,9 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
515514
if(obj_name_len > RT_NAME_MAX - 1)
516515
{
517516
LOG_E("Object name %s exceeds RT_NAME_MAX=%d, consider increasing RT_NAME_MAX.", name, RT_NAME_MAX);
518-
RT_ASSERT(obj_name_len <= RT_NAME_MAX - 1);
519517
}
520-
rt_memcpy(object->name, name, obj_name_len);
521-
object->name[obj_name_len] = '\0';
518+
rt_strncpy(object->name, name, RT_NAME_MAX - 1);
519+
object->name[RT_NAME_MAX - 1] = '\0';
522520
}
523521
else
524522
{

src/utest/messagequeue_tc.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,44 @@
88
* 2021-08-28 Sherman the first version
99
* 2023-09-15 xqyjlj change stack size in cpu64
1010
* fix in smp
11+
* 2025-11-17 Ze-Hou add standardized utest documentation block
12+
*/
13+
14+
/**
15+
* Test Case Name: Kernel Core Message Queue Test
16+
*
17+
* Test Objectives:
18+
* - Validate the RT-Thread kernel message queue (rt_messagequeue) functionality
19+
* - Test static and dynamic message queue creation, initialization, sending,
20+
* receiving, urgent send, priority send, reset, detach, and delete APIs
21+
*
22+
* Test Scenarios:
23+
* - Initialize a static message queue and verify correct setup
24+
* - Create a dynamic message queue and verify allocation
25+
* - Send messages to the queue until full, test blocking and non-blocking send,
26+
* urgent send, and priority send (if enabled)
27+
* - Receive messages from the queue, verify order and data integrity, including
28+
* priority receive (if enabled)
29+
* - Reset the message queue and verify it is empty
30+
* - Detach and delete message queues, ensuring resources are released
31+
* - Use multiple threads to simulate concurrent send/receive operations
32+
*
33+
* Verification Metrics:
34+
* - All uassert assertions pass without failure
35+
* - Message queues are created, initialized, detached, and deleted successfully
36+
* - Messages are sent and received in correct order and with correct data
37+
* - Blocking and non-blocking operations behave as expected
38+
* - Urgent and priority send/receive functions work correctly (if enabled)
39+
*
40+
* Dependencies:
41+
* - Enable message queue priority (RT-Thread Kernel -> Inter-Thread communication
42+
* -> Enable message queue priority)
43+
* - Enable Message Queue Test (RT-Thread Utestcases -> Kernel Core -> Message Queue Test)
44+
* - Test on any RT-Thread supported platform (e.g., qemu-virt64-riscv)
45+
*
46+
* Expected Results:
47+
* - After executing this test in msh, the expected output should be:
48+
* "[ PASSED ] [ result ] testcase (core.messagequeue)"
1149
*/
1250

1351
#include <rtthread.h>

src/utest/smp/smp_assigned_idle_cores_tc.c

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,52 @@
1717
* @note Create multiple threads untied core threads, run them for a while on each core to see
1818
* if the threads are automatically distributed evenly, run for a while to output the threads
1919
* running on each core.
20+
*
21+
* Test Case Name: [smp_assigned_idle_cores]
22+
*
23+
* Test Objectives:
24+
* - Test whether ready threads unbound to cores can be automatically allocated
25+
* - to idle cores under the SMP architecture.
26+
*
27+
* Test Scenarios:
28+
* - Under the SMP architecture, each core spends most of its time running the
29+
* - idle thread after the system starts. At this point, create RT_CPUS_NR-1 cyclic
30+
* - tasks and observe whether these tasks can be evenly distributed across all
31+
* - cores for execution. Since the thread running the utest occupies one core, it
32+
* - is only necessary to observe whether the remaining (RT_CPUS_NR - 1) cores can
33+
* - be allocated the newly created threads and execute them.
34+
*
35+
* Verification Metrics:
36+
* - After running this test case, it is necessary to observe the printed thread
37+
* - list, where all threads created with names from T0 to T(RT_CPUS_NR-2) must
38+
* - be in the running state. RT_CPUS_NR must be greater than or equal to 2.
39+
*
40+
* Dependencies:
41+
* - RT_USING_SMP needs to be enabled.
42+
*
43+
* Expected Results:
44+
* - Print the thread list on the terminal, and observe that T0 to T(RT_CPUS_NR-2)
45+
* - are all in the running state, with the output "[ PASSED ] [ result ] testcase
46+
* - (core.smp_assigned_idle_cores)".
2047
*/
2148

2249
#define THREAD_STACK_SIZE UTEST_THR_STACK_SIZE
2350
#define THREAD_PRIORITY 20
24-
static rt_thread_t threads[RT_CPUS_NR];
25-
static int tick = 0, finsh_flag = 0;
51+
static rt_thread_t threads[RT_CPUS_NR - 1];
52+
static int tick = 0, finish_flag = 0;
2653
static int num = 0;
2754
/* thread entry function */
2855
static void thread_entry(void *parameter)
2956
{
57+
int value = *(int *)parameter;
3058
while (1)
3159
{
3260
tick++;
33-
if (tick == 100)
61+
if (tick >= 100 && (finish_flag & (1 << value)) == 0)
3462
{
35-
/* Output the current core running threads */
36-
extern long list_thread(void);
37-
list_thread();
38-
finsh_flag = 0xA55A;
63+
rt_atomic_or((volatile rt_atomic_t *)&finish_flag, (1 << value));
3964
uassert_true(1);
4065
}
41-
rt_thread_delay(5);
4266
}
4367
}
4468

@@ -54,8 +78,8 @@ static void thread_on_idle_core_tc(void)
5478
params[i] = i;
5579
}
5680

57-
/* Create RT_CPUS_NR threads and pass the entry parameters for each thread */
58-
for (i = 0; i < RT_CPUS_NR; i++)
81+
/* Create RT_CPUS_NR-1 threads and pass the entry parameters for each thread */
82+
for (i = 0; i < RT_CPUS_NR - 1; i++)
5983
{
6084
rt_snprintf(thread_name, sizeof(thread_name), "T%d", i);
6185
threads[i] = rt_thread_create(thread_name, thread_entry, &params[i], THREAD_STACK_SIZE, THREAD_PRIORITY, 20);
@@ -66,18 +90,23 @@ static void thread_on_idle_core_tc(void)
6690
}
6791
}
6892
/* Waiting for test cases to finish */
69-
while (finsh_flag != 0xA55A);
93+
while (finish_flag != (1<<(RT_CPUS_NR-1))-1);
94+
/* Output the current core running threads */
95+
extern long list_thread(void);
96+
list_thread();
7097
}
7198

7299
static rt_err_t utest_tc_init(void)
73100
{
101+
finish_flag = 0;
102+
tick = 0;
74103
rt_kprintf("[Test case]: created threads are automatically assigned to run on idle cores\r\n");
75104
return RT_EOK;
76105
}
77106

78107
static rt_err_t utest_tc_cleanup(void)
79108
{
80-
for (num = 0; num < RT_CPUS_NR; num++)
109+
for (num = 0; num < RT_CPUS_NR - 1; num++)
81110
{
82111
rt_thread_delete(threads[num]);
83112
}
@@ -89,3 +118,4 @@ static void testcase(void)
89118
UTEST_UNIT_RUN(thread_on_idle_core_tc);
90119
}
91120
UTEST_TC_EXPORT(testcase, "core.smp_assigned_idle_cores", utest_tc_init, utest_tc_cleanup, 10);
121+

src/utest/timer_tc.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,39 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2021-08-12 luckyzjq the first version
9+
* 2025-11-17 Ze-Hou add standardized utest documentation block
10+
*/
11+
12+
/**
13+
* Test Case Name: Kernel Core Timer Test
14+
*
15+
* Test Objectives:
16+
* - Validate the RT-Thread kernel timer (rt_timer) functionality
17+
* - Test static and dynamic timer creation, initialization, start, stop, delete,
18+
* detach, and control APIs
19+
* - Verify one-shot and periodic timer behaviors, including hard and soft timer modes
20+
*
21+
* Test Scenarios:
22+
* - Initialize and start static timers in one-shot and periodic modes, with various flag combinations
23+
* - Start a timer twice before it expires to verify restart behavior
24+
* - Use timer control APIs to set and get timer period, and verify correct timing
25+
* - Start and stop timers within their callback functions to test reentrancy and robustness
26+
* - Create, start, stop, and delete dynamic timers, verifying correct operation and resource management
27+
* - Perform stress testing by rapidly starting and stopping a large number of timers concurrently
28+
*
29+
* Verification Metrics:
30+
* - All uassert assertions pass without failure
31+
* - Timers are created, started, stopped, detached, and deleted successfully
32+
* - Timer callbacks are invoked at the expected tick count
33+
* - Timer restart and control operations behave as expected
34+
*
35+
* Dependencies:
36+
* - Enable Timer Test (RT-Thread Utestcases -> Kernel Core -> Timer Test)
37+
* - Test on any RT-Thread supported platform (e.g., qemu-virt64-riscv)
38+
*
39+
* Expected Results:
40+
* - After executing this test in msh, the expected output should be:
41+
* "[ PASSED ] [ result ] testcase (core.timer)"
942
*/
1043

1144
#include <rtthread.h>

0 commit comments

Comments
 (0)