summaryrefslogtreecommitdiffstats
path: root/testsuites/validation/tr-mtx-surrender.c
blob: 6e27ff2bc9a70432ad572b744c636daeaa105df3 (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
/* SPDX-License-Identifier: BSD-2-Clause */

/**
 * @file
 *
 * @ingroup RTEMSTestCaseScoreMtxReqSurrender
 */

/*
 * Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * This file is part of the RTEMS quality process and was automatically
 * generated.  If you find something that needs to be fixed or
 * worded better please post a report or patch to an RTEMS mailing list
 * or raise a bug report:
 *
 * https://www.rtems.org/bugs.html
 *
 * For information on updating and regenerating please refer to the How-To
 * section in the Software Requirements Engineering chapter of the
 * RTEMS Software Engineering manual.  The manual is provided as a part of
 * a release.  For development sources please refer to the online
 * documentation at:
 *
 * https://docs.rtems.org
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "tr-mtx-surrender.h"
#include "tr-tq-surrender-mrsp.h"
#include "tr-tq-surrender-priority-inherit.h"
#include "tr-tq-surrender.h"

#include <rtems/test.h>

/**
 * @defgroup RTEMSTestCaseScoreMtxReqSurrender spec:/score/mtx/req/surrender
 *
 * @ingroup RTEMSTestSuiteTestsuitesValidationNoClock0
 *
 * @{
 */

typedef struct {
  uint32_t Skip : 1;
  uint32_t Pre_Protocol_NA : 1;
  uint32_t Pre_Discipline_NA : 1;
  uint32_t Pre_Recursive_NA : 1;
  uint32_t Pre_OwnerCheck_NA : 1;
  uint32_t Pre_Owner_NA : 1;
  uint32_t Pre_Nested_NA : 1;
  uint32_t Pre_Blocked_NA : 1;
  uint32_t Pre_Priority_NA : 1;
  uint32_t Post_Status : 2;
  uint32_t Post_Owner : 3;
  uint32_t Post_Surrender : 3;
  uint32_t Post_Priority : 2;
} ScoreMtxReqSurrender_Entry;

/**
 * @brief Test context for spec:/score/mtx/req/surrender test case.
 */
typedef struct {
  /**
   * @brief If this member is true, then the calling thread shall be the owner
   *   of the mutex.
   */
  bool owner_caller;

  /**
   * @brief If this member is true, then a thread other than the calling thread
   *   shall be the owner of the mutex.
   */
  bool owner_other;

  /**
   * @brief If this member is true, then the calling thread shall have seized
   *   the mutex recursively.
   */
  bool nested;

  /**
   * @brief If this member is true, then there shall be a thread blocked
   *   waiting for the mutex.
   */
  bool blocked;

  /**
   * @brief This member contains the real priority of the calling thread.
   */
  rtems_task_priority priority_real;

  /**
   * @brief This member contains the current priority of the calling thread
   *   before the directive call.
   */
  rtems_task_priority priority_before;

  /**
   * @brief This member contains the return status of the directive call.
   */
  Status_Control status;

  /**
   * @brief This member contains the owner of the mutex after the directive
   *   call.
   */
  const rtems_tcb *owner_after;

  /**
   * @brief This member contains the current priority of the calling thread
   *   after the directive call.
   */
  rtems_task_priority priority_after;

  /**
   * @brief This member contains the counter snapshot after the directive call.
   */
  uint32_t counter;

  /**
   * @brief This member contains a copy of the corresponding
   *   ScoreMtxReqSurrender_Run() parameter.
   */
  TQMtxContext *tq_ctx;

  struct {
    /**
     * @brief This member defines the pre-condition indices for the next
     *   action.
     */
    size_t pci[ 8 ];

    /**
     * @brief This member defines the pre-condition states for the next action.
     */
    size_t pcs[ 8 ];

    /**
     * @brief If this member is true, then the test action loop is executed.
     */
    bool in_action_loop;

    /**
     * @brief This member contains the next transition map index.
     */
    size_t index;

    /**
     * @brief This member contains the current transition map entry.
     */
    ScoreMtxReqSurrender_Entry entry;

    /**
     * @brief If this member is true, then the current transition variant
     *   should be skipped.
     */
    bool skip;
  } Map;
} ScoreMtxReqSurrender_Context;

static ScoreMtxReqSurrender_Context
  ScoreMtxReqSurrender_Instance;

static const char * const ScoreMtxReqSurrender_PreDesc_Protocol[] = {
  "None",
  "Inherit",
  "Ceiling",
  "MrsP",
  "NA"
};

static const char * const ScoreMtxReqSurrender_PreDesc_Discipline[] = {
  "FIFO",
  "Priority",
  "NA"
};

static const char * const ScoreMtxReqSurrender_PreDesc_Recursive[] = {
  "Allowed",
  "NotAllowed",
  "NA"
};

static const char * const ScoreMtxReqSurrender_PreDesc_OwnerCheck[] = {
  "Yes",
  "No",
  "NA"
};

static const char * const ScoreMtxReqSurrender_PreDesc_Owner[] = {
  "None",
  "Caller",
  "Other",
  "NA"
};

static const char * const ScoreMtxReqSurrender_PreDesc_Nested[] = {
  "Yes",
  "No",
  "NA"
};

static const char * const ScoreMtxReqSurrender_PreDesc_Blocked[] = {
  "Yes",
  "No",
  "NA"
};

static const char * const ScoreMtxReqSurrender_PreDesc_Priority[] = {
  "High",
  "Equal",
  "Low",
  "NA"
};

static const char * const * const ScoreMtxReqSurrender_PreDesc[] = {
  ScoreMtxReqSurrender_PreDesc_Protocol,
  ScoreMtxReqSurrender_PreDesc_Discipline,
  ScoreMtxReqSurrender_PreDesc_Recursive,
  ScoreMtxReqSurrender_PreDesc_OwnerCheck,
  ScoreMtxReqSurrender_PreDesc_Owner,
  ScoreMtxReqSurrender_PreDesc_Nested,
  ScoreMtxReqSurrender_PreDesc_Blocked,
  ScoreMtxReqSurrender_PreDesc_Priority,
  NULL
};

typedef ScoreMtxReqSurrender_Context Context;

static Status_Control Status( const Context *ctx, Status_Control status )
{
  return TQConvertStatus( &ctx->tq_ctx->base, status );
}

static void Action( Context *ctx )
{
  Status_Control status;

  TQSetScheduler(
    &ctx->tq_ctx->base,
    TQ_HELPER_A,
    SCHEDULER_A_ID,
    PRIO_VERY_HIGH
  );
  TQSetScheduler(
    &ctx->tq_ctx->base,
    TQ_BLOCKER_A,
    SCHEDULER_A_ID,
    PRIO_VERY_HIGH
  );

  if ( ctx->owner_caller ) {
    status = TQEnqueue( &ctx->tq_ctx->base, TQ_NO_WAIT );
    T_eq_int( status, Status( ctx, STATUS_SUCCESSFUL ) );
  } else if ( ctx->owner_other ) {
    TQSend( &ctx->tq_ctx->base, TQ_HELPER_A, TQ_EVENT_ENQUEUE );
  }

  if ( ctx->nested ) {
    status = TQEnqueue( &ctx->tq_ctx->base, TQ_NO_WAIT );
    T_eq_int( status, Status( ctx, STATUS_SUCCESSFUL ) );
  }

  if ( ctx->blocked ) {
    TQSend( &ctx->tq_ctx->base, TQ_BLOCKER_A, TQ_EVENT_ENQUEUE );
    Yield();
  }

  TQResetCounter( &ctx->tq_ctx->base );
  SetSelfPriority( ctx->priority_real );
  ctx->priority_before = GetSelfPriority();
  TQSchedulerRecordStart( &ctx->tq_ctx->base );
  ctx->status = TQSurrender( &ctx->tq_ctx->base );
  TQSchedulerRecordStop( &ctx->tq_ctx->base );
  ctx->owner_after = TQGetOwner( &ctx->tq_ctx->base );
  ctx->priority_after = GetSelfPriority();
  SetSelfPriority( PRIO_NORMAL );
  Yield();
  ctx->counter = TQGetCounter( &ctx->tq_ctx->base );

  if ( ctx->nested ) {
    status = TQSurrender( &ctx->tq_ctx->base );
    T_eq_int( status, Status( ctx, STATUS_SUCCESSFUL ) );
  }

  if ( ctx->owner_other ) {
    TQSend( &ctx->tq_ctx->base, TQ_HELPER_A, TQ_EVENT_SURRENDER );
  }

  if ( ctx->blocked ) {
    TQSend( &ctx->tq_ctx->base, TQ_BLOCKER_A, TQ_EVENT_SURRENDER );
  }
}

static void ActionSticky( Context *ctx )
{
  Status_Control status;

  TQSetScheduler(
    &ctx->tq_ctx->base,
    TQ_HELPER_A,
    SCHEDULER_A_ID,
    PRIO_VERY_HIGH
  );
  TQSetScheduler(
    &ctx->tq_ctx->base,
    TQ_BLOCKER_A,
    SCHEDULER_B_ID,
    PRIO_VERY_HIGH
  );

  if ( ctx->owner_caller ) {
    status = TQEnqueue( &ctx->tq_ctx->base, TQ_NO_WAIT );
    T_eq_int( status, Status( ctx, STATUS_SUCCESSFUL ) );
  } else if ( ctx->owner_other ) {
    SetSelfScheduler( SCHEDULER_B_ID, PRIO_ULTRA_HIGH );
    TQSendAndSynchronizeRunner(
      &ctx->tq_ctx->base,
      TQ_HELPER_A,
      TQ_EVENT_ENQUEUE
    );
    SetSelfScheduler( SCHEDULER_A_ID, PRIO_ULTRA_HIGH );
  }

  if ( ctx->nested ) {
    status = TQEnqueue( &ctx->tq_ctx->base, TQ_NO_WAIT );
    T_eq_int( status, Status( ctx, STATUS_SUCCESSFUL ) );
  }

  if ( ctx->blocked ) {
    TQSendAndWaitForIntendToBlock(
      &ctx->tq_ctx->base,
      TQ_BLOCKER_A,
      TQ_EVENT_ENQUEUE
    );
  }

  TQResetCounter( &ctx->tq_ctx->base );
  SetSelfPriority( ctx->priority_real );
  ctx->priority_before = GetSelfPriority();
  TQSchedulerRecordStart( &ctx->tq_ctx->base );
  ctx->status = TQSurrender( &ctx->tq_ctx->base );
  TQSchedulerRecordStop( &ctx->tq_ctx->base );
  ctx->owner_after = TQGetOwner( &ctx->tq_ctx->base );
  ctx->priority_after = GetSelfPriority();

  if ( ctx->status == Status( ctx, STATUS_SUCCESSFUL ) ) {
    TQWaitForExecutionStop( &ctx->tq_ctx->base, TQ_BLOCKER_A );
  }

  ctx->counter = TQGetCounter( &ctx->tq_ctx->base );

  if ( ctx->nested ) {
    status = TQSurrender( &ctx->tq_ctx->base );
    T_eq_int( status, Status( ctx, STATUS_SUCCESSFUL ) );
  }

  if ( ctx->owner_other ) {
    SetSelfScheduler( SCHEDULER_B_ID, PRIO_ULTRA_HIGH );
    TQSendAndSynchronizeRunner(
      &ctx->tq_ctx->base,
      TQ_HELPER_A,
      TQ_EVENT_SURRENDER
    );
    SetSelfScheduler( SCHEDULER_A_ID, PRIO_NORMAL );
  } else {
    SetSelfPriority( PRIO_NORMAL );
  }

  if ( ctx->blocked ) {
    TQSendAndSynchronizeRunner(
      &ctx->tq_ctx->base,
      TQ_BLOCKER_A,
      TQ_EVENT_SURRENDER
    );
  }
}

static void ScoreMtxReqSurrender_Pre_Protocol_Prepare(
  ScoreMtxReqSurrender_Context     *ctx,
  ScoreMtxReqSurrender_Pre_Protocol state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Pre_Protocol_None: {
      /*
       * Where the mutex does not use a locking protocol.
       */
      if ( ctx->tq_ctx->protocol != TQ_MTX_NO_PROTOCOL ) {
        ctx->Map.skip = true;
      }
      break;
    }

    case ScoreMtxReqSurrender_Pre_Protocol_Inherit: {
      /*
       * Where the mutex uses the priority inheritance locking protocol.
       */
      if ( ctx->tq_ctx->protocol != TQ_MTX_PRIORITY_INHERIT ) {
        ctx->Map.skip = true;
      }
      break;
    }

    case ScoreMtxReqSurrender_Pre_Protocol_Ceiling: {
      /*
       * Where the mutex uses the priority ceiling locking protocol.
       */
      if ( ctx->tq_ctx->protocol != TQ_MTX_PRIORITY_CEILING ) {
        ctx->Map.skip = true;
      }
      break;
    }

    case ScoreMtxReqSurrender_Pre_Protocol_MrsP: {
      /*
       * Where the mutex uses the MrsP locking protocol.
       */
      if ( ctx->tq_ctx->protocol != TQ_MTX_MRSP ) {
        ctx->Map.skip = true;
      }
      break;
    }

    case ScoreMtxReqSurrender_Pre_Protocol_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Pre_Discipline_Prepare(
  ScoreMtxReqSurrender_Context       *ctx,
  ScoreMtxReqSurrender_Pre_Discipline state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Pre_Discipline_FIFO: {
      /*
       * Where the thread queue of the mutex uses the FIFO discipline.
       */
      if ( ctx->tq_ctx->base.discipline != TQ_FIFO ) {
        ctx->Map.skip = true;
      }
      break;
    }

    case ScoreMtxReqSurrender_Pre_Discipline_Priority: {
      /*
       * Where the thread queue of the mutex uses the priority discipline.
       */
      if ( ctx->tq_ctx->base.discipline != TQ_PRIORITY ) {
        ctx->Map.skip = true;
      }
      break;
    }

    case ScoreMtxReqSurrender_Pre_Discipline_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Pre_Recursive_Prepare(
  ScoreMtxReqSurrender_Context      *ctx,
  ScoreMtxReqSurrender_Pre_Recursive state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Pre_Recursive_Allowed: {
      /*
       * Where a recursive seize of the mutex is allowed.
       */
      if ( ctx->tq_ctx->recursive != TQ_MTX_RECURSIVE_ALLOWED ) {
        ctx->Map.skip = true;
      }
      break;
    }

    case ScoreMtxReqSurrender_Pre_Recursive_NotAllowed: {
      /*
       * Where a recursive seize of the mutex is not allowed.
       */
      if ( ctx->tq_ctx->recursive == TQ_MTX_RECURSIVE_ALLOWED ) {
        ctx->Map.skip = true;
      }
      break;
    }

    case ScoreMtxReqSurrender_Pre_Recursive_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Pre_OwnerCheck_Prepare(
  ScoreMtxReqSurrender_Context       *ctx,
  ScoreMtxReqSurrender_Pre_OwnerCheck state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Pre_OwnerCheck_Yes: {
      /*
       * Where the surrender checks that the mutex owner is the calling thread.
       */
      if ( ctx->tq_ctx->owner_check != TQ_MTX_CHECKS_OWNER ) {
        ctx->Map.skip = true;
      }
      break;
    }

    case ScoreMtxReqSurrender_Pre_OwnerCheck_No: {
      /*
       * Where the surrender does not check that the mutex owner is the calling
       * thread.
       */
      if ( ctx->tq_ctx->owner_check != TQ_MTX_NO_OWNER_CHECK ) {
        ctx->Map.skip = true;
      }
      break;
    }

    case ScoreMtxReqSurrender_Pre_OwnerCheck_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Pre_Owner_Prepare(
  ScoreMtxReqSurrender_Context  *ctx,
  ScoreMtxReqSurrender_Pre_Owner state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Pre_Owner_None: {
      /*
       * While the mutex has no owner.
       */
      ctx->owner_caller = false;
      ctx->owner_other = false;
      break;
    }

    case ScoreMtxReqSurrender_Pre_Owner_Caller: {
      /*
       * While the owner of the mutex is the calling thread.
       */
      ctx->owner_caller = true;
      ctx->owner_other = false;
      break;
    }

    case ScoreMtxReqSurrender_Pre_Owner_Other: {
      /*
       * While the owner of the mutex is a thread other than the calling
       * thread.
       */
      ctx->owner_caller = false;
      ctx->owner_other = true;
      break;
    }

    case ScoreMtxReqSurrender_Pre_Owner_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Pre_Nested_Prepare(
  ScoreMtxReqSurrender_Context   *ctx,
  ScoreMtxReqSurrender_Pre_Nested state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Pre_Nested_Yes: {
      /*
       * While calling thread seized the mutex recursively.
       */
      ctx->nested = true;
      break;
    }

    case ScoreMtxReqSurrender_Pre_Nested_No: {
      /*
       * While calling thread seized the mutex not recursively.
       */
      ctx->nested = false;
      break;
    }

    case ScoreMtxReqSurrender_Pre_Nested_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Pre_Blocked_Prepare(
  ScoreMtxReqSurrender_Context    *ctx,
  ScoreMtxReqSurrender_Pre_Blocked state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Pre_Blocked_Yes: {
      /*
       * While the mutex has threads blocked on the mutex.
       */
      ctx->blocked = true;
      break;
    }

    case ScoreMtxReqSurrender_Pre_Blocked_No: {
      /*
       * While no threads are blocked on the mutex.
       */
      ctx->blocked = false;
      break;
    }

    case ScoreMtxReqSurrender_Pre_Blocked_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Pre_Priority_Prepare(
  ScoreMtxReqSurrender_Context     *ctx,
  ScoreMtxReqSurrender_Pre_Priority state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Pre_Priority_High: {
      /*
       * While the current priority of the calling thread without the
       * priorities available through the mutex would be higher than the
       * highest priority of the priorities available through the mutex.
       */
      ctx->priority_real = PRIO_ULTRA_HIGH;
      break;
    }

    case ScoreMtxReqSurrender_Pre_Priority_Equal: {
      /*
       * While the current priority of the calling thread without the
       * priorities available through the mutex would be equal to the highest
       * priority of the priorities available through the mutex.
       */
      ctx->priority_real = PRIO_VERY_HIGH;
      break;
    }

    case ScoreMtxReqSurrender_Pre_Priority_Low: {
      /*
       * While the current priority of the calling thread without the
       * priorities available through the mutex would be lower than the highest
       * priority of the priorities available through the mutex.
       */
      ctx->priority_real = PRIO_HIGH;
      break;
    }

    case ScoreMtxReqSurrender_Pre_Priority_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Post_Status_Check(
  ScoreMtxReqSurrender_Context    *ctx,
  ScoreMtxReqSurrender_Post_Status state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Post_Status_Ok: {
      /*
       * The return status of the directive call shall be derived from
       * STATUS_SUCCESSFUL.
       */
      T_eq_int( ctx->status, Status( ctx, STATUS_SUCCESSFUL ) );
      break;
    }

    case ScoreMtxReqSurrender_Post_Status_NotOwner: {
      /*
       * The return status of the directive call shall be derived from
       * STATUS_NOT_OWNER.
       */
      T_eq_int( ctx->status, Status( ctx, STATUS_NOT_OWNER ) );
      break;
    }

    case ScoreMtxReqSurrender_Post_Status_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Post_Owner_Check(
  ScoreMtxReqSurrender_Context   *ctx,
  ScoreMtxReqSurrender_Post_Owner state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Post_Owner_None: {
      /*
       * The mutex shall have no owner.
       */
      T_null( ctx->owner_after );
      break;
    }

    case ScoreMtxReqSurrender_Post_Owner_Caller: {
      /*
       * The owner of the mutex shall be the calling thread.
       */
      T_eq_ptr(
        ctx->owner_after,
        ctx->tq_ctx->base.runner_tcb
      );
      break;
    }

    case ScoreMtxReqSurrender_Post_Owner_Other: {
      /*
       * The owner of the mutex shall not be modified.
       */
      T_eq_ptr(
        ctx->owner_after,
        ctx->tq_ctx->base.worker_tcb[ TQ_HELPER_A ]
      );
      break;
    }

    case ScoreMtxReqSurrender_Post_Owner_First: {
      /*
       * The owner of the mutex shall be dequeued thread.
       */
      T_eq_ptr(
        ctx->owner_after,
        ctx->tq_ctx->base.worker_tcb[ TQ_BLOCKER_A ]
      );
      break;
    }

    case ScoreMtxReqSurrender_Post_Owner_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Post_Surrender_Check(
  ScoreMtxReqSurrender_Context       *ctx,
  ScoreMtxReqSurrender_Post_Surrender state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Post_Surrender_Nop: {
      /*
       * The thread queue of the mutex shall not be surrendered to a thread.
       */
      T_eq_u32( ctx->counter, 0 );
      break;
    }

    case ScoreMtxReqSurrender_Post_Surrender_FIFO: {
      /*
       * The thread queue of the mutex shall be surrendered in FIFO order.
       */
      T_eq_u32( ctx->counter, 1 );
      ScoreTqReqSurrender_Run( &ctx->tq_ctx->base );
      break;
    }

    case ScoreMtxReqSurrender_Post_Surrender_Priority: {
      /*
       * The thread queue of the mutex shall be surrendered in priority order.
       */
      T_eq_u32( ctx->counter, 1 );
      ScoreTqReqSurrender_Run( &ctx->tq_ctx->base );
      break;
    }

    case ScoreMtxReqSurrender_Post_Surrender_PriorityInherit: {
      /*
       * The thread queue of the mutex shall be surrendered in priority order
       * with priority inheritance.
       */
      T_eq_u32( ctx->counter, 1 );
      ScoreTqReqSurrenderPriorityInherit_Run( &ctx->tq_ctx->base );
      break;
    }

    case ScoreMtxReqSurrender_Post_Surrender_MrsP: {
      /*
       * The thread queue of the mutex shall be surrendered in priority order
       * with MrsP.
       */
      T_eq_u32( ctx->counter, 1 );
      ScoreTqReqSurrenderMrsp_Run( &ctx->tq_ctx->base );
      break;
    }

    case ScoreMtxReqSurrender_Post_Surrender_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Post_Priority_Check(
  ScoreMtxReqSurrender_Context      *ctx,
  ScoreMtxReqSurrender_Post_Priority state
)
{
  switch ( state ) {
    case ScoreMtxReqSurrender_Post_Priority_Nop: {
      /*
       * The current priority of the calling thread shall be not be modified.
       */
      T_eq_u32( ctx->priority_after, ctx->priority_before );
      break;
    }

    case ScoreMtxReqSurrender_Post_Priority_Low: {
      /*
       * The current priority of the calling thread shall be lowered to reflect
       * the removal of the priorities available through the mutex.
       */
      T_eq_u32( ctx->priority_after, ctx->priority_real );
      break;
    }

    case ScoreMtxReqSurrender_Post_Priority_NA:
      break;
  }
}

static void ScoreMtxReqSurrender_Prepare( ScoreMtxReqSurrender_Context *ctx )
{
  ctx->owner_caller = false;
  ctx->owner_other = false;
  ctx->nested = false;
  ctx->blocked = false;

  if ( ctx->tq_ctx->base.enqueue_variant == TQ_ENQUEUE_STICKY ) {
    ctx->priority_real = PRIO_ULTRA_HIGH;
  } else {
    ctx->priority_real = PRIO_NORMAL;
  }
}

static void ScoreMtxReqSurrender_Action( ScoreMtxReqSurrender_Context *ctx )
{
  if ( ctx->tq_ctx->base.enqueue_variant == TQ_ENQUEUE_STICKY ) {
    ActionSticky( ctx );
  } else {
    Action( ctx );
  }
}

static const ScoreMtxReqSurrender_Entry
ScoreMtxReqSurrender_Entries[] = {
  { 1, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_NA,
    ScoreMtxReqSurrender_Post_Owner_NA, ScoreMtxReqSurrender_Post_Surrender_NA,
    ScoreMtxReqSurrender_Post_Priority_NA },
  { 1, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_NA,
    ScoreMtxReqSurrender_Post_Owner_NA, ScoreMtxReqSurrender_Post_Surrender_NA,
    ScoreMtxReqSurrender_Post_Priority_NA },
  { 1, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_NA,
    ScoreMtxReqSurrender_Post_Owner_NA, ScoreMtxReqSurrender_Post_Surrender_NA,
    ScoreMtxReqSurrender_Post_Priority_NA },
  { 0, 0, 0, 0, 0, 0, 1, 0, 1, ScoreMtxReqSurrender_Post_Status_NotOwner,
    ScoreMtxReqSurrender_Post_Owner_Other,
    ScoreMtxReqSurrender_Post_Surrender_Nop,
    ScoreMtxReqSurrender_Post_Priority_Nop },
  { 1, 0, 0, 0, 0, 0, 1, 0, 1, ScoreMtxReqSurrender_Post_Status_NA,
    ScoreMtxReqSurrender_Post_Owner_NA, ScoreMtxReqSurrender_Post_Surrender_NA,
    ScoreMtxReqSurrender_Post_Priority_NA },
  { 0, 0, 0, 0, 0, 0, 1, 0, 1, ScoreMtxReqSurrender_Post_Status_NotOwner,
    ScoreMtxReqSurrender_Post_Owner_None,
    ScoreMtxReqSurrender_Post_Surrender_Nop,
    ScoreMtxReqSurrender_Post_Priority_Nop },
  { 0, 0, 0, 0, 0, 0, 0, 0, 1, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_None,
    ScoreMtxReqSurrender_Post_Surrender_Nop,
    ScoreMtxReqSurrender_Post_Priority_Nop },
  { 0, 0, 0, 0, 0, 0, 0, 0, 1, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_Caller,
    ScoreMtxReqSurrender_Post_Surrender_Nop,
    ScoreMtxReqSurrender_Post_Priority_Nop },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_Caller,
    ScoreMtxReqSurrender_Post_Surrender_Nop,
    ScoreMtxReqSurrender_Post_Priority_Nop },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_None,
    ScoreMtxReqSurrender_Post_Surrender_Nop,
    ScoreMtxReqSurrender_Post_Priority_Nop },
  { 0, 0, 0, 0, 0, 0, 0, 0, 1, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_First,
    ScoreMtxReqSurrender_Post_Surrender_FIFO,
    ScoreMtxReqSurrender_Post_Priority_Nop },
  { 0, 0, 0, 0, 0, 0, 0, 0, 1, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_First,
    ScoreMtxReqSurrender_Post_Surrender_Priority,
    ScoreMtxReqSurrender_Post_Priority_Nop },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_First,
    ScoreMtxReqSurrender_Post_Surrender_PriorityInherit,
    ScoreMtxReqSurrender_Post_Priority_Nop },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_First,
    ScoreMtxReqSurrender_Post_Surrender_Priority,
    ScoreMtxReqSurrender_Post_Priority_Nop },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_None,
    ScoreMtxReqSurrender_Post_Surrender_Nop,
    ScoreMtxReqSurrender_Post_Priority_Low },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_First,
    ScoreMtxReqSurrender_Post_Surrender_MrsP,
    ScoreMtxReqSurrender_Post_Priority_Nop },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_First,
    ScoreMtxReqSurrender_Post_Surrender_PriorityInherit,
    ScoreMtxReqSurrender_Post_Priority_Low },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_First,
    ScoreMtxReqSurrender_Post_Surrender_Priority,
    ScoreMtxReqSurrender_Post_Priority_Low },
  { 0, 0, 0, 0, 0, 0, 0, 0, 0, ScoreMtxReqSurrender_Post_Status_Ok,
    ScoreMtxReqSurrender_Post_Owner_First,
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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 5, 5, 5, 4, 4, 4, 5,
  5, 5, 8, 8, 8, 8, 8, 8, 15, 15, 18, 9, 9, 14, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 8, 8, 8, 8, 8, 15, 15, 18, 9, 9,
  14, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 4, 4, 4, 5, 5, 5,
  2, 2, 2, 2, 2, 2, 15, 15, 18, 9, 9, 14, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
  2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 15, 15, 18, 9, 9, 14,
  2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1
};

static size_t ScoreMtxReqSurrender_Scope( void *arg, char *buf, size_t n )
{
  ScoreMtxReqSurrender_Context *ctx;

  ctx = arg;

  if ( ctx->Map.in_action_loop ) {
    return T_get_scope( ScoreMtxReqSurrender_PreDesc, buf, n, ctx->Map.pcs );
  }

  return 0;
}

static T_fixture ScoreMtxReqSurrender_Fixture = {
  .setup = NULL,
  .stop = NULL,
  .teardown = NULL,
  .scope = ScoreMtxReqSurrender_Scope,
  .initial_context = &ScoreMtxReqSurrender_Instance
};

static const uint16_t ScoreMtxReqSurrender_Weights[] = {
  288, 144, 72, 36, 12, 6, 3, 1
};

static void ScoreMtxReqSurrender_Skip(
  ScoreMtxReqSurrender_Context *ctx,
  size_t                        index
)
{
  switch ( index + 1 ) {
    case 1:
      ctx->Map.pci[ 1 ] = ScoreMtxReqSurrender_Pre_Discipline_NA - 1;
      /* Fall through */
    case 2:
      ctx->Map.pci[ 2 ] = ScoreMtxReqSurrender_Pre_Recursive_NA - 1;
      /* Fall through */
    case 3:
      ctx->Map.pci[ 3 ] = ScoreMtxReqSurrender_Pre_OwnerCheck_NA - 1;
      /* Fall through */
    case 4:
      ctx->Map.pci[ 4 ] = ScoreMtxReqSurrender_Pre_Owner_NA - 1;
      /* Fall through */
    case 5:
      ctx->Map.pci[ 5 ] = ScoreMtxReqSurrender_Pre_Nested_NA - 1;
      /* Fall through */
    case 6:
      ctx->Map.pci[ 6 ] = ScoreMtxReqSurrender_Pre_Blocked_NA - 1;
      /* Fall through */
    case 7:
      ctx->Map.pci[ 7 ] = ScoreMtxReqSurrender_Pre_Priority_NA - 1;
      break;
  }
}

static inline ScoreMtxReqSurrender_Entry ScoreMtxReqSurrender_PopEntry(
  ScoreMtxReqSurrender_Context *ctx
)
{
  size_t index;

  if ( ctx->Map.skip ) {
    size_t i;

    ctx->Map.skip = false;
    index = 0;

    for ( i = 0; i < 8; ++i ) {
      index += ScoreMtxReqSurrender_Weights[ i ] * ctx->Map.pci[ i ];
    }
  } else {
    index = ctx->Map.index;
  }

  ctx->Map.index = index + 1;

  return ScoreMtxReqSurrender_Entries[
    ScoreMtxReqSurrender_Map[ index ]
  ];
}

static void ScoreMtxReqSurrender_SetPreConditionStates(
  ScoreMtxReqSurrender_Context *ctx
)
{
  ctx->Map.pcs[ 0 ] = ctx->Map.pci[ 0 ];
  ctx->Map.pcs[ 1 ] = ctx->Map.pci[ 1 ];
  ctx->Map.pcs[ 2 ] = ctx->Map.pci[ 2 ];
  ctx->Map.pcs[ 3 ] = ctx->Map.pci[ 3 ];
  ctx->Map.pcs[ 4 ] = ctx->Map.pci[ 4 ];

  if ( ctx->Map.entry.Pre_Nested_NA ) {
    ctx->Map.pcs[ 5 ] = ScoreMtxReqSurrender_Pre_Nested_NA;
  } else {
    ctx->Map.pcs[ 5 ] = ctx->Map.pci[ 5 ];
  }

  ctx->Map.pcs[ 6 ] = ctx->Map.pci[ 6 ];

  if ( ctx->Map.entry.Pre_Priority_NA ) {
    ctx->Map.pcs[ 7 ] = ScoreMtxReqSurrender_Pre_Priority_NA;
  } else {
    ctx->Map.pcs[ 7 ] = ctx->Map.pci[ 7 ];
  }
}

static void ScoreMtxReqSurrender_TestVariant(
  ScoreMtxReqSurrender_Context *ctx
)
{
  ScoreMtxReqSurrender_Pre_Protocol_Prepare( ctx, ctx->Map.pcs[ 0 ] );

  if ( ctx->Map.skip ) {
    ScoreMtxReqSurrender_Skip( ctx, 0 );
    return;
  }

  ScoreMtxReqSurrender_Pre_Discipline_Prepare( ctx, ctx->Map.pcs[ 1 ] );

  if ( ctx->Map.skip ) {
    ScoreMtxReqSurrender_Skip( ctx, 1 );
    return;
  }

  ScoreMtxReqSurrender_Pre_Recursive_Prepare( ctx, ctx->Map.pcs[ 2 ] );

  if ( ctx->Map.skip ) {
    ScoreMtxReqSurrender_Skip( ctx, 2 );
    return;
  }

  ScoreMtxReqSurrender_Pre_OwnerCheck_Prepare( ctx, ctx->Map.pcs[ 3 ] );

  if ( ctx->Map.skip ) {
    ScoreMtxReqSurrender_Skip( ctx, 3 );
    return;
  }

  ScoreMtxReqSurrender_Pre_Owner_Prepare( ctx, ctx->Map.pcs[ 4 ] );
  ScoreMtxReqSurrender_Pre_Nested_Prepare( ctx, ctx->Map.pcs[ 5 ] );
  ScoreMtxReqSurrender_Pre_Blocked_Prepare( ctx, ctx->Map.pcs[ 6 ] );
  ScoreMtxReqSurrender_Pre_Priority_Prepare( ctx, ctx->Map.pcs[ 7 ] );
  ScoreMtxReqSurrender_Action( ctx );
  ScoreMtxReqSurrender_Post_Status_Check( ctx, ctx->Map.entry.Post_Status );
  ScoreMtxReqSurrender_Post_Owner_Check( ctx, ctx->Map.entry.Post_Owner );
  ScoreMtxReqSurrender_Post_Surrender_Check(
    ctx,
    ctx->Map.entry.Post_Surrender
  );
  ScoreMtxReqSurrender_Post_Priority_Check(
    ctx,
    ctx->Map.entry.Post_Priority
  );
}

static T_fixture_node ScoreMtxReqSurrender_Node;

void ScoreMtxReqSurrender_Run( TQMtxContext *tq_ctx )
{
  ScoreMtxReqSurrender_Context *ctx;

  ctx = &ScoreMtxReqSurrender_Instance;
  ctx->tq_ctx = tq_ctx;

  ctx = T_push_fixture(
    &ScoreMtxReqSurrender_Node,
    &ScoreMtxReqSurrender_Fixture
  );
  ctx->Map.in_action_loop = true;
  ctx->Map.index = 0;
  ctx->Map.skip = false;

  for (
    ctx->Map.pci[ 0 ] = ScoreMtxReqSurrender_Pre_Protocol_None;
    ctx->Map.pci[ 0 ] < ScoreMtxReqSurrender_Pre_Protocol_NA;
    ++ctx->Map.pci[ 0 ]
  ) {
    for (
      ctx->Map.pci[ 1 ] = ScoreMtxReqSurrender_Pre_Discipline_FIFO;
      ctx->Map.pci[ 1 ] < ScoreMtxReqSurrender_Pre_Discipline_NA;
      ++ctx->Map.pci[ 1 ]
    ) {
      for (
        ctx->Map.pci[ 2 ] = ScoreMtxReqSurrender_Pre_Recursive_Allowed;
        ctx->Map.pci[ 2 ] < ScoreMtxReqSurrender_Pre_Recursive_NA;
        ++ctx->Map.pci[ 2 ]
      ) {
        for (
          ctx->Map.pci[ 3 ] = ScoreMtxReqSurrender_Pre_OwnerCheck_Yes;
          ctx->Map.pci[ 3 ] < ScoreMtxReqSurrender_Pre_OwnerCheck_NA;
          ++ctx->Map.pci[ 3 ]
        ) {
          for (
            ctx->Map.pci[ 4 ] = ScoreMtxReqSurrender_Pre_Owner_None;
            ctx->Map.pci[ 4 ] < ScoreMtxReqSurrender_Pre_Owner_NA;
            ++ctx->Map.pci[ 4 ]
          ) {
            for (
              ctx->Map.pci[ 5 ] = ScoreMtxReqSurrender_Pre_Nested_Yes;
              ctx->Map.pci[ 5 ] < ScoreMtxReqSurrender_Pre_Nested_NA;
              ++ctx->Map.pci[ 5 ]
            ) {
              for (
                ctx->Map.pci[ 6 ] = ScoreMtxReqSurrender_Pre_Blocked_Yes;
                ctx->Map.pci[ 6 ] < ScoreMtxReqSurrender_Pre_Blocked_NA;
                ++ctx->Map.pci[ 6 ]
              ) {
                for (
                  ctx->Map.pci[ 7 ] = ScoreMtxReqSurrender_Pre_Priority_High;
                  ctx->Map.pci[ 7 ] < ScoreMtxReqSurrender_Pre_Priority_NA;
                  ++ctx->Map.pci[ 7 ]
                ) {
                  ctx->Map.entry = ScoreMtxReqSurrender_PopEntry( ctx );

                  if ( ctx->Map.entry.Skip ) {
                    continue;
                  }

                  ScoreMtxReqSurrender_SetPreConditionStates( ctx );
                  ScoreMtxReqSurrender_Prepare( ctx );
                  ScoreMtxReqSurrender_TestVariant( ctx );
                }
              }
            }
          }
        }
      }
    }
  }

  T_pop_fixture();
}

/** @} */