source: rtems/testsuites/tmtests/tm08/task1.c @ fd46711

4.115
Last change on this file since fd46711 was 2ead50a, checked in by bjorn larsson <bjornlarsson@…>, on 03/21/14 at 15:48:01

tmtests: convert to test.h

  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2013.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define CONFIGURE_INIT
15#include "system.h"
16
17const char rtems_test_name[] = "TIME TEST 8";
18
19rtems_id Test_task_id;
20
21rtems_task test_task(
22  rtems_task_argument argument
23);
24rtems_task test_task1(
25  rtems_task_argument argument
26);
27void test_init(void);
28
29rtems_task Init(
30  rtems_task_argument argument
31)
32{
33  rtems_status_code status;
34
35  Print_Warning();
36
37  TEST_BEGIN();
38
39  test_init();
40
41  status = rtems_task_delete( RTEMS_SELF );
42  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
43}
44
45void test_init(void)
46{
47  rtems_status_code status;
48
49  status = rtems_task_create(
50    1,
51    (RTEMS_MAXIMUM_PRIORITY / 2u) + 1u,
52    RTEMS_MINIMUM_STACK_SIZE,
53    RTEMS_DEFAULT_MODES,
54    RTEMS_DEFAULT_ATTRIBUTES,
55    &Test_task_id
56  );
57  directive_failed( status, "rtems_task_create" );
58
59  status = rtems_task_start( Test_task_id, test_task, 0 );
60  directive_failed( status, "rtems_task_start" );
61
62  status = rtems_task_create(
63    1,
64    RTEMS_MAXIMUM_PRIORITY - 1u,
65    RTEMS_MINIMUM_STACK_SIZE,
66    RTEMS_DEFAULT_MODES,
67    RTEMS_DEFAULT_ATTRIBUTES,
68    &Test_task_id
69  );
70  directive_failed( status, "rtems_task_create" );
71
72  status = rtems_task_start( Test_task_id, test_task1, 0 );
73  directive_failed( status, "rtems_task_start" );
74}
75
76rtems_task test_task(
77  rtems_task_argument argument
78)
79{
80  rtems_status_code   status;
81  uint32_t      index;
82  rtems_task_priority old_priority;
83  rtems_time_of_day   time;
84  uint32_t      old_note;
85  uint32_t      old_mode;
86
87  benchmark_timer_initialize();
88    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
89      (void) benchmark_timer_empty_function();
90  overhead = benchmark_timer_read();
91
92  benchmark_timer_initialize();
93    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
94      (void) rtems_task_set_priority(
95               Test_task_id,
96               RTEMS_CURRENT_PRIORITY,
97               &old_priority
98             );
99  end_time = benchmark_timer_read();
100
101  put_time(
102    "rtems_task_set_priority: obtain current priority",
103    end_time,
104    OPERATION_COUNT,
105    overhead,
106    CALLING_OVERHEAD_TASK_SET_PRIORITY
107  );
108
109  benchmark_timer_initialize();
110    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
111      (void) rtems_task_set_priority(
112        Test_task_id,
113        RTEMS_MAXIMUM_PRIORITY - 2u,
114        &old_priority
115      );
116
117  end_time = benchmark_timer_read();
118
119  put_time(
120    "rtems_task_set_priority: returns to caller",
121    end_time,
122    OPERATION_COUNT,
123    overhead,
124    CALLING_OVERHEAD_TASK_SET_PRIORITY
125  );
126
127  benchmark_timer_initialize();
128    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
129      (void) rtems_task_mode(
130        RTEMS_CURRENT_MODE,
131        RTEMS_CURRENT_MODE,
132        &old_mode
133      );
134  end_time = benchmark_timer_read();
135
136  put_time(
137    "rtems_task_mode: obtain current mode",
138    end_time,
139    OPERATION_COUNT,
140    overhead,
141    CALLING_OVERHEAD_TASK_MODE
142  );
143
144  benchmark_timer_initialize();
145    for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
146      (void) rtems_task_mode(
147        RTEMS_INTERRUPT_LEVEL(1),
148        RTEMS_INTERRUPT_MASK,
149        &old_mode
150      );
151      (void) rtems_task_mode(
152        RTEMS_INTERRUPT_LEVEL(0),
153        RTEMS_INTERRUPT_MASK,
154        &old_mode
155      );
156    }
157  end_time = benchmark_timer_read();
158
159  put_time(
160    "rtems_task_mode: no reschedule",
161    end_time,
162    OPERATION_COUNT * 2,
163    overhead,
164    CALLING_OVERHEAD_TASK_MODE
165  );
166
167  benchmark_timer_initialize();                 /* must be one host */
168    (void) rtems_task_mode( RTEMS_NO_ASR, RTEMS_ASR_MASK, &old_mode );
169  end_time = benchmark_timer_read();
170
171  put_time(
172    "rtems_task_mode: reschedule returns to caller",
173    end_time,
174    1,
175    0,
176    CALLING_OVERHEAD_TASK_MODE
177  );
178
179  status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &old_mode );
180  directive_failed( status, "rtems_task_mode" );
181
182  status = rtems_task_set_priority( Test_task_id, 1, &old_priority );
183  directive_failed( status, "rtems_task_set_priority" );
184
185  /* preempted by test_task1 */
186  benchmark_timer_initialize();
187    (void)  rtems_task_mode( RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &old_mode );
188
189  benchmark_timer_initialize();
190    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
191      (void) rtems_task_set_note( Test_task_id, 8, 10 );
192  end_time = benchmark_timer_read();
193
194  put_time(
195    "rtems_task_set_note: only case",
196    end_time,
197    OPERATION_COUNT,
198    overhead,
199    CALLING_OVERHEAD_TASK_SET_NOTE
200  );
201
202  benchmark_timer_initialize();
203    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
204      (void) rtems_task_get_note( Test_task_id, 8, &old_note );
205  end_time = benchmark_timer_read();
206
207  put_time(
208    "rtems_task_get_note: only case",
209    end_time,
210    OPERATION_COUNT,
211    overhead,
212    CALLING_OVERHEAD_TASK_GET_NOTE
213  );
214
215  build_time( &time, 1, 1, 1988, 0, 0, 0, 0 );
216
217  benchmark_timer_initialize();
218    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
219      (void) rtems_clock_set( &time );
220  end_time = benchmark_timer_read();
221
222  put_time(
223    "rtems_clock_set: only case",
224    end_time,
225    OPERATION_COUNT,
226    overhead,
227    CALLING_OVERHEAD_CLOCK_SET
228  );
229
230  benchmark_timer_initialize();
231    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
232      (void) rtems_clock_get_tod( &time );
233  end_time = benchmark_timer_read();
234
235  put_time(
236    "rtems_clock_get_tod: only case",
237    end_time,
238    OPERATION_COUNT,
239    overhead,
240    CALLING_OVERHEAD_CLOCK_GET
241  );
242
243  TEST_END();
244  rtems_test_exit( 0 );
245}
246
247rtems_task test_task1(
248  rtems_task_argument argument
249)
250{
251  end_time = benchmark_timer_read();
252
253  put_time(
254    "rtems_task_mode: reschedule -- preempts caller",
255    end_time,
256    1,
257    0,
258    CALLING_OVERHEAD_TASK_MODE
259  );
260
261  (void) rtems_task_suspend( RTEMS_SELF );
262}
Note: See TracBrowser for help on using the repository browser.