summaryrefslogtreecommitdiffstats
path: root/spec/rtems/clock/req/set.yml
blob: 216b435e5acb8f666e872cc3d8dd524384360cc1 (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
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/set
post-conditions:
- name: Status
  states:
  - name: Ok
    test-code: |
      T_rsc_success( ctx->status );
    text: |
      The return status of ${../if/set:/name} shall be
      ${../../status/if/successful:/name}
  - name: InvAddr
    test-code: |
      T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
    text: |
      The return status of ${../if/set:/name} shall be
      ${../../status/if/invalid-address:/name}.
  - name: InvClk
    test-code: |
      T_rsc( ctx->status, RTEMS_INVALID_CLOCK );
    text: |
      The return status of ${../if/set:/name} shall be
      ${../../status/if/invalid-clock:/name}.
  test-epilogue: null
  test-prologue: null
- name: Clock
  states:
  - name: Set
    test-code: |
      T_eq_ptr( ctx->target_tod, &ctx->target_tod_value );
      T_rsc_success( ctx->get_tod_after_status );
      T_eq_u32( ctx->tod_after.year, ctx->target_tod_value.year );
      T_eq_u32( ctx->tod_after.month, ctx->target_tod_value.month );
      T_eq_u32( ctx->tod_after.day, ctx->target_tod_value.day );
      T_eq_u32( ctx->tod_after.hour, ctx->target_tod_value.hour );
      T_eq_u32( ctx->tod_after.minute, ctx->target_tod_value.minute );
      T_eq_u32( ctx->tod_after.second, ctx->target_tod_value.second );
      T_ge_u32( ctx->tod_after.ticks, ctx->target_tod_value.ticks );
      T_lt_u32( ctx->tod_after.ticks,
        ctx->target_tod_value.ticks + ctx->grace_ticks );
    text: |
      The ${/glossary/clock-realtime:/term} shall be set
      to the values of the object referenced by the
      ${../if/set:/params[0]/name} parameter during
      the ${../if/set:/name} call.
  - name: Unchanged
    test-code: |
      T_rsc_success( ctx->get_tod_before_status );
      T_eq_u32( ctx->tod_after.year, ctx->tod_before.year );
      T_eq_u32( ctx->tod_after.month, ctx->tod_before.month );
      T_eq_u32( ctx->tod_after.day, ctx->tod_before.day );
      T_eq_u32( ctx->tod_after.hour, ctx->tod_before.hour );
      T_eq_u32( ctx->tod_after.minute, ctx->tod_before.minute );
      T_eq_u32( ctx->tod_after.second, ctx->tod_before.second );
      T_ge_u32( ctx->tod_after.ticks, ctx->tod_before.ticks );
      T_lt_u32( ctx->tod_after.ticks,
        ctx->tod_before.ticks + 2 * ctx->grace_ticks );
    text: |
      The state of the ${/glossary/clock-realtime:/term} shall not be changed
      by the ${../if/set:/name} call.
  test-epilogue: null
  test-prologue: null
- name: Timer
  states:
  - name: Triggered
    test-code: |
      T_eq_int( ctx->timer_routine_counter, 1 );
      T_eq_u32( ctx->timer_routine_tod.year, 1989 );
      T_eq_u32( ctx->timer_routine_tod.month, 1 );
      T_eq_u32( ctx->timer_routine_tod.day, 1 );
      T_eq_u32( ctx->timer_routine_tod.minute, 0 );
      T_eq_u32( ctx->timer_routine_tod.second, 0 );
      T_ge_u32( ctx->timer_routine_tod.ticks, 0 );
      T_lt_u32( ctx->timer_routine_tod.ticks, 0 + ctx->grace_ticks );
    text: |
      The timer routine shall be executed once after the
      ${/glossary/clock-realtime:/term} has been set and before
      the execution of the ${../if/set:/name} call terminates.
  - name: Uncalled
    test-code: |
      T_eq_int( ctx->timer_routine_counter, 0 );
    text: |
      The the timer routine shall not be invoked
      during the ${../if/set:/name} call.
  test-epilogue: null
  test-prologue: null
pre-conditions:
- name: ToD
  states:
  - name: Valid
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2021, 3, 11, 11, 10, 59,
        rtems_clock_get_ticks_per_second() / 2 };
    text: |
      While the ${../if/set:/params[0]/name} parameter references an
      arbitrary valid date and time between 1988-01-01T00:00:00.000000000Z and
      2105-12-31T23:59:59.999999999Z.
  - name: ValidLeap4
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2104, 2, 29, 0, 0, 0, 0 };
    text: |
      While the ${../if/set:/params[0]/name} parameter references a
      date for a leap year with the value of 29th of February.
  - name: ValidLeap100
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2100, 2, 28, 23, 59, 59, 0 };
    text: |
      While the ${../if/set:/params[0]/name} parameter references a
      date for a non-leap century year with the value of 28th of February.
  - name: ValidNoneLeap100
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2100, 3, 1, 0, 0, 0, 0 };
    text: |
      While the ${../if/set:/params[0]/name} parameter references a
      date for a non-leap century year with the value of 1st of March.
  - name: ValidLeap400
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2000, 2, 29, 0, 0, 0, 0 };
    text: |
      While the ${../if/set:/params[0]/name} parameter references a
      date for a leap year with the value of 29th of February.
  - name: Youngest
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 1988, 1, 1, 0, 0, 0, 0 };
    text: |
      While the ${../if/set:/params[0]/name} parameter references the
      youngest date and time accepted (1988-01-01T00:00:00.000000000Z).
  - name: Oldest
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2105, 12, 31, 23, 59, 59,
        rtems_clock_get_ticks_per_second() - ctx->grace_ticks };
    text: |
      While the ${../if/set:/params[0]/name} parameter references the
      oldest date and time accepted (2105-12-31T23:59:59.999999999Z).
  - name: TooJung
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 1987, 12, 31, 23, 59, 59,
        rtems_clock_get_ticks_per_second() - 1 };
    text: |
      While the ${../if/set:/params[0]/name} parameter references a valid
      date and time younger than 1988-01-01T00:00:00.000000000Z.
  - name: TooOld
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2106, 1, 1, 0, 0, 0, 0 };
    text: |
      While the ${../if/set:/params[0]/name} parameter references a valid
      date and time older than 2105-12-31T23:59:59.999999999Z.
  - name: InvMonth0
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2021, 0, 11, 11, 10, 59, 1 };
    text: |
      While the ${../if/set:/params[0]/name} parameter is invalid
      because the value of the month is 0.
  - name: InvMonth
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2021, 13, 11, 11, 10, 59, 1 };
    text: |
      While the ${../if/set:/params[0]/name} parameter is invalid
      because the value of the month is larger than 12.
  - name: InvDay0
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2021, 3, 0, 11, 10, 59, 1 };
    text: |
      While the ${../if/set:/params[0]/name} parameter is invalid
      because the value of the day is 0.
  - name: InvDay
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2021, 2, 29, 11, 10, 59, 1 };
    text: |
      While the ${../if/set:/params[0]/name} parameter is invalid
      because the value of the day is larger than the days of the month.
  - name: InvHour
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2021, 3, 11, 24, 10, 59, 1 };
    text: |
      While the ${../if/set:/params[0]/name} parameter is invalid
      because the value of the hour is larger than 23.
  - name: InvMinute
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2021, 3, 11, 11, 60, 59, 1 };
    text: |
      While the ${../if/set:/params[0]/name} parameter is invalid
      because the value of the minute is larger than 59.
  - name: InvSecond
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2021, 3, 11, 11, 10, 60, 1 };
    text: |
      While the ${../if/set:/params[0]/name} parameter is invalid
      because the value of the second is larger than 59.
  - name: InvTicks
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2021, 3, 11, 11, 10, 60,
        rtems_clock_get_ticks_per_second() };
    text: |
      While the ${../if/set:/params[0]/name} parameter is invalid
      because the value of the ticks are larger or equal
      to the ticks per second.
  - name: InvLeap4
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2104, 2, 30, 0, 0, 0, 0 };
    text: |
      While the ${../if/set:/params[0]/name} parameter is invalid
      because the value 30th of February does not exist in a leap year.
  - name: InvLeap100
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2100, 2, 29, 0, 0, 0, 0 };
    text: |
      While the ${../if/set:/params[0]/name} parameter is invalid
      because the value 29th of February does not exist in a non-leap year.
  - name: InvLeap400
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 2000, 2, 30, 0, 0, 0, 0 };
    text: |
      While the ${../if/set:/params[0]/name} parameter is invalid
      because the value 30th of February does not exist in a leap year.
  - name: AtTimer
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 1989, 1, 1, 0, 0, 0, 0 };
      _TOD_prepare_timer( ctx );
    text: |
      While the ${../if/set:/params[0]/name} parameter references the
      same point in time when a timer should fire.
  - name: BeforeTimer
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 1988, 12, 31, 23, 59, 59, 0 };
      _TOD_prepare_timer( ctx );
    text: |
      While the ${../if/set:/params[0]/name} parameter references a
      point in time before a timer should fire.
  - name: AfterTimer
    test-code: |
      ctx->target_tod_value =
        (rtems_time_of_day) { 1989, 1, 1, 1, 0, 0, 0 };
      _TOD_prepare_timer( ctx );
    text: |
      While the ${../if/set:/params[0]/name} parameter references a
      point in time after a timer should fire.
  - name: 'Null'
    test-code: |
      ctx->target_tod = NULL;
    text: |
      WHile the ${../if/set:/params[0]/name} parameter is
      ${/c/if/null:/name}.
  test-epilogue: null
  test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons: {}
test-action: |
    ctx->get_tod_before_status = rtems_clock_get_tod( &ctx->tod_before );
    ctx->status = rtems_clock_set( ctx->target_tod );
    ctx->get_tod_after_status = rtems_clock_get_tod( &ctx->tod_after );
test-brief: null
test-cleanup: null
test-context:
- brief: null
  description: null
  member: rtems_status_code status
- brief: null
  description: null
  member: rtems_time_of_day *target_tod
- brief: null
  description: null
  member: rtems_time_of_day target_tod_value
- brief: null
  description: null
  member: rtems_time_of_day tod_before
- brief: null
  description: null
  member: rtems_status_code get_tod_before_status
- brief: null
  description: null
  member: rtems_time_of_day tod_after
- brief: null
  description: null
  member: rtems_status_code get_tod_after_status
- brief: null
  description: null
  member: rtems_id timer_id
- brief: null
  description: null
  member: int timer_routine_counter
- brief: null
  description: null
  member: rtems_time_of_day timer_routine_tod
- brief: Grace period in tick which may be passed between set and get ToD.
  description: null
  member: uint32_t grace_ticks
test-context-support: null
test-description: null
test-header: null
test-includes:
- rtems.h
test-local-includes:
- tc-clock-get-tod.h
test-prepare: |
  rtems_status_code status;

  status = rtems_timer_cancel( ctx->timer_id );
  T_rsc_success( status );
  ctx->timer_routine_counter = 0;
  ctx->timer_routine_tod = (rtems_time_of_day) { 0, 0, 0, 0, 0, 0, 0 };
test-setup:
  brief: null
  code: |
    rtems_status_code status;
    rtems_name timer_name = rtems_build_name( 'T', 'M', 'R', '0' );
    ctx->timer_id = RTEMS_ID_NONE;

    /* Call rtems_clock_get_tod() once before rtems_clock_set() gets called */
    get_tod_before_set_tod( NULL );

    ctx->grace_ticks = rtems_clock_get_ticks_per_second() * GRACE_PERIOD / 1000;
    ctx->target_tod = &ctx->target_tod_value;

    status = rtems_timer_create( timer_name, &ctx->timer_id );
    T_rsc_success( status );
  description: null
test-stop: null
test-support: |
  /*
   * How much time may pass between a call to rtems_clock_set() and
   * a follow up call to rtems_clock_get_tod() in millisecond?
   */
  #define GRACE_PERIOD 5

  static rtems_timer_service_routine _TOD_timer_routine(
    rtems_id   timer_id,
    void      *user_data
  )
  {
    RtemsClockReqSet_Context *ctx = user_data;
    rtems_status_code status;
    ++ctx->timer_routine_counter;
    status = rtems_clock_get_tod( &ctx->timer_routine_tod );
    T_rsc_success( status );
  }

  static void _TOD_prepare_timer( RtemsClockReqSet_Context *ctx )
  {
    rtems_status_code status;
    rtems_time_of_day tod = { 1988, 1, 1, 0, 0, 0, 0 };

    status = rtems_clock_set( &tod );
    T_rsc_success( status );

    tod.year = 1989;
    status = rtems_timer_fire_when(
      ctx->timer_id,
      &tod,
      _TOD_timer_routine,
      ctx
    );
    T_rsc_success( status );
  }
test-target: testsuites/validation/tc-clock-set.c
test-teardown:
  brief: null
  code: |
    rtems_status_code status;

    if ( RTEMS_ID_NONE != ctx->timer_id ) {
      status = rtems_timer_delete( ctx->timer_id );
      T_rsc_success( status );
    }
  description: null
text: ${.:text-template}
transition-map:
- enabled-by: true
  post-conditions:
    Status: Ok
    Clock: Set
    Timer: Uncalled
  pre-conditions:
    ToD:
      - Valid
      - Youngest
      - Oldest
      - ValidLeap4
      - ValidLeap100
      - ValidNoneLeap100
      - ValidLeap400
      - BeforeTimer
- enabled-by: true
  post-conditions:
    Status: Ok
    Clock: Set
    Timer: Triggered
  pre-conditions:
    ToD:
      - AtTimer
      - AfterTimer
- enabled-by: true
  post-conditions:
    Status: InvAddr
    Clock: Unchanged
    Timer: Uncalled
  pre-conditions:
    ToD:
      - 'Null'
- enabled-by: true
  post-conditions:
    Status: InvClk
    Clock: Unchanged
    Timer: Uncalled
  pre-conditions:
    ToD:
      - TooJung
      - TooOld
      - InvMonth0
      - InvMonth
      - InvDay0
      - InvDay
      - InvHour
      - InvMinute
      - InvSecond
      - InvTicks
      - InvLeap4
      - InvLeap100
      - InvLeap400
type: requirement