2018-04-12 16:26:12 +00:00
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
#include "utils/fluid_sys.h"
|
|
|
|
|
|
|
|
|
|
|
|
// test for fluid_align_ptr()
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
unsigned int align;
|
|
|
|
uintptr_t ptr, aligned_ptr;
|
2018-06-24 11:01:31 +00:00
|
|
|
|
|
|
|
for(align = 32; align <= 4 * 1024u; align <<= 1)
|
2018-04-12 16:26:12 +00:00
|
|
|
{
|
2018-06-24 11:01:31 +00:00
|
|
|
for(ptr = 0; ptr <= (align << 10); ptr++)
|
2018-04-12 16:26:12 +00:00
|
|
|
{
|
2018-06-24 11:01:31 +00:00
|
|
|
char *tmp = fluid_align_ptr((char *)ptr, align);
|
2018-04-12 16:26:12 +00:00
|
|
|
aligned_ptr = (uintptr_t)tmp;
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-12 16:26:12 +00:00
|
|
|
// pointer must be aligned properly
|
|
|
|
TEST_ASSERT(aligned_ptr % align == 0);
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-12 16:26:12 +00:00
|
|
|
// aligned pointer must not be smaller than ptr
|
|
|
|
TEST_ASSERT(aligned_ptr >= ptr);
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-12 16:26:12 +00:00
|
|
|
// aligned pointer must not be bigger than alignment
|
|
|
|
TEST_ASSERT(aligned_ptr < ptr + align);
|
|
|
|
}
|
|
|
|
}
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-12 16:26:12 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|