source: rtems/testsuites/validation/tc-signal-send.c @ 54c9630

Last change on this file since 54c9630 was 54c9630, checked in by Sebastian Huber <sebastian.huber@…>, on 03/01/21 at 09:00:26

validation: Add comments to signal tests

  • Property mode set to 100644
File size: 31.2 KB
RevLine 
[3e7d658]1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSTestCaseRtemsSignalReqSend
7 */
8
9/*
10 * Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/*
35 * This file is part of the RTEMS quality process and was automatically
36 * generated.  If you find something that needs to be fixed or
37 * worded better please post a report or patch to an RTEMS mailing list
38 * or raise a bug report:
39 *
40 * https://www.rtems.org/bugs.html
41 *
42 * For information on updating and regenerating please refer to the How-To
43 * section in the Software Requirements Engineering chapter of the
44 * RTEMS Software Engineering manual.  The manual is provided as a part of
45 * a release.  For development sources please refer to the online
46 * documentation at:
47 *
48 * https://docs.rtems.org
49 */
50
51#ifdef HAVE_CONFIG_H
52#include "config.h"
53#endif
54
55#include <rtems.h>
56
57#include <rtems/test.h>
58
59/**
60 * @defgroup RTEMSTestCaseRtemsSignalReqSend spec:/rtems/signal/req/send
61 *
62 * @ingroup RTEMSTestSuiteTestsuitesValidation0
63 * @ingroup RTEMSTestSuiteTestsuitesValidation1
64 *
65 * @{
66 */
67
68typedef enum {
69  RtemsSignalReqSend_Pre_Task_NoObj,
70  RtemsSignalReqSend_Pre_Task_Self,
71  RtemsSignalReqSend_Pre_Task_Other,
72  RtemsSignalReqSend_Pre_Task_NA
73} RtemsSignalReqSend_Pre_Task;
74
75typedef enum {
76  RtemsSignalReqSend_Pre_Set_Zero,
77  RtemsSignalReqSend_Pre_Set_NonZero,
78  RtemsSignalReqSend_Pre_Set_NA
79} RtemsSignalReqSend_Pre_Set;
80
81typedef enum {
82  RtemsSignalReqSend_Pre_Handler_Invalid,
83  RtemsSignalReqSend_Pre_Handler_Valid,
84  RtemsSignalReqSend_Pre_Handler_NA
85} RtemsSignalReqSend_Pre_Handler;
86
87typedef enum {
88  RtemsSignalReqSend_Pre_ASR_Enabled,
89  RtemsSignalReqSend_Pre_ASR_Disabled,
90  RtemsSignalReqSend_Pre_ASR_NA
91} RtemsSignalReqSend_Pre_ASR;
92
93typedef enum {
94  RtemsSignalReqSend_Pre_Nested_Yes,
95  RtemsSignalReqSend_Pre_Nested_No,
96  RtemsSignalReqSend_Pre_Nested_NA
97} RtemsSignalReqSend_Pre_Nested;
98
99typedef enum {
100  RtemsSignalReqSend_Post_Status_Ok,
101  RtemsSignalReqSend_Post_Status_InvNum,
102  RtemsSignalReqSend_Post_Status_InvId,
103  RtemsSignalReqSend_Post_Status_NotDef,
104  RtemsSignalReqSend_Post_Status_NA
105} RtemsSignalReqSend_Post_Status;
106
107typedef enum {
108  RtemsSignalReqSend_Post_Handler_NoCall,
109  RtemsSignalReqSend_Post_Handler_DuringSend,
110  RtemsSignalReqSend_Post_Handler_AfterDispatch,
111  RtemsSignalReqSend_Post_Handler_AfterEnable,
112  RtemsSignalReqSend_Post_Handler_NA
113} RtemsSignalReqSend_Post_Handler;
114
115typedef enum {
116  RtemsSignalReqSend_Post_Recursive_Yes,
117  RtemsSignalReqSend_Post_Recursive_No,
118  RtemsSignalReqSend_Post_Recursive_NA
119} RtemsSignalReqSend_Post_Recursive;
120
121/**
122 * @brief Test context for spec:/rtems/signal/req/send test case.
123 */
124typedef struct {
125  rtems_id runner_id;
126
127  rtems_id worker_id;
128
129  rtems_asr_entry handler;
130
131  size_t nested;
132
133  size_t handler_calls;
134
135  size_t calls_after_send;
136
137  size_t calls_after_dispatch;
138
139  size_t calls_after_enable;
140
141  rtems_signal_set processed_signal_sets[ 2 ];
142
143  uintptr_t stack_pointers[ 2 ];;
144
145  rtems_mode mode;;
146
147  rtems_status_code status;
148
149  rtems_id id;
150
151  rtems_signal_set signal_set;
152
153  /**
154   * @brief This member defines the pre-condition states for the next action.
155   */
156  size_t pcs[ 5 ];
157
158  /**
159   * @brief This member indicates if the test action loop is currently
160   *   executed.
161   */
162  bool in_action_loop;
163} RtemsSignalReqSend_Context;
164
165static RtemsSignalReqSend_Context
166  RtemsSignalReqSend_Instance;
167
168static const char * const RtemsSignalReqSend_PreDesc_Task[] = {
169  "NoObj",
170  "Self",
171  "Other",
172  "NA"
173};
174
175static const char * const RtemsSignalReqSend_PreDesc_Set[] = {
176  "Zero",
177  "NonZero",
178  "NA"
179};
180
181static const char * const RtemsSignalReqSend_PreDesc_Handler[] = {
182  "Invalid",
183  "Valid",
184  "NA"
185};
186
187static const char * const RtemsSignalReqSend_PreDesc_ASR[] = {
188  "Enabled",
189  "Disabled",
190  "NA"
191};
192
193static const char * const RtemsSignalReqSend_PreDesc_Nested[] = {
194  "Yes",
195  "No",
196  "NA"
197};
198
199static const char * const * const RtemsSignalReqSend_PreDesc[] = {
200  RtemsSignalReqSend_PreDesc_Task,
201  RtemsSignalReqSend_PreDesc_Set,
202  RtemsSignalReqSend_PreDesc_Handler,
203  RtemsSignalReqSend_PreDesc_ASR,
204  RtemsSignalReqSend_PreDesc_Nested,
205  NULL
206};
207
208#define EVENT_START RTEMS_EVENT_0
209
210#define EVENT_SEND_DONE RTEMS_EVENT_1
211
212#define EVENT_DO_ENABLE RTEMS_EVENT_2
213
214#define EVENT_END RTEMS_EVENT_3
215
216#define EVENT_WORKER_DONE RTEMS_EVENT_4
217
218typedef RtemsSignalReqSend_Context Context;
219
220typedef enum {
221  PRIO_HIGH = 1,
222  PRIO_NORMAL
223} Priorities;
224
225static rtems_event_set Wait( void )
226{
227  rtems_status_code sc;
228  rtems_event_set   events;
229
230  events = 0;
231  sc = rtems_event_receive(
232    RTEMS_ALL_EVENTS,
233    RTEMS_EVENT_ANY | RTEMS_WAIT,
234    RTEMS_NO_TIMEOUT,
235    &events
236  );
237  T_rsc_success( sc );
238
239  return events;
240}
241
242static void SendEvents( rtems_id id, rtems_event_set events )
243{
244  rtems_status_code sc;
245
246  sc = rtems_event_send( id, events );
247  T_rsc_success( sc );
248}
249
250static void WorkerDone( const Context *ctx )
251{
252#if defined(RTEMS_SMP)
253  if ( rtems_scheduler_get_processor_maximum() > 1 ) {
254    SendEvents( ctx->runner_id, EVENT_WORKER_DONE );
255  }
256#endif
257}
258
259static void SendEventsToWorker( const Context *ctx, rtems_event_set events )
260{
261  SendEvents( ctx->worker_id, events );
262
263#if defined(RTEMS_SMP)
264  if ( rtems_scheduler_get_processor_maximum() > 1 ) {
265    events = Wait();
266    T_eq_u32( events, EVENT_WORKER_DONE );
267  }
268#endif
269}
270
271static void SignalHandler( rtems_signal_set signal_set )
272{
273  Context *ctx;
274  size_t   i;
275  size_t   n;
276
277  ctx = T_fixture_context();
278  i = ctx->handler_calls;
279  n = RTEMS_ARRAY_SIZE( ctx->processed_signal_sets );
280  ctx->processed_signal_sets[ i % n ] = signal_set;
281  ctx->stack_pointers[ i % n ] = (uintptr_t) __builtin_frame_address( 0 );
282  T_lt_sz( i, n );
283  ctx->handler_calls = i + 1;
284
285  if ( ctx->nested != 0 && i == 0 ) {
286    rtems_status_code sc;
287
288    if ( ctx->id == ctx->worker_id ) {
289      rtems_event_set events;
290
291      sc = rtems_signal_catch( ctx->handler, RTEMS_NO_ASR );
292      T_rsc_success( sc );
293
294      WorkerDone( ctx );
295
296      events = Wait();
297      T_eq_u32( events, EVENT_SEND_DONE );
298
299      WorkerDone( ctx );
300
301      events = Wait();
302      T_eq_u32( events, EVENT_DO_ENABLE );
303    } else {
304      sc = rtems_signal_catch( ctx->handler, RTEMS_NO_ASR );
305      T_rsc_success( sc );
306
307      ctx->status = rtems_signal_send( ctx->id, ctx->signal_set );
308      ctx->calls_after_send = ctx->handler_calls;
309      ctx->calls_after_dispatch = ctx->handler_calls;
310    }
311  }
312}
313
314static void Worker( rtems_task_argument arg )
315{
316  Context *ctx;
317
318  ctx = (Context *) arg;
319
320  while ( true ) {
321    rtems_status_code sc;
322    rtems_event_set   events;
323
324    events = Wait();
325    T_eq_u32( events, EVENT_START );
326
327    if ( ctx->nested != 0 ) {
328      sc = rtems_signal_catch( SignalHandler, ctx->mode );
329      T_rsc_success( sc );
330
331      sc = rtems_signal_send( RTEMS_SELF, 0x600df00d );
332      T_rsc_success( sc );
333
334      WorkerDone( ctx );
335    } else {
336      rtems_mode mode;
337
338      sc = rtems_task_mode( ctx->mode, RTEMS_ASR_MASK, &mode );
339      T_rsc_success( sc );
340
341      sc = rtems_signal_catch( ctx->handler, RTEMS_NO_ASR );
342      T_rsc_success( sc );
343
344      WorkerDone( ctx );
345
346      events = Wait();
347      T_eq_u32( events, EVENT_SEND_DONE );
348
349      WorkerDone( ctx );
350
351      events = Wait();
352      T_eq_u32( events, EVENT_DO_ENABLE );
353
354      sc = rtems_task_mode( mode, RTEMS_ASR_MASK, &mode );
355      T_rsc_success( sc );
356
357      WorkerDone( ctx );
358    }
359
360    events = Wait();
361    T_eq_u32( events, EVENT_END );
362
363    WorkerDone( ctx );
364  }
365}
366
367static void RtemsSignalReqSend_Pre_Task_Prepare(
368  RtemsSignalReqSend_Context *ctx,
369  RtemsSignalReqSend_Pre_Task state
370)
371{
372  switch ( state ) {
373    case RtemsSignalReqSend_Pre_Task_NoObj: {
[54c9630]374      /*
375       * The ``id`` parameter shall be invalid.
376       */
[3e7d658]377      ctx->id = 0xffffffff;
378      break;
379    }
380
381    case RtemsSignalReqSend_Pre_Task_Self: {
[54c9630]382      /*
383       * The ``id`` parameter shall be associated with
384       * the calling task.
385       */
[3e7d658]386      ctx->id = RTEMS_SELF;
387      break;
388    }
389
390    case RtemsSignalReqSend_Pre_Task_Other: {
[54c9630]391      /*
392       * The ``id`` parameter shall be associated with a
393       * task other than the calling task.
394       */
[3e7d658]395      ctx->id = ctx->worker_id;
396      break;
397    }
398
399    case RtemsSignalReqSend_Pre_Task_NA:
400      break;
401  }
402}
403
404static void RtemsSignalReqSend_Pre_Set_Prepare(
405  RtemsSignalReqSend_Context *ctx,
406  RtemsSignalReqSend_Pre_Set  state
407)
408{
409  switch ( state ) {
410    case RtemsSignalReqSend_Pre_Set_Zero: {
[54c9630]411      /*
412       * The ``signal_set`` parameter shall be zero.
413       */
[3e7d658]414      ctx->signal_set = 0;
415      break;
416    }
417
418    case RtemsSignalReqSend_Pre_Set_NonZero: {
[54c9630]419      /*
420       * The ``signal_set`` parameter shall be non-zero.
421       */
[3e7d658]422      ctx->signal_set = 0xdeadbeef;
423      break;
424    }
425
426    case RtemsSignalReqSend_Pre_Set_NA:
427      break;
428  }
429}
430
431static void RtemsSignalReqSend_Pre_Handler_Prepare(
432  RtemsSignalReqSend_Context    *ctx,
433  RtemsSignalReqSend_Pre_Handler state
434)
435{
436  switch ( state ) {
437    case RtemsSignalReqSend_Pre_Handler_Invalid: {
[54c9630]438      /*
439       * When the target task has no valid ASR handler installed, the
440       * rtems_signal_send() directive shall be called.
441       */
[3e7d658]442      ctx->handler = NULL;
443      break;
444    }
445
446    case RtemsSignalReqSend_Pre_Handler_Valid: {
[54c9630]447      /*
448       * When the target task has a valid ASR handler installed, the
449       * rtems_signal_send() directive shall be called.
450       */
[3e7d658]451      ctx->handler = SignalHandler;
452      break;
453    }
454
455    case RtemsSignalReqSend_Pre_Handler_NA:
456      break;
457  }
458}
459
460static void RtemsSignalReqSend_Pre_ASR_Prepare(
461  RtemsSignalReqSend_Context *ctx,
462  RtemsSignalReqSend_Pre_ASR  state
463)
464{
465  switch ( state ) {
466    case RtemsSignalReqSend_Pre_ASR_Enabled: {
[54c9630]467      /*
468       * When the target task has ASR processing enabled, the rtems_signal_send()
469       * directive shall be called.
470       */
[3e7d658]471      ctx->mode = RTEMS_DEFAULT_MODES;
472      break;
473    }
474
475    case RtemsSignalReqSend_Pre_ASR_Disabled: {
[54c9630]476      /*
477       * When the target task has ASR processing disabled, the rtems_signal_send()
478       * directive shall be called.
479       */
[3e7d658]480      ctx->mode = RTEMS_NO_ASR;
481      break;
482    }
483
484    case RtemsSignalReqSend_Pre_ASR_NA:
485      break;
486  }
487}
488
489static void RtemsSignalReqSend_Pre_Nested_Prepare(
490  RtemsSignalReqSend_Context   *ctx,
491  RtemsSignalReqSend_Pre_Nested state
492)
493{
494  switch ( state ) {
495    case RtemsSignalReqSend_Pre_Nested_Yes: {
[54c9630]496      /*
497       * When the target task processes an asynchronous signal set, the
498       * rtems_signal_send() directive shall be called.
499       */
[3e7d658]500      ctx->nested = 1;
501      break;
502    }
503
504    case RtemsSignalReqSend_Pre_Nested_No: {
[54c9630]505      /*
506       * When the target task does not process an asynchronous signal set, the
507       * rtems_signal_send() directive shall be called.
508       */
[3e7d658]509      ctx->nested = 0;
510      break;
511    }
512
513    case RtemsSignalReqSend_Pre_Nested_NA:
514      break;
515  }
516}
517
518static void RtemsSignalReqSend_Post_Status_Check(
519  RtemsSignalReqSend_Context    *ctx,
520  RtemsSignalReqSend_Post_Status state
521)
522{
523  switch ( state ) {
524    case RtemsSignalReqSend_Post_Status_Ok: {
[54c9630]525      /*
526       * The return status of rtems_signal_send() shall be
527       * RTEMS_SUCCESSFUL.
528       */
[3e7d658]529      T_rsc_success( ctx->status );
530      break;
531    }
532
533    case RtemsSignalReqSend_Post_Status_InvNum: {
[54c9630]534      /*
535       * The return status of rtems_signal_send() shall be
536       * RTEMS_INVALID_NUMBER.
537       */
[3e7d658]538      T_rsc( ctx->status, RTEMS_INVALID_NUMBER );
539      break;
540    }
541
542    case RtemsSignalReqSend_Post_Status_InvId: {
[54c9630]543      /*
544       * The return status of rtems_signal_send() shall be
545       * RTEMS_INVALID_ID.
546       */
[3e7d658]547      T_rsc( ctx->status, RTEMS_INVALID_ID );
548      break;
549    }
550
551    case RtemsSignalReqSend_Post_Status_NotDef: {
[54c9630]552      /*
553       * The return status of rtems_signal_send() shall be
554       * RTEMS_NOT_DEFINED.
555       */
[3e7d658]556      T_rsc( ctx->status, RTEMS_NOT_DEFINED );
557      break;
558    }
559
560    case RtemsSignalReqSend_Post_Status_NA:
561      break;
562  }
563}
564
565static void RtemsSignalReqSend_Post_Handler_Check(
566  RtemsSignalReqSend_Context     *ctx,
567  RtemsSignalReqSend_Post_Handler state
568)
569{
570  size_t expected_calls;
571
572  expected_calls = ctx->nested;
573
574  switch ( state ) {
575    case RtemsSignalReqSend_Post_Handler_NoCall: {
[54c9630]576      /*
577       * While the ASR processing is disabled, the ASR handler shall not be
578       * called.
579       */
[3e7d658]580      T_eq_sz( ctx->calls_after_send, ctx->nested );
581      T_eq_sz( ctx->calls_after_dispatch, ctx->nested );
582      T_eq_sz( ctx->calls_after_enable, ctx->nested );
583      break;
584    }
585
586    case RtemsSignalReqSend_Post_Handler_DuringSend: {
[54c9630]587      /*
588       * The ASR handler shall be called during the rtems_signal_send() call.
589       */
[3e7d658]590      ++expected_calls;
591      T_eq_sz( ctx->calls_after_send, ctx->nested + 1 );
592      T_eq_sz( ctx->calls_after_dispatch, ctx->nested + 1 );
593      T_eq_sz( ctx->calls_after_enable, ctx->nested + 1 );
594      break;
595    }
596
597    case RtemsSignalReqSend_Post_Handler_AfterDispatch: {
[54c9630]598      /*
599       * When the next thread dispatch of the target task of the
600       * rtems_signal_send() call takes place, the ASR handler shall be called.
601       */
[3e7d658]602      ++expected_calls;
603      T_eq_sz( ctx->calls_after_send, ctx->nested );
604      T_eq_sz( ctx->calls_after_dispatch, ctx->nested + 1 );
605      T_eq_sz( ctx->calls_after_enable, ctx->nested + 1 );
606      break;
607    }
608
609    case RtemsSignalReqSend_Post_Handler_AfterEnable: {
[54c9630]610      /*
611       * When the target task of the rtems_signal_send() call re-enables ASR
612       * processing, the ASR handler shall be called.
613       */
[3e7d658]614      ++expected_calls;
615      T_eq_sz( ctx->calls_after_send, ctx->nested );
616      T_eq_sz( ctx->calls_after_dispatch, ctx->nested );
617      T_eq_sz( ctx->calls_after_enable, ctx->nested + 1 );
618      break;
619    }
620
621    case RtemsSignalReqSend_Post_Handler_NA:
622      break;
623  }
624
625  T_eq_sz( ctx->handler_calls, expected_calls );
626
627  if ( ctx->nested != 0 ) {
628    T_eq_u32( ctx->processed_signal_sets[ 0 ], 0x600df00d );
629  }
630
631  if ( expected_calls > ctx->nested ) {
632    T_eq_u32( ctx->processed_signal_sets[ ctx->nested ], 0xdeadbeef );
633  }
634}
635
636static void RtemsSignalReqSend_Post_Recursive_Check(
637  RtemsSignalReqSend_Context       *ctx,
638  RtemsSignalReqSend_Post_Recursive state
639)
640{
641  switch ( state ) {
642    case RtemsSignalReqSend_Post_Recursive_Yes: {
[54c9630]643      /*
644       * The ASR handler shall be called recursively.
645       */
[3e7d658]646      T_eq_sz( ctx->handler_calls, 2 );
647      T_ne_uptr( ctx->stack_pointers[ 0 ], 0 );
648      T_ne_uptr( ctx->stack_pointers[ 1 ], 0 );
649      T_ne_uptr( ctx->stack_pointers[ 0 ], ctx->stack_pointers[ 1 ] );
650      break;
651    }
652
653    case RtemsSignalReqSend_Post_Recursive_No: {
[54c9630]654      /*
655       * The ASR handler shall not be called recursively.
656       */
[3e7d658]657      if ( ctx->handler_calls == 2 ) {
658        T_ne_uptr( ctx->stack_pointers[ 0 ], 0 );
659        T_ne_uptr( ctx->stack_pointers[ 1 ], 0 );
660        T_eq_uptr( ctx->stack_pointers[ 0 ], ctx->stack_pointers[ 1 ] );
661      }
662      break;
663    }
664
665    case RtemsSignalReqSend_Post_Recursive_NA:
666      break;
667  }
668}
669
670static void RtemsSignalReqSend_Setup( RtemsSignalReqSend_Context *ctx )
671{
672  rtems_status_code   sc;
673  rtems_task_priority prio;
674
675  memset( ctx, 0, sizeof( *ctx ) );
676  ctx->runner_id = rtems_task_self();
677
678  prio = 0;
679  sc = rtems_task_set_priority( RTEMS_SELF, PRIO_NORMAL, &prio );
680  T_rsc_success( sc );
681  T_eq_u32( prio, PRIO_HIGH );
682
683  sc = rtems_task_create(
684    rtems_build_name( 'W', 'O', 'R', 'K' ),
685    PRIO_HIGH,
686    RTEMS_MINIMUM_STACK_SIZE,
687    RTEMS_DEFAULT_MODES,
688    RTEMS_DEFAULT_ATTRIBUTES,
689    &ctx->worker_id
690  );
691  T_assert_rsc_success( sc );
692
693  #if defined(RTEMS_SMP)
694  if ( rtems_scheduler_get_processor_maximum() > 1 ) {
695    rtems_id scheduler_id;
696
697    sc = rtems_scheduler_ident_by_processor( 1, &scheduler_id );
698    T_assert_rsc_success( sc );
699
700    sc = rtems_task_set_scheduler( ctx->worker_id, scheduler_id, PRIO_HIGH );
701    T_assert_rsc_success( sc );
702  }
703  #endif
704
705  sc = rtems_task_start( ctx->worker_id, Worker, (rtems_task_argument) ctx );
706  T_assert_rsc_success( sc );
707}
708
709static void RtemsSignalReqSend_Setup_Wrap( void *arg )
710{
711  RtemsSignalReqSend_Context *ctx;
712
713  ctx = arg;
714  ctx->in_action_loop = false;
715  RtemsSignalReqSend_Setup( ctx );
716}
717
718static void RtemsSignalReqSend_Teardown( RtemsSignalReqSend_Context *ctx )
719{
720  rtems_status_code   sc;
721  rtems_task_priority prio;
722
723  prio = 0;
724  sc = rtems_task_set_priority( RTEMS_SELF, PRIO_HIGH, &prio );
725  T_rsc_success( sc );
726  T_eq_u32( prio, PRIO_NORMAL );
727
728  if ( ctx->worker_id != 0 ) {
729    sc = rtems_task_delete( ctx->worker_id );
730    T_rsc_success( sc );
731  }
732}
733
734static void RtemsSignalReqSend_Teardown_Wrap( void *arg )
735{
736  RtemsSignalReqSend_Context *ctx;
737
738  ctx = arg;
739  ctx->in_action_loop = false;
740  RtemsSignalReqSend_Teardown( ctx );
741}
742
743static size_t RtemsSignalReqSend_Scope( void *arg, char *buf, size_t n )
744{
745  RtemsSignalReqSend_Context *ctx;
746
747  ctx = arg;
748
749  if ( ctx->in_action_loop ) {
750    return T_get_scope( RtemsSignalReqSend_PreDesc, buf, n, ctx->pcs );
751  }
752
753  return 0;
754}
755
756static T_fixture RtemsSignalReqSend_Fixture = {
757  .setup = RtemsSignalReqSend_Setup_Wrap,
758  .stop = NULL,
759  .teardown = RtemsSignalReqSend_Teardown_Wrap,
760  .scope = RtemsSignalReqSend_Scope,
761  .initial_context = &RtemsSignalReqSend_Instance
762};
763
764static const uint8_t RtemsSignalReqSend_TransitionMap[][ 3 ] = {
765  {
766    RtemsSignalReqSend_Post_Status_InvNum,
767    RtemsSignalReqSend_Post_Handler_NoCall,
768    RtemsSignalReqSend_Post_Recursive_No
769  }, {
770    RtemsSignalReqSend_Post_Status_InvNum,
771    RtemsSignalReqSend_Post_Handler_NoCall,
772    RtemsSignalReqSend_Post_Recursive_No
773  }, {
774    RtemsSignalReqSend_Post_Status_InvNum,
775    RtemsSignalReqSend_Post_Handler_NoCall,
776    RtemsSignalReqSend_Post_Recursive_No
777  }, {
778    RtemsSignalReqSend_Post_Status_InvNum,
779    RtemsSignalReqSend_Post_Handler_NoCall,
780    RtemsSignalReqSend_Post_Recursive_No
781  }, {
782    RtemsSignalReqSend_Post_Status_InvNum,
783    RtemsSignalReqSend_Post_Handler_NoCall,
784    RtemsSignalReqSend_Post_Recursive_No
785  }, {
786    RtemsSignalReqSend_Post_Status_InvNum,
787    RtemsSignalReqSend_Post_Handler_NoCall,
788    RtemsSignalReqSend_Post_Recursive_No
789  }, {
790    RtemsSignalReqSend_Post_Status_InvNum,
791    RtemsSignalReqSend_Post_Handler_NoCall,
792    RtemsSignalReqSend_Post_Recursive_No
793  }, {
794    RtemsSignalReqSend_Post_Status_InvNum,
795    RtemsSignalReqSend_Post_Handler_NoCall,
796    RtemsSignalReqSend_Post_Recursive_No
797  }, {
798    RtemsSignalReqSend_Post_Status_InvId,
799    RtemsSignalReqSend_Post_Handler_NoCall,
800    RtemsSignalReqSend_Post_Recursive_No
801  }, {
802    RtemsSignalReqSend_Post_Status_InvId,
803    RtemsSignalReqSend_Post_Handler_NoCall,
804    RtemsSignalReqSend_Post_Recursive_No
805  }, {
806    RtemsSignalReqSend_Post_Status_InvId,
807    RtemsSignalReqSend_Post_Handler_NoCall,
808    RtemsSignalReqSend_Post_Recursive_No
809  }, {
810    RtemsSignalReqSend_Post_Status_InvId,
811    RtemsSignalReqSend_Post_Handler_NoCall,
812    RtemsSignalReqSend_Post_Recursive_No
813  }, {
814    RtemsSignalReqSend_Post_Status_InvId,
815    RtemsSignalReqSend_Post_Handler_NoCall,
816    RtemsSignalReqSend_Post_Recursive_No
817  }, {
818    RtemsSignalReqSend_Post_Status_InvId,
819    RtemsSignalReqSend_Post_Handler_NoCall,
820    RtemsSignalReqSend_Post_Recursive_No
821  }, {
822    RtemsSignalReqSend_Post_Status_InvId,
823    RtemsSignalReqSend_Post_Handler_NoCall,
824    RtemsSignalReqSend_Post_Recursive_No
825  }, {
826    RtemsSignalReqSend_Post_Status_InvId,
827    RtemsSignalReqSend_Post_Handler_NoCall,
828    RtemsSignalReqSend_Post_Recursive_No
829  }, {
830    RtemsSignalReqSend_Post_Status_InvNum,
831    RtemsSignalReqSend_Post_Handler_NoCall,
832    RtemsSignalReqSend_Post_Recursive_No
833  }, {
834    RtemsSignalReqSend_Post_Status_InvNum,
835    RtemsSignalReqSend_Post_Handler_NoCall,
836    RtemsSignalReqSend_Post_Recursive_No
837  }, {
838    RtemsSignalReqSend_Post_Status_InvNum,
839    RtemsSignalReqSend_Post_Handler_NoCall,
840    RtemsSignalReqSend_Post_Recursive_No
841  }, {
842    RtemsSignalReqSend_Post_Status_InvNum,
843    RtemsSignalReqSend_Post_Handler_NoCall,
844    RtemsSignalReqSend_Post_Recursive_No
845  }, {
846    RtemsSignalReqSend_Post_Status_InvNum,
847    RtemsSignalReqSend_Post_Handler_NoCall,
848    RtemsSignalReqSend_Post_Recursive_No
849  }, {
850    RtemsSignalReqSend_Post_Status_InvNum,
851    RtemsSignalReqSend_Post_Handler_NoCall,
852    RtemsSignalReqSend_Post_Recursive_No
853  }, {
854    RtemsSignalReqSend_Post_Status_InvNum,
855    RtemsSignalReqSend_Post_Handler_NoCall,
856    RtemsSignalReqSend_Post_Recursive_No
857  }, {
858    RtemsSignalReqSend_Post_Status_InvNum,
859    RtemsSignalReqSend_Post_Handler_NoCall,
860    RtemsSignalReqSend_Post_Recursive_No
861  }, {
862    RtemsSignalReqSend_Post_Status_NotDef,
863    RtemsSignalReqSend_Post_Handler_NoCall,
864    RtemsSignalReqSend_Post_Recursive_No
865  }, {
866    RtemsSignalReqSend_Post_Status_NotDef,
867    RtemsSignalReqSend_Post_Handler_NoCall,
868    RtemsSignalReqSend_Post_Recursive_No
869  }, {
870    RtemsSignalReqSend_Post_Status_NotDef,
871    RtemsSignalReqSend_Post_Handler_NoCall,
872    RtemsSignalReqSend_Post_Recursive_No
873  }, {
874    RtemsSignalReqSend_Post_Status_NotDef,
875    RtemsSignalReqSend_Post_Handler_NoCall,
876    RtemsSignalReqSend_Post_Recursive_No
877  }, {
878    RtemsSignalReqSend_Post_Status_Ok,
879    RtemsSignalReqSend_Post_Handler_DuringSend,
880    RtemsSignalReqSend_Post_Recursive_Yes
881  }, {
882    RtemsSignalReqSend_Post_Status_Ok,
883    RtemsSignalReqSend_Post_Handler_DuringSend,
884    RtemsSignalReqSend_Post_Recursive_No
885  }, {
886    RtemsSignalReqSend_Post_Status_Ok,
887    RtemsSignalReqSend_Post_Handler_AfterEnable,
888    RtemsSignalReqSend_Post_Recursive_No
889  }, {
890    RtemsSignalReqSend_Post_Status_Ok,
891    RtemsSignalReqSend_Post_Handler_AfterEnable,
892    RtemsSignalReqSend_Post_Recursive_No
893  }, {
894    RtemsSignalReqSend_Post_Status_InvNum,
895    RtemsSignalReqSend_Post_Handler_NoCall,
896    RtemsSignalReqSend_Post_Recursive_No
897  }, {
898    RtemsSignalReqSend_Post_Status_InvNum,
899    RtemsSignalReqSend_Post_Handler_NoCall,
900    RtemsSignalReqSend_Post_Recursive_No
901  }, {
902    RtemsSignalReqSend_Post_Status_InvNum,
903    RtemsSignalReqSend_Post_Handler_NoCall,
904    RtemsSignalReqSend_Post_Recursive_No
905  }, {
906    RtemsSignalReqSend_Post_Status_InvNum,
907    RtemsSignalReqSend_Post_Handler_NoCall,
908    RtemsSignalReqSend_Post_Recursive_No
909  }, {
910    RtemsSignalReqSend_Post_Status_InvNum,
911    RtemsSignalReqSend_Post_Handler_NoCall,
912    RtemsSignalReqSend_Post_Recursive_No
913  }, {
914    RtemsSignalReqSend_Post_Status_InvNum,
915    RtemsSignalReqSend_Post_Handler_NoCall,
916    RtemsSignalReqSend_Post_Recursive_No
917  }, {
918    RtemsSignalReqSend_Post_Status_InvNum,
919    RtemsSignalReqSend_Post_Handler_NoCall,
920    RtemsSignalReqSend_Post_Recursive_No
921  }, {
922    RtemsSignalReqSend_Post_Status_InvNum,
923    RtemsSignalReqSend_Post_Handler_NoCall,
924    RtemsSignalReqSend_Post_Recursive_No
925  }, {
926    RtemsSignalReqSend_Post_Status_NotDef,
927    RtemsSignalReqSend_Post_Handler_NoCall,
928    RtemsSignalReqSend_Post_Recursive_No
929  }, {
930    RtemsSignalReqSend_Post_Status_NotDef,
931    RtemsSignalReqSend_Post_Handler_NoCall,
932    RtemsSignalReqSend_Post_Recursive_No
933  }, {
934    RtemsSignalReqSend_Post_Status_NotDef,
935    RtemsSignalReqSend_Post_Handler_NoCall,
936    RtemsSignalReqSend_Post_Recursive_No
937  }, {
938    RtemsSignalReqSend_Post_Status_NotDef,
939    RtemsSignalReqSend_Post_Handler_NoCall,
940    RtemsSignalReqSend_Post_Recursive_No
941  }, {
942    RtemsSignalReqSend_Post_Status_Ok,
943    RtemsSignalReqSend_Post_Handler_AfterDispatch,
944    RtemsSignalReqSend_Post_Recursive_Yes
945  }, {
946    RtemsSignalReqSend_Post_Status_Ok,
947    RtemsSignalReqSend_Post_Handler_AfterDispatch,
948    RtemsSignalReqSend_Post_Recursive_No
949  }, {
950    RtemsSignalReqSend_Post_Status_Ok,
951    RtemsSignalReqSend_Post_Handler_AfterEnable,
952    RtemsSignalReqSend_Post_Recursive_No
953  }, {
954    RtemsSignalReqSend_Post_Status_Ok,
955    RtemsSignalReqSend_Post_Handler_AfterEnable,
956    RtemsSignalReqSend_Post_Recursive_No
957  }
958};
959
960static const struct {
961  uint8_t Skip : 1;
962  uint8_t Pre_Task_NA : 1;
963  uint8_t Pre_Set_NA : 1;
964  uint8_t Pre_Handler_NA : 1;
965  uint8_t Pre_ASR_NA : 1;
966  uint8_t Pre_Nested_NA : 1;
967} RtemsSignalReqSend_TransitionInfo[] = {
968  {
969    0, 0, 0, 0, 0, 0
970  }, {
971    0, 0, 0, 0, 0, 0
972  }, {
973    0, 0, 0, 0, 0, 0
974  }, {
975    0, 0, 0, 0, 0, 0
976  }, {
977    0, 0, 0, 0, 0, 0
978  }, {
979    0, 0, 0, 0, 0, 0
980  }, {
981    0, 0, 0, 0, 0, 0
982  }, {
983    0, 0, 0, 0, 0, 0
984  }, {
985    0, 0, 0, 0, 0, 0
986  }, {
987    0, 0, 0, 0, 0, 0
988  }, {
989    0, 0, 0, 0, 0, 0
990  }, {
991    0, 0, 0, 0, 0, 0
992  }, {
993    0, 0, 0, 0, 0, 0
994  }, {
995    0, 0, 0, 0, 0, 0
996  }, {
997    0, 0, 0, 0, 0, 0
998  }, {
999    0, 0, 0, 0, 0, 0
1000  }, {
1001    0, 0, 0, 0, 0, 0
1002  }, {
1003    0, 0, 0, 0, 0, 0
1004  }, {
1005    0, 0, 0, 0, 0, 0
1006  }, {
1007    0, 0, 0, 0, 0, 0
1008  }, {
1009    0, 0, 0, 0, 0, 0
1010  }, {
1011    0, 0, 0, 0, 0, 0
1012  }, {
1013    0, 0, 0, 0, 0, 0
1014  }, {
1015    0, 0, 0, 0, 0, 0
1016  }, {
1017    0, 0, 0, 0, 0, 0
1018  }, {
1019    0, 0, 0, 0, 0, 0
1020  }, {
1021    0, 0, 0, 0, 0, 0
1022  }, {
1023    0, 0, 0, 0, 0, 0
1024  }, {
1025    0, 0, 0, 0, 0, 0
1026  }, {
1027    0, 0, 0, 0, 0, 0
1028  }, {
1029    0, 0, 0, 0, 0, 0
1030  }, {
1031    0, 0, 0, 0, 0, 0
1032  }, {
1033    0, 0, 0, 0, 0, 0
1034  }, {
1035    0, 0, 0, 0, 0, 0
1036  }, {
1037    0, 0, 0, 0, 0, 0
1038  }, {
1039    0, 0, 0, 0, 0, 0
1040  }, {
1041    0, 0, 0, 0, 0, 0
1042  }, {
1043    0, 0, 0, 0, 0, 0
1044  }, {
1045    0, 0, 0, 0, 0, 0
1046  }, {
1047    0, 0, 0, 0, 0, 0
1048  }, {
1049    0, 0, 0, 0, 0, 0
1050  }, {
1051    0, 0, 0, 0, 0, 0
1052  }, {
1053    0, 0, 0, 0, 0, 0
1054  }, {
1055    0, 0, 0, 0, 0, 0
1056  }, {
1057    0, 0, 0, 0, 0, 0
1058  }, {
1059    0, 0, 0, 0, 0, 0
1060  }, {
1061    0, 0, 0, 0, 0, 0
1062  }, {
1063    0, 0, 0, 0, 0, 0
1064  }
1065};
1066
1067static void RtemsSignalReqSend_Prepare( RtemsSignalReqSend_Context *ctx )
1068{
1069  ctx->handler_calls = 0;
1070  ctx->calls_after_send = 0;
1071  ctx->calls_after_dispatch = 0;
1072  ctx->calls_after_enable = 0;
1073  memset( &ctx->processed_signal_sets, 0, sizeof( ctx->processed_signal_sets ) );
1074  memset( &ctx->stack_pointers, 0, sizeof( ctx->stack_pointers ) );
1075}
1076
1077static void RtemsSignalReqSend_Action( RtemsSignalReqSend_Context *ctx )
1078{
1079  rtems_status_code sc;
1080
1081  if ( ctx->id == ctx->worker_id ) {
1082    SendEventsToWorker( ctx, EVENT_START );
1083
1084    ctx->status = rtems_signal_send( ctx->id, ctx->signal_set );
1085    ctx->calls_after_send = ctx->handler_calls;
1086
1087    SendEventsToWorker( ctx, EVENT_SEND_DONE );
1088    ctx->calls_after_dispatch = ctx->handler_calls;
1089    SendEventsToWorker( ctx, EVENT_DO_ENABLE );
1090    ctx->calls_after_enable = ctx->handler_calls;
1091    SendEventsToWorker( ctx, EVENT_END );
1092  } else if ( ctx->nested != 0 ) {
1093    sc = rtems_signal_catch( SignalHandler, ctx->mode );
1094    T_rsc_success( sc );
1095
1096    sc = rtems_signal_send( RTEMS_SELF, 0x600df00d );
1097    T_rsc_success( sc );
1098
1099    ctx->calls_after_enable = ctx->handler_calls;
1100  } else {
1101    rtems_mode mode;
1102
1103    sc = rtems_task_mode( ctx->mode, RTEMS_ASR_MASK, &mode );
1104    T_rsc_success( sc );
1105
1106    sc = rtems_signal_catch( ctx->handler, RTEMS_NO_ASR );
1107    T_rsc_success( sc );
1108
1109    ctx->status = rtems_signal_send( ctx->id, ctx->signal_set );
1110    ctx->calls_after_send = ctx->handler_calls;
1111    ctx->calls_after_dispatch = ctx->handler_calls;
1112
1113    sc = rtems_task_mode( mode, RTEMS_ASR_MASK, &mode );
1114    T_rsc_success( sc );
1115
1116    ctx->calls_after_enable = ctx->handler_calls;
1117  }
1118}
1119
1120/**
1121 * @fn void T_case_body_RtemsSignalReqSend( void )
1122 */
1123T_TEST_CASE_FIXTURE( RtemsSignalReqSend, &RtemsSignalReqSend_Fixture )
1124{
1125  RtemsSignalReqSend_Context *ctx;
1126  size_t index;
1127
1128  ctx = T_fixture_context();
1129  ctx->in_action_loop = true;
1130  index = 0;
1131
1132  for (
1133    ctx->pcs[ 0 ] = RtemsSignalReqSend_Pre_Task_NoObj;
1134    ctx->pcs[ 0 ] < RtemsSignalReqSend_Pre_Task_NA;
1135    ++ctx->pcs[ 0 ]
1136  ) {
1137    if ( RtemsSignalReqSend_TransitionInfo[ index ].Pre_Task_NA ) {
1138      ctx->pcs[ 0 ] = RtemsSignalReqSend_Pre_Task_NA;
1139      index += ( RtemsSignalReqSend_Pre_Task_NA - 1 )
1140        * RtemsSignalReqSend_Pre_Set_NA
1141        * RtemsSignalReqSend_Pre_Handler_NA
1142        * RtemsSignalReqSend_Pre_ASR_NA
1143        * RtemsSignalReqSend_Pre_Nested_NA;
1144    }
1145
1146    for (
1147      ctx->pcs[ 1 ] = RtemsSignalReqSend_Pre_Set_Zero;
1148      ctx->pcs[ 1 ] < RtemsSignalReqSend_Pre_Set_NA;
1149      ++ctx->pcs[ 1 ]
1150    ) {
1151      if ( RtemsSignalReqSend_TransitionInfo[ index ].Pre_Set_NA ) {
1152        ctx->pcs[ 1 ] = RtemsSignalReqSend_Pre_Set_NA;
1153        index += ( RtemsSignalReqSend_Pre_Set_NA - 1 )
1154          * RtemsSignalReqSend_Pre_Handler_NA
1155          * RtemsSignalReqSend_Pre_ASR_NA
1156          * RtemsSignalReqSend_Pre_Nested_NA;
1157      }
1158
1159      for (
1160        ctx->pcs[ 2 ] = RtemsSignalReqSend_Pre_Handler_Invalid;
1161        ctx->pcs[ 2 ] < RtemsSignalReqSend_Pre_Handler_NA;
1162        ++ctx->pcs[ 2 ]
1163      ) {
1164        if ( RtemsSignalReqSend_TransitionInfo[ index ].Pre_Handler_NA ) {
1165          ctx->pcs[ 2 ] = RtemsSignalReqSend_Pre_Handler_NA;
1166          index += ( RtemsSignalReqSend_Pre_Handler_NA - 1 )
1167            * RtemsSignalReqSend_Pre_ASR_NA
1168            * RtemsSignalReqSend_Pre_Nested_NA;
1169        }
1170
1171        for (
1172          ctx->pcs[ 3 ] = RtemsSignalReqSend_Pre_ASR_Enabled;
1173          ctx->pcs[ 3 ] < RtemsSignalReqSend_Pre_ASR_NA;
1174          ++ctx->pcs[ 3 ]
1175        ) {
1176          if ( RtemsSignalReqSend_TransitionInfo[ index ].Pre_ASR_NA ) {
1177            ctx->pcs[ 3 ] = RtemsSignalReqSend_Pre_ASR_NA;
1178            index += ( RtemsSignalReqSend_Pre_ASR_NA - 1 )
1179              * RtemsSignalReqSend_Pre_Nested_NA;
1180          }
1181
1182          for (
1183            ctx->pcs[ 4 ] = RtemsSignalReqSend_Pre_Nested_Yes;
1184            ctx->pcs[ 4 ] < RtemsSignalReqSend_Pre_Nested_NA;
1185            ++ctx->pcs[ 4 ]
1186          ) {
1187            if ( RtemsSignalReqSend_TransitionInfo[ index ].Pre_Nested_NA ) {
1188              ctx->pcs[ 4 ] = RtemsSignalReqSend_Pre_Nested_NA;
1189              index += ( RtemsSignalReqSend_Pre_Nested_NA - 1 );
1190            }
1191
1192            if ( RtemsSignalReqSend_TransitionInfo[ index ].Skip ) {
1193              ++index;
1194              continue;
1195            }
1196
1197            RtemsSignalReqSend_Prepare( ctx );
1198            RtemsSignalReqSend_Pre_Task_Prepare( ctx, ctx->pcs[ 0 ] );
1199            RtemsSignalReqSend_Pre_Set_Prepare( ctx, ctx->pcs[ 1 ] );
1200            RtemsSignalReqSend_Pre_Handler_Prepare( ctx, ctx->pcs[ 2 ] );
1201            RtemsSignalReqSend_Pre_ASR_Prepare( ctx, ctx->pcs[ 3 ] );
1202            RtemsSignalReqSend_Pre_Nested_Prepare( ctx, ctx->pcs[ 4 ] );
1203            RtemsSignalReqSend_Action( ctx );
1204            RtemsSignalReqSend_Post_Status_Check(
1205              ctx,
1206              RtemsSignalReqSend_TransitionMap[ index ][ 0 ]
1207            );
1208            RtemsSignalReqSend_Post_Handler_Check(
1209              ctx,
1210              RtemsSignalReqSend_TransitionMap[ index ][ 1 ]
1211            );
1212            RtemsSignalReqSend_Post_Recursive_Check(
1213              ctx,
1214              RtemsSignalReqSend_TransitionMap[ index ][ 2 ]
1215            );
1216            ++index;
1217          }
1218        }
1219      }
1220    }
1221  }
1222}
1223
1224/** @} */
Note: See TracBrowser for help on using the repository browser.