mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
Merge pull request #4521
6653062e
unit_tests: add unit test for alloc alignment being a power of 2 (moneromooo-monero)
This commit is contained in:
commit
14dbe67fa7
1 changed files with 21 additions and 0 deletions
|
@ -84,3 +84,24 @@ TEST(aligned, contents_smaller)
|
||||||
aligned_free(ptr2);
|
aligned_free(ptr2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(aligned, alignment)
|
||||||
|
{
|
||||||
|
static const size_t good_alignments[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192};
|
||||||
|
for (size_t a = 0; a <= 8192; ++a)
|
||||||
|
{
|
||||||
|
bool good = false;
|
||||||
|
for (const auto t: good_alignments) if (a == t) good = true;
|
||||||
|
void *ptr = aligned_malloc(1, a);
|
||||||
|
if (good)
|
||||||
|
{
|
||||||
|
ASSERT_TRUE(ptr != NULL);
|
||||||
|
aligned_free(ptr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ASSERT_TRUE(ptr == NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT_TRUE(aligned_malloc(1, ~0) == NULL);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue