source: rtems/testsuites/tmtests/tm03/task1.c @ 2ead50a

4.11
Last change on this file since 2ead50a was 2ead50a, checked in by bjorn larsson <bjornlarsson@…>, on Mar 21, 2014 at 3:48:01 PM

tmtests: convert to test.h

  • Property mode set to 100644
File size: 3.3 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 3";
18
19rtems_id Semaphore_id;
20rtems_task test_init(
21  rtems_task_argument argument
22);
23
24rtems_task Middle_tasks(
25  rtems_task_argument argument
26);
27
28rtems_task High_task(
29  rtems_task_argument argument
30);
31
32int operation_count = OPERATION_COUNT;
33
34rtems_task Init(
35  rtems_task_argument argument
36)
37{
38  rtems_status_code status;
39  rtems_id          task_id;
40
41  Print_Warning();
42
43  TEST_BEGIN();
44  status = rtems_task_create(
45    rtems_build_name( 'T', 'A', '1', ' ' ),
46    RTEMS_MAXIMUM_PRIORITY - 1u,
47    RTEMS_MINIMUM_STACK_SIZE,
48    RTEMS_DEFAULT_MODES,
49    RTEMS_DEFAULT_ATTRIBUTES,
50    &task_id
51  );
52  directive_failed( status, "rtems_task_create of test_init" );
53
54  status = rtems_task_start( task_id, test_init, 0 );
55  directive_failed( status, "rtems_task_start of test_init" );
56
57  status = rtems_task_delete( RTEMS_SELF );
58  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
59}
60
61rtems_task test_init(
62  rtems_task_argument argument
63)
64{
65  rtems_status_code   status;
66  int                 index;
67  rtems_id            task_id;
68  rtems_task_priority priority;
69
70  priority = RTEMS_MAXIMUM_PRIORITY - 2u;
71
72  status = rtems_semaphore_create(
73    rtems_build_name( 'S', 'M', '1', '\0'),
74    0,
75    RTEMS_DEFAULT_ATTRIBUTES,
76    RTEMS_NO_PRIORITY,
77    &Semaphore_id
78  );
79  directive_failed( status, "rtems_semaphore_create of SM1" );
80
81  if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u )
82    operation_count =  (int) (RTEMS_MAXIMUM_PRIORITY - 2u);
83  for ( index = 2 ; index < operation_count ; index ++ ) {
84    rtems_task_create(
85      rtems_build_name( 'M', 'I', 'D', ' ' ),
86      priority,
87      RTEMS_MINIMUM_STACK_SIZE,
88      RTEMS_DEFAULT_MODES,
89      RTEMS_DEFAULT_ATTRIBUTES,
90      &task_id
91    );
92    directive_failed( status, "rtems_task_create middle" );
93
94    priority--;
95
96    rtems_task_start( task_id, Middle_tasks, 0 );
97    directive_failed( status, "rtems_task_start middle" );
98  }
99
100  status = rtems_task_create(
101    rtems_build_name( 'H', 'I', 'G', 'H' ),
102    priority,
103    RTEMS_MINIMUM_STACK_SIZE,
104    RTEMS_DEFAULT_MODES,
105    RTEMS_DEFAULT_ATTRIBUTES,
106    &task_id
107  );
108  directive_failed( status, "rtems_task_create of high task" );
109
110  status = rtems_task_start( task_id, High_task, 0 );
111  directive_failed( status, "rtems_task_start of high task" );
112
113  benchmark_timer_initialize();                          /* start the timer */
114  status = rtems_semaphore_release( Semaphore_id );
115}
116
117rtems_task Middle_tasks(
118  rtems_task_argument argument
119)
120{
121  (void) rtems_semaphore_obtain(
122    Semaphore_id,
123    RTEMS_DEFAULT_OPTIONS,
124    RTEMS_NO_TIMEOUT
125  );
126
127  (void) rtems_semaphore_release( Semaphore_id );
128}
129
130rtems_task High_task(
131  rtems_task_argument argument
132)
133{
134  (void) rtems_semaphore_obtain(
135    Semaphore_id,
136    RTEMS_DEFAULT_OPTIONS,
137    RTEMS_NO_TIMEOUT
138  );
139
140  end_time = benchmark_timer_read();
141
142  put_time(
143    "rtems_semaphore_release: task readied preempts caller",
144    end_time,
145    operation_count - 1,
146    0,
147    CALLING_OVERHEAD_SEMAPHORE_RELEASE
148  );
149
150  TEST_END();
151  rtems_test_exit( 0 );
152}
Note: See TracBrowser for help on using the repository browser.