summaryrefslogtreecommitdiffstats
path: root/spec/c/req/posix-memalign.yml
blob: 7698f9814544982a5493c430df7ab54ace75ea92 (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
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
enabled-by: true
functional-type: action
links:
- role: interface-function
  uid: ../if/posix-memalign
post-conditions:
- name: Status
  states:
  - name: Zero
    test-code: |
      T_eq_int( ctx->status, 0 );
    text: |
      The return value of ${../if/posix-memalign:/name} shall be equal to zero.
  - name: EINVAL
    test-code: |
      T_eq_int( ctx->status, EINVAL );
    text: |
      The return value of ${../if/posix-memalign:/name} shall be equal to
      ${../if/einval:/name}.
  - name: ENOMEM
    test-code: |
      T_eq_int( ctx->status, ENOMEM );
    text: |
      The return value of ${../if/posix-memalign:/name} shall be equal to
      ${../if/enomem:/name}.
  test-epilogue: null
  test-prologue: null
- name: MemptrVar
  states:
  - name: AreaBegin
    test-code: |
      T_eq_ptr( ctx->memptr, &ctx->memptr_obj );
      T_not_null( ctx->memptr_obj );
    text: |
      The value of the object referenced by the memptr parameter shall be set
      to the begin address of the allocated memory area after the return of the
      ${../if/posix-memalign:/name} call.
  - name: 'Null'
    test-code: |
      T_eq_ptr( ctx->memptr, &ctx->memptr_obj );
      T_null( ctx->memptr_obj );
    text: |
      The value of the object referenced by the memptr parameter shall be set
      to ${../if/null:/name} after the return of the
      ${../if/posix-memalign:/name} call.
  - name: Nop
    test-code: |
      T_eq_uptr( (uintptr_t) ctx->memptr_obj, 1 );
    text: |
      Objects referenced by the memptr parameter in past calls to
      ${../if/posix-memalign:/name} shall not be accessed by the
      ${../if/posix-memalign:/name} call.
  test-epilogue: null
  test-prologue: null
- name: Alignment
  states:
  - name: Valid
    test-code: |
      T_eq_uptr( (uintptr_t) ctx->memptr_obj % 128, 0 );
    text: |
      The begin address of the allocated memory area shall be an integral
      multiple of the alignment parameter.
  test-epilogue: null
  test-prologue: null
- name: Size
  states:
  - name: Valid
    test-code: |
      /* Assume that the next allocation is done from adjacent memory */
      ptr = ctx->memptr_obj;
      eno = posix_memalign( &ptr, ctx->alignment, ctx->size );
      T_eq_int( eno, 0 );
      T_not_null( ptr );
      a = (uintptr_t) ptr;
      b = (uintptr_t) ctx->memptr_obj;
      size = a < b ? b - a : a - b;
      T_ge_uptr( size, ctx->size );
    text: |
      The size of the allocated memory area shall greater than or equal to the
      size parameter.
  test-epilogue: null
  test-prologue: |
    void     *ptr;
    int       eno;
    uintptr_t a;
    uintptr_t b;
    uintptr_t size;
pre-conditions:
- name: Memptr
  states:
  - name: Valid
    test-code: |
      ctx->memptr = &ctx->memptr_obj;
    text: |
      While the memptr parameter references an object of type
      ``void *``.
  - name: 'Null'
    test-code: |
      ctx->memptr = NULL;
    text: |
      While the memptr parameter is equal to ${/c/if/null:/name}.
  test-epilogue: null
  test-prologue: null
- name: Alignment
  states:
  - name: Tiny
    test-code: |
      ctx->alignment = sizeof( void * ) - 1;
    text: |
      While the alignment parameter is less than sizeof( void * ).
  - name: NotPower2
    test-code: |
      ctx->alignment = sizeof( void * ) + 1;
    text: |
      While the alignment parameter is greater than or equal to
      sizeof( void * ), while the alignment parameter is not a power of two.
  - name: Huge
    test-code: |
      ctx->alignment = SIZE_MAX / 2 + 1;
    text: |
      While the alignment parameter is greater than or equal to
      sizeof( void * ), while the alignment parameter is a power of two, while
      the alignment parameter is too large to allocate a memory area with the
      specified alignment.
  - name: Valid
    test-code: |
      ctx->alignment = 128;
    text: |
      While the alignment parameter is greater than or equal to
      sizeof( void * ), while the alignment parameter is a power of two, while
      the alignment parameter is small enough to allocate a memory area with
      the specified alignment.
  test-epilogue: null
  test-prologue: null
- name: Size
  states:
  - name: Huge
    test-code: |
      ctx->size = SIZE_MAX;
    text: |
      While the size parameter is not equal to zero, while the size parameter
      is too large to allocate a memory area with the specified size.
  - name: Zero
    test-code: |
      ctx->size = 0;
    text: |
      While the size parameter is equal to zero.
  - name: Valid
    test-code: |
      ctx->size = sizeof( uint64_t );
    text: |
      While the size parameter is not equal to zero, while the size parameter
      is small enough to allocate a memory area with the specified size.
  test-epilogue: null
  test-prologue: null
rationale: null
references: []
requirement-type: functional
skip-reasons: {}
test-action: |
  ctx->status = posix_memalign( ctx->memptr, ctx->alignment, ctx->size );
test-brief: null
test-cleanup: null
test-context:
- brief: |
    This member provides a memory support context.
  description: null
  member: |
    MemoryContext mem_ctx;
- brief: |
    This member provides the object referenced by the memptr parameter.
  description: null
  member: |
    void *memptr_obj
- brief: |
    This member contains the return value of the directive call.
  description: null
  member: |
    int status
- brief: |
    This member specifies if the memptr parameter value.
  description: null
  member: |
    void **memptr
- brief: |
    This member specifies if the alignment parameter value.
  description: null
  member: |
    size_t alignment
- brief: |
    This member specifies if the size parameter value.
  description: null
  member: |
    size_t size
test-context-support: null
test-description: null
test-header: null
test-includes:
- stdlib.h
- errno.h
test-local-includes:
- tx-support.h
test-prepare: |
  ctx->memptr_obj = (void *)(uintptr_t) 1;
test-setup:
  brief: null
  code: |
    MemorySave( &ctx->mem_ctx );
  description: null
test-stop: null
test-support: null
test-target: testsuites/validation/tc-mem-posix-memalign.c
test-teardown:
  brief: null
  code: |
    MemoryRestore( &ctx->mem_ctx );
  description: null
text: ${.:text-template}
transition-map:
- enabled-by: true
  post-conditions:
    Status: EINVAL
    MemptrVar: 'Null'
    Alignment: N/A
    Size: N/A
  pre-conditions:
    Memptr:
    - Valid
    Alignment:
    - Tiny
    - NotPower2
    Size: all
- enabled-by: true
  post-conditions:
    Status: EINVAL
    MemptrVar: Nop
    Alignment: N/A
    Size: N/A
  pre-conditions:
    Memptr:
    - 'Null'
    Alignment: all
    Size: all
- enabled-by: true
  post-conditions:
    Status: ENOMEM
    MemptrVar: 'Null'
    Alignment: N/A
    Size: N/A
  pre-conditions:
    Memptr:
    - Valid
    Alignment:
    - Huge
    Size:
    - Huge
    - Valid
- enabled-by: true
  post-conditions:
    Status: ENOMEM
    MemptrVar: 'Null'
    Alignment: N/A
    Size: N/A
  pre-conditions:
    Memptr:
    - Valid
    Alignment:
    - Valid
    Size:
    - Huge
- enabled-by: true
  post-conditions:
    Status: Zero
    MemptrVar: AreaBegin
    Alignment: Valid
    Size: Valid
  pre-conditions:
    Memptr:
    - Valid
    Alignment:
    - Valid
    Size:
    - Valid
- enabled-by: true
  post-conditions:
    Status: Zero
    MemptrVar: 'Null'
    Alignment: Valid
    Size: N/A
  pre-conditions:
    Memptr:
    - Valid
    Alignment:
    - Valid
    - Huge
    Size:
    - Zero
type: requirement