Line data Source code
1 : /** @file suite_libdebug-memdbg.c
2 : * @brief Check Libdebug memdbg functions
3 : * @author François Cerbelle (Fanfan), francois@cerbelle.net
4 : *
5 : * @internal
6 : * Created: 26/06/2024
7 : * Revision: none
8 : * Last modified: 2024-12-19 19:51
9 : * Compiler: gcc
10 : * Organization: Cerbelle.net
11 : * Copyright: Copyright (c) 2024, François Cerbelle
12 : *
13 : * This source code is released for free distribution under the terms of the
14 : * GNU General Public License as published by the Free Software Foundation.
15 : */
16 :
17 : #ifdef HAVE_CONFIG_H
18 : #include "config.h"
19 : #endif
20 :
21 : #define _XOPEN_SOURCE 500 /* snprintf */
22 : #include "libdebug/memdbg.h"
23 : #include "oom.h" /* oomfill_setup */
24 : #include <check.h>
25 : #include <unistd.h> /* pid_t getpid() */
26 : #include <sys/stat.h> /* mkdir(), chdir(), mode_t */
27 : #include <stdio.h> /* printf() */
28 : #include <stdlib.h> /* abort() */
29 : #include "checktools.inc"
30 :
31 : #ifndef NDEBUG
32 6 : START_TEST(memdbg_malloc_0) {
33 : uint64_t l_NbBlocks;
34 : size_t l_RAMSize;
35 : void* result;
36 :
37 : /* LibMemTrack consistency check preparation */
38 6 : l_NbBlocks=memtrack_getallocatedblocks();
39 6 : l_RAMSize=memtrack_getallocatedRAM();
40 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
41 :
42 : oomfill_fill(_i,2);
43 : /* Malloc has a non portable behavior, see man page, for 0 sized blocks */
44 : /* We should not support it */
45 6 : result=dbg_malloc(
46 : 0,
47 : __FILE__, __LINE__,
48 : __DATE__, __TIME__,__func__
49 : );
50 : oomfill_free();
51 6 : ck_assert(NULL==result);
52 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
53 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
54 6 : }
55 : END_TEST
56 : #endif
57 :
58 : #ifndef NDEBUG
59 6 : START_TEST(memdbg_malloc_null) {
60 : uint64_t l_NbBlocks;
61 : size_t l_RAMSize;
62 : void* result;
63 :
64 : /* LibMemTrack consistency check preparation */
65 6 : l_NbBlocks=memtrack_getallocatedblocks();
66 6 : l_RAMSize=memtrack_getallocatedRAM();
67 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
68 :
69 : oomfill_fill(_i,2);
70 6 : result=dbg_malloc(
71 : 1,
72 : __FILE__,0,
73 : __DATE__, __TIME__,__func__
74 : );
75 : oomfill_free();
76 6 : ck_assert(NULL==result);
77 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
78 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
79 :
80 : oomfill_fill(_i,2);
81 6 : result=dbg_malloc(
82 : 1,
83 : "", __LINE__,
84 : __DATE__, __TIME__,__func__
85 : );
86 : oomfill_free();
87 6 : ck_assert(NULL==result);
88 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
89 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
90 :
91 : oomfill_fill(_i,2);
92 6 : result=dbg_malloc(
93 : 1,
94 : __FILE__, __LINE__,
95 : "", __TIME__,__func__
96 : );
97 : oomfill_free();
98 6 : ck_assert(NULL==result);
99 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
100 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
101 :
102 : oomfill_fill(_i,2);
103 6 : result=dbg_malloc(
104 : 1,
105 : __FILE__, __LINE__,
106 : __DATE__, "",__func__
107 : );
108 : oomfill_free();
109 6 : ck_assert(NULL==result);
110 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
111 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
112 :
113 : oomfill_fill(_i,2);
114 6 : result=dbg_malloc(
115 : 1,
116 : __FILE__, __LINE__,
117 : __DATE__, __TIME__,""
118 : );
119 : oomfill_free();
120 6 : ck_assert(NULL==result);
121 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
122 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
123 6 : }
124 : END_TEST
125 : #endif
126 :
127 : #ifndef NDEBUG
128 6 : START_TEST(memdbg_free_null) {
129 : uint64_t l_NbBlocks;
130 : size_t l_RAMSize;
131 6 : void* result=NULL;
132 :
133 : /* LibMemTrack consistency check preparation */
134 6 : l_NbBlocks=memtrack_getallocatedblocks();
135 6 : l_RAMSize=memtrack_getallocatedRAM();
136 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
137 :
138 : /* should work */
139 : oomfill_fill(_i,2);
140 6 : dbg_free(NULL,
141 : __FILE__, __LINE__,
142 : __DATE__, __TIME__,__func__
143 : );
144 : oomfill_free();
145 6 : ck_assert(NULL==result);
146 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
147 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
148 6 : }
149 : END_TEST
150 : #endif
151 :
152 : #ifndef NDEBUG
153 6 : START_TEST(memdbg_free_invalid) {
154 : uint64_t l_NbBlocks;
155 :
156 : /* LibMemTrack consistency check preparation */
157 6 : l_NbBlocks=memtrack_getallocatedblocks();
158 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
159 :
160 : /* This test is supposed to trigger a SIGABRT(6) and will crash the
161 : * whole testsuite if not caught or not in a child process */
162 6 : forktest_only;
163 : #ifdef ENABLE_GCOV
164 : if (oomfill_enabled())
165 : __gcov_dump();
166 : #endif
167 : oomfill_fill(_i,2);
168 4 : dbg_free((void*)123,
169 : __FILE__, __LINE__,
170 : __DATE__, __TIME__,__func__
171 : );
172 : /* Never reached, dead code */
173 : }
174 : END_TEST
175 : #endif
176 :
177 :
178 : #ifndef NDEBUG
179 6 : START_TEST(memdbg_mallocfree) {
180 : uint64_t l_NbBlocks;
181 : size_t l_RAMSize;
182 : void* result;
183 :
184 : /* LibMemTrack consistency check preparation */
185 6 : l_NbBlocks=memtrack_getallocatedblocks();
186 6 : l_RAMSize=memtrack_getallocatedRAM();
187 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
188 :
189 : /* Allocate */
190 : oomfill_fill(_i,2);
191 6 : result=dbg_malloc(
192 : 10000,
193 : __FILE__, __LINE__,
194 : __DATE__, __TIME__,__func__
195 : );
196 : oomfill_free();
197 6 : ck_assert((NULL!=result)||(oomfill_enabled()));
198 6 : if (NULL!=result) {
199 : /* Function returned the expected result */
200 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
201 6 : ck_assert(l_RAMSize+10000==memtrack_getallocatedRAM());
202 : } else {
203 : /* Function failed to return expected result while in OOM mode */
204 0 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
205 0 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
206 : }
207 :
208 : /* Deallocate */
209 : oomfill_fill(_i,2);
210 6 : dbg_free(result,
211 : __FILE__, __LINE__,
212 : __DATE__, __TIME__,__func__
213 : );
214 : oomfill_free();
215 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
216 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
217 6 : }
218 : END_TEST
219 : #endif
220 :
221 : #ifndef NDEBUG
222 6 : START_TEST(memdbg_calloc_0) {
223 : uint64_t l_NbBlocks;
224 : size_t l_RAMSize;
225 : void* result;
226 :
227 : /* LibMemTrack consistency check preparation */
228 6 : l_NbBlocks=memtrack_getallocatedblocks();
229 6 : l_RAMSize=memtrack_getallocatedRAM();
230 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
231 :
232 : oomfill_fill(_i,2);
233 : /* As well as malloc, calloc returns a pointer for a zero sized block allocation */
234 : /* We do not want to support this */
235 6 : result=dbg_calloc(
236 : 0, 0,
237 : __FILE__, __LINE__,
238 : __DATE__, __TIME__,__func__
239 : );
240 : oomfill_free();
241 6 : ck_assert(NULL==result);
242 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
243 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
244 :
245 : oomfill_fill(_i,2);
246 6 : result=dbg_calloc(
247 : 1, 0,
248 : __FILE__, __LINE__,
249 : __DATE__, __TIME__,__func__
250 : );
251 : oomfill_free();
252 6 : ck_assert(NULL==result);
253 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
254 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
255 :
256 : oomfill_fill(_i,2);
257 6 : result=dbg_calloc(
258 : 0, 1,
259 : __FILE__, __LINE__,
260 : __DATE__, __TIME__,__func__
261 : );
262 : oomfill_free();
263 6 : ck_assert(NULL==result);
264 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
265 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
266 6 : }
267 : END_TEST
268 : #endif
269 :
270 : #ifndef NDEBUG
271 6 : START_TEST(memdbg_calloc_null) {
272 : uint64_t l_NbBlocks;
273 : size_t l_RAMSize;
274 : void* result;
275 :
276 : /* LibMemTrack consistency check preparation */
277 6 : l_NbBlocks=memtrack_getallocatedblocks();
278 6 : l_RAMSize=memtrack_getallocatedRAM();
279 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
280 :
281 : oomfill_fill(_i,2);
282 6 : result=dbg_calloc(
283 : 1,1,
284 : __FILE__,0,
285 : __DATE__, __TIME__,__func__
286 : );
287 : oomfill_free();
288 6 : ck_assert(NULL==result);
289 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
290 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
291 :
292 : oomfill_fill(_i,2);
293 6 : result=dbg_calloc(
294 : 1,1,
295 : "", __LINE__,
296 : __DATE__, __TIME__,__func__
297 : );
298 : oomfill_free();
299 6 : ck_assert(NULL==result);
300 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
301 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
302 :
303 : oomfill_fill(_i,2);
304 6 : result=dbg_calloc(
305 : 1,1,
306 : __FILE__, __LINE__,
307 : "", __TIME__,__func__
308 : );
309 : oomfill_free();
310 6 : ck_assert(NULL==result);
311 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
312 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
313 :
314 : oomfill_fill(_i,2);
315 6 : result=dbg_calloc(
316 : 1,1,
317 : __FILE__, __LINE__,
318 : __DATE__, "",__func__
319 : );
320 : oomfill_free();
321 6 : ck_assert(NULL==result);
322 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
323 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
324 :
325 : oomfill_fill(_i,2);
326 6 : result=dbg_calloc(
327 : 1,1,
328 : __FILE__, __LINE__,
329 : __DATE__, __TIME__,""
330 : );
331 : oomfill_free();
332 6 : ck_assert(NULL==result);
333 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
334 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
335 6 : }
336 : END_TEST
337 : #endif
338 :
339 : #ifndef NDEBUG
340 6 : START_TEST(memdbg_callocfree) {
341 : uint64_t l_NbBlocks;
342 : size_t l_RAMSize;
343 : void* result;
344 :
345 : /* LibMemTrack consistency check preparation */
346 6 : l_NbBlocks=memtrack_getallocatedblocks();
347 6 : l_RAMSize=memtrack_getallocatedRAM();
348 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
349 :
350 : /* Allocate */
351 : oomfill_fill(_i,2);
352 6 : result=dbg_calloc(
353 : 100,100,
354 : __FILE__, __LINE__,
355 : __DATE__, __TIME__,__func__
356 : );
357 : oomfill_free();
358 6 : ck_assert((NULL!=result)||(oomfill_enabled()));
359 6 : if (NULL!=result) {
360 : /* Function returned the expected result */
361 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
362 6 : ck_assert(l_RAMSize+10000==memtrack_getallocatedRAM());
363 : } else {
364 : /* Function failed to return expected result while in OOM mode */
365 0 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
366 0 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
367 : }
368 :
369 : /* Deallocate */
370 : oomfill_fill(_i,2);
371 6 : dbg_free(result,
372 : __FILE__, __LINE__,
373 : __DATE__, __TIME__,__func__
374 : );
375 : oomfill_free();
376 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
377 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
378 6 : }
379 : END_TEST
380 : #endif
381 :
382 : /* WIP */
383 : #ifndef NDEBUG
384 6 : START_TEST(memdbg_realloc_null0) {
385 : uint64_t l_NbBlocks;
386 : size_t l_RAMSize;
387 : void* l_Ptr;
388 : void* result;
389 :
390 : /* LibMemTrack consistency check preparation */
391 6 : l_NbBlocks=memtrack_getallocatedblocks();
392 6 : l_RAMSize=memtrack_getallocatedRAM();
393 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
394 :
395 : /* Null test */
396 : /* Should behave as malloc in this case and allocate a valid initial block */
397 6 : l_Ptr=NULL;
398 : oomfill_fill(_i,2);
399 6 : result=dbg_realloc(
400 : l_Ptr,
401 : 10,
402 : __FILE__,__LINE__,
403 : __DATE__, __TIME__,__func__
404 : );
405 : oomfill_free();
406 6 : ck_assert((NULL!=result)||(oomfill_enabled()));
407 6 : if (NULL!=result) {
408 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
409 6 : ck_assert(l_RAMSize+10==memtrack_getallocatedRAM());
410 6 : ck_assert_msg(l_NbBlocks+1==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
411 : } else {
412 0 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
413 0 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
414 0 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
415 : /* Repair for next test */
416 0 : result=dbg_realloc(
417 : l_Ptr,
418 : 10,
419 : __FILE__,__LINE__,
420 : __DATE__, __TIME__,__func__
421 : );
422 : }
423 :
424 : /* Non portable behavior which behaves as free */
425 6 : l_Ptr=result;
426 : oomfill_fill(_i,2);
427 6 : result=dbg_realloc(
428 : l_Ptr,
429 : 0,
430 : __FILE__, __LINE__,
431 : __DATE__, __TIME__,__func__
432 : );
433 : oomfill_free();
434 6 : ck_assert(l_Ptr==result);
435 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
436 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
437 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
438 6 : }
439 : END_TEST
440 : #endif
441 :
442 : #ifndef NDEBUG
443 6 : START_TEST(memdbg_realloc_empty) {
444 : uint64_t l_NbBlocks;
445 : size_t l_RAMSize;
446 : void* l_Ptr;
447 : void* result;
448 :
449 : /* LibMemTrack consistency check preparation */
450 6 : l_NbBlocks=memtrack_getallocatedblocks();
451 6 : l_RAMSize=memtrack_getallocatedRAM();
452 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
453 :
454 : /* Create an initial valid block */
455 6 : l_Ptr=NULL;
456 : oomfill_fill(_i,2);
457 6 : result=dbg_realloc(
458 : l_Ptr,
459 : 10,
460 : __FILE__,__LINE__,
461 : __DATE__, __TIME__,__func__
462 : );
463 : oomfill_free();
464 6 : ck_assert((NULL!=result)||(oomfill_enabled()));
465 6 : if (NULL!=result) {
466 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
467 6 : ck_assert(l_RAMSize+10==memtrack_getallocatedRAM());
468 : } else {
469 0 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
470 0 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
471 : /* Repair for next test */
472 0 : result=dbg_realloc(
473 : l_Ptr,
474 : 10,
475 : __FILE__,__LINE__,
476 : __DATE__, __TIME__,__func__
477 : );
478 : }
479 :
480 : /* Line number 0 */
481 6 : l_Ptr=result;
482 : oomfill_fill(_i,2);
483 6 : result=dbg_realloc(
484 : l_Ptr,
485 : 1,
486 : __FILE__,0,
487 : __DATE__, __TIME__,__func__
488 : );
489 : oomfill_free();
490 6 : ck_assert(NULL==result);
491 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
492 6 : ck_assert(l_RAMSize+10==memtrack_getallocatedRAM());
493 :
494 : /* Empty filename */
495 : oomfill_fill(_i,2);
496 6 : result=dbg_realloc(
497 : l_Ptr,
498 : 1,
499 : "", __LINE__,
500 : __DATE__, __TIME__,__func__
501 : );
502 : oomfill_free();
503 6 : ck_assert(NULL==result);
504 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
505 6 : ck_assert(l_RAMSize+10==memtrack_getallocatedRAM());
506 :
507 : /* Empty Compilation date */
508 : oomfill_fill(_i,2);
509 6 : result=dbg_realloc(
510 : l_Ptr,
511 : 1,
512 : __FILE__, __LINE__,
513 : "", __TIME__,__func__
514 : );
515 : oomfill_free();
516 6 : ck_assert(NULL==result);
517 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
518 6 : ck_assert(l_RAMSize+10==memtrack_getallocatedRAM());
519 :
520 : /* Empty Compilation time */
521 : oomfill_fill(_i,2);
522 6 : result=dbg_realloc(
523 : l_Ptr,
524 : 1,
525 : __FILE__, __LINE__,
526 : __DATE__, "",__func__
527 : );
528 : oomfill_free();
529 6 : ck_assert(NULL==result);
530 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
531 6 : ck_assert(l_RAMSize+10==memtrack_getallocatedRAM());
532 :
533 : /* Empty function name */
534 : oomfill_fill(_i,2);
535 6 : result=dbg_realloc(
536 : l_Ptr,
537 : 1,
538 : __FILE__, __LINE__,
539 : __DATE__, __TIME__,""
540 : );
541 : oomfill_free();
542 6 : ck_assert(NULL==result);
543 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
544 6 : ck_assert(l_RAMSize+10==memtrack_getallocatedRAM());
545 :
546 6 : dbg_free(
547 : l_Ptr,
548 : __FILE__, __LINE__,
549 : __DATE__, __TIME__,__func__
550 : );
551 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
552 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
553 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
554 6 : }
555 : END_TEST
556 : #endif
557 :
558 : #ifndef NDEBUG
559 6 : START_TEST(memdbg_realloc_invalid) {
560 : uint64_t l_NbBlocks;
561 :
562 : /* LibMemTrack consistency check preparation */
563 6 : l_NbBlocks=memtrack_getallocatedblocks();
564 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
565 :
566 : /* This test is supposed to trigger a SIGABRT(6) and will crash the
567 : * whole testsuite if not caught or not in a child process */
568 6 : forktest_only;
569 :
570 : #ifdef ENABLE_GCOV
571 : if (oomfill_enabled())
572 : __gcov_dump();
573 : #endif
574 : oomfill_fill(_i,2);
575 : /* Try to realloc a non null, not tracked block */
576 : /* Abort/SIG6 expected */
577 4 : dbg_realloc(
578 : (void*)999,
579 : 10,
580 : __FILE__, __LINE__, __DATE__, __TIME__, __func__
581 : );
582 : /* Never reached, dead code */
583 : }
584 : END_TEST
585 : #endif
586 :
587 : #ifndef NDEBUG
588 6 : START_TEST(memdbg_reallocfree) {
589 : uint64_t l_NbBlocks;
590 : size_t l_RAMSize;
591 : void* l_Ptr;
592 : void* result;
593 :
594 : /* LibMemTrack consistency check preparation */
595 6 : l_NbBlocks=memtrack_getallocatedblocks();
596 6 : l_RAMSize=memtrack_getallocatedRAM();
597 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
598 :
599 : /* Create an initial valid block */
600 6 : l_Ptr=NULL;
601 6 : result=dbg_malloc(
602 : 10,
603 : __FILE__,__LINE__,
604 : __DATE__, __TIME__,__func__
605 : );
606 6 : ck_assert(NULL!=result);
607 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
608 6 : ck_assert(l_RAMSize+10==memtrack_getallocatedRAM());
609 :
610 : /* Standard realloc to increase the block size */
611 6 : l_Ptr=result;
612 : oomfill_fill(_i,2);
613 6 : result = dbg_realloc(
614 : l_Ptr,
615 : 10000,
616 : __FILE__, __LINE__, __DATE__, __TIME__, __func__
617 : );
618 : oomfill_free();
619 6 : ck_assert((NULL!=result)||(oomfill_enabled()));
620 6 : if (NULL!=result) {
621 : /* Function returned the expected result */
622 : } else {
623 : /* Function failed to return expected result while in OOM mode */
624 0 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
625 0 : ck_assert(l_RAMSize+10==memtrack_getallocatedRAM());
626 : /* Repair for next test */
627 0 : result = dbg_realloc(
628 : l_Ptr,
629 : 10000,
630 : __FILE__, __LINE__, __DATE__, __TIME__, __func__
631 : );
632 0 : ck_assert(NULL!=result);
633 : }
634 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
635 6 : ck_assert(l_RAMSize+10000==memtrack_getallocatedRAM());
636 :
637 6 : l_Ptr=result;
638 : /* Standard realloc to reduce the block size */
639 : oomfill_fill(_i,2);
640 6 : result = dbg_realloc(
641 : l_Ptr,
642 : 1000,
643 : __FILE__, __LINE__, __DATE__, __TIME__, __func__
644 : );
645 : oomfill_free();
646 6 : ck_assert((NULL!=result)||(oomfill_enabled()));
647 6 : if (NULL!=result) {
648 : /* Function returned the expected result */
649 : } else {
650 : /* Function failed to return expected result while in OOM mode */
651 0 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
652 0 : ck_assert(l_RAMSize+10000==memtrack_getallocatedRAM());
653 : /* Repair for next test */
654 0 : result = dbg_realloc(
655 : l_Ptr,
656 : 1000,
657 : __FILE__, __LINE__, __DATE__, __TIME__, __func__
658 : );
659 : }
660 6 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
661 6 : ck_assert(l_RAMSize+1000==memtrack_getallocatedRAM());
662 :
663 : /* OOM expected, no realloc */
664 6 : l_Ptr=result;
665 : if (oomfill_enabled()) {
666 : oomfill_fill(_i,2);
667 : result= dbg_realloc(
668 : l_Ptr,
669 : (RAMLIMIT_SOFT+1),
670 : __FILE__, __LINE__, __DATE__, __TIME__, __func__
671 : );
672 : oomfill_free();
673 :
674 : ck_assert(NULL==result);
675 : ck_assert(l_NbBlocks+1==memtrack_getallocatedblocks());
676 : ck_assert(l_RAMSize+1000==memtrack_getallocatedRAM());
677 : }
678 : /* Optional cleanup when forked, but cleaner and dbg_free already tested */
679 6 : dbg_free(
680 : l_Ptr,
681 : __FILE__, __LINE__,
682 : __DATE__, __TIME__,__func__
683 : );
684 6 : ck_assert(l_NbBlocks==memtrack_getallocatedblocks());
685 6 : ck_assert(l_RAMSize==memtrack_getallocatedRAM());
686 6 : ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
687 6 : }
688 : END_TEST
689 : #endif
690 :
691 : #ifndef NDEBUG
692 6 : START_TEST(memdbg_strdup_invalid) {
693 : /* This test is supposed to trigger a SIGSEV(11) and will crash the
694 : * whole testsuite if not caught or not in a child process */
695 6 : forktest_only;
696 :
697 : oomfill_fill(_i,2);
698 : /* SIGSEV expected */
699 4 : dbg_strdup(
700 : NULL,
701 : __FILE__, __LINE__,
702 : __DATE__, __TIME__,__func__
703 : );
704 : /* Never reached, dead code */
705 : }
706 : END_TEST
707 : #endif
708 :
709 : #ifndef NDEBUG
710 6 : START_TEST(memdbg_strdup_nullempty) {
711 : char* result;
712 :
713 6 : result = NULL;
714 : oomfill_fill(_i,2);
715 6 : result=dbg_strdup(
716 : "",
717 : __FILE__, __LINE__,
718 : __DATE__, __TIME__,__func__
719 : );
720 : oomfill_free();
721 6 : ck_assert((NULL!=result)||(oomfill_enabled()));
722 6 : dbg_free(result,
723 : __FILE__, __LINE__,
724 : __DATE__, __TIME__,__func__
725 : );
726 :
727 6 : result = NULL;
728 : oomfill_fill(_i,2);
729 6 : result=dbg_strdup(
730 : "abc",
731 : NULL, __LINE__,
732 : __DATE__, __TIME__,__func__
733 : );
734 : oomfill_free();
735 6 : ck_assert((NULL==result)||(oomfill_enabled()));
736 :
737 6 : result = NULL;
738 : oomfill_fill(_i,2);
739 6 : result=dbg_strdup(
740 : "abc",
741 : __FILE__, 0,
742 : __DATE__, __TIME__,__func__
743 : );
744 : oomfill_free();
745 6 : ck_assert((NULL==result)||(oomfill_enabled()));
746 :
747 6 : result = NULL;
748 : oomfill_fill(_i,2);
749 6 : result=dbg_strdup(
750 : "abc",
751 : __FILE__, __LINE__,
752 : NULL, __TIME__,__func__
753 : );
754 : oomfill_free();
755 6 : ck_assert((NULL==result)||(oomfill_enabled()));
756 :
757 6 : result = NULL;
758 : oomfill_fill(_i,2);
759 6 : result=dbg_strdup(
760 : "abc",
761 : __FILE__, __LINE__,
762 : __DATE__, NULL,__func__
763 : );
764 : oomfill_free();
765 6 : ck_assert((NULL==result)||(oomfill_enabled()));
766 :
767 6 : result = NULL;
768 : oomfill_fill(_i,2);
769 6 : result=dbg_strdup(
770 : "abc",
771 : __FILE__, __LINE__,
772 : __DATE__, __TIME__,NULL
773 : );
774 : oomfill_free();
775 6 : ck_assert((NULL==result)||(oomfill_enabled()));
776 :
777 6 : result = NULL;
778 : oomfill_fill(_i,2);
779 6 : result=dbg_strdup(
780 : "abc",
781 : "", __LINE__,
782 : __DATE__, __TIME__,__func__
783 : );
784 : oomfill_free();
785 6 : ck_assert((NULL==result)||(oomfill_enabled()));
786 :
787 6 : result = NULL;
788 : oomfill_fill(_i,2);
789 6 : result=dbg_strdup(
790 : "abc",
791 : __FILE__, __LINE__,
792 : "", __TIME__,__func__
793 : );
794 : oomfill_free();
795 6 : ck_assert((NULL==result)||(oomfill_enabled()));
796 :
797 6 : result = NULL;
798 : oomfill_fill(_i,2);
799 6 : result=dbg_strdup(
800 : "abc",
801 : __FILE__, __LINE__,
802 : __DATE__, "",__func__
803 : );
804 : oomfill_free();
805 6 : ck_assert((NULL==result)||(oomfill_enabled()));
806 :
807 6 : result = NULL;
808 : oomfill_fill(_i,2);
809 6 : result=dbg_strdup(
810 : "abc",
811 : __FILE__, __LINE__,
812 : __DATE__, __TIME__,""
813 : );
814 : oomfill_free();
815 6 : ck_assert((NULL==result)||(oomfill_enabled()));
816 6 : }
817 : END_TEST
818 : #endif
819 :
820 : #ifndef NDEBUG
821 6 : START_TEST(memdbg_strdup_value) {
822 : char* result;
823 6 : char *szLongString =
824 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
825 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
826 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
827 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
828 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
829 : "%d"
830 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
831 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
832 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
833 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
834 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
835 : ;
836 : oomfill_fill(_i,2);
837 6 : result=dbg_strdup(
838 : szLongString,
839 : __FILE__, __LINE__,
840 : __DATE__, __TIME__,__func__
841 : );
842 : oomfill_free();
843 6 : ck_assert((NULL!=result)||(oomfill_enabled()));
844 6 : if (NULL!=result) {
845 6 : ck_assert(0==strcmp(szLongString,result));
846 6 : dbg_free(result,
847 : __FILE__, __LINE__,
848 : __DATE__, __TIME__,__func__
849 : );
850 : }
851 6 : }
852 : END_TEST
853 : #endif
854 :
855 : #ifndef NDEBUG
856 6 : START_TEST(memdbg_asprintf_invalid) {
857 6 : forktest_only;
858 : #ifdef ENABLE_GCOV
859 : if (oomfill_enabled())
860 : __gcov_dump();
861 : #endif
862 : oomfill_fill(_i,2);
863 : /* SIGABRT6 expected */
864 4 : dbg_asprintf(NULL,
865 : "abc%ddef",
866 : __FILE__, __LINE__,
867 : __DATE__, __TIME__,__func__,
868 : 123
869 : );
870 : }
871 : END_TEST
872 : #endif
873 :
874 : #ifndef NDEBUG
875 6 : START_TEST(memdbg_asprintf_nullempty) {
876 : int result;
877 : char* l_Ptr;
878 :
879 : oomfill_fill(_i,2);
880 6 : result=dbg_asprintf(&l_Ptr,
881 : NULL,
882 : __FILE__, __LINE__,
883 : __DATE__, __TIME__,__func__
884 : );
885 : oomfill_free();
886 6 : ck_assert((-1==result)||((oomfill_enabled())&&(-2==result)));
887 :
888 : oomfill_fill(_i,2);
889 6 : result=dbg_asprintf(&l_Ptr,
890 : "abcdef",
891 : NULL, __LINE__,
892 : __DATE__, __TIME__,__func__
893 : );
894 : oomfill_free();
895 6 : ck_assert((-2==result)||((oomfill_enabled())&&(-1==result)));
896 :
897 : oomfill_fill(_i,2);
898 6 : result=dbg_asprintf(&l_Ptr,
899 : "abcdef",
900 : __FILE__, 0,
901 : __DATE__, __TIME__,__func__
902 : );
903 : oomfill_free();
904 6 : ck_assert((-2==result)||((oomfill_enabled())&&(-1==result)));
905 :
906 : oomfill_fill(_i,2);
907 6 : result=dbg_asprintf(&l_Ptr,
908 : "abcdef",
909 : __FILE__, __LINE__,
910 : NULL, __TIME__,__func__
911 : );
912 : oomfill_free();
913 6 : ck_assert((-2==result)||((oomfill_enabled())&&(-1==result)));
914 :
915 : oomfill_fill(_i,2);
916 6 : result=dbg_asprintf(&l_Ptr,
917 : "abcdef",
918 : __FILE__, __LINE__,
919 : __DATE__, NULL,__func__
920 : );
921 : oomfill_free();
922 6 : ck_assert((-2==result)||((oomfill_enabled())&&(-1==result)));
923 :
924 : oomfill_fill(_i,2);
925 6 : result=dbg_asprintf(&l_Ptr,
926 : "abcdef",
927 : __FILE__, __LINE__,
928 : __DATE__, __TIME__,NULL
929 : );
930 : oomfill_free();
931 6 : ck_assert((-2==result)||((oomfill_enabled())&&(-1==result)));
932 :
933 : oomfill_fill(_i,2);
934 6 : result=dbg_asprintf(&l_Ptr,
935 : "",
936 : __FILE__, __LINE__,
937 : __DATE__, __TIME__,__func__
938 : );
939 : oomfill_free();
940 6 : ck_assert((0==result)||(oomfill_enabled()));
941 6 : if (0==result) {
942 6 : ck_assert(NULL!=l_Ptr);
943 6 : dbg_free(l_Ptr,
944 : __FILE__, __LINE__,
945 : __DATE__, __TIME__,__func__
946 : );
947 : }
948 :
949 : oomfill_fill(_i,2);
950 6 : result=dbg_asprintf(&l_Ptr,
951 : "abcdef",
952 : "", __LINE__,
953 : __DATE__, __TIME__,__func__
954 : );
955 : oomfill_free();
956 6 : ck_assert((-2==result)||((oomfill_enabled())&&(-1==result)));
957 :
958 : oomfill_fill(_i,2);
959 6 : result=dbg_asprintf(&l_Ptr,
960 : "abcdef",
961 : __FILE__, 0,
962 : __DATE__, __TIME__,__func__
963 : );
964 : oomfill_free();
965 6 : ck_assert((-2==result)||((oomfill_enabled())&&(-1==result)));
966 :
967 : oomfill_fill(_i,2);
968 6 : result=dbg_asprintf(&l_Ptr,
969 : "abcdef",
970 : __FILE__, __LINE__,
971 : "", __TIME__,__func__
972 : );
973 : oomfill_free();
974 6 : ck_assert((-2==result)||((oomfill_enabled())&&(-1==result)));
975 :
976 : oomfill_fill(_i,2);
977 6 : result=dbg_asprintf(&l_Ptr,
978 : "abcdef",
979 : __FILE__, __LINE__,
980 : __DATE__, "",__func__
981 : );
982 : oomfill_free();
983 6 : ck_assert((-2==result)||((oomfill_enabled())&&(-1==result)));
984 :
985 : oomfill_fill(_i,2);
986 6 : result=dbg_asprintf(&l_Ptr,
987 : "abcdef",
988 : __FILE__, __LINE__,
989 : __DATE__, __TIME__,""
990 : );
991 : oomfill_free();
992 6 : ck_assert((-2==result)||((oomfill_enabled())&&(-1==result)));
993 6 : }
994 : END_TEST
995 : #endif
996 :
997 : #ifndef NDEBUG
998 6 : START_TEST(memdbg_asprintf_value) {
999 : /* Only test with parameter, not without or with parameter type error */
1000 : int result;
1001 : char* l_Ptr;
1002 6 : char *szLongString =
1003 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1004 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1005 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1006 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1007 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1008 : "%d"
1009 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1010 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1011 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1012 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1013 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1014 : ;
1015 : oomfill_fill(_i,2);
1016 6 : result=dbg_asprintf(&l_Ptr,
1017 : szLongString,
1018 : __FILE__, __LINE__,
1019 : __DATE__, __TIME__,__func__,
1020 : 123
1021 : );
1022 : oomfill_free();
1023 6 : ck_assert((-1!=result)||(oomfill_enabled()));
1024 6 : if (-1!=result) {
1025 6 : char *szExpected =
1026 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1027 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1028 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1029 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1030 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1031 : "123"
1032 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1033 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1034 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1035 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1036 : "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1037 : ;
1038 : /* Test succeeded */
1039 6 : ck_assert((size_t)result==strlen(szExpected));
1040 6 : ck_assert((NULL!=l_Ptr)&&(0==strcmp(szExpected,l_Ptr)));
1041 6 : dbg_free(l_Ptr,
1042 : __FILE__, __LINE__,
1043 : __DATE__, __TIME__,__func__
1044 : );
1045 : }
1046 6 : }
1047 : END_TEST
1048 : #endif
1049 :
1050 : /************************************************************************/
1051 54 : void memdbg_checked_uninitialized_setup() {
1052 54 : signals_catch();
1053 54 : forktest_gprofdir();
1054 54 : }
1055 54 : void memdbg_checked_withdata_setup() {
1056 54 : signals_catch();
1057 54 : forktest_gprofdir();
1058 54 : }
1059 92 : void memdbg_checked_common_teardown() {
1060 92 : signals_release();
1061 : #ifndef NDEBUG
1062 92 : ck_assert(0==memtrack_getallocatedblocks());
1063 : #endif /* NDEBUG */
1064 92 : }
1065 : /************************************************************************/
1066 550 : void memdbg_unchecked_common_setup() {
1067 550 : forktest_init();
1068 550 : }
1069 478 : void memdbg_unchecked_common_teardown() {
1070 478 : }
1071 : #ifdef HAVE_LIBOOM
1072 : void memdbg_unchecked_oom_setup() {
1073 : oomfill_enable(RAMLIMIT_SOFT);
1074 : memdbg_unchecked_common_setup();
1075 : }
1076 : void memdbg_unchecked_oom_teardown() {
1077 : oomfill_disable();
1078 : memdbg_unchecked_common_teardown();
1079 : }
1080 : #endif /* HAVE_LIBOOM */
1081 :
1082 : /************************************************************************/
1083 365 : Suite* libdebug_memdbg_suite() {
1084 : Suite *s;
1085 : TCase *tc;
1086 :
1087 365 : s = suite_create("LibDebug-MemDbg");
1088 365 : tc = tcase_create("Uninitialized");
1089 365 : tcase_add_checked_fixture(tc, memdbg_checked_uninitialized_setup, memdbg_checked_common_teardown);
1090 365 : tcase_add_unchecked_fixture(tc, memdbg_unchecked_common_setup, memdbg_unchecked_common_teardown);
1091 365 : suite_add_tcase(s, tc);
1092 : #ifndef NDEBUG
1093 365 : tcase_add_test(tc, memdbg_malloc_0);
1094 365 : tcase_add_test(tc, memdbg_malloc_null);
1095 365 : tcase_add_test(tc, memdbg_free_null);
1096 365 : tcase_add_test_raise_signal(tc, memdbg_free_invalid, 6);
1097 365 : tcase_add_test(tc, memdbg_mallocfree);
1098 365 : tcase_add_test(tc, memdbg_calloc_0);
1099 365 : tcase_add_test(tc, memdbg_calloc_null);
1100 365 : tcase_add_test(tc, memdbg_callocfree);
1101 365 : tcase_add_test(tc, memdbg_realloc_null0);
1102 365 : tcase_add_test(tc, memdbg_realloc_empty);
1103 365 : tcase_add_test_raise_signal(tc, memdbg_realloc_invalid, 6);
1104 365 : tcase_add_test(tc, memdbg_reallocfree);
1105 365 : tcase_add_test_raise_signal(tc, memdbg_strdup_invalid, 11);
1106 365 : tcase_add_test(tc, memdbg_strdup_nullempty);
1107 365 : tcase_add_test(tc, memdbg_strdup_value);
1108 365 : tcase_add_test_raise_signal(tc, memdbg_asprintf_invalid, 6);
1109 365 : tcase_add_test(tc, memdbg_asprintf_nullempty);
1110 365 : tcase_add_test(tc, memdbg_asprintf_value);
1111 : #endif
1112 :
1113 365 : tc = tcase_create("WithData");
1114 365 : tcase_add_checked_fixture(tc, memdbg_checked_withdata_setup, memdbg_checked_common_teardown);
1115 365 : tcase_add_unchecked_fixture(tc, memdbg_unchecked_common_setup, memdbg_unchecked_common_teardown);
1116 365 : suite_add_tcase(s, tc);
1117 : #ifndef NDEBUG
1118 365 : tcase_add_test(tc, memdbg_malloc_0);
1119 365 : tcase_add_test(tc, memdbg_malloc_null);
1120 365 : tcase_add_test(tc, memdbg_free_null);
1121 365 : tcase_add_test_raise_signal(tc, memdbg_free_invalid, 6);
1122 365 : tcase_add_test(tc, memdbg_mallocfree);
1123 365 : tcase_add_test(tc, memdbg_calloc_0);
1124 365 : tcase_add_test(tc, memdbg_calloc_null);
1125 365 : tcase_add_test(tc, memdbg_callocfree);
1126 365 : tcase_add_test(tc, memdbg_realloc_null0);
1127 365 : tcase_add_test(tc, memdbg_realloc_empty);
1128 365 : tcase_add_test_raise_signal(tc, memdbg_realloc_invalid, 6);
1129 365 : tcase_add_test(tc, memdbg_reallocfree);
1130 365 : tcase_add_test_raise_signal(tc, memdbg_strdup_invalid, 11);
1131 365 : tcase_add_test(tc, memdbg_strdup_nullempty);
1132 365 : tcase_add_test(tc, memdbg_strdup_value);
1133 365 : tcase_add_test_raise_signal(tc, memdbg_asprintf_invalid, 6);
1134 365 : tcase_add_test(tc, memdbg_asprintf_nullempty);
1135 365 : tcase_add_test(tc, memdbg_asprintf_value);
1136 : #endif
1137 :
1138 : #ifdef HAVE_LIBOOM
1139 : tc = tcase_create("Uninitialized-OOM");
1140 : tcase_set_tags(tc,"oom");
1141 : tcase_add_checked_fixture(tc, memdbg_checked_uninitialized_setup, memdbg_checked_common_teardown);
1142 : tcase_add_unchecked_fixture(tc, memdbg_unchecked_oom_setup, memdbg_unchecked_oom_teardown);
1143 : suite_add_tcase(s, tc);
1144 : #ifndef NDEBUG
1145 : tcase_add_loop_test(tc, memdbg_malloc_0, 0, 10);
1146 : tcase_add_loop_test(tc, memdbg_malloc_null, 0, 10);
1147 : tcase_add_loop_test(tc, memdbg_free_null, 0, 10);
1148 : tcase_add_loop_test_raise_signal(tc, memdbg_free_invalid, 6, 0, 10);
1149 : tcase_add_loop_test(tc, memdbg_mallocfree, 0, 10);
1150 : tcase_add_loop_test(tc, memdbg_calloc_0, 0, 10);
1151 : tcase_add_loop_test(tc, memdbg_calloc_null, 0, 10);
1152 : tcase_add_loop_test(tc, memdbg_callocfree, 0, 10);
1153 : tcase_add_loop_test(tc, memdbg_realloc_null0, 0, 10);
1154 : tcase_add_loop_test(tc, memdbg_realloc_empty, 0, 10);
1155 : tcase_add_loop_test_raise_signal(tc, memdbg_realloc_invalid, 6, 0, 10);
1156 : tcase_add_loop_test(tc, memdbg_reallocfree, 0, 10);
1157 : tcase_add_loop_test_raise_signal(tc, memdbg_strdup_invalid, 11, 0, 10);
1158 : tcase_add_loop_test(tc, memdbg_strdup_nullempty, 0, 10);
1159 : tcase_add_loop_test(tc, memdbg_strdup_value, 0, 10);
1160 : tcase_add_loop_test_raise_signal(tc, memdbg_asprintf_invalid, 6, 0, 10);
1161 : tcase_add_loop_test(tc, memdbg_asprintf_nullempty, 0, 10);
1162 : tcase_add_loop_test(tc, memdbg_asprintf_value, 0, 10);
1163 : #endif
1164 :
1165 : tc = tcase_create("WithData-OOM");
1166 : tcase_set_tags(tc,"oom");
1167 : tcase_add_checked_fixture(tc, memdbg_checked_withdata_setup, memdbg_checked_common_teardown);
1168 : tcase_add_unchecked_fixture(tc, memdbg_unchecked_oom_setup, memdbg_unchecked_oom_teardown);
1169 : suite_add_tcase(s, tc);
1170 : #ifndef NDEBUG
1171 : tcase_add_loop_test(tc, memdbg_malloc_0, 0, 10);
1172 : tcase_add_loop_test(tc, memdbg_malloc_null, 0, 10);
1173 : tcase_add_loop_test(tc, memdbg_free_null, 0, 10);
1174 : tcase_add_loop_test_raise_signal(tc, memdbg_free_invalid, 6, 0, 10);
1175 : tcase_add_loop_test(tc, memdbg_mallocfree, 0, 10);
1176 : tcase_add_loop_test(tc, memdbg_calloc_0, 0, 10);
1177 : tcase_add_loop_test(tc, memdbg_calloc_null, 0, 10);
1178 : tcase_add_loop_test(tc, memdbg_callocfree, 0, 10);
1179 : tcase_add_loop_test(tc, memdbg_realloc_null0, 0, 10);
1180 : tcase_add_loop_test(tc, memdbg_realloc_empty, 0, 10);
1181 : tcase_add_loop_test_raise_signal(tc, memdbg_realloc_invalid, 6, 0, 10);
1182 : tcase_add_loop_test(tc, memdbg_reallocfree, 0, 10);
1183 : tcase_add_loop_test_raise_signal(tc, memdbg_strdup_invalid, 11, 0, 10);
1184 : tcase_add_loop_test(tc, memdbg_strdup_nullempty, 0, 10);
1185 : tcase_add_loop_test(tc, memdbg_strdup_value, 0, 10);
1186 : tcase_add_loop_test_raise_signal(tc, memdbg_asprintf_invalid, 6, 0, 10);
1187 : tcase_add_loop_test(tc, memdbg_asprintf_nullempty, 0, 10);
1188 : tcase_add_loop_test(tc, memdbg_asprintf_value, 0, 10);
1189 : #endif
1190 : #endif /* HAVE_LIBOOM */
1191 :
1192 365 : return s;
1193 : }
1194 :
1195 : /* vim: set tw=80: */
|