OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [tmtests/] [tm20/] [task1.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *
3
 *  COPYRIGHT (c) 1989-1999.
4
 *  On-Line Applications Research Corporation (OAR).
5
 *
6
 *  The license and distribution terms for this file may be
7
 *  found in the file LICENSE in this distribution or at
8
 *  http://www.OARcorp.com/rtems/license.html.
9
 *
10
 *  task1.c,v 1.13 2002/08/02 00:52:36 joel Exp
11
 */
12
 
13
#define TEST_INIT
14
#include "system.h"
15
#include <assert.h>
16
 
17
rtems_device_major_number _STUB_major = 1;
18
 
19
rtems_id         Region_id;
20
rtems_name       Region_name;
21
rtems_unsigned8  Region_area[ 2048 ] CPU_STRUCTURE_ALIGNMENT;
22
 
23
#define PARTITION_SIZE         2048
24
#define PARTITION_ELEMENT_SIZE  128
25
#define PARTITION_BUFFER_POINTERS \
26
    ((PARTITION_SIZE / PARTITION_ELEMENT_SIZE) + 2)
27
 
28
rtems_id         Partition_id;
29
rtems_name       Partition_name;
30
rtems_unsigned8  Partition_area[ PARTITION_SIZE ] CPU_STRUCTURE_ALIGNMENT;
31
 
32
void  *Buffer_address_1;
33
void  *Buffer_address_2;
34
void  *Buffer_address_3;
35
void  *Buffer_address_4;
36
 
37
rtems_unsigned32 buffer_count;
38
 
39
void  *Buffer_addresses[ PARTITION_BUFFER_POINTERS ];
40
 
41
rtems_task Task_1(
42
  rtems_task_argument argument
43
);
44
 
45
rtems_task Task_2(
46
  rtems_task_argument argument
47
);
48
 
49
rtems_task Init(
50
  rtems_task_argument argument
51
)
52
{
53
  rtems_status_code status;
54
 
55
  Print_Warning();
56
 
57
  puts( "\n\n*** TIME TEST 20 ***" );
58
 
59
  status = rtems_task_create(
60
    rtems_build_name( 'T', 'I', 'M', '1' ),
61
    128,
62
    RTEMS_MINIMUM_STACK_SIZE,
63
    RTEMS_DEFAULT_MODES,
64
    RTEMS_DEFAULT_ATTRIBUTES,
65
    &Task_id[ 1 ]
66
  );
67
  directive_failed( status, "rtems_task_create of TASK1" );
68
 
69
  status = rtems_task_start( Task_id[ 1 ], Task_1, 0 );
70
  directive_failed( status, "rtems_task_start of TASK1" );
71
 
72
  status = rtems_task_create(
73
    rtems_build_name( 'T', 'I', 'M', '2' ),
74
    129,
75
    RTEMS_MINIMUM_STACK_SIZE,
76
    RTEMS_DEFAULT_MODES,
77
    RTEMS_DEFAULT_ATTRIBUTES,
78
    &Task_id[ 2 ]
79
  );
80
  directive_failed( status, "rtems_task_create of TASK2" );
81
 
82
  status = rtems_task_start( Task_id[ 2 ], Task_2, 0 );
83
  directive_failed( status, "rtems_task_start of TASK2" );
84
 
85
  status = rtems_task_delete( RTEMS_SELF );
86
  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
87
}
88
 
89
rtems_task Task_1(
90
  rtems_task_argument argument
91
)
92
{
93
  rtems_unsigned32    index;
94
  rtems_mode          previous_mode;
95
  rtems_task_priority previous_priority;
96
  rtems_status_code   status;
97
 
98
  Partition_name = rtems_build_name( 'P', 'A', 'R', 'T' );
99
 
100
  Timer_initialize();
101
    rtems_partition_create(
102
      Partition_name,
103
      Partition_area,
104
      PARTITION_SIZE,
105
      128,
106
      RTEMS_DEFAULT_ATTRIBUTES,
107
      &Partition_id
108
    );
109
  end_time = Read_timer();
110
 
111
  put_time(
112
    "rtems_partition_create",
113
    end_time,
114
    1,
115
    0,
116
    CALLING_OVERHEAD_PARTITION_CREATE
117
  );
118
 
119
  Region_name = rtems_build_name( 'R', 'E', 'G', 'N' );
120
 
121
  Timer_initialize();
122
    rtems_region_create(
123
      Region_name,
124
      Region_area,
125
      2048,
126
      16,
127
      RTEMS_DEFAULT_ATTRIBUTES,
128
      &Region_id
129
    );
130
  end_time = Read_timer();
131
 
132
  put_time(
133
    "rtems_region_create",
134
    end_time,
135
    1,
136
    0,
137
    CALLING_OVERHEAD_REGION_CREATE
138
  );
139
 
140
  Timer_initialize();
141
    (void) rtems_partition_get_buffer( Partition_id, &Buffer_address_1 );
142
  end_time = Read_timer();
143
 
144
  put_time(
145
    "rtems_partition_get_buffer: available",
146
    end_time,
147
    1,
148
    0,
149
    CALLING_OVERHEAD_PARTITION_GET_BUFFER
150
  );
151
 
152
  buffer_count = 0;
153
  while ( FOREVER ) {
154
 
155
    status = rtems_partition_get_buffer(
156
               Partition_id,
157
               &Buffer_addresses[ buffer_count ]
158
            );
159
 
160
    if ( status == RTEMS_UNSATISFIED ) break;
161
 
162
    buffer_count++;
163
 
164
    assert( buffer_count < PARTITION_BUFFER_POINTERS );
165
  }
166
 
167
  Timer_initialize();
168
    (void) rtems_partition_get_buffer( Partition_id, &Buffer_address_2 );
169
  end_time = Read_timer();
170
 
171
  put_time(
172
    "rtems_partition_get_buffer: not available",
173
    end_time,
174
    1,
175
    0,
176
    CALLING_OVERHEAD_PARTITION_GET_BUFFER
177
  );
178
 
179
  Timer_initialize();
180
    (void) rtems_partition_return_buffer( Partition_id, Buffer_address_1 );
181
  end_time = Read_timer();
182
 
183
  put_time(
184
    "rtems_partition_return_buffer",
185
    end_time,
186
    1,
187
    0,
188
    CALLING_OVERHEAD_PARTITION_RETURN_BUFFER
189
  );
190
 
191
  for ( index = 0 ; index < buffer_count ; index++ ) {
192
 
193
    status = rtems_partition_return_buffer(
194
               Partition_id,
195
               Buffer_addresses[ index ]
196
             );
197
    directive_failed( status, "rtems_partition_return_buffer" );
198
 
199
  }
200
 
201
  Timer_initialize();
202
    (void) rtems_partition_delete( Partition_id );
203
  end_time = Read_timer();
204
 
205
  put_time(
206
    "rtems_partition_delete",
207
    end_time,
208
    1,
209
    0,
210
    CALLING_OVERHEAD_PARTITION_DELETE
211
  );
212
 
213
  status = rtems_region_get_segment(
214
             Region_id,
215
             400,
216
             RTEMS_DEFAULT_OPTIONS,
217
             RTEMS_NO_TIMEOUT,
218
             &Buffer_address_2
219
           );
220
  directive_failed( status, "region_get_segment" );
221
 
222
  Timer_initialize();
223
    (void) rtems_region_get_segment(
224
      Region_id,
225
      400,
226
      RTEMS_DEFAULT_OPTIONS,
227
      RTEMS_NO_TIMEOUT,
228
      &Buffer_address_3
229
    );
230
  end_time = Read_timer();
231
 
232
  put_time(
233
    "rtems_region_get_segment: available",
234
    end_time,
235
    1,
236
    0,
237
    CALLING_OVERHEAD_REGION_GET_SEGMENT
238
  );
239
 
240
  Timer_initialize();
241
    (void) rtems_region_get_segment(
242
      Region_id,
243
      1998,
244
      RTEMS_NO_WAIT,
245
      RTEMS_NO_TIMEOUT,
246
      &Buffer_address_4
247
    );
248
  end_time = Read_timer();
249
 
250
  put_time(
251
    "rtems_region_get_segment: not available -- NO_WAIT",
252
    end_time,
253
    1,
254
    0,
255
    CALLING_OVERHEAD_REGION_GET_SEGMENT
256
  );
257
 
258
  status = rtems_region_return_segment( Region_id, Buffer_address_3 );
259
  directive_failed( status, "rtems_region_return_segment" );
260
 
261
  Timer_initialize();
262
    (void) rtems_region_return_segment( Region_id, Buffer_address_2 );
263
  end_time = Read_timer();
264
 
265
  put_time(
266
    "rtems_region_return_segment: no waiting tasks",
267
    end_time,
268
    1,
269
    0,
270
    CALLING_OVERHEAD_REGION_RETURN_SEGMENT
271
  );
272
 
273
  status = rtems_region_get_segment(
274
    Region_id,
275
    400,
276
    RTEMS_DEFAULT_OPTIONS,
277
    RTEMS_NO_TIMEOUT,
278
    &Buffer_address_1
279
  );
280
  directive_failed( status, "rtems_region_get_segment" );
281
 
282
  Timer_initialize();
283
    (void) rtems_region_get_segment(
284
      Region_id,
285
      1998,
286
      RTEMS_DEFAULT_OPTIONS,
287
      RTEMS_NO_TIMEOUT,
288
      &Buffer_address_2
289
    );
290
 
291
  /* execute Task_2 */
292
 
293
  end_time = Read_timer();
294
 
295
  put_time(
296
    "rtems_region_return_segment: task readied -- preempts caller",
297
    end_time,
298
    1,
299
    0,
300
    CALLING_OVERHEAD_REGION_RETURN_SEGMENT
301
  );
302
 
303
  status = rtems_region_return_segment( Region_id, Buffer_address_2 );
304
  directive_failed( status, "rtems_region_return_segment" );
305
 
306
  status = rtems_task_mode(
307
    RTEMS_NO_PREEMPT,
308
    RTEMS_PREEMPT_MASK,
309
    &previous_mode
310
  );
311
  directive_failed( status, "rtems_task_mode" );
312
 
313
  status = rtems_task_set_priority( RTEMS_SELF, 254, &previous_priority );
314
  directive_failed( status, "rtems_task_set_priority" );
315
 
316
  status = rtems_region_get_segment(
317
    Region_id,
318
    400,
319
    RTEMS_DEFAULT_OPTIONS,
320
    RTEMS_NO_TIMEOUT,
321
    &Buffer_address_1
322
  );
323
  directive_failed( status, "rtems_region_return_segment" );
324
 
325
  status = rtems_region_get_segment(
326
    Region_id,
327
    1998,
328
    RTEMS_DEFAULT_OPTIONS,
329
    RTEMS_NO_TIMEOUT,
330
    &Buffer_address_2
331
  );
332
  directive_failed( status, "rtems_region_get_segment" );
333
 
334
  /* execute Task_2 */
335
 
336
  status = rtems_region_return_segment( Region_id, Buffer_address_2 );
337
  directive_failed( status, "rtems_region_return_segment" );
338
 
339
  Timer_initialize();
340
    (void) rtems_region_delete( Region_id );
341
  end_time = Read_timer();
342
 
343
  put_time(
344
    "rtems_region_delete",
345
    end_time,
346
    1,
347
    0,
348
    CALLING_OVERHEAD_REGION_DELETE
349
  );
350
 
351
  Timer_initialize();
352
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
353
      (void) Empty_function();
354
  overhead = Read_timer();
355
 
356
  Timer_initialize();
357
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
358
      (void) rtems_io_initialize( _STUB_major, 0, NULL );
359
  end_time = Read_timer();
360
 
361
  put_time(
362
    "rtems_io_initialize",
363
    end_time,
364
    OPERATION_COUNT,
365
    overhead,
366
    CALLING_OVERHEAD_IO_INITIALIZE
367
  );
368
 
369
  Timer_initialize();
370
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
371
      (void) rtems_io_open( _STUB_major, 0, NULL );
372
  end_time = Read_timer();
373
 
374
  put_time(
375
    "rtems_io_open",
376
    end_time,
377
    OPERATION_COUNT,
378
    overhead,
379
    CALLING_OVERHEAD_IO_OPEN
380
  );
381
 
382
  Timer_initialize();
383
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
384
      (void) rtems_io_close( _STUB_major, 0, NULL );
385
  end_time = Read_timer();
386
 
387
  put_time(
388
    "rtems_io_close",
389
    end_time,
390
    OPERATION_COUNT,
391
    overhead,
392
    CALLING_OVERHEAD_IO_CLOSE
393
  );
394
 
395
  Timer_initialize();
396
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
397
      (void) rtems_io_read( _STUB_major, 0, NULL );
398
  end_time = Read_timer();
399
 
400
  put_time(
401
    "rtems_io_read",
402
    end_time,
403
    OPERATION_COUNT,
404
    overhead,
405
    CALLING_OVERHEAD_IO_READ
406
  );
407
 
408
  Timer_initialize();
409
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
410
      (void) rtems_io_write( _STUB_major, 0, NULL );
411
  end_time = Read_timer();
412
 
413
  put_time(
414
    "rtems_io_write",
415
    end_time,
416
    OPERATION_COUNT,
417
    overhead,
418
    CALLING_OVERHEAD_IO_WRITE
419
  );
420
 
421
  Timer_initialize();
422
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
423
      (void) rtems_io_control( _STUB_major, 0, NULL );
424
  end_time = Read_timer();
425
 
426
  put_time(
427
    "rtems_io_control",
428
    end_time,
429
    OPERATION_COUNT,
430
    overhead,
431
    CALLING_OVERHEAD_IO_CONTROL
432
  );
433
 
434
  puts( "*** END OF TEST 20 ***" );
435
  rtems_test_exit( 0 );
436
}
437
 
438
rtems_task Task_2(
439
  rtems_task_argument argument
440
)
441
{
442
  rtems_status_code status;
443
 
444
  end_time = Read_timer();
445
 
446
  put_time(
447
    "rtems_region_get_segment: not available -- caller blocks",
448
    end_time,
449
    1,
450
    0,
451
    CALLING_OVERHEAD_REGION_GET_SEGMENT
452
  );
453
 
454
  Timer_initialize();
455
    (void) rtems_region_return_segment( Region_id, Buffer_address_1 );
456
 
457
  /* preempt back to Task_1 */
458
 
459
  Timer_initialize();
460
    (void) rtems_region_return_segment( Region_id, Buffer_address_1 );
461
  end_time = Read_timer();
462
 
463
  put_time(
464
    "rtems_region_return_segment: task readied -- returns to caller",
465
    end_time,
466
    1,
467
    0,
468
    CALLING_OVERHEAD_REGION_RETURN_SEGMENT
469
  );
470
 
471
  status = rtems_task_delete( RTEMS_SELF );
472
  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
473
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.