MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / _test_malloc

Function _test_malloc

mem/test/test_malloc.c:177–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177static void _test_malloc(int procs, unsigned int frag_overhead)
178{
179 int i;
180 int my_pid = 0, child_pid;
181
182 update_stat(workers, +1);
183
184 for (i = 1; i < procs; i++) {
185 update_stat(workers, +1);
186 const struct internal_fork_params ifp_th = {
187 .proc_desc = "malloc test",
188 .flags = OSS_PROC_NO_IPC|OSS_PROC_NO_LOAD,
189 .type = TYPE_NONE,
190 };
191
192 child_pid = internal_fork(&ifp_th);
193 if (child_pid < 0)
194 exit(-1);
195
196 if (child_pid == 0) {
197 my_pid = i;
198 printf("forked extra test worker #%d!\n", i);
199 break;
200 }
201 }
202
203 srand(getpid());
204
205 for (i = HPT_OPS; i; i--) {
206 if (i % 100000 == 0)
207 LM_INFO("ops left: %d, F: %ld, M: %ld, R: %ld, F: %ld, usage: %ld/%ld, frags: %lu\n",
208 i, fragments, mallocs, reallocs, frees,
209 hpt_my_used, MY_MAX_USED, get_stat_val(get_stat(_str("fragments"))));
210
211 if (should_grow) {
212 if (rand() % 10 >= 1)
213 hpt_malloc(frag_overhead);
214 else
215 hpt_free(frag_overhead);
216 } else {
217 if (rand() % 10 < 1)
218 hpt_malloc(frag_overhead);
219 else
220 hpt_free(frag_overhead);
221 }
222 }
223
224 for (i = 0; !list_empty(&hpt_frags); i++)
225 hpt_free(frag_overhead);
226
227 LM_INFO("Worker %d ended, freed up remaining %d chunks.\n", my_pid, i);
228 update_stat(workers, -1);
229
230 if (my_pid != 0) {
231 exit(0);
232 } else {
233 while (get_stat_val(workers) > 0) {
234 LM_INFO("waiting for everyone to finish...\n");

Callers 2

test_pkg_mallocFunction · 0.85
test_shm_mallocFunction · 0.85

Calls 5

internal_forkFunction · 0.85
get_statFunction · 0.85
_strClass · 0.85
hpt_freeFunction · 0.85
list_emptyFunction · 0.85

Tested by

no test coverage detected