summaryrefslogtreecommitdiffstats
path: root/spec/rtems/malloc/req/calloc.yml
blob: 8e5b25971cd4fef902f342ddfec668398dfde41e (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
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/calloc
post-conditions:
- name: Status
  states:
  - name: 'Null'
    test-code: |
      T_null( ctx->ptr );
    text: |
      The return value of ${../if/calloc:/name} shall be equal to
      ${/c/if/null:/name}.
  - name: AreaBegin
    test-code: |
      T_not_null( ctx->ptr );
    text: |
      The return value of ${../if/calloc:/name} shall be equal to the begin
      address of the allocated memory area.
  test-epilogue: null
  test-prologue: null
- name: Alignment
  states:
  - name: Valid
    test-code: |
      T_eq_uptr( (uintptr_t) ctx->ptr % CPU_HEAP_ALIGNMENT, 0 );
    text: |
      The begin address of the allocated memory area shall be an integral
      multiple of the heap alignment of the ${/glossary/target-arch:/term}.
  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->ptr;
      ctx->ptr = rtems_calloc( ctx->nelem, ctx->elsize );
      T_not_null( ptr );
      a = (uintptr_t) ptr;
      b = (uintptr_t) ctx->ptr;
      size = a < b ? b - a : a - b;
      T_ge_uptr( size, ctx->nelem * ctx->elsize );
    text: |
      The size of the allocated memory area shall greater than or equal to the
      product of the ``nelem`` and ``elsize`` parameters.
  test-epilogue: null
  test-prologue: |
    void     *ptr;
    uintptr_t a;
    uintptr_t b;
    uintptr_t size;
- name: Content
  states:
  - name: Zero
    test-code: |
      T_eq_u64( *(uint64_t *) ctx->ptr, 0 );
    text: |
      The content of the allocated memory area shall be cleared to zero.
  test-epilogue: null
  test-prologue: null
pre-conditions:
- name: ElementCount
  states:
  - name: Huge
    test-code: |
      ctx->nelem = SIZE_MAX;
    text: |
      While the ``nelem`` parameter is not equal to zero, while the ``nelem``
      parameter is too large to allocate a memory area with the specified size.
  - name: Zero
    test-code: |
      ctx->nelem = 0;
    text: |
      While the ``nelem`` parameter is equal to zero.
  - name: Valid
    test-code: |
      ctx->nelem = 1;
    text: |
      While the ``nelem`` parameter is not equal to zero, while the ``nelem``
      parameter is small enough to allocate a memory area with the specified
      size.
  test-epilogue: null
  test-prologue: null
- name: ElementSize
  states:
  - name: Huge
    test-code: |
      ctx->elsize = SIZE_MAX;
    text: |
      While the ``elsize`` parameter is not equal to zero, while the ``elsize``
      parameter is too large to allocate a memory area with the specified size.
  - name: Zero
    test-code: |
      ctx->elsize = 0;
    text: |
      While the ``elsize`` parameter is equal to zero.
  - name: Valid
    test-code: |
      ctx->elsize = sizeof( uint64_t );
    text: |
      While the ``elsize`` parameter is not equal to zero, while the ``elsize``
      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->ptr = rtems_calloc( ctx->nelem, ctx->elsize );
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 contains the return value of the ${../if/calloc:/name} call.
  description: null
  member: |
    void *ptr
- brief: |
    This member specifies if the ``nelem`` parameter value.
  description: null
  member: |
    size_t nelem
- brief: |
    This member specifies if the ``elsize`` parameter value.
  description: null
  member: |
    size_t elsize
test-context-support: null
test-description: null
test-header: null
test-includes:
- rtems/malloc.h
test-local-includes:
- tx-support.h
test-prepare: null
test-setup:
  brief: null
  code: |
    MemorySave( &ctx->mem_ctx );
  description: null
test-stop: null
test-support: null
test-target: testsuites/validation/tc-mem-rtems-calloc.c
test-teardown:
  brief: null
  code: |
    MemoryRestore( &ctx->mem_ctx );
  description: null
text: ${.:text-template}
transition-map:
- enabled-by: true
  post-conditions:
    Status: AreaBegin
    Alignment: Valid
    Size: Valid
    Content: Zero
  pre-conditions:
    ElementCount:
    - Valid
    ElementSize:
    - Valid
- enabled-by: true
  post-conditions:
    Status: 'Null'
    Alignment: Valid
    Size: N/A
    Content: N/A
  pre-conditions:
    ElementCount:
    - Huge
    - Zero
    ElementSize:
    - Huge
    - Zero
    - Valid
- enabled-by: true
  post-conditions:
    Status: 'Null'
    Alignment: Valid
    Size: N/A
    Content: N/A
  pre-conditions:
    ElementCount:
    - Valid
    ElementSize:
    - Huge
    - Zero
type: requirement