summaryrefslogtreecommitdiffstats
path: root/spec/rtems/malloc/req/malloc.yml
blob: 0d936fa657006ce1688ed658ca733bebdcaa8f80 (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
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/malloc
post-conditions:
- name: Status
  states:
  - name: 'Null'
    test-code: |
      T_null( ctx->ptr );
    text: |
      The return value of ${../if/malloc:/name} shall be equal to
      ${/c/if/null:/name}.
  - name: AreaBegin
    test-code: |
      T_not_null( ctx->ptr );
    text: |
      The return value of ${../if/malloc:/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_malloc( ctx->size );
      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->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;
    uintptr_t a;
    uintptr_t b;
    uintptr_t size;
pre-conditions:
- 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 = 1;
    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->ptr = rtems_malloc( 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 contains the return value of the ${../if/malloc:/name} call.
  description: null
  member: |
    void *ptr
- 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:
- 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-malloc.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
  pre-conditions:
    Size:
    - Valid
- enabled-by: true
  post-conditions:
    Status: 'Null'
    Alignment: Valid
    Size: N/A
  pre-conditions:
    Size:
    - Huge
    - Zero
type: requirement