LCOV - code coverage report
Current view: top level - test - suite_libdebug-memtrack.c (source / functions) Hit Total Coverage
Test: mkernel.info Lines: 675 676 99.9 %
Date: 2024-07-29 18:52:44 Functions: 27 27 100.0 %

          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 "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          33 : START_TEST(getallocatedRAM_first)
      36             : {
      37             :     unsigned int l_result;
      38             : 
      39          33 :     oomtest_fill(_i*sizeof(TMemBlock),2);
      40          33 :     l_result=memtrack_getallocatedRAM();
      41          33 :     oomtest_free();
      42             :     /* Always 0, except when initialized WithData */
      43             :     /* Uninitialized returns 0, Initialized returns 0, OOM uninitialized returns 0 */
      44          33 :     ck_assert(0==l_result);
      45          33 : }
      46             : END_TEST
      47             : #endif /* NDEBUG */
      48             : 
      49             : #ifndef NDEBUG
      50          33 : START_TEST(getallocatedblocks_first)
      51             : {
      52             :     unsigned int l_result;
      53          33 :     oomtest_fill(_i*sizeof(TMemBlock),2);
      54          33 :     l_result = memtrack_getallocatedblocks();
      55          33 :     oomtest_free();
      56             :     /* Always 0, except when initialized WithData */
      57             :     /* Uninitialized returns 0, Initialized returns 0, OOM uninitialized returns 0 */
      58          33 :     ck_assert(l_result==0);
      59          33 : }
      60             : END_TEST
      61             : #endif /* NDEBUG */
      62             : 
      63             : #ifndef NDEBUG
      64          66 : START_TEST(getblocksize_first)
      65             : {
      66             :     size_t l_result;
      67             : 
      68          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
      69          66 :     l_result = memtrack_getblocksize(NULL);
      70          66 :     oomtest_free();
      71             :     /* Always 0, because asking for "NULL" size */
      72          66 :     ck_assert(0==l_result);
      73          66 : }
      74             : END_TEST
      75             : #endif /* NDEBUG */
      76             : 
      77             : #ifndef NDEBUG
      78          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
      86          66 :     l_RAMSize=memtrack_getallocatedRAM();
      87          66 :     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          66 :     oomtest_fill(_i,2);
      92          66 :     l_BlockSize=memtrack_getblocksize(NULL);
      93          66 :     oomtest_free();
      94             : 
      95             :     /* Check expected results */
      96          66 :     ck_assert_msg(0==l_BlockSize,"Blocksize of NULL pointer should be 0");
      97             : 
      98             :     /* Check no new block registered */
      99          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     100          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     101          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     102          66 : }
     103             : END_TEST
     104             : #endif /* NDEBUG */
     105             : 
     106             : #ifndef NDEBUG
     107          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
     115          66 :     l_RAMSize=memtrack_getallocatedRAM();
     116          66 :     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          66 :     oomtest_fill(_i,2);
     120          66 :     l_BlockSize=memtrack_getblocksize((void*)999);
     121          66 :     oomtest_free();
     122             : 
     123             :     /* Check results */
     124          66 :     ck_assert_msg(0==l_BlockSize,"Blocksize of missing pointer should be 0");
     125             : 
     126             :     /* Check no new block registered */
     127          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     128          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     129          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     130          66 : }
     131             : END_TEST
     132             : #endif /* NDEBUG */
     133             : 
     134             : #ifndef NDEBUG
     135          66 : 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          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
     143          66 :     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          66 :     oomtest_free();
     153             : 
     154             :     /* Check results */
     155          66 :     ck_assert_msg(1==l_result,"Should not be able to register a NULL pointer");
     156          66 :     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          66 :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     159          66 : }
     160             : END_TEST
     161             : #endif
     162             : 
     163             : #ifndef NDEBUG
     164          66 : START_TEST(delblock_null_first)
     165             : {
     166             :     unsigned int l_result;
     167             : 
     168             :     /* Initialize memtrack and fail */
     169          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
     170          66 :     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          66 :     oomtest_free();
     179             : 
     180             :     /* Check results */
     181          66 :     ck_assert_msg(1==l_result,"Should not be able to unregister a NULL pointer");
     182          66 :     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          66 :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     185          66 : }
     186             : END_TEST
     187             : #endif
     188             : 
     189             : #ifndef NDEBUG
     190          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
     198          66 :     l_RAMSize=memtrack_getallocatedRAM();
     199          66 :     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          66 :     oomtest_fill(_i,2);
     204          66 :     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          66 :     oomtest_free();
     214             : 
     215             :     /* Check results */
     216          66 :     ck_assert_msg(1==result,"Should not be able to register a NULL pointer");
     217          66 :     ck_assert_msg(0==memtrack_getblocksize(NULL),"Blocksize of NULL pointer should be 0");
     218          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     219          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     220          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     221          66 : }
     222             : END_TEST
     223             : #endif
     224             : 
     225             : #ifndef NDEBUG
     226          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
     234          66 :     l_RAMSize=memtrack_getallocatedRAM();
     235          66 :     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          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
     240          66 :     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          66 :     oomtest_free();
     250          66 :     ck_assert((0==result)||(oomtest_enabled()));
     251          66 :     if (0!=result) {
     252             :         /* OOM occured, fix that */
     253          60 :         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          66 :     l_NbBlocks+=1;
     264          66 :     l_RAMSize+=10;
     265             : 
     266             :     /* Check results */
     267          66 :     ck_assert_msg(0==result,"Should able to register a pointer");
     268          66 :     ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of pointer should be 10");
     269          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     270          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     271          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     272             : 
     273             :     /* Add a duplicate, should fail */
     274          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
     275          66 :     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          66 :     oomtest_free();
     285             : 
     286             :     /* Check results */
     287          66 :     ck_assert_msg(1==result,"Should not be able to register a duplicate pointer");
     288          66 :     ck_assert_msg(10==memtrack_getblocksize((void*)999),"Duplicate pointer updated the size");
     289          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     290          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     291          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     292             : 
     293             :     /* Cleanup */
     294          66 :     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          66 :     ck_assert(0==result);
     303          66 : }
     304             : END_TEST
     305             : #endif
     306             : 
     307             : #ifndef NDEBUG
     308          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
     316          66 :     l_RAMSize=memtrack_getallocatedRAM();
     317          66 :     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          66 :     oomtest_fill(_i,2);
     322          66 :     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          66 :     oomtest_free();
     332             : 
     333             :     /* Check results */
     334          66 :     ck_assert_msg(1==result,"Should not be able to register a 0 sized pointer");
     335          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     336          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     337          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     338          66 :     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          66 :     oomtest_fill(_i,2);
     342          66 :     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          66 :     oomtest_free();
     352             : 
     353             :     /* Check results */
     354          66 :     ck_assert_msg(1==result,"Should not be able to register a pointer without filename");
     355          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     356          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     357          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     358          66 :     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          66 :     oomtest_fill(_i,2);
     362          66 :     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          66 :     oomtest_free();
     372             : 
     373             :     /* Check results */
     374          66 :     ck_assert_msg(1==result,"Should not be able to register a pointer à line number 0");
     375          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     376          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     377          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     378          66 :     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          66 :     oomtest_fill(_i,2);
     382          66 :     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          66 :     oomtest_free();
     392             : 
     393             :     /* Check results */
     394          66 :     ck_assert_msg(1==result,"Should not be able to register a pointer without a compilation date");
     395          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     396          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     397          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     398          66 :     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          66 :     oomtest_fill(_i,2);
     402          66 :     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          66 :     oomtest_free();
     412             : 
     413             :     /* Check results */
     414          66 :     ck_assert_msg(1==result,"Should not be able to register a pointer without a compilation time");
     415          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     416          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     417          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     418          66 :     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          66 :     oomtest_fill(_i,2);
     422          66 :     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          66 :     oomtest_free();
     432             : 
     433             :     /* Check results */
     434          66 :     ck_assert_msg(1==result,"Should not be able to register a pointer without a function name");
     435          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing block should be 0");
     436          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     437          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     438          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     439          66 : }
     440             : END_TEST
     441             : #endif /* NDEBUG */
     442             : 
     443             : #ifndef NDEBUG
     444          66 : 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          66 :     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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
     465          66 :     l_RAMSize=memtrack_getallocatedRAM();
     466          66 :     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          66 :     oomtest_fill(_i*(sizeof(TMemBlock)+sizeof(*szLongString)),2);
     470          66 :     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          66 :     oomtest_free();
     480             : 
     481             :     /* Check results */
     482          66 :     ck_assert((0==result)||(oomtest_enabled()));
     483          66 :     if (0==result) {
     484           6 :         l_NbBlocks+=1;
     485           6 :         l_RAMSize+=1;
     486           6 :         l_BlockSize=1;
     487             :     } else {
     488             :         /* result is false while oom testing : OOM occured */
     489          60 :         l_BlockSize = 0;
     490             :     }
     491          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     492          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     493          66 :     ck_assert_msg(l_BlockSize==memtrack_getblocksize((void*)999),"Blocksize inconsistency");
     494          66 :     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          66 :     oomtest_fill(_i*(sizeof(TMemBlock)+sizeof(*szLongString)),2);
     498          66 :     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          66 :     oomtest_free();
     508             : 
     509             :     /* Check results */
     510          66 :     ck_assert((0==result)||(oomtest_enabled()));
     511          66 :     if (0==result) {
     512           6 :         l_NbBlocks+=1;
     513           6 :         l_RAMSize+=2;
     514           6 :         l_BlockSize=2;
     515             :     } else {
     516             :         /* result is false while oom testing : OOM occured */
     517          60 :         l_BlockSize = 0;
     518             :     }
     519          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     520          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     521          66 :     ck_assert_msg(l_BlockSize==memtrack_getblocksize((void*)998),"Blocksize inconsistency");
     522          66 :     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          66 :     oomtest_fill(_i*(sizeof(TMemBlock)+sizeof(*szLongString)),2);
     526          66 :     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          66 :     oomtest_free();
     536             : 
     537             :     /* Check results */
     538          66 :     ck_assert((0==result)||(oomtest_enabled()));
     539          66 :     if (0==result) {
     540           6 :         l_NbBlocks+=1;
     541           6 :         l_RAMSize+=3;
     542           6 :         l_BlockSize=3;
     543             :     } else {
     544             :         /* result is false while oom testing : OOM occured */
     545          60 :         l_BlockSize = 0;
     546             :     }
     547          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     548          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     549          66 :     ck_assert_msg(l_BlockSize==memtrack_getblocksize((void*)997),"Blocksize inconsistency");
     550          66 :     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          66 :     oomtest_fill(_i*(sizeof(TMemBlock)+sizeof(*szLongString)),2);
     554          66 :     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          66 :     oomtest_free();
     564             : 
     565             :     /* Check results */
     566          66 :     ck_assert((0==result)||(oomtest_enabled()));
     567          66 :     if (0==result) {
     568           6 :         l_NbBlocks+=1;
     569           6 :         l_RAMSize+=4;
     570           6 :         l_BlockSize=4;
     571             :     } else {
     572             :         /* result is false while oom testing : OOM occured */
     573          60 :         l_BlockSize = 0;
     574             :     }
     575          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     576          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     577          66 :     ck_assert_msg(l_BlockSize==memtrack_getblocksize((void*)996),"Blocksize inconsistency");
     578          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     579          66 : }
     580             : END_TEST
     581             : #endif /* NDEBUG */
     582             : 
     583             : #ifndef NDEBUG
     584          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
     592          66 :     l_RAMSize=memtrack_getallocatedRAM();
     593          66 :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
     594             : 
     595             :     /* Run tests under constraint */
     596          66 :     oomtest_fill(_i,2);
     597          66 :     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          66 :     oomtest_free();
     606             : 
     607             :     /* Check results should always fail, oom or not */
     608          66 :     ck_assert_msg(1==result,"Should not be able to unregister a NULL pointer");
     609          66 :     ck_assert_msg(0==memtrack_getblocksize(NULL),"Blocksize of NULL pointer should be 0");
     610          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     611          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     612          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     613          66 : }
     614             : END_TEST
     615             : #endif /* NDEBUG */
     616             : 
     617             : #ifndef NDEBUG
     618          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
     626          66 :     l_RAMSize=memtrack_getallocatedRAM();
     627          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     628             : 
     629             :     /* Run tests under constraint */
     630          66 :     oomtest_fill(_i,2);
     631          66 :     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          66 :     oomtest_free();
     640             : 
     641             :     /* Check results should always fail, oom or not */
     642          66 :     ck_assert_msg(1==result,"Should not be able to unregister a missing pointer");
     643          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of missing pointer should be 0");
     644          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count changed");
     645          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM changed");
     646          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     647          66 : }
     648             : END_TEST
     649             : #endif /* NDEBUG */
     650             : 
     651             : #ifndef NDEBUG
     652          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
     660          66 :     l_RAMSize=memtrack_getallocatedRAM();
     661          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     662             : 
     663             :     /* Ensure that block does not already exist */
     664          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"The 999 block should not already exist");
     665             : 
     666          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
     667             :     /* Create a new block */
     668          66 :     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          66 :     oomtest_free();
     678             : 
     679             :     /* Intermediate check */
     680          66 :     ck_assert((0==result)||(oomtest_enabled()));
     681          66 :     if (0==result) {
     682             :         /* No OOM error, update the check counters */
     683           6 :         l_NbBlocks+=1;
     684           6 :         l_RAMSize+=10;
     685           6 :         ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of 999 block should be 10");
     686             :     } else {
     687          60 :         ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of 999 missing block should be 0");
     688             :     }
     689          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     690          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     691             : 
     692          66 :     oomtest_fill(_i,2);
     693             :     /* Delete the created block */
     694          66 :     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          66 :     oomtest_free();
     703             : 
     704             :     /* Check results */
     705          66 :     ck_assert((0==result)||(oomtest_enabled()));
     706          66 :     if (0==result) {
     707             :         /* No OOM error, update the check counters */
     708           6 :         l_NbBlocks-=1;
     709           6 :         l_RAMSize-=10;
     710             :     }
     711          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     712          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     713          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of deleted 999 block should be 0");
     714          66 : }
     715             : END_TEST
     716             : #endif /* NDEBUG */
     717             : 
     718             : #ifndef NDEBUG
     719          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
     727          66 :     l_RAMSize=memtrack_getallocatedRAM();
     728          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     729             : 
     730             :     /* Ensure that block does not already exist */
     731          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"The 999 block should not already exist");
     732             : 
     733          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
     734             :     /* Create a new block */
     735          66 :     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          66 :     oomtest_free();
     745             : 
     746             :     /* Intermediate check */
     747          66 :     ck_assert((0==result)||(oomtest_enabled()));
     748          66 :     if (0==result) {
     749             :         /* No OOM error, update the check counters */
     750           6 :         l_NbBlocks+=1;
     751           6 :         l_RAMSize+=10;
     752           6 :         ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of 999 block should be 10");
     753             :     } else {
     754          60 :         ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of 999 missing block should be 0");
     755             :     }
     756          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     757          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     758             : 
     759             :     /* Ensure that block does not already exist */
     760          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"The 998 block should not already exist");
     761             : 
     762          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
     763             :     /* Create a new block */
     764          66 :     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          66 :     oomtest_free();
     774             : 
     775             :     /* Intermediate check */
     776          66 :     ck_assert((0==result)||(oomtest_enabled()));
     777          66 :     if (0==result) {
     778             :         /* No OOM error, update the check counters */
     779           6 :         l_NbBlocks+=1;
     780           6 :         l_RAMSize+=20;
     781           6 :         ck_assert_msg(20==memtrack_getblocksize((void*)998),"Blocksize of 998 block should be 10");
     782             :     } else {
     783          60 :         ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of 998 missing block should be 0");
     784             :     }
     785          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     786          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     787             : 
     788          66 :     oomtest_fill(_i,2);
     789             :     /* Delete the created block */
     790          66 :     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          66 :     oomtest_free();
     799             : 
     800             :     /* Check results */
     801          66 :     ck_assert((0==result)||(oomtest_enabled()));
     802          66 :     if (0==result) {
     803             :         /* No OOM error, update the check counters */
     804           6 :         l_NbBlocks-=1;
     805           6 :         l_RAMSize-=10;
     806             :     }
     807          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     808          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     809          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of deleted 999 block should be 0");
     810             : 
     811          66 :     oomtest_fill(_i,2);
     812             :     /* Delete the created block */
     813          66 :     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          66 :     oomtest_free();
     822             : 
     823             :     /* Check results */
     824          66 :     ck_assert((0==result)||(oomtest_enabled()));
     825          66 :     if (0==result) {
     826             :         /* No OOM error, update the check counters */
     827           6 :         l_NbBlocks-=1;
     828           6 :         l_RAMSize-=20;
     829             :     }
     830          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     831          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     832          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of deleted 998 block should be 0");
     833          66 : }
     834             : END_TEST
     835             : #endif /* NDEBUG */
     836             : 
     837             : #ifndef NDEBUG
     838          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
     846          66 :     l_RAMSize=memtrack_getallocatedRAM();
     847          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     848             : 
     849             :     /* Ensure that block does not already exist */
     850          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"The 999 block should not already exist");
     851             : 
     852          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
     853             :     /* Create a new block */
     854          66 :     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          66 :     oomtest_free();
     864             : 
     865             :     /* Intermediate check */
     866          66 :     ck_assert((0==result)||(oomtest_enabled()));
     867          66 :     if (0==result) {
     868             :         /* No OOM error, update the check counters */
     869           6 :         l_NbBlocks+=1;
     870           6 :         l_RAMSize+=10;
     871           6 :         ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of 999 block should be 10");
     872             :     } else {
     873          60 :         ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of 999 missing block should be 0");
     874             :     }
     875          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     876          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     877             : 
     878             :     /* Ensure that block does not already exist */
     879          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"The 998 block should not already exist");
     880             : 
     881          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
     882             :     /* Create a new block */
     883          66 :     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          66 :     oomtest_free();
     893             : 
     894             :     /* Intermediate check */
     895          66 :     ck_assert((0==result)||(oomtest_enabled()));
     896          66 :     if (0==result) {
     897             :         /* No OOM error, update the check counters */
     898           6 :         l_NbBlocks+=1;
     899           6 :         l_RAMSize+=20;
     900           6 :         ck_assert_msg(20==memtrack_getblocksize((void*)998),"Blocksize of 998 block should be 10");
     901             :     } else {
     902          60 :         ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of 998 missing block should be 0");
     903             :     }
     904          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     905          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     906             : 
     907          66 :     oomtest_fill(_i,2);
     908             :     /* Delete the created block */
     909          66 :     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          66 :     oomtest_free();
     918             : 
     919             :     /* Check results */
     920          66 :     ck_assert((0==result)||(oomtest_enabled()));
     921          66 :     if (0==result) {
     922             :         /* No OOM error, update the check counters */
     923           6 :         l_NbBlocks-=1;
     924           6 :         l_RAMSize-=20;
     925             :     }
     926          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     927          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     928          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of deleted 998 block should be 0");
     929             : 
     930          66 :     oomtest_fill(_i,2);
     931             :     /* Delete the created block */
     932          66 :     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          66 :     oomtest_free();
     941             : 
     942             :     /* Check results */
     943          66 :     ck_assert((0==result)||(oomtest_enabled()));
     944          66 :     if (0==result) {
     945             :         /* No OOM error, update the check counters */
     946           6 :         l_NbBlocks-=1;
     947           6 :         l_RAMSize-=10;
     948             :     }
     949          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     950          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     951          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of deleted 999 block should be 0");
     952          66 : }
     953             : END_TEST
     954             : #endif /* NDEBUG */
     955             : 
     956             : #ifndef NDEBUG
     957          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
     965          66 :     l_RAMSize=memtrack_getallocatedRAM();
     966          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
     967             : 
     968             :     /* Ensure that block does not already exist */
     969          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"The 999 block should not already exist");
     970             : 
     971          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
     972             :     /* Create a new block */
     973          66 :     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          66 :     oomtest_free();
     983             : 
     984             :     /* Intermediate check */
     985          66 :     ck_assert((0==result)||(oomtest_enabled()));
     986          66 :     if (0==result) {
     987             :         /* No OOM error, update the check counters */
     988           6 :         l_NbBlocks+=1;
     989           6 :         l_RAMSize+=10;
     990           6 :         ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of 999 block should be 10");
     991             :     } else {
     992          60 :         ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of 999 missing block should be 0");
     993             :     }
     994          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
     995          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
     996             : 
     997             :     /* Ensure that block does not already exist */
     998          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"The 998 block should not already exist");
     999             : 
    1000          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
    1001             :     /* Create a new block */
    1002          66 :     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          66 :     oomtest_free();
    1012             : 
    1013             :     /* Intermediate check */
    1014          66 :     ck_assert((0==result)||(oomtest_enabled()));
    1015          66 :     if (0==result) {
    1016             :         /* No OOM error, update the check counters */
    1017           6 :         l_NbBlocks+=1;
    1018           6 :         l_RAMSize+=20;
    1019           6 :         ck_assert_msg(20==memtrack_getblocksize((void*)998),"Blocksize of 998 block should be 10");
    1020             :     } else {
    1021          60 :         ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of 998 missing block should be 0");
    1022             :     }
    1023          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1024          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1025             : 
    1026             :     /* Ensure that block does not already exist */
    1027          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)997),"The 997 block should not already exist");
    1028             : 
    1029          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
    1030             :     /* Create a new block */
    1031          66 :     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          66 :     oomtest_free();
    1041             : 
    1042             :     /* Intermediate check */
    1043          66 :     ck_assert((0==result)||(oomtest_enabled()));
    1044          66 :     if (0==result) {
    1045             :         /* No OOM error, update the check counters */
    1046           6 :         l_NbBlocks+=1;
    1047           6 :         l_RAMSize+=30;
    1048           6 :         ck_assert_msg(30==memtrack_getblocksize((void*)997),"Blocksize of 997 block should be 10");
    1049             :     } else {
    1050          60 :         ck_assert_msg(0==memtrack_getblocksize((void*)997),"Blocksize of 997 missing block should be 0");
    1051             :     }
    1052          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1053          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1054             : 
    1055          66 :     oomtest_fill(_i,2);
    1056             :     /* Delete the created block */
    1057          66 :     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          66 :     oomtest_free();
    1066             : 
    1067             :     /* Check results */
    1068          66 :     ck_assert((0==result)||(oomtest_enabled()));
    1069          66 :     if (0==result) {
    1070             :         /* No OOM error, update the check counters */
    1071           6 :         l_NbBlocks-=1;
    1072           6 :         l_RAMSize-=10;
    1073             :     }
    1074          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1075          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1076          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of deleted 999 block should be 0");
    1077             : 
    1078          66 :     oomtest_fill(_i,2);
    1079             :     /* Delete the created block */
    1080          66 :     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          66 :     oomtest_free();
    1089             : 
    1090             :     /* Check results */
    1091          66 :     ck_assert((0==result)||(oomtest_enabled()));
    1092          66 :     if (0==result) {
    1093             :         /* No OOM error, update the check counters */
    1094           6 :         l_NbBlocks-=1;
    1095           6 :         l_RAMSize-=20;
    1096             :     }
    1097          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1098          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1099          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of deleted 998 block should be 0");
    1100             : 
    1101          66 :     oomtest_fill(_i,2);
    1102             :     /* Delete the created block */
    1103          66 :     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          66 :     oomtest_free();
    1112             : 
    1113             :     /* Check results */
    1114          66 :     ck_assert((0==result)||(oomtest_enabled()));
    1115          66 :     if (0==result) {
    1116             :         /* No OOM error, update the check counters */
    1117           6 :         l_NbBlocks-=1;
    1118           6 :         l_RAMSize-=30;
    1119             :     }
    1120          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1121          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1122          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)997),"Blocksize of deleted 997 block should be 0");
    1123          66 : }
    1124             : END_TEST
    1125             : #endif /* NDEBUG */
    1126             : 
    1127             : #ifndef NDEBUG
    1128          66 : 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          66 :     l_NbBlocks=memtrack_getallocatedblocks();
    1136          66 :     l_RAMSize=memtrack_getallocatedRAM();
    1137          66 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
    1138             : 
    1139             :     /* Ensure that block does not already exist */
    1140          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)999),"The 999 block should not already exist");
    1141             : 
    1142          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
    1143             :     /* Create a new block */
    1144          66 :     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          66 :     oomtest_free();
    1154             : 
    1155             :     /* Intermediate check */
    1156          66 :     ck_assert((0==result)||(oomtest_enabled()));
    1157          66 :     if (0==result) {
    1158             :         /* No OOM error, update the check counters */
    1159           6 :         l_NbBlocks+=1;
    1160           6 :         l_RAMSize+=10;
    1161           6 :         ck_assert_msg(10==memtrack_getblocksize((void*)999),"Blocksize of 999 block should be 10");
    1162             :     } else {
    1163          60 :         ck_assert_msg(0==memtrack_getblocksize((void*)999),"Blocksize of 999 missing block should be 0");
    1164             :     }
    1165          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1166          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1167             : 
    1168             :     /* Ensure that block does not already exist */
    1169          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"The 998 block should not already exist");
    1170             : 
    1171          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
    1172             :     /* Create a new block */
    1173          66 :     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          66 :     oomtest_free();
    1183             : 
    1184             :     /* Intermediate check */
    1185          66 :     ck_assert((0==result)||(oomtest_enabled()));
    1186          66 :     if (0==result) {
    1187             :         /* No OOM error, update the check counters */
    1188           6 :         l_NbBlocks+=1;
    1189           6 :         l_RAMSize+=20;
    1190           6 :         ck_assert_msg(20==memtrack_getblocksize((void*)998),"Blocksize of 998 block should be 10");
    1191             :     } else {
    1192          60 :         ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of 998 missing block should be 0");
    1193             :     }
    1194          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1195          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1196             : 
    1197             :     /* Ensure that block does not already exist */
    1198          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)997),"The 997 block should not already exist");
    1199             : 
    1200          66 :     oomtest_fill(_i*sizeof(TMemBlock),2);
    1201             :     /* Create a new block */
    1202          66 :     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          66 :     oomtest_free();
    1212             : 
    1213             :     /* Intermediate check */
    1214          66 :     ck_assert((0==result)||(oomtest_enabled()));
    1215          66 :     if (0==result) {
    1216             :         /* No OOM error, update the check counters */
    1217           6 :         l_NbBlocks+=1;
    1218           6 :         l_RAMSize+=30;
    1219           6 :         ck_assert_msg(30==memtrack_getblocksize((void*)997),"Blocksize of 997 block should be 10");
    1220             :     } else {
    1221          60 :         ck_assert_msg(0==memtrack_getblocksize((void*)997),"Blocksize of 997 missing block should be 0");
    1222             :     }
    1223          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1224          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1225             : 
    1226          66 :     oomtest_fill(_i,2);
    1227             :     /* Delete the created block */
    1228          66 :     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          66 :     oomtest_free();
    1237             : 
    1238             :     /* Check results */
    1239          66 :     ck_assert((0==result)||(oomtest_enabled()));
    1240          66 :     if (0==result) {
    1241             :         /* No OOM error, update the check counters */
    1242           6 :         l_NbBlocks-=1;
    1243           6 :         l_RAMSize-=20;
    1244             :     }
    1245          66 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1246          66 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1247          66 :     ck_assert_msg(0==memtrack_getblocksize((void*)998),"Blocksize of deleted 998 block should be 0");
    1248          66 : }
    1249             : END_TEST
    1250             : #endif /* NDEBUG */
    1251             : 
    1252             : #ifndef NDEBUG
    1253          60 : START_TEST(adddelblock_oom)
    1254             : {
    1255             :     uint64_t l_NbBlocks;
    1256             :     size_t l_RAMSize;
    1257          60 :     long unsigned int i=0;
    1258          60 :     uint16_t oomtestvalues[65536] = {0};
    1259          60 :     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          60 :     l_NbBlocks=memtrack_getallocatedblocks();
    1274          60 :     l_RAMSize=memtrack_getallocatedRAM();
    1275          60 :     ck_assert_msg(l_NbBlocks==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks mismatch");
    1276             : 
    1277             :     /* Try to trigger OOM inside the tested feature */
    1278          60 :     i = 0;
    1279          60 :     oomtest_fill(_i*(sizeof(TMemBlock)+4*(26+10+26)*10),2);
    1280             :     do {
    1281         283 :         i++;
    1282         566 :         oomtestvalues[i] = memtrack_addblock(
    1283         283 :                                (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         283 :     } while ((i<65535)&&(0==oomtestvalues[i]));
    1292          60 :     oomtest_free();
    1293             : 
    1294             :     /* Intermediate check */
    1295          60 :     l_NbBlocks+=i-1;
    1296          60 :     l_RAMSize+=(i-1)*10;
    1297             :     /* Should have returned NULL (OOM) before reaching 65535 */
    1298          60 :     ck_assert_msg(65535!=i,"Did not manage to trigger OOM");
    1299          60 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1300          60 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1301             : 
    1302             :     /* We will loose i value, precalculate values */
    1303          60 :     l_NbBlocks-=i-1;
    1304          60 :     l_RAMSize-=(i-1)*10;
    1305             : 
    1306          60 :     oomtest_fill(_i,2);
    1307             :     /* Free all the allocated memory */
    1308          60 :     i = 1;
    1309         283 :     while ((i<65535)&&(0==oomtestvalues[i])) {
    1310         223 :         if(0!=(oomtestvalues[i]=memtrack_delblock(
    1311         223 :                                     (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           0 :             break;
    1319         223 :         i++;
    1320             :     }
    1321          60 :     oomtest_free();
    1322             : 
    1323          60 :     ck_assert_msg(65535!=i,"Did not manage to free all allocated RAM");
    1324          60 :     ck_assert(1==oomtestvalues[i]);
    1325          60 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"Block count inconsistency");
    1326          60 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"Allocated RAM inconsistency");
    1327          60 : }
    1328             : END_TEST
    1329             : #endif /* NDEBUG */
    1330             : 
    1331             : /************************************************************************/
    1332         624 : void memtrack_checked_uninitialized_setup()
    1333             : {
    1334         624 :     signals_catch();
    1335         624 :     forktest_gprofdir();
    1336         624 : }
    1337         558 : void memtrack_checked_withdata_setup()
    1338             : {
    1339         558 :     signals_catch();
    1340         558 :     forktest_gprofdir();
    1341             : #ifndef NDEBUG
    1342             :     uint64_t l_NbBlocks;
    1343             :     uint64_t l_RAMSize;
    1344             : 
    1345         558 :     l_NbBlocks=memtrack_getallocatedblocks();
    1346         558 :     l_RAMSize=memtrack_getallocatedRAM();
    1347         558 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1348         558 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1349         558 :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1350         558 :     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         558 :     ck_assert_msg(10==memtrack_getblocksize((void*)1),"Invalid getblocksize");
    1360         558 :     ck_assert_msg( 0==memtrack_getblocksize((void*)2),"Invalid getblocksize");
    1361         558 :     ck_assert_msg( 0==memtrack_getblocksize((void*)3),"Invalid getblocksize");
    1362         558 :     l_NbBlocks += 1;
    1363         558 :     l_RAMSize += 10;
    1364         558 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1365         558 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1366         558 :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1367         558 :     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         558 :     ck_assert_msg(10==memtrack_getblocksize((void*)1),"Invalid getblocksize");
    1377         558 :     ck_assert_msg(20==memtrack_getblocksize((void*)2),"Invalid getblocksize");
    1378         558 :     ck_assert_msg( 0==memtrack_getblocksize((void*)3),"Invalid getblocksize");
    1379         558 :     l_NbBlocks += 1;
    1380         558 :     l_RAMSize += 20;
    1381         558 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1382         558 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1383         558 :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1384         558 :     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         558 :     ck_assert_msg(10==memtrack_getblocksize((void*)1),"Invalid getblocksize");
    1394         558 :     ck_assert_msg(20==memtrack_getblocksize((void*)2),"Invalid getblocksize");
    1395         558 :     ck_assert_msg(30==memtrack_getblocksize((void*)3),"Invalid getblocksize");
    1396         558 :     l_NbBlocks += 1;
    1397         558 :     l_RAMSize += 30;
    1398         558 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1399         558 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1400         558 :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1401             : #endif /* NDEBUG */
    1402         558 : }
    1403        1182 : void memtrack_checked_common_teardown()
    1404             : {
    1405        1182 :     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        1182 :     l_NbBlocks=memtrack_getallocatedblocks();
    1411        1182 :     l_RAMSize=memtrack_getallocatedRAM();
    1412        1182 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1413        1182 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1414        1182 :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1415        1182 :     memtrack_reset();
    1416        1182 :     memtrack_reset(); /* Test the double run protection */
    1417        1182 :     l_NbBlocks = 0;
    1418        1182 :     l_RAMSize = 0;
    1419        1182 :     ck_assert_msg(l_NbBlocks==memtrack_getallocatedblocks(),"getallocatedblocks does not match counter");
    1420        1182 :     ck_assert_msg(l_RAMSize==memtrack_getallocatedRAM(),"getallocatedRAM does not match the counter");
    1421        1182 :     ck_assert_msg(memtrack_getallocatedblocks()==memtrack_dumpblocks(),"Internal NbBlocks counter and dumpblocks count differs");
    1422             : #endif /* NDEBUG */
    1423        1182 : }
    1424             : /************************************************************************/
    1425       15068 : void memtrack_unchecked_common_setup()
    1426             : {
    1427       15068 :     forktest_init();
    1428       15068 : }
    1429       14280 : void memtrack_unchecked_common_teardown()
    1430             : {
    1431       14280 : }
    1432        7294 : void memtrack_unchecked_oom_setup()
    1433             : {
    1434        7294 :     oomtest_enable(RAMLIMIT_SOFT);
    1435        7294 :     memtrack_unchecked_common_setup();
    1436        7294 : }
    1437        6574 : void memtrack_unchecked_oom_teardown()
    1438             : {
    1439        6574 :     oomtest_disable();
    1440        6574 :     memtrack_unchecked_common_teardown();
    1441        6574 : }
    1442             : /************************************************************************/
    1443        3909 : Suite* libdebug_memtrack_suite()
    1444             : {
    1445             :     Suite *s;
    1446             :     TCase *tc;
    1447             : 
    1448        3909 :     s = suite_create("LibDebug-MemTrack");
    1449        3909 :     tc = tcase_create("Uninitialized");
    1450        3909 :     tcase_add_checked_fixture(tc, memtrack_checked_uninitialized_setup, memtrack_checked_common_teardown);
    1451        3909 :     tcase_add_unchecked_fixture(tc, memtrack_unchecked_common_setup, memtrack_unchecked_common_teardown);
    1452        3909 :     suite_add_tcase(s, tc);
    1453             : #ifndef NDEBUG
    1454        3909 :     tcase_add_test(tc, getallocatedRAM_first);
    1455        3909 :     tcase_add_test(tc, getallocatedblocks_first);
    1456        3909 :     tcase_add_test(tc, getblocksize_first);
    1457        3909 :     tcase_add_test(tc, getblocksize_null);
    1458        3909 :     tcase_add_test(tc, getblocksize_missing);
    1459        3909 :     tcase_add_test(tc, addblock_null_first);
    1460        3909 :     tcase_add_test(tc, delblock_null_first);
    1461        3909 :     tcase_add_test(tc, addblock_null);
    1462        3909 :     tcase_add_test(tc, addblock_duplicate);
    1463        3909 :     tcase_add_test(tc, addblock_empty);
    1464        3909 :     tcase_add_test(tc, addblock_longstrings);
    1465        3909 :     tcase_add_test(tc, delblock_null);
    1466        3909 :     tcase_add_test(tc, delblock_missing);
    1467        3909 :     tcase_add_test(tc, addblock1_delblock1);
    1468        3909 :     tcase_add_test(tc, addblock12_delblock12);
    1469        3909 :     tcase_add_test(tc, addblock12_delblock21);
    1470        3909 :     tcase_add_test(tc, addblock123_delblock123);
    1471        3909 :     tcase_add_test(tc, addblock123_delblock2);
    1472             :     /* tcase_add_test(tc, adddelblock_oom); */
    1473             : #endif
    1474             : 
    1475        3909 :     tc = tcase_create("WithData");
    1476        3909 :     tcase_add_checked_fixture(tc, memtrack_checked_withdata_setup, memtrack_checked_common_teardown);
    1477        3909 :     tcase_add_unchecked_fixture(tc, memtrack_unchecked_common_setup, memtrack_unchecked_common_teardown);
    1478        3909 :     suite_add_tcase(s, tc);
    1479             : #ifndef NDEBUG
    1480             :     /* tcase_add_test(tc, getallocatedRAM_first); */
    1481             :     /* tcase_add_test(tc, getallocatedblocks_first); */
    1482        3909 :     tcase_add_test(tc, getblocksize_first);
    1483        3909 :     tcase_add_test(tc, getblocksize_null);
    1484        3909 :     tcase_add_test(tc, getblocksize_missing);
    1485        3909 :     tcase_add_test(tc, addblock_null_first);
    1486        3909 :     tcase_add_test(tc, delblock_null_first);
    1487        3909 :     tcase_add_test(tc, addblock_null);
    1488        3909 :     tcase_add_test(tc, addblock_duplicate);
    1489        3909 :     tcase_add_test(tc, addblock_empty);
    1490        3909 :     tcase_add_test(tc, addblock_longstrings);
    1491        3909 :     tcase_add_test(tc, delblock_null);
    1492        3909 :     tcase_add_test(tc, delblock_missing);
    1493        3909 :     tcase_add_test(tc, addblock1_delblock1);
    1494        3909 :     tcase_add_test(tc, addblock12_delblock12);
    1495        3909 :     tcase_add_test(tc, addblock12_delblock21);
    1496        3909 :     tcase_add_test(tc, addblock123_delblock123);
    1497        3909 :     tcase_add_test(tc, addblock123_delblock2);
    1498             :     /* tcase_add_test(tc, adddelblock_oom); */
    1499             : #endif
    1500             : 
    1501        3909 :     tc = tcase_create("Uninitialized-OOM");
    1502        3909 :     tcase_set_tags(tc,"oom");
    1503        3909 :     tcase_add_checked_fixture(tc, memtrack_checked_uninitialized_setup, memtrack_checked_common_teardown);
    1504        3909 :     tcase_add_unchecked_fixture(tc, memtrack_unchecked_oom_setup, memtrack_unchecked_oom_teardown);
    1505        3909 :     suite_add_tcase(s, tc);
    1506             : #ifndef NDEBUG
    1507        3909 :     tcase_add_loop_test(tc, getallocatedRAM_first, 0, 10);
    1508        3909 :     tcase_add_loop_test(tc, getallocatedblocks_first, 0, 10);
    1509        3909 :     tcase_add_loop_test(tc, getblocksize_first, 0, 10);
    1510        3909 :     tcase_add_loop_test(tc, getblocksize_null, 0, 10);
    1511        3909 :     tcase_add_loop_test(tc, getblocksize_missing, 0, 10);
    1512        3909 :     tcase_add_loop_test(tc, addblock_null_first, 0, 10);
    1513        3909 :     tcase_add_loop_test(tc, delblock_null_first, 0, 10);
    1514        3909 :     tcase_add_loop_test(tc, addblock_null, 0, 10);
    1515        3909 :     tcase_add_loop_test(tc, addblock_duplicate, 0, 10);
    1516        3909 :     tcase_add_loop_test(tc, addblock_empty, 0, 10);
    1517        3909 :     tcase_add_loop_test(tc, addblock_longstrings, 0, 10);
    1518        3909 :     tcase_add_loop_test(tc, delblock_null, 0, 10);
    1519        3909 :     tcase_add_loop_test(tc, delblock_missing, 0, 10);
    1520        3909 :     tcase_add_loop_test(tc, addblock1_delblock1, 0, 10);
    1521        3909 :     tcase_add_loop_test(tc, addblock12_delblock12, 0, 10);
    1522        3909 :     tcase_add_loop_test(tc, addblock12_delblock21, 0, 10);
    1523        3909 :     tcase_add_loop_test(tc, addblock123_delblock123, 0, 10);
    1524        3909 :     tcase_add_loop_test(tc, addblock123_delblock2, 0, 10);
    1525        3909 :     tcase_add_loop_test(tc, adddelblock_oom, 0, 10);
    1526             : #endif
    1527             : 
    1528        3909 :     tc = tcase_create("WithData-OOM");
    1529        3909 :     tcase_set_tags(tc,"oom");
    1530        3909 :     tcase_add_checked_fixture(tc, memtrack_checked_withdata_setup, memtrack_checked_common_teardown);
    1531        3909 :     tcase_add_unchecked_fixture(tc, memtrack_unchecked_oom_setup, memtrack_unchecked_oom_teardown);
    1532        3909 :     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        3909 :     tcase_add_loop_test(tc, getblocksize_first, 0, 10);
    1537        3909 :     tcase_add_loop_test(tc, getblocksize_null, 0, 10);
    1538        3909 :     tcase_add_loop_test(tc, getblocksize_missing, 0, 10);
    1539        3909 :     tcase_add_loop_test(tc, addblock_null_first, 0, 10);
    1540        3909 :     tcase_add_loop_test(tc, delblock_null_first, 0, 10);
    1541        3909 :     tcase_add_loop_test(tc, addblock_null, 0, 10);
    1542        3909 :     tcase_add_loop_test(tc, addblock_duplicate, 0, 10);
    1543        3909 :     tcase_add_loop_test(tc, addblock_empty, 0, 10);
    1544        3909 :     tcase_add_loop_test(tc, addblock_longstrings, 0, 10);
    1545        3909 :     tcase_add_loop_test(tc, delblock_null, 0, 10);
    1546        3909 :     tcase_add_loop_test(tc, delblock_missing, 0, 10);
    1547        3909 :     tcase_add_loop_test(tc, addblock1_delblock1, 0, 10);
    1548        3909 :     tcase_add_loop_test(tc, addblock12_delblock12, 0, 10);
    1549        3909 :     tcase_add_loop_test(tc, addblock12_delblock21, 0, 10);
    1550        3909 :     tcase_add_loop_test(tc, addblock123_delblock123, 0, 10);
    1551        3909 :     tcase_add_loop_test(tc, addblock123_delblock2, 0, 10);
    1552        3909 :     tcase_add_loop_test(tc, adddelblock_oom, 0, 10);
    1553             : #endif
    1554             : 
    1555        3909 :     return s;
    1556             : }
    1557             : 

Generated by: LCOV version 1.16