diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-10-08 10:44:51 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-10-08 11:36:42 +0000 |
commit | 6653062e6135e37fd36d81c575e70ef33b02609b (patch) | |
tree | a5baf64acfb86102d26fb626546061c44f99c57f /tests | |
parent | Merge pull request #4036 (diff) | |
download | monero-6653062e6135e37fd36d81c575e70ef33b02609b.tar.xz |
unit_tests: add unit test for alloc alignment being a power of 2
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit_tests/aligned.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/unit_tests/aligned.cpp b/tests/unit_tests/aligned.cpp index ad4837bec..2b733faf2 100644 --- a/tests/unit_tests/aligned.cpp +++ b/tests/unit_tests/aligned.cpp @@ -84,3 +84,24 @@ TEST(aligned, contents_smaller) 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); +} |