summaryrefslogtreecommitdiffstats
path: root/spec/rtems/signal/req/send.yml
blob: 050c6e8ed08b741f45176d4bfbfa371c971e7982 (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
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
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
enabled-by: true
functional-type: action
links:
- role: interface-function
  uid: ../if/send
post-conditions:
- name: Status
  states:
  - name: Ok
    test-code: |
      T_rsc_success( ctx->status );
    text: |
      The return status of ${../if/send:/name} shall be
      ${../../status/if/successful:/name}.
  - name: InvNum
    test-code: |
      T_rsc( ctx->status, RTEMS_INVALID_NUMBER );
    text: |
      The return status of ${../if/send:/name} shall be
      ${../../status/if/invalid-number:/name}.
  - name: InvId
    test-code: |
      T_rsc( ctx->status, RTEMS_INVALID_ID );
    text: |
      The return status of ${../if/send:/name} shall be
      ${../../status/if/invalid-id:/name}.
  - name: NotDef
    test-code: |
      T_rsc( ctx->status, RTEMS_NOT_DEFINED );
    text: |
      The return status of ${../if/send:/name} shall be
      ${../../status/if/not-defined:/name}.
  test-epilogue: null
  test-prologue: null
- name: Handler
  states:
  - name: NoCall
    test-code: |
      T_eq_sz( ctx->calls_after_send, ctx->nested );
      T_eq_sz( ctx->calls_after_dispatch, ctx->nested );
      T_eq_sz( ctx->calls_after_enable, ctx->nested );
    text: |
      While the ASR processing is disabled, the ASR handler shall not be
      called.
  - name: DuringSend
    test-code: |
      ++expected_calls;
      T_eq_sz( ctx->calls_after_send, ctx->nested + 1 );
      T_eq_sz( ctx->calls_after_dispatch, ctx->nested + 1 );
      T_eq_sz( ctx->calls_after_enable, ctx->nested + 1 );
    text: |
      The ASR handler shall be called during the ${../if/send:/name} call.
  - name: AfterDispatch
    test-code: |
      ++expected_calls;
      T_eq_sz( ctx->calls_after_send, ctx->nested );
      T_eq_sz( ctx->calls_after_dispatch, ctx->nested + 1 );
      T_eq_sz( ctx->calls_after_enable, ctx->nested + 1 );
    text: |
      When the next thread dispatch of the target task of the
      ${../if/send:/name} call takes place, the ASR handler shall be called.
  - name: AfterEnable
    test-code: |
      ++expected_calls;
      T_eq_sz( ctx->calls_after_send, ctx->nested );
      T_eq_sz( ctx->calls_after_dispatch, ctx->nested );
      T_eq_sz( ctx->calls_after_enable, ctx->nested + 1 );
    text: |
      When the target task of the ${../if/send:/name} call re-enables ASR
      processing, the ASR handler shall be called.
  test-epilogue: |
    T_eq_sz( ctx->handler_calls, expected_calls );

    if ( ctx->nested != 0 ) {
      T_eq_u32( ctx->processed_signal_sets[ 0 ], 0x600df00d );
    }

    if ( expected_calls > ctx->nested ) {
      T_eq_u32( ctx->processed_signal_sets[ ctx->nested ], 0xdeadbeef );
    }
  test-prologue: |
    size_t expected_calls;

    expected_calls = ctx->nested;
- name: Recursive
  states:
  - name: 'Yes'
    test-code: |
      T_eq_sz( ctx->handler_calls, 2 );
      T_ne_uptr( ctx->stack_pointers[ 0 ], 0 );
      T_ne_uptr( ctx->stack_pointers[ 1 ], 0 );
      T_ne_uptr( ctx->stack_pointers[ 0 ], ctx->stack_pointers[ 1 ] );
    text: |
      The ASR handler shall be called recursively.
  - name: 'No'
    test-code: |
      if ( ctx->handler_calls == 2 ) {
        T_ne_uptr( ctx->stack_pointers[ 0 ], 0 );
        T_ne_uptr( ctx->stack_pointers[ 1 ], 0 );
        T_eq_uptr( ctx->stack_pointers[ 0 ], ctx->stack_pointers[ 1 ] );
      }
    text: |
      The ASR handler shall not be called recursively.
  test-epilogue: null
  test-prologue: null
pre-conditions:
- name: Task
  states:
  - name: NoObj
    test-code: |
      ctx->id = 0xffffffff;
    text: |
      While the ${../if/send:/params[0]/name} parameter is not associated with
      a task.
  - name: Self
    test-code: |
      ctx->id = RTEMS_SELF;
    text: |
      While the ${../if/send:/params[0]/name} parameter is associated with
      the calling task.
  - name: Other
    test-code: |
      ctx->id = ctx->worker_id;
    text: |
      While the ${../if/send:/params[0]/name} parameter is associated with a
      task other than the calling task.
  test-epilogue: null
  test-prologue: null
- name: Set
  states:
  - name: Zero
    test-code: |
      ctx->signal_set = 0;
    text: |
      While the ${../if/send:/params[1]/name} parameter is zero.
  - name: NonZero
    test-code: |
      ctx->signal_set = 0xdeadbeef;
    text: |
      While the ${../if/send:/params[1]/name} parameter is non-zero.
  test-epilogue: null
  test-prologue: null
- name: Handler
  states:
  - name: Invalid
    test-code: |
      ctx->handler = NULL;
    text: |
      While the target task has no valid ASR handler installed.
  - name: Valid
    test-code: |
      ctx->handler = SignalHandler;
    text: |
      While the target task has a valid ASR handler installed.
  test-epilogue: null
  test-prologue: null
- name: ASR
  states:
  - name: Enabled
    test-code: |
      ctx->mode = RTEMS_DEFAULT_MODES;
    text: |
      While the target task has ASR processing enabled.
  - name: Disabled
    test-code: |
      ctx->mode = RTEMS_NO_ASR;
    text: |
      While the target task has ASR processing disabled.
  test-epilogue: null
  test-prologue: null
- name: Nested
  states:
  - name: 'Yes'
    test-code: |
      ctx->nested = 1;
    text: |
      While the target task processes an asynchronous signal.
  - name: 'No'
    test-code: |
      ctx->nested = 0;
    text: |
      While the target task does not process an asynchronous signal.
  test-epilogue: null
  test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons: {}
test-action: |
  rtems_status_code sc;

  if ( ctx->id == ctx->worker_id ) {
    SendEventsToWorker( ctx, EVENT_START );

    ctx->status = rtems_signal_send( ctx->id, ctx->signal_set );
    ctx->calls_after_send = ctx->handler_calls;

    SendEventsToWorker( ctx, EVENT_SEND_DONE );
    ctx->calls_after_dispatch = ctx->handler_calls;
    SendEventsToWorker( ctx, EVENT_DO_ENABLE );
    ctx->calls_after_enable = ctx->handler_calls;
    SendEventsToWorker( ctx, EVENT_END );
  } else if ( ctx->nested != 0 ) {
    sc = rtems_signal_catch( SignalHandler, ctx->mode );
    T_rsc_success( sc );

    sc = rtems_signal_send( RTEMS_SELF, 0x600df00d );
    T_rsc_success( sc );

    ctx->calls_after_enable = ctx->handler_calls;
  } else {
    rtems_mode mode;

    sc = rtems_task_mode( ctx->mode, RTEMS_ASR_MASK, &mode );
    T_rsc_success( sc );

    sc = rtems_signal_catch( ctx->handler, RTEMS_NO_ASR );
    T_rsc_success( sc );

    ctx->status = rtems_signal_send( ctx->id, ctx->signal_set );
    ctx->calls_after_send = ctx->handler_calls;
    ctx->calls_after_dispatch = ctx->handler_calls;

    sc = rtems_task_mode( mode, RTEMS_ASR_MASK, &mode );
    T_rsc_success( sc );

    ctx->calls_after_enable = ctx->handler_calls;
  }
test-brief: null
test-cleanup: null
test-context:
- brief: null
  description: null
  member: |
    rtems_id runner_id
- brief: null
  description: null
  member: |
    rtems_id worker_id
- brief: null
  description: null
  member: |
    rtems_asr_entry handler
- brief: null
  description: null
  member: |
    size_t nested
- brief: null
  description: null
  member: |
    size_t handler_calls
- brief: null
  description: null
  member: |
    size_t calls_after_send
- brief: null
  description: null
  member: |
    size_t calls_after_dispatch
- brief: null
  description: null
  member: |
    size_t calls_after_enable
- brief: null
  description: null
  member: |
    rtems_signal_set processed_signal_sets[ 2 ]
- brief: null
  description: null
  member: |
    uintptr_t stack_pointers[ 2 ];
- brief: null
  description: null
  member: |
    rtems_mode mode;
- brief: null
  description: null
  member: |
    rtems_status_code status
- brief: null
  description: null
  member: |
    rtems_id id
- brief: null
  description: null
  member: |
    rtems_signal_set signal_set
test-context-support: null
test-description: null
test-header: null
test-includes:
- rtems.h
test-local-includes: []
test-prepare: |
  ctx->handler_calls = 0;
  ctx->calls_after_send = 0;
  ctx->calls_after_dispatch = 0;
  ctx->calls_after_enable = 0;
  memset( &ctx->processed_signal_sets, 0, sizeof( ctx->processed_signal_sets ) );
  memset( &ctx->stack_pointers, 0, sizeof( ctx->stack_pointers ) );
test-setup:
  brief: null
  code: |
    rtems_status_code   sc;
    rtems_task_priority prio;

    memset( ctx, 0, sizeof( *ctx ) );
    ctx->runner_id = rtems_task_self();

    prio = 0;
    sc = rtems_task_set_priority( RTEMS_SELF, PRIO_NORMAL, &prio );
    T_rsc_success( sc );
    T_eq_u32( prio, PRIO_HIGH );

    sc = rtems_task_create(
      rtems_build_name( 'W', 'O', 'R', 'K' ),
      PRIO_HIGH,
      RTEMS_MINIMUM_STACK_SIZE,
      RTEMS_DEFAULT_MODES,
      RTEMS_DEFAULT_ATTRIBUTES,
      &ctx->worker_id
    );
    T_assert_rsc_success( sc );

    #if defined(RTEMS_SMP)
    if ( rtems_scheduler_get_processor_maximum() > 1 ) {
      rtems_id scheduler_id;

      sc = rtems_scheduler_ident_by_processor( 1, &scheduler_id );
      T_assert_rsc_success( sc );

      sc = rtems_task_set_scheduler( ctx->worker_id, scheduler_id, PRIO_HIGH );
      T_assert_rsc_success( sc );
    }
    #endif

    sc = rtems_task_start( ctx->worker_id, Worker, (rtems_task_argument) ctx );
    T_assert_rsc_success( sc );
  description: null
test-stop: null
test-support: |
  #define EVENT_START RTEMS_EVENT_0

  #define EVENT_SEND_DONE RTEMS_EVENT_1

  #define EVENT_DO_ENABLE RTEMS_EVENT_2

  #define EVENT_END RTEMS_EVENT_3

  #define EVENT_WORKER_DONE RTEMS_EVENT_4

  typedef RtemsSignalReqSend_Context Context;

  typedef enum {
    PRIO_HIGH = 1,
    PRIO_NORMAL
  } Priorities;

  static rtems_event_set Wait( void )
  {
    rtems_status_code sc;
    rtems_event_set   events;

    events = 0;
    sc = rtems_event_receive(
      RTEMS_ALL_EVENTS,
      RTEMS_EVENT_ANY | RTEMS_WAIT,
      RTEMS_NO_TIMEOUT,
      &events
    );
    T_rsc_success( sc );

    return events;
  }

  static void SendEvents( rtems_id id, rtems_event_set events )
  {
    rtems_status_code sc;

    sc = rtems_event_send( id, events );
    T_rsc_success( sc );
  }

  static void WorkerDone( const Context *ctx )
  {
  #if defined(RTEMS_SMP)
    if ( rtems_scheduler_get_processor_maximum() > 1 ) {
      SendEvents( ctx->runner_id, EVENT_WORKER_DONE );
    }
  #endif
  }

  static void SendEventsToWorker( const Context *ctx, rtems_event_set events )
  {
    SendEvents( ctx->worker_id, events );

  #if defined(RTEMS_SMP)
    if ( rtems_scheduler_get_processor_maximum() > 1 ) {
      events = Wait();
      T_eq_u32( events, EVENT_WORKER_DONE );
    }
  #endif
  }

  static void SignalHandler( rtems_signal_set signal_set )
  {
    Context *ctx;
    size_t   i;
    size_t   n;

    ctx = T_fixture_context();
    i = ctx->handler_calls;
    n = RTEMS_ARRAY_SIZE( ctx->processed_signal_sets );
    ctx->processed_signal_sets[ i % n ] = signal_set;
    ctx->stack_pointers[ i % n ] = (uintptr_t) __builtin_frame_address( 0 );
    T_lt_sz( i, n );
    ctx->handler_calls = i + 1;

    if ( ctx->nested != 0 && i == 0 ) {
      rtems_status_code sc;

      if ( ctx->id == ctx->worker_id ) {
        rtems_event_set events;

        sc = rtems_signal_catch( ctx->handler, RTEMS_NO_ASR );
        T_rsc_success( sc );

        WorkerDone( ctx );

        events = Wait();
        T_eq_u32( events, EVENT_SEND_DONE );

        WorkerDone( ctx );

        events = Wait();
        T_eq_u32( events, EVENT_DO_ENABLE );
      } else {
        sc = rtems_signal_catch( ctx->handler, RTEMS_NO_ASR );
        T_rsc_success( sc );

        ctx->status = rtems_signal_send( ctx->id, ctx->signal_set );
        ctx->calls_after_send = ctx->handler_calls;
        ctx->calls_after_dispatch = ctx->handler_calls;
      }
    }
  }

  static void Worker( rtems_task_argument arg )
  {
    Context *ctx;

    ctx = (Context *) arg;

    while ( true ) {
      rtems_status_code sc;
      rtems_event_set   events;

      events = Wait();
      T_eq_u32( events, EVENT_START );

      if ( ctx->nested != 0 ) {
        sc = rtems_signal_catch( SignalHandler, ctx->mode );
        T_rsc_success( sc );

        sc = rtems_signal_send( RTEMS_SELF, 0x600df00d );
        T_rsc_success( sc );

        WorkerDone( ctx );
      } else {
        rtems_mode mode;

        sc = rtems_task_mode( ctx->mode, RTEMS_ASR_MASK, &mode );
        T_rsc_success( sc );

        sc = rtems_signal_catch( ctx->handler, RTEMS_NO_ASR );
        T_rsc_success( sc );

        WorkerDone( ctx );

        events = Wait();
        T_eq_u32( events, EVENT_SEND_DONE );

        WorkerDone( ctx );

        events = Wait();
        T_eq_u32( events, EVENT_DO_ENABLE );

        sc = rtems_task_mode( mode, RTEMS_ASR_MASK, &mode );
        T_rsc_success( sc );

        WorkerDone( ctx );
      }

      events = Wait();
      T_eq_u32( events, EVENT_END );

      WorkerDone( ctx );
    }
  }
test-target: testsuites/validation/tc-signal-send.c
test-teardown:
  brief: null
  code: |
    rtems_status_code   sc;
    rtems_task_priority prio;

    prio = 0;
    sc = rtems_task_set_priority( RTEMS_SELF, PRIO_HIGH, &prio );
    T_rsc_success( sc );
    T_eq_u32( prio, PRIO_NORMAL );

    if ( ctx->worker_id != 0 ) {
      sc = rtems_task_delete( ctx->worker_id );
      T_rsc_success( sc );
    }
  description: null
text: ${.:text-template}
transition-map:
- enabled-by: true
  post-conditions:
    Status: InvNum
    Handler: NoCall
    Recursive: 'No'
  pre-conditions:
    Task: all
    Set:
    - Zero
    Handler: all
    ASR: all
    Nested: all
- enabled-by: true
  post-conditions:
    Status: InvId
    Handler: NoCall
    Recursive: 'No'
  pre-conditions:
    Task:
    - NoObj
    Set:
    - NonZero
    Handler: all
    ASR: all
    Nested: all
- enabled-by: true
  post-conditions:
    Status: NotDef
    Handler: NoCall
    Recursive: 'No'
  pre-conditions:
    Task:
    - Self
    - Other
    Set:
    - NonZero
    Handler:
    - Invalid
    ASR: all
    Nested: all
- enabled-by: true
  post-conditions:
    Status: Ok
    Handler: AfterEnable
    Recursive: 'No'
  pre-conditions:
    Task:
    - Self
    - Other
    Set:
    - NonZero
    Handler:
    - Valid
    ASR:
    - Disabled
    Nested: all
- enabled-by: true
  post-conditions:
    Status: Ok
    Handler: DuringSend
    Recursive: 'No'
  pre-conditions:
    Task:
    - Self
    Set:
    - NonZero
    Handler:
    - Valid
    ASR:
    - Enabled
    Nested:
    - 'No'
- enabled-by: true
  post-conditions:
    Status: Ok
    Handler: AfterDispatch
    Recursive: 'No'
  pre-conditions:
    Task:
    - Other
    Set:
    - NonZero
    Handler:
    - Valid
    ASR:
    - Enabled
    Nested:
    - 'No'
- enabled-by: true
  post-conditions:
    Status: Ok
    Handler: DuringSend
    Recursive: 'Yes'
  pre-conditions:
    Task:
    - Self
    Set:
    - NonZero
    Handler:
    - Valid
    ASR:
    - Enabled
    Nested:
    - 'Yes'
- enabled-by: true
  post-conditions:
    Status: Ok
    Handler: AfterDispatch
    Recursive: 'Yes'
  pre-conditions:
    Task:
    - Other
    Set:
    - NonZero
    Handler:
    - Valid
    ASR:
    - Enabled
    Nested:
    - 'Yes'
type: requirement