Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK committed Aug 22, 2024
1 parent dd4e827 commit c4d45ea
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
58 changes: 57 additions & 1 deletion tests/alloc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)

0 comments on commit c4d45ea

Please sign in to comment.