summaryrefslogtreecommitdiff
path: root/firmware/test/malloc/dmytest.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test/malloc/dmytest.c')
-rw-r--r--firmware/test/malloc/dmytest.c173
1 files changed, 0 insertions, 173 deletions
diff --git a/firmware/test/malloc/dmytest.c b/firmware/test/malloc/dmytest.c
deleted file mode 100644
index a63bb30d74..0000000000
--- a/firmware/test/malloc/dmytest.c
+++ /dev/null
@@ -1,173 +0,0 @@
1#include <stdio.h>
2#include <stdlib.h>
3
4#include "dmalloc.h"
5#include "bmalloc.h"
6
7#define MAX 500
8#define MAX2 1000
9#define MAXC 2
10
11#define TESTA
12#define TESTB
13#define TESTC
14#define TESTD
15
16int test1(void)
17{
18#define MAXK 100
19 int i;
20 void *wow[MAXK];
21 for(i=0; i<MAXK; i++)
22 if(!(wow[i]=malloc(412))) {
23 printf("*** Couldn't allocate memory, exiting\n");
24 return -2;
25 }
26 for(i=MAXK-1; i>=0; i-=2)
27 free(wow[i]);
28 return 0;
29}
30
31int test2(void)
32{
33#define MAXS 10
34#define MAXS1 0
35 int i;
36 void *ptr[MAXS];
37
38 for(i=MAXS1; i< MAXS; i++) {
39 printf("%d malloc(%d)\n", i, i*55);
40 ptr[i] = malloc (i*55);
41 }
42 for(i=MAXS1; i< MAXS; i++) {
43 void *tmp;
44 printf("%d realloc(%d)\n", i, i*155);
45 tmp=realloc(ptr[i], i*155);
46 if(tmp)
47 ptr[i] = tmp;
48 }
49 for(i=MAXS1; i< MAXS; i++) {
50 if(ptr[i]) {
51 printf("%d free(%d)\n", i, i*155);
52 free(ptr[i]);
53 }
54 }
55 return 0;
56}
57
58int test3(void)
59{
60 int i;
61 void *ptr[MAXC];
62 printf("This is test C:\n");
63
64 for(i=0; i< MAXC; i++) {
65 printf("%d malloc(100)\n", i+1);
66 ptr[i] = malloc(100);
67 printf(" ...returned %p\n", ptr[i]);
68 }
69
70 for(i=0; i< MAXC; i++) {
71 printf("%d free()\n", i+1);
72 if(ptr[i])
73 free(ptr[i]);
74 }
75
76 printf("End of test C:\n");
77
78 return 0;
79}
80
81int test4(void)
82{
83 int i;
84 int memory = 0;
85 void *pointers[MAX];
86 printf("This is test I:\n");
87
88 for(i=0; i<MAX; i++) {
89 printf("%d attempts malloc(%d)\n", i, i*6);
90 pointers[i]=malloc(i*6);
91 if(!pointers[i]) {
92 printf("cant get more memory!");
93 return(0);
94 }
95 memory += (i*6);
96 }
97 printf("\namount: %d\n", memory);
98 memory = 0;
99 for(i=0; i<MAX; i++) {
100 printf("%d attempts realloc(%d)\n", i, i*7);
101 pointers[i]=realloc(pointers[i], i*7);
102 memory += i*7;
103 }
104 printf("\namount: %d\n", memory);
105 for(i=0; i<MAX; i++) {
106 printf("%d attempts free(%d)\n", i, i*7);
107 free(pointers[i]);
108 }
109 printf("\nend of test 1\n");
110
111 return 0;
112}
113
114int test5(void)
115{
116 int memory = 0;
117 int i;
118 void *pointers2[MAX2];
119 memory = 0;
120 printf("\nTest II\n");
121 for(i=0; i< MAX2; i++) {
122 printf("%d attempts malloc(%d)\n", i, 7);
123 pointers2[i] = malloc(7);
124 memory += 7;
125 }
126 printf("\namount: %d\n", memory);
127 for(i=0; i< MAX2; i++) {
128 if(pointers2[i])
129 free(pointers2[i]);
130 }
131 printf("\nend of test II\n");
132
133 return 0;
134}
135
136#define HEAPSIZE 10000
137
138void smallblocks(void)
139{
140 void *ptr;
141 int i=0;
142 do {
143
144 ptr = malloc(16);
145 i++;
146 } while(ptr);
147
148 printf("I: %d\n", i);
149}
150
151int main(int argc, char **argv)
152{
153 void *heap = (malloc)(HEAPSIZE);
154 if(!heap)
155 return -1;
156 dmalloc_initialize();
157 bmalloc_add_pool(heap, HEAPSIZE);
158
159 smallblocks();
160
161 bmalloc_status();
162 dmalloc_status();
163
164 return 0;
165
166 test1();
167 test2();
168 test3();
169 test4();
170 test5();
171
172 return 0;
173}