Wire Sysio
Wire Sysion 1.0.0
Loading...
Searching...
No Matches
growable_allocator_test.cpp
Go to the documentation of this file.
1
#define CATCH_CONFIG_MAIN
2
#include <
catch2/catch.hpp
>
3
4
#include <iostream>
5
#include <fstream>
6
#include <sysio/vm/backend.hpp>
7
8
using namespace
sysio
;
9
using namespace
sysio::vm
;
10
11
TEST_CASE
(
"Allocate until failure"
,
"[alloc_fail]"
) {
12
growable_allocator
ga(1);
// allocate 1 page
13
int
* base = ga.
alloc
<
int
>(0);
14
int
* p1, *p2;
15
size_t
amt1, amt2;
16
17
auto
equals = [&](
auto
* p1,
auto
* p2,
size_t
off) {
18
return
(
uintptr_t
)p1 - (
uintptr_t
)p2-off;
19
};
20
21
auto
alloc = [&](
size_t
amt) {
return
(
int
*)ga.
alloc
<
uint8_t
>(amt); };
22
auto
is_aligned = [](
auto
*
p
) {
return
((
uintptr_t
)
p
) % 16 == 0; };
23
24
p1 = alloc(15);
25
26
// base should == the first allocated memory
27
REQUIRE
(base == p1);
28
29
// should be 16 byte aligned
30
REQUIRE
(is_aligned(p1));
31
32
p2 = alloc(1);
33
REQUIRE
(is_aligned(p2));
34
REQUIRE
(equals(p1, p2, 16));
35
36
p1 = alloc(1);
37
REQUIRE
(is_aligned(p1));
38
REQUIRE
(equals(p2, p1, 16));
39
}
p
const mie::Vuint & p
Definition
bn.cpp:27
sysio::vm::growable_allocator
Definition
allocator.hpp:267
sysio::vm::growable_allocator::alloc
T * alloc(size_t size=0)
Definition
allocator.hpp:302
TEST_CASE
#define TEST_CASE(...)
Definition
catch.hpp:222
REQUIRE
#define REQUIRE(...)
Definition
catch.hpp:185
sysio::vm
Definition
controller.hpp:23
sysio
Definition
abi_serializer.cpp:8
catch.hpp
uintptr_t
_W64 unsigned int uintptr_t
Definition
stdint.h:165
uint8_t
unsigned char uint8_t
Definition
stdint.h:124
libraries
sys-vm
tests
memory_tests
growable_allocator_test.cpp
Generated by
1.12.0