Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
allocator_tests.cpp File Reference
#include <sysio/vm/allocator.hpp>
#include <catch2/catch.hpp>
Include dependency graph for allocator_tests.cpp:

Go to the source code of this file.

Functions

template<typename T >
bool check_alignment (T *ptr)
 
 TEST_CASE ("Testing growable_allocator alignment", "[growable_allocator]")
 
 TEST_CASE ("Testing maximum single allocation", "[growable_allocator]")
 
 TEST_CASE ("Testing maximum multiple allocation", "[growable_allocator]")
 
 TEST_CASE ("Testing too large single allocation", "[growable_allocator]")
 
 TEST_CASE ("Testing too large multiple allocation", "[growable_allocator]")
 
 TEST_CASE ("Testing maximum initial size", "[growable_allocator]")
 
 TEST_CASE ("Testing too large initial size", "[growable_allocator]")
 
 TEST_CASE ("Testing maximum aligned allocation", "[growable_allocator]")
 
 TEST_CASE ("Testing reclaim", "[growable_allocator]")
 

Function Documentation

◆ check_alignment()

template<typename T >
bool check_alignment ( T * ptr)

Definition at line 9 of file allocator_tests.cpp.

9 {
10 void * p = ptr;
11 std::size_t sz = sizeof(T);
12 return std::align(alignof(T), sizeof(T), p, sz) != nullptr;
13}
const mie::Vuint & p
Definition bn.cpp:27
#define T(meth, val, expected)
Here is the caller graph for this function:

◆ TEST_CASE() [1/9]

TEST_CASE ( "Testing growable_allocator alignment" ,
"" [growable_allocator] )

Definition at line 15 of file allocator_tests.cpp.

15 {
16 growable_allocator alloc(1024);
17 unsigned char * cptr = alloc.alloc<unsigned char>(1);
19 uint16_t * sptr = alloc.alloc<uint16_t>(1);
21 uint32_t * iptr = alloc.alloc<uint32_t>(1);
23 uint64_t * lptr = alloc.alloc<uint64_t>(1);
25 *cptr = 0x11u;
26 *sptr = 0x2233u;
27 *iptr = 0x44556677u;
28 *lptr = 0x8899102030405060u;
29 CHECK(*cptr == 0x11u);
30 CHECK(*sptr == 0x2233u);
31 CHECK(*iptr == 0x44556677u);
32 CHECK(*lptr == 0x8899102030405060u);
33}
bool check_alignment(T *ptr)
#define CHECK(cond)
Definition util.h:80
unsigned short uint16_t
Definition stdint.h:125
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:

◆ TEST_CASE() [2/9]

TEST_CASE ( "Testing maximum aligned allocation" ,
"" [growable_allocator] )

Definition at line 82 of file allocator_tests.cpp.

82 {
83 growable_allocator alloc(1024);
84 struct alignas(8) aligned_t { char a[8]; };
85 alloc.alloc<char>(0x3FFFFFF4);
86 aligned_t * ptr = alloc.alloc<aligned_t>(1);
87 ptr->a[0] = 'a';
88 ptr->a[7] = 'z';
89 alloc.alloc<aligned_t>(0);
90 CHECK_THROWS_AS(alloc.alloc<char>(1), wasm_bad_alloc);
91}
#define CHECK_THROWS_AS(expr, exceptionType)
Definition catch.hpp:203
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
Here is the call graph for this function:

◆ TEST_CASE() [3/9]

TEST_CASE ( "Testing maximum initial size" ,
"" [growable_allocator] )

Definition at line 67 of file allocator_tests.cpp.

67 {
68 growable_allocator alloc(0x40000000);
69 char * ptr = alloc.alloc<char>(0x40000000);
70 ptr[0] = 'a';
71 ptr[0x3FFFFFFF] = 'z';
72}
Here is the call graph for this function:

◆ TEST_CASE() [4/9]

TEST_CASE ( "Testing maximum multiple allocation" ,
"" [growable_allocator] )

Definition at line 44 of file allocator_tests.cpp.

44 {
45 growable_allocator alloc(1024);
46 for(int i = 0; i < 4; ++i) {
47 char * ptr = alloc.alloc<char>(0x10000000);
48 ptr[0] = 'a';
49 ptr[0x0FFFFFFF] = 'z';
50 }
51 alloc.alloc<char>(0);
52}
Here is the call graph for this function:

◆ TEST_CASE() [5/9]

TEST_CASE ( "Testing maximum single allocation" ,
"" [growable_allocator] )

Definition at line 35 of file allocator_tests.cpp.

35 {
36 growable_allocator alloc(0);
37 char * ptr = alloc.alloc<char>(0x40000000);
38 ptr[0] = 'a';
39 ptr[0x3FFFFFFF] = 'z';
40 alloc.alloc<char>(0);
41}
Here is the call graph for this function:

◆ TEST_CASE() [6/9]

TEST_CASE ( "Testing reclaim" ,
"" [growable_allocator] )

Definition at line 93 of file allocator_tests.cpp.

93 {
94 growable_allocator alloc(1024);
95 int * ptr1 = alloc.alloc<int>(10);
96 alloc.reclaim(ptr1 + 2, 8);
97 int * ptr2 = alloc.alloc<int>(10);
98 CHECK(ptr2 == ptr1 + 2);
99}
Here is the call graph for this function:

◆ TEST_CASE() [7/9]

TEST_CASE ( "Testing too large initial size" ,
"" [growable_allocator] )

Definition at line 74 of file allocator_tests.cpp.

74 {
75 CHECK_THROWS_AS(growable_allocator{0x40000001}, wasm_bad_alloc);
76 // Check that integer overflow in rounding functions won't cause issues
77 CHECK_THROWS_AS(growable_allocator{0x8000000000000000ull}, wasm_bad_alloc);
78 CHECK_THROWS_AS(growable_allocator{0xFFFFFFFFFFFE0001ull}, wasm_bad_alloc);
79 CHECK_THROWS_AS(growable_allocator{0xFFFFFFFFFFFFFFFFull}, wasm_bad_alloc);
80}

◆ TEST_CASE() [8/9]

TEST_CASE ( "Testing too large multiple allocation" ,
"" [growable_allocator] )

Definition at line 59 of file allocator_tests.cpp.

59 {
60 growable_allocator alloc(1024);
61 alloc.alloc<char>(0x10000000);
62 alloc.alloc<char>(0x10000000);
63 alloc.alloc<char>(0x10000000);
64 CHECK_THROWS_AS(alloc.alloc<char>(0x10000001), wasm_bad_alloc);
65}
Here is the call graph for this function:

◆ TEST_CASE() [9/9]

TEST_CASE ( "Testing too large single allocation" ,
"" [growable_allocator] )

Definition at line 54 of file allocator_tests.cpp.

54 {
55 growable_allocator alloc(1024);
56 CHECK_THROWS_AS(alloc.alloc<char>(0x40000001), wasm_bad_alloc);
57}
Here is the call graph for this function: