diff options
author | Mark D. Roth <roth@google.com> | 2018-01-22 12:51:03 -0800 |
---|---|---|
committer | Mark D. Roth <roth@google.com> | 2018-01-22 12:51:03 -0800 |
commit | 62569dd9785e59a6b87a5002d09aeec1c39f541b (patch) | |
tree | b7e0fd0f075b891af60f1c6736a04ed12f77bf16 /test | |
parent | a9fc084ec1be4ab8f2071227d9affb77f713e0db (diff) |
Fix arena to return aligned memory.
Diffstat (limited to 'test')
-rw-r--r-- | test/core/gpr/alloc_test.cc | 14 | ||||
-rw-r--r-- | test/core/gpr/arena_test.cc | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/test/core/gpr/alloc_test.cc b/test/core/gpr/alloc_test.cc index 6074c6e6e7..bf4471c36f 100644 --- a/test/core/gpr/alloc_test.cc +++ b/test/core/gpr/alloc_test.cc @@ -16,8 +16,11 @@ * */ +#include <string.h> + #include <grpc/support/alloc.h> #include <grpc/support/log.h> + #include "test/core/util/test_config.h" static void* fake_malloc(size_t size) { return (void*)size; } @@ -48,8 +51,19 @@ static void test_custom_allocs() { gpr_free(i); } +static void test_malloc_aligned() { + for (size_t size = 1; size <= 256; ++size) { + void* ptr = gpr_malloc_aligned(size, 16); + GPR_ASSERT(ptr != nullptr); + GPR_ASSERT(((intptr_t)ptr & 0xf) == 0); + memset(ptr, 0, size); + gpr_free_aligned(ptr); + } +} + int main(int argc, char** argv) { grpc_test_init(argc, argv); test_custom_allocs(); + test_malloc_aligned(); return 0; } diff --git a/test/core/gpr/arena_test.cc b/test/core/gpr/arena_test.cc index 59ea04c0ed..62a3f8bf50 100644 --- a/test/core/gpr/arena_test.cc +++ b/test/core/gpr/arena_test.cc @@ -53,6 +53,8 @@ static void test(const char* name, size_t init_size, const size_t* allocs, void** ps = static_cast<void**>(gpr_zalloc(sizeof(*ps) * nallocs)); for (size_t i = 0; i < nallocs; i++) { ps[i] = gpr_arena_alloc(a, allocs[i]); + // ensure the returned address is aligned + GPR_ASSERT(((intptr_t)ps[i] & 0xf) == 0); // ensure no duplicate results for (size_t j = 0; j < i; j++) { GPR_ASSERT(ps[i] != ps[j]); |