1 /* Simple malloc tests.
6 #if defined(__SDCC_pic16)
11 #if defined(__SDCC_pic16)
12 __xdata
char heap
[100];
17 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
21 LOG (("mallocfree()\n"));
32 LOG (("1 a %u b %u c %u\n", (unsigned)a
, (unsigned)b
, (unsigned)c
));
35 ASSERT(!memcmp(d
, a
, 16));
37 ASSERT(!memcmp(d
, b
, 16));
39 ASSERT(!memcmp(d
, c
, 16));
45 LOG (("2 a %u b %u c %u\n", (unsigned)a
, (unsigned)b
, (unsigned)c
));
48 ASSERT(!memcmp(d
, a
, 16));
50 ASSERT(!memcmp(d
, b
, 20));
52 ASSERT(!memcmp(d
, c
, 16));
58 LOG (("3 a %u b %u c %u\n", (unsigned)a
, (unsigned)b
, (unsigned)c
));
61 ASSERT(!memcmp(d
, a
, 16));
63 ASSERT(!memcmp(d
, b
, 10));
65 ASSERT(!memcmp(d
, c
, 16));
72 ASSERT(!memcmp(d
, b
, 4));
74 LOG (("4 a %u b %u c %u\n", (unsigned)a
, (unsigned)b
, (unsigned)c
));
79 ASSERT(!memcmp(d
, b
, 4));
82 LOG (("5 a %u b %u c %u\n", (unsigned)a
, (unsigned)b
, (unsigned)c
));
86 LOG (("6 a %u b %u c %u\n", (unsigned)a
, (unsigned)b
, (unsigned)c
));
90 LOG (("7 a %u b %u c %u\n", (unsigned)a
, (unsigned)b
, (unsigned)c
));
100 LOG (("8 a %u b %u c %u\n", (unsigned)a
, (unsigned)b
, (unsigned)c
));
105 memset(a
+ 10, 6, 15);
107 LOG (("9 a %u b %u c %u\n", (unsigned)a
, (unsigned)b
, (unsigned)c
));
111 ASSERT(!memcmp(d
, a
, 25));
113 ASSERT(!memcmp(d
, c
, 10));
118 /* Check that we can allocate at least 256 bytes at once. */
119 #if defined(PORT_HOST) || defined(__SDCC_z80) || defined(__SDCC_z80n) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r2ka) || defined(__SDCC_r3ka)
125 /* Check for overflow in calloc() memory size calculation, bug #2650. */
127 c
= calloc(SIZE_MAX
/ 256, 258);
136 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
138 void __xdata
*p1
, *p2
, *p3
;
143 #if defined(__SDCC_pic16)
144 _initHeap (heap
, sizeof heap
);
148 p1
= malloc (0xFFFF);
150 LOG (("p1 == NULL when out of memory\n"));
153 #if !defined(PORT_HOST) && !defined(__SDCC_sm83) && !defined(__SDCC_z80) && !defined(__SDCC_z80n)
156 LOG (("p1 == NULL when out of memory\n"));
158 LOG (("p1: %p\n", p1
));
160 LOG (("p1: %u\n", (unsigned) p1
));
167 LOG (("p1: %p\n", p1
));
169 LOG (("p1: %u\n", (unsigned) p1
));
175 LOG (("p2: %p\n", p2
));
177 LOG (("p2: %u\n", (unsigned) p2
));
181 for (i
= 0; i
< 20; i
++, p
++)
184 p2
= realloc (p2
, 25);
187 LOG (("p2, after expanding realloc: %p\n", p2
));
189 LOG (("p2, after expanding realloc: %u\n", (unsigned) p2
));
193 for (i
= 0; i
< 20; i
++, p
++)
196 p2
= realloc (p2
, 15);
199 LOG (("p2, after shrinking realloc: %p\n", p2
));
201 LOG (("p2, after shrinking realloc: %u\n", (unsigned) p2
));
205 for (i
= 0; i
< 15; i
++, p
++)
213 LOG (("p3, after freeing p2: %p\n", p3
));
215 LOG (("p3, after freeing p2: %u\n", (unsigned) p3
));