2016-10-10 18:18:29 +11:00
|
|
|
#include "tap.hpp"
|
|
|
|
|
2018-12-19 17:55:24 +11:00
|
|
|
#include "alloc/aligned/direct.hpp"
|
|
|
|
#include "alloc/linear.hpp"
|
2016-10-10 18:18:29 +11:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int, char**)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2016-10-10 18:18:29 +11:00
|
|
|
|
|
|
|
// set aside a sizeable buffer. it has to be large enough to conceivably
|
|
|
|
// satisfy a sane allocation request during testing, just in case the
|
|
|
|
// underlying code actually decides to do something; we don't be touching
|
|
|
|
// it ourselves.
|
2018-12-19 17:16:57 +11:00
|
|
|
static u08 buffer[1024*1024];
|
2016-10-10 18:18:29 +11:00
|
|
|
|
|
|
|
// pick an alignment that isn't likely to be satisfied by any likely
|
|
|
|
// underlying allocator. if the allocation fulfills this alignment then
|
|
|
|
// we're probably operating correctly.
|
|
|
|
static constexpr std::size_t alignment = 3;
|
|
|
|
|
2018-12-19 17:55:24 +11:00
|
|
|
cruft::alloc::aligned::direct<cruft::alloc::linear> alloc (
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::make_view (buffer), alignment
|
2016-10-10 18:18:29 +11:00
|
|
|
);
|
|
|
|
|
|
|
|
// allocate a range of values and make sure they all satisfy our alignment.
|
|
|
|
// don't choose values which are likely to combine with the testing
|
|
|
|
// alignment to produce a likely system alignment. eg, 3 + 5 == 8 which is
|
|
|
|
// a power-of-2.
|
|
|
|
uintptr_t result[4] = {
|
2018-12-19 17:16:57 +11:00
|
|
|
reinterpret_cast<uintptr_t>(alloc.allocate ( 9).data ()), // just over a power of two
|
|
|
|
reinterpret_cast<uintptr_t>(alloc.allocate ( 1).data ()), // a single byte
|
|
|
|
reinterpret_cast<uintptr_t>(alloc.allocate ( 64).data ()), // a cache line
|
|
|
|
reinterpret_cast<uintptr_t>(alloc.allocate (250).data ()) // multiple lines, but not a power of two
|
2016-10-10 18:18:29 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
tap.expect (
|
|
|
|
!(result[0] % alignment) &&
|
|
|
|
!(result[1] % alignment) &&
|
|
|
|
!(result[2] % alignment) &&
|
|
|
|
!(result[3] % alignment),
|
|
|
|
|
|
|
|
"allocations make alignment of %zu", alignment
|
|
|
|
);
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|