Branch data Line data Source code
1 : : #include "sute.h"
2 : :
3 : : #include <time.h>
4 : : #include "sha512.h"
5 : :
6 : : #ifndef ullint
7 : : typedef unsigned long long int ullint;
8 : : #endif
9 : :
10 : : #ifndef uchar
11 : : typedef unsigned char uchar;
12 : : #endif
13 : :
14 : : #define CYCLES 10
15 : : #define SHOW_TEST 0 /* Change to 1 to print out debug details */
16 : :
17 : : #if SHOW_TEST
18 : :
19 : : /**
20 : : * @brief Prints SHA-512 hash in hexadecimal format
21 : : * @details Outputs each byte of the hash as a two-digit hexadecimal number
22 : : *
23 : : * @param hash Pointer to SHA-512 hash array to be printed
24 : : *
25 : : * @note Only compiled when SHOW_TEST is set to 1
26 : : * @note Requires STDERR to be properly initialized
27 : : */
28 : : static void print_hash(const unsigned char *hash)
29 : : {
30 : : for(int i = 0; i < SHA512_DIGEST_LENGTH; i++)
31 : : {
32 : : echo(STDERR,"%02x",hash[i]);
33 : : }
34 : : echo(STDERR,"\n");
35 : : }
36 : : #endif
37 : :
38 : : /**
39 : : * @brief Tests copying of empty memory unsigned long long int structures
40 : : * @details Verifies that copying an empty memory structure works correctly
41 : : * by creating two unsigned long long int memory structures and copying one to another
42 : : *
43 : : * @return Return enum indicating success or failure of the test
44 : : * @retval SUCCESS if test passed
45 : : * @retval FAILURE if test failed
46 : : */
47 : 1 : static Return test0007_1(void)
48 : : {
49 : 1 : INITTEST;
50 : :
51 : : // Allocate memory for the structure int
52 : 1 : create(unsigned long long int,test0_0);
53 : 1 : create(unsigned long long int,test0_1);
54 : :
55 : : // Create and copy of an unsigned long long int memory arrays
56 [ + - + - ]: 1 : ASSERT(SUCCESS == resize(test0_0,0));
57 [ + - + - ]: 1 : ASSERT(SUCCESS == copy(test0_1,test0_0));
58 : :
59 : : // Cleanup
60 [ + - + - ]: 1 : ASSERT(SUCCESS == del(test0_0));
61 [ + - + - ]: 1 : ASSERT(SUCCESS == del(test0_1));
62 : :
63 [ + - - + : 1 : RETURN_STATUS;
- - - + +
- ]
64 : : }
65 : :
66 : : /**
67 : : * @brief Tests memory allocation and integrity for integer arrays
68 : : * @details Creates a random array of integers, computes its SHA-512 hash,
69 : : * copies the data to a managed memory structure, and verifies
70 : : * data integrity by comparing hashes
71 : : *
72 : : * @return Return enum indicating success or failure of the test
73 : : * @retval SUCCESS if memory allocation worked and hashes match
74 : : * @retval FAILURE if memory allocation failed or hashes don't match
75 : : */
76 : 1 : static Return test0007_2(void)
77 : : {
78 : 1 : INITTEST;
79 : :
80 : : unsigned char hash_1[SHA512_DIGEST_LENGTH];
81 : : unsigned char hash_2[SHA512_DIGEST_LENGTH];
82 : 1 : uint64_t random = 0;
83 : :
84 : 1 : size_t array_length = 1792;
85 : 1 : size_t array_size = array_length * sizeof(int);
86 : 1 : unsigned char *int_array = (unsigned char *)calloc(array_length,sizeof(int));
87 : :
88 [ - + ]: 1 : if(int_array == NULL)
89 : : {
90 : 0 : report("Memory callocation failed with bytes %zu",array_length * sizeof(int));
91 : 0 : return(FAILURE);
92 : : }
93 : :
94 : : // Fill the array with random bytes
95 [ + + ]: 7169 : for(size_t i = 0; i < array_size; i++)
96 : : {
97 [ + - + - ]: 7168 : ASSERT(SUCCESS == random_number_generator(&random,0,255));
98 : 7168 : int_array[i] = (unsigned char)random;
99 : : }
100 : :
101 : : // Calculate SHA-512 initial hash
102 : : SHA512_Context ctx;
103 : 1 : sha512_init(&ctx);
104 : 1 : sha512_update(&ctx,int_array,array_size);
105 : 1 : sha512_final(&ctx,hash_1);
106 : :
107 : : #if SHOW_TEST
108 : : // Print array summary and hash
109 : : echo(STDERR,"Test 1 array size: %zu bytes, array_length=%zu, sizeof(int)=%zu bytes\n",array_size,array_length,sizeof(int));
110 : : echo(STDERR,"Test 1 SHA-512 hash: ");
111 : : print_hash(hash_1);
112 : : #endif
113 : :
114 : : // Allocate memory for the structure int
115 : 1 : create(int,test1);
116 : :
117 : : // Create an int memory
118 [ + - + - ]: 1 : ASSERT(SUCCESS == resize(test1,array_length,ZERO_NEW_MEMORY));
119 : :
120 : : // Test memory edges
121 : 1 : int *test1_data = data(int,test1);
122 [ + - + - ]: 1 : ASSERT(test1_data != NULL);
123 : :
124 [ + - ]: 1 : if(test1_data != NULL)
125 : : {
126 : 1 : memcpy(test1_data,int_array,test1->length * test1->element_size);
127 : : }
128 : :
129 : : // Calculate hash of copied data
130 : 1 : sha512_init(&ctx);
131 : 1 : const int *test1_view = cdata(int,test1);
132 [ + - + - ]: 1 : ASSERT(test1_view != NULL);
133 : :
134 [ + - ]: 1 : if(test1_view != NULL)
135 : : {
136 : 1 : sha512_update(&ctx,(const unsigned char *)test1_view,test1->length * test1->element_size);
137 : : }
138 : 1 : sha512_final(&ctx,hash_2);
139 : :
140 : : #if SHOW_TEST
141 : : echo(STDERR,"Test 1 Array size: %zu bytes\n",test1->length * test1->element_size);
142 : : echo(STDERR,"Test 1 SHA-512 hash: ");
143 : : print_hash(hash_2);
144 : : #endif
145 : :
146 : : // Verify data integrity
147 [ + - + - ]: 1 : ASSERT(0 == memcmp(hash_1,hash_2,(size_t)SHA512_DIGEST_LENGTH));
148 : :
149 : : // Cleanup int array
150 : 1 : del(test1);
151 : 1 : reset(&int_array);
152 : :
153 [ + - - + : 1 : RETURN_STATUS;
- - - + +
- ]
154 : : }
155 : :
156 : : /**
157 : : * @brief Tests memory allocation and integrity for character arrays
158 : : * @details Creates a random array of characters, computes its SHA-512 hash,
159 : : * copies the data to a managed memory structure, and verifies
160 : : * data integrity by comparing hashes
161 : : *
162 : : * @return Return enum indicating success or failure of the test
163 : : * @retval SUCCESS if memory allocation worked and hashes match
164 : : * @retval FAILURE if memory allocation failed or hashes don't match
165 : : */
166 : 1 : static Return test0007_3(void)
167 : : {
168 : 1 : INITTEST;
169 : :
170 : : unsigned char hash_1[SHA512_DIGEST_LENGTH];
171 : : unsigned char hash_2[SHA512_DIGEST_LENGTH];
172 : 1 : uint64_t random = 0;
173 : :
174 : 1 : size_t array_length = 512;
175 : 1 : size_t array_size = array_length * sizeof(char);
176 : 1 : unsigned char *char_array = (unsigned char *)calloc(array_length,sizeof(char));
177 [ + - + - ]: 1 : ASSERT(char_array != NULL);
178 : :
179 [ - + ]: 1 : if(char_array == NULL)
180 : : {
181 : 0 : status = FAILURE;
182 [ # # # # : 0 : RETURN_STATUS;
# # # # #
# ]
183 : : }
184 : :
185 : : // Fill array with random bytes
186 [ + + ]: 513 : for(size_t i = 0; i < array_size; i++)
187 : : {
188 [ + - + - ]: 512 : ASSERT(SUCCESS == random_number_generator(&random,0,255));
189 : 512 : char_array[i] = (unsigned char)random;
190 : : }
191 : :
192 : : // Calculate initial hash
193 : : SHA512_Context ctx;
194 : 1 : sha512_init(&ctx);
195 : 1 : sha512_update(&ctx,char_array,array_size);
196 : 1 : sha512_final(&ctx,hash_1);
197 : :
198 : : #if SHOW_TEST
199 : : echo(STDERR,"Test 2 array size: %zu bytes, array_length=%zu, sizeof(char)=%zu bytes\n",array_size,array_length,sizeof(char));
200 : : echo(STDERR,"Test 2 SHA-512 hash: ");
201 : : print_hash(hash_1);
202 : : #endif
203 : :
204 : : // Test managed memory structure
205 : 1 : create(char,test2);
206 : :
207 : : // Create a char memory
208 [ + - + - ]: 1 : ASSERT(SUCCESS == resize(test2,array_length));
209 : :
210 : : // Test memory edges
211 : 1 : char *test2_data = data(char,test2);
212 [ + - + - ]: 1 : ASSERT(test2_data != NULL);
213 : :
214 [ + - ]: 1 : if(test2_data != NULL)
215 : : {
216 : 1 : memcpy(test2_data,char_array,test2->length * test2->element_size);
217 : : }
218 : :
219 : : // Calculate hash of copied data
220 : 1 : sha512_init(&ctx);
221 : 1 : const char *test2_view = cdata(char,test2);
222 [ + - + - ]: 1 : ASSERT(test2_view != NULL);
223 : :
224 [ + - ]: 1 : if(test2_view != NULL)
225 : : {
226 : 1 : sha512_update(&ctx,(const unsigned char *)test2_view,test2->length * test2->element_size);
227 : : }
228 : 1 : sha512_final(&ctx,hash_2);
229 : :
230 : : #if SHOW_TEST
231 : : echo(STDERR,"Test 2 array size: %zu bytes\n",test2->length * test2->element_size);
232 : : echo(STDERR,"Test 2 SHA-512 hash: ");
233 : : print_hash(hash_2);
234 : : #endif
235 : :
236 : : // Verify data integrity
237 [ - + ]: 1 : if(0 != memcmp(hash_1,hash_2,(size_t)SHA512_DIGEST_LENGTH))
238 : : {
239 : 0 : echo(STDERR,"Test 2 fail\n");
240 : 0 : status = FAILURE;
241 : : }
242 : :
243 : : // Cleanup char array
244 : 1 : del(test2);
245 : 1 : reset(&char_array);
246 : :
247 [ + - - + : 1 : RETURN_STATUS;
- - - + +
- ]
248 : : }
249 : :
250 : : /**
251 : : * @brief Comprehensive test of memory allocation and reallocation
252 : : * @details Performs three sequential tests:
253 : : * 1. Large allocation (4096 elements)
254 : : * 2. Reduction to medium size (256 elements)
255 : : * 3. Further reduction with forced memory shrinking (128 elements)
256 : : * Each test verifies data integrity using SHA-512 hashes
257 : : *
258 : : * @return Return enum indicating success or failure of the tests
259 : : * @retval SUCCESS if all three tests pass
260 : : * @retval FAILURE if any test fails or memory allocation fails
261 : : */
262 : 1 : static Return test0007_4(void)
263 : : {
264 : 1 : INITTEST;
265 : :
266 : : unsigned char hash_1[SHA512_DIGEST_LENGTH];
267 : : unsigned char hash_2[SHA512_DIGEST_LENGTH];
268 : 1 : uint64_t random = 0;
269 : 1 : unsigned long long int *test_data = NULL;
270 : 1 : const unsigned long long int *test_view = NULL;
271 : :
272 : : // TEST 4: Large allocation
273 : 1 : size_t array_length = 4096;
274 : 1 : size_t array_size = array_length * sizeof(unsigned long long int);
275 : 1 : unsigned char *ullint_array = (unsigned char *)calloc(array_length,sizeof(unsigned long long int));
276 : :
277 [ - + ]: 1 : if(ullint_array == NULL)
278 : : {
279 : 0 : return(FAILURE);
280 : : }
281 : :
282 : : // Fill array with random bytes
283 [ + + ]: 32769 : for(size_t i = 0; i < array_size; i++)
284 : : {
285 [ + - + - ]: 32768 : ASSERT(SUCCESS == random_number_generator(&random,0,255));
286 : 32768 : ullint_array[i] = (unsigned char)random;
287 : : }
288 : :
289 : : // Calculate SHA-512 hash
290 : : SHA512_Context ctx;
291 : 1 : sha512_init(&ctx);
292 : 1 : sha512_update(&ctx,ullint_array,array_size);
293 : 1 : sha512_final(&ctx,hash_1);
294 : :
295 : : #if SHOW_TEST
296 : : // Print array summary and hash
297 : : echo(STDERR,"Test 4 array size: %zu bytes, array_length=%zu, sizeof(unsigned long long int)=%zu bytes\n",array_size,array_length,sizeof(unsigned long long int));
298 : : echo(STDERR,"Test 4 SHA-512 hash: ");
299 : : print_hash(hash_1);
300 : : #endif
301 : :
302 : : // Allocate memory for the structure unsigned long long int
303 : 1 : create(unsigned long long int,test);
304 : :
305 : : // Create an unsigned long long int memory
306 [ + - + - ]: 1 : ASSERT(SUCCESS == resize(test,array_length));
307 : :
308 : : // Test memory edges
309 : 1 : test_data = data(unsigned long long int,test);
310 [ + - + - ]: 1 : ASSERT(test_data != NULL);
311 : :
312 [ + - ]: 1 : if(test_data != NULL)
313 : : {
314 : 1 : memcpy(test_data,ullint_array,test->length * test->element_size);
315 : : }
316 : :
317 : : // Calculate SHA-512 hash
318 : 1 : sha512_init(&ctx);
319 : 1 : test_view = cdata(unsigned long long int,test);
320 [ + - + - ]: 1 : ASSERT(test_view != NULL);
321 : :
322 [ + - ]: 1 : if(test_view != NULL)
323 : : {
324 : 1 : sha512_update(&ctx,(const unsigned char *)test_view,test->length * test->element_size);
325 : : }
326 : 1 : sha512_final(&ctx,hash_2);
327 : :
328 : : #if SHOW_TEST
329 : : // Print array summary and hash
330 : : echo(STDERR,"Test 4 array size: %zu bytes\n",test->length * test->element_size);
331 : : echo(STDERR,"Test 4 SHA-512 hash: ");
332 : : print_hash(hash_2);
333 : : #endif
334 : :
335 [ + - + - ]: 1 : ASSERT(0 == memcmp(hash_1,hash_2,(size_t)SHA512_DIGEST_LENGTH));
336 : :
337 : : /**
338 : : * @brief TEST 5 verifies correct memory reallocation with size reduction
339 : : * @details Checks that:
340 : : * 1. Memory block can be correctly reallocated to a smaller size
341 : : * 2. Memory contents are preserved during reduction
342 : : * 3. Memory integrity is maintained after reduction
343 : : */
344 : 1 : array_length = 256;
345 : 1 : array_size = array_length * sizeof(unsigned long long int);
346 : 1 : ullint_array = (unsigned char *)realloc(ullint_array,array_size);
347 : :
348 : : // Fill array with random bytes
349 [ + + ]: 2049 : for(size_t i = 0; i < array_size; i++)
350 : : {
351 [ + - + - ]: 2048 : ASSERT(SUCCESS == random_number_generator(&random,0,255));
352 : 2048 : ullint_array[i] = (unsigned char)random;
353 : : }
354 : :
355 : : // Calculate SHA-512 hash
356 : 1 : sha512_init(&ctx);
357 : 1 : sha512_update(&ctx,ullint_array,array_size);
358 : 1 : sha512_final(&ctx,hash_1);
359 : :
360 : : #if SHOW_TEST
361 : : // Print array summary and hash
362 : : echo(STDERR,"Test 5 array size: %zu bytes, array_length=%zu, sizeof(unsigned long long int)=%zu bytes\n",array_size,array_length,sizeof(unsigned long long int));
363 : : echo(STDERR,"Test 5 SHA-512 hash: ");
364 : : print_hash(hash_1);
365 : : #endif
366 : :
367 : : // Create an unsigned long long int memory
368 [ + - + - ]: 1 : ASSERT(SUCCESS == resize(test,array_length));
369 : :
370 : 1 : test_data = data(unsigned long long int,test);
371 [ + - + - ]: 1 : ASSERT(test_data != NULL);
372 : :
373 [ + - ]: 1 : if(test_data != NULL)
374 : : {
375 : 1 : memcpy(test_data,ullint_array,test->length * test->element_size);
376 : : }
377 : :
378 : : // Calculate SHA-512 hash
379 : 1 : sha512_init(&ctx);
380 : 1 : test_view = cdata(unsigned long long int,test);
381 [ + - + - ]: 1 : ASSERT(test_view != NULL);
382 : :
383 [ + - ]: 1 : if(test_view != NULL)
384 : : {
385 : 1 : sha512_update(&ctx,(const unsigned char *)test_view,test->length * test->element_size);
386 : : }
387 : 1 : sha512_final(&ctx,hash_2);
388 : :
389 : : #if SHOW_TEST
390 : : // Print array summary and hash
391 : : echo(STDERR,"Test 5 array size: %zu bytes\n",test->length * test->element_size);
392 : : echo(STDERR,"Test 5 SHA-512 hash: ");
393 : : print_hash(hash_2);
394 : : #endif
395 : :
396 [ + - + - ]: 1 : ASSERT(0 == memcmp(hash_1,hash_2,(size_t)SHA512_DIGEST_LENGTH));
397 : :
398 : : /**
399 : : * @brief TEST 6 validates memory cleanup and deallocation
400 : : * @details Verifies:
401 : : * 1. Memory can be properly freed
402 : : * 2. All memory counters are correctly updated
403 : : * 3. Memory structure is reset to initial state
404 : : * 4. No memory leaks occur during cleanup
405 : : * 5. Telemetry accurately reflects the deallocation
406 : : */
407 : 1 : array_length = 128;
408 : 1 : array_size = array_length * sizeof(unsigned long long int);
409 : 1 : ullint_array = (unsigned char *)realloc(ullint_array,array_size);
410 : :
411 : : // Fill array with random bytes
412 [ + + ]: 1025 : for(size_t i = 0; i < array_size; i++)
413 : : {
414 [ + - + - ]: 1024 : ASSERT(SUCCESS == random_number_generator(&random,0,255));
415 : 1024 : ullint_array[i] = (unsigned char)random;
416 : : }
417 : :
418 : : // Calculate SHA-512 hash
419 : 1 : sha512_init(&ctx);
420 : 1 : sha512_update(&ctx,ullint_array,array_size);
421 : 1 : sha512_final(&ctx,hash_1);
422 : :
423 : : #if SHOW_TEST
424 : : // Print array summary and hash
425 : : echo(STDERR,"Test 6 array size: %zu bytes, array_length=%zu, sizeof(unsigned long long int)=%zu bytes\n",array_size,array_length,sizeof(unsigned long long int));
426 : : echo(STDERR,"Test 6 SHA-512 hash: ");
427 : : print_hash(hash_1);
428 : : #endif
429 : :
430 : : // Create an unsigned long long int memory
431 [ + - + - ]: 1 : ASSERT(SUCCESS == resize(test,array_length));
432 : :
433 : 1 : test_data = data(unsigned long long int,test);
434 [ + - + - ]: 1 : ASSERT(test_data != NULL);
435 : :
436 [ + - ]: 1 : if(test_data != NULL)
437 : : {
438 : 1 : memcpy(test_data,ullint_array,test->length * test->element_size);
439 : : }
440 : :
441 : : // Calculate SHA-512 hash
442 : 1 : sha512_init(&ctx);
443 : 1 : test_view = cdata(unsigned long long int,test);
444 [ + - + - ]: 1 : ASSERT(test_view != NULL);
445 : :
446 [ + - ]: 1 : if(test_view != NULL)
447 : : {
448 : 1 : sha512_update(&ctx,(const unsigned char *)test_view,test->length * test->element_size);
449 : : }
450 : 1 : sha512_final(&ctx,hash_2);
451 : :
452 : : #if SHOW_TEST
453 : : // Print array summary and hash
454 : : echo(STDERR,"Test 6 array size: %zu bytes\n",test->length * test->element_size);
455 : : echo(STDERR,"Test 6 SHA-512 hash: ");
456 : : print_hash(hash_2);
457 : : #endif
458 : :
459 [ + - + - ]: 1 : ASSERT(0 == memcmp(hash_1,hash_2,(size_t)SHA512_DIGEST_LENGTH));
460 : :
461 : : // free an empty unsigned long long int array
462 : 1 : del(test);
463 : 1 : reset(&ullint_array);
464 : :
465 : : #if SHOW_TEST
466 : : telemetry_show();
467 : : #endif
468 : :
469 [ + - - + : 1 : RETURN_STATUS;
- - - + +
- ]
470 : : }
471 : :
472 : : /**
473 : : * @brief Multiple tests with unsigned long long int type and different array sizes
474 : : *
475 : : */
476 : 1 : static Return test0007_5(void)
477 : : {
478 : 1 : INITTEST;
479 : :
480 [ - + - - : 1 : SLOWTEST;
- - - - -
- - - ]
481 : :
482 : : #define TYPE ullint
483 : : #include "test0007.cc"
484 : : #undef TYPE
485 : :
486 [ + - - + : 1 : RETURN_STATUS;
- - - + +
- ]
487 : : }
488 : :
489 : : /**
490 : : * @brief Multiple tests with char type and different array sizes
491 : : *
492 : : */
493 : 1 : static Return test0007_6(void)
494 : : {
495 : 1 : INITTEST;
496 : :
497 [ - + - - : 1 : SLOWTEST;
- - - - -
- - - ]
498 : :
499 : : #define TYPE char
500 : : #include "test0007.cc"
501 : : #undef TYPE
502 : :
503 [ + - - + : 1 : RETURN_STATUS;
- - - + +
- ]
504 : : }
505 : :
506 : : /**
507 : : * @brief Multiple tests with int type and different array sizes
508 : : *
509 : : */
510 : 1 : static Return test0007_7(void)
511 : : {
512 : 1 : INITTEST;
513 : :
514 [ - + - - : 1 : SLOWTEST;
- - - - -
- - - ]
515 : :
516 : : #define TYPE int
517 : : #include "test0007.cc"
518 : : #undef TYPE
519 : :
520 [ + - - + : 1 : RETURN_STATUS;
- - - + +
- ]
521 : : }
522 : :
523 : : /**
524 : : * @brief Multiple tests with undigned char type and different array sizes
525 : : *
526 : : */
527 : 1 : static Return test0007_8(void)
528 : : {
529 : 1 : INITTEST;
530 : :
531 [ - + - - : 1 : SLOWTEST;
- - - - -
- - - ]
532 : :
533 : : #define TYPE uchar
534 : : #include "test0007.cc"
535 : : #undef TYPE
536 : :
537 [ + - - + : 1 : RETURN_STATUS;
- - - + +
- ]
538 : : }
539 : :
540 : 1 : static Return test0007_9(void)
541 : : {
542 : 1 : INITTEST;
543 : :
544 : 1 : init_telemetry();
545 : :
546 : 1 : create(char,buffer);
547 : :
548 [ + - + - ]: 1 : ASSERT(telemetry.current_heap_bytes == 0);
549 [ + - + - ]: 1 : ASSERT(telemetry.current_payload_bytes == 0);
550 [ + - + - ]: 1 : ASSERT(telemetry.active_descriptors == 0);
551 : :
552 : 1 : const size_t block = MEMORY_BLOCK_BYTES;
553 : 1 : const size_t big_count = block + 1;
554 : :
555 [ + - + - ]: 1 : ASSERT(SUCCESS == resize(buffer,1));
556 : :
557 [ + - + - ]: 1 : ASSERT(telemetry.current_heap_bytes == block);
558 [ + - + - ]: 1 : ASSERT(telemetry.current_payload_bytes == 1);
559 [ + - + - ]: 1 : ASSERT(telemetry.total_heap_bytes_acquired == block);
560 [ + - + - ]: 1 : ASSERT(telemetry.total_payload_bytes_acquired == 1);
561 [ + - + - ]: 1 : ASSERT(telemetry.fresh_allocations_counter == 1);
562 [ + - + - ]: 1 : ASSERT(telemetry.active_descriptors == 1);
563 [ + - + - ]: 1 : ASSERT(telemetry.peak_active_descriptors == 1);
564 [ + - + - ]: 1 : ASSERT(telemetry.peak_heap_bytes == block);
565 [ + - + - ]: 1 : ASSERT(telemetry.current_alignment_overhead_bytes == block - 1);
566 [ + - + - ]: 1 : ASSERT(telemetry.total_alignment_overhead_bytes == block - 1);
567 [ + - + - ]: 1 : ASSERT(telemetry.peak_alignment_overhead_bytes == block - 1);
568 : :
569 [ + - + - ]: 1 : ASSERT(SUCCESS == resize(buffer,big_count));
570 : :
571 [ + - + - ]: 1 : ASSERT(telemetry.current_heap_bytes == block * 2);
572 [ + - + - ]: 1 : ASSERT(telemetry.total_heap_bytes_acquired == block * 2);
573 [ + - + - ]: 1 : ASSERT(telemetry.current_payload_bytes == big_count);
574 [ + - + - ]: 1 : ASSERT(telemetry.total_payload_bytes_acquired == big_count);
575 [ + - + - ]: 1 : ASSERT(telemetry.heap_reallocations_counter == 1);
576 [ + - + - ]: 1 : ASSERT(telemetry.peak_heap_bytes == block * 2);
577 : :
578 [ + - + - ]: 1 : ASSERT(SUCCESS == resize(buffer,1,RELEASE_UNUSED));
579 : :
580 [ + - + - ]: 1 : ASSERT(telemetry.current_heap_bytes == block);
581 [ + - + - ]: 1 : ASSERT(telemetry.current_payload_bytes == 1);
582 [ + - + - ]: 1 : ASSERT(telemetry.total_heap_bytes_released == block);
583 [ + - + - ]: 1 : ASSERT(telemetry.release_unused_operations_counter == 1);
584 [ + - + - ]: 1 : ASSERT(telemetry.release_unused_bytes_total == block);
585 [ + - + - ]: 1 : ASSERT(telemetry.heap_reallocations_counter == 2);
586 : :
587 [ + - + - ]: 1 : ASSERT(SUCCESS == del(buffer));
588 : :
589 [ + - + - ]: 1 : ASSERT(telemetry.current_heap_bytes == 0);
590 [ + - + - ]: 1 : ASSERT(telemetry.current_payload_bytes == 0);
591 [ + - + - ]: 1 : ASSERT(telemetry.active_descriptors == 0);
592 [ + - + - ]: 1 : ASSERT(telemetry.release_operations_counter == 1);
593 [ + - + - ]: 1 : ASSERT(telemetry.total_heap_bytes_released == block * 2);
594 [ + - + - ]: 1 : ASSERT(telemetry.peak_heap_bytes == block * 2);
595 : :
596 : : #if SHOW_TEST
597 : : telemetry_show();
598 : : #endif
599 : :
600 [ + - - + : 1 : RETURN_STATUS;
- - - + +
- ]
601 : : }
602 : :
603 : : /**
604 : : * @brief Main test runner for memory management tests
605 : : * @details Executes a series of tests to verify memory management functionality:
606 : : * - Empty structure copying
607 : : * - Integer array allocation and verification
608 : : * - Character array allocation and verification
609 : : * - Multiple reallocation scenarios
610 : : *
611 : : * @return Return enum indicating overall test success or failure
612 : : * @retval SUCCESS if all tests pass
613 : : * @retval FAILURE if any test fails
614 : : */
615 : 1 : Return test0007(void)
616 : : {
617 : 1 : INITTEST;
618 : :
619 [ + - ]: 1 : TEST(test0007_1,"Copy an array of 0 size…");
620 [ + - ]: 1 : TEST(test0007_2,"libmem Memory allocator test 1…");
621 [ + - ]: 1 : TEST(test0007_3,"libmem Memory allocator test 2…");
622 [ + - ]: 1 : TEST(test0007_4,"libmem Memory allocator tests 4,5,6…");
623 [ + - ]: 1 : TEST(test0007_5,"libmem generate multiple tests unsigned long long int type…");
624 [ + - ]: 1 : TEST(test0007_6,"libmem generate multiple tests char type…");
625 [ + - ]: 1 : TEST(test0007_7,"libmem generate multiple tests int type…");
626 [ + - ]: 1 : TEST(test0007_8,"libmem generate multiple tests unsigned char type…");
627 [ + - ]: 1 : TEST(test0007_9,"libmem telemetry counters…");
628 : :
629 [ + - - + : 1 : RETURN_STATUS;
- - - + +
- ]
630 : : }
|