Ignore:
Timestamp:
Jul 8, 2008, 11:16:14 AM (16 years ago)
Author:
katerina
Message:

Include dnmalloc (ticket #108) and fix bugs #106 (EINPROGRESS) and #107 (compressBound).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cutest_sh_unix.c

    r30 r171  
    77#include "sh_unix.h"
    88
     9int malloc_count = 0;
     10
     11void Test_dnmalloc (CuTest *tc) {
     12
     13  const int nalloc = 64 /* original dnmalloc 1.0-beta5 fails fo >= 45 */;
     14  int j, i;
     15  int sum;
     16  int i_malloc =  malloc_count;
     17
     18  char * buf;
     19  char * area[256];
     20
     21  /* test reuse of last freed chunk */
     22  buf = malloc(1024);
     23  CuAssertPtrNotNull(tc, buf);
     24  free(buf);
     25  area[0] = malloc(1024);
     26  CuAssertTrue(tc, buf == area[0]);
     27  free(area[0]);
     28
     29  /* test realloc */
     30  buf = malloc(16);
     31  CuAssertPtrNotNull(tc, buf);
     32  strcpy(buf, "testing realloc");
     33  buf = realloc(buf, 32);
     34  strcat(buf, "testing realloc");
     35  CuAssertStrEquals(tc, "testing realloctesting realloc", buf);
     36
     37  i_malloc = malloc_count;
     38
     39  for (j = 0; j < 64; ++j)
     40    {
     41      buf = malloc((j+1) * 1024);
     42      CuAssertPtrNotNull(tc, buf);
     43#ifndef USE_SYSTEM_MALLOC
     44      CuAssertIntEquals (tc, malloc_count, (i_malloc + 1));
     45#endif
     46      free(buf);
     47#ifndef USE_SYSTEM_MALLOC
     48      CuAssertIntEquals (tc, malloc_count, i_malloc);
     49#endif
     50    }
     51
     52  /* test realloc */
     53  buf = malloc(16);
     54  CuAssertPtrNotNull(tc, buf);
     55  strcpy(buf, "testing realloc");
     56  buf = realloc(buf, 32);
     57  strcat(buf, "testing realloc");
     58  CuAssertStrEquals(tc, "testing realloctesting realloc", buf);
     59
     60  i_malloc = malloc_count;
     61
     62  for (j = 0; j < 64; ++j)
     63    {
     64      buf = calloc(1, (j+1) * 1024);
     65      CuAssertPtrNotNull(tc, buf);
     66#ifndef USE_SYSTEM_MALLOC
     67      CuAssertIntEquals (tc, malloc_count, (i_malloc + 1));
     68#endif
     69      sum = 0;
     70      for (i = 0; i < ((j+1) * 1024); ++i)
     71        sum += buf[i];
     72      CuAssertIntEquals (tc, 0, sum);
     73      free(buf);
     74#ifndef USE_SYSTEM_MALLOC
     75      CuAssertIntEquals (tc, malloc_count, i_malloc);
     76#endif
     77    }
     78
     79  /* test realloc */
     80  buf = malloc(16);
     81  CuAssertPtrNotNull(tc, buf);
     82  strcpy(buf, "testing realloc");
     83  buf = realloc(buf, 32);
     84  strcat(buf, "testing realloc");
     85  CuAssertStrEquals(tc, "testing realloctesting realloc", buf);
     86
     87  for (j = 0; j < nalloc; ++j)
     88    {
     89      area[j] = malloc((j+1) * 1024);
     90      CuAssertPtrNotNull(tc, area[j]);
     91#ifndef USE_SYSTEM_MALLOC
     92      // CuAssertIntEquals (tc, malloc_count, (i_malloc + (j+1)));
     93#endif
     94      memset(area[j], (unsigned char) ('a'+1), (j+1) * 1024);
     95    }
     96
     97  i_malloc =  malloc_count;
     98
     99  for (j = 0; j < nalloc; ++j)
     100    {
     101      sum = 0;
     102      for (i = 0; i < ((j+1) * 1024); ++i)
     103        sum +=  area[j][i];
     104      CuAssertIntEquals (tc, sum, ((j+1) * 1024 * ((unsigned char) ('a'+1))));
     105      free(area[j]);
     106#ifndef USE_SYSTEM_MALLOC
     107      CuAssertIntEquals (tc, malloc_count, i_malloc - (j+1));
     108#endif
     109    }
     110
     111  /* test realloc */
     112  buf = malloc(16);
     113  CuAssertPtrNotNull(tc, buf);
     114  strcpy(buf, "testing realloc");
     115  buf = realloc(buf, 32);
     116  strcat(buf, "testing realloc");
     117  CuAssertStrEquals(tc, "testing realloctesting realloc", buf);
     118
     119
     120  for (j = 0; j < 32; ++j)
     121    {
     122      i_malloc =  malloc_count;
     123      buf = malloc((j+1) * 1024 * 1024);
     124      CuAssertPtrNotNull(tc, buf);
     125      for (i = 0; i < 32; ++i)
     126        {
     127          area[i] = malloc((i+1) * 1024);
     128          CuAssertPtrNotNull(tc, area[i]);
     129        }
     130      free(buf);
     131      for (i = 0; i < 32; ++i)
     132        {
     133          free(area[i]);
     134        }
     135#ifndef USE_SYSTEM_MALLOC
     136      CuAssertIntEquals (tc, malloc_count, i_malloc);
     137#endif
     138    }
     139
     140  /* test realloc */
     141  buf = malloc(16);
     142  CuAssertPtrNotNull(tc, buf);
     143  strcpy(buf, "testing realloc");
     144  buf = realloc(buf, 32);
     145  strcat(buf, "testing realloc");
     146  CuAssertStrEquals(tc, "testing realloctesting realloc", buf);
     147}
     148
     149 
    9150void Test_sh_unix_lookup_page (CuTest *tc) {
    10151
Note: See TracChangeset for help on using the changeset viewer.