-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
74 lines (59 loc) · 1.31 KB
/
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
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
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "buddy.h"
static int _test_size(struct buddy *buddy, unsigned int size)
{
unsigned int offset;
int rc;
if ((rc = buddy_alloc(buddy, size, &offset)) == 0)
printf("%s>size=%d, offset=%d\n", __FUNCTION__, size, offset);
else
printf("%s>size=%d fail\n", __FUNCTION__, size);
buddy_dump(buddy);
return rc;
}
static int _arg(int argc, char **argv)
{
int rc = 0;
struct buddy *buddy;
unsigned int size;
if (argc > 1)
size = atoi(argv[1]);
else
size = 1024;
buddy = buddy_new(size);
if (!buddy) {
printf("buddy_new(%d) fail\n", size);
goto fail;
}
buddy_dump(buddy);
_test_size(buddy, 1);
_test_size(buddy, 2);
_test_size(buddy, 3);
_test_size(buddy, 1);
buddy_free(buddy, 4);
buddy_dump(buddy);
_test_size(buddy, 4);
_test_size(buddy, 6);
_test_size(buddy, 7);
buddy_free(buddy, 8);
buddy_dump(buddy);
_test_size(buddy, 4);
buddy_free(buddy, 0);
buddy_free(buddy, 1);
_test_size(buddy, 9);
printf("success!\n");
goto end;
fail:
rc = -1;
end:
if (buddy)
buddy_delete(buddy);
return rc;
}
int main(int argc, char **argv)
{
return _arg(argc, argv);
}