summaryrefslogtreecommitdiffstats
path: root/spec/score/tq/req/flush-priority-inherit.yml
blob: 6c0f84d4aee2591f356db3f0f9027cb9bc997a04 (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
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: requirement-refinement
  uid: ../if/group
- role: validation
  uid: flush-filter
- role: validation
  uid: flush-remove-timer
- role: validation
  uid: flush-unblock
post-conditions:
- name: Extract
  states:
  - name: Nop
    test-code: |
      /* Event receive */
      T_eq_ptr( GetUnblock( ctx, &i )->thread, GetTCB( ctx, TQ_BLOCKER_A ) );
      T_eq_ptr( GetPriorityUpdate( ctx, &i ), &T_scheduler_event_null );
    text: |
      No operation shall be performed.
  - name: All
    test-code: |
      event = GetUnblock( ctx, &i );
      T_eq_ptr( event->executing, NULL );
      T_eq_ptr( event->thread, GetTCB( ctx, TQ_BLOCKER_D ) );

      event = GetUnblock( ctx, &i );
      T_eq_ptr( event->executing, NULL );
      T_eq_ptr( event->thread, GetTCB( ctx, TQ_BLOCKER_C ) );

      if ( ctx->minimum ) {
        /*
         * This priority update is carried out by
         * _Thread_queue_Flush_critical().
         */
        event = GetPriorityUpdate( ctx, &i );
        T_eq_ptr( event->executing, NULL );
        T_eq_ptr( event->thread, GetTCB( ctx, TQ_BLOCKER_A ) );
      }

      event = GetUnblock( ctx, &i );
      T_eq_ptr( event->executing, GetTCB( ctx, TQ_BLOCKER_B ) );
      T_eq_ptr( event->thread, GetTCB( ctx, TQ_BLOCKER_B ) );

      if ( ctx->minimum && rtems_configuration_get_maximum_processors() > 1 ) {
        /*
         * This superfluous priority update is carried out by
         * _Thread_queue_Enqueue() since TQ_BLOCKER_B would have inherited its
         * priority for scheduler B to TQ_BLOCKER_A if it were not flushed from
         * the thread queue.
         */
        event = GetPriorityUpdate( ctx, &i );
        T_eq_ptr( event->executing, GetTCB( ctx, TQ_BLOCKER_B ) );
        T_eq_ptr( event->thread, GetTCB( ctx, TQ_BLOCKER_A ) );
      }

      event = GetPriorityUpdate( ctx, &i );
      T_eq_ptr( event, &T_scheduler_event_null );

      T_eq_u32(
        GetPriority( ctx->tq_ctx->worker_id[ TQ_BLOCKER_A ] ),
        PRIO_HIGH
      );
    text: |
      The enqueued threads of the thread queue shall be extracted in
      ${/glossary/priority:/term} order for each priority queue associated with
      a scheduler.  The priority queues of the thread queue shall be accessed
      in ${/glossary/fifo:/term} order.
  test-epilogue: null
  test-prologue: |
    size_t                   i;
    const T_scheduler_event *event;

    i = 0;
- name: PriorityUpdate
  states:
  - name: 'No'
    test-code: |
      /* Checked by ``Extract`` post-condition state ``Nop`` */
    text: |
      The ${/glossary/priority-current:/term} of the owner of the thread queue
      shall not be updated by the thread queue flush operation.
  - name: 'Yes'
    test-code: |
      /* Checked by ``Extract`` post-condition state ``All`` */
    text: |
      The ${/glossary/priority-current:/term} of the owner of the thread queue
      shall be updated by the thread queue flush operation to reflect the loss
      of inherited priorities of the flushed threads.
  test-epilogue: null
  test-prologue: null
pre-conditions:
- name: Priority
  states:
  - name: Minimum
    test-code: |
      ctx->minimum = true;
    text: |
      While a minimum priority of the owner of the thread queue is inherited
      from a thread enqueued on the thread queue.
  - name: NotMinimum
    test-code: |
      ctx->minimum = false;
    text: |
      While no minimum priority of the owner of the thread queue is inherited
      from a thread enqueued on the thread queue.
  test-epilogue: null
  test-prologue: null
- name: Queue
  states:
  - name: Empty
    test-code: |
      ctx->tq_ctx->how_many = 0;
    text: |
      While the thread queue is empty.
  - name: NonEmpty
    test-code: |
      ctx->tq_ctx->how_many = 3;
    text: |
      While the thread queue has at least one enqueued thread.
  test-epilogue: null
  test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons: {}
test-action: |
  TQSend( ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_ENQUEUE_PREPARE );

  if ( ctx->tq_ctx->how_many > 0 ) {
    if ( ctx->minimum ) {
      if ( rtems_configuration_get_maximum_processors() > 1 ) {
        TQSetScheduler( ctx->tq_ctx, TQ_BLOCKER_B, SCHEDULER_B_ID, PRIO_HIGH );
      } else {
        TQSetScheduler( ctx->tq_ctx, TQ_BLOCKER_B, SCHEDULER_A_ID, PRIO_HIGH );
      }

      TQSetPriority( ctx->tq_ctx, TQ_BLOCKER_C, PRIO_VERY_HIGH );
      TQSetPriority( ctx->tq_ctx, TQ_BLOCKER_D, PRIO_ULTRA_HIGH );
      TQSend( ctx->tq_ctx, TQ_BLOCKER_C, TQ_EVENT_ENQUEUE );
      TQSend( ctx->tq_ctx, TQ_BLOCKER_D, TQ_EVENT_ENQUEUE );
    } else {
      TQSetScheduler( ctx->tq_ctx, TQ_BLOCKER_B, SCHEDULER_A_ID, PRIO_HIGH );
      TQSetPriority( ctx->tq_ctx, TQ_BLOCKER_C, PRIO_HIGH );
      TQSetPriority( ctx->tq_ctx, TQ_BLOCKER_D, PRIO_HIGH );

      TQSend( ctx->tq_ctx, TQ_BLOCKER_D, TQ_EVENT_ENQUEUE );
      TQSend( ctx->tq_ctx, TQ_BLOCKER_C, TQ_EVENT_ENQUEUE );
    }

    T_scheduler_set_event_handler( SchedulerEvent, ctx );
    TQSendAndWaitForExecutionStop(
      ctx->tq_ctx,
      TQ_BLOCKER_B,
      TQ_EVENT_ENQUEUE
    );
  } else {
    TQSchedulerRecordStart( ctx->tq_ctx );
    TQSend( ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_FLUSH_ALL );
  }

  TQSchedulerRecordStop( ctx->tq_ctx );
  TQSend( ctx->tq_ctx, TQ_BLOCKER_A, TQ_EVENT_ENQUEUE_DONE );
test-brief: null
test-cleanup: null
test-context:
- brief: |
    This member contains the call within ISR request.
  description: null
  member: |
    CallWithinISRRequest request;
- brief: |
    If this member is true, then a minimum priority of the owner of the thread
    queue shall be inherited from a thread enqueued on the thread queue.
  description: null
  member: |
    bool minimum
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-flush-priority-inherit.h
test-includes: []
test-local-includes:
- tx-support.h
- tr-tq-flush-priority-inherit.h
test-prepare: null
test-setup:
  brief: null
  code: |
    TQReset( ctx->tq_ctx );
    TQSetPriority( ctx->tq_ctx, TQ_BLOCKER_A, PRIO_HIGH );
  description: null
test-stop: null
test-support: |
  typedef ${.:/test-context-type} Context;

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

  static const T_scheduler_event *GetPriorityUpdate( Context *ctx, size_t *index )
  {
    return T_scheduler_next(
      &ctx->tq_ctx->scheduler_log.header,
      T_SCHEDULER_UPDATE_PRIORITY,
      index
    );
  }

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

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

    ctx = arg;
    TQSchedulerRecordStart( ctx->tq_ctx );
    TQFlush( ctx->tq_ctx, true );
  }

  static void SchedulerEvent(
    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
    ) {
      ctx->request.handler = Flush;
      ctx->request.arg = ctx;
      CallWithinISRSubmit( &ctx->request );
      T_scheduler_set_event_handler( NULL, NULL );
    }
  }
test-target: testsuites/validation/tr-tq-flush-priority-inherit.c
test-teardown:
  brief: null
  code: |
    TQReset( ctx->tq_ctx );
  description: null
text: |
  When the ${/glossary/priority:/term} thread queue with support for
  ${/glossary/priorityinheritance:/term} is flushed.
transition-map:
- enabled-by: true
  post-conditions:
    Extract: Nop
    PriorityUpdate: 'No'
  pre-conditions:
    Queue:
    - Empty
    Priority: N/A
- enabled-by: true
  post-conditions:
    Extract: All
    PriorityUpdate: 'No'
  pre-conditions:
    Queue:
    - NonEmpty
    Priority:
    - NotMinimum
- enabled-by: true
  post-conditions:
    Extract: All
    PriorityUpdate: 'Yes'
  pre-conditions:
    Queue:
    - NonEmpty
    Priority:
    - Minimum
type: requirement