aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2018-10-20 20:39:57 +0200
committerRiccardo Spagni <ric@spagni.net>2018-10-20 20:39:58 +0200
commit14dbe67fa76236a590463d22fe405b8e3eeb4979 (patch)
tree00941f14895b09621c73d00acc0bf55092988971
parentMerge pull request #4518 (diff)
parentunit_tests: add unit test for alloc alignment being a power of 2 (diff)
downloadmonero-14dbe67fa76236a590463d22fe405b8e3eeb4979.tar.xz
Merge pull request #4521
6653062e unit_tests: add unit test for alloc alignment being a power of 2 (moneromooo-monero)
-rw-r--r--tests/unit_tests/aligned.cpp21
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);
+}