00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef DBG_QM_MALLOC
00023
00024 #include <stdio.h>
00025 #include <string.h>
00026 #include <stdlib.h>
00027
00028
00029 #include "../globals.h"
00030 #include "../config.h"
00031
00032 #if 0
00033 #ifdef PKG_MALLOC
00034 # include "q_malloc.h"
00035 # define MY_MALLOC qm_malloc
00036 # define MY_FREE qm_free
00037 # define MY_INIT qm_malloc_init
00038 # define MY_BLOCK qm_block
00039 # define MY_STATUS qm_status
00040 #endif
00041
00042 void memtest()
00043 {
00044 #define TEST_SIZE 1024*1024
00045 #define TEST_RUN 1024
00046 #define LONG_RUN 100000
00047 #define ma(s) MY_MALLOC(mem_block, (s),__FILE__, __FUNCTION__, \
00048 __LINE__);
00049 #define mf(p) MY_FREE(mem_block, (p), __FILE__, __FUNCTION__, \
00050 __LINE__);
00051 char tst_mem[TEST_SIZE];
00052 struct MY_BLOCK* mem_block;
00053 char *p0,*p1,*p2,*p3,*p4,*p5,*p6;
00054 int i, j, f;
00055 char *p[TEST_RUN];
00056 int t;
00057
00058 debug=7;
00059 log_stderr=1;
00060
00061 printf("entering test\n");
00062
00063 mem_block=MY_INIT( tst_mem, TEST_SIZE );
00064
00065
00066 p0=ma(8194);
00067 p1=ma(8194);
00068 p2=ma(8194);
00069 MY_STATUS(mem_block);
00070 mf(p1);
00071 mf(p0);
00072 MY_STATUS(mem_block);
00073 mf(p2);
00074 MY_STATUS(mem_block);
00075
00076
00077 p0=ma(8194);
00078 p1=ma(4196);
00079 mf(p0);
00080 p0=ma(8190);
00081 MY_STATUS(mem_block);
00082 mf(p1);
00083 mf(p0);
00084 MY_STATUS(mem_block);
00085
00086
00087 exit(0);
00088
00089 p0=ma(8);
00090 p1=ma(24);
00091 p2=ma(32);
00092 p3=ma(32);
00093 p4=ma(32);
00094 p5=ma(1024);
00095 p6=ma(2048);
00096
00097
00098
00099
00100 mf(p0);
00101 mf(p2);
00102 mf(p5);
00103 mf(p6);
00104
00105
00106
00107 mf(p1);
00108 mf(p4);
00109 mf(p3);
00110
00111
00112
00113
00114 for (i=0;i<TEST_RUN;i++)
00115 p[i]=ma( random() & 1023 );
00116
00117 for (i=0;i<TEST_RUN;i++)
00118 mf( p[i] );
00119
00120
00121 f = 0;
00122 #define GRANULARITY 100
00123 for (j=0; j<LONG_RUN; j++) {
00124 for (i=0;i<TEST_RUN;i++) {
00125 t=random() & 1023;
00126 if (! (t%24) ) t=(t+4096)*2;
00127 p[i]=ma( random() & 1023 );
00128 }
00129 for (i=TEST_RUN/3;i<2*TEST_RUN/3;i++)
00130 mf( p[i] );
00131 for (i=TEST_RUN/3;i<2*TEST_RUN/3;i++) {
00132 t=random() & 1023;
00133 if (! (t%24) ) t=(t+4096)*2;
00134 p[i]=ma( random() & 1023 );
00135 }
00136 for (i=0;i<TEST_RUN;i++)
00137 mf( p[i] );
00138 if ( GRANULARITY*j/LONG_RUN > f ) {
00139 f=GRANULARITY*j/LONG_RUN ;
00140 printf("%d%% done\n", f);
00141 }
00142 }
00143 printf("now I'm really done\n");
00144 MY_STATUS(mem_block);
00145 printf("And I'm done with dumping final report too\n");
00146
00147 exit(0);
00148 }
00149 #endif
00150
00151
00152 #endif