From c4d45ea9a13c4a37b00fdd7a39f8fb60fc9d6948 Mon Sep 17 00:00:00 2001 From: Dengke Date: Thu, 22 Aug 2024 16:57:54 -0700 Subject: [PATCH] add test --- tests/CMakeLists.txt | 3 +++ tests/alloc_test.c | 58 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d3556c5f7..f19f3df81 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -327,6 +327,9 @@ add_test_case(default_threaded_reallocs) add_test_case(default_threaded_allocs_and_frees) add_test_case(aligned_threaded_reallocs) add_test_case(aligned_threaded_allocs_and_frees) +add_test_case(customized_aligned_sanitize) +add_test_case(customized_aligned_threaded_reallocs) +add_test_case(customized_aligned_threaded_allocs_and_frees) add_test_case(test_memtrace_none) add_test_case(test_memtrace_count) diff --git a/tests/alloc_test.c b/tests/alloc_test.c index 364b3f319..433226928 100644 --- a/tests/alloc_test.c +++ b/tests/alloc_test.c @@ -350,7 +350,7 @@ static int s_default_threaded_allocs_and_frees(struct aws_allocator *allocator, AWS_TEST_CASE(default_threaded_allocs_and_frees, s_default_threaded_allocs_and_frees) /* - * No align allocator tests. + * aligned allocator tests. */ static int s_aligned_threaded_reallocs(struct aws_allocator *allocator, void *ctx) { (void)allocator; @@ -381,3 +381,59 @@ static int s_aligned_threaded_allocs_and_frees(struct aws_allocator *allocator, return 0; } AWS_TEST_CASE(aligned_threaded_allocs_and_frees, s_aligned_threaded_allocs_and_frees) + +static int s_customized_aligned_sanitize(struct aws_allocator *allocator, void *ctx) { + (void)ctx; + + struct aws_allocator *aligned_alloc = aws_customized_aligned_allocator_new(allocator, 1); + ASSERT_NULL(aligned_alloc); + ASSERT_UINT_EQUALS(aws_last_error(), AWS_ERROR_INVALID_ARGUMENT); + + aligned_alloc = aws_customized_aligned_allocator_new(allocator, 3 * sizeof(void *)); + ASSERT_NULL(aligned_alloc); + ASSERT_UINT_EQUALS(aws_last_error(), AWS_ERROR_INVALID_ARGUMENT); + + size_t aligned_size = 1024; + aligned_alloc = aws_customized_aligned_allocator_new(allocator, aligned_size); + ASSERT_NOT_NULL(aligned_alloc); + void *test = aws_mem_acquire(aligned_alloc, sizeof(void *)); + ASSERT_TRUE((uintptr_t)test % aligned_size == 0); + aws_mem_release(aligned_alloc, test); + + aws_customized_aligned_allocator_destroy(aligned_alloc); + + return 0; +} +AWS_TEST_CASE(customized_aligned_sanitize, s_customized_aligned_sanitize) + +static int s_customized_aligned_threaded_reallocs(struct aws_allocator *allocator, void *ctx) { + (void)ctx; + srand(15); + struct aws_allocator *aligned_alloc = aws_customized_aligned_allocator_new(allocator, 512); + + struct aws_allocator *alloc = aws_mem_tracer_new(aligned_alloc, NULL, AWS_MEMTRACE_STACKS, 8); + + s_thread_test(alloc, s_threaded_realloc_worker, alloc); + + aws_mem_tracer_destroy(alloc); + aws_customized_aligned_allocator_destroy(aligned_alloc); + + return 0; +} +AWS_TEST_CASE(customized_aligned_threaded_reallocs, s_customized_aligned_threaded_reallocs) + +static int s_customized_aligned_threaded_allocs_and_frees(struct aws_allocator *allocator, void *ctx) { + (void)ctx; + srand(99); + struct aws_allocator *aligned_alloc = aws_customized_aligned_allocator_new(allocator, 512); + + struct aws_allocator *alloc = aws_mem_tracer_new(aligned_alloc, NULL, AWS_MEMTRACE_STACKS, 8); + + s_thread_test(alloc, s_threaded_alloc_worker, alloc); + + aws_mem_tracer_destroy(alloc); + aws_customized_aligned_allocator_destroy(aligned_alloc); + + return 0; +} +AWS_TEST_CASE(customized_aligned_threaded_allocs_and_frees, s_customized_aligned_threaded_allocs_and_frees)