forked from nlitsme/eimgfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtstallocmap.cpp
More file actions
86 lines (82 loc) · 2.13 KB
/
Copy pathtstallocmap.cpp
File metadata and controls
86 lines (82 loc) · 2.13 KB
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
#include <stdio.h>
#include "allocmap.h"
struct maptest_t {
bool use; uint32_t ofs; uint32_t size;
};
maptest_t tests[]= {
{ 1, 0x80080000, 0x123 },
{ 1, 0x80080124, 0x121 },
{ 1, 0x80001000, 0x2000 },
{ 0, 0x80001200, 0x123 },
{ 0, 0x80002000, 0x120 },
{ 0, 0x80002200, 0x121 },
{ 0, 0x80002400, 0x122 },
{ 0, 0x80002600, 0x123 },
{ 0, 0x80002800, 0x124 },
};
void tstamap()
{
allocmap m;
printf("free of empty map\n");
for (unsigned n= 0 ; n<16 ; n++)
printf("%04x: %08x\n", n, m.findfree(n));
for (unsigned i=0 ; i<sizeof(tests)/sizeof(*tests) ; ++i)
{
if (tests[i].use)
m.markused(tests[i].ofs, tests[i].size, "test");
else
m.markfree(tests[i].ofs, tests[i].size);
printf("exec %s %08x, %x\n", tests[i].use? "use":"free", tests[i].ofs, tests[i].size);
m.printallocmap();
}
printf("free\n");
for (unsigned n= 0 ; n<0x4000 ; n++)
printf("%04x: %08x\n", n, m.findfree(n));
}
struct maptest2_t {
int n;
maptest_t init[4];
};
maptest2_t tests2[]= {
{ 2, {{ 1, 0x10000, 0x100}, { 1, 0x10100, 0x100 } }},
//{ 2, {{ 1, 0x10000, 0x100}, { 1, 0x100f0, 0x100 } }}, -> overlap
//{ 2, {{ 1, 0x10000, 0x100}, { 1, 0x10080, 0x10 } }}, -> overlap
{ 2, {{ 1, 0x10000, 0x100}, { 0, 0x10080, 0x80 } }},
{ 2, {{ 1, 0x10000, 0x100}, { 0, 0x10000, 0x80 } }},
{ 2, {{ 1, 0x10000, 0x100}, { 0, 0x10080, 0x10 } }},
};
void tstamap2()
{
for (unsigned i=0 ; i<sizeof(tests2)/sizeof(*tests2) ; ++i)
{
printf("test2: %d\n", i);
maptest2_t & t= tests2[i];
allocmap m;
for (unsigned j=0 ; j<t.n ; j++) {
maptest_t & I= t.init[j];
if (I.use)
m.markused(I.ofs, I.size, "test2");
else
m.markfree(I.ofs, I.size);
}
m.printallocmap();
}
}
int main(int,char**)
{
try {
tstamap();
tstamap2();
}
catch(const char*msg)
{
printf("E: %s\n", msg);
return 1;
}
catch(...)
{
printf("EXCEPTION\n");
return 1;
}
return 0;
}