1515#include <utest_assert.h>
1616#include <perf_tc.h>
1717
18- #define RET_INT 0
19- #define RET_DECIMALS 1
18+ #define RET_INT 0
19+ #define RET_DECIMALS 1
2020
21- #define GET_INT (num ) split_double(num, RET_INT)
22- #define GET_DECIMALS (num ) split_double(num, RET_DECIMALS)
21+ #define GET_INT (num ) split_double(num, RET_INT)
22+ #define GET_DECIMALS (num ) split_double(num, RET_DECIMALS)
2323
2424static rt_device_t hw_dev = RT_NULL ;
25- static rt_hwtimerval_t timeout_s = {0 };
25+ static rt_hwtimerval_t timeout_s = { 0 };
2626
2727typedef rt_err_t (* testcase_function )(rt_perf_t * perf );
28- testcase_function test_func_ptrs [] =
29- {
28+ testcase_function test_func_ptrs [] = {
3029 context_switch_test ,
3130 rt_perf_thread_sem ,
3231 rt_perf_thread_event ,
@@ -38,7 +37,7 @@ testcase_function test_func_ptrs[] =
3837
3938static rt_uint32_t rt_perf_get_timer_us (void )
4039{
41- rt_hwtimerval_t timer_val = {0 };
40+ rt_hwtimerval_t timer_val = { 0 };
4241 if (hw_dev && rt_device_read (hw_dev , 0 , & timer_val , sizeof (rt_hwtimerval_t )))
4342 {
4443 return (rt_uint32_t )(timer_val .sec * 1000000u + timer_val .usec ); /* return us */
@@ -61,7 +60,8 @@ void rt_perf_stop(rt_perf_t *perf)
6160{
6261 perf -> real_time = rt_perf_get_timer_us () - perf -> begin_time ;
6362
64- if (perf -> local_modify ) perf -> local_modify (perf );
63+ if (perf -> local_modify )
64+ perf -> local_modify (perf );
6565 if (perf -> real_time > perf -> max_time )
6666 {
6767 perf -> max_time = perf -> real_time ;
@@ -75,7 +75,7 @@ void rt_perf_stop(rt_perf_t *perf)
7575 perf -> count ++ ;
7676 perf -> tot_time += perf -> real_time ;
7777
78- if (hw_dev )
78+ if (hw_dev )
7979 rt_device_control (hw_dev , HWTIMER_CTRL_STOP , NULL );
8080}
8181
@@ -97,11 +97,11 @@ static rt_int32_t split_double(double num, rt_uint32_t type)
9797 return (-1 );
9898}
9999
100- void rt_perf_dump ( rt_perf_t * perf )
100+ void rt_perf_dump (rt_perf_t * perf )
101101{
102102 static rt_uint32_t test_index = 1 ;
103- char avg_str [10 ] = {0 };
104- if (perf -> dump_head )
103+ char avg_str [10 ] = { 0 };
104+ if (perf -> dump_head )
105105 {
106106 rt_kprintf ("Test No | Test Name | Count | Total Time (us) | Max Time (us) | Min Time (us) | Avg Time (us)\n" );
107107 rt_kprintf ("--------|----------------------|-------|-----------------|---------------|---------------|--------------\n" );
@@ -116,13 +116,13 @@ void rt_perf_dump( rt_perf_t *perf)
116116 rt_sprintf (avg_str , "%u.%04u" , GET_INT (perf -> avg_time ), GET_DECIMALS (perf -> avg_time ));
117117
118118 rt_kprintf ("%7u | %-20s | %5u | %15u | %13u | %13u | %12s\n" ,
119- test_index ++ ,
120- perf -> name ,
121- perf -> count ,
122- perf -> tot_time ,
123- perf -> max_time ,
124- perf -> min_time ,
125- avg_str );
119+ test_index ++ ,
120+ perf -> name ,
121+ perf -> count ,
122+ perf -> tot_time ,
123+ perf -> max_time ,
124+ perf -> min_time ,
125+ avg_str );
126126}
127127
128128static void rt_perf_clear (rt_perf_t * perf )
@@ -140,7 +140,6 @@ static void rt_perf_clear(rt_perf_t *perf)
140140
141141static void rt_perf_all_test (void )
142142{
143-
144143 rt_perf_t * perf_data = rt_malloc (sizeof (rt_perf_t ));
145144 if (perf_data == RT_NULL )
146145 {
@@ -154,7 +153,7 @@ static void rt_perf_all_test(void)
154153 rt_perf_clear (perf_data );
155154 if (test_func_ptrs [i ](perf_data ) != RT_EOK )
156155 {
157- LOG_E ("%s test fail" ,perf_data -> name );
156+ LOG_E ("%s test fail" , perf_data -> name );
158157 continue ;
159158 }
160159 }
@@ -181,15 +180,16 @@ static rt_err_t utest_tc_init(void)
181180 return ret ;
182181 }
183182
184- timeout_s .sec = 10 ; /* No modification is necessary here, use the fixed value */
183+ timeout_s .sec = 10 ; /* No modification is necessary here, use the fixed value */
185184 timeout_s .usec = 0 ;
186185
187186 return ret ;
188187}
189188
190189static rt_err_t utest_tc_cleanup (void )
191190{
192- if (hw_dev ) rt_device_close (hw_dev );
191+ if (hw_dev )
192+ rt_device_close (hw_dev );
193193 return RT_EOK ;
194194}
195195
@@ -198,5 +198,5 @@ static void testcase(void)
198198 UTEST_UNIT_RUN (rt_perf_all_test );
199199}
200200
201- UTEST_TC_EXPORT (testcase , "core.pref_test " , utest_tc_init , utest_tc_cleanup , 10 );
201+ UTEST_TC_EXPORT (testcase , "core.perf_test " , utest_tc_init , utest_tc_cleanup , 10 );
202202
0 commit comments