8 #ifndef HEAPMEMORY_UNIT_TESTS_HPP_
9 #define HEAPMEMORY_UNIT_TESTS_HPP_
13 #include "memory/HeapMemory.hpp"
14 #include "memory/BHeapMemory.hpp"
16 #include "memory/CudaMemory.cuh"
19 BOOST_AUTO_TEST_SUITE( HeapMemory_test )
21 #define FIRST_ALLOCATION 1024ul
23 #define SECOND_ALLOCATION 4096ul
26 template<
typename T>
void test()
31 BOOST_REQUIRE_EQUAL(mem.size(),0ul);
33 mem.allocate(FIRST_ALLOCATION);
35 BOOST_REQUIRE_EQUAL(mem.size(),FIRST_ALLOCATION);
39 unsigned char * ptr = (
unsigned char *)mem.getPointer();
40 for (
size_t i = 0 ; i < mem.size() ; i++)
48 mem.resize(SECOND_ALLOCATION);
50 unsigned char * ptr2 = (
unsigned char *)mem.getPointer();
52 BOOST_REQUIRE_EQUAL(mem.size(),SECOND_ALLOCATION);
53 BOOST_REQUIRE_EQUAL(mem.isInitialized(),
false);
58 for (
size_t i = 0 ; i < FIRST_ALLOCATION ; i++)
61 BOOST_REQUIRE_EQUAL(ptr2[i],c);
67 BOOST_REQUIRE_EQUAL(mem.size(),SECOND_ALLOCATION);
77 src.allocate(FIRST_ALLOCATION);
78 dst.allocate(SECOND_ALLOCATION);
80 unsigned char * ptr = (
unsigned char *)src.getPointer();
81 for (
size_t i = 0 ; i < src.size() ; i++)
86 for (
size_t i = 0 ; i < FIRST_ALLOCATION ; i++)
89 BOOST_REQUIRE_EQUAL(ptr2[i],c);
97 src.allocate(FIRST_ALLOCATION);
99 unsigned char * ptr = (
unsigned char *)src.getPointer();
100 for (
size_t i = 0 ; i < src.size() ; i++)
107 unsigned char * ptr2 = (
unsigned char *)dst.getPointer();
109 BOOST_REQUIRE(src.getPointer() != dst.getPointer());
110 for (
size_t i = 0 ; i < FIRST_ALLOCATION ; i++)
113 BOOST_REQUIRE_EQUAL(ptr2[i],c);
118 BOOST_REQUIRE_EQUAL(mem.size(),0ul);
120 mem.allocate(FIRST_ALLOCATION);
122 BOOST_REQUIRE_EQUAL(mem.size(),FIRST_ALLOCATION);
127 template<
typename T>
void Btest()
132 mem.allocate(FIRST_ALLOCATION);
134 BOOST_REQUIRE_EQUAL(mem.size(),FIRST_ALLOCATION);
138 unsigned char * ptr = (
unsigned char *)mem.getPointer();
139 for (
size_t i = 0 ; i < mem.size() ; i++)
145 mem.resize(SECOND_ALLOCATION);
147 unsigned char * ptr2 = (
unsigned char *)mem.getPointer();
149 BOOST_REQUIRE_EQUAL(mem.size(),SECOND_ALLOCATION);
150 BOOST_REQUIRE_EQUAL(mem.isInitialized(),
false);
155 for (
size_t i = 0 ; i < FIRST_ALLOCATION ; i++)
158 BOOST_REQUIRE_EQUAL(ptr2[i],c);
164 BOOST_REQUIRE_EQUAL(mem.size(),1ul);
170 BOOST_REQUIRE_EQUAL(mem.size(),0ul);
172 mem.allocate(FIRST_ALLOCATION);
174 BOOST_REQUIRE_EQUAL(mem.size(),FIRST_ALLOCATION);
178 template<
typename T>
void Stest()
183 mem1.allocate(5*
sizeof(
size_t));
184 mem2.allocate(6*
sizeof(
size_t));
186 BOOST_REQUIRE_EQUAL(mem1.size(),5*
sizeof(size_t));
187 BOOST_REQUIRE_EQUAL(mem2.size(),6*
sizeof(size_t));
191 size_t * ptr1 = (
size_t *)mem1.getPointer();
192 size_t * ptr2 = (
size_t *)mem2.getPointer();
193 for (
size_t i = 0 ; i < 5 ; i++)
196 for (
size_t i = 0 ; i < 6 ; i++)
202 ptr1 = (
size_t *)mem2.getPointer();
203 ptr2 = (
size_t *)mem1.getPointer();
204 for (
size_t i = 0 ; i < 5 ; i++)
207 for (
size_t i = 0 ; i < 6 ; i++)
208 ret &= ptr2[i] == i+100;
210 BOOST_REQUIRE_EQUAL(ret,
true);
212 BOOST_REQUIRE_EQUAL(mem1.size(),6*
sizeof(size_t));
213 BOOST_REQUIRE_EQUAL(mem2.size(),5*
sizeof(size_t));
216 BOOST_AUTO_TEST_CASE( use_heap_memory )
224 BOOST_AUTO_TEST_CASE( use_memory )
232 BOOST_AUTO_TEST_CASE( use_bheap_memory )
234 Btest<BHeapMemory>();
237 BOOST_AUTO_TEST_CASE( swap_heap_memory )
242 BOOST_AUTO_TEST_SUITE_END()