LCOV - code coverage report
Current view: top level - test - suite_libdebug-memtrack.c (source / functions) Hit Total Coverage
Test: mkernel.info Lines: 34 45 75.6 %
Date: 2024-11-28 07:26:08 Functions: 5 8 62.5 %

          Line data    Source code
       1             : /**   \file  suite_libdebug-memtrack.c
       2             :  *   \brief  Check Libdebug memtrack functions
       3             :  *  \author  François Cerbelle (Fanfan), francois@cerbelle.net
       4             :  *
       5             :  *  \internal
       6             :  *       Created:  24/06/2024
       7             :  *      Revision:  none
       8             :  * Last modified:  2024-07-28 16:36
       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             : #include "debug/memtrack.h"
      22             : #include "debug/oom.h"                                /* OOM simulation */
      23             : #include <check.h>
      24             : #include <unistd.h>                             /* pid_t getpid() */
      25             : #include <sys/stat.h>                           /* mkdir(), chdir(), mode_t */
      26             : #include <stdio.h>                              /* fprintf */
      27             : #include <stdlib.h>                             /* abort() */
      28             : #include "checktools.inc"
      29             : 
      30             : #ifndef NDEBUG
      31             : extern void memtrack_reset();
      32             : #endif
      33             : 
      34             : #ifndef NDEBUG
      35             : START_TEST(getallocatedRAM_first)
      36             : {
      37             :     unsigned int l_result;
      38             : 
      39             :     oomtest_fill(_i*sizeof(TMemBlock),2);
      40             :     l_result=memtrack_getallocatedRAM();
      41             :     oomtest_free();
      42             :     /* Always 0, except when initialized WithData */
      43             :     /* Uninitialized returns 0, Initialized returns 0, OOM uninitialized returns 0 */
      44             :     ck_assert(0==l_result);
      45             : }
      46             : END_TEST
      47             : #endif /* NDEBUG */
      48             : 
      49             : #ifndef NDEBUG
      50             : START_TEST(getallocatedblocks_first)
      51             : {
      52             :     unsigned int l_result;
      53             :     oomtest_fill(_i*sizeof(TMemBlock),2);
      54             :     l_result = memtrack_getallocatedblocks();
      55             :     oomtest_free();
      56             :     /* Always 0, except when initialized WithData */
      57             :     /* Uninitialized returns 0, Initialized returns 0, OOM uninitialized returns 0 */
      58             :     ck_assert(l_result==0);
      59             : }
      60             : END_TEST
      61             : #endif /* NDEBUG */
      62             : 
      63             : #ifndef NDEBUG
      64             : START_TEST(getblocksize_first)
      65             : {
      66             :     size_t l_result;
      67             : 
      68             :     oomtest_fill(_i*sizeof(TMemBlock),2);
      69             :     l_result = memtrack_getblocksize(NULL);
      70             :     oomtest_free();
      71             :     /* Always 0, because asking for "NULL" size */
      72             :     ck_assert(0==l_result);
      73             : }
      74             : END_TEST
      75             : #endif /* NDEBUG */
      76             : 
      77             : #ifndef NDEBUG
      78             : START_TEST(getblocksize_null)
      79             : {
      80             :     uint64_t l_NbBlocks;
      81             :     size_t l_BlockSize;
      82             :     size_t l_RAMSize;
      83             : 
      84             :     /* LibMemTrack consistency check preparation */
      85             :     l_NbBlocks=memtrack_getallocatedblocks();
      86             :     l_RAMSize=memtrack_getallocatedRAM();
      87             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
      88             : 
      89             :     /* Run tests under constraint */
      90             :     /* Already initialized in previous lines, thus no need for allocation */
      91             :     oomtest_fill(_i,2);
      92             :     l_BlockSize=memtrack_getblocksize(NULL);
      93             :     oomtest_free();
      94             : 
      95             :     /* Check expected results */
      96             :     ck_assert_msg(0==l_BlockSize,"Blocksize of NULL pointer should be 0");
      97             : 
      98             :     /* Check no new block registered */
      99             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     100             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     101             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     102             : }
     103             : END_TEST
     104             : #endif /* NDEBUG */
     105             : 
     106             : #ifndef NDEBUG
     107             : START_TEST(getblocksize_missing)
     108             : {
     109             :     uint64_t l_NbBlocks;
     110             :     size_t l_BlockSize;
     111             :     size_t l_RAMSize;
     112             : 
     113             :     /* LibMemTrack consistency check preparation */
     114             :     l_NbBlocks=memtrack_getallocatedblocks();
     115             :     l_RAMSize=memtrack_getallocatedRAM();
     116             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     117             : 
     118             :     /* Already initialized in previous lines, thus no need for allocation */
     119             :     oomtest_fill(_i,2);
     120             :     l_BlockSize=memtrack_getblocksize((void*)999);
     121             :     oomtest_free();
     122             : 
     123             :     /* Check results */
     124             :     ck_assert_msg(0==l_BlockSize,"Blocksize of missing pointer should be 0");
     125             : 
     126             :     /* Check no new block registered */
     127             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     128             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     129             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     130             : }
     131             : END_TEST
     132             : #endif /* NDEBUG */
     133             : 
     134             : #ifndef NDEBUG
     135             : START_TEST(addblock_null_first)
     136             : {
     137             :     unsigned int l_result;
     138             : 
     139             :     /* First test to trigger autoinit */
     140             :     /* Try to create/update a new blocks with null values */
     141             :     /* Initialize memtrack and fail */
     142             :     oomtest_fill(_i*sizeof(TMemBlock),2);
     143             :     l_result = memtrack_addblock(
     144             :                    NULL,       /* Pointer */
     145             :                    10,         /* Size */
     146             :                    __FILE__,   /* Source code filename */
     147             :                    __LINE__,   /* Source code line number */
     148             :                    __DATE__,   /* Compilation date */
     149             :                    __TIME__,   /* Compilation time */
     150             :                    __func__    /* Source code function, GNU extension */
     151             :                );
     152             :     oomtest_free();
     153             : 
     154             :     /* Check results */
     155             :     ck_assert_msg(1==l_result,"Should not be able to register a NULL pointer");
     156             :     ck_assert_msg(0==memtrack_getblocksize(NULL),"Blocksize of NULL pointer should be 0");
     157             :     /* Can not check the block counters value, it depends on WithData */
     158             :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     159             : }
     160             : END_TEST
     161             : #endif
     162             : 
     163             : #ifndef NDEBUG
     164             : START_TEST(delblock_null_first)
     165             : {
     166             :     unsigned int l_result;
     167             : 
     168             :     /* Initialize memtrack and fail */
     169             :     oomtest_fill(_i*sizeof(TMemBlock),2);
     170             :     l_result = memtrack_delblock(
     171             :                    NULL,       /* Pointer */
     172             :                    __FILE__,   /* Source code filename */
     173             :                    __LINE__,   /* Source code line number */
     174             :                    __DATE__,   /* Compilation date */
     175             :                    __TIME__,   /* Compilation time */
     176             :                    __func__    /* Source code function, GNU extension */
     177             :                );
     178             :     oomtest_free();
     179             : 
     180             :     /* Check results */
     181             :     ck_assert_msg(1==l_result,"Should not be able to unregister a NULL pointer");
     182             :     ck_assert_msg(0==memtrack_getblocksize(NULL),"Blocksize of NULL pointer should be 0");
     183             :     /* Can not check the block counters value, it depends on WithData */
     184             :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     185             : }
     186             : END_TEST
     187             : #endif
     188             : 
     189             : #ifndef NDEBUG
     190             : START_TEST(addblock_null)
     191             : {
     192             :     uint64_t l_NbBlocks;
     193             :     size_t l_RAMSize;
     194             :     unsigned int result;
     195             : 
     196             :     /* LibMemTrack consistency check preparation */
     197             :     l_NbBlocks=memtrack_getallocatedblocks();
     198             :     l_RAMSize=memtrack_getallocatedRAM();
     199             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     200             : 
     201             :     /* Already initialized in previous lines, thus no need for allocation */
     202             :     /* Try to create/update a new blocks with null values, fails, no need for RAM */
     203             :     oomtest_fill(_i,2);
     204             :     result=memtrack_addblock(
     205             :                NULL,       /* Pointer */
     206             :                10,         /* Size */
     207             :                __FILE__,   /* Source code filename */
     208             :                __LINE__,   /* Source code line number */
     209             :                __DATE__,   /* Compilation date */
     210             :                __TIME__,   /* Compilation time */
     211             :                __func__    /* Source code function, GNU extension */
     212             :            );
     213             :     oomtest_free();
     214             : 
     215             :     /* Check results */
     216             :     ck_assert_msg(1==result,"Should not be able to register a NULL pointer");
     217             :     ck_assert_msg(0==memtrack_getblocksize(NULL),"Blocksize of NULL pointer should be 0");
     218             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     219             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     220             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     221             : }
     222             : END_TEST
     223             : #endif
     224             : 
     225             : #ifndef NDEBUG
     226             : START_TEST(addblock_duplicate)
     227             : {
     228             :     uint64_t l_NbBlocks;
     229             :     size_t l_RAMSize;
     230             :     unsigned int result;
     231             : 
     232             :     /* LibMemTrack consistency check preparation */
     233             :     l_NbBlocks=memtrack_getallocatedblocks();
     234             :     l_RAMSize=memtrack_getallocatedRAM();
     235             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     236             : 
     237             :     /* Already initialized in previous lines, thus no need for allocation */
     238             :     /* Try to create/update one new block  */
     239             :     oomtest_fill(_i*sizeof(TMemBlock),2);
     240             :     result=memtrack_addblock(
     241             :                (void*)999, /* Pointer */
     242             :                10,         /* Size */
     243             :                __FILE__,   /* Source code filename */
     244             :                __LINE__,   /* Source code line number */
     245             :                __DATE__,   /* Compilation date */
     246             :                __TIME__,   /* Compilation time */
     247             :                __func__    /* Source code function, GNU extension */
     248             :            );
     249             :     oomtest_free();
     250             :     ck_assert((0==result)||(oomtest_enabled()));
     251             :     if (0!=result) {
     252             :         /* OOM occured, fix that */
     253             :         result=memtrack_addblock(
     254             :                    (void*)999, /* Pointer */
     255             :                    10,         /* Size */
     256             :                    __FILE__,   /* Source code filename */
     257             :                    __LINE__,   /* Source code line number */
     258             :                    __DATE__,   /* Compilation date */
     259             :                    __TIME__,   /* Compilation time */
     260             :                    __func__    /* Source code function, GNU extension */
     261             :                );
     262             :     }
     263             :     l_NbBlocks+=1;
     264             :     l_RAMSize+=10;
     265             : 
     266             :     /* Check results */
     267             :     ck_assert_msg(0==result,"Should able to register a pointer");
     268             :     ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of pointer should be 10");
     269             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     270             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     271             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     272             : 
     273             :     /* Add a duplicate, should fail */
     274             :     oomtest_fill(_i*sizeof(TMemBlock),2);
     275             :     result=memtrack_addblock(
     276             :                (void*)999, /* Pointer */
     277             :                20,         /* Size */
     278             :                __FILE__,   /* Source code filename */
     279             :                __LINE__,   /* Source code line number */
     280             :                __DATE__,   /* Compilation date */
     281             :                __TIME__,   /* Compilation time */
     282             :                __func__    /* Source code function, GNU extension */
     283             :            );
     284             :     oomtest_free();
     285             : 
     286             :     /* Check results */
     287             :     ck_assert_msg(1==result,"Should not be able to register a duplicate pointer");
     288             :     ck_assert_msg(10==memtrack_getblocksize((void*)999),"Duplicate pointer updated the size");
     289             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     290             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     291             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     292             : 
     293             :     /* Cleanup */
     294             :     result = memtrack_delblock(
     295             :                  (void*)999, /* Pointer */
     296             :                  __FILE__,   /* Source code filename */
     297             :                  __LINE__,   /* Source code line number */
     298             :                  __DATE__,   /* Compilation date */
     299             :                  __TIME__,   /* Compilation time */
     300             :                  __func__    /* Source code function, GNU extension */
     301             :              );
     302             :     ck_assert(0==result);
     303             : }
     304             : END_TEST
     305             : #endif
     306             : 
     307             : #ifndef NDEBUG
     308             : START_TEST(addblock_empty)
     309             : {
     310             :     uint64_t l_NbBlocks;
     311             :     size_t l_RAMSize;
     312             :     unsigned int result;
     313             : 
     314             :     /* LibMemTrack consistency check preparation */
     315             :     l_NbBlocks=memtrack_getallocatedblocks();
     316             :     l_RAMSize=memtrack_getallocatedRAM();
     317             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     318             : 
     319             :     /* Try to create/add a new  block with empty values */
     320             :     /* Already initialized and empty val will fail, thus no need for RAM */
     321             :     oomtest_fill(_i,2);
     322             :     result=memtrack_addblock(
     323             :                (void*)999, /* Pointer */
     324             :                0,          /* Size */
     325             :                __FILE__,   /* Source code filename */
     326             :                __LINE__,   /* Source code line number */
     327             :                __DATE__,   /* Compilation date */
     328             :                __TIME__,   /* Compilation time */
     329             :                __func__    /* Source code function, GNU extension */
     330             :            );
     331             :     oomtest_free();
     332             : 
     333             :     /* Check results */
     334             :     ck_assert_msg(1==result,"Should not be able to register a 0 sized pointer");
     335             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     336             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     337             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     338             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     339             : 
     340             :     /* Try to create/add a new  block with empty values */
     341             :     oomtest_fill(_i,2);
     342             :     result=memtrack_addblock(
     343             :                (void*)999, /* Pointer */
     344             :                1,          /* Size */
     345             :                "",         /* Source code filename */
     346             :                __LINE__,   /* Source code line number */
     347             :                __DATE__,   /* Compilation date */
     348             :                __TIME__,   /* Compilation time */
     349             :                __func__    /* Source code function, GNU extension */
     350             :            );
     351             :     oomtest_free();
     352             : 
     353             :     /* Check results */
     354             :     ck_assert_msg(1==result,"Should not be able to register a pointer without filename");
     355             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     356             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     357             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     358             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     359             : 
     360             :     /* Try to create/add a new  block with empty values */
     361             :     oomtest_fill(_i,2);
     362             :     result=memtrack_addblock(
     363             :                (void*)999, /* Pointer */
     364             :                1,          /* Size */
     365             :                __FILE__,   /* Source code filename */
     366             :                0,          /* Source code line number */
     367             :                __DATE__,   /* Compilation date */
     368             :                __TIME__,   /* Compilation time */
     369             :                __func__    /* Source code function, GNU extension */
     370             :            );
     371             :     oomtest_free();
     372             : 
     373             :     /* Check results */
     374             :     ck_assert_msg(1==result,"Should not be able to register a pointer à line number 0");
     375             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     376             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     377             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     378             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     379             : 
     380             :     /* Try to create/add a new  block with empty values */
     381             :     oomtest_fill(_i,2);
     382             :     result=memtrack_addblock(
     383             :                (void*)999, /* Pointer */
     384             :                1,          /* Size */
     385             :                __FILE__,   /* Source code filename */
     386             :                __LINE__,   /* Source code line number */
     387             :                "",         /* Compilation date */
     388             :                __TIME__,   /* Compilation time */
     389             :                __func__    /* Source code function, GNU extension */
     390             :            );
     391             :     oomtest_free();
     392             : 
     393             :     /* Check results */
     394             :     ck_assert_msg(1==result,"Should not be able to register a pointer without a compilation date");
     395             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     396             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     397             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     398             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     399             : 
     400             :     /* Try to create/add a new  block with empty values */
     401             :     oomtest_fill(_i,2);
     402             :     result=memtrack_addblock(
     403             :                (void*)999, /* Pointer */
     404             :                1,          /* Size */
     405             :                __FILE__,   /* Source code filename */
     406             :                __LINE__,   /* Source code line number */
     407             :                __DATE__,   /* Compilation date */
     408             :                "",         /* Compilation time */
     409             :                __func__    /* Source code function, GNU extension */
     410             :            );
     411             :     oomtest_free();
     412             : 
     413             :     /* Check results */
     414             :     ck_assert_msg(1==result,"Should not be able to register a pointer without a compilation time");
     415             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     416             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     417             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     418             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     419             : 
     420             :     /* Try to create/add a new  block with empty values */
     421             :     oomtest_fill(_i,2);
     422             :     result=memtrack_addblock(
     423             :                (void*)999, /* Pointer */
     424             :                1,          /* Size */
     425             :                __FILE__,   /* Source code filename */
     426             :                __LINE__,   /* Source code line number */
     427             :                __DATE__,   /* Compilation date */
     428             :                __TIME__,   /* Compilation time */
     429             :                ""          /* Source code function, GNU extension */
     430             :            );
     431             :     oomtest_free();
     432             : 
     433             :     /* Check results */
     434             :     ck_assert_msg(1==result,"Should not be able to register a pointer without a function name");
     435             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     436             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     437             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     438             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     439             : }
     440             : END_TEST
     441             : #endif /* NDEBUG */
     442             : 
     443             : #ifndef NDEBUG
     444             : START_TEST(addblock_longstrings)
     445             : {
     446             :     uint64_t l_NbBlocks;
     447             :     size_t l_BlockSize;
     448             :     size_t l_RAMSize;
     449             :     unsigned int result;
     450             :     char *szLongString =
     451             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     452             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     453             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     454             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     455             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     456             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     457             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     458             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     459             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     460             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     461             :         ;
     462             : 
     463             :     /* LibMemTrack consistency check preparation */
     464             :     l_NbBlocks=memtrack_getallocatedblocks();
     465             :     l_RAMSize=memtrack_getallocatedRAM();
     466             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     467             : 
     468             :     /* Try to create/add a new  block with empty values */
     469             :     oomtest_fill(_i*(sizeof(TMemBlock)+sizeof(*szLongString)),2);
     470             :     result=memtrack_addblock(
     471             :                (void*)999,  /* Pointer */
     472             :                1,           /* Size */
     473             :                szLongString,/* Source code filename */
     474             :                __LINE__,    /* Source code line number */
     475             :                __DATE__,    /* Compilation date */
     476             :                __TIME__,    /* Compilation time */
     477             :                __func__     /* Source code function, GNU extension */
     478             :            );
     479             :     oomtest_free();
     480             : 
     481             :     /* Check results */
     482             :     ck_assert((0==result)||(oomtest_enabled()));
     483             :     if (0==result) {
     484             :         l_NbBlocks+=1;
     485             :         l_RAMSize+=1;
     486             :         l_BlockSize=1;
     487             :     } else {
     488             :         /* result is false while oom testing : OOM occured */
     489             :         l_BlockSize = 0;
     490             :     }
     491             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     492             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     493             :     ck_assert_msg(l_BlockSize==memtrack_getblocksize((void*)999),"Blocksize inconsistency");
     494             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     495             : 
     496             :     /* Try to create/add a new  block with empty values */
     497             :     oomtest_fill(_i*(sizeof(TMemBlock)+sizeof(*szLongString)),2);
     498             :     result=memtrack_addblock(
     499             :                (void*)998,  /* Pointer */
     500             :                2,           /* Size */
     501             :                __FILE__,    /* Source code filename */
     502             :                1,           /* Source code line number */
     503             :                szLongString,/* Compilation date */
     504             :                __TIME__,    /* Compilation time */
     505             :                __func__     /* Source code function, GNU extension */
     506             :            );
     507             :     oomtest_free();
     508             : 
     509             :     /* Check results */
     510             :     ck_assert((0==result)||(oomtest_enabled()));
     511             :     if (0==result) {
     512             :         l_NbBlocks+=1;
     513             :         l_RAMSize+=2;
     514             :         l_BlockSize=2;
     515             :     } else {
     516             :         /* result is false while oom testing : OOM occured */
     517             :         l_BlockSize = 0;
     518             :     }
     519             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     520             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     521             :     ck_assert_msg(l_BlockSize==memtrack_getblocksize((void*)998),"Blocksize inconsistency");
     522             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     523             : 
     524             :     /* Try to create/add a new  block with empty values */
     525             :     oomtest_fill(_i*(sizeof(TMemBlock)+sizeof(*szLongString)),2);
     526             :     result=memtrack_addblock(
     527             :                (void*)997,  /* Pointer */
     528             :                3,           /* Size */
     529             :                __FILE__,    /* Source code filename */
     530             :                1,           /* Source code line number */
     531             :                __DATE__,    /* Compilation date */
     532             :                szLongString,/* Compilation time */
     533             :                __func__     /* Source code function, GNU extension */
     534             :            );
     535             :     oomtest_free();
     536             : 
     537             :     /* Check results */
     538             :     ck_assert((0==result)||(oomtest_enabled()));
     539             :     if (0==result) {
     540             :         l_NbBlocks+=1;
     541             :         l_RAMSize+=3;
     542             :         l_BlockSize=3;
     543             :     } else {
     544             :         /* result is false while oom testing : OOM occured */
     545             :         l_BlockSize = 0;
     546             :     }
     547             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     548             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     549             :     ck_assert_msg(l_BlockSize==memtrack_getblocksize((void*)997),"Blocksize inconsistency");
     550             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     551             : 
     552             :     /* Try to create/add a new  block with empty values */
     553             :     oomtest_fill(_i*(sizeof(TMemBlock)+sizeof(*szLongString)),2);
     554             :     result=memtrack_addblock(
     555             :                (void*)996,  /* Pointer */
     556             :                4,           /* Size */
     557             :                __FILE__,    /* Source code filename */
     558             :                1,           /* Source code line number */
     559             :                __DATE__,    /* Compilation date */
     560             :                __TIME__,    /* Compilation time */
     561             :                szLongString /* Source code function, GNU extension */
     562             :            );
     563             :     oomtest_free();
     564             : 
     565             :     /* Check results */
     566             :     ck_assert((0==result)||(oomtest_enabled()));
     567             :     if (0==result) {
     568             :         l_NbBlocks+=1;
     569             :         l_RAMSize+=4;
     570             :         l_BlockSize=4;
     571             :     } else {
     572             :         /* result is false while oom testing : OOM occured */
     573             :         l_BlockSize = 0;
     574             :     }
     575             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     576             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     577             :     ck_assert_msg(l_BlockSize==memtrack_getblocksize((void*)996),"Blocksize inconsistency");
     578             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     579             : }
     580             : END_TEST
     581             : #endif /* NDEBUG */
     582             : 
     583             : #ifndef NDEBUG
     584             : START_TEST(delblock_null)
     585             : {
     586             :     uint64_t l_NbBlocks;
     587             :     size_t l_RAMSize;
     588             :     unsigned int result;
     589             : 
     590             :     /* Functor autoinit already tested in a previous test, can surround with sanity checks */
     591             :     l_NbBlocks=memtrack_getallocatedblocks();
     592             :     l_RAMSize=memtrack_getallocatedRAM();
     593             :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
     594             : 
     595             :     /* Run tests under constraint */
     596             :     oomtest_fill(_i,2);
     597             :     result=memtrack_delblock(
     598             :                NULL,       /* Pointer */
     599             :                __FILE__,   /* Source code filename */
     600             :                __LINE__,   /* Source code line number */
     601             :                __DATE__,   /* Compilation date */
     602             :                __TIME__,   /* Compilation time */
     603             :                __func__    /* Source code function, GNU extension */
     604             :            );
     605             :     oomtest_free();
     606             : 
     607             :     /* Check results should always fail, oom or not */
     608             :     ck_assert_msg(1==result,"Should not be able to unregister a NULL pointer");
     609             :     ck_assert_msg(0==memtrack_getblocksize(NULL),"Blocksize of NULL pointer should be 0");
     610             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     611             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     612             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     613             : }
     614             : END_TEST
     615             : #endif /* NDEBUG */
     616             : 
     617             : #ifndef NDEBUG
     618             : START_TEST(delblock_missing)
     619             : {
     620             :     uint64_t l_NbBlocks;
     621             :     size_t l_RAMSize;
     622             :     unsigned int result;
     623             : 
     624             :     /* Functor autoinit already tested in a previous test, can surround with sanity checks */
     625             :     l_NbBlocks=memtrack_getallocatedblocks();
     626             :     l_RAMSize=memtrack_getallocatedRAM();
     627             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     628             : 
     629             :     /* Run tests under constraint */
     630             :     oomtest_fill(_i,2);
     631             :     result=memtrack_delblock(
     632             :                (void*)999, /* Pointer */
     633             :                __FILE__,   /* Source code filename */
     634             :                __LINE__,   /* Source code line number */
     635             :                __DATE__,   /* Compilation date */
     636             :                __TIME__,   /* Compilation time */
     637             :                __func__    /* Source code function, GNU extension */
     638             :            );
     639             :     oomtest_free();
     640             : 
     641             :     /* Check results should always fail, oom or not */
     642             :     ck_assert_msg(1==result,"Should not be able to unregister a missing pointer");
     643             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing pointer should be 0");
     644             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     645             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     646             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     647             : }
     648             : END_TEST
     649             : #endif /* NDEBUG */
     650             : 
     651             : #ifndef NDEBUG
     652             : START_TEST(addblock1_delblock1)
     653             : {
     654             :     uint64_t l_NbBlocks;
     655             :     size_t l_RAMSize;
     656             :     unsigned int result;
     657             : 
     658             :     /* LibMemTrack consistency check preparation */
     659             :     l_NbBlocks=memtrack_getallocatedblocks();
     660             :     l_RAMSize=memtrack_getallocatedRAM();
     661             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     662             : 
     663             :     /* Ensure that block does not already exist */
     664             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"The 999 block should not already exist");
     665             : 
     666             :     oomtest_fill(_i*sizeof(TMemBlock),2);
     667             :     /* Create a new block */
     668             :     result=memtrack_addblock(
     669             :                (void*)999, /* Pointer */
     670             :                10,         /* Size */
     671             :                __FILE__,   /* Source code filename */
     672             :                __LINE__,   /* Source code line number */
     673             :                __DATE__,   /* Compilation date */
     674             :                __TIME__,   /* Compilation time */
     675             :                __func__    /* Source code function, GNU extension */
     676             :            );
     677             :     oomtest_free();
     678             : 
     679             :     /* Intermediate check */
     680             :     ck_assert((0==result)||(oomtest_enabled()));
     681             :     if (0==result) {
     682             :         /* No OOM error, update the check counters */
     683             :         l_NbBlocks+=1;
     684             :         l_RAMSize+=10;
     685             :         ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of 999 block should be 10");
     686             :     } else {
     687             :         ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of 999 missing block should be 0");
     688             :     }
     689             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     690             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     691             : 
     692             :     oomtest_fill(_i,2);
     693             :     /* Delete the created block */
     694             :     result = memtrack_delblock(
     695             :                  (void*)999, /* Pointer */
     696             :                  __FILE__,   /* Source code filename */
     697             :                  __LINE__,   /* Source code line number */
     698             :                  __DATE__,   /* Compilation date */
     699             :                  __TIME__,   /* Compilation time */
     700             :                  __func__    /* Source code function, GNU extension */
     701             :              );
     702             :     oomtest_free();
     703             : 
     704             :     /* Check results */
     705             :     ck_assert((0==result)||(oomtest_enabled()));
     706             :     if (0==result) {
     707             :         /* No OOM error, update the check counters */
     708             :         l_NbBlocks-=1;
     709             :         l_RAMSize-=10;
     710             :     }
     711             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     712             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     713             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of deleted 999 block should be 0");
     714             : }
     715             : END_TEST
     716             : #endif /* NDEBUG */
     717             : 
     718             : #ifndef NDEBUG
     719             : START_TEST(addblock12_delblock12)
     720             : {
     721             :     uint64_t l_NbBlocks;
     722             :     size_t l_RAMSize;
     723             :     unsigned int result;
     724             : 
     725             :     /* LibMemTrack consistency check preparation */
     726             :     l_NbBlocks=memtrack_getallocatedblocks();
     727             :     l_RAMSize=memtrack_getallocatedRAM();
     728             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     729             : 
     730             :     /* Ensure that block does not already exist */
     731             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"The 999 block should not already exist");
     732             : 
     733             :     oomtest_fill(_i*sizeof(TMemBlock),2);
     734             :     /* Create a new block */
     735             :     result=memtrack_addblock(
     736             :                (void*)999, /* Pointer */
     737             :                10,         /* Size */
     738             :                __FILE__,   /* Source code filename */
     739             :                __LINE__,   /* Source code line number */
     740             :                __DATE__,   /* Compilation date */
     741             :                __TIME__,   /* Compilation time */
     742             :                __func__    /* Source code function, GNU extension */
     743             :            );
     744             :     oomtest_free();
     745             : 
     746             :     /* Intermediate check */
     747             :     ck_assert((0==result)||(oomtest_enabled()));
     748             :     if (0==result) {
     749             :         /* No OOM error, update the check counters */
     750             :         l_NbBlocks+=1;
     751             :         l_RAMSize+=10;
     752             :         ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of 999 block should be 10");
     753             :     } else {
     754             :         ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of 999 missing block should be 0");
     755             :     }
     756             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     757             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     758             : 
     759             :     /* Ensure that block does not already exist */
     760             :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"The 998 block should not already exist");
     761             : 
     762             :     oomtest_fill(_i*sizeof(TMemBlock),2);
     763             :     /* Create a new block */
     764             :     result=memtrack_addblock(
     765             :                (void*)998, /* Pointer */
     766             :                20,         /* Size */
     767             :                __FILE__,   /* Source code filename */
     768             :                __LINE__,   /* Source code line number */
     769             :                __DATE__,   /* Compilation date */
     770             :                __TIME__,   /* Compilation time */
     771             :                __func__    /* Source code function, GNU extension */
     772             :            );
     773             :     oomtest_free();
     774             : 
     775             :     /* Intermediate check */
     776             :     ck_assert((0==result)||(oomtest_enabled()));
     777             :     if (0==result) {
     778             :         /* No OOM error, update the check counters */
     779             :         l_NbBlocks+=1;
     780             :         l_RAMSize+=20;
     781             :         ck_assert_msg(20==memtrack_getblocksize((void*)998),"Blocksize of 998 block should be 10");
     782             :     } else {
     783             :         ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of 998 missing block should be 0");
     784             :     }
     785             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     786             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     787             : 
     788             :     oomtest_fill(_i,2);
     789             :     /* Delete the created block */
     790             :     result = memtrack_delblock(
     791             :                  (void*)999, /* Pointer */
     792             :                  __FILE__,   /* Source code filename */
     793             :                  __LINE__,   /* Source code line number */
     794             :                  __DATE__,   /* Compilation date */
     795             :                  __TIME__,   /* Compilation time */
     796             :                  __func__    /* Source code function, GNU extension */
     797             :              );
     798             :     oomtest_free();
     799             : 
     800             :     /* Check results */
     801             :     ck_assert((0==result)||(oomtest_enabled()));
     802             :     if (0==result) {
     803             :         /* No OOM error, update the check counters */
     804             :         l_NbBlocks-=1;
     805             :         l_RAMSize-=10;
     806             :     }
     807             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     808             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     809             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of deleted 999 block should be 0");
     810             : 
     811             :     oomtest_fill(_i,2);
     812             :     /* Delete the created block */
     813             :     result = memtrack_delblock(
     814             :                  (void*)998, /* Pointer */
     815             :                  __FILE__,   /* Source code filename */
     816             :                  __LINE__,   /* Source code line number */
     817             :                  __DATE__,   /* Compilation date */
     818             :                  __TIME__,   /* Compilation time */
     819             :                  __func__    /* Source code function, GNU extension */
     820             :              );
     821             :     oomtest_free();
     822             : 
     823             :     /* Check results */
     824             :     ck_assert((0==result)||(oomtest_enabled()));
     825             :     if (0==result) {
     826             :         /* No OOM error, update the check counters */
     827             :         l_NbBlocks-=1;
     828             :         l_RAMSize-=20;
     829             :     }
     830             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     831             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     832             :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of deleted 998 block should be 0");
     833             : }
     834             : END_TEST
     835             : #endif /* NDEBUG */
     836             : 
     837             : #ifndef NDEBUG
     838             : START_TEST(addblock12_delblock21)
     839             : {
     840             :     uint64_t l_NbBlocks;
     841             :     size_t l_RAMSize;
     842             :     unsigned int result;
     843             : 
     844             :     /* LibMemTrack consistency check preparation */
     845             :     l_NbBlocks=memtrack_getallocatedblocks();
     846             :     l_RAMSize=memtrack_getallocatedRAM();
     847             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     848             : 
     849             :     /* Ensure that block does not already exist */
     850             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"The 999 block should not already exist");
     851             : 
     852             :     oomtest_fill(_i*sizeof(TMemBlock),2);
     853             :     /* Create a new block */
     854             :     result=memtrack_addblock(
     855             :                (void*)999, /* Pointer */
     856             :                10,         /* Size */
     857             :                __FILE__,   /* Source code filename */
     858             :                __LINE__,   /* Source code line number */
     859             :                __DATE__,   /* Compilation date */
     860             :                __TIME__,   /* Compilation time */
     861             :                __func__    /* Source code function, GNU extension */
     862             :            );
     863             :     oomtest_free();
     864             : 
     865             :     /* Intermediate check */
     866             :     ck_assert((0==result)||(oomtest_enabled()));
     867             :     if (0==result) {
     868             :         /* No OOM error, update the check counters */
     869             :         l_NbBlocks+=1;
     870             :         l_RAMSize+=10;
     871             :         ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of 999 block should be 10");
     872             :     } else {
     873             :         ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of 999 missing block should be 0");
     874             :     }
     875             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     876             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     877             : 
     878             :     /* Ensure that block does not already exist */
     879             :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"The 998 block should not already exist");
     880             : 
     881             :     oomtest_fill(_i*sizeof(TMemBlock),2);
     882             :     /* Create a new block */
     883             :     result=memtrack_addblock(
     884             :                (void*)998, /* Pointer */
     885             :                20,         /* Size */
     886             :                __FILE__,   /* Source code filename */
     887             :                __LINE__,   /* Source code line number */
     888             :                __DATE__,   /* Compilation date */
     889             :                __TIME__,   /* Compilation time */
     890             :                __func__    /* Source code function, GNU extension */
     891             :            );
     892             :     oomtest_free();
     893             : 
     894             :     /* Intermediate check */
     895             :     ck_assert((0==result)||(oomtest_enabled()));
     896             :     if (0==result) {
     897             :         /* No OOM error, update the check counters */
     898             :         l_NbBlocks+=1;
     899             :         l_RAMSize+=20;
     900             :         ck_assert_msg(20==memtrack_getblocksize((void*)998),"Blocksize of 998 block should be 10");
     901             :     } else {
     902             :         ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of 998 missing block should be 0");
     903             :     }
     904             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     905             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     906             : 
     907             :     oomtest_fill(_i,2);
     908             :     /* Delete the created block */
     909             :     result = memtrack_delblock(
     910             :                  (void*)998, /* Pointer */
     911             :                  __FILE__,   /* Source code filename */
     912             :                  __LINE__,   /* Source code line number */
     913             :                  __DATE__,   /* Compilation date */
     914             :                  __TIME__,   /* Compilation time */
     915             :                  __func__    /* Source code function, GNU extension */
     916             :              );
     917             :     oomtest_free();
     918             : 
     919             :     /* Check results */
     920             :     ck_assert((0==result)||(oomtest_enabled()));
     921             :     if (0==result) {
     922             :         /* No OOM error, update the check counters */
     923             :         l_NbBlocks-=1;
     924             :         l_RAMSize-=20;
     925             :     }
     926             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     927             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     928             :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of deleted 998 block should be 0");
     929             : 
     930             :     oomtest_fill(_i,2);
     931             :     /* Delete the created block */
     932             :     result = memtrack_delblock(
     933             :                  (void*)999, /* Pointer */
     934             :                  __FILE__,   /* Source code filename */
     935             :                  __LINE__,   /* Source code line number */
     936             :                  __DATE__,   /* Compilation date */
     937             :                  __TIME__,   /* Compilation time */
     938             :                  __func__    /* Source code function, GNU extension */
     939             :              );
     940             :     oomtest_free();
     941             : 
     942             :     /* Check results */
     943             :     ck_assert((0==result)||(oomtest_enabled()));
     944             :     if (0==result) {
     945             :         /* No OOM error, update the check counters */
     946             :         l_NbBlocks-=1;
     947             :         l_RAMSize-=10;
     948             :     }
     949             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     950             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     951             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of deleted 999 block should be 0");
     952             : }
     953             : END_TEST
     954             : #endif /* NDEBUG */
     955             : 
     956             : #ifndef NDEBUG
     957             : START_TEST(addblock123_delblock123)
     958             : {
     959             :     uint64_t l_NbBlocks;
     960             :     size_t l_RAMSize;
     961             :     unsigned int result;
     962             : 
     963             :     /* LibMemTrack consistency check preparation */
     964             :     l_NbBlocks=memtrack_getallocatedblocks();
     965             :     l_RAMSize=memtrack_getallocatedRAM();
     966             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     967             : 
     968             :     /* Ensure that block does not already exist */
     969             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"The 999 block should not already exist");
     970             : 
     971             :     oomtest_fill(_i*sizeof(TMemBlock),2);
     972             :     /* Create a new block */
     973             :     result=memtrack_addblock(
     974             :                (void*)999, /* Pointer */
     975             :                10,         /* Size */
     976             :                __FILE__,   /* Source code filename */
     977             :                __LINE__,   /* Source code line number */
     978             :                __DATE__,   /* Compilation date */
     979             :                __TIME__,   /* Compilation time */
     980             :                __func__    /* Source code function, GNU extension */
     981             :            );
     982             :     oomtest_free();
     983             : 
     984             :     /* Intermediate check */
     985             :     ck_assert((0==result)||(oomtest_enabled()));
     986             :     if (0==result) {
     987             :         /* No OOM error, update the check counters */
     988             :         l_NbBlocks+=1;
     989             :         l_RAMSize+=10;
     990             :         ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of 999 block should be 10");
     991             :     } else {
     992             :         ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of 999 missing block should be 0");
     993             :     }
     994             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     995             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     996             : 
     997             :     /* Ensure that block does not already exist */
     998             :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"The 998 block should not already exist");
     999             : 
    1000             :     oomtest_fill(_i*sizeof(TMemBlock),2);
    1001             :     /* Create a new block */
    1002             :     result=memtrack_addblock(
    1003             :                (void*)998, /* Pointer */
    1004             :                20,         /* Size */
    1005             :                __FILE__,   /* Source code filename */
    1006             :                __LINE__,   /* Source code line number */
    1007             :                __DATE__,   /* Compilation date */
    1008             :                __TIME__,   /* Compilation time */
    1009             :                __func__    /* Source code function, GNU extension */
    1010             :            );
    1011             :     oomtest_free();
    1012             : 
    1013             :     /* Intermediate check */
    1014             :     ck_assert((0==result)||(oomtest_enabled()));
    1015             :     if (0==result) {
    1016             :         /* No OOM error, update the check counters */
    1017             :         l_NbBlocks+=1;
    1018             :         l_RAMSize+=20;
    1019             :         ck_assert_msg(20==memtrack_getblocksize((void*)998),"Blocksize of 998 block should be 10");
    1020             :     } else {
    1021             :         ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of 998 missing block should be 0");
    1022             :     }
    1023             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1024             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1025             : 
    1026             :     /* Ensure that block does not already exist */
    1027             :     ck_assert_msg(0==memtrack_getblocksize((void*)997),"The 997 block should not already exist");
    1028             : 
    1029             :     oomtest_fill(_i*sizeof(TMemBlock),2);
    1030             :     /* Create a new block */
    1031             :     result=memtrack_addblock(
    1032             :                (void*)997, /* Pointer */
    1033             :                30,         /* Size */
    1034             :                __FILE__,   /* Source code filename */
    1035             :                __LINE__,   /* Source code line number */
    1036             :                __DATE__,   /* Compilation date */
    1037             :                __TIME__,   /* Compilation time */
    1038             :                __func__    /* Source code function, GNU extension */
    1039             :            );
    1040             :     oomtest_free();
    1041             : 
    1042             :     /* Intermediate check */
    1043             :     ck_assert((0==result)||(oomtest_enabled()));
    1044             :     if (0==result) {
    1045             :         /* No OOM error, update the check counters */
    1046             :         l_NbBlocks+=1;
    1047             :         l_RAMSize+=30;
    1048             :         ck_assert_msg(30==memtrack_getblocksize((void*)997),"Blocksize of 997 block should be 10");
    1049             :     } else {
    1050             :         ck_assert_msg(0==memtrack_getblocksize((void*)997),"Blocksize of 997 missing block should be 0");
    1051             :     }
    1052             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1053             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1054             : 
    1055             :     oomtest_fill(_i,2);
    1056             :     /* Delete the created block */
    1057             :     result = memtrack_delblock(
    1058             :                  (void*)999, /* Pointer */
    1059             :                  __FILE__,   /* Source code filename */
    1060             :                  __LINE__,   /* Source code line number */
    1061             :                  __DATE__,   /* Compilation date */
    1062             :                  __TIME__,   /* Compilation time */
    1063             :                  __func__    /* Source code function, GNU extension */
    1064             :              );
    1065             :     oomtest_free();
    1066             : 
    1067             :     /* Check results */
    1068             :     ck_assert((0==result)||(oomtest_enabled()));
    1069             :     if (0==result) {
    1070             :         /* No OOM error, update the check counters */
    1071             :         l_NbBlocks-=1;
    1072             :         l_RAMSize-=10;
    1073             :     }
    1074             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1075             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1076             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of deleted 999 block should be 0");
    1077             : 
    1078             :     oomtest_fill(_i,2);
    1079             :     /* Delete the created block */
    1080             :     result = memtrack_delblock(
    1081             :                  (void*)998, /* Pointer */
    1082             :                  __FILE__,   /* Source code filename */
    1083             :                  __LINE__,   /* Source code line number */
    1084             :                  __DATE__,   /* Compilation date */
    1085             :                  __TIME__,   /* Compilation time */
    1086             :                  __func__    /* Source code function, GNU extension */
    1087             :              );
    1088             :     oomtest_free();
    1089             : 
    1090             :     /* Check results */
    1091             :     ck_assert((0==result)||(oomtest_enabled()));
    1092             :     if (0==result) {
    1093             :         /* No OOM error, update the check counters */
    1094             :         l_NbBlocks-=1;
    1095             :         l_RAMSize-=20;
    1096             :     }
    1097             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1098             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1099             :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of deleted 998 block should be 0");
    1100             : 
    1101             :     oomtest_fill(_i,2);
    1102             :     /* Delete the created block */
    1103             :     result = memtrack_delblock(
    1104             :                  (void*)997, /* Pointer */
    1105             :                  __FILE__,   /* Source code filename */
    1106             :                  __LINE__,   /* Source code line number */
    1107             :                  __DATE__,   /* Compilation date */
    1108             :                  __TIME__,   /* Compilation time */
    1109             :                  __func__    /* Source code function, GNU extension */
    1110             :              );
    1111             :     oomtest_free();
    1112             : 
    1113             :     /* Check results */
    1114             :     ck_assert((0==result)||(oomtest_enabled()));
    1115             :     if (0==result) {
    1116             :         /* No OOM error, update the check counters */
    1117             :         l_NbBlocks-=1;
    1118             :         l_RAMSize-=30;
    1119             :     }
    1120             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1121             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1122             :     ck_assert_msg(0==memtrack_getblocksize((void*)997),"Blocksize of deleted 997 block should be 0");
    1123             : }
    1124             : END_TEST
    1125             : #endif /* NDEBUG */
    1126             : 
    1127             : #ifndef NDEBUG
    1128             : START_TEST(addblock123_delblock2)
    1129             : {
    1130             :     uint64_t l_NbBlocks;
    1131             :     size_t l_RAMSize;
    1132             :     unsigned int result;
    1133             : 
    1134             :     /* LibMemTrack consistency check preparation */
    1135             :     l_NbBlocks=memtrack_getallocatedblocks();
    1136             :     l_RAMSize=memtrack_getallocatedRAM();
    1137             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
    1138             : 
    1139             :     /* Ensure that block does not already exist */
    1140             :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"The 999 block should not already exist");
    1141             : 
    1142             :     oomtest_fill(_i*sizeof(TMemBlock),2);
    1143             :     /* Create a new block */
    1144             :     result=memtrack_addblock(
    1145             :                (void*)999, /* Pointer */
    1146             :                10,         /* Size */
    1147             :                __FILE__,   /* Source code filename */
    1148             :                __LINE__,   /* Source code line number */
    1149             :                __DATE__,   /* Compilation date */
    1150             :                __TIME__,   /* Compilation time */
    1151             :                __func__    /* Source code function, GNU extension */
    1152             :            );
    1153             :     oomtest_free();
    1154             : 
    1155             :     /* Intermediate check */
    1156             :     ck_assert((0==result)||(oomtest_enabled()));
    1157             :     if (0==result) {
    1158             :         /* No OOM error, update the check counters */
    1159             :         l_NbBlocks+=1;
    1160             :         l_RAMSize+=10;
    1161             :         ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of 999 block should be 10");
    1162             :     } else {
    1163             :         ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of 999 missing block should be 0");
    1164             :     }
    1165             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1166             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1167             : 
    1168             :     /* Ensure that block does not already exist */
    1169             :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"The 998 block should not already exist");
    1170             : 
    1171             :     oomtest_fill(_i*sizeof(TMemBlock),2);
    1172             :     /* Create a new block */
    1173             :     result=memtrack_addblock(
    1174             :                (void*)998, /* Pointer */
    1175             :                20,         /* Size */
    1176             :                __FILE__,   /* Source code filename */
    1177             :                __LINE__,   /* Source code line number */
    1178             :                __DATE__,   /* Compilation date */
    1179             :                __TIME__,   /* Compilation time */
    1180             :                __func__    /* Source code function, GNU extension */
    1181             :            );
    1182             :     oomtest_free();
    1183             : 
    1184             :     /* Intermediate check */
    1185             :     ck_assert((0==result)||(oomtest_enabled()));
    1186             :     if (0==result) {
    1187             :         /* No OOM error, update the check counters */
    1188             :         l_NbBlocks+=1;
    1189             :         l_RAMSize+=20;
    1190             :         ck_assert_msg(20==memtrack_getblocksize((void*)998),"Blocksize of 998 block should be 10");
    1191             :     } else {
    1192             :         ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of 998 missing block should be 0");
    1193             :     }
    1194             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1195             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1196             : 
    1197             :     /* Ensure that block does not already exist */
    1198             :     ck_assert_msg(0==memtrack_getblocksize((void*)997),"The 997 block should not already exist");
    1199             : 
    1200             :     oomtest_fill(_i*sizeof(TMemBlock),2);
    1201             :     /* Create a new block */
    1202             :     result=memtrack_addblock(
    1203             :                (void*)997, /* Pointer */
    1204             :                30,         /* Size */
    1205             :                __FILE__,   /* Source code filename */
    1206             :                __LINE__,   /* Source code line number */
    1207             :                __DATE__,   /* Compilation date */
    1208             :                __TIME__,   /* Compilation time */
    1209             :                __func__    /* Source code function, GNU extension */
    1210             :            );
    1211             :     oomtest_free();
    1212             : 
    1213             :     /* Intermediate check */
    1214             :     ck_assert((0==result)||(oomtest_enabled()));
    1215             :     if (0==result) {
    1216             :         /* No OOM error, update the check counters */
    1217             :         l_NbBlocks+=1;
    1218             :         l_RAMSize+=30;
    1219             :         ck_assert_msg(30==memtrack_getblocksize((void*)997),"Blocksize of 997 block should be 10");
    1220             :     } else {
    1221             :         ck_assert_msg(0==memtrack_getblocksize((void*)997),"Blocksize of 997 missing block should be 0");
    1222             :     }
    1223             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1224             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1225             : 
    1226             :     oomtest_fill(_i,2);
    1227             :     /* Delete the created block */
    1228             :     result = memtrack_delblock(
    1229             :                  (void*)998, /* Pointer */
    1230             :                  __FILE__,   /* Source code filename */
    1231             :                  __LINE__,   /* Source code line number */
    1232             :                  __DATE__,   /* Compilation date */
    1233             :                  __TIME__,   /* Compilation time */
    1234             :                  __func__    /* Source code function, GNU extension */
    1235             :              );
    1236             :     oomtest_free();
    1237             : 
    1238             :     /* Check results */
    1239             :     ck_assert((0==result)||(oomtest_enabled()));
    1240             :     if (0==result) {
    1241             :         /* No OOM error, update the check counters */
    1242             :         l_NbBlocks-=1;
    1243             :         l_RAMSize-=20;
    1244             :     }
    1245             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1246             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1247             :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of deleted 998 block should be 0");
    1248             : }
    1249             : END_TEST
    1250             : #endif /* NDEBUG */
    1251             : 
    1252             : #ifndef NDEBUG
    1253             : START_TEST(adddelblock_oom)
    1254             : {
    1255             :     uint64_t l_NbBlocks;
    1256             :     size_t l_RAMSize;
    1257             :     long unsigned int i=0;
    1258             :     uint16_t oomtestvalues[65536] = {0};
    1259             :     char *szLongString =
    1260             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    1261             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    1262             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    1263             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    1264             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    1265             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    1266             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    1267             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    1268             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    1269             :         "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    1270             :         ;
    1271             : 
    1272             :     /* LibMemTrack consistency check preparation */
    1273             :     l_NbBlocks=memtrack_getallocatedblocks();
    1274             :     l_RAMSize=memtrack_getallocatedRAM();
    1275             :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
    1276             : 
    1277             :     /* Try to trigger OOM inside the tested feature */
    1278             :     i = 0;
    1279             :     oomtest_fill(_i*(sizeof(TMemBlock)+4*(26+10+26)*10),2);
    1280             :     do {
    1281             :         i++;
    1282             :         oomtestvalues[i] = memtrack_addblock(
    1283             :                                (void*)(i+99),/* Pointer */
    1284             :                                10,           /* Size */
    1285             :                                szLongString, /* Source code filename */
    1286             :                                __LINE__,     /* Source code line number */
    1287             :                                szLongString, /* Compilation date */
    1288             :                                szLongString, /* Compilation time */
    1289             :                                szLongString  /* Source code function, GNU extension */
    1290             :                            );
    1291             :     } while ((i<65535)&&(0==oomtestvalues[i]));
    1292             :     oomtest_free();
    1293             : 
    1294             :     /* Intermediate check */
    1295             :     l_NbBlocks+=i-1;
    1296             :     l_RAMSize+=(i-1)*10;
    1297             :     /* Should have returned NULL (OOM) before reaching 65535 */
    1298             :     ck_assert_msg(65535!=i,"Did not manage to trigger OOM");
    1299             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1300             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1301             : 
    1302             :     /* We will loose i value, precalculate values */
    1303             :     l_NbBlocks-=i-1;
    1304             :     l_RAMSize-=(i-1)*10;
    1305             : 
    1306             :     oomtest_fill(_i,2);
    1307             :     /* Free all the allocated memory */
    1308             :     i = 1;
    1309             :     while ((i<65535)&&(0==oomtestvalues[i])) {
    1310             :         if(0!=(oomtestvalues[i]=memtrack_delblock(
    1311             :                                     (void*)(i+99),/* Pointer */
    1312             :                                     __FILE__,     /* Source code filename */
    1313             :                                     __LINE__,     /* Source code line number */
    1314             :                                     __DATE__,     /* Compilation date */
    1315             :                                     __TIME__,     /* Compilation time */
    1316             :                                     __func__      /* Source code function, GNU extension */
    1317             :                                 )))
    1318             :             break;
    1319             :         i++;
    1320             :     }
    1321             :     oomtest_free();
    1322             : 
    1323             :     ck_assert_msg(65535!=i,"Did not manage to free all allocated RAM");
    1324             :     ck_assert(1==oomtestvalues[i]);
    1325             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1326             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1327             : }
    1328             : END_TEST
    1329             : #endif /* NDEBUG */
    1330             : 
    1331             : /************************************************************************/
    1332           0 : void memtrack_checked_uninitialized_setup()
    1333             : {
    1334           0 :     signals_catch();
    1335           0 :     forktest_gprofdir();
    1336           0 : }
    1337           0 : void memtrack_checked_withdata_setup()
    1338             : {
    1339           0 :     signals_catch();
    1340           0 :     forktest_gprofdir();
    1341             : #ifndef NDEBUG
    1342             :     uint64_t l_NbBlocks;
    1343             :     uint64_t l_RAMSize;
    1344             : 
    1345             :     l_NbBlocks=memtrack_getallocatedblocks();
    1346             :     l_RAMSize=memtrack_getallocatedRAM();
    1347             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1348             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1349             :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1350             :     ck_assert_msg(0==memtrack_addblock(
    1351             :                       (void*)1,   /* Pointer */
    1352             :                       10,         /* Size */
    1353             :                       __FILE__,   /* Source code filename */
    1354             :                       __LINE__,   /* Source code line number */
    1355             :                       __DATE__,   /* Compilation date */
    1356             :                       __TIME__,   /* Compilation time */
    1357             :                       "fonction"  /* Source code function, GNU extension */
    1358             :                   ),"Creating block (Normal values)");
    1359             :     ck_assert_msg(10==memtrack_getblocksize((void*)1),"Invalid getblocksize");
    1360             :     ck_assert_msg( 0==memtrack_getblocksize((void*)2),"Invalid getblocksize");
    1361             :     ck_assert_msg( 0==memtrack_getblocksize((void*)3),"Invalid getblocksize");
    1362             :     l_NbBlocks += 1;
    1363             :     l_RAMSize += 10;
    1364             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1365             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1366             :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1367             :     ck_assert_msg(0==memtrack_addblock(
    1368             :                       (void*)2,   /* Pointer */
    1369             :                       20,         /* Size */
    1370             :                       __FILE__,   /* Source code filename */
    1371             :                       __LINE__,   /* Source code line number */
    1372             :                       __DATE__,   /* Compilation date */
    1373             :                       __TIME__,   /* Compilation time */
    1374             :                       "fonction"  /* Source code function, GNU extension */
    1375             :                   ),"Creating block (Normal values)");
    1376             :     ck_assert_msg(10==memtrack_getblocksize((void*)1),"Invalid getblocksize");
    1377             :     ck_assert_msg(20==memtrack_getblocksize((void*)2),"Invalid getblocksize");
    1378             :     ck_assert_msg( 0==memtrack_getblocksize((void*)3),"Invalid getblocksize");
    1379             :     l_NbBlocks += 1;
    1380             :     l_RAMSize += 20;
    1381             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1382             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1383             :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1384             :     ck_assert_msg(0==memtrack_addblock(
    1385             :                       (void*)3,   /* Pointer */
    1386             :                       30,         /* Size */
    1387             :                       __FILE__,   /* Source code filename */
    1388             :                       __LINE__,   /* Source code line number */
    1389             :                       __DATE__,   /* Compilation date */
    1390             :                       __TIME__,   /* Compilation time */
    1391             :                       "fonction"  /* Source code function, GNU extension */
    1392             :                   ),"Creating block (Normal values)");
    1393             :     ck_assert_msg(10==memtrack_getblocksize((void*)1),"Invalid getblocksize");
    1394             :     ck_assert_msg(20==memtrack_getblocksize((void*)2),"Invalid getblocksize");
    1395             :     ck_assert_msg(30==memtrack_getblocksize((void*)3),"Invalid getblocksize");
    1396             :     l_NbBlocks += 1;
    1397             :     l_RAMSize += 30;
    1398             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1399             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1400             :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1401             : #endif /* NDEBUG */
    1402           0 : }
    1403           0 : void memtrack_checked_common_teardown()
    1404             : {
    1405           0 :     signals_release();
    1406             : #ifndef NDEBUG
    1407             :     uint64_t l_NbBlocks;
    1408             :     uint64_t l_RAMSize;
    1409             :     /** @todo make memtrack_reset compatible with OOMTEST_* helpers */
    1410             :     l_NbBlocks=memtrack_getallocatedblocks();
    1411             :     l_RAMSize=memtrack_getallocatedRAM();
    1412             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1413             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1414             :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1415             :     memtrack_reset();
    1416             :     memtrack_reset(); /* Test the double run protection */
    1417             :     l_NbBlocks = 0;
    1418             :     l_RAMSize = 0;
    1419             :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1420             :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1421             :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1422             : #endif /* NDEBUG */
    1423           0 : }
    1424             : /************************************************************************/
    1425        5748 : void memtrack_unchecked_common_setup()
    1426             : {
    1427        5748 :     forktest_init();
    1428        5748 : }
    1429        5748 : void memtrack_unchecked_common_teardown()
    1430             : {
    1431        5748 : }
    1432        2874 : void memtrack_unchecked_oom_setup()
    1433             : {
    1434        2874 :     oomtest_enable(RAMLIMIT_SOFT);
    1435        2874 :     memtrack_unchecked_common_setup();
    1436        2874 : }
    1437        2874 : void memtrack_unchecked_oom_teardown()
    1438             : {
    1439        2874 :     oomtest_disable();
    1440        2874 :     memtrack_unchecked_common_teardown();
    1441        2874 : }
    1442             : /************************************************************************/
    1443        1441 : Suite* libdebug_memtrack_suite()
    1444             : {
    1445             :     Suite *s;
    1446             :     TCase *tc;
    1447             : 
    1448        1441 :     s = suite_create("LibDebug-MemTrack");
    1449        1441 :     tc = tcase_create("Uninitialized");
    1450        1441 :     tcase_add_checked_fixture(tc, memtrack_checked_uninitialized_setup, memtrack_checked_common_teardown);
    1451        1441 :     tcase_add_unchecked_fixture(tc, memtrack_unchecked_common_setup, memtrack_unchecked_common_teardown);
    1452        1441 :     suite_add_tcase(s, tc);
    1453             : #ifndef NDEBUG
    1454             :     tcase_add_test(tc, getallocatedRAM_first);
    1455             :     tcase_add_test(tc, getallocatedblocks_first);
    1456             :     tcase_add_test(tc, getblocksize_first);
    1457             :     tcase_add_test(tc, getblocksize_null);
    1458             :     tcase_add_test(tc, getblocksize_missing);
    1459             :     tcase_add_test(tc, addblock_null_first);
    1460             :     tcase_add_test(tc, delblock_null_first);
    1461             :     tcase_add_test(tc, addblock_null);
    1462             :     tcase_add_test(tc, addblock_duplicate);
    1463             :     tcase_add_test(tc, addblock_empty);
    1464             :     tcase_add_test(tc, addblock_longstrings);
    1465             :     tcase_add_test(tc, delblock_null);
    1466             :     tcase_add_test(tc, delblock_missing);
    1467             :     tcase_add_test(tc, addblock1_delblock1);
    1468             :     tcase_add_test(tc, addblock12_delblock12);
    1469             :     tcase_add_test(tc, addblock12_delblock21);
    1470             :     tcase_add_test(tc, addblock123_delblock123);
    1471             :     tcase_add_test(tc, addblock123_delblock2);
    1472             :     /* tcase_add_test(tc, adddelblock_oom); */
    1473             : #endif
    1474             : 
    1475        1441 :     tc = tcase_create("WithData");
    1476        1441 :     tcase_add_checked_fixture(tc, memtrack_checked_withdata_setup, memtrack_checked_common_teardown);
    1477        1441 :     tcase_add_unchecked_fixture(tc, memtrack_unchecked_common_setup, memtrack_unchecked_common_teardown);
    1478        1441 :     suite_add_tcase(s, tc);
    1479             : #ifndef NDEBUG
    1480             :     /* tcase_add_test(tc, getallocatedRAM_first); */
    1481             :     /* tcase_add_test(tc, getallocatedblocks_first); */
    1482             :     tcase_add_test(tc, getblocksize_first);
    1483             :     tcase_add_test(tc, getblocksize_null);
    1484             :     tcase_add_test(tc, getblocksize_missing);
    1485             :     tcase_add_test(tc, addblock_null_first);
    1486             :     tcase_add_test(tc, delblock_null_first);
    1487             :     tcase_add_test(tc, addblock_null);
    1488             :     tcase_add_test(tc, addblock_duplicate);
    1489             :     tcase_add_test(tc, addblock_empty);
    1490             :     tcase_add_test(tc, addblock_longstrings);
    1491             :     tcase_add_test(tc, delblock_null);
    1492             :     tcase_add_test(tc, delblock_missing);
    1493             :     tcase_add_test(tc, addblock1_delblock1);
    1494             :     tcase_add_test(tc, addblock12_delblock12);
    1495             :     tcase_add_test(tc, addblock12_delblock21);
    1496             :     tcase_add_test(tc, addblock123_delblock123);
    1497             :     tcase_add_test(tc, addblock123_delblock2);
    1498             :     /* tcase_add_test(tc, adddelblock_oom); */
    1499             : #endif
    1500             : 
    1501        1441 :     tc = tcase_create("Uninitialized-OOM");
    1502        1441 :     tcase_set_tags(tc,"oom");
    1503        1441 :     tcase_add_checked_fixture(tc, memtrack_checked_uninitialized_setup, memtrack_checked_common_teardown);
    1504        1441 :     tcase_add_unchecked_fixture(tc, memtrack_unchecked_oom_setup, memtrack_unchecked_oom_teardown);
    1505        1441 :     suite_add_tcase(s, tc);
    1506             : #ifndef NDEBUG
    1507             :     tcase_add_loop_test(tc, getallocatedRAM_first, 0, 10);
    1508             :     tcase_add_loop_test(tc, getallocatedblocks_first, 0, 10);
    1509             :     tcase_add_loop_test(tc, getblocksize_first, 0, 10);
    1510             :     tcase_add_loop_test(tc, getblocksize_null, 0, 10);
    1511             :     tcase_add_loop_test(tc, getblocksize_missing, 0, 10);
    1512             :     tcase_add_loop_test(tc, addblock_null_first, 0, 10);
    1513             :     tcase_add_loop_test(tc, delblock_null_first, 0, 10);
    1514             :     tcase_add_loop_test(tc, addblock_null, 0, 10);
    1515             :     tcase_add_loop_test(tc, addblock_duplicate, 0, 10);
    1516             :     tcase_add_loop_test(tc, addblock_empty, 0, 10);
    1517             :     tcase_add_loop_test(tc, addblock_longstrings, 0, 10);
    1518             :     tcase_add_loop_test(tc, delblock_null, 0, 10);
    1519             :     tcase_add_loop_test(tc, delblock_missing, 0, 10);
    1520             :     tcase_add_loop_test(tc, addblock1_delblock1, 0, 10);
    1521             :     tcase_add_loop_test(tc, addblock12_delblock12, 0, 10);
    1522             :     tcase_add_loop_test(tc, addblock12_delblock21, 0, 10);
    1523             :     tcase_add_loop_test(tc, addblock123_delblock123, 0, 10);
    1524             :     tcase_add_loop_test(tc, addblock123_delblock2, 0, 10);
    1525             :     tcase_add_loop_test(tc, adddelblock_oom, 0, 10);
    1526             : #endif
    1527             : 
    1528        1441 :     tc = tcase_create("WithData-OOM");
    1529        1441 :     tcase_set_tags(tc,"oom");
    1530        1441 :     tcase_add_checked_fixture(tc, memtrack_checked_withdata_setup, memtrack_checked_common_teardown);
    1531        1441 :     tcase_add_unchecked_fixture(tc, memtrack_unchecked_oom_setup, memtrack_unchecked_oom_teardown);
    1532        1441 :     suite_add_tcase(s, tc);
    1533             : #ifndef NDEBUG
    1534             :     /* tcase_add_loop_test(tc, getallocatedRAM_first, 0, 10); */
    1535             :     /* tcase_add_loop_test(tc, getallocatedblocks_first, 0, 10); */
    1536             :     tcase_add_loop_test(tc, getblocksize_first, 0, 10);
    1537             :     tcase_add_loop_test(tc, getblocksize_null, 0, 10);
    1538             :     tcase_add_loop_test(tc, getblocksize_missing, 0, 10);
    1539             :     tcase_add_loop_test(tc, addblock_null_first, 0, 10);
    1540             :     tcase_add_loop_test(tc, delblock_null_first, 0, 10);
    1541             :     tcase_add_loop_test(tc, addblock_null, 0, 10);
    1542             :     tcase_add_loop_test(tc, addblock_duplicate, 0, 10);
    1543             :     tcase_add_loop_test(tc, addblock_empty, 0, 10);
    1544             :     tcase_add_loop_test(tc, addblock_longstrings, 0, 10);
    1545             :     tcase_add_loop_test(tc, delblock_null, 0, 10);
    1546             :     tcase_add_loop_test(tc, delblock_missing, 0, 10);
    1547             :     tcase_add_loop_test(tc, addblock1_delblock1, 0, 10);
    1548             :     tcase_add_loop_test(tc, addblock12_delblock12, 0, 10);
    1549             :     tcase_add_loop_test(tc, addblock12_delblock21, 0, 10);
    1550             :     tcase_add_loop_test(tc, addblock123_delblock123, 0, 10);
    1551             :     tcase_add_loop_test(tc, addblock123_delblock2, 0, 10);
    1552             :     tcase_add_loop_test(tc, adddelblock_oom, 0, 10);
    1553             : #endif
    1554             : 
    1555        1441 :     return s;
    1556             : }
    1557             : 

Generated by: LCOV version 1.16