summaryrefslogtreecommitdiffstats
path: root/testsuites/tmtests/tm09/task1.c
blob: 3d8ab1986d5440930a1c6b5f30dbdea53784655b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
 *  COPYRIGHT (c) 1989-2013.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#define TEST_INIT

#define CONFIGURE_INIT
#include "system.h"

const char rtems_test_name[] = "TIME TEST 9";

rtems_id Queue_id;

rtems_task Test_task(
  rtems_task_argument argument
);
void queue_test(void);

rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code status;

  Print_Warning();

  TEST_BEGIN();

  status = rtems_task_create(
    1,
    (RTEMS_MAXIMUM_PRIORITY / 2u) + 1u,
    RTEMS_MINIMUM_STACK_SIZE * 2,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &Task_id[ 1 ]
  );
  directive_failed( status, "rtems_task_create" );

  status = rtems_task_start( Task_id[ 1 ], Test_task, 0 );
  directive_failed( status, "rtems_task_start" );

  status = rtems_task_delete( RTEMS_SELF );
  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
}

rtems_task Test_task (
  rtems_task_argument argument
)
{
  benchmark_timer_initialize();
    rtems_message_queue_create(
      1,
      OPERATION_COUNT,
      MESSAGE_SIZE,
      RTEMS_DEFAULT_ATTRIBUTES,
      &Queue_id
    );
  end_time = benchmark_timer_read();

  put_time(
    "rtems_message_queue_create: only case",
    end_time,
    1,
    0,
    CALLING_OVERHEAD_MESSAGE_QUEUE_CREATE
  );

  queue_test();

  benchmark_timer_initialize();
    rtems_message_queue_delete( Queue_id );
  end_time = benchmark_timer_read();

  put_time(
    "rtems_message_queue_delete: only case",
    end_time,
    1,
    0,
    CALLING_OVERHEAD_MESSAGE_QUEUE_DELETE
  );

  TEST_END();
  rtems_test_exit( 0 );
}

void queue_test(void)
{
  uint32_t    send_loop_time;
  uint32_t    urgent_loop_time;
  uint32_t    receive_loop_time;
  uint32_t    send_time;
  uint32_t    urgent_time;
  uint32_t    receive_time;
  uint32_t    empty_flush_time;
  uint32_t    flush_time;
  uint32_t    empty_flush_count;
  uint32_t    flush_count;
  uint32_t    index;
  uint32_t    iterations;
  long        buffer[4];
  rtems_status_code status;
  size_t      size;

  send_loop_time    = 0;
  urgent_loop_time  = 0;
  receive_loop_time = 0;
  send_time         = 0;
  urgent_time       = 0;
  receive_time      = 0;
  empty_flush_time  = 0;
  flush_time        = 0;
  flush_count       = 0;
  empty_flush_count = 0;

  for ( iterations = 1 ; iterations <= OPERATION_COUNT ; iterations++ ) {

    benchmark_timer_initialize();
      for ( index=1 ; index <= OPERATION_COUNT ; index++ )
        (void) benchmark_timer_empty_function();
    send_loop_time += benchmark_timer_read();

    benchmark_timer_initialize();
      for ( index=1 ; index <= OPERATION_COUNT ; index++ )
        (void) benchmark_timer_empty_function();
    urgent_loop_time += benchmark_timer_read();

    benchmark_timer_initialize();
      for ( index=1 ; index <= OPERATION_COUNT ; index++ )
        (void) benchmark_timer_empty_function();
    receive_loop_time += benchmark_timer_read();

    benchmark_timer_initialize();
      for ( index=1 ; index <= OPERATION_COUNT ; index++ )
        (void) rtems_message_queue_send( Queue_id, buffer, MESSAGE_SIZE );
    send_time += benchmark_timer_read();

    benchmark_timer_initialize();
      for ( index=1 ; index <= OPERATION_COUNT ; index++ )
        (void) rtems_message_queue_receive(
                 Queue_id,
                 (long (*)[4])buffer,
                 &size,
                 RTEMS_DEFAULT_OPTIONS,
                 RTEMS_NO_TIMEOUT
               );
    receive_time += benchmark_timer_read();

    benchmark_timer_initialize();
      for ( index=1 ; index <= OPERATION_COUNT ; index++ )
        (void) rtems_message_queue_urgent( Queue_id, buffer, MESSAGE_SIZE );
    urgent_time += benchmark_timer_read();

    benchmark_timer_initialize();
      for ( index=1 ; index <= OPERATION_COUNT ; index++ )
        (void) rtems_message_queue_receive(
                 Queue_id,
                 (long (*)[4])buffer,
                 &size,
                 RTEMS_DEFAULT_OPTIONS,
                 RTEMS_NO_TIMEOUT
               );
    receive_time += benchmark_timer_read();

    benchmark_timer_initialize();
      rtems_message_queue_flush( Queue_id, &empty_flush_count );
    empty_flush_time += benchmark_timer_read();

    /* send one message to flush */
    status = rtems_message_queue_send(
       Queue_id,
       (long (*)[4])buffer,
       MESSAGE_SIZE
    );
    directive_failed( status, "rtems_message_queue_send" );

    benchmark_timer_initialize();
      rtems_message_queue_flush( Queue_id, &flush_count );
    flush_time += benchmark_timer_read();
  }

  put_time(
    "rtems_message_queue_send: no waiting tasks",
    send_time,
    OPERATION_COUNT * OPERATION_COUNT,
    send_loop_time,
    CALLING_OVERHEAD_MESSAGE_QUEUE_SEND
  );

  put_time(
    "rtems_message_queue_urgent: no waiting tasks",
    urgent_time,
    OPERATION_COUNT * OPERATION_COUNT,
    urgent_loop_time,
    CALLING_OVERHEAD_MESSAGE_QUEUE_URGENT
  );

  put_time(
    "rtems_message_queue_receive: available",
    receive_time,
    OPERATION_COUNT * OPERATION_COUNT * 2,
    receive_loop_time * 2,
    CALLING_OVERHEAD_MESSAGE_QUEUE_RECEIVE
  );

  put_time(
    "rtems_message_queue_flush: no messages flushed",
    empty_flush_time,
    OPERATION_COUNT,
    0,
    CALLING_OVERHEAD_MESSAGE_QUEUE_FLUSH
  );

  put_time(
    "rtems_message_queue_flush: messages flushed",
    flush_time,
    OPERATION_COUNT,
    0,
    CALLING_OVERHEAD_MESSAGE_QUEUE_FLUSH
  );

}