summaryrefslogtreecommitdiffstats
path: root/spec/c/req/clock-nanosleep.yml
blob: aea335b1a70cc1dcdac59f4ea2fb8c19e8f1e534 (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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
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: interface-function
  uid: ../if/clock-nanosleep
post-conditions:
- name: Status
  states:
  - name: Zero
    test-code: |
      T_eq_int( ctx->status, 0 );
    text: |
      The return value of ${../if/clock-nanosleep:/name} shall be equal to zero.
  - name: ENOTSUP
    test-code: |
      T_eq_int( ctx->status, ENOTSUP );
    text: |
      The return value of ${../if/clock-nanosleep:/name} shall be equal to
      ${../if/enotsup:/name}.
  - name: EINVAL
    test-code: |
      T_eq_int( ctx->status, EINVAL );
    text: |
      The return value of ${../if/clock-nanosleep:/name} shall be equal to
      ${../if/einval:/name}.
  test-epilogue: null
  test-prologue: null
- name: Timer
  states:
  - name: Inactive
    test-code: |
      T_eq_int( ctx->timer_info.state, TASK_TIMER_INACTIVE );
    text: |
      The timer of the calling task shall be inactive.
  - name: Monotonic
    test-code: |
      T_eq_int( ctx->timer_info.state, TASK_TIMER_MONOTONIC );
    text: |
      The timer of the calling task shall be active using the
      ${/glossary/clock-monotonic:/term}.
  - name: Realtime
    test-code: |
      T_eq_int( ctx->timer_info.state, TASK_TIMER_REALTIME );
    text: |
      The timer of the calling task shall be active using the
      ${/glossary/clock-realtime:/term}.
  test-epilogue: null
  test-prologue: null
- name: Expire
  states:
  - name: Last
    test-code: |
      T_eq_u64( ctx->timer_info.expire_ticks, 0xffffffffffffffff );
    text: |
      The timer of the calling task shall expire at the last valid time point
      of the clock specified by the ``clock_id`` parameter.
  - name: Absolute
    test-code: |
      T_eq_i64( ctx->timer_info.expire_timespec.tv_sec, ctx->rqtp_obj.tv_sec );
      T_eq_long(
        ctx->timer_info.expire_timespec.tv_nsec,
        ctx->rqtp_obj.tv_nsec
      );
    text: |
      The timer of the calling task shall expire at the time point specified by
      the ``rqtp`` parameter.
  - name: Relative
    test-code: |
      expire = ctx->now_monotonic;
      expire.tv_sec += ctx->rqtp_obj.tv_sec;
      expire.tv_nsec += ctx->rqtp_obj.tv_nsec;

      if ( expire.tv_nsec >= 1000000000 ) {
        ++expire.tv_sec;
        expire.tv_nsec -= 1000000000;
      }

      T_eq_i64( ctx->timer_info.expire_timespec.tv_sec, expire.tv_sec );
      T_eq_long( ctx->timer_info.expire_timespec.tv_nsec, expire.tv_nsec );
    text: |
      The timer of the calling task shall expire at the time point specified by
      the sum of the current time of the clock specified by
      ${../if/clock-monotonic:/name} and the interval specified by the ``rqtp``
      parameter.
  test-epilogue: null
  test-prologue: |
    struct timespec expire;
- name: Scheduler
  states:
  - name: Block
    test-code: |
      T_eq_sz( ctx->scheduler_log.header.recorded, 1 );
      T_eq_int(
        ctx->scheduler_log.events[ 0 ].operation,
        T_SCHEDULER_BLOCK
      );
    text: |
      The calling task shall be blocked by the scheduler exactly once by the
      ${../if/clock-nanosleep:/name} call.
  - name: BlockUnblock
    test-code: |
      T_eq_sz( ctx->scheduler_log.header.recorded, 2 );
      T_eq_int(
        ctx->scheduler_log.events[ 0 ].operation,
        T_SCHEDULER_BLOCK
      );
      T_eq_int(
        ctx->scheduler_log.events[ 1 ].operation,
        T_SCHEDULER_UNBLOCK
      );
    text: |
      The calling task shall be blocked exactly once by the scheduler and then
      unblocked in the same thread dispatch critical section by the
      ${../if/clock-nanosleep:/name} call.
  - name: Nop
    test-code: |
      T_eq_sz( ctx->scheduler_log.header.recorded, 0 );
    text: |
      The calling task shall not be altered by the scheduler by the
      ${../if/clock-nanosleep:/name} call.
  test-epilogue: null
  test-prologue: null
- name: RMTp
  states:
  - name: Zero
    test-code: |
      T_eq_i64( ctx->rmtp_obj.tv_sec, 0 );
      T_eq_long( ctx->rmtp_obj.tv_nsec, 0 );
    text: |
      The object referenced by the ``rmtp`` parameter shall be cleared to zero
      after the return of the ${../if/clock-nanosleep:/name} call.
  - name: Nop
    test-code: |
      T_eq_i64( ctx->rmtp_obj.tv_sec, -1 );
      T_eq_long( ctx->rmtp_obj.tv_nsec, -1 );
    text: |
      Objects referenced by the ``rmtp`` parameter in past calls to
      ${../if/clock-nanosleep:/name} shall not be accessed by the
      ${../if/clock-nanosleep:/name} call.
  test-epilogue: null
  test-prologue: null
pre-conditions:
- name: ClockId
  states:
  - name: Monotonic
    test-code: |
      ctx->clock_id = CLOCK_MONOTONIC;
    text: |
      While the ``clock_id`` parameter is equal to ${../if/clock-monotonic:/name}.
  - name: Realtime
    test-code: |
      ctx->clock_id = CLOCK_REALTIME;
    text: |
      While the ``clock_id`` parameter is equal to ${../if/clock-realtime:/name}.
  - name: Invalid
    test-code: |
      ctx->clock_id = INT_MAX;
    text: |
      While the ``clock_id`` parameter is an invalid clock identifier.
  test-epilogue: null
  test-prologue: null
- name: Abstime
  states:
  - name: 'Yes'
    test-code: |
      ctx->flags |= TIMER_ABSTIME;
    text: |
      While the ``flags`` parameter indicates an absolute time.
  - name: 'No'
    test-code: |
      /* This is the default */
    text: |
      While the ``flags`` parameter does not indicate an absolute time.
  test-epilogue: null
  test-prologue: null
- name: RQTp
  states:
  - name: Valid
    test-code: |
      ctx->rqtp = &ctx->rqtp_obj;
    text: |
      While the ``rqtp`` parameter references an object of type
      ${../if/timespec:/name}.
  - name: 'Null'
    test-code: |
      ctx->rqtp = NULL;
    text: |
      While the ``rqtp`` parameter is equal to ${../if/null:/name}.
  test-epilogue: null
  test-prologue: null
- name: RQTpNSec
  states:
  - name: Valid
    test-code: |
      ctx->rqtp_obj.tv_nsec = 999999999;
    text: |
      While the ``tv_nsec`` member of the object referenced by the ``rqtp``
      parameter is a valid nanoseconds value.
  - name: Invalid
    test-code: |
      ctx->rqtp_obj.tv_nsec = -1;
    text: |
      While the ``tv_nsec`` member of the object referenced by the ``rqtp``
      parameter is an invalid nanoseconds value.
  test-epilogue: null
  test-prologue: null
- name: RQTpSec
  states:
  - name: Negative
    test-code: |
      ctx->rqtp_obj.tv_sec = -238479;
    text: |
      While the ``tv_sec`` member of the object referenced by the ``rqtp``
      parameter is negative.
  - name: FarFuture
    test-code: |
      ctx->rqtp_obj.tv_sec = INT64_MAX;
    text: |
      While the ``tv_sec`` member of the object referenced by the ``rqtp``
      parameter specifies a time point which is past the implementation limit.
  - name: Future
    test-code: |
      ctx->rqtp_obj.tv_sec = 1621322302;
    text: |
      While the ``tv_sec`` member of the object referenced by the ``rqtp``
      parameter specifies a time point which is after the current time of the
      clock specified by the ``clock_id`` parameter and is within the
      implementation limits.
  - name: PastOrNow
    test-code: |
      ctx->rqtp_obj.tv_sec = 0;

      if ( ctx->rqtp_obj.tv_nsec == 999999999 ) {
        ctx->rqtp_obj.tv_nsec = 0;
      }
    text: |
      While the ``tv_sec`` member of the object referenced by the ``rqtp``
      parameter is non-negative and specifies a time point which is before or
      at the current time of the clock specified by the ``clock_id`` parameter.
  test-epilogue: null
  test-prologue: null
- name: RMTp
  states:
  - name: Valid
    test-code: |
      ctx->rmtp = &ctx->rmtp_obj;
    text: |
      While the ``rmtp`` parameter references an object of type
      ${../if/timespec:/name}.
  - name: 'Null'
    test-code: |
      ctx->rmtp = NULL;
    text: |
      While the ``rmtp`` parameter is equal to ${../if/null:/name}.
  test-epilogue: null
  test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons:
  NeedClock: |
    The terms past and future need a clock for reference.
test-action: |
  ResumeTask( ctx->worker_id );
  (void) T_scheduler_record( NULL );
  GetTaskTimerInfo( ctx->worker_id, &ctx->timer_info );
  ClockTick();
  FinalClockTick();
test-brief: null
test-cleanup: null
test-context:
- brief: |
    This member provides the scheduler operation records.
  description: null
  member: |
    T_scheduler_log_4 scheduler_log;
- brief: |
    This member contains the CLOCK_REALTIME value before the
    ${../if/clock-nanosleep:/name} call.
  description: null
  member: |
    struct timespec now_realtime;
- brief: |
    This member contains the CLOCK_MONOTONIC value before the
    ${../if/clock-nanosleep:/name} call.
  description: null
  member: |
    struct timespec now_monotonic;
- brief: |
    This member contains the worker task identifier.
  description: null
  member: |
    rtems_id worker_id;
- brief: |
    This member contains the timer information of the worker task.
  description: null
  member: |
    TaskTimerInfo timer_info;
- brief: |
    This member provides the object referenced by the ``rqtp`` parameter.
  description: null
  member: |
    struct timespec rqtp_obj
- brief: |
    This member provides the object referenced by the ``rmtp`` parameter.
  description: null
  member: |
    struct timespec rmtp_obj
- brief: |
    This member contains the return value of the ${../if/clock-nanosleep:/name}
    call.
  description: null
  member: |
    int status
- brief: |
    This member specifies the ``clock_id`` parameter value.
  description: null
  member: |
    clockid_t clock_id
- brief: |
    This member specifies the ``flags`` parameter value.
  description: null
  member: |
    int flags
- brief: |
    This member specifies the ``rqtp`` parameter value.
  description: null
  member: |
    const struct timespec *rqtp
- brief: |
    This member specifies the ``rmtp`` parameter value.
  description: null
  member: |
    struct timespec *rmtp
test-context-support: null
test-description: null
test-header: null
test-includes:
- errno.h
- limits.h
- rtems.h
- time.h
- rtems/test-scheduler.h
- rtems/score/timecounter.h
test-local-includes:
- tx-support.h
test-prepare: |
  ctx->status = -1;
  ctx->flags = 0;
  ctx->rmtp_obj.tv_sec = -1;
  ctx->rmtp_obj.tv_nsec = -1;
test-setup:
  brief: null
  code: |
    rtems_time_of_day now = { 1988, 1, 1, 0, 0, 0, 0 };
    T_rsc_success( rtems_clock_set( &now ) );
    SetSelfPriority( PRIO_NORMAL );
    ctx->worker_id = CreateTask( "WORK", PRIO_HIGH );
    StartTask( ctx->worker_id, Worker, ctx );
  description: null
test-stop: null
test-support: |
  typedef ${.:/test-context-type} Context;

  static void Worker( rtems_task_argument arg )
  {
    Context *ctx;

    ctx = (Context *) arg;

    while ( true ) {
      T_scheduler_log *log;
      uint32_t         counter;

      SuspendSelf();

      log = T_scheduler_record_4( &ctx->scheduler_log );
      T_null( log );

      counter = GetTimecountCounter();
      _Timecounter_Nanotime( &ctx->now_realtime );
      SetTimecountCounter( counter );

      counter = GetTimecountCounter();
      _Timecounter_Nanouptime( &ctx->now_monotonic );
      SetTimecountCounter( counter );

      ctx->status = clock_nanosleep(
        ctx->clock_id,
        ctx->flags,
        ctx->rqtp,
        ctx->rmtp
      );

      (void) T_scheduler_record( NULL );
    }
  }
test-target: testsuites/validation/tc-clock-nanosleep.c
test-teardown:
  brief: null
  code: |
    DeleteTask( ctx->worker_id );
    RestoreRunnerPriority();
  description: null
text: ${.:text-template}
transition-map:
- enabled-by: true
  post-conditions:
    Status: Zero
    Timer:
    - if:
       pre-conditions:
         RQTpSec:
         - Negative
         - PastOrNow
      then: Inactive
    - specified-by: ClockId
    Expire:
    - if:
       pre-conditions:
         RQTpSec:
         - Negative
         - PastOrNow
      then: N/A
    - if:
       pre-conditions:
         RQTpSec: FarFuture
      then: Last
    - else: Absolute
    Scheduler:
    - if:
       pre-conditions:
         RQTpSec:
         - Negative
         - PastOrNow
      then: BlockUnblock
    - else: Block
    RMTp: Nop
  pre-conditions:
    ClockId:
    - Monotonic
    - Realtime
    Abstime:
    - 'Yes'
    RQTp:
    - Valid
    RQTpSec: all
    RQTpNSec:
    - Valid
    RMTp: all
- enabled-by: true
  post-conditions:
    Status: Zero
    Timer:
    - if:
       pre-conditions:
         RQTpSec: PastOrNow
      then: Inactive
    - else: Monotonic
    Expire:
    - if:
       pre-conditions:
         RQTpSec: PastOrNow
      then: N/A
    - if:
       pre-conditions:
         RQTpSec: FarFuture
      then: Last
    - else: Relative
    Scheduler:
    - if:
       pre-conditions:
         RQTpSec: PastOrNow
      then: BlockUnblock
    - else: Block
    RMTp:
    - if:
        pre-conditions:
          RMTp: Valid
      then: Zero
    - else: Nop
  pre-conditions:
    ClockId:
    - Monotonic
    - Realtime
    Abstime:
    - 'No'
    RQTp:
    - Valid
    RQTpSec:
    - FarFuture
    - Future
    - PastOrNow
    RQTpNSec:
    - Valid
    RMTp: all
- enabled-by: true
  post-conditions:
    Status: ENOTSUP
    Timer: Inactive
    Expire: N/A
    Scheduler: Nop
    RMTp: Nop
  pre-conditions:
    ClockId:
    - Invalid
    Abstime: all
    RQTp:
    - Valid
    RQTpSec: all
    RQTpNSec: all
    RMTp: all
- enabled-by: true
  post-conditions:
    Status: ENOTSUP
    Timer: Inactive
    Expire: N/A
    Scheduler: Nop
    RMTp: Nop
  pre-conditions:
    ClockId:
    - Invalid
    Abstime: all
    RQTp:
    - 'Null'
    RQTpSec: N/A
    RQTpNSec: N/A
    RMTp: all
- enabled-by: true
  post-conditions:
    Status: EINVAL
    Timer: Inactive
    Expire: N/A
    Scheduler: BlockUnblock
    RMTp:
    - if:
        pre-conditions:
          Abstime: 'No'
          RMTp: Valid
      then: Zero
    - else: Nop
  pre-conditions:
    ClockId:
    - Monotonic
    - Realtime
    Abstime: all
    RQTp:
    - 'Null'
    RQTpSec: N/A
    RQTpNSec: N/A
    RMTp: all
- enabled-by: true
  post-conditions:
    Status: EINVAL
    Timer: Inactive
    Expire: N/A
    Scheduler: BlockUnblock
    RMTp:
    - if:
        pre-conditions:
          Abstime: 'No'
          RMTp: Valid
      then: Zero
    - else: Nop
  pre-conditions:
    ClockId:
    - Monotonic
    - Realtime
    Abstime: all
    RQTp:
    - Valid
    RQTpSec: all
    RQTpNSec:
    - Invalid
    RMTp: all
- enabled-by: true
  post-conditions:
    Status: EINVAL
    Timer: Inactive
    Expire: N/A
    Scheduler: BlockUnblock
    RMTp:
    - if:
        pre-conditions:
          RMTp: Valid
      then: Zero
    - else: Nop
  pre-conditions:
    ClockId:
    - Monotonic
    - Realtime
    Abstime:
    - 'No'
    RQTp:
    - Valid
    RQTpSec:
    - Negative
    RQTpNSec:
    - Valid
    RMTp: all
- enabled-by: true
  post-conditions: NeedClock
  pre-conditions:
    ClockId:
    - Invalid
    Abstime: all
    RQTp:
    - Valid
    RQTpSec:
    - Future
    - PastOrNow
    RQTpNSec: all
    RMTp: all
type: requirement