summaryrefslogtreecommitdiffstats
path: root/spec/rtems/ratemon/req/cancel.yml
blob: ecfaef34fe260a5bcfca27d602880e6308dee84d (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
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/cancel
post-conditions:
- name: Status
  states:
  - name: Ok
    test-code: |
      T_rsc_success( ctx->status );
    text: |
      The return status of ${../if/cancel:/name} shall be
      ${../../status/if/successful:/name}
  - name: InvId
    test-code: |
      T_rsc( ctx->status, RTEMS_INVALID_ID );
    text: |
      The return status of ${../if/cancel:/name} shall be
      ${../../status/if/invalid-id:/name}.
  - name: NotOwn
    test-code: |
      T_rsc( ctx->status, RTEMS_NOT_OWNER_OF_RESOURCE );
    text: |
      The return status of ${../if/cancel:/name} shall be
      ${../../status/if/not-owner-of-resource:/name}.
  test-epilogue: null
  test-prologue: null
- name: State
  states:
  - name: Inactive
    test-code: |
      T_eq_int( ctx->period_status.state, RATE_MONOTONIC_INACTIVE );
    text: |
      The ${../glossary/state:/term} of the period shall be
      ${../glossary/inactive:/term} after the return of the
      ${../if/cancel:/name} call.
  - name: Nop
    test-code: |
      T_eq_u32( ctx->period_status.state, ctx->previous_state );
    text: |
      Objects referenced by the ${../if/cancel:/params[0]/name}
      parameter in past calls to ${../if/cancel:/name} shall not be
      accessed by the ${../if/cancel:/name} call (see also
      ${../glossary/nop:/term}).
  test-epilogue: null
  test-prologue: null
- name: Postponed
  states:
  - name: Zero
    test-code: |
      T_eq_u32( ctx->period_status.postponed_jobs_count, 0 );
    text: |
      There shall be no ${../glossary/postponedjob:/plural}
      after the return of the ${../if/cancel:/name} call.
  - name: Nop
    test-code: |
      T_eq_u32( ctx->period_status.postponed_jobs_count,
        ctx->postponed_jobs_count );
    text: |
      Objects referenced by the ${../if/cancel:/params[0]/name}
      parameter in past calls to ${../if/cancel:/name} shall not be
      accessed by the ${../if/cancel:/name} call (see also
      ${../glossary/nop:/term}).
  test-epilogue: null
  test-prologue: null
- name: Scheduler
  states:
  - name: Called
    test-code: |
      /* Cannot be tested as the effect is unknown. */
    text: |
      The last call of the ${../if/cancel:/name} function shall execute
      the ``cancel_job`` ${../glossary/scheduleroperation:/term} of the
      ${/glossary/scheduler-home:/term}.
  - name: Nop
    test-code: |
      /* Cannot be tested as the effect is unknown. */
    text: |
      The last call of the ${../if/cancel:/name} function shall not execute
      any ${../glossary/scheduleroperation:/term}.
  test-epilogue: null
  test-prologue: null
pre-conditions:
- name: Id
  states:
  - name: Valid
    test-code: |
      ctx->id_param = ctx->period_id;
    text: |
      While the ${../if/cancel:/params[0]/name} parameter is valid.
  - name: Invalid
    test-code: |
      ctx->id_param = RTEMS_ID_NONE;
    text: |
      While the ${../if/cancel:/params[0]/name} parameter is invalid.
  test-epilogue: null
  test-prologue: null
- name: Caller
  states:
  - name: OwnerTask
    test-code: |
      ctx->do_action = Action;
    text: |
      While the ${/glossary/task:/term} invoking ${../if/cancel:/name} is
      the ${/glossary/task:/term} which created the period -
      the ${../glossary/ownertask:/term}.
  - name: OtherTask
    test-code: |
      ctx->do_action = WorkerTaskAction;
    text: |
      While the ${/glossary/task:/term} invoking ${../if/cancel:/name} is not
      the ${../glossary/ownertask:/term}.
  test-epilogue: null
  test-prologue: null
- name: State
  states:
  - name: Inactive
    test-code: |
      /* Nothing to do here as the period is newly created. */
      ctx->previous_state = RATE_MONOTONIC_INACTIVE;
    text: |
      While the ${../if/cancel:/params[0]/name} parameter references an
      period object in ${../glossary/inactive:/term}
      ${../glossary/state:/term}.
  - name: Active
    test-code: |
      rtems_status_code status;
      status = rtems_rate_monotonic_period( ctx->period_id, period_length );
      T_rsc_success( status );
      ctx->previous_state = RATE_MONOTONIC_ACTIVE;
    text: |
      While the ${../if/cancel:/params[0]/name} parameter references an
      period object in ${../glossary/active:/term} ${../glossary/state:/term}.
  - name: Expired
    test-code: |
      rtems_status_code status;
      status = rtems_rate_monotonic_period( ctx->period_id, period_length );
      T_rsc_success( status );
      ctx->previous_state = RATE_MONOTONIC_EXPIRED;
    text: |
      While the ${../if/cancel:/params[0]/name} parameter references an
      period object in ${../glossary/expired:/term}
      ${../glossary/state:/term}.
  test-epilogue: null
  test-prologue: null
- name: Postponed
  states:
  - name: Zero
    test-code:  |
      ctx->postponed_jobs_count = 0;
    text: |
      While the period is not in ${../glossary/expired:/term}
      ${../glossary/state:/term}.
  - name: One
    test-code: |
      CreatePostponedJobs( ctx, 1 );
    text: |
      While there is one ${../glossary/postponedjob:/term}.
  - name: Several
    test-code: |
      CreatePostponedJobs( ctx, 5 );
    text: |
      While there are two or more ${../glossary/postponedjob:/plural}.
  test-epilogue: null
  test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons:
  NotInInactiveState: |
    ${../glossary/postponedjob:/plural} do not exist in
    ${../glossary/inactive:/term} ${../glossary/state:/term}.
  NeverInExpiredState: |
    There must be ${../glossary/postponedjob:/plural} in
    ${../glossary/expired:/term} ${../glossary/state:/term}.
test-action: |
  rtems_status_code status;

  ctx->do_action( ctx );

  status = rtems_rate_monotonic_get_status(
    ctx->period_id,
    &ctx->period_status
  );
  T_rsc_success( status );
test-brief: null
test-cleanup: |
  T_rsc_success( rtems_rate_monotonic_delete( ctx->period_id ) );
test-context:
- brief: |
    This member contains a valid identifier of a period.
  description: null
  member: |
    rtems_id period_id
- brief: |
    This member is used to receive the ${../if/period-status:/name}
    after the action.
  description: null
  member: |
    rtems_rate_monotonic_period_status period_status
- brief: |
    This member specifies the ${../if/cancel:/params[0]/name} parameter
    for the action.
  description: null
  member: |
    rtems_id id_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 pointer to the function which executes the action.
  description: |
    The action is either executed by the ${../glossary/ownertask:/term}
    or by the worker ${/glossary/task:/term} depending on the function pointer
    used here.  ``argument`` is a pointer to this context structure.
  member: |
    void ( *do_action )( void *ctx )
- brief: |
    This member contains the ${/glossary/task:/term} identifier of the
    ${../glossary/ownertask:/term}.
  description: null
  member: |
    rtems_id task_id
- brief: |
    This member contains the ${/glossary/task:/term} identifier of the
    worker ${/glossary/task:/term} (which is not the
    ${../glossary/ownertask:/term}).
  description: null
  member: |
    rtems_id worker_id
- brief: |
    This member contains a backup of the ${/glossary/priority-task:/term}
    before the execution of this test.
  description: null
  member: |
    rtems_id original_priority
- brief: |
    This member contains the number of ${../glossary/postponedjob:/plural}
    before the action.
  description: null
  member: |
    uint32_t postponed_jobs_count
- brief: |
    This member contains the ${../glossary/state:/term}
    before the action.
  description: null
  member: |
    rtems_rate_monotonic_period_states previous_state
test-context-support: null
test-description: null
test-header: null
test-includes:
- rtems.h
test-local-includes:
- tx-support.h
test-prepare: |
  rtems_status_code status;
  status =  rtems_rate_monotonic_create(
    rtems_build_name( 'R', 'M', 'O', 'N' ),
    &ctx->period_id
  );
  T_rsc_success( status );

  ctx->postponed_jobs_count = 0;
test-setup:
  brief: null
  code: |
    rtems_status_code status;
    rtems_task_priority priority;
    rtems_event_set event_set;
    ctx->worker_id = RTEMS_INVALID_ID;

    status = rtems_task_ident(
      RTEMS_SELF,
      RTEMS_SEARCH_ALL_NODES,
      &ctx->task_id
    );
    T_rsc_success( status );

    status = rtems_task_set_priority(
      RTEMS_SELF,
      RTEMS_CURRENT_PRIORITY,
      &ctx->original_priority
    );
    T_rsc_success( status );

    status = rtems_task_set_priority(
      RTEMS_SELF,
      background_task_priority,
      &priority
    );
    T_rsc_success( status );

    status = rtems_task_create(
      rtems_build_name( 'W', 'O', 'R', 'K' ),
      foreground_task_priority,
      RTEMS_MINIMUM_STACK_SIZE,
      RTEMS_DEFAULT_MODES,
      RTEMS_DEFAULT_ATTRIBUTES,
      &ctx->worker_id
    );
    T_rsc_success( status );

    /* Defensive programming: clean away any pending events */
    status = rtems_event_receive(
      RTEMS_ALL_EVENTS,
      RTEMS_NO_WAIT | RTEMS_EVENT_ANY,
      RTEMS_NO_TIMEOUT,
      &event_set
    );
    T_true( status == RTEMS_SUCCESSFUL || status == RTEMS_UNSATISFIED );

    status = rtems_task_start(
      ctx->worker_id,
      WorkerTask,
      (rtems_task_argument) NULL
    );
    T_rsc_success( status );
  description: null
test-stop: null
test-support: |
  static const rtems_interval period_length = 5;
  static const rtems_task_priority background_task_priority = 100;
  static const rtems_task_priority foreground_task_priority = 10;
  static const rtems_event_set wake_main_task_event = RTEMS_EVENT_17;

  static void TickTheClock(
    RtemsRatemonReqCancel_Context *ctx,
    uint32_t ticks
  )
  {
    uint32_t i;
    for ( i = 0; i < ticks; ++i ) {
      TimecounterTick();
    }
  }

  static void Action( void *ctx_in )
  {
    RtemsRatemonReqCancel_Context *ctx = ctx_in;
    ctx->status = rtems_rate_monotonic_cancel( ctx->id_param );
  }

  RTEMS_INLINE_ROUTINE void WorkerTask( unsigned int argument )
  {
    RtemsRatemonReqCancel_Context *ctx =
      (RtemsRatemonReqCancel_Context *) argument;

    if ( ctx != NULL ) {
      Action( ctx );
      T_rsc_success( rtems_event_send( ctx->task_id, wake_main_task_event ) );
    }

    T_rsc_success( rtems_task_suspend( RTEMS_SELF ) );
  }

  RTEMS_INLINE_ROUTINE void WorkerTaskAction( void *ctx_in )
  {
    rtems_status_code status;
    rtems_event_set event_set;
    RtemsRatemonReqCancel_Context *ctx = ctx_in;

    status = rtems_task_restart( ctx->worker_id, (rtems_task_argument) ctx );
    T_rsc_success( status );

    /* Wait till the worker task finishes */
    status = rtems_event_receive(
      wake_main_task_event,
      RTEMS_DEFAULT_OPTIONS,
      RTEMS_NO_TIMEOUT,
      &event_set
    );
    T_rsc_success( status );
  }

  static void CreatePostponedJobs(
    RtemsRatemonReqCancel_Context *ctx,
    uint32_t jobs_count
  )
  {
    rtems_status_code status;
    ctx->postponed_jobs_count = jobs_count;
    if ( ctx->previous_state == RATE_MONOTONIC_ACTIVE ) {
      TickTheClock( ctx, ( jobs_count + 1 ) * period_length );
      status = rtems_rate_monotonic_period( ctx->period_id, period_length );
      T_rsc( status, RTEMS_TIMEOUT );
    } else {
      /* ctx->previous_state == RATE_MONOTONIC_INACTIVE || _EXPIRED */
      TickTheClock( ctx, jobs_count * period_length );
    }
  }
test-target: testsuites/validation/tc-ratemon-cancel.c
test-teardown:
  brief: null
  code: |
    rtems_status_code status;
    rtems_task_priority priority;

    T_rsc_success( rtems_task_delete( ctx->worker_id ) );

    status = rtems_task_set_priority(
      RTEMS_SELF,
      ctx->original_priority,
      &priority
    );
    T_rsc_success( status );
  description: null
text: ${.:text-template}
transition-map:
- enabled-by: true
  post-conditions:
    Status: Ok
    State: Inactive
    Postponed: N/A
    Scheduler: Called
  pre-conditions:
    Id:
      - Valid
    Caller:
      - OwnerTask
    State:
      - Inactive
    Postponed: N/A
- enabled-by: true
  post-conditions:
    Status: Ok
    State: Inactive
    Postponed: Zero
    Scheduler: Called
  pre-conditions:
    Id:
      - Valid
    Caller:
      - OwnerTask
    State:
      - Active
      - Expired
    Postponed: all
- enabled-by: true
  post-conditions:
    Status: InvId
    State: Nop
    Postponed: Nop
    Scheduler: Nop
  pre-conditions:
    Id:
      - Invalid
    Caller: all
    State:
      - Inactive
    Postponed: N/A
- enabled-by: true
  post-conditions:
    Status: InvId
    State: Nop
    Postponed: Nop
    Scheduler: Nop
  pre-conditions:
    Id:
      - Invalid
    Caller: all
    State:
      - Active
      - Expired
    Postponed: all
- enabled-by: true
  post-conditions:
    Status: NotOwn
    State: Nop
    Postponed: Nop
    Scheduler: Nop
  pre-conditions:
    Id:
      - Valid
    Caller:
      - OtherTask
    State:
      - Inactive
    Postponed: N/A
- enabled-by: true
  post-conditions:
    Status: NotOwn
    State: Nop
    Postponed: Nop
    Scheduler: Nop
  pre-conditions:
    Id:
      - Valid
    Caller:
      - OtherTask
    State:
      - Active
      - Expired
    Postponed: all
- enabled-by: true
  post-conditions: NotInInactiveState
  pre-conditions:
    Id: all
    Caller: all
    State:
      - Inactive
    Postponed:
      - One
      - Several
- enabled-by: true
  post-conditions: NeverInExpiredState
  pre-conditions:
    Id: all
    Caller: all
    State:
      - Expired
    Postponed:
      - Zero
type: requirement