forked from cloudwu/buddy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
41 lines (36 loc) · 706 Bytes
/
Copy pathtest.c
File metadata and controls
41 lines (36 loc) · 706 Bytes
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
#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);
test_free(b,m3);
test_free(b,m1);
test_free(b,m2);
buddy_delete(b);
return 0;
}