99 * 2021-10.11 mazhiyuan add idle, yield, suspend, control, priority, delay_until
1010 */
1111
12+ #define __RTT_IPC_SOURCE__ /* include internal API for utest */
13+
1214#include <rtthread.h>
1315#include <stdlib.h>
1416#include "utest.h"
@@ -56,7 +58,7 @@ static void test_dynamic_thread(void)
5658 thread1_entry ,
5759 (void * )1 ,
5860 THREAD_STACK_SIZE ,
59- __current_thread -> current_priority + 1 ,
61+ UTEST_THR_PRIORITY + 1 ,
6062 THREAD_TIMESLICE - 5 );
6163 if (tid1 == RT_NULL )
6264 {
@@ -105,7 +107,7 @@ static void test_static_thread(void)
105107 (void * )2 ,
106108 & thread2_stack [0 ],
107109 sizeof (thread2_stack ),
108- __current_thread -> current_priority + 1 ,
110+ UTEST_THR_PRIORITY + 1 ,
109111 THREAD_TIMESLICE );
110112 if (ret_init != RT_EOK )
111113 {
@@ -139,10 +141,11 @@ static void test_static_thread(void)
139141
140142static void thread3_entry (void * parameter )
141143{
142- rt_tick_t tick ;
144+ rt_tick_t tick , latency_tick ;
143145 tick = rt_tick_get ();
144146 rt_thread_delay (15 );
145- if (rt_tick_get () - tick > 16 )
147+ latency_tick = rt_tick_get () - tick ;
148+ if (latency_tick > 16 || latency_tick < 15 )
146149 {
147150 tid3_finish_flag = 1 ;
148151 tid3_delay_pass_flag = 0 ;
@@ -160,7 +163,7 @@ static void test_thread_delay(void)
160163 thread3_entry ,
161164 RT_NULL ,
162165 THREAD_STACK_SIZE ,
163- __current_thread -> current_priority - 1 ,
166+ UTEST_THR_PRIORITY - 1 ,
164167 THREAD_TIMESLICE );
165168 if (tid3 == RT_NULL )
166169 {
@@ -210,7 +213,7 @@ static void test_idle_hook(void)
210213 thread4_entry ,
211214 RT_NULL ,
212215 THREAD_STACK_SIZE ,
213- __current_thread -> current_priority - 1 ,
216+ UTEST_THR_PRIORITY - 1 ,
214217 THREAD_TIMESLICE );
215218 if (tid4 == RT_NULL )
216219 {
@@ -264,7 +267,7 @@ static void test_thread_yield(void)
264267 thread5_entry ,
265268 RT_NULL ,
266269 THREAD_STACK_SIZE ,
267- __current_thread -> current_priority - 1 ,
270+ UTEST_THR_PRIORITY - 1 ,
268271 THREAD_TIMESLICE );
269272 if (tid5 == RT_NULL )
270273 {
@@ -283,7 +286,7 @@ static void test_thread_yield(void)
283286 thread6_entry ,
284287 RT_NULL ,
285288 THREAD_STACK_SIZE ,
286- __current_thread -> current_priority - 1 ,
289+ UTEST_THR_PRIORITY - 1 ,
287290 THREAD_TIMESLICE );
288291 if (tid6 == RT_NULL )
289292 {
@@ -319,12 +322,13 @@ static void test_thread_control(void)
319322{
320323 rt_err_t ret_control = - RT_ERROR ;
321324 rt_err_t rst_delete = - RT_ERROR ;
325+ rt_sched_lock_level_t slvl ;
322326
323327 tid7 = rt_thread_create ("thread7" ,
324328 thread7_entry ,
325329 RT_NULL ,
326330 THREAD_STACK_SIZE ,
327- __current_thread -> current_priority + 1 ,
331+ UTEST_THR_PRIORITY + 1 ,
328332 THREAD_TIMESLICE );
329333 if (tid7 == RT_NULL )
330334 {
@@ -342,12 +346,17 @@ static void test_thread_control(void)
342346 }
343347 rt_thread_mdelay (200 );
344348 rt_thread_control (tid7 , RT_THREAD_CTRL_CHANGE_PRIORITY , & change_priority );
345- if (tid7 -> current_priority != change_priority )
349+
350+ rt_sched_lock (& slvl );
351+ if (rt_sched_thread_get_curr_prio (tid7 ) != change_priority )
346352 {
347353 LOG_E ("rt_thread_control failed!" );
348354 uassert_false (1 );
355+ rt_sched_unlock (slvl );
349356 goto __exit ;
350357 }
358+ rt_sched_unlock (slvl );
359+
351360 rst_delete = rt_thread_control (tid7 , RT_THREAD_CTRL_CLOSE , RT_NULL );
352361 if (rst_delete != RT_EOK )
353362 {
@@ -380,7 +389,7 @@ static void test_thread_priority(void)
380389 thread8_entry ,
381390 RT_NULL ,
382391 THREAD_STACK_SIZE ,
383- __current_thread -> current_priority - 1 ,
392+ UTEST_THR_PRIORITY - 1 ,
384393 THREAD_TIMESLICE );
385394 if (tid8 == RT_NULL )
386395 {
@@ -495,7 +504,7 @@ void test_timeslice(void)
495504 timeslice_cntB2 = 0 ;
496505
497506 tidA = rt_thread_create ("timeslice" , test_timeslice_threadA_entry , RT_NULL ,
498- 2048 , __current_thread -> current_priority + 1 , 10 );
507+ 2048 , UTEST_THR_PRIORITY + 1 , 10 );
499508 if (!tidA )
500509 {
501510 LOG_E ("rt_thread_create failed!" );
@@ -512,7 +521,7 @@ void test_timeslice(void)
512521 }
513522
514523 tidB1 = rt_thread_create ("timeslice" , test_timeslice_threadB1_entry , RT_NULL ,
515- 2048 , __current_thread -> current_priority + 2 , 2 );
524+ 2048 , UTEST_THR_PRIORITY + 2 , 2 );
516525 if (!tidB1 )
517526 {
518527 LOG_E ("rt_thread_create failed!" );
@@ -529,7 +538,7 @@ void test_timeslice(void)
529538 }
530539
531540 tidB2 = rt_thread_create ("timeslice" , test_timeslice_threadB2_entry , RT_NULL ,
532- 2048 , __current_thread -> current_priority + 2 , 2 );
541+ 2048 , UTEST_THR_PRIORITY + 2 , 2 );
533542 if (!tidB2 )
534543 {
535544 LOG_E ("rt_thread_create failed!" );
@@ -655,7 +664,7 @@ void test_thread_yield_nosmp(void)
655664// thread9_entry,
656665// RT_NULL,
657666// THREAD_STACK_SIZE,
658- // __current_thread->current_priority + 1,
667+ // UTEST_THR_PRIORITY + 1,
659668// THREAD_TIMESLICE);
660669// if (tid == RT_NULL)
661670// {
@@ -695,7 +704,7 @@ void test_thread_yield_nosmp(void)
695704static rt_err_t utest_tc_init (void )
696705{
697706 __current_thread = rt_thread_self ();
698- change_priority = __current_thread -> current_priority + 5 ;
707+ change_priority = UTEST_THR_PRIORITY + 5 ;
699708 tid3_delay_pass_flag = 0 ;
700709 tid3_finish_flag = 0 ;
701710 tid4_finish_flag = 0 ;
0 commit comments