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