-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_coalesce.c
103 lines (90 loc) · 2.02 KB
/
test_coalesce.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
#include <stdlib.h> //for exit
#include <string.h>
#include <assert.h>
#include "dmm.h"
int main(int argc, char *argv[]) {
char *array1, *array2, *array3;
int i;
printf("malloc(10)\n");
array1 = (char*)dmalloc(10);
if(array1 == NULL)
{
fprintf(stderr,"call to dmalloc() failed\n");
fflush(stderr);
exit(1);
}
for(i=0; i < 9; i++)
{
array1[i] = 'a';
}
array1[9] = '\0';
printf("String: %s\n",array1);
assert(strncmp(array1,"aaaaaaaaa",9)==0);
printf("malloc(100)\n");
array2 = (char*)dmalloc(100);
if(array2 == NULL)
{
fprintf(stderr,"call to dmalloc() failed\n");
fflush(stderr);
exit(1);
}
for(i=0; i < 99; i++)
{
array2[i] = 'b';
}
array2[99] = '\0';
printf("String: %s\n",array2);
assert(strncmp(array2,"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",99)==0);
printf("malloc(50)\n");
array3 = (char*)dmalloc(50);
if(array3 == NULL)
{
fprintf(stderr,"call to dmalloc() failed\n");
fflush(stderr);
exit(1);
}
for(i=0; i < 49; i++)
{
array3[i] = 'c';
}
array3[49] = '\0';
printf("String: %s\n",array3);
assert(strncmp(array3,"ccccccccccccccccccccccccccccccccccccccccccccccccc",49)==0);
printf("free(10)\n");
dfree(array1);
printf("After free\n");
print_freelist();
printf("free(50)\n");
dfree(array3);
printf("After free\n");
print_freelist();
printf("free(100)\n");
dfree(array2);
printf("After free\n");
print_freelist();
printf("malloc(510)\n");
array3 = (char*)dmalloc(510);
if(array3 == NULL)
{
fprintf(stderr,"call to dmalloc() failed\n");
fflush(stderr);
exit(1);
}
for(i=0; i < 509; i++)
{
array3[i] = 'c';
}
array3[509] = '\0';
//assert(strncmp(array3,"ccccccccccccccccccccccccccccccccccccccccccccccccc")==0);
printf("malloc(510)\n");
array3 = (char*)dmalloc(510);
if(array3 == NULL)
{
fprintf(stderr,"call to dmalloc() failed\n");
fflush(stderr);
//exit(1); // We expect the fail here. So do not exit
}
printf("Coalescing test cases passed!\n");
return(0);
}