Mercurial > MadButterfly
comparison nodejs/testleak.js @ 772:11f062c2c0b8
Script to detect memory leaking
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sun, 29 Aug 2010 19:13:59 +0800 |
parents | |
children | 586e50f82c1f |
comparison
equal
deleted
inserted
replaced
771:01b514800fbe | 772:11f062c2c0b8 |
---|---|
1 var mbfly = require("mbfly"); | |
2 var sys = require("sys"); | |
3 var cproc = require("child_process"); | |
4 | |
5 function testcase1() { | |
6 var mbrt = new mbfly.mb_rt(":32.0", 300, 200); | |
7 var root = mbrt.root; | |
8 var coords = []; | |
9 var coord; | |
10 var i; | |
11 | |
12 while(true) { | |
13 for(i = 0; i < 200; i++) { | |
14 coords.push(mbrt.coord_new(root)); | |
15 } | |
16 mbrt.redraw_changed(); | |
17 mbrt.flush(); | |
18 | |
19 while(coords.length > 0) { | |
20 coord = coords.pop(); | |
21 coord.remove(); | |
22 } | |
23 } | |
24 } | |
25 | |
26 function testcase2() { | |
27 var mbrt = new mbfly.mb_rt(":32.0", 300, 200); | |
28 var root = mbrt.root; | |
29 var coords = []; | |
30 var coord; | |
31 var i, j; | |
32 | |
33 while(true) { | |
34 for(i = 0; i < 200; i++) { | |
35 coords.push(mbrt.coord_new(root)); | |
36 for(j = 0; j < 10; j++) | |
37 coord = mbrt.coord_new(coords[i]); | |
38 } | |
39 mbrt.redraw_changed(); | |
40 mbrt.flush(); | |
41 | |
42 while(coords.length > 0) { | |
43 coord = coords.pop(); | |
44 coord.remove(); | |
45 } | |
46 } | |
47 } | |
48 | |
49 function testcase3() { | |
50 var mbrt = new mbfly.mb_rt(":32.0", 300, 200); | |
51 var root = mbrt.root; | |
52 var coords = []; | |
53 var coord; | |
54 var shape; | |
55 var i, j; | |
56 | |
57 while(true) { | |
58 for(i = 0; i < 200; i++) { | |
59 coords.push(mbrt.coord_new(root)); | |
60 for(j = 0; j < 10; j++) { | |
61 coord = mbrt.coord_new(coords[i]); | |
62 shape = mbrt.rect_new(15, 15, 20, 20, 0, 0); | |
63 coord.add_shape(shape); | |
64 } | |
65 } | |
66 mbrt.redraw_changed(); | |
67 mbrt.flush(); | |
68 | |
69 while(coords.length > 0) { | |
70 coord = coords.pop(); | |
71 coord.remove(); | |
72 } | |
73 } | |
74 } | |
75 | |
76 function testcase4() { | |
77 var mbrt = new mbfly.mb_rt(":32.0", 300, 200); | |
78 var root = mbrt.root; | |
79 var coords = []; | |
80 var coord; | |
81 var shape; | |
82 var i, j; | |
83 | |
84 while(true) { | |
85 for(i = 0; i < 200; i++) { | |
86 coords.push(mbrt.coord_new(root)); | |
87 for(j = 0; j < 10; j++) { | |
88 coord = mbrt.coord_new(coords[i]); | |
89 shape = mbrt.path_new("m 10,10 l 55,27 l -30,-3 z"); | |
90 coord.add_shape(shape); | |
91 } | |
92 } | |
93 mbrt.redraw_changed(); | |
94 mbrt.flush(); | |
95 | |
96 while(coords.length > 0) { | |
97 coord = coords.pop(); | |
98 coord.remove(); | |
99 } | |
100 } | |
101 } | |
102 | |
103 function testcase5() { | |
104 var mbrt = new mbfly.mb_rt(":32.0", 300, 200); | |
105 var root = mbrt.root; | |
106 var paint; | |
107 | |
108 while(true) { | |
109 paint = mbrt.paint_color_new(0.5, 0.5, 0.5, 1); | |
110 } | |
111 } | |
112 | |
113 function testcase6() { | |
114 var mbrt = new mbfly.mb_rt(":32.0", 300, 200); | |
115 var root = mbrt.root; | |
116 var coords = []; | |
117 var coord; | |
118 var shape; | |
119 var paint; | |
120 var i, j; | |
121 | |
122 while(true) { | |
123 for(i = 0; i < 200; i++) { | |
124 coords.push(mbrt.coord_new(root)); | |
125 /* Paint is free, but rdman is dirty */ | |
126 paint = mbrt.paint_color_new(0.5, 0.5, 0.5, 1); | |
127 for(j = 0; j < 10; j++) { | |
128 coord = mbrt.coord_new(coords[i]); | |
129 shape = mbrt.rect_new(5, 5, 20, 20, 0, 0); | |
130 coord.add_shape(shape); | |
131 } | |
132 } | |
133 mbrt.redraw_changed(); | |
134 mbrt.flush(); | |
135 | |
136 while(coords.length > 0) { | |
137 coord = coords.pop(); | |
138 coord.remove(); | |
139 } | |
140 } | |
141 } | |
142 | |
143 function testcase7() { | |
144 var mbrt = new mbfly.mb_rt(":32.0", 300, 200); | |
145 var root = mbrt.root; | |
146 var coords = []; | |
147 var coord; | |
148 var shape; | |
149 var paint; | |
150 var i, j; | |
151 | |
152 while(true) { | |
153 for(i = 0; i < 200; i++) { | |
154 coords.push(mbrt.coord_new(root)); | |
155 for(j = 0; j < 10; j++) { | |
156 /* paint is not free, and rdman is dirty */ | |
157 paint = mbrt.paint_color_new(0.5, 0.5, 0.5, 1); | |
158 coord = mbrt.coord_new(coords[i]); | |
159 shape = mbrt.path_new("M 100,100 L 30,30 L 0,30 z"); | |
160 coord.add_shape(shape); | |
161 paint.stroke(shape); | |
162 } | |
163 } | |
164 mbrt.redraw_changed(); | |
165 mbrt.flush(); | |
166 | |
167 while(coords.length > 0) { | |
168 coord = coords.pop(); | |
169 coord.remove(); | |
170 } | |
171 } | |
172 } | |
173 | |
174 cproc.exec("killall -9 Xvfb; Xvfb :32 -screen 0 800x600x24"); | |
175 setTimeout(function() { | |
176 if(process.argv.length == 1) | |
177 testcase1(); | |
178 else if(process.argv.length == 3) { | |
179 sys.puts("testcase " + process.argv[2]); | |
180 switch(process.argv[2]) { | |
181 case "1": | |
182 testcase1(); | |
183 break; | |
184 | |
185 case "2": | |
186 testcase2(); | |
187 break; | |
188 | |
189 case "3": | |
190 testcase3(); | |
191 break; | |
192 | |
193 case "4": | |
194 testcase4(); | |
195 break; | |
196 | |
197 case "5": | |
198 testcase5(); | |
199 break; | |
200 | |
201 case "6": | |
202 testcase6(); | |
203 break; | |
204 | |
205 case "7": | |
206 testcase7(); | |
207 break; | |
208 | |
209 default: | |
210 sys.puts("Usage: node testleak.js [1|2|3...7]"); | |
211 } | |
212 } else | |
213 sys.puts("Usage: node testleak.js [1|2|3...7]"); | |
214 cproc.exec("killall -9 Xvfb"); | |
215 }, 1500); |