-
Notifications
You must be signed in to change notification settings - Fork 122
/
test.c
49 lines (42 loc) · 844 Bytes
/
test.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
#include "buddy.h"
#include <stdio.h>
static int
test_alloc(struct buddy *b, int sz) {
int r = buddy_alloc(b,sz);
printf("alloc %d (sz= %d)\n",r,sz);
buddy_dump(b);
return r;
}
static void
test_free(struct buddy *b, int addr) {
printf("free %d\n",addr);
buddy_free(b,addr);
buddy_dump(b);
}
static void
test_size(struct buddy *b, int addr) {
int s = buddy_size(b,addr);
printf("size %d (sz = %d)\n",addr,s);
}
int
main() {
struct buddy * b = buddy_new(5);
buddy_dump(b);
int m1 = test_alloc(b,4);
test_size(b,m1);
int m2 = test_alloc(b,9);
test_size(b,m2);
int m3 = test_alloc(b,3);
test_size(b,m3);
int m4 = test_alloc(b,7);
test_free(b,m3);
test_free(b,m1);
test_free(b,m4);
test_free(b,m2);
int m5 = test_alloc(b,32);
test_free(b,m5);
int m6 = test_alloc(b,0);
test_free(b,m6);
buddy_delete(b);
return 0;
}