@@ -29,7 +29,7 @@ void mbedtls_memory_buffer_alloc_self_test( )
29
29
}
30
30
/* END_CASE */
31
31
32
- /* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
32
+ /* BEGIN_CASE */
33
33
void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
34
34
int d_bytes, int free_a, int free_b,
35
35
int free_c, int free_d, int e_bytes,
@@ -39,8 +39,11 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
39
39
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL, *ptr_d = NULL,
40
40
*ptr_e = NULL, *ptr_f = NULL;
41
41
42
+ #if defined(MBEDTLS_MEMORY_DEBUG)
42
43
size_t reported_blocks;
43
- size_t allocated_bytes = 0, reported_bytes;
44
+ size_t reported_bytes;
45
+ #endif
46
+ size_t allocated_bytes = 0;
44
47
45
48
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
46
49
@@ -78,8 +81,10 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
78
81
allocated_bytes += d_bytes * sizeof(char);
79
82
}
80
83
84
+ #if defined(MBEDTLS_MEMORY_DEBUG)
81
85
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
82
86
TEST_ASSERT( reported_bytes == allocated_bytes );
87
+ #endif
83
88
84
89
if( free_a )
85
90
{
@@ -117,8 +122,10 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
117
122
allocated_bytes -= d_bytes * sizeof(char);
118
123
}
119
124
125
+ #if defined(MBEDTLS_MEMORY_DEBUG)
120
126
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
121
127
TEST_ASSERT( reported_bytes == allocated_bytes );
128
+ #endif
122
129
123
130
if( e_bytes > 0 )
124
131
{
@@ -178,8 +185,10 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
178
185
ptr_f = NULL;
179
186
}
180
187
188
+ #if defined(MBEDTLS_MEMORY_DEBUG)
181
189
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
182
190
TEST_ASSERT( reported_bytes == 0 );
191
+ #endif
183
192
184
193
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
185
194
@@ -188,12 +197,14 @@ exit:
188
197
}
189
198
/* END_CASE */
190
199
191
- /* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
200
+ /* BEGIN_CASE */
192
201
void memory_buffer_alloc_oom_test( )
193
202
{
194
203
unsigned char buf[1024];
195
204
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL;
205
+ #if defined(MBEDTLS_MEMORY_DEBUG)
196
206
size_t reported_blocks, reported_bytes;
207
+ #endif
197
208
198
209
(void)ptr_c;
199
210
@@ -210,8 +221,10 @@ void memory_buffer_alloc_oom_test( )
210
221
ptr_c = mbedtls_calloc( 431, sizeof(char) );
211
222
TEST_ASSERT( ptr_c == NULL );
212
223
224
+ #if defined(MBEDTLS_MEMORY_DEBUG)
213
225
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
214
226
TEST_ASSERT( reported_bytes >= 864 && reported_bytes <= sizeof(buf) );
227
+ #endif
215
228
216
229
mbedtls_free( ptr_a );
217
230
ptr_a = NULL;
@@ -221,8 +234,10 @@ void memory_buffer_alloc_oom_test( )
221
234
ptr_b = NULL;
222
235
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
223
236
237
+ #if defined(MBEDTLS_MEMORY_DEBUG)
224
238
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
225
239
TEST_ASSERT( reported_bytes == 0 );
240
+ #endif
226
241
227
242
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
228
243
@@ -231,17 +246,20 @@ exit:
231
246
}
232
247
/* END_CASE */
233
248
234
- /* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
235
- void memory_buffer_small_buffer ( )
249
+ /* BEGIN_CASE */
250
+ void memory_buffer_heap_too_small ( )
236
251
{
237
252
unsigned char buf[1];
238
253
239
254
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
255
+ /* With MBEDTLS_MEMORY_DEBUG enabled, this prints a message
256
+ * "FATAL: verification of first header failed".
257
+ */
240
258
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() != 0 );
241
259
}
242
260
/* END_CASE */
243
261
244
- /* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
262
+ /* BEGIN_CASE */
245
263
void memory_buffer_underalloc( )
246
264
{
247
265
unsigned char buf[100];
0 commit comments