-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpage.test.cpp
61 lines (43 loc) · 1.52 KB
/
page.test.cpp
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
#include <boost/ut.hpp>
#include <lime/page.hpp>
using namespace boost::ut;
using namespace boost::ut::literals;
int example(int arg)
{
return arg + 20;
}
suite<"Page"> page_suite = []
{
using prot = lime::protection;
expect(gt(lime::page::pages().size(), 0));
auto addr = reinterpret_cast<std::uintptr_t>(example);
{
auto page = lime::page::at(addr);
expect(eq(page.has_value(), true));
expect(page->prot() & prot::read);
expect(page->prot() & prot::execute);
expect(ge(addr, page->start()));
expect(le(addr, page->end()));
}
auto allocated = lime::page::allocate(100, prot::read | prot::write | prot::execute);
{
expect(neq(allocated, nullptr));
auto page = lime::page::at(allocated->start());
expect(eq(page.has_value(), true));
expect(page->prot() & prot::read);
expect(page->prot() & prot::write);
expect(page->prot() & prot::execute);
}
auto near = lime::page::allocate(addr, 10, prot::read);
{
expect(neq(near, nullptr));
auto page = lime::page::at(near->start());
expect(eq(page.has_value(), true));
expect(page->prot() & prot::read);
expect(not(page->prot() & prot::write));
expect(not(page->prot() & prot::execute));
const auto diff = std::abs(static_cast<std::intptr_t>(near->start()) - static_cast<std::intptr_t>(addr));
expect(gt(diff, 0));
expect(lt(diff, std::numeric_limits<std::uint32_t>::max()));
}
};