summaryrefslogtreecommitdiffstats
path: root/spec/score/sem/req/seize-wait.yml
blob: 89a65b1a552ef7186a19738ee82df2ab5f62a66d (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
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: function-implementation
  uid: /score/tq/req/enqueue-fifo
- role: function-implementation
  uid: /score/tq/req/enqueue-priority
- role: requirement-refinement
  uid: ../if/group
post-conditions:
- name: Status
  states:
  - name: Ok
    test-code: |
      status = TQEnqueue( &ctx->tq_ctx->base, ctx->tq_ctx->base.wait );
      T_eq_int( status, Status( ctx, STATUS_SUCCESSFUL ) );
    text: |
      The return status of the directive call shall be derived from
      ${../../status/if/successful:/name}.
  - name: Enqueued
    test-code: |
      switch ( ctx->tq_ctx->base.discipline ) {
        case TQ_FIFO:
          ${../../tq/req/enqueue-fifo:/test-run}( &ctx->tq_ctx->base );
          break;
        case TQ_PRIORITY:
          ${../../tq/req/enqueue-priority:/test-run}( &ctx->tq_ctx->base );
          break;
        default:
          T_unreachable();
          break;
      }
    text: |
      Where the thread queue uses the FIFO discipline, the calling thread shall
      be enqueued in FIFO order.

      Where the thread queue uses the priority discipline, the calling thread
      shall be enqueued in priority order.
  test-epilogue: null
  test-prologue: |
    Status_Control status;
- name: Count
  states:
  - name: Nop
    test-code: |
      /* Checked by GetProperties() */
    text: |
      The count of the semaphore shall not be modified.
  - name: MinusOne
    test-code: |
      T_eq_u32( TQSemGetCount( ctx->tq_ctx ), 0 );
    text: |
      The count of the semaphore shall be decremented by one.
  test-epilogue: null
  test-prologue: null
- name: Timer
  states:
  - name: Optional
    test-code: |
      /* Checked by GetProperties() */
    text: |
      Where the directive was called with a timeout in clock ticks, the thread
      timer of the calling task shall fire after the specified clock ticks.

      Where the directive was called without a timeout, the thread timer of the
      calling task shall be inactive.
  - name: 'No'
    test-code: |
      T_eq_int(
        T_get_thread_timer_state( RTEMS_SELF ),
        T_THREAD_TIMER_INACTIVE
      );
    text: |
      The thread timer of the calling task shall be inactive.
  test-epilogue: null
  test-prologue: null
pre-conditions:
- name: Count
  states:
  - name: Zero
    test-code: |
      /* Done by TQEnqueuePrepareDefault() */
    text: |
      While the count of the semaphore is zero.
  - name: Positive
    test-code: |
      TQSemSetCount( ctx->tq_ctx, 1 );
    text: |
      While the count of the semaphore is greater than zero.
  test-epilogue: null
  test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons: {}
test-action: |
  /* Action performed by Status post-condition */
test-brief: null
test-cleanup: null
test-context: []
test-context-support: null
test-description: null
test-header:
  code: null
  freestanding: false
  includes: []
  local-includes:
  - tx-thread-queue.h
  run-params:
  - description: |
      is the semaphore thread queue context.
    dir: inout
    name: tq_ctx
    specifier: TQSemContext *${.:name}
  target: testsuites/validation/tr-sem-seize-wait.h
test-includes:
- rtems/score/statesimpl.h
test-local-includes:
- tr-sem-seize-wait.h
- tr-tq-enqueue-fifo.h
- tr-tq-enqueue-priority.h
test-prepare: |
  ctx->tq_ctx->base.enqueue_prepare = TQEnqueuePrepareDefault;
  ctx->tq_ctx->base.enqueue_done = TQEnqueueDoneDefault;
  ctx->tq_ctx->base.get_properties = GetProperties;
test-setup: null
test-stop: null
test-support: |
  typedef ${.:/test-context-type} Context;

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

  static void GetProperties( TQContext *base, TQWorkerKind enqueued_worker )
  {
    TQSemContext        *ctx;
    T_thread_timer_state timer_state;

    ctx = (TQSemContext *) base;
    T_eq_u32(
      ctx->base.worker_tcb[ enqueued_worker ]->current_state,
      STATES_WAITING_FOR_SEMAPHORE
    );

    timer_state = T_get_thread_timer_state(
      ctx->base.worker_id[ enqueued_worker ]
    );

    if ( base->wait == TQ_WAIT_TIMED ) {
      T_eq_int( timer_state, T_THREAD_TIMER_SCHEDULED );
    } else {
      T_eq_int( timer_state, T_THREAD_TIMER_INACTIVE );
    }

    T_eq_u32( TQSemGetCount( ctx ), 0 );
  }
test-target: testsuites/validation/tr-sem-seize-wait.c
test-teardown: null
text: |
  When the calling task tries to seize the semaphore.
transition-map:
- enabled-by: true
  post-conditions:
    Status: Ok
    Count: MinusOne
    Timer: 'No'
  pre-conditions:
    Count:
    - Positive
- enabled-by: true
  post-conditions:
    Status: Enqueued
    Count: Nop
    Timer: Optional
  pre-conditions:
    Count:
    - Zero
type: requirement