source: rtems/testsuites/tmtests/tm20/task1.c @ b331f40

Last change on this file since b331f40 was b331f40, checked in by Joel Sherrill <joel@…>, on 04/01/22 at 19:05:19

testsuites/tmtests/*: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 11.1 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 *  COPYRIGHT (c) 1989-2013.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#if !defined(OPERATION_COUNT)
30#define OPERATION_COUNT 100
31#endif
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
37#include <rtems/btimer.h>
38
39#define CONFIGURE_INIT
40#include "system.h"
41
42const char rtems_test_name[] = "TIME TEST 20";
43
44rtems_device_major_number _STUB_major = 1;
45
46rtems_id         Region_id;
47rtems_name       Region_name;
48uint8_t    Region_area[ 2048 ] CPU_STRUCTURE_ALIGNMENT;
49
50#define PARTITION_SIZE         2048
51#define PARTITION_ELEMENT_SIZE  128
52#define PARTITION_BUFFER_POINTERS \
53    ((PARTITION_SIZE / PARTITION_ELEMENT_SIZE) + 2)
54
55rtems_id         Partition_id;
56rtems_name       Partition_name;
57uint8_t    Partition_area[ PARTITION_SIZE ] CPU_STRUCTURE_ALIGNMENT;
58
59void  *Buffer_address_1;
60void  *Buffer_address_2;
61void  *Buffer_address_3;
62void  *Buffer_address_4;
63
64uint32_t   buffer_count;
65
66void  *Buffer_addresses[ PARTITION_BUFFER_POINTERS ];
67
68rtems_task Task_1(
69  rtems_task_argument argument
70);
71
72rtems_task Task_2(
73  rtems_task_argument argument
74);
75
76rtems_task Init(
77  rtems_task_argument argument
78)
79{
80  rtems_status_code status;
81
82  Print_Warning();
83
84  TEST_BEGIN();
85
86  status = rtems_task_create(
87    rtems_build_name( 'T', 'I', 'M', '1' ),
88    (RTEMS_MAXIMUM_PRIORITY / 2u) + 1u,
89    RTEMS_MINIMUM_STACK_SIZE,
90    RTEMS_DEFAULT_MODES,
91    RTEMS_DEFAULT_ATTRIBUTES,
92    &Task_id[ 1 ]
93  );
94  directive_failed( status, "rtems_task_create of TASK1" );
95
96  status = rtems_task_start( Task_id[ 1 ], Task_1, 0 );
97  directive_failed( status, "rtems_task_start of TASK1" );
98
99  status = rtems_task_create(
100    rtems_build_name( 'T', 'I', 'M', '2' ),
101    (RTEMS_MAXIMUM_PRIORITY / 2u) + 2u,
102    RTEMS_MINIMUM_STACK_SIZE,
103    RTEMS_DEFAULT_MODES,
104    RTEMS_DEFAULT_ATTRIBUTES,
105    &Task_id[ 2 ]
106  );
107  directive_failed( status, "rtems_task_create of TASK2" );
108
109  status = rtems_task_start( Task_id[ 2 ], Task_2, 0 );
110  directive_failed( status, "rtems_task_start of TASK2" );
111
112  rtems_task_exit();
113}
114
115rtems_task Task_1(
116  rtems_task_argument argument
117)
118{
119  uint32_t      index;
120  rtems_mode          previous_mode;
121  rtems_task_priority previous_priority;
122  rtems_status_code   status;
123
124  Partition_name = rtems_build_name( 'P', 'A', 'R', 'T' );
125
126  benchmark_timer_initialize();
127    rtems_partition_create(
128      Partition_name,
129      Partition_area,
130      PARTITION_SIZE,
131      128,
132      RTEMS_DEFAULT_ATTRIBUTES,
133      &Partition_id
134    );
135  end_time = benchmark_timer_read();
136
137  put_time(
138    "rtems_partition_create: only case",
139    end_time,
140    1,
141    0,
142    0
143  );
144
145  Region_name = rtems_build_name( 'R', 'E', 'G', 'N' );
146
147  benchmark_timer_initialize();
148    rtems_region_create(
149      Region_name,
150      Region_area,
151      2048,
152      16,
153      RTEMS_DEFAULT_ATTRIBUTES,
154      &Region_id
155    );
156  end_time = benchmark_timer_read();
157
158  put_time(
159    "rtems_region_create: only case",
160    end_time,
161    1,
162    0,
163    0
164  );
165
166  benchmark_timer_initialize();
167    (void) rtems_partition_get_buffer( Partition_id, &Buffer_address_1 );
168  end_time = benchmark_timer_read();
169
170  put_time(
171    "rtems_partition_get_buffer: available",
172    end_time,
173    1,
174    0,
175    0
176  );
177
178  buffer_count = 0;
179  while ( FOREVER ) {
180
181    status = rtems_partition_get_buffer(
182               Partition_id,
183               &Buffer_addresses[ buffer_count ]
184            );
185
186    if ( status == RTEMS_UNSATISFIED ) break;
187
188    buffer_count++;
189
190    rtems_test_assert( buffer_count < PARTITION_BUFFER_POINTERS );
191  }
192
193  benchmark_timer_initialize();
194    (void) rtems_partition_get_buffer( Partition_id, &Buffer_address_2 );
195  end_time = benchmark_timer_read();
196
197  put_time(
198    "rtems_partition_get_buffer: not available",
199    end_time,
200    1,
201    0,
202    0
203  );
204
205  benchmark_timer_initialize();
206    (void) rtems_partition_return_buffer( Partition_id, Buffer_address_1 );
207  end_time = benchmark_timer_read();
208
209  put_time(
210    "rtems_partition_return_buffer: only case",
211    end_time,
212    1,
213    0,
214    0
215  );
216
217  for ( index = 0 ; index < buffer_count ; index++ ) {
218
219    status = rtems_partition_return_buffer(
220               Partition_id,
221               Buffer_addresses[ index ]
222             );
223    directive_failed( status, "rtems_partition_return_buffer" );
224
225  }
226
227  benchmark_timer_initialize();
228    (void) rtems_partition_delete( Partition_id );
229  end_time = benchmark_timer_read();
230
231  put_time(
232    "rtems_partition_delete: only case",
233    end_time,
234    1,
235    0,
236    0
237  );
238
239  status = rtems_region_get_segment(
240             Region_id,
241             400,
242             RTEMS_DEFAULT_OPTIONS,
243             RTEMS_NO_TIMEOUT,
244             &Buffer_address_2
245           );
246  directive_failed( status, "region_get_segment" );
247
248  benchmark_timer_initialize();
249    (void) rtems_region_get_segment(
250      Region_id,
251      400,
252      RTEMS_DEFAULT_OPTIONS,
253      RTEMS_NO_TIMEOUT,
254      &Buffer_address_3
255    );
256  end_time = benchmark_timer_read();
257
258  put_time(
259    "rtems_region_get_segment: available",
260    end_time,
261    1,
262    0,
263    0
264  );
265
266  benchmark_timer_initialize();
267    (void) rtems_region_get_segment(
268      Region_id,
269      1700,
270      RTEMS_NO_WAIT,
271      RTEMS_NO_TIMEOUT,
272      &Buffer_address_4
273    );
274  end_time = benchmark_timer_read();
275
276  put_time(
277    "rtems_region_get_segment: not available NO_WAIT",
278    end_time,
279    1,
280    0,
281    0
282  );
283
284  status = rtems_region_return_segment( Region_id, Buffer_address_3 );
285  directive_failed( status, "rtems_region_return_segment" );
286
287  benchmark_timer_initialize();
288    (void) rtems_region_return_segment( Region_id, Buffer_address_2 );
289  end_time = benchmark_timer_read();
290
291  put_time(
292    "rtems_region_return_segment: no waiting tasks",
293    end_time,
294    1,
295    0,
296    0
297  );
298
299  status = rtems_region_get_segment(
300    Region_id,
301    400,
302    RTEMS_DEFAULT_OPTIONS,
303    RTEMS_NO_TIMEOUT,
304    &Buffer_address_1
305  );
306  directive_failed( status, "rtems_region_get_segment" );
307
308  benchmark_timer_initialize();
309    (void) rtems_region_get_segment(
310      Region_id,
311      1700,
312      RTEMS_DEFAULT_OPTIONS,
313      RTEMS_NO_TIMEOUT,
314      &Buffer_address_2
315    );
316
317  /* execute Task_2 */
318
319  end_time = benchmark_timer_read();
320
321  put_time(
322    "rtems_region_return_segment: task readied preempts caller",
323    end_time,
324    1,
325    0,
326    0
327  );
328
329  status = rtems_region_return_segment( Region_id, Buffer_address_2 );
330  directive_failed( status, "rtems_region_return_segment" );
331
332  status = rtems_task_mode(
333    RTEMS_NO_PREEMPT,
334    RTEMS_PREEMPT_MASK,
335    &previous_mode
336  );
337  directive_failed( status, "rtems_task_mode" );
338
339  status = rtems_task_set_priority(
340    RTEMS_SELF, RTEMS_MAXIMUM_PRIORITY - 1u, &previous_priority );
341  directive_failed( status, "rtems_task_set_priority" );
342
343  status = rtems_region_get_segment(
344    Region_id,
345    400,
346    RTEMS_DEFAULT_OPTIONS,
347    RTEMS_NO_TIMEOUT,
348    &Buffer_address_1
349  );
350  directive_failed( status, "rtems_region_return_segment" );
351
352  status = rtems_region_get_segment(
353    Region_id,
354    1700,
355    RTEMS_DEFAULT_OPTIONS,
356    RTEMS_NO_TIMEOUT,
357    &Buffer_address_2
358  );
359  directive_failed( status, "rtems_region_get_segment" );
360
361  /* execute Task_2 */
362
363  status = rtems_region_return_segment( Region_id, Buffer_address_2 );
364  directive_failed( status, "rtems_region_return_segment" );
365
366  benchmark_timer_initialize();
367    (void) rtems_region_delete( Region_id );
368  end_time = benchmark_timer_read();
369
370  put_time(
371    "rtems_region_delete: only case",
372    end_time,
373    1,
374    0,
375    0
376  );
377
378  benchmark_timer_initialize();
379    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
380      (void) benchmark_timer_empty_function();
381  overhead = benchmark_timer_read();
382
383  benchmark_timer_initialize();
384    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
385      (void) rtems_io_initialize( _STUB_major, 0, NULL );
386  end_time = benchmark_timer_read();
387
388  put_time(
389    "rtems_io_initialize: only case",
390    end_time,
391    OPERATION_COUNT,
392    overhead,
393    0
394  );
395
396  benchmark_timer_initialize();
397    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
398      (void) rtems_io_open( _STUB_major, 0, NULL );
399  end_time = benchmark_timer_read();
400
401  put_time(
402    "rtems_io_open: only case",
403    end_time,
404    OPERATION_COUNT,
405    overhead,
406    0
407  );
408
409  benchmark_timer_initialize();
410    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
411      (void) rtems_io_close( _STUB_major, 0, NULL );
412  end_time = benchmark_timer_read();
413
414  put_time(
415    "rtems_io_close: only case",
416    end_time,
417    OPERATION_COUNT,
418    overhead,
419    0
420  );
421
422  benchmark_timer_initialize();
423    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
424      (void) rtems_io_read( _STUB_major, 0, NULL );
425  end_time = benchmark_timer_read();
426
427  put_time(
428    "rtems_io_read: only case",
429    end_time,
430    OPERATION_COUNT,
431    overhead,
432    0
433  );
434
435  benchmark_timer_initialize();
436    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
437      (void) rtems_io_write( _STUB_major, 0, NULL );
438  end_time = benchmark_timer_read();
439
440  put_time(
441    "rtems_io_write: only case",
442    end_time,
443    OPERATION_COUNT,
444    overhead,
445    0
446  );
447
448  benchmark_timer_initialize();
449    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
450      (void) rtems_io_control( _STUB_major, 0, NULL );
451  end_time = benchmark_timer_read();
452
453  put_time(
454    "rtems_io_control: only case",
455    end_time,
456    OPERATION_COUNT,
457    overhead,
458    0
459  );
460
461  TEST_END();
462  rtems_test_exit( 0 );
463}
464
465rtems_task Task_2(
466  rtems_task_argument argument
467)
468{
469  end_time = benchmark_timer_read();
470
471  put_time(
472    "rtems_region_get_segment: not available caller blocks",
473    end_time,
474    1,
475    0,
476    0
477  );
478
479  benchmark_timer_initialize();
480    (void) rtems_region_return_segment( Region_id, Buffer_address_1 );
481
482  /* preempt back to Task_1 */
483
484  benchmark_timer_initialize();
485    (void) rtems_region_return_segment( Region_id, Buffer_address_1 );
486  end_time = benchmark_timer_read();
487
488  put_time(
489    "rtems_region_return_segment: task readied returns to caller",
490    end_time,
491    1,
492    0,
493    0
494  );
495
496  rtems_task_exit();
497}
Note: See TracBrowser for help on using the repository browser.