1 | /* |
---|
2 | * This test checks rtems_cpu_usage_top command with |
---|
3 | * 30 tasks being created and deleted. The command |
---|
4 | * should show the task list grow to the top 20 tasks |
---|
5 | * then shrink back down to 5 tasks. |
---|
6 | * |
---|
7 | * Input parameters: |
---|
8 | * argument - task argument |
---|
9 | * |
---|
10 | * Output parameters: NONE |
---|
11 | * |
---|
12 | * COPYRIGHT (c) 2014. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.org/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #ifdef HAVE_CONFIG_H |
---|
21 | #include "config.h" |
---|
22 | #endif |
---|
23 | |
---|
24 | #define CONFIGURE_INIT |
---|
25 | #include "system.h" |
---|
26 | |
---|
27 | #include <rtems/shell.h> |
---|
28 | |
---|
29 | const char rtems_test_name[] = "TOP"; |
---|
30 | |
---|
31 | /* |
---|
32 | * This method is called by Task_3 to provide |
---|
33 | * a variable lengh run time for each instance |
---|
34 | * of the task. |
---|
35 | */ |
---|
36 | |
---|
37 | void add_some( |
---|
38 | uint32_t per_loop, |
---|
39 | uint32_t *sum, |
---|
40 | uint32_t *next |
---|
41 | ) |
---|
42 | { |
---|
43 | int i; |
---|
44 | |
---|
45 | for ( i=0 ; i<per_loop ; i++ ) { |
---|
46 | *sum += *next; |
---|
47 | *next += 1; |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | static void notification(int fd, int seconds_remaining, void *arg) |
---|
52 | { |
---|
53 | printf( |
---|
54 | "Press any key to enter top test (%is remaining)\n", |
---|
55 | seconds_remaining |
---|
56 | ); |
---|
57 | } |
---|
58 | |
---|
59 | rtems_task Init( |
---|
60 | rtems_task_argument argument |
---|
61 | ) |
---|
62 | { |
---|
63 | rtems_status_code status; |
---|
64 | rtems_time_of_day time; |
---|
65 | |
---|
66 | TEST_BEGIN(); |
---|
67 | |
---|
68 | status = rtems_shell_wait_for_input( |
---|
69 | STDIN_FILENO, |
---|
70 | 20, |
---|
71 | notification, |
---|
72 | NULL |
---|
73 | ); |
---|
74 | if ( status != RTEMS_SUCCESSFUL ) { |
---|
75 | TEST_END(); |
---|
76 | |
---|
77 | rtems_test_exit( 0 ); |
---|
78 | } |
---|
79 | |
---|
80 | build_time( &time, 12, 31, 1988, 9, 15, 0, 0 ); |
---|
81 | |
---|
82 | status = rtems_clock_set( &time ); |
---|
83 | directive_failed( status, "rtems_clock_set" ); |
---|
84 | |
---|
85 | TicksPerSecond = rtems_clock_get_ticks_per_second(); |
---|
86 | if (TicksPerSecond <= 0) { |
---|
87 | printf( |
---|
88 | "Invalid ticks per second: %" PRIdrtems_interval "\n", |
---|
89 | TicksPerSecond |
---|
90 | ); |
---|
91 | exit (1); |
---|
92 | } |
---|
93 | |
---|
94 | /* Create and start the task to run top command. */ |
---|
95 | Task_name[ 2 ] = rtems_build_name( 'T', 'A', '0', '2' ); |
---|
96 | status = rtems_task_create( |
---|
97 | Task_name[ 2 ], |
---|
98 | 2, |
---|
99 | RTEMS_MINIMUM_STACK_SIZE, |
---|
100 | RTEMS_TIMESLICE, |
---|
101 | RTEMS_FLOATING_POINT, |
---|
102 | &Task_id[ 2 ] |
---|
103 | ); |
---|
104 | directive_failed( status, "rtems_task_create of TA02" ); |
---|
105 | status = rtems_task_start( Task_id[ 2 ], Task_2, 0 ); |
---|
106 | directive_failed( status, "rtems_task_start of TA2" ); |
---|
107 | |
---|
108 | /* Create and start task to run the test. */ |
---|
109 | Task_name[ 1 ] = rtems_build_name( 'T', 'A', '0', '1' ); |
---|
110 | status = rtems_task_create( |
---|
111 | Task_name[ 1 ], |
---|
112 | 2, |
---|
113 | RTEMS_MINIMUM_STACK_SIZE, |
---|
114 | RTEMS_TIMESLICE, |
---|
115 | RTEMS_FLOATING_POINT, |
---|
116 | &Task_id[ 1 ] |
---|
117 | ); |
---|
118 | directive_failed( status, "rtems_task_create of TA01" ); |
---|
119 | status = rtems_task_start( Task_id[ 1 ], Task_1, 0 ); |
---|
120 | directive_failed( status, "rtems_task_start of TA01" ); |
---|
121 | |
---|
122 | /* |
---|
123 | * We suspend the Init task rather than delete it so it still |
---|
124 | * shows up in the output. |
---|
125 | */ |
---|
126 | status = rtems_task_suspend( RTEMS_SELF ); |
---|
127 | directive_failed( status, "rtems_task_suspend of RTEMS_SELF" ); |
---|
128 | } |
---|