summaryrefslogtreecommitdiffstats
path: root/spec/score/tq/req/timeout.yml
blob: ca071b7bc18943bf656fd8b94e49117f27518afc (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
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: requirement-refinement
  uid: ../if/group
post-conditions:
- name: Status
  states:
  - name: Ok
    test-code: |
      T_eq_int(
        ctx->tq_ctx->status[ TQ_BLOCKER_A ],
        TQConvertStatus( ctx->tq_ctx, STATUS_SUCCESSFUL )
      );
    text: |
      The return status of the directive call shall be derived from
      ${../../status/if/successful:/name}.
  - name: Timeout
    test-code: |
      T_eq_int(
        ctx->tq_ctx->status[ TQ_BLOCKER_A ],
        TQConvertStatus( ctx->tq_ctx, STATUS_TIMEOUT )
      );
    text: |
      The return status of the directive call shall be derived from
      ${../../status/if/timeout:/name}.
  test-epilogue: null
  test-prologue: null
- name: Unblock
  states:
  - name: 'Yes'
    test-code: |
      T_eq_ptr( GetUnblock( ctx, &i ), GetTCB( ctx, TQ_BLOCKER_A ) );
      T_eq_ptr( GetUnblock( ctx, &i ), NULL );
    text: |
      The thread of the timeout operation shall be unblocked by the timeout
      operation.
  - name: 'No'
    test-code: |
      T_eq_ptr( GetUnblock( ctx, &i ), NULL );
    text: |
      The thread of the timeout operation shall not be unblocked by the timeout
      operation.
  test-epilogue: null
  test-prologue: |
    size_t i;

    i = 0;
pre-conditions:
- name: WaitState
  states:
  - name: Blocked
    test-code: |
      TQEnqueuePrepare( ctx->tq_ctx );
      TQSend( ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_ENQUEUE );
      Yield();
      Tick( ctx );
      TQEnqueueDone( ctx->tq_ctx );
    text: |
      While the thread of the timeout operation is in the blocked wait state.
  - name: IntendToBlock
    test-code: |
      TQEnqueuePrepare( ctx->tq_ctx );
      T_scheduler_set_event_handler( SchedulerBlock, ctx );
      TQSend( ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_ENQUEUE );
      Yield();
      TQEnqueueDone( ctx->tq_ctx );
    text: |
      While the thread of the timeout operation is in the intend to block wait
      state.
  - name: ReadyAgain
    test-code: |
      TQEnqueuePrepare( ctx->tq_ctx );
      TQSend( ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_ENQUEUE );
      Yield();
      T_scheduler_set_event_handler( SchedulerUnblock, ctx );
      TQEnqueueDone( ctx->tq_ctx );
      TQSend( ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_SURRENDER );
    text: |
      While the thread of the timeout operation is in the ready again wait
      state.
  test-epilogue: null
  test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons: {}
test-action: |
  /*
   * The action is performed by the ``WaitState`` pre-condition preparation.
   */
test-brief: null
test-cleanup: null
test-context:
- brief: |
    This member contains the call within ISR request.
  description: null
  member: |
    CallWithinISRRequest request;
test-context-support: null
test-description: null
test-header:
  code: null
  freestanding: false
  includes: []
  local-includes:
  - tx-thread-queue.h
  run-params:
  - description: |
      is the thread queue test context.
    dir: inout
    name: tq_ctx
    specifier: TQContext *${.:name}
  target: testsuites/validation/tr-tq-timeout.h
test-includes:
- rtems/score/threadimpl.h
test-local-includes:
- tx-support.h
- tr-tq-timeout.h
test-prepare: null
test-setup:
  brief: null
  code: |
    ctx->request.arg = ctx;
    TQReset( ctx->tq_ctx );

    if ( ctx->tq_ctx->enqueue_variant == TQ_ENQUEUE_STICKY ) {
      TQSetScheduler( ctx->tq_ctx, TQ_BLOCKER_A, SCHEDULER_B_ID, PRIO_NORMAL );
    } else {
      TQSetPriority( ctx->tq_ctx, TQ_BLOCKER_A, PRIO_HIGH );
    }
  description: null
test-stop: null
test-support: |
  typedef ${.:/test-context-type} Context;

  static const rtems_tcb *GetUnblock( Context *ctx, size_t *index )
  {
    return TQGetNextUnblock( ctx->tq_ctx, index )->thread;
  }

  static const rtems_tcb *GetTCB( Context *ctx, TQWorkerKind worker )
  {
    return ctx->tq_ctx->worker_tcb[ worker ];
  }

  static void Tick( void *arg )
  {
    Context *ctx;

    ctx = arg;
    TQSchedulerRecordStart( ctx->tq_ctx );
    FinalClockTick();
    TQSchedulerRecordStop( ctx->tq_ctx );
  }

  static void SchedulerBlock(
    void                    *arg,
    const T_scheduler_event *event,
    T_scheduler_when         when
  )
  {
    Context *ctx;

    ctx = arg;

    if (
      when == T_SCHEDULER_BEFORE &&
      event->operation == T_SCHEDULER_BLOCK
    ) {
      T_scheduler_set_event_handler( NULL, NULL );
      ctx->request.handler = Tick;
      CallWithinISRSubmit( &ctx->request );
    }
  }

  static void ThreadTimeout( void *arg )
  {
    Context *ctx;

    ctx = arg;
    TQSchedulerRecordStart( ctx->tq_ctx );
    _Thread_Timeout(
      &ctx->tq_ctx->worker_tcb[ TQ_BLOCKER_A ]->Timer.Watchdog
    );
    TQSchedulerRecordStop( ctx->tq_ctx );
  }

  static void SchedulerUnblock(
    void                    *arg,
    const T_scheduler_event *event,
    T_scheduler_when         when
  )
  {
    Context *ctx;

    ctx = arg;

    if (
      when == T_SCHEDULER_BEFORE &&
      event->operation == T_SCHEDULER_UNBLOCK
    ) {
      T_scheduler_set_event_handler( NULL, NULL );
      ctx->request.handler = ThreadTimeout;
      CallWithinISRSubmit( &ctx->request );
    }
  }
test-target: testsuites/validation/tr-tq-timeout.c
test-teardown:
  brief: null
  code: |
    TQReset( ctx->tq_ctx );
  description: null
text: |
  When the thread queue enqueue operation timed out.
transition-map:
- enabled-by: true
  post-conditions:
    Status: Timeout
    Unblock: 'Yes'
  pre-conditions:
    WaitState:
    - Blocked
- enabled-by: true
  post-conditions:
    Status: Timeout
    Unblock: 'No'
  pre-conditions:
    WaitState:
    - IntendToBlock
- enabled-by: true
  post-conditions:
    Status: Ok
    Unblock: 'No'
  pre-conditions:
    WaitState:
    - ReadyAgain
type: requirement