aboutsummaryrefslogtreecommitdiffstats
path: root/tests/liballoc_tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/liballoc_tests.c')
-rw-r--r--tests/liballoc_tests.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/tests/liballoc_tests.c b/tests/liballoc_tests.c
index 6b4a4d3..fed6080 100644
--- a/tests/liballoc_tests.c
+++ b/tests/liballoc_tests.c
@@ -32,16 +32,25 @@ END_TEST
START_TEST(multiple_allocations) {
size_t size = ALIGNMENT*5;
+
+ void *allocations[100];
for (size_t i=0; i<100; i++) {
- void *memory = allocate(size);
- ck_assert_ptr_nonnull(memory);
+ allocations[i] = allocate(size);
+ ck_assert_ptr_nonnull(allocations[i]);
- memset(memory, 0, size);
+ memset(allocations[i], 0, size);
- size_t alignment = (size_t) memory % ALIGNMENT;
+ size_t alignment = (size_t) allocations[i]% ALIGNMENT;
ck_assert_int_eq(alignment, 0);
}
+ /* verify the headers */
+ for (size_t i=0; i<100; i++) {
+ header *hdr = allocations[i] - sizeof(header);
+ ck_assert_int_eq(hdr->size, size);
+ ck_assert_int_eq(hdr->magic_number, MAGIC_NUMBER);
+ }
+
/* leak the memory--we aren't testing release */
}
@@ -70,19 +79,32 @@ END_TEST
START_TEST(unaligned_allocation) {
size_t unaligned_size = ALIGNMENT + 3;
+ void *allocations[100];
/* ensure first allocation is aligned */
- void *first_memory = allocate(unaligned_size);
- size_t first_alignment = (size_t) first_memory % ALIGNMENT;
+ allocations[0] = allocate(unaligned_size);
+ size_t first_alignment = (size_t) allocations[0] % ALIGNMENT;
ck_assert_int_eq(first_alignment, 0);
+ memset(allocations[0], 0, unaligned_size);
+
/* now allocate several more times--each allocation should be aligned */
- for (size_t i=0; i<10; i++) {
- void *memory = allocate(unaligned_size);
- size_t alignment = (size_t) memory % ALIGNMENT;
+ for (size_t i=1; i<100; i++) {
+ allocations[i] = allocate(unaligned_size);
+ size_t alignment = (size_t) allocations[i] % ALIGNMENT;
ck_assert_int_eq(alignment, 0);
+ /* verify we can write the the memory */
+ memset(allocations[i], 0, unaligned_size);
+
/* just leak the memory--we aren't testing release here */
}
+
+ /* verify the headers */
+ for (size_t i=0; i<100; i++) {
+ header *hdr = allocations[i] - sizeof(header);
+ ck_assert_int_eq(hdr->magic_number, MAGIC_NUMBER);
+ }
+
}