source: trunk/src/win32k/misc/heaptest.c@ 2502

Last change on this file since 2502 was 2501, checked in by bird, 26 years ago

Temporary backup checkin.

File size: 5.5 KB
Line 
1/* $Id: heaptest.c,v 1.1 2000-01-22 18:21:03 bird Exp $
2 *
3 * Test of resident and swappable heaps.
4 *
5 *
6 * Copyright (c) 2000 knut st. osmundsen
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12/******************************************************************************
13* Defined Constants
14*******************************************************************************/
15#define NUMBER_OF_POINTERS 10240
16#define RANDOMTEST_ITERATIONS 10240
17
18
19/*******************************************************************************
20* Internal Functions
21*******************************************************************************/
22#include "malloc.h"
23#include "rmalloc.h"
24#include <stdio.h>
25#include <stdlib.h>
26
27
28
29
30int main(int argc, char *argv)
31{
32 static void * apv[NUMBER_OF_POINTERS];
33 static int acb[NUMBER_OF_POINTERS];
34 unsigned cAllocations;
35 unsigned cb = 0;
36 unsigned crmalloc;
37 unsigned crfree;
38
39 int i;
40
41 /*
42 * Initiate the heap.
43 */
44 if (ResHeapInit(128*1024, 1024*1024*64) != 0)
45 {
46 printf("Failed to initiate the resident heap.\n");
47 return 1;
48 }
49
50/*
51 *
52 * resident heap tests
53 * resident heap tests
54 *
55 */
56 /*
57 * Simple allocation test.
58 */
59 for (i = 0; i < NUMBER_OF_POINTERS; i++)
60 {
61 do
62 {
63 acb[i] = rand();
64 } while(acb[i] == 0 || acb[i] > 64);
65
66 apv[i] = rmalloc(acb[i]);
67 if (apv[i] == NULL)
68 {
69 printf("rmalloc failed: acb[%d]=%d\n", i, acb[i]);
70 if (acb[i] > 1000)
71 break;
72 }
73 cb += acb[i];
74 }
75
76 printf("Finished allocating memory: %d allocations %d bytes\n", i, cb);
77
78
79 printf("_res_dump_subheaps:\n");
80 _res_dump_subheaps();
81
82 for (i = 0; i < NUMBER_OF_POINTERS; i++)
83 {
84 int cb = _res_msize(apv[i]);
85 if (cb != ((acb[i] + 3) & ~3) && (cb < ((acb[i] + 3) & ~3) || cb > 40 + ((acb[i] + 3) & ~3)) )
86 printf("size of avp[%d] (%d) != acb[%] (%d)\n", i, cb, i, acb[i]);
87 rfree(apv[i]);
88 }
89
90
91 /*
92 * test _res_heapmin
93 */
94 printf("_res_memfree - before heapmin: %d\n", _res_memfree());
95 _res_heapmin();
96 printf("_res_memfree - after heapmin : %d\n", _res_memfree());
97
98 /*
99 * Test _res_dump_subheaps
100 */
101 printf("\n_res_dump_subheaps:\n");
102 _res_dump_subheaps();
103
104
105 /*
106 * Test 2 - random allocation and freeing of memory.
107 */
108 printf("\n"
109 "Random allocation and freeing test:\n");
110 for (i = 0; i < NUMBER_OF_POINTERS; i++)
111 apv[i] = NULL, acb[i] = 0;
112 cAllocations = 0;
113 i = 0;
114 cb = 0;
115 crfree = 0;
116 crmalloc = 0;
117 while (i++ < RANDOMTEST_ITERATIONS || cAllocations > 0)
118 {
119 int j;
120 j = rand();
121 if (cAllocations + (NUMBER_OF_POINTERS/20) < NUMBER_OF_POINTERS &&
122 (i < RANDOMTEST_ITERATIONS*1/4 ? (j % 8) > 1 :
123 i < RANDOMTEST_ITERATIONS*2/4 ? (j % 8) > 2 :
124 i < RANDOMTEST_ITERATIONS*3/4 ? (j % 8) > 3 :
125 i < RANDOMTEST_ITERATIONS ? (j % 8) > 5 : 0
126 )
127 )
128 { /* malloc */
129 for (j = 0; j < NUMBER_OF_POINTERS && apv[j] != NULL; j++)
130 (void)0;
131 if (j < NUMBER_OF_POINTERS)
132 {
133 do
134 {
135 acb[j] = rand();
136 } while (acb[j] == 0 || acb[j] > 2048);
137 apv[j] = rmalloc(acb[j]);
138 if (apv[j] == NULL)
139 {
140 printf("rmalloc failed, acb[%d] = %d\n", j, acb[j]);
141 if (acb[j] > 10000)
142 continue;
143 }
144 cAllocations++;
145 cb += acb[j];
146 crmalloc++;
147 }
148 }
149 else
150 { /* free */
151 if (cAllocations == 0)
152 continue;
153 if (cAllocations < NUMBER_OF_POINTERS/10)
154 {
155 for (j = 0; j < NUMBER_OF_POINTERS && apv[j] == NULL; j++)
156 (void)0;
157 }
158 else
159 {
160 int k = 0;
161 do
162 {
163 j = rand();
164 } while (k < NUMBER_OF_POINTERS/2 && (j >= NUMBER_OF_POINTERS || apv[j] == NULL));
165 if (k >= NUMBER_OF_POINTERS/2)
166 {
167 for (j = 0; j < NUMBER_OF_POINTERS && apv[j] == NULL; j++)
168 (void)0;
169 }
170 }
171
172 if (j < NUMBER_OF_POINTERS && apv[j] != NULL)
173 {
174 int cb = _res_msize(apv[j]);
175 if (cb != ((acb[j] + 3) & ~3) && (cb < ((acb[j] + 3) & ~3) || cb > 40 + ((acb[j] + 3) & ~3)) )
176 printf("size of avp[%d] (%d) != acb[%d] (%d)\n", j, cb, j, acb[j]);
177 rfree(apv[j]);
178 apv[j] = NULL;
179 cAllocations--;
180 crfree++;
181 }
182 }
183 _res_heap_check();
184 if (RANDOMTEST_ITERATIONS == i*2)
185 _res_dump_subheaps();
186 }
187
188 printf("cb=%d crfree=%d crmalloc=%d\n", cb, crfree, crmalloc);
189
190 printf("_res_dump_subheaps:\n");
191 _res_dump_subheaps();
192
193 printf("_res_memfree - before heapmin: %d\n", _res_memfree());
194 _res_heapmin();
195 printf("_res_memfree - after heapmin : %d\n", _res_memfree());
196
197 printf("_res_dump_subheaps:\n");
198 _res_dump_subheaps();
199
200
201
202/*
203 *
204 * swappable heap tests
205 * swappable heap tests
206 *
207 */
208
209
210
211
212 /* unreferenced parameters */
213 argc = argc;
214 argv = argv;
215
216 return 0;
217}
218
219
220
Note: See TracBrowser for help on using the repository browser.