summaryrefslogtreecommitdiffstats
path: root/spec/rtems/task/req/construct.yml
blob: 9d2f0607512c8ac1bce3618b4d2cd3216aa14837 (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
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2020, 2021 embedded brains GmbH (http://www.embedded-brains.de)
enabled-by: true
functional-type: action
links:
- role: interface-function
  uid: ../if/construct
post-conditions:
- name: Status
  states:
  - name: Ok
    test-code: |
      T_rsc_success( ctx->status );
    text: |
      The return status of ${../if/construct:/name} shall be
      ${../../status/if/successful:/name}.
  - name: InvAddr
    test-code: |
      T_rsc( ctx->status, RTEMS_INVALID_ADDRESS );
    text: |
      The return status of ${../if/construct:/name} shall be
      ${../../status/if/invalid-address:/name}.
  - name: InvName
    test-code: |
      T_rsc( ctx->status, RTEMS_INVALID_NAME );
    text: |
      The return status of ${../if/construct:/name} shall be
      ${../../status/if/invalid-name:/name}.
  - name: InvPrio
    test-code: |
      T_rsc( ctx->status, RTEMS_INVALID_PRIORITY );
    text: |
      The return status of ${../if/construct:/name} shall be
      ${../../status/if/invalid-priority:/name}.
  - name: InvSize
    test-code: |
      T_rsc( ctx->status, RTEMS_INVALID_SIZE );
    text: |
      The return status of ${../if/construct:/name} shall be
      ${../../status/if/invalid-size:/name}.
  - name: TooMany
    test-code: |
      T_rsc( ctx->status, RTEMS_TOO_MANY );
    text: |
      The return status of ${../if/construct:/name} shall be
      ${../../status/if/too-many:/name}.
  - name: Unsat
    test-code: |
      T_rsc( ctx->status, RTEMS_UNSATISFIED  );
    text: |
      The return status of ${../if/construct:/name} shall be
      ${../../status/if/unsatisfied:/name}.
  test-epilogue: null
  test-prologue: null
- name: Name
  states:
  - name: Valid
    test-code: |
      id = 0;
      sc = rtems_task_ident( NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
      T_rsc_success( sc );
      T_eq_u32( id, ctx->id_obj );
    text: |
      The unique object name shall identify the task constructed by
      the ${../if/construct:/name} call.
  - name: Invalid
    test-code: |
      sc = rtems_task_ident( NAME, RTEMS_SEARCH_LOCAL_NODE, &id );
      T_rsc( sc, RTEMS_INVALID_NAME );
    text: |
      The unique object name shall not identify a task.
  test-epilogue: null
  test-prologue: |
    rtems_status_code sc;
    rtems_id          id;
- name: IdObj
  states:
  - name: Set
    test-code: |
      T_eq_ptr( ctx->id, &ctx->id_obj );
      T_ne_u32( ctx->id_obj, INVALID_ID );
    text: |
      The value of the object referenced by the
      ${../if/construct:/params[1]/name} parameter shall be set to the object
      identifier of the constructed task after the return of the
      ${../if/construct:/name} call.
  - name: Nop
    test-code: |
      T_eq_u32( ctx->id_obj, INVALID_ID );
    text: |
      Objects referenced by the ${../if/construct:/params[1]/name} parameter in
      past calls to ${../if/construct:/name} shall not be accessed by the
      ${../if/construct:/name} call.
  test-epilogue: null
  test-prologue: null
- name: CreateNew
  states:
  - name: All
    test-code: |
      T_eq_u32( ctx->create_extension_calls, 2 );
    text: |
      The thread create user extensions shall be invoked for the task under
      construction during the ${../if/construct:/name} call.
  - name: UpToFailing
    test-code: |
      T_eq_u32( ctx->create_extension_calls, 1 );
    text: |
      The thread create user extensions up to the failing extension shall be
      invoked for the task under construction during the
      ${../if/construct:/name} call.
  - name: Nop
    test-code: |
      T_eq_u32( ctx->create_extension_calls, 0 );
    text: |
      The thread create user extensions shall not be invoked for the task under
      construction during the ${../if/construct:/name} call.
  test-epilogue: null
  test-prologue: null
- name: DeleteNew
  states:
  - name: All
    test-code: |
      T_eq_u32( ctx->delete_extension_calls, 2 );
    text: |
      The thread delete user extensions shall be invoked for the task under
      construction during the ${../if/construct:/name} call.
  - name: Nop
    test-code: |
      T_eq_u32( ctx->delete_extension_calls, 0 );
    text: |
      The thread delete user extensions shall not be invoked for the task under
      construction during the ${../if/construct:/name} call.
  test-epilogue: null
  test-prologue: null
- name: KillZombies
  states:
  - name: 'Yes'
    test-code: |
      /*
       * We cannot check the zombie delete extension calls if we should call
       * rtems_task_construct() without an inactive TCB available.  Killing
       * a zombie would make one inactive TCB available.
       */
      if ( ctx->seized_objects == NULL ) {
        T_eq_u32( ctx->delete_zombie_extension_calls, 2 );
      }
    text: |
      The registered zombie threads shall be killed before an attempt to
      allocate a ${/glossary/tcb:/term} is made by the ${../if/construct:/name}
      call.
  - name: 'No'
    test-code: |
      T_eq_u32( ctx->delete_zombie_extension_calls, 0 );
    text: |
      The registered zombie threads shall not be killed by the
      ${../if/construct:/name} call.
  test-epilogue: null
  test-prologue: null
- name: StorageFree
  states:
  - name: 'Yes'
    test-code: |
      T_eq_u32( ctx->storage_free_calls, 1 );
    text: |
      The storage free handler of the task configuration shall be invoked
      during the ${../if/construct:/name} call.
  - name: 'No'
    test-code: |
      T_eq_u32( ctx->storage_free_calls, 0 );
    text: |
      The storage free handler of the task configuration shall not be invoked
      during the ${../if/construct:/name} call.
  test-epilogue: null
  test-prologue: null
- name: FloatingPoint
  states:
  - name: 'Yes'
    test-code: |
      /* Validated by WorkerTask() */
    text: |
      Where threads have a dedicated floating-point context, the task
      constructed by the ${../if/construct:/name} call shall be able to use the
      floating-point unit.
  - name: 'No'
    test-code: |
      /* Validated by WorkerTask() */
    text: |
      Where threads have a dedicated floating-point context, the task
      constructed by the ${../if/construct:/name} call shall not be able to use
      the floating-point unit.
  test-epilogue: null
  test-prologue: null
- name: Preempt
  states:
  - name: 'Yes'
    test-code: |
      T_eq_u32( ctx->actual_modes & RTEMS_PREEMPT, RTEMS_PREEMPT );
    text: |
      Task preemption in the initial modes of the task constructed by the
      ${../if/construct:/name} call shall be enabled.
  - name: 'No'
    test-code: |
      T_eq_u32( ctx->actual_modes & RTEMS_PREEMPT, 0 );
    text: |
      Task preemption in the initial modes of the task constructed by the
      ${../if/construct:/name} call shall be disabled.
  test-epilogue: null
  test-prologue: null
- name: Timeslice
  states:
  - name: 'Yes'
    test-code: |
      T_eq_u32( ctx->actual_modes & RTEMS_TIMESLICE, RTEMS_TIMESLICE );
    text: |
      Timeslicing in the initial modes of the task constructed by the
      ${../if/construct:/name} call shall be enabled.
  - name: 'No'
    test-code: |
      T_eq_u32( ctx->actual_modes & RTEMS_TIMESLICE, 0 );
    text: |
      Timeslicing in the initial modes of the task constructed by the
      ${../if/construct:/name} call shall be disabled.
  test-epilogue: null
  test-prologue: null
- name: ASR
  states:
  - name: 'Yes'
    test-code: |
      T_eq_u32( ctx->actual_modes & RTEMS_ASR, RTEMS_ASR );
    text: |
      ASR processing in the initial modes of the task constructed by the
      ${../if/construct:/name} call shall be enabled.
  - name: 'No'
    test-code: |
      T_eq_u32( ctx->actual_modes & RTEMS_ASR, 0 );
    text: |
      ASR processing in the initial modes of the task constructed by the
      ${../if/construct:/name} call shall be disabled.
  test-epilogue: null
  test-prologue: null
- name: IntLvl
  states:
  - name: Zero
    test-code: |
      T_eq_u32( ctx->actual_modes & RTEMS_INTERRUPT_MASK, 0 );
    text: |
      The interrupt level in the initial modes of the task constructed by the
      ${../if/construct:/name} call shall be zero.
  - name: Positive
    test-code: |
      T_eq_u32(
        ctx->actual_modes & RTEMS_INTERRUPT_MASK,
        ctx->config_obj.initial_modes & RTEMS_INTERRUPT_MASK
      );
    text: |
      The interrupt level in the initial modes of the task constructed by the
      ${../if/construct:/name} call shall be the interrupt level specified by
      the initial modes of the task configuration mapped to an
      ${/glossary/target-arch:/term}-specific positive value.
  test-epilogue: null
  test-prologue: null
pre-conditions:
- name: CPUs
  states:
  - name: One
    test-code: |
      if ( rtems_scheduler_get_processor_maximum() != 1 ) {
        ${.:skip}
      }
    text: |
      Where the system does not need inter-processor interrupts,
      where the scheduler does support the no-preempt mode.
  - name: More
    test-code: |
      if ( rtems_scheduler_get_processor_maximum() == 1 ) {
        ${.:skip}
      }
    text: |
      Where the system needs inter-processor interrupts,
      where the scheduler does not support the no-preempt mode.
  test-epilogue: null
  test-prologue: null
- name: Config
  states:
  - name: Valid
    test-code: |
      ctx->config = &ctx->config_obj;
    text: |
      While the ${../if/construct:/params[0]/name} parameter references an
      object of type ${../if/config:/name}.
  - name: 'Null'
    test-code: |
      ctx->config = NULL;
    text: |
      While the ${../if/construct:/params[0]/name} parameter is
      ${/c/if/null:/name}.
  test-epilogue: null
  test-prologue: null
- name: Name
  states:
  - name: Valid
    test-code: |
      ctx->config_obj.name = NAME;
    text: |
      While the name of the task configuration is valid.
  - name: Invalid
    test-code: |
      ctx->config_obj.name = 0;
    text: |
      While the name of the task configuration is invalid.
  test-epilogue: null
  test-prologue: null
- name: Id
  states:
  - name: Valid
    test-code: |
      ctx->id = &ctx->id_obj;
    text: |
      While the ${../if/construct:/params[1]/name} parameter references an
      object of type ${../../type/if/id:/name}.
  - name: 'Null'
    test-code: |
      ctx->id = NULL;
    text: |
      While the ${../if/construct:/params[1]/name} parameter is
      ${/c/if/null:/name}.
  test-epilogue: null
  test-prologue: null
- name: SystemTask
  states:
  - name: 'Yes'
    test-code: |
      ctx->config_obj.attributes |= RTEMS_SYSTEM_TASK;
    text: |
      While the attributes of the task configuration specifies a system task.
  - name: 'No'
    test-code: |
      ctx->config_obj.attributes |= RTEMS_APPLICATION_TASK;
    text: |
      While the attributes of the task configuration specifies an application
      task.
  test-epilogue: null
  test-prologue: null
- name: Priority
  states:
  - name: Valid
    test-code: |
      ctx->config_obj.initial_priority = PRIO_HIGH;
    text: |
      While the initial priority of the task configuration is valid and
      non-zero.
  - name: Zero
    test-code: |
      ctx->config_obj.initial_priority = 0;
    text: |
      While the initial priority of the task configuration is zero.
  - name: Invalid
    test-code: |
      ctx->config_obj.initial_priority = 0xffffffff;
    text: |
      While the initial priority of the task configuration is invalid.
  test-epilogue: null
  test-prologue: null
- name: Free
  states:
  - name: 'Yes'
    test-code: |
      /* Nothing to do */
    text: |
      While the system has at least one inactive task object available.
  - name: 'No'
    test-code: |
      ctx->seized_objects = T_seize_objects( Create, ctx );
    text: |
      While the system has no inactive task object available.
  test-epilogue: null
  test-prologue: null
- name: TLS
  states:
  - name: Enough
    test-code: |
      ctx->config_obj.maximum_thread_local_storage_size = MAX_TLS_SIZE;
    text: |
      While the maximum thread-local storage size of the task configuration is
      greater than or equal to the thread-local storage size.
  - name: TooSmall
    test-code: |
      ctx->config_obj.maximum_thread_local_storage_size = 0;
    text: |
      While the maximum thread-local storage size of the task configuration is
      less than the thread-local storage size.
  test-epilogue: null
  test-prologue: null
- name: Stack
  states:
  - name: Enough
    test-code: |
      ctx->stack_size = TEST_MINIMUM_STACK_SIZE;
    text: |
      While the task stack size of the task configuration is greater than or
      equal to the configured minimum size.
  - name: TooSmall
    test-code: |
      ctx->stack_size = 0;
    text: |
      While the task stack size of the task configuration is less than the
      configured minimum size.
  test-epilogue: null
  test-prologue: null
- name: Create
  states:
  - name: Ok
    test-code: |
      ctx->create_extension_status = true;
    text: |
      While none of the thread create user extensions fails.
  - name: Error
    test-code: |
      ctx->create_extension_status = false;
    text: |
      While at least one of the thread create user extensions fails.
  test-epilogue: null
  test-prologue: null
- name: FloatingPoint
  states:
  - name: 'Yes'
    test-code: |
      ctx->config_obj.attributes |= RTEMS_FLOATING_POINT;
    text: |
      While the attributes of the task configuration specifies a floating-point
      task.
  - name: 'No'
    test-code: |
      ctx->config_obj.attributes |= RTEMS_NO_FLOATING_POINT;
    text: |
      While the attributes of the task configuration specifies a
      non-floating-point task.
  test-epilogue: null
  test-prologue: null
- name: Preempt
  states:
  - name: 'Yes'
    test-code: |
      ctx->config_obj.initial_modes |= RTEMS_PREEMPT;
    text: |
      While the initial modes of the task configuration specify that preemption
      is enabled.
  - name: 'No'
    test-code: |
      ctx->config_obj.initial_modes |= RTEMS_NO_PREEMPT;
    text: |
      While the initial modes of the task configuration specify that preemption
      is disabled.
  test-epilogue: null
  test-prologue: null
- name: Timeslice
  states:
  - name: 'Yes'
    test-code: |
      ctx->config_obj.initial_modes |= RTEMS_TIMESLICE;
    text: |
      While the initial modes of the task configuration specify that
      timeslicing is enabled.
  - name: 'No'
    test-code: |
      ctx->config_obj.initial_modes |= RTEMS_NO_TIMESLICE;
    text: |
      While the initial modes of the task configuration specify that
      timeslicing is disabled.
  test-epilogue: null
  test-prologue: null
- name: ASR
  states:
  - name: 'Yes'
    test-code: |
      ctx->config_obj.initial_modes |= RTEMS_ASR;
    text: |
      While the initial modes of the task configuration specify that ASR
      processing is enabled.
  - name: 'No'
    test-code: |
      ctx->config_obj.initial_modes |= RTEMS_NO_ASR;
    text: |
      While the initial modes of the task configuration specify that ASR
      processing is disabled.
  test-epilogue: null
  test-prologue: null
- name: IntLvl
  states:
  - name: Zero
    test-code: |
      ctx->config_obj.initial_modes |= RTEMS_INTERRUPT_LEVEL( 0 );
    text: |
      While the initial modes of the task configuration specify an interrupt
      level of zero.
  - name: Positive
    test-code: |
      ctx->config_obj.initial_modes |= RTEMS_INTERRUPT_LEVEL( 1 );
    text: |
      While the initial modes of the task configuration specify an interrupt
      level greater than zero and less than or equal to
      ${/score/cpu/if/modes-interrupt-mask:/name}.
  test-epilogue: null
  test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons:
  OnlyOneCPU: |
    Where the system is build with SMP support disabled, the system has exactly
    one processor.
test-action: |
  if ( ctx->seized_objects == NULL ) {
    PrepareZombie( ctx );
  }

  ctx->actual_modes = UINT32_MAX;
  ctx->create_extension_calls = 0;
  ctx->delete_extension_calls = 0;
  ctx->delete_zombie_extension_calls = 0;
  ctx->storage_free_calls = 0;
  ctx->config_obj.storage_size = RTEMS_TASK_STORAGE_SIZE(
    ctx->config_obj.maximum_thread_local_storage_size + ctx->stack_size,
    ctx->config_obj.attributes
  );
  ctx->status = rtems_task_construct( ctx->config, ctx->id );

  if ( ctx->status == RTEMS_SUCCESSFUL ) {
    StartTask( ctx->id_obj, WorkerTask, ctx );
  }
test-brief: null
test-cleanup: |
  if ( ctx->id_obj != INVALID_ID ) {
    rtems_status_code sc;

    sc = rtems_task_delete( ctx->id_obj );
    T_rsc_success( sc );

    ctx->id_obj = INVALID_ID;
  }

  T_surrender_objects( &ctx->seized_objects, rtems_task_delete );
test-context:
- brief: |
    This member contains the scheduler B identifier.
  description: null
  member: |
    rtems_id scheduler_b_id
- brief: |
    This member contains the thread zombie registry ticket right before the
    task exit of the zombie task.
  description: null
  member: |
    unsigned int thread_zombie_ticket
- brief: |
    If this member is true, then the zombie thread is ready to get killed.
  description: null
  member: |
    volatile bool zombie_ready;
- brief: |
    This member contains the actual modes of the constructed task.
  description: null
  member: |
    rtems_mode actual_modes
- brief: null
  description: null
  member: |
    rtems_status_code status
- brief: null
  description: null
  member: |
    const rtems_task_config *config
- brief: null
  description: null
  member: |
    rtems_task_config config_obj
- brief: null
  description: null
  member: |
    rtems_id zombie_id
- brief: null
  description: null
  member: |
    rtems_id *id
- brief: null
  description: null
  member: |
    rtems_id id_obj
- brief: null
  description: null
  member: |
    bool create_extension_status
- brief: null
  description: null
  member: |
    uint32_t create_extension_calls
- brief: null
  description: null
  member: |
    uint32_t delete_extension_calls
- brief: null
  description: null
  member: |
    uint32_t delete_zombie_extension_calls
- brief: null
  description: null
  member: |
    uint32_t storage_free_calls
- brief: null
  description: null
  member: |
    size_t stack_size
- brief: null
  description: null
  member: |
    rtems_id extension_ids[ 2 ]
- brief: null
  description: null
  member: |
    void *seized_objects
test-context-support: null
test-description: null
test-header: null
test-includes:
- rtems.h
- rtems/score/atomic.h
- rtems/score/percpu.h
- rtems/score/threadimpl.h
- string.h
test-local-includes:
- ts-config.h
- tx-support.h
test-prepare: |
  KillZombies();
  ctx->id_obj = INVALID_ID;
  memset( &ctx->config_obj, 0, sizeof( ctx->config_obj ) );
  ctx->config_obj.storage_area = task_storage,
  ctx->config_obj.storage_free = StorageFree;
test-setup:
  brief: null
  code: |
    rtems_status_code sc;
    int var;

    var = tls_object;
    RTEMS_OBFUSCATE_VARIABLE( var );
    tls_object = var;

    ctx->scheduler_b_id = INVALID_ID;
    #if defined(RTEMS_SMP)
    ctx->zombie_ready = true;
    if ( rtems_scheduler_get_processor_maximum() > 1 ) {
      sc = rtems_scheduler_ident(
        TEST_SCHEDULER_B_NAME,
        &ctx->scheduler_b_id
      );
      T_rsc_success( sc );
    }
    #endif

    sc = rtems_extension_create(
      rtems_build_name( 'E', 'X', 'T', '1' ),
      &extensions[ 0 ],
      &ctx->extension_ids[ 0 ]
    );
    T_rsc_success( sc );

    sc = rtems_extension_create(
      rtems_build_name( 'E', 'X', 'T', '2' ),
      &extensions[ 1 ],
      &ctx->extension_ids[ 1 ]
    );
    T_rsc_success( sc );

    SetSelfPriority( PRIO_NORMAL );
  description: null
test-stop: null
test-support: |
  #define NAME rtems_build_name( 'T', 'E', 'S', 'T' )

  typedef ${.:/test-context-type} Context;

  static volatile _Thread_local int tls_object;

  #define MAX_TLS_SIZE RTEMS_ALIGN_UP( 128, RTEMS_TASK_STORAGE_ALIGNMENT )

  RTEMS_ALIGNED( RTEMS_TASK_STORAGE_ALIGNMENT ) static char task_storage[
    RTEMS_TASK_STORAGE_SIZE(
      MAX_TLS_SIZE + TEST_MINIMUM_STACK_SIZE,
      RTEMS_FLOATING_POINT
    )
  ];

  static const rtems_task_config seize_task_config = {
    .name = rtems_build_name( 'S', 'I', 'Z', 'E' ),
    .initial_priority = 1,
    .storage_area = task_storage,
    .storage_size = sizeof( task_storage ),
    .maximum_thread_local_storage_size = MAX_TLS_SIZE,
    .initial_modes = RTEMS_DEFAULT_MODES,
    .attributes = RTEMS_DEFAULT_MODES
  };

  static void StorageFree( void *ptr )
  {
    T_eq_ptr( ptr, task_storage );
    ++${.:/test-context-instance}.storage_free_calls;
  }

  static rtems_status_code Create( void *arg, uint32_t *id )
  {
    Context          *ctx;
    bool              create_extension_status;
    rtems_status_code sc;

    ctx = arg;
    create_extension_status = ctx->create_extension_status;
    ctx->create_extension_status = true;
    sc = rtems_task_construct( &seize_task_config, id );
    ctx->create_extension_status = create_extension_status;

    return sc;
  }

  static bool ThreadCreate( rtems_tcb *executing, rtems_tcb *created )
  {
    (void) executing;
    (void) created;

    ++${.:/test-context-instance}.create_extension_calls;
    return ${.:/test-context-instance}.create_extension_status;
  }

  static bool SecondThreadCreate( rtems_tcb *executing, rtems_tcb *created )
  {
    (void) executing;
    (void) created;

    ++${.:/test-context-instance}.create_extension_calls;
    return true;
  }

  static void ThreadDelete( rtems_tcb *executing, rtems_tcb *deleted )
  {
    Context *ctx;

    (void) executing;

    ctx = &${.:/test-context-instance};

    if ( deleted->Object.id == ctx->zombie_id ) {
      ++ctx->delete_zombie_extension_calls;
    } else {
      ++ctx->delete_extension_calls;
    }
  }

  #if defined(RTEMS_SMP)
  static void PreemptionIntervention( void *arg )
  {
    Context     *ctx;
    unsigned int ticket;

    ctx = arg;
    T_false( ctx->zombie_ready );
    ctx->zombie_ready = true;

    do {
      ticket = _Atomic_Load_uint(
        &_Thread_Zombies.Lock.Lock.Ticket_lock.now_serving,
        ATOMIC_ORDER_RELAXED
      );
    } while ( ( ticket - ctx->thread_zombie_ticket ) < 2 );

    T_busy( 100 );
  }

  static void ThreadTerminate( rtems_tcb *executing )
  {
    Context *ctx;

    ctx = &${.:/test-context-instance};

    if (
      ctx->scheduler_b_id != INVALID_ID &&
      ctx->zombie_id == executing->Object.id
    ) {
      /*
       * We use the ticket lock of the thread zombie registry to delay the thread
       * dispatch and provoke an executing thread in
       * _Thread_Kill_zombies().  The first acquire is done in the
       * rtems_task_exit() below.  The second acquire is done in
       * _Thread_Kill_zombies().
       */
      ctx->thread_zombie_ticket = _Atomic_Fetch_add_uint(
        &_Thread_Zombies.Lock.Lock.Ticket_lock.now_serving,
        0,
        ATOMIC_ORDER_RELAXED
      );
      SetPreemptionIntervention(
        _Per_CPU_Get_snapshot(),
        PreemptionIntervention,
        ctx
      );
    }
  }
  #endif

  static const rtems_extensions_table extensions[] = {
    {
  #if defined(RTEMS_SMP)
      .thread_terminate = ThreadTerminate,
  #endif
      .thread_create = ThreadCreate,
      .thread_delete = ThreadDelete
    }, {
      .thread_create = SecondThreadCreate,
      .thread_delete = ThreadDelete
    }
  };

  static void ZombieTask( rtems_task_argument arg )
  {
    (void) arg;
    rtems_task_exit();
  }

  static void PrepareZombie( Context *ctx )
  {
    bool create_extension_status;

    create_extension_status = ctx->create_extension_status;
    ctx->create_extension_status = true;
    ctx->zombie_id = CreateTask( "ZOMB", PRIO_HIGH );
    ctx->create_extension_status = create_extension_status;
  #if defined(RTEMS_SMP)
    if ( ctx->scheduler_b_id != INVALID_ID ) {
      ctx->zombie_ready = false;
      SetScheduler( ctx->zombie_id, ctx->scheduler_b_id, PRIO_NORMAL );
    }
  #endif
    StartTask( ctx->zombie_id, ZombieTask, ctx );
  #if defined(RTEMS_SMP)
    while ( !ctx->zombie_ready ) {
      /* Wait */
    }
  #endif
  }

  static volatile double double_object;

  static RTEMS_NO_INLINE void UseFloatingPointUnit( void )
  {
    double_object = ( 123.0 * double_object + double_object / 123.0 ) / 2.0;
  }

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

    ctx = (Context *) arg;
    ctx->actual_modes = GetMode();

    /*
     * We don't validate here that we cannot use the floating-point unit if the
     * RTEMS_FLOATING_POINT attribute is not set.  This is done elsewhere.
     * Using the floating-point unit if the RTEMS_FLOATING_POINT attribute is
     * not set may result in unrecoverable fatal errors.
     */
    if ( ( ctx->config_obj.attributes & RTEMS_FLOATING_POINT ) != 0 ) {
      UseFloatingPointUnit();
    }

    SuspendSelf();
  }
test-target: testsuites/validation/tc-task-construct.c
test-teardown:
  brief: null
  code: |
    rtems_status_code sc;

    sc = rtems_extension_delete( ctx->extension_ids[ 0 ] );
    T_rsc_success( sc );

    sc = rtems_extension_delete( ctx->extension_ids[ 1 ] );
    T_rsc_success( sc );

    RestoreRunnerPriority();
  description: null
text: ${.:text-template}
transition-map:
- enabled-by: true
  post-conditions:
    Status:
    - if:
        pre-conditions:
          Config: 'Null'
      then: InvAddr
    - if:
        pre-conditions:
          Name: Invalid
      then: InvName
    - if:
        pre-conditions:
          Id: 'Null'
      then: InvAddr
    - if:
        pre-conditions:
          Priority: Zero
          SystemTask: 'No'
      then: InvPrio
    - if:
        pre-conditions:
          Priority: Invalid
      then: InvPrio
    - if:
        pre-conditions:
          Free: 'No'
      then: TooMany
    - if:
        pre-conditions:
          TLS: TooSmall
      then: InvSize
    - if:
        pre-conditions:
          Stack: TooSmall
      then: InvSize
    - if:
        pre-conditions:
          Create: Error
      then: Unsat
    - else: Ok
    Name:
    - if:
        post-conditions:
          Status: Ok
      then: Valid
    - else: Invalid
    IdObj:
    - if:
        post-conditions:
          Status: Ok
      then: Set
    - else: Nop
    CreateNew:
    - if:
        post-conditions:
          Status: Ok
      then: All
    - if:
        post-conditions:
          Status: Unsat
      then: UpToFailing
    - else: Nop
    DeleteNew:
    - if:
        post-conditions:
          Status: Unsat
      then: All
    - else: Nop
    KillZombies:
    - if:
        - pre-conditions:
            Config: Valid
            Name: Valid
            Id: Valid
            SystemTask: 'Yes'
            Priority:
            - Valid
            - Zero
        - pre-conditions:
            Config: Valid
            Name: Valid
            Id: Valid
            SystemTask: 'No'
            Priority:
            - Valid
      then: 'Yes'
    - else: 'No'
    StorageFree:
    - if:
        post-conditions:
          Status: Unsat
      then: 'Yes'
    - else: 'No'
    FloatingPoint:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: FloatingPoint
    - else: N/A
    Preempt:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: Preempt
    - else: N/A
    Timeslice:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: Timeslice
    - else: N/A
    ASR:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: ASR
    - else: N/A
    IntLvl:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: IntLvl
    - else: N/A
  pre-conditions:
    CPUs:
    - One
    Config: all
    Create: all
    Id: all
    Name: all
    SystemTask: all
    Priority: all
    Stack: all
    TLS: all
    Free: all
    FloatingPoint: all
    Preempt: all
    Timeslice: all
    ASR: all
    IntLvl: all
- enabled-by: true
  post-conditions: OnlyOneCPU
  pre-conditions:
    CPUs:
    - More
    Config: all
    Create: all
    Id: all
    Name: all
    SystemTask: all
    Priority: all
    Stack: all
    TLS: all
    Free: all
    FloatingPoint: all
    Preempt: all
    Timeslice: all
    ASR: all
    IntLvl: all
- enabled-by: CPU_ENABLE_ROBUST_THREAD_DISPATCH
  post-conditions:
    Status:
    - if:
        pre-conditions:
          Config: 'Null'
      then: InvAddr
    - if:
        pre-conditions:
          Name: Invalid
      then: InvName
    - if:
        pre-conditions:
          Id: 'Null'
      then: InvAddr
    - if:
        pre-conditions:
          Priority: Zero
          SystemTask: 'No'
      then: InvPrio
    - if:
        pre-conditions:
          Priority: Invalid
      then: InvPrio
    - if:
        pre-conditions:
          Free: 'No'
      then: TooMany
    - if:
        pre-conditions:
          TLS: TooSmall
      then: InvSize
    - if:
        pre-conditions:
          Stack: TooSmall
      then: InvSize
    - if:
        pre-conditions:
          IntLvl: Positive
      then: Unsat
    - if:
        pre-conditions:
          Create: Error
      then: Unsat
    - else: Ok
    Name:
    - if:
        post-conditions:
          Status: Ok
      then: Valid
    - else: Invalid
    IdObj:
    - if:
        post-conditions:
          Status: Ok
      then: Set
    - else: Nop
    CreateNew:
    - if:
        post-conditions:
          Status: Ok
      then: All
    - if:
        and:
          - post-conditions:
              Status: Unsat
          - pre-conditions:
              IntLvl: Zero
      then: UpToFailing
    - else: Nop
    DeleteNew:
    - if:
        post-conditions:
          Status: Unsat
      then: All
    - else: Nop
    KillZombies:
    - if:
        - pre-conditions:
            Config: Valid
            Name: Valid
            Id: Valid
            SystemTask: 'Yes'
            Priority:
            - Valid
            - Zero
        - pre-conditions:
            Config: Valid
            Name: Valid
            Id: Valid
            SystemTask: 'No'
            Priority:
            - Valid
      then: 'Yes'
    - else: 'No'
    StorageFree:
    - if:
        post-conditions:
          Status: Unsat
      then: 'Yes'
    - else: 'No'
    FloatingPoint:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: FloatingPoint
    - else: N/A
    Preempt:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: Preempt
    - else: N/A
    Timeslice:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: Timeslice
    - else: N/A
    ASR:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: ASR
    - else: N/A
    IntLvl:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: IntLvl
    - else: N/A
  pre-conditions:
    CPUs:
    - One
    Config: all
    Create: all
    Id: all
    Name: all
    SystemTask: all
    Priority: all
    Stack: all
    TLS: all
    Free: all
    FloatingPoint: all
    Preempt: all
    Timeslice: all
    ASR: all
    IntLvl: all
- enabled-by: RTEMS_SMP
  post-conditions:
    Status:
    - if:
        pre-conditions:
          Config: 'Null'
      then: InvAddr
    - if:
        pre-conditions:
          Name: Invalid
      then: InvName
    - if:
        pre-conditions:
          Id: 'Null'
      then: InvAddr
    - if:
        pre-conditions:
          Priority: Zero
          SystemTask: 'No'
      then: InvPrio
    - if:
        pre-conditions:
          Priority: Invalid
      then: InvPrio
    - if:
        pre-conditions:
          Free: 'No'
      then: TooMany
    - if:
        pre-conditions:
          TLS: TooSmall
      then: InvSize
    - if:
        pre-conditions:
          Stack: TooSmall
      then: InvSize
    - if:
        pre-conditions:
          Preempt: 'No'
      then: Unsat
    - if:
        pre-conditions:
          IntLvl: Positive
      then: Unsat
    - if:
        pre-conditions:
          Create: Error
      then: Unsat
    - else: Ok
    Name:
    - if:
        post-conditions:
          Status: Ok
      then: Valid
    - else: Invalid
    IdObj:
    - if:
        post-conditions:
          Status: Ok
      then: Set
    - else: Nop
    CreateNew:
    - if:
        post-conditions:
          Status: Ok
      then: All
    - if:
        and:
          - post-conditions:
              Status: Unsat
          - pre-conditions:
              Preempt: 'Yes'
              IntLvl: Zero
      then: UpToFailing
    - else: Nop
    DeleteNew:
    - if:
        post-conditions:
          Status: Unsat
      then: All
    - else: Nop
    KillZombies:
    - if:
        - pre-conditions:
            Config: Valid
            Name: Valid
            Id: Valid
            SystemTask: 'Yes'
            Priority:
            - Valid
            - Zero
        - pre-conditions:
            Config: Valid
            Name: Valid
            Id: Valid
            SystemTask: 'No'
            Priority:
            - Valid
      then: 'Yes'
    - else: 'No'
    StorageFree:
    - if:
        post-conditions:
          Status: Unsat
      then: 'Yes'
    - else: 'No'
    FloatingPoint:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: FloatingPoint
    - else: N/A
    Preempt:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: Preempt
    - else: N/A
    Timeslice:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: Timeslice
    - else: N/A
    ASR:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: ASR
    - else: N/A
    IntLvl:
    - if:
        post-conditions:
          Status: Ok
      then-specified-by: IntLvl
    - else: N/A
  pre-conditions:
    CPUs:
    - More
    Config: all
    Create: all
    Id: all
    Name: all
    SystemTask: all
    Priority: all
    Stack: all
    TLS: all
    Free: all
    FloatingPoint: all
    Preempt: all
    Timeslice: all
    ASR: all
    IntLvl: all
type: requirement