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
8using namespace sysio;
9using namespace sysio::vm;
10
11TEST_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}
const mie::Vuint & p
Definition bn.cpp:27
#define TEST_CASE(...)
Definition catch.hpp:222
#define REQUIRE(...)
Definition catch.hpp:185
_W64 unsigned int uintptr_t
Definition stdint.h:165
unsigned char uint8_t
Definition stdint.h:124