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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
|
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2021 embedded brains GmbH & Co. KG
enabled-by: true
functional-type: action
links:
- role: interface-function
uid: ../if/flush
- role: interface-function
uid: ../if/get-number-pending
post-conditions:
- name: Status
states:
- name: Ok
test-code: |
T_rsc_success( ctx->status );
text: |
The return status of the called directive (${../if/flush:/name} or
${../if/get-number-pending:/name}) shall be
${../../status/if/successful:/name}
- name: InvId
test-code: |
T_rsc( ctx->status, RTEMS_INVALID_ID );
text: |
The return status of the called directive (${../if/flush:/name} or
${../if/get-number-pending:/name}) shall be
${../../status/if/invalid-id:/name}.
- name: InvAddr
test-code: |
T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
text: |
The return status of the called directive (${../if/flush:/name} or
${../if/get-number-pending:/name}) shall be
${../../status/if/invalid-address:/name}.
test-epilogue: null
test-prologue: null
- name: Count
states:
- name: Zero
test-code: |
T_eq_u32( ctx->count, 0 );
text: |
The value of the object referenced by the
${../if/flush:/params[1]/name} parameter shall be 0 after
the return of the ${../if/flush:/name} or
${../if/get-number-pending:/name} call.
- name: Set
test-code: |
T_eq_u32( ctx->count, NUMBER_OF_PENDING_MESSAGES );
text: |
The ${../if/get-number-pending:/name} directive shall set
the value of the object referenced by the
${../if/get-number-pending:/params[1]/name} parameter to the number
of messages present in the ${/glossary/messagequeue:/term}
at a point in time during the single execution of the
${../if/get-number-pending:/name} directive.
The ${../if/flush:/name} directive shall set
the value of the object referenced by the
${../if/flush:/params[1]/name} parameter to the number
of messages it removed from the ${/glossary/messagequeue:/term}
during the single execution of the ${../if/flush:/name} directive.
- name: Nop
test-code: |
T_eq_u32( ctx->count, UINT8_MAX );
text: |
The value of the object referenced by the
${../if/flush:/params[1]/name} parameter in past call
to ${../if/flush:/name} or ${../if/get-number-pending:/name}
shall not be accessed by the ${../if/flush:/name} or
${../if/get-number-pending:/name} call
(see also ${../glossary/nop:/term}).
test-epilogue: null
test-prologue: null
- name: MsgQueue
states:
- name: Empty
test-code: |
PopMessage( ctx, CheckForNoMessage );
text: |
The ${/glossary/messagequeue:/term} shall contain no messages
after the last call to ${../if/flush:/params[0]/name}.
- name: Nop
test-code: |
ctx->check_msgq_unchanged( ctx );
text: |
Objects referenced by the ${../if/flush:/params[0]/name}
parameter in the past call to ${../if/flush:/name} or
${../if/get-number-pending:/name} shall not be
changed by that call (see also ${../glossary/nop:/term}).
test-epilogue: null
test-prologue: null
- name: Receivers
states:
- name: Nop
test-code: |
size_t i;
for ( i = 0; i < NUMBER_OF_WORKERS; ++i ) {
T_rsc( ctx->receive_status[i], RTEMS_TIMEOUT );
}
text: |
The ${../glossary/receiver:/plural} waiting for
a message at the ${/glossary/messagequeue:/term} shall not be affected
by the call to the ${../if/flush:/name} or
${../if/get-number-pending:/name} directive.
test-epilogue: null
test-prologue: null
pre-conditions:
- name: Count
states:
- name: Valid
test-code: |
ctx->count_param = &ctx->count;
text: |
While the ${../if/flush:/params[1]/name} parameter references
an ``uint32_t`` object.
- name: 'Null'
test-code: |
ctx->count_param = NULL;
text: |
While the ${../if/flush:/params[1]/name} parameter is
${/c/if/null:/name}.
test-epilogue: null
test-prologue: null
- name: Id
states:
- name: Valid
test-code: |
ctx->id_param = ctx->message_queue_id;
text: |
While the ${../if/flush:/params[0]/name} parameter is valid.
- name: Invalid
test-code: |
ctx->id_param = RTEMS_ID_NONE;
text: |
While the ${../if/flush:/params[0]/name} parameter is invalid.
test-epilogue: null
test-prologue: null
- name: MsgQueue
states:
- name: Empty
test-code: |
/* Message queue is already empty. */
ctx->check_msgq_unchanged = CheckForNoMessageInQueue;
text: |
While there is no message in the ${/glossary/messagequeue:/term}.
- name: Several
test-code: |
uint32_t i;
for ( i = 0; i < NUMBER_OF_PENDING_MESSAGES; ++i ) {
SendMsg( ctx );
}
ctx->check_msgq_unchanged = CheckForSeveralMessagesInQueue;
text: |
While there are messages in the ${/glossary/messagequeue:/term}.
test-epilogue: null
test-prologue: null
- name: Receivers
states:
- name: Waiting
test-code: |
size_t i;
for ( i = 0; i < NUMBER_OF_WORKERS; ++i ) {
SendEvents( ctx->worker_id[i], EVENT_RECEIVE );
}
text: |
While one or more ${../glossary/receiver:/plural} are waiting to
receive a message.
- name: None
test-code: |
/* There is already no receiver waiting. */
text: |
While no ${../glossary/receiver:/term} is waiting to receive a message.
test-epilogue: null
test-prologue: null
- name: Directive
states:
- name: Flush
test-code: |
ctx->action = rtems_message_queue_flush;
text: |
While the directive ${../if/flush:/name} is called.
- name: Pending
test-code: |
ctx->action = rtems_message_queue_get_number_pending;
text: |
While the directive ${../if/get-number-pending:/name} is called.
test-epilogue: null
test-prologue: null
- name: Storage
states:
- name: Nop
test-code: |
/* Only a requirement text. */
text: |
While the memory area to which a pointer is provided as member
${../if/config:/definition[3]/default/name} of type
${../if/config:/name} when the ${/glossary/messagequeue:/term} is
constructed by ${../if/construct:/name} is altered only by the
${/glossary/rtems:/term} operating system.
test-epilogue: null
test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons:
NoWait: |
The ${/glossary/messagequeue:/term} must be empty for an
${../glossary/receiver:/term} to wait for a message.
test-action: |
ctx->status = (ctx->action)(
ctx->id_param,
ctx->count_param
);
FinalClockTick();
test-brief: null
test-cleanup: |
T_rsc_success( rtems_message_queue_delete( ctx->message_queue_id ) );
test-context:
- brief: |
This member contains a valid ${/glossary/id:/term} of a
${/glossary/messagequeue:/term}.
description: null
member: |
rtems_id message_queue_id
- brief: |
This member is used as storage area for the
${/glossary/messagequeue:/term}.
description: null
member: |
RTEMS_MESSAGE_QUEUE_BUFFER( MAXIMUM_MESSAGE_SIZE )
storage_area[ MAXIMUM_PENDING_MESSAGES ]
- brief: |
This member contains the returned ${/glossary/statuscode:/plural}
of the receivers.
description: null
member: |
rtems_status_code receive_status[ NUMBER_OF_WORKERS ]
- brief: |
This member specifies the directive to be called as action.
description: |
This is either ${../if/flush:/name} or ${../if/get-number-pending:/name}.
member:
rtems_status_code (*action)( rtems_id id, uint32_t *count )
- brief: |
This member specifies the ${../if/flush:/params[0]/name} parameter
of the action.
description: null
member: |
rtems_id id_param
- brief: |
This member specifies the ${../if/flush:/params[1]/name} parameter
of the action.
description: null
member: |
uint32_t *count_param
- brief: |
This member contains the returned ${/glossary/statuscode:/term}
of the action.
description: null
member: |
rtems_status_code status
- brief: |
This member contains the value returned in parameter
${../if/flush:/params[1]/name} of the action.
description: null
member: |
uint32_t count
- brief: |
This member contains the ${/glossary/task:/term} identifiers of the
worker ${/glossary/task:/plural}.
description: null
member: |
rtems_id worker_id[ NUMBER_OF_WORKERS ]
- brief: |
This member contains a pointer to a function which is executed
to check that the action has not changed the content of the
${/glossary/messagequeue:/term}.
description: null
member: |
void (*check_msgq_unchanged)( void *ctx_in )
test-context-support: |
#define MAXIMUM_PENDING_MESSAGES 3
#define MAXIMUM_MESSAGE_SIZE 5
#define NUMBER_OF_WORKERS 3
test-description: null
test-header: null
test-includes:
- rtems.h
test-local-includes:
- tx-support.h
test-prepare: |
rtems_status_code status;
rtems_message_queue_config config = {
.name = rtems_build_name( 'M', 'S', 'G', 'Q' ),
.maximum_pending_messages = MAXIMUM_PENDING_MESSAGES,
.maximum_message_size = MAXIMUM_MESSAGE_SIZE,
.storage_area = ctx->storage_area,
.storage_size = sizeof( ctx->storage_area ),
.storage_free = NULL,
.attributes = RTEMS_DEFAULT_ATTRIBUTES
};
status = rtems_message_queue_construct(
&config,
&ctx->message_queue_id
);
T_rsc_success( status );
ctx->count = UINT8_MAX;
test-setup:
brief: null
code: |
size_t i;
SetSelfPriority( PRIO_NORMAL );
for ( i = 0; i < NUMBER_OF_WORKERS; ++i ) {
ctx->worker_id[i] = CreateTask( "WORK", PRIO_HIGH );
StartTask( ctx->worker_id[i], WorkerTask, ctx );
}
description: null
test-stop: null
test-support: |
typedef ${.:/test-context-type} Context;
static const uint32_t NUMBER_OF_PENDING_MESSAGES = 2;
static const rtems_interval TIMEOUT_TICKS = 1;
static const rtems_event_set EVENT_RECEIVE = RTEMS_EVENT_17;
static const uint8_t queued_message[] = { 200, 201, 202 };
static void Receive( Context *ctx, size_t worker_index )
{
size_t size;
uint8_t buffer[ MAXIMUM_MESSAGE_SIZE ];
ctx->receive_status[worker_index] = rtems_message_queue_receive(
ctx->message_queue_id,
buffer,
&size,
RTEMS_WAIT,
TIMEOUT_TICKS
);
}
static void WorkerTask( rtems_task_argument argument )
{
static size_t worker_number = 0;
size_t worker_index = worker_number++;
Context *ctx = (Context *) argument;
while ( true ) {
ReceiveAnyEvents();
Receive( ctx, worker_index );
}
}
static void CheckForNoMessage(
Context *ctx,
rtems_status_code status,
uint8_t *message_buffer,
size_t message_size
)
{
(void) ctx;
(void) message_buffer;
(void) message_size;
T_rsc( status, RTEMS_UNSATISFIED );
}
static void CheckForQueuedMessage(
Context *ctx,
rtems_status_code status,
uint8_t *message_buffer,
size_t message_size
)
{
(void) ctx;
T_rsc_success( status );
T_eq_u32( message_size, sizeof( queued_message ) );
T_eq_mem( message_buffer, queued_message, sizeof( queued_message ) );
}
static void PopMessage(
Context *ctx,
void (*check_fn)(
Context *ctx,
rtems_status_code status,
uint8_t *message_buffer,
size_t message_size
)
)
{
rtems_status_code status;
uint8_t message_buffer[ MAXIMUM_MESSAGE_SIZE ];
size_t message_size;
status = rtems_message_queue_receive(
ctx->message_queue_id,
&message_buffer,
&message_size,
RTEMS_LOCAL | RTEMS_NO_WAIT,
RTEMS_NO_TIMEOUT
);
check_fn( ctx, status, message_buffer, message_size );
}
static void CheckForNoMessageInQueue( void *ctx_in )
{
Context *ctx = ctx_in;
PopMessage( ctx, CheckForNoMessage );
}
static void CheckForSeveralMessagesInQueue( void *ctx_in )
{
Context *ctx = ctx_in;
uint32_t i;
for ( i = 0; i < NUMBER_OF_PENDING_MESSAGES; ++i ) {
PopMessage( ctx, CheckForQueuedMessage );
}
PopMessage( ctx, CheckForNoMessage );
}
static void SendMsg( Context *ctx )
{
rtems_status_code status;
status = rtems_message_queue_send(
ctx->message_queue_id,
queued_message,
sizeof( queued_message )
);
T_rsc_success( status );
}
test-target: testsuites/validation/tc-message-flush-pending.c
test-teardown:
brief: null
code: |
size_t i;
for ( i = 0; i < NUMBER_OF_WORKERS; ++i ) {
DeleteTask( ctx->worker_id[i] );
}
RestoreRunnerPriority();
description: null
text: ${.:text-template}
transition-map:
# ---- Ok Case ----
- enabled-by: true
post-conditions:
Status: Ok
Count:
- if:
pre-conditions:
MsgQueue: Several
then: Set
- else: Zero
MsgQueue:
- if:
pre-conditions:
Directive: Flush
then: Empty
- else: Nop
Receivers:
- if:
pre-conditions:
Receivers: Waiting
then: Nop
- else: N/A
pre-conditions:
Count:
- Valid
Id:
- Valid
MsgQueue: all
Receivers: all
Directive: all
Storage: all
# ---- InvAddr: Count ----
- enabled-by: true
post-conditions:
Status: InvAddr
Count: Nop
MsgQueue: Nop
Receivers:
- if:
pre-conditions:
Receivers: Waiting
then: Nop
- else: N/A
pre-conditions:
Count:
- 'Null'
Id: all
MsgQueue: all
Receivers: all
Directive: all
Storage: all
# ---- InvId ----
- enabled-by: true
post-conditions:
Status: InvId
Count: Nop
MsgQueue: Nop
Receivers:
- if:
pre-conditions:
Receivers: Waiting
then: Nop
- else: N/A
RecSize:
- if:
pre-conditions:
Receivers: Waiting
then: Nop
- else: N/A
RecBuffer:
- if:
pre-conditions:
Receivers: Waiting
then: Nop
- else: N/A
pre-conditions:
Count:
- Valid
Id:
- Invalid
MsgQueue: all
Receivers: all
Directive: all
Storage: all
# ---- Impossible Cases ----
- enabled-by: true
post-conditions: NoWait
pre-conditions:
Count: all
Id: all
MsgQueue:
- Several
Receivers:
- Waiting
Directive: all
Storage: all
type: requirement
|