|
@@ -5,10 +5,13 @@
|
|
|
#include <dmmlib/dmmlib.h>
|
|
|
#include <dmm_config.h>
|
|
|
|
|
|
-#define ALLOCATOR_SIZE 16*1024*sizeof(char)
|
|
|
+#define ALLOCATOR_SIZE 2*MAX_COALESCE_SIZE*sizeof(char)
|
|
|
|
|
|
#define cmalloc(size) custom_ahmalloc(&systemallocator, &systemallocator.heaps[0], (size_t) size)
|
|
|
#define cfree(ptr) custom_ahfree(&systemallocator, &systemallocator.heaps[0], ptr)
|
|
|
+#ifdef WITH_REALLOC
|
|
|
+#define crealloc(ptr, size) custom_ahrealloc(&systemallocator, &systemallocator.heaps[0], ptr, size)
|
|
|
+#endif
|
|
|
|
|
|
int main(void) {
|
|
|
|
|
@@ -34,7 +37,7 @@ int main(void) {
|
|
|
|
|
|
printf("Test 2: Check if best fit on LIFO works.\n");
|
|
|
|
|
|
- p1 = cmalloc(1024);
|
|
|
+ p1 = cmalloc(MAX_COALESCE_SIZE);
|
|
|
p2 = cmalloc(432);
|
|
|
|
|
|
cfree(p2);
|
|
@@ -75,6 +78,50 @@ int main(void) {
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
+#ifdef WITH_REALLOC
|
|
|
+
|
|
|
+ printf("Testing realloc()...\n");
|
|
|
+
|
|
|
+ initialize_allocator(&systemallocator, block_from_malloc, ALLOCATOR_SIZE);
|
|
|
+
|
|
|
+
|
|
|
+ p1 = crealloc(NULL, 1000);
|
|
|
+ assert( p1 != NULL );
|
|
|
+
|
|
|
+
|
|
|
+ p2 = crealloc(p1, 50);
|
|
|
+ assert( p2 == p1 );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ initialize_allocator(&systemallocator, block_from_malloc, ALLOCATOR_SIZE);
|
|
|
+ p1 = cmalloc(100);
|
|
|
+ p2 = cmalloc(100);
|
|
|
+ p3 = crealloc(p1, 1000);
|
|
|
+ assert( p3 > p2 );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ initialize_allocator(&systemallocator, block_from_malloc, ALLOCATOR_SIZE);
|
|
|
+#if defined (SPLITTING_FIXED) || defined (SPLITTING_VARIABLE)
|
|
|
+ p1 = cmalloc(MIN_SPLITTING_SIZE);
|
|
|
+ p2 = cmalloc(2*MIN_SPLITTING_SIZE);
|
|
|
+ cfree(p2);
|
|
|
+ p3 = crealloc(p1, 2*MIN_SPLITTING_SIZE);
|
|
|
+ p2 = cmalloc(MIN_SPLITTING_SIZE);
|
|
|
+
|
|
|
+ assert( (char *) p2 == (char *) p1 + 24 + 2 * MIN_SPLITTING_SIZE);
|
|
|
+#else
|
|
|
+ p1 = cmalloc(100);
|
|
|
+ p2 = cmalloc(100);
|
|
|
+ cfree(p2);
|
|
|
+ p3 = crealloc(p1, 200);
|
|
|
+#endif
|
|
|
+ assert( p3 == p1 );
|
|
|
+
|
|
|
+ printf("Passed.\n");
|
|
|
+#endif
|
|
|
+
|
|
|
free(block_from_malloc);
|
|
|
|
|
|
return 0;
|